diff --git a/.gitignore b/.gitignore index e69de29bb..c2fd41347 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1,5 @@ +linux-*.tar.bz2 +patch-*.bz2 +clog +*.rpm +kernel-2.6.*/ diff --git a/Makefile b/Makefile new file mode 100644 index 000000000..ea1296b48 --- /dev/null +++ b/Makefile @@ -0,0 +1,297 @@ +# Makefile for source rpm: kernel +SPECFILE := kernel.spec + +# use noarch for make prep instead of the current CPU +# noarch creates and checks all config files not just the current one, +# in addition "i386" isn't a valid kernel target +PREPARCH = noarch + +# we only check the .sign signatures +UPSTREAM_CHECKS = sign + +.PHONY: help +help: +%: + @echo "Try fedpkg $@ or something like that" + @exit 1 + +include Makefile.config + +ifndef KVERSION +KVERSION := $(shell awk '$$1 == "%define" && $$2 == "base_sublevel" { \ + print "2.6." $$3 \ + }' $(SPECFILE)) +endif + +prep: + fedpkg -v prep --arch=$(PREPARCH) + +extremedebug: + @perl -pi -e 's/# CONFIG_DEBUG_PAGEALLOC is not set/CONFIG_DEBUG_PAGEALLOC=y/' config-nodebug + +debug: + @perl -pi -e 's/# CONFIG_SLUB_DEBUG_ON is not set/CONFIG_SLUB_DEBUG_ON=y/' config-nodebug + @perl -pi -e 's/# CONFIG_LOCK_STAT is not set/CONFIG_LOCK_STAT=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_STACK_USAGE is not set/CONFIG_DEBUG_STACK_USAGE=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_SLAB is not set/CONFIG_DEBUG_SLAB=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_MUTEXES is not set/CONFIG_DEBUG_MUTEXES=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_RT_MUTEXES is not set/CONFIG_DEBUG_RT_MUTEXES=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_RWSEMS is not set/CONFIG_DEBUG_RWSEMS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_LOCK_ALLOC is not set/CONFIG_DEBUG_LOCK_ALLOC=y/' config-nodebug + @perl -pi -e 's/# CONFIG_PROVE_LOCKING is not set/CONFIG_PROVE_LOCKING=y/' config-nodebug + @perl -pi -e 's/# CONFIG_PROVE_RCU is not set/CONFIG_PROVE_RCU=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_SPINLOCK is not set/CONFIG_DEBUG_SPINLOCK=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_VM is not set/CONFIG_DEBUG_VM=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_SLEEP_IN_IRQ is not set/CONFIG_DEBUG_SLEEP_IN_IRQ=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAULT_INJECTION is not set/CONFIG_FAULT_INJECTION=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAILSLAB is not set/CONFIG_FAILSLAB=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAIL_PAGE_ALLOC is not set/CONFIG_FAIL_PAGE_ALLOC=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAIL_IO_TIMEOUT is not set/CONFIG_FAIL_IO_TIMEOUT=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAIL_MAKE_REQUEST is not set/CONFIG_FAIL_MAKE_REQUEST=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAULT_INJECTION_DEBUG_FS is not set/CONFIG_FAULT_INJECTION_DEBUG_FS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_FAULT_INJECTION_STACKTRACE_FILTER is not set/CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_SG is not set/CONFIG_DEBUG_SG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_WRITECOUNT is not set/CONFIG_DEBUG_WRITECOUNT=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_OBJECTS is not set/CONFIG_DEBUG_OBJECTS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_OBJECTS_FREE is not set/CONFIG_DEBUG_OBJECTS_FREE=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_OBJECTS_TIMERS is not set/CONFIG_DEBUG_OBJECTS_TIMERS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_X86_PTDUMP is not set/CONFIG_X86_PTDUMP=y/' config-nodebug + @perl -pi -e 's/# CONFIG_CAN_DEBUG_DEVICES is not set/CONFIG_CAN_DEBUG_DEVICES=y/' config-nodebug + @perl -pi -e 's/# CONFIG_MODULE_FORCE_UNLOAD is not set/CONFIG_MODULE_FORCE_UNLOAD=y/' config-nodebug + @perl -pi -e 's/# CONFIG_SYSCTL_SYSCALL_CHECK is not set/CONFIG_SYSCTL_SYSCALL_CHECK=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_NOTIFIERS is not set/CONFIG_DEBUG_NOTIFIERS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DMA_API_DEBUG is not set/CONFIG_DMA_API_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_PM_TEST_SUSPEND is not set/CONFIG_PM_TEST_SUSPEND=y/' config-generic + @perl -pi -e 's/# CONFIG_PM_ADVANCED_DEBUG is not set/CONFIG_PM_ADVANCED_DEBUG=y/' config-generic + @perl -pi -e 's/# CONFIG_BOOT_TRACER is not set/CONFIG_BOOT_TRACER=y/' config-generic + @perl -pi -e 's/# CONFIG_B43_DEBUG is not set/CONFIG_B43_DEBUG=y/' config-generic + @perl -pi -e 's/# CONFIG_B43LEGACY_DEBUG is not set/CONFIG_B43LEGACY_DEBUG=y/' config-generic + @perl -pi -e 's/# CONFIG_MMIOTRACE is not set/CONFIG_MMIOTRACE=y/' config-nodebug + @perl -pi -e 's/CONFIG_STRIP_ASM_SYMS=y/# CONFIG_STRIP_ASM_SYMS is not set/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_CREDENTIALS is not set/CONFIG_DEBUG_CREDENTIALS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set/CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y/' config-nodebug + @perl -pi -e 's/# CONFIG_ACPI_DEBUG is not set/CONFIG_ACPI_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_EXT4_DEBUG is not set/CONFIG_EXT4_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_PERF_USE_VMALLOC is not set/CONFIG_DEBUG_PERF_USE_VMALLOC=y/' config-nodebug + @perl -pi -e 's/# CONFIG_JBD2_DEBUG is not set/CONFIG_JBD2_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_CFQ_IOSCHED is not set/CONFIG_DEBUG_CFQ_IOSCHED=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DRBD_FAULT_INJECTION is not set/CONFIG_DRBD_FAULT_INJECTION=y/' config-nodebug + @perl -pi -e 's/# CONFIG_ATH_DEBUG is not set/CONFIG_ATH_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_IWLWIFI_DEVICE_TRACING is not set/CONFIG_IWLWIFI_DEVICE_TRACING=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_OBJECTS_WORK is not set/CONFIG_DEBUG_OBJECTS_WORK=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_STRICT_USER_COPY_CHECKS is not set/CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DMADEVICES_DEBUG is not set/CONFIG_DMADEVICES_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_DMADEVICES_VDEBUG is not set/CONFIG_DMADEVICES_VDEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_CEPH_FS_PRETTYDEBUG is not set/CONFIG_CEPH_FS_PRETTYDEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_QUOTA_DEBUG is not set/CONFIG_QUOTA_DEBUG=y/' config-nodebug + @perl -pi -e 's/# CONFIG_KGDB_KDB is not set/CONFIG_KGDB_KDB=y/' config-nodebug + @perl -pi -e 's/# CONFIG_KDB_KEYBOARD is not set/CONFIG_KDB_KEYBOARD=y/' config-nodebug + @perl -pi -e 's/# CONFIG_CPU_NOTIFIER_ERROR_INJECT is not set/CONFIG_CPU_NOTIFIER_ERROR_INJECT=m/' config-nodebug + @perl -pi -e 's/# CONFIG_DEBUG_PER_CPU_MAPS is not set/CONFIG_DEBUG_PER_CPU_MAPS=y/' config-nodebug + + @# just in case we're going from extremedebug -> debug + @perl -pi -e 's/CONFIG_DEBUG_PAGEALLOC=y/# CONFIG_DEBUG_PAGEALLOC is not set/' config-nodebug + + @perl -pi -e 's/CONFIG_NR_CPUS=256/CONFIG_NR_CPUS=512/' config-x86_64-generic + + @perl -pi -e 's/^%define debugbuildsenabled 1/%define debugbuildsenabled 0/' kernel.spec + @perl -pi -e 's/^%define rawhide_skip_docs 0/%define rawhide_skip_docs 1/' kernel.spec + +release: + @perl -pi -e 's/CONFIG_SLUB_DEBUG_ON=y/# CONFIG_SLUB_DEBUG_ON is not set/' config-nodebug + @perl -pi -e 's/CONFIG_LOCK_STAT=y/# CONFIG_LOCK_STAT is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_STACK_USAGE=y/# CONFIG_DEBUG_STACK_USAGE is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_SLAB=y/# CONFIG_DEBUG_SLAB is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_MUTEXES=y/# CONFIG_DEBUG_MUTEXES is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_RT_MUTEXES=y/# CONFIG_DEBUG_RT_MUTEXES is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_RWSEMS=y/# CONFIG_DEBUG_RWSEMS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_LOCK_ALLOC=y/# CONFIG_DEBUG_LOCK_ALLOC is not set/' config-nodebug + @perl -pi -e 's/CONFIG_PROVE_LOCKING=y/# CONFIG_PROVE_LOCKING is not set/' config-nodebug + @perl -pi -e 's/CONFIG_PROVE_RCU=y/# CONFIG_PROVE_RCU is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_SPINLOCK=y/# CONFIG_DEBUG_SPINLOCK is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_VM=y/# CONFIG_DEBUG_VM is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_SLEEP_IN_IRQ=y/# CONFIG_DEBUG_SLEEP_IN_IRQ is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAULT_INJECTION=y/# CONFIG_FAULT_INJECTION is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAILSLAB=y/# CONFIG_FAILSLAB is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAIL_PAGE_ALLOC=y/# CONFIG_FAIL_PAGE_ALLOC is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAIL_IO_TIMEOUT=y/# CONFIG_FAIL_IO_TIMEOUT is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAIL_MAKE_REQUEST=y/# CONFIG_FAIL_MAKE_REQUEST is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAULT_INJECTION_DEBUG_FS=y/# CONFIG_FAULT_INJECTION_DEBUG_FS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y/# CONFIG_FAULT_INJECTION_STACKTRACE_FILTER is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_SG=y/# CONFIG_DEBUG_SG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_WRITECOUNT=y/# CONFIG_DEBUG_WRITECOUNT is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_OBJECTS=y/# CONFIG_DEBUG_OBJECTS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_OBJECTS_FREE=y/# CONFIG_DEBUG_OBJECTS_FREE is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_OBJECTS_TIMERS=y/# CONFIG_DEBUG_OBJECTS_TIMERS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_X86_PTDUMP=y/# CONFIG_X86_PTDUMP is not set/' config-nodebug + @perl -pi -e 's/CONFIG_CAN_DEBUG_DEVICES=y/# CONFIG_CAN_DEBUG_DEVICES is not set/' config-nodebug + @perl -pi -e 's/CONFIG_MODULE_FORCE_UNLOAD=y/# CONFIG_MODULE_FORCE_UNLOAD is not set/' config-nodebug + @perl -pi -e 's/CONFIG_SYSCTL_SYSCALL_CHECK=y/# CONFIG_SYSCTL_SYSCALL_CHECK is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_NOTIFIERS=y/# CONFIG_DEBUG_NOTIFIERS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DMA_API_DEBUG=y/# CONFIG_DMA_API_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_PM_TEST_SUSPEND=y/#\ CONFIG_PM_TEST_SUSPEND\ is\ not\ set/' config-generic + @perl -pi -e 's/CONFIG_PM_ADVANCED_DEBUG=y/#\ CONFIG_PM_ADVANCED_DEBUG\ is\ not\ set/' config-generic + @perl -pi -e 's/CONFIG_BOOT_TRACER=y/#\ CONFIG_BOOT_TRACER\ is\ not\ set/' config-generic + @perl -pi -e 's/CONFIG_B43_DEBUG=y/# CONFIG_B43_DEBUG is not set/' config-generic + @perl -pi -e 's/CONFIG_B43LEGACY_DEBUG=y/# CONFIG_B43LEGACY_DEBUG is not set/' config-generic + @perl -pi -e 's/CONFIG_MMIOTRACE=y/# CONFIG_MMIOTRACE is not set/' config-nodebug + @perl -pi -e 's/# CONFIG_STRIP_ASM_SYMS is not set/CONFIG_STRIP_ASM_SYMS=y/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_CREDENTIALS=y/# CONFIG_DEBUG_CREDENTIALS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_FORCE_WEAK_PER_CPU=y/# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set/' config-nodebug + @perl -pi -e 's/CONFIG_ACPI_DEBUG=y/# CONFIG_ACPI_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_EXT4_DEBUG=y/# CONFIG_EXT4_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_PERF_USE_VMALLOC=y/# CONFIG_DEBUG_PERF_USE_VMALLOC is not set/' config-nodebug + @perl -pi -e 's/CONFIG_JBD2_DEBUG=y/# CONFIG_JBD2_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_CFQ_IOSCHED=y/# CONFIG_DEBUG_CFQ_IOSCHED is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DRBD_FAULT_INJECTION=y/# CONFIG_DRBD_FAULT_INJECTION is not set/' config-nodebug + @perl -pi -e 's/CONFIG_ATH_DEBUG=y/# CONFIG_ATH_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_IWLWIFI_DEVICE_TRACING=y/# CONFIG_IWLWIFI_DEVICE_TRACING is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_OBJECTS_WORK=y/# CONFIG_DEBUG_OBJECTS_WORK is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_STRICT_USER_COPY_CHECKS=y/# CONFIG_DEBUG_STRICT_USER_COPY_CHECKS is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DMADEVICES_DEBUG=y/# CONFIG_DMADEVICES_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DMADEVICES_VDEBUG=y/# CONFIG_DMADEVICES_VDEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_CEPH_FS_PRETTYDEBUG=y/# CONFIG_CEPH_FS_PRETTYDEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_QUOTA_DEBUG=y/# CONFIG_QUOTA_DEBUG is not set/' config-nodebug + @perl -pi -e 's/CONFIG_CPU_NOTIFIER_ERROR_INJECT=m/# CONFIG_CPU_NOTIFIER_ERROR_INJECT is not set/' config-nodebug + #@perl -pi -e 's/CONFIG_KGDB_KDB=y/# CONFIG_KGDB_KDB is not set/' config-nodebug + #@perl -pi -e 's/CONFIG_KDB_KEYBOARD=y/# CONFIG_KDB_KEYBOARD is not set/' config-nodebug + @perl -pi -e 's/CONFIG_DEBUG_PER_CPU_MAPS=y/# CONFIG_DEBUG_PER_CPU_MAPS is not set/' config-nodebug + + @perl -pi -e 's/CONFIG_DEBUG_PAGEALLOC=y/# CONFIG_DEBUG_PAGEALLOC is not set/' config-debug + @perl -pi -e 's/CONFIG_DEBUG_PAGEALLOC=y/# CONFIG_DEBUG_PAGEALLOC is not set/' config-nodebug + + @perl -pi -e 's/CONFIG_NR_CPUS=512/CONFIG_NR_CPUS=256/' config-x86_64-generic + + @perl -pi -e 's/^%define debugbuildsenabled 0/%define debugbuildsenabled 1/' kernel.spec + @perl -pi -e 's/^%define rawhide_skip_docs 1/%define rawhide_skip_docs 0/' kernel.spec + +reconfig: + @rm -f kernel-*-config + @VERSION=$(KVERSION) make -f Makefile.config configs + @scripts/reconfig.sh + +unused-kernel-patches: + @for f in *.patch; do if [ -e $$f ]; then (egrep -q "^Patch[[:digit:]]+:[[:space:]]+$$f" $(SPECFILE) || echo "Unused: $$f") && egrep -q "^ApplyPatch[[:space:]]+$$f|^ApplyOptionalPatch[[:space:]]+$$f" $(SPECFILE) || echo "Unapplied: $$f"; fi; done + +# since i386 isn't a target... +compile compile-short: DIST_DEFINES += --target $(shell uname -m) + +# 'make local' also needs to build the noarch firmware package +local: noarch + +# +# Hacks for building vanilla (unpatched) kernel rpms. +# Use "make vanilla-TARGET" like "make TARGET" (make vanilla-scratch-build). +# +vanilla-%: $(SPECFILE:.spec=-vanilla.spec) + @$(MAKE) $* SPECFILE=$< + +$(SPECFILE:.spec=-vanilla.spec): $(SPECFILE) + @rm -f $@ + (echo %define nopatches 1; cat $<) > $@ + +#scratch-build: NAME = $(shell rpm $(RPM_DEFINES) $(DIST_DEFINES) -q --qf "%{NAME}\n" --specfile $(SPECFILE)| head -1) +#scratch-build: test-srpm +# $(BUILD_CLIENT) build $(BUILD_FLAGS) --scratch $(TARGET) \ +# $(SRCRPMDIR)/$(NAME)-$(VERSION)-$(RELEASE).src.rpm + +# Dismal kludge for building via brew from cvs after "make vanilla-tag". +ifdef BEEHIVE_SRPM_BUILD +export CHECKOUT_TAG ?= $(shell sed s/^.// CVS/Tag) +tag-pattern = $(TAG_NAME)-$(TAG_VERSION)-0_%_$(TAG_RELEASE) +ifeq (,$(filter-out $(tag-pattern),$(CHECKOUT_TAG))) +variant := $(patsubst $(tag-pattern),%,$(CHECKOUT_TAG)) +srpm: SPECFILE := $(wildcard $(SPECFILE:.spec=-$(variant).spec) \ + $(SPECFILE:.spec=.t.$(variant).spec)) +srpm beehive-sprm: RELEASE := 0.$(variant).$(RELEASE) +endif +endif + +# +# Hacks for building kernel rpms from upstream code plus local GIT branches. +# Use "make git/BRANCH/TARGET" like "make TARGET". +# Use "make git/BRANCH-fedora/TARGET" to include Fedora patches on top. +# +ifndef GIT_SPEC +git/%: + @$(MAKE) GIT_SPEC=$(subst /,-,$(*D)) git-$(*F) +else +git-%: $(SPECFILE:.spec=.t.$(GIT_SPEC).spec) + @$(MAKE) GIT_SPEC= $* SPECFILE=$< +endif + +# +# Your git-branches.mk file can define GIT_DIR, e.g.: +# GIT_DIR = ${HOME}/kernel/.git +# Make sure GIT_AUTHOR_NAME and GIT_AUTHOR_EMAIL are also set +# or your rpm changelogs will look like crap. +# +# For each branch it can define a variable branch-BRANCH or tag-BRANCH +# giving the parent of BRANCH to diff against in a separate patch. If +# the parent is unknown, it will use $(branch-upstream) defaulting to +# "refs/remotes/upstream/master". +# +# Defining tag-BRANCH means the tag corresponds to an upstream patch in +# the sources file, so that is used instead of generating a patch with +# git. If there is no tag-upstream defined, it will figure out a vNNN +# tag or vNNN-gitN pseudo-tag from the last patch in the sources file. +# For example: +# tag-some-hacks = v2.6.21-rc5 +# branch-more-hacks = some-hacks +# Leads to patches: +# git diff v2.6.21-rc5..more-hacks > linux-2.6.21-rc5-some-hacks.patch +# git diff some-hacks..more-hacks > linux-2.6.21-rc5-more-hacks.patch +# Whereas having no git-branches.mk at all but doing +# "make GIT_DIR=... git/mybranch/test-srpm" does: +# id=`cat patch-2.6.21-rc5-git4.id` # auto-fetched via upstream file +# git diff $id..upstream > linux-2.6.21-rc5-git4-upstream.patch +# git diff upstream..mybranch > linux-2.6.21-rc5-git4-mybranch.patch +# If the upstream patch (or any branch patch) is empty it's left out. +# +git-branches.mk:; +-include git-branches.mk + +branch-upstream ?= refs/remotes/upstream/master + +ifdef GIT_DIR +export GIT_DIR +export GIT_AUTHOR_NAME +export GIT_AUTHOR_EMAIL +gen-patches ?= gen-patches + +ifndef havespec +$(SPECFILE:.spec=.t.%-fedora.spec): $(SPECFILE) $(gen-patches) FORCE + ./$(gen-patches) --fedora < $< > $@ $(gen-patches-args) +$(SPECFILE:.spec=.t.%.spec): $(SPECFILE) $(gen-patches) FORCE + ./$(gen-patches) < $< > $@ $(gen-patches-args) +.PRECIOUS: $(SPECFILE:.spec=.t.%.spec) $(SPECFILE:.spec=.t.%-fedora.spec) +endif + +spec-%: $(SPECFILE:.spec=.t.%.spec) ; +$(SPECFILE):; +FORCE:; + +branch-of-* = $(firstword $(head-$*) $*) +gen-patches-args = --name $* v$(KVERSION) $(call heads,$(branch-of-*)) +define heads +$(if $(tag-$1),$(filter-out v$(KVERSION),$(tag-$1)),\ + $(call heads,$(firstword $(branch-$1) $(branch-upstream)))) $1 +endef + +files-%-fedora: + @echo $(SPECFILE:.spec=.t.$*-fedora.spec) + @$(call list-patches,$(branch-of-*)) +files-%: + @echo $(SPECFILE:.spec=.t.$*.spec) + @$(call list-patches,$(branch-of-*)) +define list-patches +$(if $(tag-$1),version=$(patsubst v%,%,$(tag-$1)),\ + $(call list-patches,$(firstword $(branch-$1) $(branch-upstream)))); \ +echo linux-$${version}-$(patsubst refs/remotes/%/master,%,$1).patch +endef + +ifndef tag-$(branch-upstream) +tag-$(branch-upstream) := $(shell \ + sed -n 's/^.* *//;s/\.bz2$$//;s/patch-/v/;/^v/h;$${g;p}' sources) +endif +endif diff --git a/Makefile.config b/Makefile.config new file mode 100644 index 000000000..53812fa9b --- /dev/null +++ b/Makefile.config @@ -0,0 +1,105 @@ +# Make rules for configuration files. +# +# $Id$ + +CFG = kernel-$(VERSION) + +CONFIGFILES = \ + $(CFG)-i686.config $(CFG)-i686-debug.config \ + $(CFG)-i686-PAE.config $(CFG)-i686-PAEdebug.config \ + $(CFG)-x86_64.config $(CFG)-x86_64-debug.config \ + $(CFG)-s390x.config $(CFG)-arm.config \ + $(CFG)-ppc.config $(CFG)-ppc-smp.config \ + $(CFG)-sparc64.config \ + $(CFG)-ppc64.config $(CFG)-ppc64-debug.config \ + $(CFG)-ia64.config + +PLATFORMS = x86 x86_64 powerpc powerpc32 powerpc64 s390x ia64 sparc64 +TEMPFILES = $(addprefix temp-, $(addsuffix -generic, $(PLATFORMS))) + +configs: $(CONFIGFILES) + @rm -f kernel-*-config + @rm -f $(TEMPFILES) + @rm -f temp-generic temp-*-generic temp-*-generic-tmp + +# Augment the clean target to clean up our own cruft +clean :: + @rm -fv $(CONFIGFILES) $(TEMPFILES) temp-generic kernel-$(VERSION)*config + +temp-generic: config-generic + cat config-generic config-nodebug > temp-generic + +temp-debug-generic: config-generic + cat config-generic config-debug > temp-debug-generic + +temp-x86-generic: config-x86-generic temp-generic + perl merge.pl $^ > $@ + +temp-x86-debug-generic: config-x86-generic temp-debug-generic + perl merge.pl $^ > $@ + +temp-x86_64-generic: config-x86_64-generic temp-generic + perl merge.pl $^ > $@ + +temp-x86_64-debug-generic: config-x86_64-generic temp-debug-generic + perl merge.pl $^ > $@ + +temp-sparc64-generic: config-sparc64-generic temp-generic + perl merge.pl $^ > $@ + +temp-powerpc-generic: config-powerpc-generic temp-generic + perl merge.pl $^ > $@ + +temp-powerpc-debug-generic: config-powerpc-generic temp-debug-generic + perl merge.pl $^ > $@ + +temp-powerpc32-generic: config-powerpc32-generic temp-powerpc-generic + perl merge.pl $^ > $@ + +temp-s390-generic: config-s390x temp-generic + perl merge.pl $^ > $@ + +temp-ia64-generic: config-ia64-generic temp-generic + perl merge.pl $^ > $@ + +kernel-$(VERSION)-i686-PAE.config: config-i686-PAE temp-x86-generic + perl merge.pl $^ i386 > $@ + +kernel-$(VERSION)-i686-PAEdebug.config: config-i686-PAE temp-x86-debug-generic + perl merge.pl $^ i386 > $@ + +kernel-$(VERSION)-i686.config: /dev/null temp-x86-generic + perl merge.pl $^ i386 > $@ + +kernel-$(VERSION)-i686-debug.config: /dev/null temp-x86-debug-generic + perl merge.pl $^ i386 > $@ + +kernel-$(VERSION)-x86_64.config: /dev/null temp-x86_64-generic + perl merge.pl $^ x86_64 > $@ + +kernel-$(VERSION)-x86_64-debug.config: /dev/null temp-x86_64-debug-generic + perl merge.pl $^ x86_64 > $@ + +kernel-$(VERSION)-sparc64.config: /dev/null temp-sparc64-generic + perl merge.pl $^ sparc64 > $@ + +kernel-$(VERSION)-ppc64.config: config-powerpc64 temp-powerpc-generic + perl merge.pl $^ powerpc > $@ + +kernel-$(VERSION)-ppc64-debug.config: config-powerpc64 temp-powerpc-debug-generic + perl merge.pl $^ powerpc > $@ + +kernel-$(VERSION)-s390x.config: config-s390x temp-s390-generic + perl merge.pl $^ s390 > $@ + +kernel-$(VERSION)-arm.config: config-arm temp-generic + perl merge.pl $^ arm > $@ + +kernel-$(VERSION)-ppc.config: /dev/null temp-powerpc32-generic + perl merge.pl $^ powerpc > $@ + +kernel-$(VERSION)-ppc-smp.config: config-powerpc32-smp temp-powerpc32-generic + perl merge.pl $^ powerpc > $@ + +kernel-$(VERSION)-ia64.config: /dev/null temp-ia64-generic + perl merge.pl $^ ia64 > $@ diff --git a/README.txt b/README.txt new file mode 100644 index 000000000..482f8ea5b --- /dev/null +++ b/README.txt @@ -0,0 +1,67 @@ + + Kernel package tips & tricks. + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ + +The kernel is one of the more complicated packages in the distro, and +for the newcomer, some of the voodoo in the spec file can be somewhat scary. +This file attempts to document some of the magic. + + +Speeding up make prep +--------------------- +The kernel is nearly 500MB of source code, and as such, 'make prep' +takes a while. The spec file employs some trickery so that repeated +invocations of make prep don't take as long. Ordinarily the %prep +phase of a package will delete the tree it is about to untar/patch. +The kernel %prep keeps around an unpatched version of the tree, +and makes a symlink tree clone of that clean tree and than applies +the patches listed in the spec to the symlink tree. +This makes a huge difference if you're doing multiple make preps a day. +As an added bonus, doing a diff between the clean tree and the symlink +tree is slightly faster than it would be doing two proper copies of the tree. + + +build logs. +----------- +There's a convenience helper script in scripts/grab-logs.sh +that will grab the build logs from koji for the kernel version reported +by make verrel + + +config heirarchy. +----------------- +Instead of having to maintain a config file for every arch variant we build on, +the kernel spec uses a nested system of configs. At the top level, is +config-generic. Add options here that should be present in every possible +config on all architectures. +Beneath this are per-arch overrides. For example config-x86-generic add +additional x86 specific options, and also _override_ any options that were +set in config-generic. +There exist two additional overrides, config-debug, and config-nodebug, +which override -generic, and the per-arch overrides. It is documented +further below. + +debug options. +-------------- +This is a little complicated, as the purpose & meaning of this changes +depending on where we are in the release cycle. +If we are building for a current stable release, 'make release' has +typically been run already, which sets up the following.. +- Two builds occur, a 'kernel' and a 'kernel-debug' flavor. +- kernel-debug will get various heavyweight debugging options like + lockdep etc turned on. + +If we are building for rawhide, 'make debug' has been run, which changes +the status quo to: +- We only build one kernel 'kernel' +- The debug options from 'config-debug' are always turned on. +This is done to increase coverage testing, as not many people actually +run kernel-debug. + +To add new debug options, add an option to _both_ config-debug and config-nodebug, +and also new stanzas to the Makefile 'debug' and 'release' targets. + +Sometimes debug options get added to config-generic, or per-arch overrides +instead of config-[no]debug. In this instance, the options should have no +discernable performance impact, otherwise they belong in the debug files. + diff --git a/acpi-ec-add-delay-before-write.patch b/acpi-ec-add-delay-before-write.patch new file mode 100644 index 000000000..af49cccbd --- /dev/null +++ b/acpi-ec-add-delay-before-write.patch @@ -0,0 +1,52 @@ +https://bugzilla.kernel.org/show_bug.cgi?id=14733#c41 + +diff --git a/drivers/acpi/ec.c b/drivers/acpi/ec.c +index 27e0b92..09fbb69 100644 +--- a/drivers/acpi/ec.c ++++ b/drivers/acpi/ec.c +@@ -226,6 +226,7 @@ static int ec_poll(struct acpi_ec *ec) + if (ec_transaction_done(ec)) + return 0; + } else { ++ msleep(1); + if (wait_event_timeout(ec->wait, + ec_transaction_done(ec), + msecs_to_jiffies(1))) +@@ -233,8 +234,8 @@ static int ec_poll(struct acpi_ec *ec) + } + advance_transaction(ec, acpi_ec_read_status(ec)); + } while (time_before(jiffies, delay)); +- if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) +- break; ++// if (acpi_ec_read_status(ec) & ACPI_EC_FLAG_IBF) ++// break; + pr_debug(PREFIX "controller reset, restart transaction\n"); + spin_lock_irqsave(&ec->curr_lock, flags); + start_transaction(ec); +@@ -271,15 +272,25 @@ static int ec_check_ibf0(struct acpi_ec *ec) + return (status & ACPI_EC_FLAG_IBF) == 0; + } + ++/* try to clean input buffer with burst_disable transaction */ ++static int acpi_ec_clean_buffer(struct acpi_ec *ec) ++{ ++ struct transaction t = {.command = ACPI_EC_BURST_DISABLE, ++ .wdata = NULL, .rdata = NULL, ++ .wlen = 0, .rlen = 0}; ++ return acpi_ec_transaction_unlocked(ec, &t); ++} ++ + static int ec_wait_ibf0(struct acpi_ec *ec) + { ++ + unsigned long delay = jiffies + msecs_to_jiffies(ACPI_EC_DELAY); + /* interrupt wait manually if GPE mode is not active */ + while (time_before(jiffies, delay)) + if (wait_event_timeout(ec->wait, ec_check_ibf0(ec), + msecs_to_jiffies(1))) + return 0; +- return -ETIME; ++ return acpi_ec_clean_buffer(ec); + } + + static int acpi_ec_transaction(struct acpi_ec *ec, struct transaction *t) diff --git a/add-appleir-driver.patch b/add-appleir-driver.patch new file mode 100644 index 000000000..0eb350cd6 --- /dev/null +++ b/add-appleir-driver.patch @@ -0,0 +1,682 @@ +commit 92c912df2a0725d719263357176f98b2201a2acd +Author: Bastien Nocera +Date: Wed Apr 21 14:51:58 2010 +0100 + + Input: add appleir USB driver + + This driver was originally written by James McKenzie, updated by + Greg Kroah-Hartman, further updated by myself, with suspend support + added. + + More recent versions of the IR receiver are also supported through + a patch by Alex Karpenko. + + Tested on a MacbookAir1,1 + + Signed-off-by: Bastien Nocera + +commit 6ffcbf68913840e9e882db14441576ffee6eba0c +Author: Bastien Nocera +Date: Fri Apr 16 17:19:50 2010 +0100 + + Add HID_QUIRK_HIDDEV_FORCE and HID_QUIRK_NO_IGNORE + + Add two quirks to make it possible for usbhid module options to + override whether a device is ignored (HID_QUIRK_NO_IGNORE) and + whether to connect a hiddev device (HID_QUIRK_HIDDEV_FORCE). + + Passing HID_QUIRK_NO_IGNORE for your device means that it will + not be ignored by the HID layer, even if present in a blacklist. + + HID_QUIRK_HIDDEV_FORCE will force the creation of a hiddev for that + device, making it accessible from user-space. + + Tested with an Apple IR Receiver, switching it from using appleir + to using lirc's macmini driver. + + Signed-off-by: Bastien Nocera + +diff --git a/Documentation/input/appleir.txt b/Documentation/input/appleir.txt +new file mode 100644 +index 0000000..0267a4b +--- /dev/null ++++ b/Documentation/input/appleir.txt +@@ -0,0 +1,45 @@ ++Apple IR receiver Driver (appleir) ++---------------------------------- ++ Copyright (C) 2009 Bastien Nocera ++ ++The appleir driver is a kernel input driver to handle Apple's IR ++receivers (and associated remotes) in the kernel. ++ ++The driver is an input driver which only handles "official" remotes ++as built and sold by Apple. ++ ++Authors ++------- ++ ++James McKenzie (original driver) ++Alex Karpenko (05ac:8242 support) ++Greg Kroah-Hartman (cleanups and original submission) ++Bastien Nocera (further cleanups and suspend support) ++ ++Supported hardware ++------------------ ++ ++- All Apple laptops and desktops from 2005 onwards, except: ++ - the unibody Macbook (2009) ++ - Mac Pro (all versions) ++- Apple TV (all revisions) ++ ++The remote will only support the 6 buttons of the original remotes ++as sold by Apple. See the next section if you want to use other remotes ++or want to use lirc with the device instead of the kernel driver. ++ ++Using lirc (native) instead of the kernel driver ++------------------------------------------------ ++ ++First, you will need to disable the kernel driver for the receiver. ++ ++This can be achieved by passing quirks to the usbhid driver. ++The quirk line would be: ++usbhid.quirks=0x05ac:0x8242:0x40000010 ++ ++With 0x05ac being the vendor ID (Apple, you shouldn't need to change this) ++With 0x8242 being the product ID (check the output of lsusb for your hardware) ++And 0x10 being "HID_QUIRK_HIDDEV_FORCE" and 0x40000000 being "HID_QUIRK_NO_IGNORE" ++ ++This should force the creation of a hiddev device for the receiver, and ++make it usable under lirc. +diff --git a/drivers/hid/hid-apple.c b/drivers/hid/hid-apple.c +index 5b4d66d..b0e1811 100644 +--- a/drivers/hid/hid-apple.c ++++ b/drivers/hid/hid-apple.c +@@ -353,10 +353,6 @@ static void apple_remove(struct hid_device *hdev) + } + + static const struct hid_device_id apple_devices[] = { +- { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL), +- .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT }, +- { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4), +- .driver_data = APPLE_HIDDEV | APPLE_IGNORE_HIDINPUT }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE), + .driver_data = APPLE_MIGHTYMOUSE | APPLE_INVERT_HWHEEL }, + +diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c +index 8455f3d..e795d8c 100644 +--- a/drivers/hid/hid-core.c ++++ b/drivers/hid/hid-core.c +@@ -1170,6 +1170,8 @@ int hid_connect(struct hid_device *hdev, unsigned int connect_mask) + unsigned int i; + int len; + ++ if (hdev->quirks & HID_QUIRK_HIDDEV_FORCE) ++ connect_mask |= (HID_CONNECT_HIDDEV_FORCE | HID_CONNECT_HIDDEV); + if (hdev->bus != BUS_USB) + connect_mask &= ~HID_CONNECT_HIDDEV; + if (hid_hiddev(hdev)) +@@ -1250,8 +1252,6 @@ EXPORT_SYMBOL_GPL(hid_disconnect); + static const struct hid_device_id hid_blacklist[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_WCP32PU) }, + { HID_USB_DEVICE(USB_VENDOR_ID_A4TECH, USB_DEVICE_ID_A4TECH_X5_005D) }, +- { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, +- { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_MIGHTYMOUSE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ANSI) }, + { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_FOUNTAIN_ISO) }, +@@ -1545,6 +1545,9 @@ static const struct hid_device_id hid_ignore_list[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_ALCOR, USB_DEVICE_ID_ALCOR_USBRS232) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM)}, + { HID_USB_DEVICE(USB_VENDOR_ID_ASUS, USB_DEVICE_ID_ASUS_LCM2)}, ++ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, ++ { HID_USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, + { HID_USB_DEVICE(USB_VENDOR_ID_AVERMEDIA, USB_DEVICE_ID_AVER_FM_MR800) }, + { HID_USB_DEVICE(USB_VENDOR_ID_BERKSHIRE, USB_DEVICE_ID_BERKSHIRE_PCWD) }, + { HID_USB_DEVICE(USB_VENDOR_ID_CIDC, 0x0103) }, +@@ -1749,7 +1752,7 @@ int hid_add_device(struct hid_device *hdev) + + /* we need to kill them here, otherwise they will stay allocated to + * wait for coming driver */ +- if (hid_ignore(hdev)) ++ if (!(hdev->quirks & HID_QUIRK_NO_IGNORE) && hid_ignore(hdev)) + return -ENODEV; + + /* XXX hack, any other cleaner solution after the driver core +diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h +index 793691f..9255c1a 100644 +--- a/drivers/hid/hid-ids.h ++++ b/drivers/hid/hid-ids.h +@@ -93,6 +93,7 @@ + #define USB_DEVICE_ID_APPLE_ALU_WIRELESS_2009_JIS 0x023b + #define USB_DEVICE_ID_APPLE_FOUNTAIN_TP_ONLY 0x030a + #define USB_DEVICE_ID_APPLE_GEYSER1_TP_ONLY 0x030b ++#define USB_DEVICE_ID_APPLE_IRCONTROL 0x8240 + #define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241 + #define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242 + +diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c +index 2f84237..2de42e1 100644 +--- a/drivers/hid/usbhid/hid-core.c ++++ b/drivers/hid/usbhid/hid-core.c +@@ -1142,6 +1142,7 @@ static int usbhid_probe(struct usb_interface *intf, const struct usb_device_id * + hid->vendor = le16_to_cpu(dev->descriptor.idVendor); + hid->product = le16_to_cpu(dev->descriptor.idProduct); + hid->name[0] = 0; ++ hid->quirks = usbhid_lookup_quirk(hid->vendor, hid->product); + if (intf->cur_altsetting->desc.bInterfaceProtocol == + USB_INTERFACE_PROTOCOL_MOUSE) + hid->type = HID_TYPE_USBMOUSE; +diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig +index 16ec523..4340986 100644 +--- a/drivers/input/misc/Kconfig ++++ b/drivers/input/misc/Kconfig +@@ -149,6 +149,19 @@ config INPUT_KEYSPAN_REMOTE + To compile this driver as a module, choose M here: the module will + be called keyspan_remote. + ++config INPUT_APPLEIR ++ tristate "Apple infrared receiver (built in)" ++ depends on USB_ARCH_HAS_HCD ++ select USB ++ help ++ Say Y here if you want to use a Apple infrared remote control. All ++ the Apple computers from 2005 onwards include such a port, except ++ the unibody Macbook (2009), and Mac Pros. This receiver is also ++ used in the Apple TV set-top box. ++ ++ To compile this driver as a module, choose M here: the module will ++ be called appleir. ++ + config INPUT_POWERMATE + tristate "Griffin PowerMate and Contour Jog support" + depends on USB_ARCH_HAS_HCD +diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile +index a8b8485..041e6f5 100644 +--- a/drivers/input/misc/Makefile ++++ b/drivers/input/misc/Makefile +@@ -5,6 +5,7 @@ + # Each configuration option enables a list of files. + + obj-$(CONFIG_INPUT_APANEL) += apanel.o ++obj-$(CONFIG_INPUT_APPLEIR) += appleir.o + obj-$(CONFIG_INPUT_ATI_REMOTE) += ati_remote.o + obj-$(CONFIG_INPUT_ATI_REMOTE2) += ati_remote2.o + obj-$(CONFIG_INPUT_ATLAS_BTNS) += atlas_btns.o +diff --git a/drivers/input/misc/appleir.c b/drivers/input/misc/appleir.c +new file mode 100644 +index 0000000..cff4df6 +--- /dev/null ++++ b/drivers/input/misc/appleir.c +@@ -0,0 +1,453 @@ ++/* ++ * appleir: USB driver for the apple ir device ++ * ++ * Original driver written by James McKenzie ++ * Ported to recent 2.6 kernel versions by Greg Kroah-Hartman ++ * ++ * Copyright (C) 2006 James McKenzie ++ * Copyright (C) 2008 Greg Kroah-Hartman ++ * Copyright (C) 2008 Novell Inc. ++ * ++ * This program is free software; you can redistribute it and/or modify it ++ * under the terms of the GNU General Public License as published by the Free ++ * Software Foundation, version 2. ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define DRIVER_VERSION "v1.2" ++#define DRIVER_AUTHOR "James McKenzie" ++#define DRIVER_DESC "Apple infrared receiver driver" ++#define DRIVER_LICENSE "GPL" ++ ++MODULE_AUTHOR(DRIVER_AUTHOR); ++MODULE_DESCRIPTION(DRIVER_DESC); ++MODULE_LICENSE(DRIVER_LICENSE); ++ ++#define USB_VENDOR_ID_APPLE 0x05ac ++#define USB_DEVICE_ID_APPLE_IRCONTROL 0x8240 ++#define USB_DEVICE_ID_APPLE_ATV_IRCONTROL 0x8241 ++#define USB_DEVICE_ID_APPLE_IRCONTROL4 0x8242 ++ ++#define URB_SIZE 32 ++ ++#define MAX_KEYS 8 ++#define MAX_KEYS_MASK (MAX_KEYS - 1) ++ ++#define dbginfo(dev, format, arg...) do { if (debug) dev_info(dev , format , ## arg); } while (0) ++ ++static int debug; ++module_param(debug, int, 0644); ++MODULE_PARM_DESC(debug, "Enable extra debug messages and information"); ++ ++/* I have two devices both of which report the following */ ++/* 25 87 ee 83 0a + */ ++/* 25 87 ee 83 0c - */ ++/* 25 87 ee 83 09 << */ ++/* 25 87 ee 83 06 >> */ ++/* 25 87 ee 83 05 >" */ ++/* 25 87 ee 83 03 menu */ ++/* 26 00 00 00 00 for key repeat*/ ++ ++/* Thomas Glanzmann reports the following responses */ ++/* 25 87 ee ca 0b + */ ++/* 25 87 ee ca 0d - */ ++/* 25 87 ee ca 08 << */ ++/* 25 87 ee ca 07 >> */ ++/* 25 87 ee ca 04 >" */ ++/* 25 87 ee ca 02 menu */ ++/* 26 00 00 00 00 for key repeat*/ ++/* He also observes the following event sometimes */ ++/* sent after a key is release, which I interpret */ ++/* as a flat battery message */ ++/* 25 87 e0 ca 06 flat battery */ ++ ++/* Alexandre Karpenko reports the following responses for Device ID 0x8242 */ ++/* 25 87 ee 47 0b + */ ++/* 25 87 ee 47 0d - */ ++/* 25 87 ee 47 08 << */ ++/* 25 87 ee 47 07 >> */ ++/* 25 87 ee 47 04 >" */ ++/* 25 87 ee 47 02 menu */ ++/* 26 87 ee 47 ** for key repeat (** is the code of the key being held) */ ++ ++static const unsigned short appleir_key_table[] = { ++ KEY_RESERVED, ++ KEY_MENU, ++ KEY_PLAYPAUSE, ++ KEY_FORWARD, ++ KEY_BACK, ++ KEY_VOLUMEUP, ++ KEY_VOLUMEDOWN, ++ KEY_RESERVED, ++}; ++ ++struct appleir { ++ struct input_dev *input_dev; ++ unsigned short keymap[ARRAY_SIZE(appleir_key_table)]; ++ u8 *data; ++ dma_addr_t dma_buf; ++ struct usb_device *usbdev; ++ unsigned int flags; ++ struct urb *urb; ++ struct timer_list key_up_timer; ++ int current_key; ++ char phys[32]; ++}; ++ ++static DEFINE_MUTEX(appleir_mutex); ++ ++enum { ++ APPLEIR_OPENED = 0x1, ++ APPLEIR_SUSPENDED = 0x2, ++}; ++ ++static struct usb_device_id appleir_ids[] = { ++ { USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL) }, ++ { USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_ATV_IRCONTROL) }, ++ { USB_DEVICE(USB_VENDOR_ID_APPLE, USB_DEVICE_ID_APPLE_IRCONTROL4) }, ++ {} ++}; ++MODULE_DEVICE_TABLE(usb, appleir_ids); ++ ++static void dump_packet(struct appleir *appleir, char *msg, u8 *data, int len) ++{ ++ int i; ++ ++ printk(KERN_ERR "appleir: %s (%d bytes)", msg, len); ++ ++ for (i = 0; i < len; ++i) ++ printk(" %02x", data[i]); ++ printk("\n"); ++} ++ ++static void key_up(struct appleir *appleir, int key) ++{ ++ dbginfo(&appleir->input_dev->dev, "key %d up\n", key); ++ input_report_key(appleir->input_dev, key, 0); ++ input_sync(appleir->input_dev); ++} ++ ++static void key_down(struct appleir *appleir, int key) ++{ ++ dbginfo(&appleir->input_dev->dev, "key %d down\n", key); ++ input_report_key(appleir->input_dev, key, 1); ++ input_sync(appleir->input_dev); ++} ++ ++static void battery_flat(struct appleir *appleir) ++{ ++ dev_err(&appleir->input_dev->dev, "possible flat battery?\n"); ++} ++ ++static void key_up_tick(unsigned long data) ++{ ++ struct appleir *appleir = (struct appleir *)data; ++ ++ if (appleir->current_key) { ++ key_up(appleir, appleir->current_key); ++ appleir->current_key = 0; ++ } ++} ++ ++static void new_data(struct appleir *appleir, u8 *data, int len) ++{ ++ static const u8 keydown[] = { 0x25, 0x87, 0xee }; ++ static const u8 keyrepeat[] = { 0x26, }; ++ static const u8 flatbattery[] = { 0x25, 0x87, 0xe0 }; ++ ++ if (debug) ++ dump_packet(appleir, "received", data, len); ++ ++ if (len != 5) ++ return; ++ ++ if (!memcmp(data, keydown, sizeof(keydown))) { ++ /* If we already have a key down, take it up before marking ++ this one down */ ++ if (appleir->current_key) ++ key_up(appleir, appleir->current_key); ++ appleir->current_key = appleir->keymap[(data[4] >> 1) & MAX_KEYS_MASK]; ++ ++ key_down(appleir, appleir->current_key); ++ /* Remote doesn't do key up, either pull them up, in the test ++ above, or here set a timer which pulls them up after 1/8 s */ ++ mod_timer(&appleir->key_up_timer, jiffies + HZ / 8); ++ ++ return; ++ } ++ ++ if (!memcmp(data, keyrepeat, sizeof(keyrepeat))) { ++ key_down(appleir, appleir->current_key); ++ /* Remote doesn't do key up, either pull them up, in the test ++ above, or here set a timer which pulls them up after 1/8 s */ ++ mod_timer(&appleir->key_up_timer, jiffies + HZ / 8); ++ return; ++ } ++ ++ if (!memcmp(data, flatbattery, sizeof(flatbattery))) { ++ battery_flat(appleir); ++ /* Fall through */ ++ } ++ ++ dump_packet(appleir, "unknown packet", data, len); ++} ++ ++static void appleir_urb(struct urb *urb) ++{ ++ struct appleir *appleir = urb->context; ++ int status = urb->status; ++ int retval; ++ ++ switch (status) { ++ case 0: ++ new_data(appleir, urb->transfer_buffer, urb->actual_length); ++ break; ++ case -ECONNRESET: ++ case -ENOENT: ++ case -ESHUTDOWN: ++ /* This urb is terminated, clean up */ ++ dbginfo(&appleir->input_dev->dev, "%s - urb shutting down with status: %d", __func__, ++ urb->status); ++ return; ++ default: ++ dbginfo(&appleir->input_dev->dev, "%s - nonzero urb status received: %d", __func__, ++ urb->status); ++ } ++ ++ retval = usb_submit_urb(urb, GFP_ATOMIC); ++ if (retval) ++ err("%s - usb_submit_urb failed with result %d", __func__, ++ retval); ++} ++ ++static int appleir_open(struct input_dev *dev) ++{ ++ struct appleir *appleir = input_get_drvdata(dev); ++ struct usb_interface *intf = usb_ifnum_to_if(appleir->usbdev, 0); ++ int r; ++ ++ r = usb_autopm_get_interface(intf); ++ if (r) { ++ dev_err(&intf->dev, ++ "%s(): usb_autopm_get_interface() = %d\n", __func__, r); ++ return r; ++ } ++ ++ mutex_lock(&appleir_mutex); ++ ++ if (usb_submit_urb(appleir->urb, GFP_ATOMIC)) { ++ r = -EIO; ++ goto fail; ++ } ++ ++ appleir->flags |= APPLEIR_OPENED; ++ ++ mutex_unlock(&appleir_mutex); ++ ++ usb_autopm_put_interface(intf); ++ ++ return 0; ++fail: ++ mutex_unlock(&appleir_mutex); ++ usb_autopm_put_interface(intf); ++ return r; ++} ++ ++static void appleir_close(struct input_dev *dev) ++{ ++ struct appleir *appleir = input_get_drvdata(dev); ++ ++ mutex_lock(&appleir_mutex); ++ ++ if (!(appleir->flags & APPLEIR_SUSPENDED)) { ++ usb_kill_urb(appleir->urb); ++ del_timer_sync(&appleir->key_up_timer); ++ } ++ ++ appleir->flags &= ~APPLEIR_OPENED; ++ ++ mutex_unlock(&appleir_mutex); ++} ++ ++static int appleir_probe(struct usb_interface *intf, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *dev = interface_to_usbdev(intf); ++ struct usb_endpoint_descriptor *endpoint; ++ struct appleir *appleir = NULL; ++ struct input_dev *input_dev; ++ int retval = -ENOMEM; ++ int i; ++ ++ appleir = kzalloc(sizeof(struct appleir), GFP_KERNEL); ++ if (!appleir) ++ goto allocfail; ++ ++ appleir->data = usb_buffer_alloc(dev, URB_SIZE, GFP_KERNEL, ++ &appleir->dma_buf); ++ if (!appleir->data) ++ goto usbfail; ++ ++ appleir->urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!appleir->urb) ++ goto urbfail; ++ ++ appleir->usbdev = dev; ++ ++ input_dev = input_allocate_device(); ++ if (!input_dev) ++ goto inputfail; ++ ++ appleir->input_dev = input_dev; ++ ++ usb_make_path(dev, appleir->phys, sizeof(appleir->phys)); ++ strlcpy(appleir->phys, "/input0", sizeof(appleir->phys)); ++ ++ input_dev->name = "Apple Infrared Remote Controller"; ++ input_dev->phys = appleir->phys; ++ usb_to_input_id(dev, &input_dev->id); ++ input_dev->dev.parent = &intf->dev; ++ input_dev->keycode = appleir->keymap; ++ input_dev->keycodesize = sizeof(unsigned short); ++ input_dev->keycodemax = ARRAY_SIZE(appleir->keymap); ++ ++ input_dev->evbit[0] = BIT(EV_KEY) | BIT(EV_REP); ++ ++ memcpy(appleir->keymap, appleir_key_table, sizeof(appleir->keymap)); ++ for (i = 0; i < ARRAY_SIZE(appleir_key_table); i++) ++ set_bit(appleir->keymap[i], input_dev->keybit); ++ clear_bit(KEY_RESERVED, input_dev->keybit); ++ ++ input_set_drvdata(input_dev, appleir); ++ input_dev->open = appleir_open; ++ input_dev->close = appleir_close; ++ ++ endpoint = &intf->cur_altsetting->endpoint[0].desc; ++ ++ usb_fill_int_urb(appleir->urb, dev, ++ usb_rcvintpipe(dev, endpoint->bEndpointAddress), ++ appleir->data, 8, ++ appleir_urb, appleir, endpoint->bInterval); ++ ++ appleir->urb->transfer_dma = appleir->dma_buf; ++ appleir->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; ++ ++ setup_timer(&appleir->key_up_timer, ++ key_up_tick, (unsigned long) appleir); ++ ++ retval = input_register_device(appleir->input_dev); ++ if (retval) ++ goto inputfail; ++ ++ usb_set_intfdata(intf, appleir); ++ ++ return 0; ++ ++inputfail: ++ input_free_device(appleir->input_dev); ++ ++urbfail: ++ usb_free_urb(appleir->urb); ++ ++usbfail: ++ usb_buffer_free(dev, URB_SIZE, appleir->data, ++ appleir->dma_buf); ++ ++allocfail: ++ kfree(appleir); ++ ++ return retval; ++} ++ ++static void appleir_disconnect(struct usb_interface *intf) ++{ ++ struct appleir *appleir = usb_get_intfdata(intf); ++ ++ usb_set_intfdata(intf, NULL); ++ input_unregister_device(appleir->input_dev); ++ usb_free_urb(appleir->urb); ++ usb_buffer_free(interface_to_usbdev(intf), URB_SIZE, ++ appleir->data, appleir->dma_buf); ++ kfree(appleir); ++} ++ ++static int appleir_suspend(struct usb_interface *interface, ++ pm_message_t message) ++{ ++ struct appleir *appleir = usb_get_intfdata(interface); ++ ++ mutex_lock(&appleir_mutex); ++ if (appleir->flags & APPLEIR_OPENED) ++ usb_kill_urb(appleir->urb); ++ ++ appleir->flags |= APPLEIR_SUSPENDED; ++ ++ mutex_unlock(&appleir_mutex); ++ ++ return 0; ++} ++ ++static int appleir_resume(struct usb_interface *interface) ++{ ++ struct appleir *appleir; ++ int r = 0; ++ ++ appleir = usb_get_intfdata(interface); ++ ++ mutex_lock(&appleir_mutex); ++ if (appleir->flags & APPLEIR_OPENED) { ++ struct usb_endpoint_descriptor *endpoint; ++ ++ endpoint = &interface->cur_altsetting->endpoint[0].desc; ++ usb_fill_int_urb(appleir->urb, appleir->usbdev, ++ usb_rcvintpipe(appleir->usbdev, endpoint->bEndpointAddress), ++ appleir->data, 8, ++ appleir_urb, appleir, endpoint->bInterval); ++ appleir->urb->transfer_dma = appleir->dma_buf; ++ appleir->urb->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; ++ ++ /* And reset the USB device */ ++ if (usb_submit_urb(appleir->urb, GFP_ATOMIC)) ++ r = -EIO; ++ } ++ ++ appleir->flags &= ~APPLEIR_SUSPENDED; ++ ++ mutex_unlock(&appleir_mutex); ++ ++ return r; ++} ++ ++static struct usb_driver appleir_driver = { ++ .name = "appleir", ++ .probe = appleir_probe, ++ .disconnect = appleir_disconnect, ++ .suspend = appleir_suspend, ++ .resume = appleir_resume, ++ .reset_resume = appleir_resume, ++ .id_table = appleir_ids, ++}; ++ ++static int __init appleir_init(void) ++{ ++ return usb_register(&appleir_driver); ++} ++ ++static void __exit appleir_exit(void) ++{ ++ usb_deregister(&appleir_driver); ++} ++ ++module_init(appleir_init); ++module_exit(appleir_exit); +diff --git a/include/linux/hid.h b/include/linux/hid.h +index 8709365..662596b 100644 +--- a/include/linux/hid.h ++++ b/include/linux/hid.h +@@ -308,11 +308,13 @@ struct hid_item { + #define HID_QUIRK_NOTOUCH 0x00000002 + #define HID_QUIRK_IGNORE 0x00000004 + #define HID_QUIRK_NOGET 0x00000008 ++#define HID_QUIRK_HIDDEV_FORCE 0x00000010 + #define HID_QUIRK_BADPAD 0x00000020 + #define HID_QUIRK_MULTI_INPUT 0x00000040 + #define HID_QUIRK_SKIP_OUTPUT_REPORTS 0x00010000 + #define HID_QUIRK_FULLSPEED_INTERVAL 0x10000000 + #define HID_QUIRK_NO_INIT_REPORTS 0x20000000 ++#define HID_QUIRK_NO_IGNORE 0x40000000 + + /* + * This is the global environment of the parser. This information is diff --git a/alsa-usbmixer-add-possibility-to-remap-dB-values.patch b/alsa-usbmixer-add-possibility-to-remap-dB-values.patch new file mode 100644 index 000000000..b2729bbe2 --- /dev/null +++ b/alsa-usbmixer-add-possibility-to-remap-dB-values.patch @@ -0,0 +1,348 @@ +From 82ff9c3b767ec5bfaed3d99c9ed1160e44cbfd53 Mon Sep 17 00:00:00 2001 +From: Jaroslav Kysela +Date: Thu, 11 Feb 2010 17:50:44 +0100 +Subject: ALSA: usbmixer - add possibility to remap dB values + +USB devices tends to represent dB ranges in different way than ALSA expects. +Add possibility to override these values and add guessed values for +SoundBlaster MP3+. + +Also rename 'Capture Input Source' control to 'Capture Source' for +SoundBlaster MP3+ and Extigy. + +Signed-off-by: Jaroslav Kysela +--- + sound/usb/usbmixer.c | 125 +++++++++++++++++++++++++++------------------ + sound/usb/usbmixer_maps.c | 23 ++++++-- + 2 files changed, 93 insertions(+), 55 deletions(-) + +diff --git a/sound/usb/usbmixer.c b/sound/usb/usbmixer.c +index c998220..c72ad0c 100644 +--- a/sound/usb/usbmixer.c ++++ b/sound/usb/usbmixer.c +@@ -123,6 +123,7 @@ struct usb_mixer_elem_info { + int channels; + int val_type; + int min, max, res; ++ int dBmin, dBmax; + int cached; + int cache_val[MAX_CHANNELS]; + u8 initialized; +@@ -194,42 +195,50 @@ enum { + */ + #include "usbmixer_maps.c" + +-/* get the mapped name if the unit matches */ +-static int check_mapped_name(struct mixer_build *state, int unitid, int control, char *buf, int buflen) ++static const struct usbmix_name_map * ++find_map(struct mixer_build *state, int unitid, int control) + { +- const struct usbmix_name_map *p; ++ const struct usbmix_name_map *p = state->map; + +- if (! state->map) +- return 0; ++ if (!p) ++ return NULL; + + for (p = state->map; p->id; p++) { +- if (p->id == unitid && p->name && +- (! control || ! p->control || control == p->control)) { +- buflen--; +- return strlcpy(buf, p->name, buflen); +- } ++ if (p->id == unitid && ++ (!control || !p->control || control == p->control)) ++ return p; + } +- return 0; ++ return NULL; + } + +-/* check whether the control should be ignored */ +-static int check_ignored_ctl(struct mixer_build *state, int unitid, int control) ++/* get the mapped name if the unit matches */ ++static int ++check_mapped_name(const struct usbmix_name_map *p, char *buf, int buflen) + { +- const struct usbmix_name_map *p; ++ if (!p || !p->name) ++ return 0; + +- if (! state->map) ++ buflen--; ++ return strlcpy(buf, p->name, buflen); ++} ++ ++/* check whether the control should be ignored */ ++static inline int ++check_ignored_ctl(const struct usbmix_name_map *p) ++{ ++ if (!p || p->name || p->dB) + return 0; +- for (p = state->map; p->id; p++) { +- if (p->id == unitid && ! p->name && +- (! control || ! p->control || control == p->control)) { +- /* +- printk(KERN_DEBUG "ignored control %d:%d\n", +- unitid, control); +- */ +- return 1; +- } ++ return 1; ++} ++ ++/* dB mapping */ ++static inline void check_mapped_dB(const struct usbmix_name_map *p, ++ struct usb_mixer_elem_info *cval) ++{ ++ if (p && p->dB) { ++ cval->dBmin = p->dB->min; ++ cval->dBmax = p->dB->max; + } +- return 0; + } + + /* get the mapped selector source name */ +@@ -466,20 +475,8 @@ static int mixer_vol_tlv(struct snd_kcontrol *kcontrol, int op_flag, + + if (size < sizeof(scale)) + return -ENOMEM; +- /* USB descriptions contain the dB scale in 1/256 dB unit +- * while ALSA TLV contains in 1/100 dB unit +- */ +- scale[2] = (convert_signed_value(cval, cval->min) * 100) / 256; +- scale[3] = (convert_signed_value(cval, cval->max) * 100) / 256; +- if (scale[3] <= scale[2]) { +- /* something is wrong; assume it's either from/to 0dB */ +- if (scale[2] < 0) +- scale[3] = 0; +- else if (scale[2] > 0) +- scale[2] = 0; +- else /* totally crap, return an error */ +- return -EINVAL; +- } ++ scale[2] = cval->dBmin; ++ scale[3] = cval->dBmax; + if (copy_to_user(_tlv, scale, sizeof(scale))) + return -EFAULT; + return 0; +@@ -720,6 +717,7 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) + cval->min = default_min; + cval->max = cval->min + 1; + cval->res = 1; ++ cval->dBmin = cval->dBmax = 0; + + if (cval->val_type == USB_MIXER_BOOLEAN || + cval->val_type == USB_MIXER_INV_BOOLEAN) { +@@ -787,6 +785,24 @@ static int get_min_max(struct usb_mixer_elem_info *cval, int default_min) + + cval->initialized = 1; + } ++ ++ /* USB descriptions contain the dB scale in 1/256 dB unit ++ * while ALSA TLV contains in 1/100 dB unit ++ */ ++ cval->dBmin = (convert_signed_value(cval, cval->min) * 100) / 256; ++ cval->dBmax = (convert_signed_value(cval, cval->max) * 100) / 256; ++ if (cval->dBmin > cval->dBmax) { ++ /* something is wrong; assume it's either from/to 0dB */ ++ if (cval->dBmin < 0) ++ cval->dBmax = 0; ++ else if (cval->dBmin > 0) ++ cval->dBmin = 0; ++ if (cval->dBmin > cval->dBmax) { ++ /* totally crap, return an error */ ++ return -EINVAL; ++ } ++ } ++ + return 0; + } + +@@ -912,6 +928,7 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, + int nameid = desc[desc[0] - 1]; + struct snd_kcontrol *kctl; + struct usb_mixer_elem_info *cval; ++ const struct usbmix_name_map *map; + + control++; /* change from zero-based to 1-based value */ + +@@ -920,7 +937,8 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, + return; + } + +- if (check_ignored_ctl(state, unitid, control)) ++ map = find_map(state, unitid, control); ++ if (check_ignored_ctl(map)) + return; + + cval = kzalloc(sizeof(*cval), GFP_KERNEL); +@@ -954,10 +972,11 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, + } + kctl->private_free = usb_mixer_elem_free; + +- len = check_mapped_name(state, unitid, control, kctl->id.name, sizeof(kctl->id.name)); ++ len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); + mapped_name = len != 0; + if (! len && nameid) +- len = snd_usb_copy_string_desc(state, nameid, kctl->id.name, sizeof(kctl->id.name)); ++ len = snd_usb_copy_string_desc(state, nameid, ++ kctl->id.name, sizeof(kctl->id.name)); + + switch (control) { + case USB_FEATURE_MUTE: +@@ -995,6 +1014,7 @@ static void build_feature_ctl(struct mixer_build *state, unsigned char *desc, + kctl->vd[0].access |= + SNDRV_CTL_ELEM_ACCESS_TLV_READ | + SNDRV_CTL_ELEM_ACCESS_TLV_CALLBACK; ++ check_mapped_dB(map, cval); + } + break; + +@@ -1122,8 +1142,10 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc, + unsigned int num_outs = desc[5 + input_pins]; + unsigned int i, len; + struct snd_kcontrol *kctl; ++ const struct usbmix_name_map *map; + +- if (check_ignored_ctl(state, unitid, 0)) ++ map = find_map(state, unitid, 0); ++ if (check_ignored_ctl(map)) + return; + + cval = kzalloc(sizeof(*cval), GFP_KERNEL); +@@ -1152,7 +1174,7 @@ static void build_mixer_unit_ctl(struct mixer_build *state, unsigned char *desc, + } + kctl->private_free = usb_mixer_elem_free; + +- len = check_mapped_name(state, unitid, 0, kctl->id.name, sizeof(kctl->id.name)); ++ len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); + if (! len) + len = get_term_name(state, iterm, kctl->id.name, sizeof(kctl->id.name), 0); + if (! len) +@@ -1342,6 +1364,7 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned + int i, err, nameid, type, len; + struct procunit_info *info; + struct procunit_value_info *valinfo; ++ const struct usbmix_name_map *map; + static struct procunit_value_info default_value_info[] = { + { 0x01, "Switch", USB_MIXER_BOOLEAN }, + { 0 } +@@ -1371,7 +1394,8 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned + /* FIXME: bitmap might be longer than 8bit */ + if (! (dsc[12 + num_ins] & (1 << (valinfo->control - 1)))) + continue; +- if (check_ignored_ctl(state, unitid, valinfo->control)) ++ map = find_map(state, unitid, valinfo->control); ++ if (check_ignored_ctl(map)) + continue; + cval = kzalloc(sizeof(*cval), GFP_KERNEL); + if (! cval) { +@@ -1402,8 +1426,9 @@ static int build_audio_procunit(struct mixer_build *state, int unitid, unsigned + } + kctl->private_free = usb_mixer_elem_free; + +- if (check_mapped_name(state, unitid, cval->control, kctl->id.name, sizeof(kctl->id.name))) +- ; ++ if (check_mapped_name(map, kctl->id.name, ++ sizeof(kctl->id.name))) ++ /* nothing */ ; + else if (info->name) + strlcpy(kctl->id.name, info->name, sizeof(kctl->id.name)); + else { +@@ -1542,6 +1567,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi + int err; + struct usb_mixer_elem_info *cval; + struct snd_kcontrol *kctl; ++ const struct usbmix_name_map *map; + char **namelist; + + if (! num_ins || desc[0] < 5 + num_ins) { +@@ -1557,7 +1583,8 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi + if (num_ins == 1) /* only one ? nonsense! */ + return 0; + +- if (check_ignored_ctl(state, unitid, 0)) ++ map = find_map(state, unitid, 0); ++ if (check_ignored_ctl(map)) + return 0; + + cval = kzalloc(sizeof(*cval), GFP_KERNEL); +@@ -1612,7 +1639,7 @@ static int parse_audio_selector_unit(struct mixer_build *state, int unitid, unsi + kctl->private_free = usb_mixer_selector_elem_free; + + nameid = desc[desc[0] - 1]; +- len = check_mapped_name(state, unitid, 0, kctl->id.name, sizeof(kctl->id.name)); ++ len = check_mapped_name(map, kctl->id.name, sizeof(kctl->id.name)); + if (len) + ; + else if (nameid) +diff --git a/sound/usb/usbmixer_maps.c b/sound/usb/usbmixer_maps.c +index 77c3588..79e903a 100644 +--- a/sound/usb/usbmixer_maps.c ++++ b/sound/usb/usbmixer_maps.c +@@ -19,11 +19,16 @@ + * + */ + ++struct usbmix_dB_map { ++ u32 min; ++ u32 max; ++}; + + struct usbmix_name_map { + int id; + const char *name; + int control; ++ struct usbmix_dB_map *dB; + }; + + struct usbmix_selector_map { +@@ -72,7 +77,7 @@ static struct usbmix_name_map extigy_map[] = { + { 8, "Line Playback" }, /* FU */ + /* 9: IT mic */ + { 10, "Mic Playback" }, /* FU */ +- { 11, "Capture Input Source" }, /* SU */ ++ { 11, "Capture Source" }, /* SU */ + { 12, "Capture" }, /* FU */ + /* 13: OT pcm capture */ + /* 14: MU (w/o controls) */ +@@ -102,6 +107,9 @@ static struct usbmix_name_map extigy_map[] = { + * e.g. no Master and fake PCM volume + * Pavel Mihaylov + */ ++static struct usbmix_dB_map mp3plus_dB_1 = {-4781, 0}; /* just guess */ ++static struct usbmix_dB_map mp3plus_dB_2 = {-1781, 618}; /* just guess */ ++ + static struct usbmix_name_map mp3plus_map[] = { + /* 1: IT pcm */ + /* 2: IT mic */ +@@ -110,16 +118,19 @@ static struct usbmix_name_map mp3plus_map[] = { + /* 5: OT digital out */ + /* 6: OT speaker */ + /* 7: OT pcm capture */ +- { 8, "Capture Input Source" }, /* FU, default PCM Capture Source */ ++ { 8, "Capture Source" }, /* FU, default PCM Capture Source */ + /* (Mic, Input 1 = Line input, Input 2 = Optical input) */ + { 9, "Master Playback" }, /* FU, default Speaker 1 */ + /* { 10, "Mic Capture", 1 }, */ /* FU, Mic Capture */ +- /* { 10, "Mic Capture", 2 }, */ /* FU, Mic Capture */ ++ { 10, /* "Mic Capture", */ NULL, 2, .dB = &mp3plus_dB_2 }, ++ /* FU, Mic Capture */ + { 10, "Mic Boost", 7 }, /* FU, default Auto Gain Input */ +- { 11, "Line Capture" }, /* FU, default PCM Capture */ ++ { 11, "Line Capture", .dB = &mp3plus_dB_2 }, ++ /* FU, default PCM Capture */ + { 12, "Digital In Playback" }, /* FU, default PCM 1 */ +- /* { 13, "Mic Playback" }, */ /* FU, default Mic Playback */ +- { 14, "Line Playback" }, /* FU, default Speaker */ ++ { 13, /* "Mic Playback", */ .dB = &mp3plus_dB_1 }, ++ /* FU, default Mic Playback */ ++ { 14, "Line Playback", .dB = &mp3plus_dB_1 }, /* FU, default Speaker */ + /* 15: MU */ + { 0 } /* terminator */ + }; +-- +1.7.0.1 + diff --git a/btrfs-prohibit-a-operation-of-changing-acls-mask-when-noacl-mount-option-is-used.patch b/btrfs-prohibit-a-operation-of-changing-acls-mask-when-noacl-mount-option-is-used.patch new file mode 100644 index 000000000..89b67a762 --- /dev/null +++ b/btrfs-prohibit-a-operation-of-changing-acls-mask-when-noacl-mount-option-is-used.patch @@ -0,0 +1,42 @@ +From: Shi Weihua +Date: Tue, 18 May 2010 00:51:54 +0000 (+0000) +Subject: Btrfs: prohibit a operation of changing acl's mask when noacl mount option used +X-Git-Tag: v2.6.35-rc3~3^2~3 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=731e3d1b + +Btrfs: prohibit a operation of changing acl's mask when noacl mount option used + +when used Posix File System Test Suite(pjd-fstest) to test btrfs, +some cases about setfacl failed when noacl mount option used. +I simplified used commands in pjd-fstest, and the following steps +can reproduce it. +------------------------ +# cd btrfs-part/ +# mkdir aaa +# setfacl -m m::rw aaa <- successed, but not expected by pjd-fstest. +------------------------ +I checked ext3, a warning message occured, like as: + setfacl: aaa/: Operation not supported +Certainly, it's expected by pjd-fstest. + +So, i compared acl.c of btrfs and ext3. Based on that, a patch created. +Fortunately, it works. + +Signed-off-by: Shi Weihua +Signed-off-by: Chris Mason +--- + +diff --git a/fs/btrfs/acl.c b/fs/btrfs/acl.c +index 6b4d0cc..a372985 100644 +--- a/fs/btrfs/acl.c ++++ b/fs/btrfs/acl.c +@@ -163,6 +163,9 @@ static int btrfs_xattr_acl_set(struct dentry *dentry, const char *name, + if (!is_owner_or_cap(dentry->d_inode)) + return -EPERM; + ++ if (!IS_POSIXACL(dentry->d_inode)) ++ return -EOPNOTSUPP; ++ + if (value) { + acl = posix_acl_from_xattr(value, size); + if (acl == NULL) { diff --git a/config-arm b/config-arm new file mode 100644 index 000000000..923ebc3a8 --- /dev/null +++ b/config-arm @@ -0,0 +1,107 @@ +CONFIG_ARM=y +CONFIG_SYS_SUPPORTS_APM_EMULATION=y +# CONFIG_SMP is not set + +CONFIG_CC_OPTIMIZE_FOR_SIZE=y + +CONFIG_ARCH_VERSATILE=y +CONFIG_ARCH_VERSATILE_PB=y +CONFIG_MACH_VERSATILE_AB=y + +CONFIG_HIGHMEM=y +# CONFIG_HIGHPTE is not set + +# CONFIG_CPU_ICACHE_DISABLE is not set +# CONFIG_CPU_DCACHE_DISABLE is not set +# CONFIG_CPU_DCACHE_WRITETHROUGH is not set +# CONFIG_CPU_CACHE_ROUND_ROBIN is not set + +CONFIG_ZBOOT_ROM_TEXT=0 +CONFIG_ZBOOT_ROM_BSS=0 + +# CONFIG_XIP_KERNEL is not set + +CONFIG_ATAGS_PROC=y + +# CONFIG_FPE_NWFPE is not set +CONFIG_FPE_FASTFPE=y +CONFIG_VFP=y + +CONFIG_PM=y +# CONFIG_PM_DEBUG is not set +# CONFIG_PM_TRACE is not set +CONFIG_SUSPEND=y +# CONFIG_PM_TEST_SUSPEND is not set +CONFIG_APM_EMULATION=y + +CONFIG_ARM_THUMB=y + +CONFIG_AEABI=y +CONFIG_OABI_COMPAT=y + +# CONFIG_UACCESS_WITH_MEMCPY is not set + +CONFIG_CMDLINE="console=ttyAM0,115200 root=/dev/sda1 rootdelay=20" + +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y + +# CONFIG_CPU_IDLE is not set + +CONFIG_LEDS=y +CONFIG_LEDS_CPU=y + +CONFIG_MTD_AFS_PARTS=y +CONFIG_MTD_ARM_INTEGRATOR=y +CONFIG_MTD_IMPA7=y + +CONFIG_AX88796=m +CONFIG_AX88796_93CX6=y +CONFIG_SMC91X=m +CONFIG_DM9000=m +CONFIG_DM9000_DEBUGLEVEL=4 +# CONFIG_DM9000_FORCE_SIMPLE_PHY_POLL is not set +CONFIG_SMC911X=m +CONFIG_SMSC911X=m + +CONFIG_SERIO_AMBAKMI=m + +CONFIG_SERIAL_AMBA_PL011=y +CONFIG_SERIAL_AMBA_PL011_CONSOLE=y + +CONFIG_I2C_VERSATILE=y + +CONFIG_THERMAL=y + +# CONFIG_MFD_T7L66XB is not set +# CONFIG_MFD_TC6387XB is not set + +CONFIG_FB_ARMCLCD=m + +CONFIG_SND_ARM=y +CONFIG_SND_ARMAACI=m + +CONFIG_USB_MUSB_HDRC=m +# CONFIG_MUSB_PIO_ONLY is not set +CONFIG_USB_TUSB6010=y +# CONFIG_USB_MUSB_DEBUG is not set + +CONFIG_MMC_ARMMMCI=m + +CONFIG_RTC_DRV_PL030=m +CONFIG_RTC_DRV_PL031=m + +# CONFIG_SGI_IOC4 is not set + +# CONFIG_DEBUG_USER is not set +# CONFIG_DEBUG_ERRORS is not set +# CONFIG_DEBUG_LL is not set + +CONFIG_ARM_UNWIND=y + +CONFIG_RCU_FANOUT=32 + +# CONFIG_USB_ULPI is not set +# CONFIG_OC_ETM is not set + +# CONFIG_MTD_PISMO is not set diff --git a/config-debug b/config-debug new file mode 100644 index 000000000..1e51d4698 --- /dev/null +++ b/config-debug @@ -0,0 +1,78 @@ +CONFIG_SND_VERBOSE_PRINTK=y +CONFIG_SND_DEBUG=y +CONFIG_SND_PCM_XRUN_DEBUG=y + +CONFIG_DEBUG_MUTEXES=y +CONFIG_DEBUG_RT_MUTEXES=y +CONFIG_DEBUG_LOCK_ALLOC=y +CONFIG_PROVE_LOCKING=y +CONFIG_DEBUG_VM=y +CONFIG_DEBUG_SPINLOCK=y + +CONFIG_FAULT_INJECTION=y +CONFIG_FAILSLAB=y +CONFIG_FAIL_PAGE_ALLOC=y +CONFIG_FAIL_MAKE_REQUEST=y +CONFIG_FAULT_INJECTION_DEBUG_FS=y +CONFIG_FAULT_INJECTION_STACKTRACE_FILTER=y +CONFIG_FAIL_IO_TIMEOUT=y + +CONFIG_SLUB_DEBUG_ON=y + +CONFIG_LOCK_STAT=y + +CONFIG_DEBUG_STACK_USAGE=y + +CONFIG_ACPI_DEBUG=y +# CONFIG_ACPI_DEBUG_FUNC_TRACE is not set + +CONFIG_DEBUG_SG=y + +# CONFIG_DEBUG_PAGEALLOC is not set + +CONFIG_DEBUG_WRITECOUNT=y +CONFIG_DEBUG_OBJECTS=y +# CONFIG_DEBUG_OBJECTS_SELFTEST is not set +CONFIG_DEBUG_OBJECTS_FREE=y +CONFIG_DEBUG_OBJECTS_TIMERS=y +CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1 + +CONFIG_X86_PTDUMP=y + +CONFIG_CAN_DEBUG_DEVICES=y + +CONFIG_MODULE_FORCE_UNLOAD=y + +CONFIG_SYSCTL_SYSCALL_CHECK=y + +CONFIG_DEBUG_NOTIFIERS=y + +CONFIG_DMA_API_DEBUG=y + +CONFIG_MMIOTRACE=y + +CONFIG_DEBUG_CREDENTIALS=y + +CONFIG_EXT4_DEBUG=y + +CONFIG_DEBUG_PERF_USE_VMALLOC=y + +# off in both production debug and nodebug builds, +# on in rawhide nodebug builds +# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set + +CONFIG_JBD2_DEBUG=y + +CONFIG_FUNCTION_TRACER=y +CONFIG_STACK_TRACER=y +CONFIG_DYNAMIC_FTRACE=y + +CONFIG_DEBUG_CFQ_IOSCHED=y + +CONFIG_DRBD_FAULT_INJECTION=y + +CONFIG_ATH_DEBUG=y +CONFIG_IWLWIFI_DEVICE_TRACING=y + +CONFIG_DEBUG_OBJECTS_WORK=y +# CONFIG_DEBUG_STRICT_USER_COPY_CHECKS is not set diff --git a/config-generic b/config-generic new file mode 100644 index 000000000..2338defce --- /dev/null +++ b/config-generic @@ -0,0 +1,4316 @@ +# +# Automatically generated make config: don't edit +# +CONFIG_MMU=y +CONFIG_SMP=y +CONFIG_HOTPLUG_CPU=y +CONFIG_LOCALVERSION="" + +# +# Code maturity level options +# +CONFIG_EXPERIMENTAL=y +CONFIG_HOTPLUG=y +CONFIG_UEVENT_HELPER_PATH="" +CONFIG_DEVTMPFS=y +CONFIG_DEVTMPFS_MOUNT=y +CONFIG_STANDALONE=y +CONFIG_PREVENT_FIRMWARE_BUILD=y + +CONFIG_BUILD_DOCSRC=y + +# +# General setup +# +# CONFIG_LOCALVERSION_AUTO is not set +CONFIG_SWAP=y +CONFIG_SYSVIPC=y +CONFIG_BSD_PROCESS_ACCT=y +# CONFIG_BSD_PROCESS_ACCT_V3 is not set +CONFIG_TASKSTATS=y +CONFIG_TASK_DELAY_ACCT=y +CONFIG_TASK_XACCT=y +CONFIG_TASK_IO_ACCOUNTING=y +CONFIG_SYSCTL=y +CONFIG_LOG_BUF_SHIFT=17 +# CONFIG_IKCONFIG is not set +# CONFIG_EMBEDDED is not set +CONFIG_KALLSYMS=y +CONFIG_KALLSYMS_ALL=y +CONFIG_KALLSYMS_EXTRA_PASS=y +CONFIG_KALLSYMS_STRIP_GENERATED=y +CONFIG_FUTEX=y +CONFIG_EPOLL=y +CONFIG_IOSCHED_NOOP=y +CONFIG_IOSCHED_DEADLINE=y +CONFIG_IOSCHED_CFQ=y +CONFIG_CFQ_GROUP_IOSCHED=y +CONFIG_DEFAULT_CFQ=y +CONFIG_USER_NS=y +CONFIG_PID_NS=y +CONFIG_UTS_NS=y +CONFIG_IPC_NS=y +CONFIG_NET_NS=y + +CONFIG_POSIX_MQUEUE=y +# CONFIG_PREEMPT_NONE is not set +CONFIG_PREEMPT_VOLUNTARY=y +# CONFIG_PREEMPT is not set +CONFIG_PREEMPT_BKL=y + +CONFIG_SLUB=y +# CONFIG_SLUB_STATS is not set + +CONFIG_MISC_DEVICES=y +# CONFIG_AD525X_DPOT is not set +CONFIG_IWMC3200TOP=m +# CONFIG_IWMC3200TOP_DEBUG is not set +CONFIG_IWMC3200TOP_DEBUGFS=y + +# +# Loadable module support +# +CONFIG_MODULES=y +CONFIG_MODULE_UNLOAD=y +# CONFIG_MODULE_FORCE_LOAD is not set +# -- MODULE_FORCE_UNLOAD is controlled by config-debug/nodebug +# CONFIG_MODVERSIONS is not set +CONFIG_MODULE_SRCVERSION_ALL=y +CONFIG_KMOD=y + +# +# Bus options (PCI, PCMCIA, EISA, MCA, ISA) +# +CONFIG_PCI=y +# CONFIG_PCI_DEBUG is not set +CONFIG_PCI_STUB=y +CONFIG_PCI_IOV=y +CONFIG_HT_IRQ=y +CONFIG_PCI_MSI=y +CONFIG_PCI_MSI_DEFAULT_ON=y +CONFIG_PCIEPORTBUS=y +CONFIG_PCIEAER=y +CONFIG_PCIEASPM=y +# CONFIG_PCIEASPM_DEBUG is not set +CONFIG_PCIE_ECRC=y +CONFIG_PCIEAER_INJECT=m +CONFIG_HOTPLUG_PCI_PCIE=y +CONFIG_HOTPLUG_PCI_FAKE=m +CONFIG_PCI_LEGACY=y + +CONFIG_ISA=y +# CONFIG_EISA is not set +# CONFIG_MCA is not set +# CONFIG_SCx200 is not set + +# +# PCMCIA/CardBus support +# +CONFIG_PCMCIA=y +CONFIG_PCMCIA_LOAD_CIS=y +# CONFIG_PCMCIA_DEBUG is not set +CONFIG_YENTA=m +CONFIG_CARDBUS=y +CONFIG_I82092=m +CONFIG_PD6729=m +CONFIG_PCMCIA_IOCTL=y + +CONFIG_PCCARD=y +CONFIG_MMC=m +CONFIG_MMC_BLOCK_BOUNCE=y +CONFIG_SDIO_UART=m +# CONFIG_MMC_TEST is not set +# CONFIG_MMC_DEBUG is not set +# CONFIG_MMC_UNSAFE_RESUME is not set +CONFIG_MMC_BLOCK=m +CONFIG_MMC_RICOH_MMC=m +CONFIG_MMC_SDHCI=m +CONFIG_MMC_SDHCI_PCI=m +CONFIG_MMC_SDRICOH_CS=m +CONFIG_MMC_TIFM_SD=m +CONFIG_MMC_WBSD=m +CONFIG_MMC_VIA_SDMMC=m +CONFIG_MMC_SDHCI_PLTFM=m +CONFIG_MMC_CB710=m + +CONFIG_CB710_CORE=m +# CONFIG_CB710_DEBUG is not set + +CONFIG_INFINIBAND=m +CONFIG_INFINIBAND_MTHCA=m +# CONFIG_INFINIBAND_MTHCA_DEBUG is not set +CONFIG_INFINIBAND_IPOIB=m +CONFIG_INFINIBAND_IPOIB_DEBUG=y +CONFIG_INFINIBAND_IPOIB_DEBUG_DATA=y +CONFIG_INFINIBAND_IPOIB_CM=y +CONFIG_INFINIBAND_SRP=m +CONFIG_INFINIBAND_USER_MAD=m +CONFIG_INFINIBAND_USER_ACCESS=m +CONFIG_INFINIBAND_IPATH=m +CONFIG_INFINIBAND_ISER=m +CONFIG_INFINIBAND_AMSO1100=m +# CONFIG_INFINIBAND_AMSO1100_DEBUG is not set +CONFIG_INFINIBAND_CXGB3=m +# CONFIG_INFINIBAND_CXGB3_DEBUG is not set +CONFIG_MLX4_INFINIBAND=m +CONFIG_INFINIBAND_NES=m +# CONFIG_INFINIBAND_NES_DEBUG is not set + +# +# Executable file formats +# +CONFIG_BINFMT_ELF=y +CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y +# CONFIG_BINFMT_AOUT is not set +CONFIG_BINFMT_MISC=y + +# +# Device Drivers +# + +# +# Generic Driver Options +# +CONFIG_FW_LOADER=y +# CONFIG_FIRMWARE_IN_KERNEL is not set +CONFIG_EXTRA_FIRMWARE="" + +# CONFIG_SPI is not set + +# +# Memory Technology Devices (MTD) +# +CONFIG_MTD=m +# CONFIG_MTD_DEBUG is not set +CONFIG_MTD_PARTITIONS=y +CONFIG_MTD_AR7_PARTS=m +CONFIG_MTD_CONCAT=m +CONFIG_MTD_CMDLINE_PARTS=y +# +# User Modules And Translation Layers +# +CONFIG_MTD_CHAR=m +CONFIG_MTD_BLOCK=m +CONFIG_MTD_BLOCK_RO=m +CONFIG_MTD_BLOCK2MTD=m + +CONFIG_MTD_OOPS=m +# CONFIG_MTD_INTEL_VR_NOR is not set +CONFIG_MTD_ALAUDA=m + +CONFIG_FTL=m +CONFIG_NFTL=m +CONFIG_NFTL_RW=y +CONFIG_INFTL=m +CONFIG_RFD_FTL=m +CONFIG_SSFDC=m + +CONFIG_MTD_UBI=m +CONFIG_MTD_UBI_WL_THRESHOLD=4096 +CONFIG_MTD_UBI_BEB_RESERVE=1 +# CONFIG_MTD_UBI_GLUEBI is not set +# CONFIG_MTD_UBI_DEBUG is not set + +# +# RAM/ROM/Flash chip drivers +# +CONFIG_MTD_CFI=m +CONFIG_MTD_JEDECPROBE=m +CONFIG_MTD_GEN_PROBE=m +# CONFIG_MTD_CFI_ADV_OPTIONS is not set +CONFIG_MTD_CFI_INTELEXT=m +CONFIG_MTD_CFI_AMDSTD=m +CONFIG_MTD_CFI_STAA=m +CONFIG_MTD_RAM=m +CONFIG_MTD_ROM=m +CONFIG_MTD_ABSENT=m + +# +# Mapping drivers for chip access +# +CONFIG_MTD_COMPLEX_MAPPINGS=y +# CONFIG_MTD_PHYSMAP is not set +# CONFIG_MTD_PNC2000 is not set +CONFIG_MTD_SC520CDP=m +CONFIG_MTD_NETSC520=m +# CONFIG_MTD_SBC_GXX is not set +# CONFIG_MTD_SCx200_DOCFLASH is not set +# CONFIG_MTD_AMD76XROM is not set +CONFIG_MTD_SCB2_FLASH=m +# CONFIG_MTD_NETtel is not set +# CONFIG_MTD_DILNETPC is not set +# CONFIG_MTD_L440GX is not set +CONFIG_MTD_PCI=m +CONFIG_MTD_TS5500=m +# CONFIG_MTD_GPIO_ADDR is not set + +# +# Self-contained MTD device drivers +# +CONFIG_MTD_PMC551=m +# CONFIG_MTD_PMC551_BUGFIX is not set +# CONFIG_MTD_PMC551_DEBUG is not set +# CONFIG_MTD_SLRAM is not set +CONFIG_MTD_MTDRAM=m +CONFIG_MTDRAM_TOTAL_SIZE=4096 +CONFIG_MTDRAM_ERASE_SIZE=128 + +# +# Disk-On-Chip Device Drivers +# +# CONFIG_MTD_DOC2000 is not set +# CONFIG_MTD_DOC2001 is not set +# CONFIG_MTD_DOC2001PLUS is not set +# CONFIG_MTD_DOCPROBE is not set +# CONFIG_MTD_DOCPROBE_ADVANCED is not set +# CONFIG_MTD_DOCPROBE_ADDRESS is not set + +# +# NAND Flash Device Drivers +# +CONFIG_MTD_NAND=m +# CONFIG_MTD_NAND_MUSEUM_IDS is not set +# CONFIG_MTD_NAND_PLATFORM is not set +# CONFIG_MTD_NAND_VERIFY_WRITE is not set +# CONFIG_MTD_NAND_CAFE is not set +CONFIG_MTD_NAND_IDS=m +CONFIG_MTD_NAND_NANDSIM=m +# CONFIG_MTD_ONENAND is not set +CONFIG_MTD_NAND_ECC_SMC=y +CONFIG_MTD_NAND_CS553X=m + +CONFIG_MTD_REDBOOT_PARTS=m +# CONFIG_MTD_REDBOOT_PARTS_UNALLOCATED is not set +# CONFIG_MTD_REDBOOT_PARTS_READONLY is not set +CONFIG_MTD_REDBOOT_DIRECTORY_BLOCK=-1 +# CONFIG_MTD_XIP is not set +# CONFIG_MTD_ICHXROM is not set +# CONFIG_MTD_PHRAM is not set +CONFIG_MTD_NAND_DISKONCHIP=m +# CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADVANCED is not set +CONFIG_MTD_NAND_DISKONCHIP_PROBE_ADDRESS=0 +# CONFIG_MTD_NAND_DISKONCHIP_BBTWRITE is not set +# CONFIG_MTD_PLATRAM is not set + +# CONFIG_MTD_TESTS is not set +CONFIG_MTD_LPDDR=m +CONFIG_MTD_QINFO_PROBE=m + +# +# Parallel port support +# +CONFIG_PARPORT=m +CONFIG_PARPORT_PC=m +CONFIG_PARPORT_SERIAL=m +# CONFIG_PARPORT_PC_FIFO is not set +# CONFIG_PARPORT_PC_SUPERIO is not set +CONFIG_PARPORT_PC_PCMCIA=m +CONFIG_PARPORT_1284=y +# CONFIG_PARPORT_AX88796 is not set + +# +# Plug and Play support +# +CONFIG_PNP=y +# CONFIG_PNP_DEBUG is not set +# CONFIG_PNP_DEBUG_MESSAGES is not set + +# +# Protocols +# +CONFIG_ISAPNP=y +# CONFIG_PNPBIOS is not set + +CONFIG_ACPI_PCI_SLOT=y +CONFIG_HOTPLUG_PCI_ACPI=y +CONFIG_HOTPLUG_PCI_ACPI_IBM=m + +# +# Block devices +# +CONFIG_BLK_DEV=y +CONFIG_BLK_DEV_FD=m +# CONFIG_BLK_DEV_XD is not set +CONFIG_PARIDE=m +CONFIG_PARIDE_PD=m +CONFIG_PARIDE_PCD=m +CONFIG_PARIDE_PF=m +CONFIG_PARIDE_PT=m +CONFIG_PARIDE_PG=m +CONFIG_PARIDE_ATEN=m +CONFIG_PARIDE_BPCK=m +CONFIG_PARIDE_BPCK6=m +CONFIG_PARIDE_COMM=m +CONFIG_PARIDE_DSTR=m +CONFIG_PARIDE_FIT2=m +CONFIG_PARIDE_FIT3=m +CONFIG_PARIDE_EPAT=m +CONFIG_PARIDE_EPATC8=y +CONFIG_PARIDE_EPIA=m +CONFIG_PARIDE_FRIQ=m +CONFIG_PARIDE_FRPW=m +CONFIG_PARIDE_KBIC=m +CONFIG_PARIDE_KTTI=m +CONFIG_PARIDE_ON20=m +CONFIG_PARIDE_ON26=m +CONFIG_BLK_CPQ_DA=m +CONFIG_BLK_CPQ_CISS_DA=m +CONFIG_CISS_SCSI_TAPE=y +CONFIG_BLK_DEV_DAC960=m +CONFIG_BLK_DEV_UMEM=m +CONFIG_BLK_DEV_LOOP=y +CONFIG_BLK_DEV_CRYPTOLOOP=m +CONFIG_BLK_DEV_NBD=m +CONFIG_BLK_DEV_OSD=m +CONFIG_BLK_DEV_RAM=y +CONFIG_BLK_DEV_RAM_COUNT=16 +CONFIG_BLK_DEV_RAM_SIZE=16384 +CONFIG_BLK_DEV_RAM_BLOCKSIZE=4096 +CONFIG_BLK_DEV_INITRD=y +CONFIG_BLK_DEV_ATIIXP=y +CONFIG_LBD=y +CONFIG_BLK_DEV_IO_TRACE=y +CONFIG_LSF=y + +CONFIG_BLK_DEV_DELKIN=m +# CONFIG_BLK_DEV_IT8213 is not set +# CONFIG_BLK_DEV_TC86C001 is not set +CONFIG_LBDAF=y +CONFIG_BLK_DEV_BSG=y +CONFIG_BLK_DEV_INTEGRITY=y + + +# +# ATA/ATAPI/MFM/RLL support +# +# CONFIG_IDE is not set + +CONFIG_BLK_DEV_IDE=y + +# +# Please see Documentation/ide.txt for help/info on IDE drives +# +# CONFIG_BLK_DEV_HD_IDE is not set +CONFIG_BLK_DEV_IDEDISK=y +CONFIG_IDEDISK_MULTI_MODE=y +CONFIG_BLK_DEV_IDECS=m +CONFIG_BLK_DEV_IDECD=m +# CONFIG_BLK_DEV_IDETAPE is not set +CONFIG_BLK_DEV_IDEFLOPPY=y +CONFIG_IDE_TASK_IOCTL=y +# CONFIG_BLK_DEV_IDE_SATA is not set + +# +# IDE chipset support/bugfixes +# +CONFIG_BLK_DEV_CMD640=y +CONFIG_BLK_DEV_CMD640_ENHANCED=y +CONFIG_BLK_DEV_IDEPNP=y +CONFIG_BLK_DEV_IDEPCI=y +CONFIG_IDEPCI_SHARE_IRQ=y +# CONFIG_BLK_DEV_OFFBOARD is not set +CONFIG_BLK_DEV_GENERIC=y +# CONFIG_BLK_DEV_OPTI621 is not set +CONFIG_BLK_DEV_RZ1000=y +CONFIG_BLK_DEV_IDEDMA_PCI=y +CONFIG_BLK_DEV_AEC62XX=y +CONFIG_BLK_DEV_ALI15X3=y +# CONFIG_WDC_ALI15X3 is not set +# CONFIG_BLK_DEV_AMD74XX is not set +CONFIG_BLK_DEV_CMD64X=y +CONFIG_BLK_DEV_TRIFLEX=y +# CONFIG_BLK_DEV_CY82C693 is not set +CONFIG_BLK_DEV_CS5520=y +CONFIG_BLK_DEV_CS5530=y +CONFIG_BLK_DEV_CS5535=y +CONFIG_BLK_DEV_HPT34X=y +CONFIG_BLK_DEV_HPT366=y +CONFIG_BLK_DEV_IT821X=y +CONFIG_BLK_DEV_JMICRON=y +# CONFIG_BLK_DEV_SC1200 is not set +CONFIG_BLK_DEV_PIIX=y +# CONFIG_BLK_DEV_NS87415 is not set +CONFIG_BLK_DEV_PDC202XX_OLD=y +# CONFIG_PDC202XX_BURST is not set +CONFIG_BLK_DEV_PDC202XX_NEW=y +CONFIG_BLK_DEV_SVWKS=y +CONFIG_BLK_DEV_SIIMAGE=y +CONFIG_BLK_DEV_SIS5513=y +# CONFIG_BLK_DEV_SLC90E66 is not set +# CONFIG_BLK_DEV_TRM290 is not set +CONFIG_BLK_DEV_VIA82CXXX=y +CONFIG_BLK_DEV_IDEDMA=y +# CONFIG_BLK_DEV_HD is not set + +CONFIG_VIRTIO=m +CONFIG_VIRTIO_BLK=m +CONFIG_VIRTIO_RING=m +CONFIG_VIRTIO_PCI=m +CONFIG_VIRTIO_BALLOON=m +CONFIG_VIRTIO_NET=m +CONFIG_VMXNET3=m +CONFIG_HW_RANDOM_VIRTIO=m +CONFIG_VIRTIO_CONSOLE=m +CONFIG_VHOST_NET=m + +# +# SCSI device support +# +CONFIG_SCSI=y + +CONFIG_SCSI_ENCLOSURE=m +CONFIG_SCSI_PROC_FS=y +CONFIG_SCSI_SCAN_ASYNC=y +CONFIG_SCSI_SRP=m +CONFIG_SCSI_SRP_ATTRS=m +CONFIG_SCSI_TGT=m + +CONFIG_SCSI_DH=y +CONFIG_SCSI_DH_RDAC=m +CONFIG_SCSI_DH_HP_SW=m +CONFIG_SCSI_DH_EMC=m +CONFIG_SCSI_DH_ALUA=m + +# +# SCSI support type (disk, tape, CD-ROM) +# +CONFIG_BLK_DEV_SD=y +CONFIG_CHR_DEV_ST=m +CONFIG_CHR_DEV_OSST=m +CONFIG_BLK_DEV_SR=y +CONFIG_BLK_DEV_SR_VENDOR=y +CONFIG_CHR_DEV_SG=y +CONFIG_CHR_DEV_SCH=m + +# +# Some SCSI devices (e.g. CD jukebox) support multiple LUNs +# +CONFIG_SCSI_MULTI_LUN=y +CONFIG_SCSI_CONSTANTS=y +CONFIG_SCSI_LOGGING=y +CONFIG_SCSI_SPI_ATTRS=m +CONFIG_SCSI_FC_ATTRS=m +CONFIG_SCSI_FC_TGT_ATTRS=y +CONFIG_SCSI_ISCSI_ATTRS=m +CONFIG_SCSI_SAS_ATTRS=m +CONFIG_SCSI_SRP_TGT_ATTRS=y +CONFIG_SCSI_SAS_LIBSAS=m +CONFIG_SCSI_SAS_ATA=y +# CONFIG_SCSI_SAS_LIBSAS_DEBUG is not set +CONFIG_SCSI_SAS_HOST_SMP=y +CONFIG_RAID_ATTRS=m + +CONFIG_ISCSI_TCP=m + +# +# SCSI low-level drivers +# +CONFIG_SCSI_LOWLEVEL=y +CONFIG_BLK_DEV_3W_XXXX_RAID=m +CONFIG_SCSI_3W_9XXX=m +# CONFIG_SCSI_7000FASST is not set +CONFIG_SCSI_ACARD=m +CONFIG_SCSI_AACRAID=m +CONFIG_SCSI_AIC7XXX=m +CONFIG_SCSI_AIC94XX=m +# CONFIG_AIC94XX_DEBUG is not set +CONFIG_AIC7XXX_CMDS_PER_DEVICE=4 +CONFIG_AIC7XXX_RESET_DELAY_MS=15000 +# CONFIG_AIC7XXX_BUILD_FIRMWARE is not set +# CONFIG_AIC7XXX_DEBUG_ENABLE is not set +CONFIG_AIC7XXX_DEBUG_MASK=0 +# CONFIG_AIC7XXX_REG_PRETTY_PRINT is not set +CONFIG_SCSI_AIC7XXX_OLD=m +CONFIG_SCSI_AIC79XX=m +CONFIG_AIC79XX_CMDS_PER_DEVICE=4 +CONFIG_AIC79XX_RESET_DELAY_MS=15000 +# CONFIG_AIC79XX_BUILD_FIRMWARE is not set +# CONFIG_AIC79XX_DEBUG_ENABLE is not set +CONFIG_AIC79XX_DEBUG_MASK=0 +# CONFIG_AIC79XX_REG_PRETTY_PRINT is not set +# CONFIG_SCSI_ADVANSYS is not set +CONFIG_SCSI_BFA_FC=m +CONFIG_MEGARAID_NEWGEN=y +CONFIG_MEGARAID_MM=m +CONFIG_MEGARAID_MAILBOX=m +CONFIG_MEGARAID_LEGACY=m +CONFIG_MEGARAID_SAS=m +CONFIG_SCSI_MVSAS=m +# CONFIG_SCSI_MVSAS_DEBUG is not set +CONFIG_SCSI_MPT2SAS=m +CONFIG_SCSI_MPT2SAS_MAX_SGE=128 +CONFIG_SCSI_MPT2SAS_LOGGING=y + +CONFIG_SCSI_OSD_INITIATOR=m +CONFIG_SCSI_OSD_ULD=m +CONFIG_SCSI_OSD_DPRINT_SENSE=1 +# CONFIG_SCSI_OSD_DEBUG is not set + +CONFIG_SCSI_BNX2_ISCSI=m +CONFIG_BE2ISCSI=m +CONFIG_SCSI_PMCRAID=m + +CONFIG_SCSI_HPSA=m +CONFIG_SCSI_3W_SAS=m +CONFIG_SCSI_PM8001=m +CONFIG_VMWARE_PVSCSI=m + +CONFIG_ATA=y +CONFIG_ATA_VERBOSE_ERROR=y +CONFIG_ATA_SFF=y +CONFIG_ATA_PIIX=y +CONFIG_ATA_ACPI=y +CONFIG_BLK_DEV_SX8=m +CONFIG_PDC_ADMA=m +CONFIG_SATA_AHCI=y +CONFIG_SATA_INIC162X=m +CONFIG_SATA_MV=m +CONFIG_SATA_NV=m +CONFIG_SATA_PMP=y +CONFIG_SATA_PROMISE=m +CONFIG_SATA_QSTOR=m +CONFIG_SATA_SIL=m +CONFIG_SATA_SIL24=m +CONFIG_SATA_SIS=m +CONFIG_SATA_SVW=m +CONFIG_SATA_SX4=m +CONFIG_SATA_ULI=m +CONFIG_SATA_VIA=m +CONFIG_SATA_VITESSE=m + +CONFIG_PATA_ACPI=m +CONFIG_PATA_ALI=m +CONFIG_PATA_AMD=m +CONFIG_PATA_ARTOP=m +CONFIG_PATA_ATIIXP=m +CONFIG_PATA_CMD640_PCI=m +CONFIG_PATA_CMD64X=m +CONFIG_PATA_CS5520=m +CONFIG_PATA_CS5530=m +CONFIG_PATA_CS5535=m +CONFIG_PATA_CS5536=m +CONFIG_PATA_CYPRESS=m +CONFIG_PATA_EFAR=m +CONFIG_ATA_GENERIC=m +CONFIG_PATA_HPT366=m +CONFIG_PATA_HPT37X=m +CONFIG_PATA_HPT3X2N=m +CONFIG_PATA_HPT3X3=m +# CONFIG_PATA_HPT3X3_DMA is not set +# CONFIG_PATA_ISAPNP is not set +CONFIG_PATA_IT821X=m +CONFIG_PATA_IT8213=m +CONFIG_PATA_JMICRON=m +# CONFIG_PATA_LEGACY is not set +CONFIG_PATA_NINJA32=m +CONFIG_PATA_MARVELL=m +# CONFIG_PATA_WINBOND_VLB is not set +CONFIG_PATA_MPIIX=m +CONFIG_PATA_NETCELL=m +CONFIG_PATA_NS87410=m +CONFIG_PATA_NS87415=m +CONFIG_PATA_OLDPIIX=m +CONFIG_PATA_OPTI=m +CONFIG_PATA_OPTIDMA=m +CONFIG_PATA_PCMCIA=m +CONFIG_PATA_PDC_OLD=m +CONFIG_PATA_QDI=m +# CONFIG_PATA_RADISYS is not set +CONFIG_PATA_RDC=m +# CONFIG_PATA_RZ1000 is not set +# CONFIG_PATA_SC1200 is not set +CONFIG_PATA_SERVERWORKS=m +CONFIG_PATA_PDC2027X=m +CONFIG_PATA_SCH=m +CONFIG_PATA_SIL680=m +CONFIG_PATA_SIS=m +CONFIG_PATA_TOSHIBA=m +CONFIG_PATA_TRIFLEX=m +CONFIG_PATA_VIA=m +CONFIG_PATA_WINBOND=m +CONFIG_PATA_ATP867X=m + +CONFIG_SCSI_BUSLOGIC=m +CONFIG_SCSI_INITIO=m +CONFIG_SCSI_FLASHPOINT=y +# CONFIG_SCSI_DMX3191D is not set +# CONFIG_SCSI_EATA is not set +# CONFIG_SCSI_EATA_PIO is not set +# CONFIG_SCSI_FUTURE_DOMAIN is not set +CONFIG_SCSI_GDTH=m +CONFIG_SCSI_HPTIOP=m +CONFIG_SCSI_IPS=m +CONFIG_SCSI_INIA100=m +CONFIG_SCSI_PPA=m +CONFIG_SCSI_IMM=m +# CONFIG_SCSI_IZIP_EPP16 is not set +# CONFIG_SCSI_IZIP_SLOW_CTR is not set +CONFIG_SCSI_STEX=m +CONFIG_SCSI_SYM53C8XX_2=m +CONFIG_SCSI_SYM53C8XX_DMA_ADDRESSING_MODE=1 +CONFIG_SCSI_SYM53C8XX_DEFAULT_TAGS=16 +CONFIG_SCSI_SYM53C8XX_MAX_TAGS=64 +CONFIG_SCSI_SYM53C8XX_MMIO=y +# CONFIG_SCSI_QLOGIC_FC is not set +# CONFIG_SCSI_QLOGIC_FC_FIRMWARE is not set +CONFIG_SCSI_QLOGIC_1280=m +CONFIG_SCSI_DC395x=m +# CONFIG_SCSI_NSP32 is not set +CONFIG_SCSI_DEBUG=m +CONFIG_SCSI_DC390T=m +CONFIG_SCSI_QLA_FC=m +CONFIG_SCSI_QLA_ISCSI=m +# CONFIG_SCSI_IPR is not set +# CONFIG_SCSI_DPT_I2O is not set +CONFIG_SCSI_LPFC=m +# CONFIG_SCSI_SEAGATE is not set + +# +# PCMCIA SCSI adapter support +# +CONFIG_SCSI_LOWLEVEL_PCMCIA=y +CONFIG_PCMCIA_AHA152X=m +# CONFIG_PCMCIA_FDOMAIN is not set +CONFIG_PCMCIA_NINJA_SCSI=m +CONFIG_PCMCIA_QLOGIC=m +CONFIG_PCMCIA_SYM53C500=m + + +# +# Multi-device support (RAID and LVM) +# +CONFIG_MD=y +CONFIG_BLK_DEV_MD=y +CONFIG_MD_AUTODETECT=y +CONFIG_MD_FAULTY=m +CONFIG_MD_LINEAR=m +CONFIG_MD_MULTIPATH=m +CONFIG_MD_RAID0=m +CONFIG_MD_RAID1=m +CONFIG_MD_RAID5_RESHAPE=y +CONFIG_MD_RAID10=m +CONFIG_MD_RAID456=m +# CONFIG_MULTICORE_RAID456 is not set +CONFIG_ASYNC_RAID6_TEST=m +CONFIG_BLK_DEV_DM=y +CONFIG_DM_CRYPT=m +CONFIG_DM_DEBUG=y +# CONFIG_DM_DELAY is not set +CONFIG_DM_MIRROR=y +CONFIG_DM_MULTIPATH=m +CONFIG_DM_MULTIPATH_EMC=m +CONFIG_DM_MULTIPATH_HP=m +CONFIG_DM_MULTIPATH_RDAC=m +CONFIG_DM_SNAPSHOT=y +CONFIG_DM_UEVENT=y +CONFIG_DM_ZERO=y +CONFIG_DM_LOG_USERSPACE=m +CONFIG_DM_MULTIPATH_QL=m +CONFIG_DM_MULTIPATH_ST=m + +# +# Fusion MPT device support +# +CONFIG_FUSION=y +CONFIG_FUSION_SPI=m +CONFIG_FUSION_FC=m +CONFIG_FUSION_MAX_SGE=40 +CONFIG_FUSION_CTL=m +CONFIG_FUSION_LAN=m +CONFIG_FUSION_SAS=m +CONFIG_FUSION_LOGGING=y + +# +# IEEE 1394 (FireWire) support (JUJU alternative stack) +# +CONFIG_FIREWIRE=m +CONFIG_FIREWIRE_OHCI=m +CONFIG_FIREWIRE_SBP2=m +CONFIG_FIREWIRE_NET=m +CONFIG_FIREWIRE_OHCI_DEBUG=y +# CONFIG_FIREWIRE_OHCI_REMOTE_DMA is not set + +# +# IEEE 1394 (FireWire) support +# +# CONFIG_IEEE1394 is not set + +# +# I2O device support +# +# CONFIG_I2O is not set +# CONFIG_I2O_LCT_NOTIFY_ON_CHANGES is not set + +# +# Networking support +# +CONFIG_NET=y + +CONFIG_TCP_CONG_ADVANCED=y +CONFIG_TCP_CONG_BIC=m +CONFIG_TCP_CONG_CUBIC=y +CONFIG_TCP_CONG_HTCP=m +CONFIG_TCP_CONG_HSTCP=m +CONFIG_TCP_CONG_HYBLA=m +CONFIG_TCP_CONG_ILLINOIS=m +CONFIG_TCP_CONG_LP=m +CONFIG_TCP_CONG_SCALABLE=m +CONFIG_TCP_CONG_VEGAS=m +CONFIG_TCP_CONG_VENO=m +CONFIG_TCP_CONG_WESTWOOD=m +CONFIG_TCP_CONG_YEAH=m + +CONFIG_TCP_MD5SIG=y + +# +# Networking options +# +CONFIG_PACKET=y +CONFIG_PACKET_MMAP=y +CONFIG_UNIX=y +CONFIG_NET_KEY=m +CONFIG_NET_KEY_MIGRATE=y +CONFIG_INET=y +CONFIG_INET_LRO=y +CONFIG_INET_TUNNEL=m +CONFIG_INET_DIAG=m +CONFIG_IP_MULTICAST=y +CONFIG_IP_ADVANCED_ROUTER=y +CONFIG_IP_MULTIPLE_TABLES=y +CONFIG_IP_ROUTE_MULTIPATH=y +CONFIG_IP_ROUTE_VERBOSE=y +CONFIG_IP_NF_SECURITY=m +# CONFIG_IP_PNP is not set +CONFIG_NET_IPIP=m +CONFIG_NET_IPGRE=m +CONFIG_NET_IPGRE_BROADCAST=y +CONFIG_IP_MROUTE=y +CONFIG_IP_PIMSM_V1=y +CONFIG_IP_PIMSM_V2=y +CONFIG_ARPD=y +CONFIG_SYN_COOKIES=y +CONFIG_INET_AH=m +CONFIG_INET_ESP=m +CONFIG_INET_IPCOMP=m +CONFIG_NETCONSOLE=m +CONFIG_NETCONSOLE_DYNAMIC=y +CONFIG_NETPOLL_TRAP=y +CONFIG_NET_POLL_CONTROLLER=y + +# +# IP: Virtual Server Configuration +# +CONFIG_IP_VS=m +# CONFIG_IP_VS_DEBUG is not set +CONFIG_IP_VS_TAB_BITS=12 +CONFIG_IP_VS_PROTO_TCP=y +CONFIG_IP_VS_PROTO_UDP=y +CONFIG_IP_VS_PROTO_ESP=y +CONFIG_IP_VS_PROTO_AH=y +CONFIG_IP_VS_RR=m +CONFIG_IP_VS_WRR=m +CONFIG_IP_VS_LC=m +CONFIG_IP_VS_WLC=m +CONFIG_IP_VS_LBLC=m +CONFIG_IP_VS_LBLCR=m +CONFIG_IP_VS_DH=m +CONFIG_IP_VS_SH=m +CONFIG_IP_VS_SED=m +CONFIG_IP_VS_NQ=m +CONFIG_IP_VS_FTP=m + +CONFIG_IPV6=m +CONFIG_IPV6_PRIVACY=y +CONFIG_IPV6_ROUTER_PREF=y +CONFIG_IPV6_ROUTE_INFO=y +CONFIG_IPV6_OPTIMISTIC_DAD=y +CONFIG_INET6_AH=m +CONFIG_INET6_ESP=m +CONFIG_INET6_IPCOMP=m +CONFIG_IPV6_MIP6=y +CONFIG_IPV6_SIT=m +CONFIG_IPV6_SIT_6RD=y +CONFIG_IPV6_TUNNEL=m +CONFIG_IPV6_SUBTREES=y +CONFIG_IPV6_MULTIPLE_TABLES=y +CONFIG_IPV6_MROUTE=y +CONFIG_IPV6_PIMSM_V2=y + +CONFIG_RDS=m +# CONFIG_RDS_DEBUG is not set +CONFIG_RDS_RDMA=m +CONFIG_RDS_TCP=m + +CONFIG_NET_9P=m +CONFIG_NET_9P_FD=m +CONFIG_NET_9P_VIRTIO=m +# CONFIG_NET_9P_DEBUG is not set +CONFIG_NET_9P_RDMA=m + +CONFIG_DECNET=m +CONFIG_DECNET_ROUTER=y +# CONFIG_DECNET_NF_GRABULATOR is not set +CONFIG_BRIDGE=m +CONFIG_NETFILTER=y +CONFIG_NETFILTER_ADVANCED=y +CONFIG_NF_CONNTRACK=y +CONFIG_NETFILTER_NETLINK=m +CONFIG_NETFILTER_NETLINK_QUEUE=m +CONFIG_NETFILTER_NETLINK_LOG=m +CONFIG_NETFILTER_XTABLES=y +CONFIG_NETFILTER_XT_TARGET_CLASSIFY=m +CONFIG_NETFILTER_XT_TARGET_CONNMARK=m +CONFIG_NETFILTER_XT_TARGET_CONNSECMARK=m +CONFIG_NETFILTER_XT_TARGET_DSCP=m +CONFIG_NETFILTER_XT_TARGET_MARK=m +CONFIG_NETFILTER_XT_TARGET_NFLOG=m +CONFIG_NETFILTER_XT_TARGET_NFQUEUE=m +CONFIG_NETFILTER_XT_TARGET_NOTRACK=m +CONFIG_NETFILTER_XT_TARGET_RATEEST=m +CONFIG_NETFILTER_XT_TARGET_SECMARK=m +CONFIG_NETFILTER_XT_TARGET_TCPMSS=m +CONFIG_NETFILTER_XT_TARGET_TCPOPTSTRIP=m +CONFIG_NETFILTER_XT_TARGET_TRACE=m +CONFIG_NETFILTER_XT_TARGET_LED=m +CONFIG_NETFILTER_XT_MATCH_COMMENT=m +CONFIG_NETFILTER_XT_MATCH_CONNBYTES=m +CONFIG_NETFILTER_XT_MATCH_CONNMARK=m +CONFIG_NETFILTER_XT_MATCH_CONNLIMIT=m +CONFIG_NETFILTER_XT_MATCH_CONNTRACK=y +CONFIG_NETFILTER_XT_MATCH_DCCP=m +CONFIG_NETFILTER_XT_MATCH_DSCP=m +CONFIG_NETFILTER_XT_MATCH_ESP=m +CONFIG_NETFILTER_XT_MATCH_HASHLIMIT=m +CONFIG_NETFILTER_XT_MATCH_HELPER=m +CONFIG_NETFILTER_XT_MATCH_IPRANGE=m +CONFIG_NETFILTER_XT_MATCH_LENGTH=m +CONFIG_NETFILTER_XT_MATCH_LIMIT=m +CONFIG_NETFILTER_XT_MATCH_MAC=m +CONFIG_NETFILTER_XT_MATCH_MARK=m +CONFIG_NETFILTER_XT_MATCH_MULTIPORT=m +CONFIG_NETFILTER_XT_MATCH_OWNER=m +CONFIG_NETFILTER_XT_MATCH_PHYSDEV=m +CONFIG_NETFILTER_XT_MATCH_PKTTYPE=m +CONFIG_NETFILTER_XT_MATCH_POLICY=m +CONFIG_NETFILTER_XT_MATCH_QUOTA=m +CONFIG_NETFILTER_XT_MATCH_RATEEST=m +CONFIG_NETFILTER_XT_MATCH_REALM=m +CONFIG_NETFILTER_XT_MATCH_SCTP=m +CONFIG_NETFILTER_XT_MATCH_STATE=y +CONFIG_NETFILTER_XT_MATCH_STATISTIC=m +CONFIG_NETFILTER_XT_MATCH_STRING=m +CONFIG_NETFILTER_XT_MATCH_TCPMSS=m +CONFIG_NETFILTER_XT_MATCH_TIME=m +CONFIG_NETFILTER_XT_MATCH_U32=m +CONFIG_NETFILTER_XT_MATCH_CLUSTER=m +CONFIG_NETFILTER_XT_MATCH_HL=m +CONFIG_NETFILTER_XT_MATCH_OSF=m + +# CONFIG_NETFILTER_DEBUG is not set +CONFIG_BRIDGE_NETFILTER=y + +# +# IP: Netfilter Configuration +# +CONFIG_NF_CONNTRACK_ENABLED=y + +CONFIG_NF_CT_ACCT=y +CONFIG_NF_CONNTRACK_MARK=y +CONFIG_NF_CONNTRACK_SECMARK=y +CONFIG_NF_CONNTRACK_EVENTS=y +# CONFIG_NF_CONNTRACK_PROC_COMPAT is not set +CONFIG_NF_CONNTRACK_AMANDA=m +CONFIG_NF_CONNTRACK_FTP=m +CONFIG_NF_CONNTRACK_H323=m +CONFIG_NF_CONNTRACK_IRC=m +CONFIG_NF_CONNTRACK_NETBIOS_NS=m +CONFIG_NF_CONNTRACK_PPTP=m +CONFIG_NF_CONNTRACK_SANE=m +CONFIG_NF_CONNTRACK_SIP=m +CONFIG_NF_CONNTRACK_TFTP=m +CONFIG_NF_CONNTRACK_IPV4=y +CONFIG_NF_CONNTRACK_IPV6=y +CONFIG_NF_NAT=m +CONFIG_NF_NAT_SNMP_BASIC=m +CONFIG_NF_CT_PROTO_DCCP=m +CONFIG_NF_CT_PROTO_SCTP=m +CONFIG_NF_CT_NETLINK=m +CONFIG_NF_CT_PROTO_UDPLITE=m + +CONFIG_IP_NF_MATCH_ADDRTYPE=m +CONFIG_IP_NF_MATCH_AH=m +CONFIG_IP_NF_MATCH_ECN=m +CONFIG_IP_NF_MATCH_IPRANGE=m +CONFIG_IP_NF_MATCH_OWNER=m +CONFIG_IP_NF_MATCH_RECENT=m +CONFIG_IP_NF_MATCH_TOS=m +CONFIG_IP_NF_MATCH_TTL=m +CONFIG_IP_NF_TARGET_CLUSTERIP=m +CONFIG_IP_NF_TARGET_MASQUERADE=m +CONFIG_IP_NF_TARGET_REDIRECT=m +CONFIG_IP_NF_TARGET_NETMAP=m +CONFIG_IP_NF_TARGET_SAME=m +CONFIG_IP_NF_TARGET_TOS=m +CONFIG_IP_NF_TARGET_ECN=m +CONFIG_IP_NF_TARGET_LOG=m +CONFIG_IP_NF_TARGET_ULOG=m +CONFIG_IP_NF_TARGET_REJECT=y +CONFIG_IP_NF_TARGET_TTL=m +CONFIG_IP_NF_MANGLE=m +CONFIG_IP_NF_ARPTABLES=m +CONFIG_IP_NF_ARPFILTER=m +CONFIG_IP_NF_ARP_MANGLE=m +CONFIG_IP_NF_QUEUE=m +CONFIG_IP_NF_RAW=m + +CONFIG_IP_NF_IPTABLES=y +CONFIG_IP_NF_FILTER=y + +# +# IPv6: Netfilter Configuration +# +CONFIG_IP6_NF_FILTER=m +CONFIG_IP6_NF_IPTABLES=m +CONFIG_IP6_NF_MANGLE=m +CONFIG_IP6_NF_MATCH_AH=m +CONFIG_IP6_NF_MATCH_EUI64=m +CONFIG_IP6_NF_MATCH_FRAG=m +CONFIG_IP6_NF_MATCH_HL=m +CONFIG_IP6_NF_MATCH_IPV6HEADER=m +CONFIG_IP6_NF_MATCH_MH=m +CONFIG_IP6_NF_MATCH_OPTS=m +CONFIG_IP6_NF_MATCH_OWNER=m +CONFIG_IP6_NF_MATCH_RT=m +CONFIG_IP6_NF_QUEUE=m +CONFIG_IP6_NF_RAW=m +CONFIG_IP6_NF_SECURITY=m +CONFIG_IP6_NF_TARGET_LOG=m +CONFIG_IP6_NF_TARGET_REJECT=m +CONFIG_IP6_NF_TARGET_HL=m + +# +# Bridge: Netfilter Configuration +# +CONFIG_BRIDGE_NF_EBTABLES=m +CONFIG_BRIDGE_EBT_802_3=m +CONFIG_BRIDGE_EBT_AMONG=m +CONFIG_BRIDGE_EBT_ARP=m +CONFIG_BRIDGE_EBT_ARPREPLY=m +CONFIG_BRIDGE_EBT_BROUTE=m +CONFIG_BRIDGE_EBT_DNAT=m +CONFIG_BRIDGE_EBT_IP=m +CONFIG_BRIDGE_EBT_IP6=m +CONFIG_BRIDGE_EBT_LIMIT=m +CONFIG_BRIDGE_EBT_LOG=m +CONFIG_BRIDGE_EBT_MARK=m +CONFIG_BRIDGE_EBT_MARK_T=m +CONFIG_BRIDGE_EBT_NFLOG=m +CONFIG_BRIDGE_EBT_PKTTYPE=m +CONFIG_BRIDGE_EBT_REDIRECT=m +CONFIG_BRIDGE_EBT_SNAT=m +CONFIG_BRIDGE_EBT_STP=m +CONFIG_BRIDGE_EBT_T_FILTER=m +CONFIG_BRIDGE_EBT_T_NAT=m +CONFIG_BRIDGE_EBT_ULOG=m +CONFIG_BRIDGE_EBT_VLAN=m +CONFIG_XFRM=y +CONFIG_XFRM_MIGRATE=y +CONFIG_XFRM_SUB_POLICY=y +CONFIG_XFRM_STATISTICS=y +CONFIG_XFRM_USER=y +CONFIG_INET_XFRM_MODE_TRANSPORT=m +CONFIG_INET_XFRM_MODE_TUNNEL=m +CONFIG_INET_XFRM_MODE_BEET=m +CONFIG_INET6_XFRM_MODE_TRANSPORT=m +CONFIG_INET6_XFRM_MODE_TUNNEL=m +CONFIG_INET6_XFRM_MODE_ROUTEOPTIMIZATION=m +CONFIG_INET6_XFRM_MODE_BEET=m + +# +# SCTP Configuration (EXPERIMENTAL) +# +CONFIG_IP_SCTP=m +# CONFIG_SCTP_DBG_MSG is not set +# CONFIG_SCTP_DBG_OBJCNT is not set +# CONFIG_SCTP_HMAC_NONE is not set +CONFIG_SCTP_HMAC_SHA1=y +# CONFIG_SCTP_HMAC_MD5 is not set +CONFIG_ATM=m +CONFIG_VLAN_8021Q=m +CONFIG_VLAN_8021Q_GVRP=y +CONFIG_LLC=m +# CONFIG_LLC2 is not set +CONFIG_IPX=m +# CONFIG_IPX_INTERN is not set +CONFIG_ATALK=m +CONFIG_DEV_APPLETALK=y +CONFIG_IPDDP=m +CONFIG_IPDDP_ENCAP=y +CONFIG_IPDDP_DECAP=y +# CONFIG_X25 is not set +# CONFIG_LAPB is not set +# CONFIG_ECONET is not set +CONFIG_WAN_ROUTER=m +CONFIG_IP_DCCP=m +CONFIG_IP_DCCP_CCID2=m +# CONFIG_IP_DCCP_CCID2_DEBUG is not set +CONFIG_IP_DCCP_CCID3=y +# CONFIG_IP_DCCP_CCID3_DEBUG is not set +CONFIG_IP_DCCP_CCID3_RTO=100 +# CONFIG_IP_DCCP_DEBUG is not set +CONFIG_NET_DCCPPROBE=m + +# +# TIPC Configuration (EXPERIMENTAL) +# +# CONFIG_TIPC is not set +# CONFIG_TIPC_ADVANCED is not set +# CONFIG_TIPC_DEBUG is not set + +CONFIG_NETLABEL=y + +# +# QoS and/or fair queueing +# +CONFIG_NET_SCHED=y +CONFIG_NET_SCH_CBQ=m +CONFIG_NET_SCH_DSMARK=m +CONFIG_NET_SCH_DRR=m +CONFIG_NET_SCH_GRED=m +CONFIG_NET_SCH_HFSC=m +CONFIG_NET_SCH_HTB=m +CONFIG_NET_SCH_INGRESS=m +CONFIG_NET_SCH_NETEM=m +CONFIG_NET_SCH_PRIO=m +CONFIG_NET_SCH_RED=m +CONFIG_NET_SCH_RR=m +CONFIG_NET_SCH_SFQ=m +CONFIG_NET_SCH_TBF=m +CONFIG_NET_SCH_TEQL=m +CONFIG_NET_CLS=y +CONFIG_NET_CLS_ACT=y +CONFIG_NET_CLS_BASIC=m +CONFIG_NET_CLS_CGROUP=y +CONFIG_NET_CLS_FLOW=m +CONFIG_NET_CLS_FW=m +CONFIG_NET_CLS_IND=y +CONFIG_NET_CLS_POLICE=y +CONFIG_NET_CLS_ROUTE4=m +CONFIG_NET_CLS_ROUTE=y +CONFIG_NET_CLS_RSVP=m +CONFIG_NET_CLS_RSVP6=m +CONFIG_NET_CLS_TCINDEX=m +CONFIG_NET_CLS_U32=m +CONFIG_CLS_U32_MARK=y +CONFIG_CLS_U32_PERF=y +CONFIG_NET_EMATCH=y +CONFIG_NET_EMATCH_CMP=m +CONFIG_NET_EMATCH_META=m +CONFIG_NET_EMATCH_NBYTE=m +CONFIG_NET_EMATCH_STACK=32 +CONFIG_NET_EMATCH_TEXT=m +CONFIG_NET_EMATCH_U32=m + +CONFIG_NET_ACT_GACT=m +CONFIG_GACT_PROB=y +CONFIG_NET_ACT_IPT=m +CONFIG_NET_ACT_MIRRED=m +CONFIG_NET_ACT_NAT=m +CONFIG_NET_ACT_PEDIT=m +CONFIG_NET_ACT_POLICE=m +CONFIG_NET_ACT_SIMP=m + +CONFIG_DCB=y + +# +# Network testing +# +CONFIG_NET_PKTGEN=m +# CONFIG_NET_TCPPROBE is not set +CONFIG_NET_DROP_MONITOR=y +CONFIG_NETDEVICES=y + +# disable later --kyle +CONFIG_COMPAT_NET_DEV_OPS=y + +# +# ARCnet devices +# +# CONFIG_ARCNET is not set +CONFIG_IFB=m +CONFIG_DUMMY=m +CONFIG_BONDING=m +CONFIG_MACVLAN=m +CONFIG_EQUALIZER=m +CONFIG_TUN=m +CONFIG_VETH=m +CONFIG_NET_SB1000=m + +# +# ATM +# +CONFIG_ATM_DRIVERS=y +# CONFIG_ATM_DUMMY is not set +CONFIG_ATM_CLIP=m +CONFIG_ATM_LANE=m +CONFIG_ATM_BR2684=m +CONFIG_NET_SCH_ATM=m +CONFIG_ATM_TCP=m +# CONFIG_ATM_LANAI is not set +CONFIG_ATM_ENI=m +CONFIG_ATM_FIRESTREAM=m +# CONFIG_ATM_ZATM is not set +# CONFIG_ATM_IDT77252 is not set +# CONFIG_ATM_AMBASSADOR is not set +# CONFIG_ATM_HORIZON is not set +# CONFIG_ATM_FORE200E is not set +# CONFIG_ATM_FORE200E_USE_TASKLET is not set +CONFIG_ATM_FORE200E_TX_RETRY=16 +CONFIG_ATM_FORE200E_DEBUG=0 + +CONFIG_ATM_HE=m +CONFIG_PPPOATM=m +CONFIG_PPPOL2TP=m +CONFIG_ATM_NICSTAR=m +# CONFIG_ATM_IA is not set +# CONFIG_ATM_CLIP_NO_ICMP is not set +# CONFIG_ATM_MPOA is not set +# CONFIG_ATM_BR2684_IPFILTER is not set +# CONFIG_ATM_ENI_DEBUG is not set +# CONFIG_ATM_ENI_TUNE_BURST is not set +# CONFIG_ATM_ZATM_DEBUG is not set +# CONFIG_ATM_IDT77252_DEBUG is not set +# CONFIG_ATM_IDT77252_RCV_ALL is not set +# CONFIG_ATM_AMBASSADOR_DEBUG is not set +# CONFIG_ATM_HORIZON_DEBUG is not set +# CONFIG_ATM_HE_USE_SUNI is not set +# CONFIG_ATM_NICSTAR_USE_SUNI is not set +# CONFIG_ATM_NICSTAR_USE_IDT77105 is not set +# CONFIG_ATM_IA_DEBUG is not set +CONFIG_ATM_SOLOS=m + +CONFIG_RFKILL=m +CONFIG_RFKILL_INPUT=y + +# +# Ethernet (10 or 100Mbit) +# +CONFIG_NETDEV_1000=y +CONFIG_NETDEV_10000=y +CONFIG_NET_ETHERNET=y +CONFIG_PHYLIB=m +CONFIG_BROADCOM_PHY=m +CONFIG_CICADA_PHY=m +CONFIG_DAVICOM_PHY=m +CONFIG_FIXED_PHY=y +CONFIG_FIXED_MII_10_FDX=y +CONFIG_FIXED_MII_100_FDX=y +CONFIG_FIXED_MII_1000_FDX=y +CONFIG_FIXED_MII_AMNT=1 +CONFIG_MDIO_BITBANG=m +CONFIG_NATIONAL_PHY=m +CONFIG_ICPLUS_PHY=m +CONFIG_LSI_ET1011C_PHY=m +CONFIG_LXT_PHY=m +CONFIG_MARVELL_PHY=m +CONFIG_QSEMI_PHY=m +CONFIG_REALTEK_PHY=m +CONFIG_SMSC_PHY=m +CONFIG_STE10XP=m +CONFIG_VITESSE_PHY=m + +CONFIG_MII=m +CONFIG_HAPPYMEAL=m +CONFIG_SUNGEM=m +CONFIG_NET_VENDOR_3COM=y +CONFIG_VORTEX=m +CONFIG_TYPHOON=m +CONFIG_DNET=m + +# +# Tulip family network device support +# +CONFIG_NET_TULIP=y +CONFIG_DE2104X=m +CONFIG_DE2104X_DSL=0 +CONFIG_TULIP=m +# CONFIG_TULIP_NAPI is not set +# CONFIG_TULIP_MWI is not set +CONFIG_TULIP_MMIO=y +# CONFIG_NI5010 is not set +# CONFIG_PCMCIA_XIRTULIP is not set +CONFIG_DE4X5=m +CONFIG_WINBOND_840=m +CONFIG_DM9102=m +CONFIG_PCMCIA_XIRCOM=m +CONFIG_ULI526X=m +# CONFIG_HP100 is not set +CONFIG_LNE390=m +CONFIG_NE3210=m +CONFIG_ES3210=m +CONFIG_NET_PCI=y +CONFIG_PCNET32=m +CONFIG_PCNET32_NAPI=y +CONFIG_AMD8111_ETH=m +CONFIG_AMD8111E_NAPI=y +CONFIG_ADAPTEC_STARFIRE=m +CONFIG_ADAPTEC_STARFIRE_NAPI=y +CONFIG_B44=m +CONFIG_B44_PCI=y +CONFIG_BNX2=m +CONFIG_CNIC=m +CONFIG_QLA3XXX=m +CONFIG_ATL1=m +CONFIG_ATL1C=m +CONFIG_ATL2=m +CONFIG_ATL1E=m +# CONFIG_EEPRO100 is not set +CONFIG_E100=m +CONFIG_FEALNX=m +CONFIG_FORCEDETH=m +CONFIG_FORCEDETH_NAPI=y +CONFIG_NATSEMI=m +CONFIG_NE2K_PCI=m +CONFIG_8139CP=m +CONFIG_8139TOO=m +# CONFIG_8139TOO_PIO is not set +# CONFIG_8139TOO_TUNE_TWISTER is not set +CONFIG_8139TOO_8129=y +# CONFIG_8139_OLD_RX_RESET is not set +CONFIG_SIS900=m +CONFIG_SIS190=m +CONFIG_EPIC100=m +CONFIG_SC92031=m +CONFIG_SMSC9420=m +CONFIG_SUNDANCE=m +# CONFIG_SUNDANCE_MMIO is not set +CONFIG_TLAN=m +CONFIG_VIA_RHINE=m +CONFIG_VIA_RHINE_MMIO=y +CONFIG_VIA_RHINE_NAPI=y +CONFIG_VIA_VELOCITY=m +CONFIG_NET_POCKET=y +CONFIG_ATP=m +CONFIG_DE600=m +CONFIG_DE620=m +CONFIG_CASSINI=m +# CONFIG_FEC_8XX is not set +CONFIG_ETHOC=m +# CONFIG_KS8842 is not set +# CONFIG_KS8851_MLL is not set + +# +# Ethernet (1000 Mbit) +# +CONFIG_ACENIC=m +# CONFIG_ACENIC_OMIT_TIGON_I is not set +CONFIG_DL2K=m +CONFIG_E1000=m +CONFIG_E1000_NAPI=y +# CONFIG_E1000_DISABLE_PACKET_SPLIT is not set +CONFIG_E1000E=m +CONFIG_IGB=m +# CONFIG_IGB_LRO is not set +CONFIG_IGB_DCA=y +CONFIG_IGBVF=m +CONFIG_NS83820=m +CONFIG_HAMACHI=m +CONFIG_YELLOWFIN=m +CONFIG_R8169=m +CONFIG_R8169_NAPI=y +CONFIG_R8169_VLAN=y +# CONFIG_SK98LIN is not set +CONFIG_SKGE=m +# CONFIG_SKGE_DEBUG is not set +CONFIG_TIGON3=m +CONFIG_SKY2=m +# CONFIG_SKY2_DEBUG is not set +CONFIG_JME=m + +# +# Ethernet (10000 Mbit) +# +CONFIG_CHELSIO_T1=m +CONFIG_CHELSIO_T1_1G=y +CONFIG_CHELSIO_T1_NAPI=y +CONFIG_CHELSIO_T3=m +CONFIG_IP1000=m +CONFIG_IXGB=m +CONFIG_IXGB_NAPI=y +CONFIG_IXGBE=m +CONFIG_IXGBE_DCA=y +CONFIG_IXGBE_DCB=y +CONFIG_MYRI10GE=m +CONFIG_MYRI10GE_DCA=y +CONFIG_NETXEN_NIC=m +CONFIG_NIU=m +CONFIG_S2IO=m +CONFIG_S2IO_NAPI=y +CONFIG_VXGE=m +# CONFIG_VXGE_DEBUG_TRACE_ALL is not set +CONFIG_TEHUTI=m +CONFIG_ENIC=m +CONFIG_MLX4_EN=m +# CONFIG_MLX4_DEBUG is not set +CONFIG_QLGE=m +CONFIG_SFC=m +CONFIG_SFC_MTD=y +CONFIG_BE2NET=m + +CONFIG_FDDI=y +# CONFIG_DEFXX is not set +CONFIG_SKFP=m +# CONFIG_HIPPI is not set +CONFIG_PLIP=m +CONFIG_PPP=m +CONFIG_PPP_MULTILINK=y +CONFIG_PPP_FILTER=y +CONFIG_PPP_ASYNC=m +CONFIG_PPP_SYNC_TTY=m +CONFIG_PPP_DEFLATE=m +CONFIG_IPPP_FILTER=y +# CONFIG_PPP_BSDCOMP is not set +CONFIG_PPPOE=m +CONFIG_PPP_MPPE=m +CONFIG_SLIP=m +CONFIG_SLIP_COMPRESSED=y +CONFIG_SLIP_SMART=y +# CONFIG_SLIP_MODE_SLIP6 is not set + +# +# Wireless LAN +# +# +CONFIG_WLAN=y +# CONFIG_WLAN_PRE80211 is not set +# CONFIG_STRIP is not set +# CONFIG_ARLAN is not set +CONFIG_PCMCIA_WAVELAN=m +CONFIG_PCMCIA_NETWAVE=m +CONFIG_WLAN_80211=y +# CONFIG_PCMCIA_RAYCS is not set + +CONFIG_WIRELESS=y +CONFIG_CFG80211=m +CONFIG_CFG80211_WEXT=y +# CONFIG_CFG80211_REG_DEBUG is not set +CONFIG_CFG80211_DEBUGFS=y +# CONFIG_CFG80211_DEVELOPER_WARNINGS is not set +CONFIG_CFG80211_DEFAULT_PS=y +CONFIG_NL80211=y +# CONFIG_NL80211_TESTMODE is not set +# CONFIG_WIRELESS_OLD_REGULATORY is not set +CONFIG_WIRELESS_EXT=y +CONFIG_WIRELESS_EXT_SYSFS=y +CONFIG_LIB80211=m +CONFIG_LIB80211_CRYPT_WEP=m +CONFIG_LIB80211_CRYPT_CCMP=m +CONFIG_LIB80211_CRYPT_TKIP=m +# CONFIG_LIB80211_DEBUG is not set + +CONFIG_MAC80211=m +CONFIG_MAC80211_QOS=y +CONFIG_MAC80211_RC_MINSTREL=y +# CONFIG_MAC80211_RC_DEFAULT_PID is not set +CONFIG_MAC80211_RC_DEFAULT_MINSTREL=y +CONFIG_MAC80211_RC_DEFAULT="minstrel" +CONFIG_MAC80211_MESH=y +CONFIG_MAC80211_LEDS=y +CONFIG_MAC80211_DEBUGFS=y +# CONFIG_MAC80211_DEBUG_MENU is not set +CONFIG_MAC80211_DEFAULT_PS=y + +CONFIG_WIMAX=m +CONFIG_WIMAX_DEBUG_LEVEL=8 +CONFIG_WIMAX_I2400M_USB=m +CONFIG_WIMAX_I2400M_SDIO=m +CONFIG_WIMAX_I2400M_DEBUG_LEVEL=8 +CONFIG_WIMAX_IWMC3200_SDIO=y + +CONFIG_ADM8211=m +CONFIG_ATH_COMMON=m +CONFIG_ATH5K=m +CONFIG_ATH5K_DEBUG=y +CONFIG_ATH9K=m +# CONFIG_ATH9K_DEBUG is not set +CONFIG_ATH9K_DEBUGFS=y +CONFIG_AT76C50X_USB=m +CONFIG_AIRO=m +CONFIG_AIRO_CS=m +CONFIG_ATMEL=m +# CONFIG_BCM43XX is not set +CONFIG_B43=m +CONFIG_B43_PCMCIA=y +CONFIG_B43_SDIO=y +# CONFIG_B43_DEBUG is not set +CONFIG_B43_PHY_LP=y +# CONFIG_B43_FORCE_PIO is not set +CONFIG_B43LEGACY=m +# CONFIG_B43LEGACY_DEBUG is not set +CONFIG_B43LEGACY_DMA=y +CONFIG_B43LEGACY_PIO=y +CONFIG_B43LEGACY_DMA_AND_PIO_MODE=y +# CONFIG_B43LEGACY_DMA_MODE is not set +# CONFIG_B43LEGACY_PIO_MODE is not set +CONFIG_HERMES=m +CONFIG_HERMES_CACHE_FW_ON_INIT=y +CONFIG_HOSTAP=m +CONFIG_HOSTAP_PCI=m +CONFIG_HOSTAP_PLX=m +CONFIG_HOSTAP_FIRMWARE=y +CONFIG_HOSTAP_FIRMWARE_NVRAM=y +CONFIG_HOSTAP_CS=m +# CONFIG_IPW2100 is not set +# CONFIG_IPW2200 is not set +# CONFIG_IPW2100_DEBUG is not set +# CONFIG_IPW2200_DEBUG is not set +# CONFIG_LIBIPW_DEBUG is not set +CONFIG_LIBERTAS=m +CONFIG_LIBERTAS_USB=m +CONFIG_LIBERTAS_CS=m +CONFIG_LIBERTAS_SDIO=m +CONFIG_LIBERTAS_DEBUG=y +CONFIG_LIBERTAS_THINFIRM=m +CONFIG_LIBERTAS_THINFIRM_USB=m +CONFIG_IWLWIFI=m +CONFIG_IWLWIFI_LEDS=y +CONFIG_IWLWIFI_RUN_TIME_CALIB=y +CONFIG_IWLWIFI_DEBUG=y +CONFIG_IWLWIFI_DEBUGFS=y +CONFIG_IWLWIFI_RFKILL=y +CONFIG_IWLWIFI_SPECTRUM_MEASUREMENT=y +CONFIG_IWLAGN=m +CONFIG_IWL4965=y +CONFIG_IWL5000=y +CONFIG_IWL5000_RUN_TIME_CALIB=y +CONFIG_IWL3945=m +CONFIG_IWL3945_RFKILL=y +CONFIG_IWL3945_DEBUG=y +CONFIG_IWL3945_SPECTRUM_MEASUREMENT=y +CONFIG_IWL3945_LEDS=y +CONFIG_IWM=m +# CONFIG_IWM_DEBUG is not set +CONFIG_MAC80211_HWSIM=m +CONFIG_NORTEL_HERMES=m +CONFIG_P54_COMMON=m +CONFIG_P54_USB=m +CONFIG_P54_PCI=m +CONFIG_PCI_HERMES=m +CONFIG_PLX_HERMES=m +CONFIG_PCI_ATMEL=m +CONFIG_MWL8K=m +# CONFIG_PRISM54 is not set +CONFIG_PCMCIA_HERMES=m +CONFIG_PCMCIA_SPECTRUM=m +CONFIG_PCMCIA_ATMEL=m +CONFIG_PCMCIA_WL3501=m +CONFIG_RT2X00=m +CONFIG_RT2X00_LIB_DEBUGFS=y +# CONFIG_RT2X00_DEBUG is not set +CONFIG_RT2400PCI=m +CONFIG_RT2400PCI_RFKILL=y +CONFIG_RT2400PCI_LEDS=y +CONFIG_RT2500PCI=m +CONFIG_RT2500PCI_RFKILL=y +CONFIG_RT2500PCI_LEDS=y +CONFIG_RT61PCI=m +CONFIG_RT61PCI_RFKILL=y +CONFIG_RT61PCI_LEDS=y +CONFIG_RT2500USB=m +CONFIG_RT2500USB_LEDS=y +CONFIG_RT2800USB=m +# CONFIG_RT2800USB_RT30XX is not set +# CONFIG_RT2800USB_RT35XX is not set +# CONFIG_RT2800USB_UNKNOWN is not set +CONFIG_RT2800PCI=m +# CONFIG_RT2800PCI_RT30XX is not set +# CONFIG_RT2800PCI_RT35XX is not set +CONFIG_RT73USB=m +CONFIG_RT73USB_LEDS=y +CONFIG_RTL8180=m +CONFIG_RTL8187=m +CONFIG_TMD_HERMES=m +CONFIG_USB_ZD1201=m +CONFIG_USB_NET_RNDIS_WLAN=m +CONFIG_ZD1211RW=m +# CONFIG_ZD1211RW_DEBUG is not set +CONFIG_AR9170_USB=m + +CONFIG_WL12XX=y +CONFIG_WL1251=m +CONFIG_WL1251_SPI=m +CONFIG_WL1251_SDIO=m +CONFIG_WL1271=m + +# +# Token Ring devices +# +# CONFIG_TR is not set +# CONFIG_IBMOL is not set +# CONFIG_3C359 is not set +# Broken with gcc4.1 +# CONFIG_TMS380TR is not set +# CONFIG_TMSPCI is not set +# CONFIG_ABYSS is not set +# CONFIG_IBMLS is not set +# CONFIG_PCMCIA_IBMTR is not set + + +CONFIG_NET_FC=y +# CONFIG_SHAPER is not set + +# +# Wan interfaces +# +# CONFIG_WAN is not set + +# +# PCMCIA network device support +# +CONFIG_NET_PCMCIA=y +CONFIG_PCMCIA_3C589=m +CONFIG_PCMCIA_3C574=m +CONFIG_PCMCIA_FMVJ18X=m +CONFIG_PCMCIA_PCNET=m +CONFIG_PCMCIA_NMCLAN=m +CONFIG_PCMCIA_SMC91C92=m +CONFIG_PCMCIA_XIRC2PS=m +CONFIG_PCMCIA_AXNET=m + +# +# Amateur Radio support +# +CONFIG_HAMRADIO=y +CONFIG_AX25=m +CONFIG_AX25_DAMA_SLAVE=y +CONFIG_CAN=m +CONFIG_CAN_RAW=m +CONFIG_CAN_BCM=m +CONFIG_CAN_VCAN=m +CONFIG_CAN_DEV=m +CONFIG_CAN_CALC_BITTIMING=y +CONFIG_CAN_SJA1000=m +CONFIG_CAN_SJA1000_ISA=m +CONFIG_CAN_SJA1000_PLATFORM=m +CONFIG_CAN_EMS_PCI=m +CONFIG_CAN_EMS_USB=m +CONFIG_CAN_KVASER_PCI=m +CONFIG_NETROM=m +CONFIG_ROSE=m +CONFIG_MKISS=m +CONFIG_6PACK=m +CONFIG_BPQETHER=m +CONFIG_SCC=m +CONFIG_DMASCC=m +# CONFIG_SCC_DELAY is not set +CONFIG_SCC_TRXECHO=y +CONFIG_BAYCOM_SER_FDX=m +CONFIG_BAYCOM_SER_HDX=m +CONFIG_BAYCOM_PAR=m +CONFIG_BAYCOM_EPP=m +CONFIG_YAM=m + +# +# IrDA (infrared) support +# +CONFIG_IRDA=m +# CONFIG_IRDA_DEBUG is not set +CONFIG_IRLAN=m +CONFIG_IRNET=m +CONFIG_IRCOMM=m +# CONFIG_IRDA_ULTRA is not set +CONFIG_IRDA_CACHE_LAST_LSAP=y +CONFIG_IRDA_FAST_RR=y +CONFIG_IRTTY_SIR=m +CONFIG_DONGLE=y +CONFIG_ACTISYS_DONGLE=m +CONFIG_ACT200L_DONGLE=m +CONFIG_ESI_DONGLE=m +CONFIG_GIRBIL_DONGLE=m +CONFIG_IRPORT_SIR=m +CONFIG_KINGSUN_DONGLE=m +CONFIG_KSDAZZLE_DONGLE=m +CONFIG_KS959_DONGLE=m +CONFIG_LITELINK_DONGLE=m +CONFIG_MA600_DONGLE=m +CONFIG_MCP2120_DONGLE=m +CONFIG_OLD_BELKIN_DONGLE=m +CONFIG_TEKRAM_DONGLE=m +CONFIG_TOIM3232_DONGLE=m +# CONFIG_DONGLE_OLD is not set + +CONFIG_ALI_FIR=m +CONFIG_MCS_FIR=m +CONFIG_NSC_FIR=m +CONFIG_SIGMATEL_FIR=m +CONFIG_SMC_IRCC_FIR=m +# CONFIG_TOSHIBA_FIR is not set +CONFIG_USB_IRDA=m +CONFIG_VLSI_FIR=m +CONFIG_VIA_FIR=m +CONFIG_WINBOND_FIR=m + +# +# Bluetooth support +# +CONFIG_BT=m +CONFIG_BT_L2CAP=m +CONFIG_BT_SCO=m +CONFIG_BT_CMTP=m +CONFIG_BT_RFCOMM=m +CONFIG_BT_RFCOMM_TTY=y +CONFIG_BT_BNEP=m +CONFIG_BT_BNEP_MC_FILTER=y +CONFIG_BT_BNEP_PROTO_FILTER=y +CONFIG_BT_HIDP=m + +# +# Bluetooth device drivers +# +CONFIG_BT_HCIBTUSB=m +# Disable the BT_HCIUSB driver. +# It sucks more power than BT_HCIBTUSB which has the same functionality. +# CONFIG_BT_HCIUSB is not set +CONFIG_BT_HCIUART=m +CONFIG_BT_HCIUART_H4=y +CONFIG_BT_HCIUART_BCSP=y +CONFIG_BT_HCIDTL1=m +CONFIG_BT_HCIBT3C=m +CONFIG_BT_HCIBLUECARD=m +CONFIG_BT_HCIBTUART=m +CONFIG_BT_HCIVHCI=m +CONFIG_BT_HCIUSB_SCO=y +CONFIG_BT_HCIBCM203X=m +CONFIG_BT_HCIBFUSB=m +CONFIG_BT_HCIBPA10X=m +CONFIG_BT_HCIBTSDIO=m +CONFIG_BT_HCIUART_LL=y +CONFIG_BT_MRVL=m +CONFIG_BT_MRVL_SDIO=m +CONFIG_BT_ATH3K=m + +# +# ISDN subsystem +# +CONFIG_ISDN=y +CONFIG_MISDN=m +CONFIG_MISDN_DSP=m +CONFIG_MISDN_L1OIP=m +CONFIG_MISDN_AVMFRITZ=m +CONFIG_MISDN_SPEEDFAX=m +CONFIG_MISDN_INFINEON=m +CONFIG_MISDN_W6692=m +CONFIG_MISDN_NETJET=m + +# +# mISDN hardware drivers +# +CONFIG_MISDN_HFCPCI=m +CONFIG_MISDN_HFCMULTI=m +CONFIG_ISDN_I4L=m +CONFIG_ISDN_DRV_AVMB1_B1PCI=m +CONFIG_ISDN_DRV_AVMB1_B1PCMCIA=m +CONFIG_ISDN_DRV_AVMB1_T1PCI=m +CONFIG_ISDN_DRV_AVMB1_C4=m + +CONFIG_MISDN_HFCUSB=m + +CONFIG_ISDN_PPP=y +CONFIG_ISDN_PPP_VJ=y +CONFIG_ISDN_MPP=y +# CONFIG_ISDN_PPP_BSDCOMP is not set +CONFIG_ISDN_TTY_FAX=y +CONFIG_DE_AOC=y + +CONFIG_ISDN_AUDIO=y + +CONFIG_ISDN_DRV_HISAX=m +CONFIG_ISDN_DRV_AVMB1_B1PCIV4=y +CONFIG_ISDN_DRV_AVMB1_AVM_CS=m + +CONFIG_ISDN_CAPI_CAPIDRV=m +CONFIG_ISDN_DIVERSION=m + +CONFIG_HISAX_EURO=y +CONFIG_HISAX_1TR6=y +CONFIG_HISAX_NI1=y +CONFIG_HISAX_MAX_CARDS=8 +CONFIG_HISAX_16_3=y +CONFIG_HISAX_TELESPCI=y +CONFIG_HISAX_S0BOX=y +CONFIG_HISAX_FRITZPCI=y +CONFIG_HISAX_AVM_A1_PCMCIA=y +CONFIG_HISAX_ELSA=y +CONFIG_HISAX_DIEHLDIVA=y +CONFIG_HISAX_SEDLBAUER=y +CONFIG_HISAX_NETJET=y +CONFIG_HISAX_NETJET_U=y +CONFIG_HISAX_NICCY=y +CONFIG_HISAX_BKM_A4T=y +CONFIG_HISAX_SCT_QUADRO=y +CONFIG_HISAX_GAZEL=y +CONFIG_HISAX_HFC_PCI=y +CONFIG_HISAX_W6692=y +CONFIG_HISAX_HFC_SX=y +CONFIG_HISAX_ENTERNOW_PCI=y +# CONFIG_HISAX_DEBUG is not set +CONFIG_HISAX_AVM_A1_CS=m +CONFIG_HISAX_ST5481=m +# CONFIG_HISAX_HFCUSB is not set +CONFIG_HISAX_FRITZ_PCIPNP=m +CONFIG_HISAX_NO_SENDCOMPLETE=y +CONFIG_HISAX_NO_LLC=y +CONFIG_HISAX_NO_KEYPAD=y +CONFIG_HISAX_SEDLBAUER_CS=m +CONFIG_HISAX_ELSA_CS=m +CONFIG_HISAX_TELES_CS=m +CONFIG_HISAX_HFC4S8S=m + +CONFIG_ISDN_DRV_LOOP=m +CONFIG_HYSDN=m +CONFIG_HYSDN_CAPI=y + + +# +# CAPI subsystem +# +CONFIG_ISDN_CAPI=m +# CONFIG_CAPI_TRACE is not set +CONFIG_ISDN_DRV_AVMB1_VERBOSE_REASON=y +CONFIG_ISDN_CAPI_MIDDLEWARE=y +CONFIG_ISDN_CAPI_CAPI20=m +CONFIG_ISDN_CAPI_CAPIFS_BOOL=y +CONFIG_ISDN_CAPI_CAPIFS=m + +# +# CAPI hardware drivers +# + +# +# Active AVM cards +# +CONFIG_CAPI_AVM=y + +# +# Active Eicon DIVA Server cards +# +# CONFIG_CAPI_EICON is not set +CONFIG_ISDN_DIVAS=m +CONFIG_ISDN_DIVAS_BRIPCI=y +CONFIG_ISDN_DIVAS_PRIPCI=y +CONFIG_ISDN_DIVAS_DIVACAPI=m +CONFIG_ISDN_DIVAS_USERIDI=m +CONFIG_ISDN_DIVAS_MAINT=m + +CONFIG_ISDN_DRV_GIGASET=m +CONFIG_GIGASET_CAPI=y +CONFIG_GIGASET_BASE=m +CONFIG_GIGASET_M101=m +CONFIG_GIGASET_M105=m +# CONFIG_GIGASET_DEBUG is not set +# CONFIG_GIGASET_UNDOCREQ is not set + +# +# Telephony Support +# +# CONFIG_PHONE is not set + +# +# Input device support +# +CONFIG_INPUT=y +CONFIG_INPUT_FF_MEMLESS=m + +# +# Userland interfaces +# +CONFIG_INPUT_MOUSEDEV=y +# CONFIG_INPUT_MOUSEDEV_PSAUX is not set +CONFIG_INPUT_MOUSEDEV_SCREEN_X=1024 +CONFIG_INPUT_MOUSEDEV_SCREEN_Y=768 +CONFIG_INPUT_JOYDEV=m +CONFIG_INPUT_EVDEV=y +# CONFIG_INPUT_EVBUG is not set + +CONFIG_INPUT_TABLET=y +CONFIG_TABLET_USB_ACECAD=m +CONFIG_TABLET_USB_AIPTEK=m +CONFIG_TABLET_USB_GTCO=m +CONFIG_TABLET_USB_KBTAB=m +CONFIG_TABLET_USB_WACOM=m + +CONFIG_INPUT_POWERMATE=m +CONFIG_INPUT_YEALINK=m +CONFIG_INPUT_CM109=m +CONFIG_INPUT_POLLDEV=m +CONFIG_INPUT_SPARSEKMAP=m + +# +# Input I/O drivers +# +CONFIG_GAMEPORT=m +CONFIG_GAMEPORT_NS558=m +CONFIG_GAMEPORT_L4=m +CONFIG_GAMEPORT_EMU10K1=m +CONFIG_GAMEPORT_FM801=m +CONFIG_SERIO=y +CONFIG_SERIO_I8042=y +CONFIG_SERIO_SERPORT=y +CONFIG_SERIO_RAW=m +CONFIG_SERIO_ALTERA_PS2=m + +# CONFIG_SERIO_CT82C710 is not set +# CONFIG_SERIO_PARKBD is not set +# CONFIG_SERIO_PCIPS2 is not set + +# +# Input Device Drivers +# +CONFIG_INPUT_KEYBOARD=y +CONFIG_KEYBOARD_ATKBD=y +# CONFIG_KEYBOARD_SUNKBD is not set +# CONFIG_KEYBOARD_XTKBD is not set +# CONFIG_KEYBOARD_MATRIX is not set +# CONFIG_KEYBOARD_NEWTON is not set +# CONFIG_KEYBOARD_STOWAWAY is not set +# CONFIG_KEYBOARD_LKKBD is not set +# CONFIG_KEYBOARD_LM8323 is not set +CONFIG_QT2160=m +CONFIG_KEYBOARD_ADP5588=m +CONFIG_KEYBOARD_MAX7359=m +CONFIG_KEYBOARD_OPENCORES=m +CONFIG_INPUT_MOUSE=y +CONFIG_MOUSE_PS2=y +# CONFIG_MOUSE_PS2_TOUCHKIT is not set +CONFIG_MOUSE_PS2_ELANTECH=y +CONFIG_MOUSE_PS2_SENTELIC=y +CONFIG_MOUSE_SERIAL=m +CONFIG_MOUSE_VSXXXAA=m +CONFIG_MOUSE_APPLETOUCH=m +CONFIG_MOUSE_BCM5974=m +CONFIG_MOUSE_SYNAPTICS_I2C=m +CONFIG_INPUT_JOYSTICK=y +CONFIG_JOYSTICK_ANALOG=m +CONFIG_JOYSTICK_A3D=m +CONFIG_JOYSTICK_ADI=m +CONFIG_JOYSTICK_COBRA=m +CONFIG_JOYSTICK_GF2K=m +CONFIG_JOYSTICK_GRIP=m +CONFIG_JOYSTICK_GRIP_MP=m +CONFIG_JOYSTICK_GUILLEMOT=m +CONFIG_JOYSTICK_INTERACT=m +CONFIG_JOYSTICK_SIDEWINDER=m +CONFIG_JOYSTICK_TMDC=m +CONFIG_JOYSTICK_IFORCE=m +CONFIG_JOYSTICK_IFORCE_USB=y +CONFIG_JOYSTICK_IFORCE_232=y +CONFIG_JOYSTICK_WARRIOR=m +CONFIG_JOYSTICK_MAGELLAN=m +CONFIG_JOYSTICK_SPACEORB=m +CONFIG_JOYSTICK_SPACEBALL=m +CONFIG_JOYSTICK_STINGER=m +CONFIG_JOYSTICK_DB9=m +CONFIG_JOYSTICK_GAMECON=m +CONFIG_JOYSTICK_TURBOGRAFX=m +CONFIG_JOYSTICK_JOYDUMP=m +CONFIG_JOYSTICK_TWIDJOY=m +CONFIG_JOYSTICK_WALKERA0701=m +CONFIG_JOYSTICK_XPAD=m +CONFIG_JOYSTICK_XPAD_FF=y +CONFIG_JOYSTICK_XPAD_LEDS=y +CONFIG_JOYSTICK_ZHENHUA=m +CONFIG_INPUT_TOUCHSCREEN=y +CONFIG_TOUCHSCREEN_GUNZE=m +CONFIG_TOUCHSCREEN_ELO=m +CONFIG_TOUCHSCREEN_FUJITSU=m +CONFIG_TOUCHSCREEN_HTCPEN=m +CONFIG_TOUCHSCREEN_INEXIO=m +CONFIG_TOUCHSCREEN_MTOUCH=m +CONFIG_TOUCHSCREEN_MK712=m +CONFIG_TOUCHSCREEN_PENMOUNT=m +CONFIG_TOUCHSCREEN_TSC2007=m +CONFIG_TOUCHSCREEN_AD7879_I2C=m +CONFIG_TOUCHSCREEN_TOUCHIT213=m +CONFIG_TOUCHSCREEN_TOUCHRIGHT=m +CONFIG_TOUCHSCREEN_TOUCHWIN=m +CONFIG_TOUCHSCREEN_UCB1400=m +CONFIG_TOUCHSCREEN_WACOM_W8001=m +CONFIG_TOUCHSCREEN_USB_E2I=y +CONFIG_TOUCHSCREEN_USB_COMPOSITE=m +CONFIG_TOUCHSCREEN_DYNAPRO=m +# CONFIG_TOUCHSCREEN_WM97XX is not set +CONFIG_TOUCHSCREEN_EETI=m +CONFIG_TOUCHSCREEN_W90X900=m +CONFIG_TOUCHSCREEN_MCS5000=m +CONFIG_INPUT_MISC=y +CONFIG_INPUT_PCSPKR=m +CONFIG_INPUT_UINPUT=m +CONFIG_INPUT_WISTRON_BTNS=m +CONFIG_INPUT_ATLAS_BTNS=m + +CONFIG_INPUT_ATI_REMOTE=m +CONFIG_INPUT_ATI_REMOTE2=m +CONFIG_INPUT_KEYSPAN_REMOTE=m +CONFIG_INPUT_IMON=m + +CONFIG_MAC_EMUMOUSEBTN=y + +CONFIG_INPUT_WM831X_ON=m + +CONFIG_INPUT_APPLEIR=m + +# +# Character devices +# +CONFIG_VT=y +CONFIG_VT_CONSOLE=y +CONFIG_HW_CONSOLE=y +CONFIG_VT_HW_CONSOLE_BINDING=y +CONFIG_SERIAL_NONSTANDARD=y +CONFIG_ROCKETPORT=m +CONFIG_SYNCLINK=m +CONFIG_SYNCLINKMP=m +CONFIG_SYNCLINK_GT=m +CONFIG_N_HDLC=m +# CONFIG_STALDRV is not set +# CONFIG_IBM_ASM is not set +CONFIG_TIFM_CORE=m +CONFIG_TIFM_7XX1=m +CONFIG_TCG_TPM=m +CONFIG_TCG_TIS=m +CONFIG_TCG_NSC=m +CONFIG_TCG_ATMEL=m +# CONFIG_TCG_INFINEON is not set +CONFIG_TELCLOCK=m + +# +# Serial drivers +# +CONFIG_SERIAL_8250=y +CONFIG_SERIAL_8250_CONSOLE=y +CONFIG_SERIAL_8250_CS=m +CONFIG_SERIAL_8250_NR_UARTS=32 +CONFIG_SERIAL_8250_RUNTIME_UARTS=4 +CONFIG_SERIAL_8250_EXTENDED=y +CONFIG_SERIAL_8250_MANY_PORTS=y +CONFIG_SERIAL_8250_SHARE_IRQ=y +CONFIG_SERIAL_8250_DETECT_IRQ=y +CONFIG_SERIAL_8250_RSA=y +# CONFIG_COMPUTONE is not set +CONFIG_CYCLADES=m +# CONFIG_CYZ_INTR is not set +# CONFIG_DIGIEPCA is not set +# CONFIG_ESPSERIAL is not set +# CONFIG_MOXA_INTELLIO is not set +# CONFIG_MOXA_SMARTIO is not set +# CONFIG_MOXA_SMARTIO_NEW is not set +# CONFIG_ISI is not set +# CONFIG_RISCOM8 is not set +# CONFIG_SPECIALIX is not set +# CONFIG_SX is not set +# CONFIG_RIO is not set +# CONFIG_STALLION is not set +# CONFIG_ISTALLION is not set +CONFIG_SERIAL_JSM=m + +# +# Non-8250 serial port support +# +CONFIG_SERIAL_CORE=y +CONFIG_SERIAL_CORE_CONSOLE=y +CONFIG_UNIX98_PTYS=y +CONFIG_DEVPTS_MULTIPLE_INSTANCES=y +# CONFIG_LEGACY_PTYS is not set +CONFIG_PRINTER=m +CONFIG_LP_CONSOLE=y +CONFIG_PPDEV=m + +# +# I2C support +# +CONFIG_I2C=m +CONFIG_I2C_COMPAT=y +CONFIG_I2C_CHARDEV=m + +# +# I2C Algorithms +# +# CONFIG_I2C_DEBUG_ALGO is not set +CONFIG_I2C_HELPER_AUTO=y +CONFIG_I2C_ALGOBIT=m +CONFIG_I2C_ALGOPCF=m + +# +# I2C Hardware Bus support +# + +CONFIG_I2C_ALGOPCA=m +# CONFIG_I2C_ALI1535 is not set +# CONFIG_I2C_ALI1563 is not set +# CONFIG_I2C_ALI15X3 is not set +# CONFIG_I2C_AMD756 is not set +# CONFIG_I2C_AMD756_S4882 is not set +# CONFIG_I2C_AMD8111 is not set +# CONFIG_I2C_DEBUG_CORE is not set +# CONFIG_I2C_DEBUG_BUS is not set +# CONFIG_I2C_DEBUG_CHIP is not set +# CONFIG_I2C_ELEKTOR is not set +# CONFIG_I2C_I801 is not set +# CONFIG_I2C_I810 is not set +# CONFIG_I2C_ISCH is not set +# CONFIG_I2C_NFORCE2_S4985 is not set + +CONFIG_EEPROM_AT24=m +CONFIG_EEPROM_LEGACY=m +CONFIG_EEPROM_93CX6=m +CONFIG_EEPROM_MAX6875=m + +CONFIG_I2C_NFORCE2=m +# CONFIG_I2C_OCORES is not set +CONFIG_I2C_PARPORT=m +CONFIG_I2C_PARPORT_LIGHT=m +CONFIG_I2C_PASEMI=m +CONFIG_I2C_PCA_ISA=m +CONFIG_I2C_PCA_PLATFORM=m +# CONFIG_I2C_PIIX4 is not set +CONFIG_I2C_PROSAVAGE=m +CONFIG_I2C_SAVAGE4=m +# CONFIG_SCx200_ACB is not set +# CONFIG_I2C_SIS5595 is not set +# CONFIG_I2C_SIS630 is not set +# CONFIG_I2C_SIS96X is not set +CONFIG_I2C_SIMTEC=m +CONFIG_I2C_STUB=m +CONFIG_I2C_TINY_USB=m +# CONFIG_I2C_TAOS_EVM is not set +# CONFIG_I2C_VIA is not set +# CONFIG_I2C_VIAPRO is not set +CONFIG_I2C_VOODOO3=m +# CONFIG_I2C_DESIGNWARE is not set + +# +# I2C Hardware Sensors Chip support +# +CONFIG_SENSORS_ATK0110=m +CONFIG_SENSORS_ABITUGURU=m +CONFIG_SENSORS_ABITUGURU3=m +CONFIG_SENSORS_AD7414=m +CONFIG_SENSORS_AD7418=m +CONFIG_SENSORS_ADM1021=m +CONFIG_SENSORS_ADM1025=m +CONFIG_SENSORS_ADM1026=m +CONFIG_SENSORS_ADM1029=m +CONFIG_SENSORS_ADM1031=m +CONFIG_SENSORS_ADM9240=m +CONFIG_SENSORS_ADS7828=m +CONFIG_SENSORS_ADT7462=m +CONFIG_SENSORS_ADT7470=m +CONFIG_SENSORS_ADT7473=m +CONFIG_SENSORS_ADT7475=m +CONFIG_SENSORS_APPLESMC=m +CONFIG_SENSORS_ASB100=m +CONFIG_SENSORS_ATXP1=m +CONFIG_SENSORS_CORETEMP=m +CONFIG_SENSORS_DME1737=m +CONFIG_SENSORS_DS1621=m +CONFIG_SENSORS_DS1337=m +CONFIG_SENSORS_DS1374=m +# CONFIG_DS1682 is not set +CONFIG_SENSORS_FSCHER=m +CONFIG_SENSORS_FSCPOS=m +CONFIG_SENSORS_F71805F=m +CONFIG_SENSORS_F71882FG=m +CONFIG_SENSORS_F75375S=m +CONFIG_SENSORS_FSCHMD=m +CONFIG_SENSORS_G760A=m +CONFIG_SENSORS_GL518SM=m +CONFIG_SENSORS_GL520SM=m +CONFIG_SENSORS_HDAPS=m +# CONFIG_SENSORS_I5K_AMB is not set +# FIXME: IBMAEM x86 only? +CONFIG_SENSORS_IBMAEM=m +CONFIG_SENSORS_IBMPEX=m +CONFIG_SENSORS_IT87=m +CONFIG_SENSORS_K8TEMP=m +CONFIG_SENSORS_K10TEMP=m +CONFIG_SENSORS_LIS3LV02D=m +CONFIG_SENSORS_LIS3_I2C=m +CONFIG_SENSORS_LM63=m +CONFIG_SENSORS_LM75=m +CONFIG_SENSORS_LM77=m +CONFIG_SENSORS_LM78=m +CONFIG_SENSORS_LM80=m +CONFIG_SENSORS_LM83=m +CONFIG_SENSORS_LM85=m +CONFIG_SENSORS_LM87=m +CONFIG_SENSORS_LM90=m +CONFIG_SENSORS_LM92=m +CONFIG_SENSORS_LM93=m +CONFIG_SENSORS_LTC4245=m +CONFIG_SENSORS_MAX1619=m +CONFIG_SENSORS_MAX6650=m +CONFIG_SENSORS_MAX6875=m +CONFIG_SENSORS_PC87360=m +CONFIG_SENSORS_PC87427=m +CONFIG_SENSORS_PCA9539=m +CONFIG_SENSORS_PCF8574=m +CONFIG_SENSORS_PCF8591=m +CONFIG_SENSORS_SHT15=m +CONFIG_SENSORS_SIS5595=m +CONFIG_SENSORS_SMSC47M1=m +CONFIG_SENSORS_SMSC47M192=m +CONFIG_SENSORS_SMSC47B397=m +CONFIG_SENSORS_THMC50=m +CONFIG_SENSORS_TMP401=m +CONFIG_SENSORS_TSL2550=m +CONFIG_SENSORS_VIA686A=m +CONFIG_SENSORS_VIA_CPUTEMP=m +CONFIG_SENSORS_VT1211=m +CONFIG_SENSORS_VT8231=m +CONFIG_SENSORS_W83627HF=m +CONFIG_SENSORS_W83781D=m +CONFIG_SENSORS_W83L785TS=m +CONFIG_SENSORS_W83L786NG=m +CONFIG_SENSORS_W83627EHF=m +CONFIG_SENSORS_W83791D=m +CONFIG_SENSORS_W83792D=m +CONFIG_SENSORS_W83793=m +CONFIG_SENSORS_LTC4215=m +CONFIG_SENSORS_LM95241=m +CONFIG_SENSORS_TMP421=m +CONFIG_SENSORS_WM8350=m +CONFIG_SENSORS_WM831X=m +CONFIG_SENSORS_LM73=m +CONFIG_SENSORS_AMC6821=m + +CONFIG_W1=m +CONFIG_W1_CON=y +# This is busted. +# If we enable it, it steals Matrox cards, and the +# framebuffer drivers stop working. +# CONFIG_W1_MASTER_MATROX is not set +CONFIG_W1_MASTER_DS2482=m +CONFIG_W1_MASTER_DS2490=m +CONFIG_W1_MASTER_DS1WM=m +CONFIG_W1_SLAVE_THERM=m +CONFIG_W1_SLAVE_SMEM=m +CONFIG_W1_SLAVE_DS2431=m +CONFIG_W1_SLAVE_DS2433=m +CONFIG_W1_SLAVE_DS2433_CRC=y +CONFIG_W1_SLAVE_DS2760=m +# +# Mice +# + +# +# IPMI +# +CONFIG_IPMI_HANDLER=m +# CONFIG_IPMI_PANIC_EVENT is not set +CONFIG_IPMI_DEVICE_INTERFACE=m +CONFIG_IPMI_WATCHDOG=m +CONFIG_IPMI_SI=m +CONFIG_IPMI_POWEROFF=m + +# +# Watchdog Cards +# +CONFIG_WATCHDOG=y +# CONFIG_WATCHDOG_NOWAYOUT is not set +CONFIG_SOFT_WATCHDOG=m +# CONFIG_WDT_501 is not set +CONFIG_WDTPCI=m +CONFIG_WDT_501_PCI=y +# CONFIG_ACQUIRE_WDT is not set +# CONFIG_ADVANTECH_WDT is not set +# CONFIG_EUROTECH_WDT is not set +# CONFIG_IB700_WDT is not set +# CONFIG_MIXCOMWD is not set +# CONFIG_SCx200_WDT is not set +# CONFIG_60XX_WDT is not set +CONFIG_W83877F_WDT=m +CONFIG_W83627HF_WDT=m +CONFIG_MACHZ_WDT=m +# CONFIG_SC520_WDT is not set +CONFIG_ALIM7101_WDT=m +CONFIG_ALIM1535_WDT=m +CONFIG_ITCO_WDT=m +CONFIG_ITCO_VENDOR_SUPPORT=y +# CONFIG_SC1200_WDT is not set +# CONFIG_PC87413_WDT is not set +# CONFIG_WAFER_WDT is not set +# CONFIG_CPU5_WDT is not set +CONFIG_I6300ESB_WDT=m +CONFIG_IT8712F_WDT=m +# CONFIG_SBC8360_WDT is not set +# CONFIG_SBC7240_WDT is not set +CONFIG_SMSC_SCH311X_WDT=m +CONFIG_W83977F_WDT=m +CONFIG_PCIPCWATCHDOG=m +CONFIG_USBPCWATCHDOG=m +# CONFIG_SBC_EPX_C3_WATCHDOG is not set +CONFIG_WM8350_WATCHDOG=m +CONFIG_WM831X_WATCHDOG=m + +CONFIG_HW_RANDOM=y +CONFIG_HW_RANDOM_TIMERIOMEM=m +# CONFIG_NVRAM is not set +# CONFIG_RTC is not set +# CONFIG_RTC_DEBUG is not set +# CONFIG_GEN_RTC is not set +CONFIG_RTC_CLASS=y +CONFIG_RTC_HCTOSYS=y +CONFIG_RTC_HCTOSYS_DEVICE="rtc0" +CONFIG_RTC_INTF_SYSFS=y +CONFIG_RTC_INTF_PROC=y +CONFIG_RTC_INTF_DEV=y +# CONFIG_RTC_INTF_DEV_UIE_EMUL is not set +CONFIG_RTC_DRV_CMOS=y +CONFIG_RTC_DRV_DS1307=m +CONFIG_RTC_DRV_DS1553=m +CONFIG_RTC_DRV_DS1672=m +CONFIG_RTC_DRV_DS1742=m +CONFIG_RTC_DRV_DS1374=m +# CONFIG_RTC_DRV_EP93XX is not set +CONFIG_RTC_DRV_FM3130=m +CONFIG_RTC_DRV_ISL1208=m +CONFIG_RTC_DRV_M41T80=m +CONFIG_RTC_DRV_M41T80_WDT=y +CONFIG_RTC_DRV_M48T59=m +CONFIG_RTC_DRV_MAX6900=m +# CONFIG_RTC_DRV_M48T86 is not set +CONFIG_RTC_DRV_PCF8563=m +CONFIG_RTC_DRV_PCF8583=m +CONFIG_RTC_DRV_RS5C372=m +# CONFIG_RTC_DRV_SA1100 is not set +# CONFIG_RTC_DRV_TEST is not set +CONFIG_RTC_DRV_X1205=m +CONFIG_RTC_DRV_V3020=m +CONFIG_RTC_DRV_STK17TA8=m +# CONFIG_RTC_DRV_S35390A is not set +CONFIG_RTC_DRV_RX8581=m +CONFIG_RTC_DRV_RX8025=m +CONFIG_RTC_DRV_DS1286=m +CONFIG_RTC_DRV_M48T35=m +CONFIG_RTC_DRV_BQ4802=m +CONFIG_RTC_DRV_WM8350=m +CONFIG_RTC_DRV_AB3100=m +CONFIG_RTC_DRV_WM831X=m +CONFIG_RTC_DRV_BQ32K=m +CONFIG_RTC_DRV_MSM6242=m +CONFIG_RTC_DRV_RP5C01=m + +CONFIG_DTLK=m +CONFIG_R3964=m +# CONFIG_APPLICOM is not set +# CONFIG_SONYPI is not set + +# +# Ftape, the floppy tape device driver +# +CONFIG_AGP=y +CONFIG_AGP_ALI=y +CONFIG_AGP_ATI=y +CONFIG_AGP_AMD=y +CONFIG_AGP_AMD64=y +CONFIG_AGP_INTEL=y +CONFIG_AGP_NVIDIA=y +CONFIG_AGP_SIS=y +CONFIG_AGP_SWORKS=y +CONFIG_AGP_VIA=y +CONFIG_AGP_EFFICEON=y +CONFIG_VGA_ARB=y +CONFIG_DRM=m +CONFIG_DRM_TDFX=m +CONFIG_DRM_R128=m +CONFIG_DRM_RADEON=m +CONFIG_DRM_RADEON_KMS=y +CONFIG_DRM_I810=m +# CONFIG_DRM_I830 is not set +CONFIG_DRM_MGA=m +CONFIG_DRM_SIS=m +CONFIG_DRM_SAVAGE=m +CONFIG_DRM_I915=m +CONFIG_DRM_I915_KMS=y +CONFIG_DRM_VIA=m +CONFIG_DRM_NOUVEAU=m +CONFIG_DRM_NOUVEAU_KMS=y +CONFIG_DRM_NOUVEAU_BACKLIGHT=y +CONFIG_DRM_NOUVEAU_DEBUG=y +CONFIG_DRM_I2C_CH7006=m +CONFIG_DRM_VMWGFX=n + +# +# PCMCIA character devices +# +# CONFIG_SYNCLINK_CS is not set + +CONFIG_CARDMAN_4000=m +CONFIG_CARDMAN_4040=m + +CONFIG_MWAVE=m +CONFIG_RAW_DRIVER=y +CONFIG_MAX_RAW_DEVS=8192 +CONFIG_HANGCHECK_TIMER=m + +# +# Multimedia devices +# +CONFIG_MEDIA_SUPPORT=m +CONFIG_VIDEO_DEV=m +# CONFIG_VIDEO_ADV_DEBUG is not set +CONFIG_VIDEO_HELPER_CHIPS_AUTO=y +CONFIG_VIDEO_ALLOW_V4L1=y +CONFIG_VIDEO_V4L1_COMPAT=y +CONFIG_VIDEO_V4L2=y +# CONFIG_VIDEO_VIVI is not set + +# +# Video For Linux +# + +# +# Video Adapters +# +CONFIG_V4L_USB_DRIVERS=y +CONFIG_VIDEO_CAPTURE_DRIVERS=y +CONFIG_VIDEO_AU0828=m +CONFIG_VIDEO_BT848=m +CONFIG_VIDEO_BT848_DVB=y +CONFIG_VIDEO_BWQCAM=m +# CONFIG_VIDEO_CAFE_CCIC is not set +# CONFIG_VIDEO_CPIA is not set +CONFIG_VIDEO_CPIA2=m +CONFIG_VIDEO_CQCAM=m +CONFIG_VIDEO_CX23885=m +CONFIG_VIDEO_CX18=m +CONFIG_VIDEO_CX88=m +CONFIG_VIDEO_CX88_DVB=m +CONFIG_VIDEO_CX88_ALSA=m +CONFIG_VIDEO_CX88_BLACKBIRD=m +CONFIG_VIDEO_CX88_VP3054=m +CONFIG_VIDEO_DPC=m +CONFIG_VIDEO_EM28XX=m +CONFIG_VIDEO_EM28XX_ALSA=m +CONFIG_VIDEO_EM28XX_DVB=m +CONFIG_VIDEO_CX231XX=m +CONFIG_VIDEO_CX231XX_ALSA=m +CONFIG_VIDEO_CX231XX_DVB=m +CONFIG_VIDEO_HEXIUM_ORION=m +CONFIG_VIDEO_HEXIUM_GEMINI=m +CONFIG_VIDEO_IVTV=m +CONFIG_VIDEO_MEYE=m +CONFIG_VIDEO_MXB=m +# CONFIG_VIDEO_OVCAMCHIP is not set +CONFIG_VIDEO_PVRUSB2_DVB=y +CONFIG_VIDEO_HDPVR=m +CONFIG_VIDEO_SAA5246A=m +CONFIG_VIDEO_SAA5249=m +CONFIG_VIDEO_SAA6588=m +CONFIG_VIDEO_SAA7134=m +CONFIG_VIDEO_SAA7134_ALSA=m +CONFIG_VIDEO_SAA7134_DVB=m +CONFIG_VIDEO_STRADIS=m +CONFIG_VIDEO_USBVISION=m +CONFIG_VIDEO_W9966=m +CONFIG_VIDEO_ZORAN=m +CONFIG_VIDEO_ZORAN_AVS6EYES=m +CONFIG_VIDEO_ZORAN_BUZ=m +CONFIG_VIDEO_ZORAN_DC10=m +CONFIG_VIDEO_ZORAN_DC30=m +CONFIG_VIDEO_ZORAN_LML33=m +CONFIG_VIDEO_ZORAN_LML33R10=m +CONFIG_VIDEO_ZORAN_ZR36060=m +CONFIG_VIDEO_FB_IVTV=m +CONFIG_VIDEO_SAA7164=m + +CONFIG_USB_VIDEO_CLASS=m +CONFIG_USB_VIDEO_CLASS_INPUT_EVDEV=y + +# +# Radio Adapters +# +CONFIG_RADIO_GEMTEK_PCI=m +CONFIG_RADIO_MAXIRADIO=m +CONFIG_RADIO_MAESTRO=m + +CONFIG_MEDIA_ATTACH=y +CONFIG_MEDIA_TUNER_CUSTOMISE=y +CONFIG_MEDIA_TUNER_SIMPLE=m +CONFIG_MEDIA_TUNER_TDA8290=m +CONFIG_MEDIA_TUNER_TEA5761=m +CONFIG_MEDIA_TUNER_TEA5767=m +CONFIG_MEDIA_TUNER_MT20XX=m +CONFIG_MEDIA_TUNER_MT2060=m +CONFIG_MEDIA_TUNER_MT2266=m +CONFIG_MEDIA_TUNER_MT2131=m +CONFIG_MEDIA_TUNER_QT1010=m +CONFIG_MEDIA_TUNER_XC2028=m +CONFIG_MEDIA_TUNER_XC5000=m +CONFIG_MEDIA_TUNER_MXL5005S=m +CONFIG_MEDIA_TUNER_MXL5007T=m +CONFIG_MEDIA_TUNER_MC44S803=m +CONFIG_MEDIA_TUNER_MAX2165=m + +# +# Digital Video Broadcasting Devices +# +CONFIG_DVB_CAPTURE_DRIVERS=y +CONFIG_DVB_CORE=m +CONFIG_DVB_MAX_ADAPTERS=8 +CONFIG_DVB_DYNAMIC_MINORS=y + +CONFIG_DVB_FE_CUSTOMISE=y +CONFIG_DVB_STB0899=m +CONFIG_DVB_STB6100=m +CONFIG_DVB_STV090x=m +CONFIG_DVB_STV6110x=m +CONFIG_DVB_CX24110=m +CONFIG_DVB_CX24123=m +CONFIG_DVB_MT312=m +CONFIG_DVB_ZL10036=m +CONFIG_DVB_ZL10039=m +CONFIG_DVB_S5H1420=m +CONFIG_DVB_STV0288=m +CONFIG_DVB_STB6000=m +CONFIG_DVB_STV6110=m +CONFIG_DVB_STV0900=m +CONFIG_DVB_TDA8083=m +CONFIG_DVB_TDA10086=m +CONFIG_DVB_TDA8261=m +CONFIG_DVB_VES1X93=m +CONFIG_DVB_TUNER_ITD1000=m +CONFIG_DVB_TUNER_CX24113=m +CONFIG_DVB_TDA826X=m +CONFIG_DVB_TUA6100=m +CONFIG_DVB_CX24116=m +CONFIG_DVB_SI21XX=m +CONFIG_DVB_DS3000=m +CONFIG_DVB_SP8870=m +CONFIG_DVB_SP887X=m +CONFIG_DVB_CX22700=m +CONFIG_DVB_CX22702=m +CONFIG_DVB_L64781=m +CONFIG_DVB_NXT6000=m +CONFIG_DVB_MT352=m +CONFIG_DVB_DIB7000M=m +CONFIG_DVB_DIB7000P=m +CONFIG_DVB_TDA10048=m +CONFIG_DVB_VES1820=m +CONFIG_DVB_TDA10021=m +CONFIG_DVB_TDA10023=m +CONFIG_DVB_STV0297=m +CONFIG_DVB_NXT200X=m +CONFIG_DVB_OR51211=m +CONFIG_DVB_OR51132=m +CONFIG_DVB_BCM3510=m +CONFIG_DVB_LGDT330X=m +CONFIG_DVB_LGDT3305=m +CONFIG_DVB_S5H1409=m +CONFIG_DVB_AU8522=m +CONFIG_DVB_S5H1411=m +CONFIG_DVB_DIB8000=m +CONFIG_DVB_TUNER_DIB0070=m +CONFIG_DVB_TUNER_DIB0090=m +CONFIG_DVB_LNBP21=m +CONFIG_DVB_ISL6421=m +CONFIG_DVB_ISL6423=m +CONFIG_DVB_LGS8GXX=m +CONFIG_DVB_ATBM8830=m +CONFIG_DVB_TDA665x=m + +# +# Supported Frontend Modules +# +CONFIG_DVB_BT8XX=m +CONFIG_DVB_BUDGET_CORE=m +CONFIG_DVB_PLUTO2=m +CONFIG_SMS_SIANO_MDTV=m +CONFIG_SMS_USB_DRV=m +CONFIG_SMS_SDIO_DRV=m +CONFIG_DVB_TTUSB_DEC=m +CONFIG_DVB_USB_DTV5100=m +CONFIG_DVB_USB_AF9015=m +CONFIG_DVB_USB_ANYSEE=m +CONFIG_DVB_USB_DW2102=m +CONFIG_DVB_USB_FRIIO=m +CONFIG_DVB_USB_EC168=m +CONFIG_DVB_DM1105=m +CONFIG_DVB_DRX397XD=m +CONFIG_DVB_LGDT3304=m +CONFIG_DVB_S921=m +CONFIG_DVB_ISL6405=m +CONFIG_DVB_LGS8GL5=m +CONFIG_DVB_DUMMY_FE=m +CONFIG_DVB_FIREDTV=m + +# +# Supported SAA7146 based PCI Adapters +# +CONFIG_DVB_AV7110=m +CONFIG_DVB_AV7110_OSD=y +CONFIG_DVB_BUDGET=m +CONFIG_DVB_BUDGET_CI=m +CONFIG_DVB_BUDGET_AV=m +CONFIG_DVB_BUDGET_PATCH=m + +# +# Supported USB Adapters +# +CONFIG_DVB_TTUSB_BUDGET=m + +# +# Supported FlexCopII (B2C2) Adapters +# +CONFIG_DVB_USB_CINERGY_T2=m +CONFIG_DVB_B2C2_FLEXCOP=m +CONFIG_DVB_B2C2_FLEXCOP_PCI=m +CONFIG_DVB_B2C2_FLEXCOP_USB=m +# CONFIG_DVB_B2C2_FLEXCOP_DEBUG is not set +CONFIG_DVB_USB=m +# CONFIG_DVB_USB_DEBUG is not set +CONFIG_DVB_USB_A800=m +CONFIG_DVB_USB_AF9005=m +CONFIG_DVB_USB_AF9005_REMOTE=m +CONFIG_DVB_USB_AU6610=m +CONFIG_DVB_USB_CXUSB=m +CONFIG_DVB_USB_DIBUSB_MB=m +# CONFIG_DVB_USB_DIBUSB_MB_FAULTY is not set +CONFIG_DVB_USB_DIBUSB_MC=m +CONFIG_DVB_USB_DIB0700=m +CONFIG_DVB_USB_DIGITV=m +CONFIG_DVB_USB_DTT200U=m +CONFIG_DVB_USB_GL861=m +CONFIG_DVB_USB_GP8PSK=m +CONFIG_DVB_USB_M920X=m +CONFIG_DVB_USB_NOVA_T_USB2=m +CONFIG_DVB_USB_CE6230=m +CONFIG_DVB_USB_OPERA1=m +CONFIG_DVB_USB_TTUSB2=m +CONFIG_DVB_USB_UMT_010=m +CONFIG_DVB_USB_VP702X=m +CONFIG_DVB_USB_VP7045=m + +CONFIG_DVB_PT1=m + +CONFIG_MANTIS_CORE=m +CONFIG_DVB_MANTIS=m +CONFIG_DVB_HOPPER=m + +CONFIG_VIDEO_SAA7146=m +CONFIG_VIDEO_SAA7146_VV=m +CONFIG_VIDEO_TUNER=m +# CONFIG_VIDEO_TUNER_CUSTOMISE is not set +CONFIG_VIDEO_BTCX=m +CONFIG_VIDEO_PVRUSB2=m +CONFIG_VIDEO_PVRUSB2_24XXX=y +CONFIG_VIDEO_PVRUSB2_29XXX=y +CONFIG_VIDEO_PVRUSB2_SYSFS=y +# CONFIG_VIDEO_PVRUSB2_DEBUGIFC is not set + +# +# Broadcom Crystal HD video decoder driver +# +CONFIG_CRYSTALHD=m + +# +# Graphics support +# + +CONFIG_DISPLAY_SUPPORT=m +CONFIG_VIDEO_OUTPUT_CONTROL=m + +CONFIG_FB=y +CONFIG_VIDEO_SELECT=y +# CONFIG_FB_FOREIGN_ENDIAN is not set +CONFIG_FB_3DFX=m +CONFIG_FB_3DFX_ACCEL=y +CONFIG_FB_3DFX_I2C=y +# CONFIG_FB_ARC is not set +# CONFIG_FB_ARK is not set +CONFIG_FB_ATY128=m +CONFIG_FB_ATY=m +CONFIG_FB_ATY_CT=y +CONFIG_FB_ATY_GX=y +CONFIG_FB_ATY_GENERIC_LCD=y +# CONFIG_FB_ASILIANT is not set +# CONFIG_FB_CARMINE is not set +CONFIG_FB_CIRRUS=m +# CONFIG_FB_CYBER2000 is not set +# CONFIG_FB_CYBLA is not set +# CONFIG_FB_GEODE is not set +# CONFIG_FB_HECUBA is not set +# CONFIG_FB_HGA is not set +CONFIG_FB_I810=m +CONFIG_FB_I810_GTF=y +CONFIG_FB_I810_I2C=y +# CONFIG_FB_IMSTT is not set +# CONFIG_FB_IMAC is not set +# CONFIG_FB_INTEL is not set +# CONFIG_FB_INTEL_DEBUG is not set +# CONFIG_FB_INTEL_I2C is not set +CONFIG_FB_KYRO=m +# CONFIG_FB_LE80578 is not set +CONFIG_FB_MATROX=m +CONFIG_FB_MATROX_MILLENIUM=y +CONFIG_FB_MATROX_MYSTIQUE=y +CONFIG_FB_MATROX_G=y +CONFIG_FB_MATROX_I2C=m +CONFIG_FB_MATROX_MAVEN=m +CONFIG_FB_MATROX_MULTIHEAD=y +CONFIG_FB_NEOMAGIC=m +CONFIG_FB_NVIDIA=m +# CONFIG_FB_NVIDIA_DEBUG is not set +CONFIG_FB_NVIDIA_I2C=y +# CONFIG_FB_PM2 is not set +# CONFIG_FB_PM2_FIFO_DISCONNECT is not set +# CONFIG_FB_PM3 is not set +CONFIG_FB_RADEON=m +# CONFIG_FB_RADEON_DEBUG is not set +CONFIG_FB_RADEON_I2C=y +CONFIG_FB_RIVA=m +# CONFIG_FB_RIVA_DEBUG is not set +# CONFIG_FB_RIVA_I2C is not set +# CONFIG_FB_S1D13XXX is not set +CONFIG_FB_S3=m +CONFIG_FB_SAVAGE=m +CONFIG_FB_SAVAGE_I2C=y +CONFIG_FB_SAVAGE_ACCEL=y +# CONFIG_FB_SIS is not set +CONFIG_FB_SIS_300=y +CONFIG_FB_SIS_315=y +CONFIG_FB_SM501=m +CONFIG_FB_TILEBLITTING=y +CONFIG_FB_TRIDENT=m +CONFIG_FB_TRIDENT_ACCEL=y +# CONFIG_FB_UVESA is not set +CONFIG_FB_VESA=y +CONFIG_FB_VGA16=m +CONFIG_FB_VIRTUAL=m +CONFIG_FB_VOODOO1=m +# CONFIG_FB_VT8623 is not set +CONFIG_FB_EFI=y +CONFIG_FB_VIA=m +CONFIG_FB_METRONOME=m +CONFIG_FB_MB862XX=m +CONFIG_FB_MB862XX_PCI_GDC=y +CONFIG_FB_MB862XX_LIME=y +# CONFIG_FB_PRE_INIT_FB is not set +# CONFIG_FB_TMIO is not set +# CONFIG_FB_BROADSHEET is not set + +# CONFIG_FIRMWARE_EDID is not set + +# +# Console display driver support +# +CONFIG_VGA_CONSOLE=y +CONFIG_VGACON_SOFT_SCROLLBACK=y +CONFIG_VGACON_SOFT_SCROLLBACK_SIZE=64 +# CONFIG_MDA_CONSOLE is not set +CONFIG_DUMMY_CONSOLE=y +CONFIG_FRAMEBUFFER_CONSOLE=y +CONFIG_FRAMEBUFFER_CONSOLE_ROTATION=y +CONFIG_FRAMEBUFFER_CONSOLE_DETECT_PRIMARY=y +# CONFIG_FONTS is not set + +# +# Logo configuration +# +CONFIG_LOGO=y +# CONFIG_LOGO_LINUX_MONO is not set +# CONFIG_LOGO_LINUX_VGA16 is not set +CONFIG_LOGO_LINUX_CLUT224=y + +# +# Sound +# +CONFIG_SOUND=m + +# +# Advanced Linux Sound Architecture +# +CONFIG_SND=y +CONFIG_SOUND_OSS_CORE_PRECLAIM=y +# CONFIG_SND_DEBUG_VERBOSE is not set +CONFIG_SND_VERBOSE_PROCFS=y +CONFIG_SND_SEQUENCER=y +CONFIG_SND_HRTIMER=y +CONFIG_SND_SEQ_HRTIMER_DEFAULT=y +CONFIG_SND_SEQ_DUMMY=m +CONFIG_SND_SEQUENCER_OSS=y +CONFIG_SND_SEQ_RTCTIMER_DEFAULT=y +CONFIG_SND_OSSEMUL=y +CONFIG_SND_MIXER_OSS=y +CONFIG_SND_PCM_OSS=y +CONFIG_SND_PCM_OSS_PLUGINS=y +CONFIG_SND_RTCTIMER=y +CONFIG_SND_DYNAMIC_MINORS=y +# CONFIG_SND_SUPPORT_OLD_API is not set + +# +# Generic devices +# +CONFIG_SND_DUMMY=m +CONFIG_SND_VIRMIDI=m +CONFIG_SND_MTPAV=m +CONFIG_SND_MTS64=m +CONFIG_SND_SERIAL_U16550=m +CONFIG_SND_MPU401=m +CONFIG_SND_PORTMAN2X4=m +CONFIG_SND_AC97_POWER_SAVE=y +CONFIG_SND_AC97_POWER_SAVE_DEFAULT=0 + +CONFIG_SND_DRIVERS=y + +# +# ISA devices +# +CONFIG_SND_AD1889=m +# CONFIG_SND_WAVEFRONT is not set +# CONFIG_SND_MSND_PINNACLE is not set +# CONFIG_SND_MSND_CLASSIC is not set + +# +# PCI devices +# +CONFIG_SND_PCI=y +CONFIG_SND_ADLIB=m +CONFIG_SND_ALI5451=m +CONFIG_SND_ALS300=m +CONFIG_SND_ALS4000=m +CONFIG_SND_ATIIXP=m +CONFIG_SND_ATIIXP_MODEM=m +CONFIG_SND_AU8810=m +CONFIG_SND_AU8820=m +CONFIG_SND_AU8830=m +# CONFIG_SND_AW2 is not set +CONFIG_SND_AZT3328=m +CONFIG_SND_BT87X=m +# CONFIG_SND_BT87X_OVERCLOCK is not set +CONFIG_SND_CA0106=m +CONFIG_SND_CMIPCI=m +CONFIG_SND_CS46XX=m +CONFIG_SND_CS46XX_NEW_DSP=y +CONFIG_SND_CS4281=m +CONFIG_SND_CS5530=m +CONFIG_SND_CS5535AUDIO=m +CONFIG_SND_EMU10K1=m +CONFIG_SND_EMU10K1X=m +CONFIG_SND_ENS1370=m +CONFIG_SND_ENS1371=m +CONFIG_SND_ES1938=m +CONFIG_SND_ES1968=m +CONFIG_SND_FM801=m +CONFIG_SND_FM801_TEA575X_BOOL=y +CONFIG_SND_CTXFI=m +CONFIG_SND_LX6464ES=m +CONFIG_SND_HDA_INTEL=y +CONFIG_SND_HDA_INPUT_BEEP=y +CONFIG_SND_HDA_INPUT_BEEP_MODE=0 +CONFIG_SND_HDA_INPUT_JACK=y +CONFIG_SND_HDA_PATCH_LOADER=y +CONFIG_SND_HDA_HWDEP=y +CONFIG_SND_HDA_CODEC_REALTEK=y +CONFIG_SND_HDA_CODEC_CA0110=y +CONFIG_SND_HDA_CODEC_ANALOG=y +CONFIG_SND_HDA_CODEC_SIGMATEL=y +CONFIG_SND_HDA_CODEC_VIA=y +CONFIG_SND_HDA_CODEC_ATIHDMI=y +CONFIG_SND_HDA_CODEC_CIRRUS=y +CONFIG_SND_HDA_CODEC_CONEXANT=y +CONFIG_SND_HDA_CODEC_CMEDIA=y +CONFIG_SND_HDA_CODEC_INTELHDMI=y +CONFIG_SND_HDA_CODEC_SI3054=y +CONFIG_SND_HDA_CODEC_NVHDMI=y +CONFIG_SND_HDA_GENERIC=y +CONFIG_SND_HDA_POWER_SAVE=y +CONFIG_SND_HDA_POWER_SAVE_DEFAULT=0 +CONFIG_SND_HDA_RECONFIG=y +CONFIG_SND_HDSPM=m +CONFIG_SND_HIFIER=m +CONFIG_SND_ICE1712=m +CONFIG_SND_ICE1724=m +CONFIG_SND_INTEL8X0=y +CONFIG_SND_INTEL8X0M=m +CONFIG_SND_KORG1212=m +CONFIG_SND_KORG1212_FIRMWARE_IN_KERNEL=y +CONFIG_SND_MAESTRO3=m +CONFIG_SND_MAESTRO3_FIRMWARE_IN_KERNEL=y +CONFIG_SND_MIRO=m +CONFIG_SND_MIXART=m +CONFIG_SND_NM256=m +CONFIG_SND_OXYGEN=m +CONFIG_SND_RME32=m +CONFIG_SND_PCSP=m +CONFIG_SND_PCXHR=m +CONFIG_SND_RIPTIDE=m +CONFIG_SND_RME96=m +CONFIG_SND_RME9652=m +CONFIG_SND_SC6000=m +CONFIG_SND_SIS7019=m +CONFIG_SND_SONICVIBES=m +CONFIG_SND_HDSP=m +CONFIG_SND_TRIDENT=m +CONFIG_SND_VIA82XX=m +CONFIG_SND_VIA82XX_MODEM=m +CONFIG_SND_VIRTUOSO=m +CONFIG_SND_VX222=m +CONFIG_SND_YMFPCI=m +CONFIG_SND_YMFPCI_FIRMWARE_IN_KERNEL=y + +# +# ALSA USB devices +# +CONFIG_SND_USB=y +CONFIG_SND_USB_AUDIO=m +CONFIG_SND_USB_CAIAQ=m +CONFIG_SND_USB_CAIAQ_INPUT=y +CONFIG_SND_USB_USX2Y=m +CONFIG_SND_USB_US122L=m + +# +# PCMCIA devices +# +CONFIG_SND_PCMCIA=y +CONFIG_SND_VXPOCKET=m +CONFIG_SND_PDAUDIOCF=m + +# +# Open Sound System +# +# CONFIG_SOUND_PRIME is not set + +# +# USB support +# +CONFIG_USB=y +CONFIG_USB_SUPPORT=y +# CONFIG_USB_DEBUG is not set + +# DEPRECATED: See bug 362221. Fix udev. +# CONFIG_USB_DEVICE_CLASS is not set + +CONFIG_USB_PERSIST=y + +# +# Miscellaneous USB options +# +CONFIG_USB_DEVICEFS=y +# CONFIG_USB_DYNAMIC_MINORS is not set +CONFIG_USB_SUSPEND=y + +# +# USB Host Controller Drivers +# +CONFIG_USB_EHCI_HCD=y +CONFIG_USB_EHCI_SPLIT_ISO=y +CONFIG_USB_EHCI_ROOT_HUB_TT=y +CONFIG_USB_EHCI_TT_NEWSCHED=y +CONFIG_USB_OHCI_HCD=y +# CONFIG_USB_OHCI_HCD_SSB is not set +CONFIG_USB_UHCI_HCD=y +# CONFIG_USB_SL811_CS is not set +# CONFIG_USB_R8A66597_HCD is not set +CONFIG_USB_XHCI_HCD=m +# CONFIG_USB_XHCI_HCD_DEBUGGING is not set +CONFIG_USB_ISP1362_HCD=m + +# +# USB Device Class drivers +# + +# +# USB Bluetooth TTY can only be used with disabled Bluetooth subsystem +# +CONFIG_USB_ACM=m +CONFIG_USB_PRINTER=m +CONFIG_USB_WDM=m +CONFIG_USB_TMC=m +# CONFIG_BLK_DEV_UB is not set +CONFIG_USB_STORAGE=m +# CONFIG_USB_STORAGE_DEBUG is not set +CONFIG_USB_STORAGE_CYPRESS_ATACB=y +CONFIG_USB_STORAGE_DATAFAB=y +CONFIG_USB_STORAGE_FREECOM=y +CONFIG_USB_STORAGE_ISD200=y +CONFIG_USB_STORAGE_DPCM=y +CONFIG_USB_STORAGE_SDDR09=y +CONFIG_USB_STORAGE_SDDR55=y +CONFIG_USB_STORAGE_SIERRA=y +CONFIG_USB_STORAGE_JUMPSHOT=y +CONFIG_USB_STORAGE_USBAT=y +CONFIG_USB_STORAGE_ONETOUCH=y +CONFIG_USB_STORAGE_ALAUDA=y +CONFIG_USB_STORAGE_KARMA=y +# CONFIG_USB_LIBUSUAL is not set + +# +# USB Human Interface Devices (HID) +# +CONFIG_USB_HID=y + +CONFIG_HID_SUPPORT=y + +CONFIG_HID=m +# debugging default is y upstream now +CONFIG_HID_DEBUG=y +CONFIG_HIDRAW=y +CONFIG_HID_FF=y +CONFIG_HID_PID=y +# CONFIG_HID_COMPAT is not set +CONFIG_LOGITECH_FF=y +CONFIG_LOGIRUMBLEPAD2_FF=y +CONFIG_PANTHERLORD_FF=y +CONFIG_THRUSTMASTER_FF=y +CONFIG_HID_WACOM=y +CONFIG_ZEROPLUS_FF=y +CONFIG_USB_HIDDEV=y +CONFIG_USB_IDMOUSE=m +CONFIG_DRAGONRISE_FF=y +CONFIG_GREENASIA_FF=y +CONFIG_SMARTJOYPLUS_FF=y + +# +# USB Imaging devices +# +CONFIG_USB_MDC800=m +CONFIG_USB_MICROTEK=m + +# +# USB Multimedia devices +# +CONFIG_DAB=y +CONFIG_USB_DABUSB=m + +CONFIG_USB_VICAM=m +CONFIG_USB_DSBR=m +# CONFIG_USB_ET61X251 is not set +CONFIG_USB_M5602=m +CONFIG_USB_STV06XX=m +CONFIG_USB_GSPCA=m +CONFIG_USB_GSPCA_MR97310A=m +CONFIG_USB_GSPCA_BENQ=m +CONFIG_USB_GSPCA_CONEX=m +CONFIG_USB_GSPCA_CPIA1=m +CONFIG_USB_GSPCA_ETOMS=m +CONFIG_USB_GSPCA_FINEPIX=m +CONFIG_USB_GSPCA_MARS=m +CONFIG_USB_GSPCA_OV519=m +CONFIG_USB_GSPCA_OV534=m +CONFIG_USB_GSPCA_OV534_9=m +CONFIG_USB_GSPCA_PAC207=m +CONFIG_USB_GSPCA_PAC7311=m +CONFIG_USB_GSPCA_SN9C2028=m +CONFIG_USB_GSPCA_SN9C20X=m +CONFIG_USB_GSPCA_SN9C20X_EVDEV=y +CONFIG_USB_GSPCA_SONIXB=m +CONFIG_USB_GSPCA_SONIXJ=m +CONFIG_USB_GSPCA_SPCA500=m +CONFIG_USB_GSPCA_SPCA501=m +CONFIG_USB_GSPCA_SPCA505=m +CONFIG_USB_GSPCA_SPCA506=m +CONFIG_USB_GSPCA_SPCA508=m +CONFIG_USB_GSPCA_SPCA561=m +CONFIG_USB_GSPCA_STK014=m +CONFIG_USB_GSPCA_SUNPLUS=m +CONFIG_USB_GSPCA_T613=m +CONFIG_USB_GSPCA_TV8532=m +CONFIG_USB_GSPCA_VC032X=m +CONFIG_USB_GSPCA_ZC3XX=m +CONFIG_USB_GSPCA_SQ905=m +CONFIG_USB_GSPCA_SQ905C=m +CONFIG_USB_GSPCA_PAC7302=m +CONFIG_USB_GSPCA_STV0680=m +CONFIG_USB_GL860=m +CONFIG_USB_GSPCA_JEILINJ=m + +CONFIG_USB_IBMCAM=m +CONFIG_USB_KONICAWC=m +# CONFIG_USB_OV511 is not set +CONFIG_USB_S2255=m +CONFIG_USB_SE401=m +# CONFIG_VIDEO_SH_MOBILE_CEU is not set +# CONFIG_USB_STV680 is not set +# CONFIG_USB_SN9C102 is not set +CONFIG_USB_ZR364XX=m +CONFIG_SOC_CAMERA=m +CONFIG_SOC_CAMERA_MT9M001=m +CONFIG_SOC_CAMERA_MT9V022=m +CONFIG_SOC_CAMERA_PLATFORM=m +CONFIG_SOC_CAMERA_MT9M111=m +CONFIG_SOC_CAMERA_MT9T031=m +CONFIG_SOC_CAMERA_TW9910=m +CONFIG_SOC_CAMERA_OV772X=m +CONFIG_SOC_CAMERA_MT9T112=m +CONFIG_SOC_CAMERA_RJ54N1=m +CONFIG_SOC_CAMERA_OV9640=m + +# +# USB Network adaptors +# +CONFIG_USB_CATC=m +CONFIG_USB_HSO=m +CONFIG_USB_KAWETH=m +CONFIG_USB_PEGASUS=m +CONFIG_USB_RTL8150=m +CONFIG_USB_USBNET=m +CONFIG_USB_SPEEDTOUCH=m +CONFIG_USB_NET_AX8817X=m +CONFIG_USB_NET_DM9601=m +CONFIG_USB_NET_SMSC95XX=m +CONFIG_USB_NET_GL620A=m +CONFIG_USB_NET_NET1080=m +CONFIG_USB_NET_PLUSB=m +CONFIG_USB_NET_MCS7830=m +CONFIG_USB_NET_RNDIS_HOST=m +CONFIG_USB_NET_CDC_SUBSET=m +CONFIG_USB_NET_CDC_EEM=m +CONFIG_USB_NET_ZAURUS=m +CONFIG_USB_NET_INT51X1=m +CONFIG_USB_CDC_PHONET=m + +# +# USB Host-to-Host Cables +# +CONFIG_USB_AN2720=y +CONFIG_USB_BELKIN=y + +# +# Intelligent USB Devices/Gadgets +# +CONFIG_USB_ARMLINUX=y +CONFIG_USB_EPSON2888=y +CONFIG_USB_KC2190=y + +# CONFIG_USB_MUSB_HDRC is not set + +# +# USB port drivers +# +CONFIG_USB_USS720=m + +# +# USB Serial Converter support +# +CONFIG_USB_SERIAL=m +CONFIG_USB_SERIAL_GENERIC=y +CONFIG_USB_SERIAL_AIRCABLE=m +CONFIG_USB_SERIAL_AIRPRIME=m +CONFIG_USB_SERIAL_ARK3116=m +CONFIG_USB_SERIAL_BELKIN=m +CONFIG_USB_SERIAL_CH341=m +CONFIG_USB_SERIAL_CP2101=m +CONFIG_USB_SERIAL_CYPRESS_M8=m +CONFIG_USB_SERIAL_CYBERJACK=m +CONFIG_USB_SERIAL_DIGI_ACCELEPORT=m +CONFIG_USB_SERIAL_CP210X=m +CONFIG_USB_SERIAL_QUALCOMM=m +CONFIG_USB_SERIAL_SYMBOL=m +CONFIG_USB_SERIAL_EDGEPORT=m +CONFIG_USB_SERIAL_EDGEPORT_TI=m +CONFIG_USB_SERIAL_EMPEG=m +CONFIG_USB_SERIAL_FTDI_SIO=m +CONFIG_USB_SERIAL_FUNSOFT=m +CONFIG_USB_SERIAL_GARMIN=m +CONFIG_USB_SERIAL_HP4X=m +CONFIG_USB_SERIAL_IPAQ=m +CONFIG_USB_SERIAL_IPW=m +CONFIG_USB_SERIAL_IR=m +CONFIG_USB_SERIAL_IUU=m +CONFIG_USB_SERIAL_KEYSPAN_PDA=m +CONFIG_USB_SERIAL_KEYSPAN=m +CONFIG_USB_SERIAL_KEYSPAN_MPR=y +CONFIG_USB_SERIAL_KEYSPAN_USA28=y +CONFIG_USB_SERIAL_KEYSPAN_USA28X=y +CONFIG_USB_SERIAL_KEYSPAN_USA28XA=y +CONFIG_USB_SERIAL_KEYSPAN_USA28XB=y +CONFIG_USB_SERIAL_KEYSPAN_USA19=y +CONFIG_USB_SERIAL_KEYSPAN_USA18X=y +CONFIG_USB_SERIAL_KEYSPAN_USA19W=y +CONFIG_USB_SERIAL_KEYSPAN_USA19QW=y +CONFIG_USB_SERIAL_KEYSPAN_USA19QI=y +CONFIG_USB_SERIAL_KEYSPAN_USA49W=y +CONFIG_USB_SERIAL_KEYSPAN_USA49WLC=y +CONFIG_USB_SERIAL_KLSI=m +CONFIG_USB_SERIAL_KOBIL_SCT=m +CONFIG_USB_SERIAL_MCT_U232=m +CONFIG_USB_SERIAL_MOS7720=m +CONFIG_USB_SERIAL_MOS7840=m +CONFIG_USB_SERIAL_MOTOROLA=m +CONFIG_USB_SERIAL_NAVMAN=m +CONFIG_USB_SERIAL_OPTION=y +CONFIG_USB_SERIAL_OTI6858=m +CONFIG_USB_SERIAL_OPTICON=m +CONFIG_USB_SERIAL_OMNINET=m +CONFIG_USB_SERIAL_PL2303=m +CONFIG_USB_SERIAL_SAFE=m +CONFIG_USB_SERIAL_SAFE_PADDED=y +CONFIG_USB_SERIAL_SIERRAWIRELESS=m +CONFIG_USB_SERIAL_SIEMENS_MPI=m +CONFIG_USB_SERIAL_SPCP8X5=m +CONFIG_USB_SERIAL_TI=m +CONFIG_USB_SERIAL_VISOR=m +CONFIG_USB_SERIAL_WHITEHEAT=m +CONFIG_USB_SERIAL_XIRCOM=m +CONFIG_USB_SERIAL_DEBUG=m + +CONFIG_USB_EZUSB=y +CONFIG_USB_EMI62=m +CONFIG_USB_LED=m +# CONFIG_USB_CYPRESS_CY7C63 is not set +CONFIG_USB_G_SERIAL=m + +# +# USB Miscellaneous drivers +# + +CONFIG_USB_ADUTUX=m +CONFIG_USB_SEVSEG=m +CONFIG_USB_ALI_M5632=y +CONFIG_USB_APPLEDISPLAY=m +CONFIG_USB_ATM=m +CONFIG_USB_AUERSWALD=m +CONFIG_USB_BERRY_CHARGE=m +CONFIG_USB_CXACRU=m +# CONFIG_USB_C67X00_HCD is not set +# CONFIG_USB_CYTHERM is not set +CONFIG_USB_EMI26=m +CONFIG_USB_ETH=m +CONFIG_USB_FTDI_ELAN=m +CONFIG_USB_FILE_STORAGE=m +# CONFIG_USB_FILE_STORAGE_TEST is not set +# CONFIG_USB_GADGET is not set +# CONFIG_USB_GADGET_PXA2XX is not set +# CONFIG_USB_GADGET_GOKU is not set +# CONFIG_USB_GADGETFS is not set +# CONFIG_USB_HIDINPUT_POWERBOOK is not set +# CONFIG_USB_ISP116X_HCD is not set +# CONFIG_USB_ISP1760_HCD is not set +# CONFIG_USB_OXU210HP_HCD is not set +CONFIG_USB_IOWARRIOR=m +CONFIG_USB_ISIGHTFW=m +CONFIG_USB_VST=m +CONFIG_USB_LCD=m +CONFIG_USB_LD=m +CONFIG_USB_LEGOTOWER=m +CONFIG_USB_MON=y +CONFIG_USB_PHIDGET=m +CONFIG_USB_PHIDGETSERVO=m +CONFIG_USB_PHIDGETKIT=m +CONFIG_USB_PHIDGETMOTORCONTROL=m +CONFIG_USB_PWC=m +CONFIG_USB_PWC_INPUT_EVDEV=y +# CONFIG_USB_PWC_DEBUG is not set +# CONFIG_USB_RIO500 is not set +# CONFIG_USB_QUICKCAM_MESSENGER is not set +CONFIG_USB_SL811_HCD=m +CONFIG_USB_SISUSBVGA=m +CONFIG_USB_SISUSBVGA_CON=y +CONFIG_RADIO_SI470X=y +CONFIG_USB_SI470X=m +CONFIG_I2C_SI470X=m +CONFIG_RADIO_SI4713=m +# CONFIG_RADIO_TEF6862 is not set +CONFIG_USB_MR800=m +CONFIG_USB_STKWEBCAM=m +# CONFIG_USB_TEST is not set +CONFIG_USB_TRANCEVIBRATOR=m +CONFIG_USB_U132_HCD=m +CONFIG_USB_UEAGLEATM=m +CONFIG_USB_UVCVIDEO=m +CONFIG_USB_XUSBATM=m +# CONFIG_USB_ZC0301 is not set +CONFIG_USB_ZERO=m + +CONFIG_USB_ANNOUNCE_NEW_DEVICES=y + +# +# Sonics Silicon Backplane +# +CONFIG_SSB=m +CONFIG_SSB_PCIHOST=y +CONFIG_SSB_SDIOHOST=y +CONFIG_SSB_PCMCIAHOST=y +# CONFIG_SSB_SILENT is not set +# CONFIG_SSB_DEBUG is not set +CONFIG_SSB_DRIVER_PCICORE=y + +# Multifunction USB devices +# CONFIG_MFD_PCF50633 is not set +CONFIG_PCF50633_ADC=m +CONFIG_PCF50633_GPIO=m +CONFIG_AB3100_CORE=m +CONFIG_INPUT_PCF50633_PMU=m +CONFIG_INPUT_GPIO_ROTARY_ENCODER=m +CONFIG_CHARGER_PCF50633=m +CONFIG_REGULATOR_PCF50633=m +CONFIG_RTC_DRV_PCF50633=m + +CONFIG_MFD_SM501=m +CONFIG_MFD_SM501_GPIO=y +# CONFIG_MFD_TC6393XB is not set +CONFIG_MFD_WM8400=m +CONFIG_MFD_WM8350_I2C=m +CONFIG_MFD_WM8350=m +# CONFIG_MFD_WM831X is not set +CONFIG_AB3100_OTP=m + +# +# File systems +# +CONFIG_MISC_FILESYSTEMS=y + +CONFIG_EXT2_FS=m +CONFIG_EXT2_FS_XATTR=y +CONFIG_EXT2_FS_POSIX_ACL=y +CONFIG_EXT2_FS_SECURITY=y +CONFIG_EXT2_FS_XIP=y +CONFIG_EXT3_FS=y +CONFIG_EXT3_DEFAULTS_TO_ORDERED=y +CONFIG_EXT3_FS_XATTR=y +CONFIG_EXT3_FS_POSIX_ACL=y +CONFIG_EXT3_FS_SECURITY=y +CONFIG_JBD=y +# CONFIG_JBD_DEBUG is not set +CONFIG_EXT4_FS=y +CONFIG_EXT4_FS_XATTR=y +CONFIG_EXT4_FS_POSIX_ACL=y +CONFIG_EXT4_FS_SECURITY=y +CONFIG_EXT4DEV_COMPAT=y +CONFIG_JBD2=y +CONFIG_FS_MBCACHE=y +CONFIG_REISERFS_FS=m +# CONFIG_REISERFS_CHECK is not set +CONFIG_REISERFS_PROC_INFO=y +CONFIG_REISERFS_FS_XATTR=y +CONFIG_REISERFS_FS_POSIX_ACL=y +CONFIG_REISERFS_FS_SECURITY=y +CONFIG_JFS_FS=m +# CONFIG_JFS_DEBUG is not set +# CONFIG_JFS_STATISTICS is not set +CONFIG_JFS_POSIX_ACL=y +CONFIG_JFS_SECURITY=y +CONFIG_XFS_FS=m +# CONFIG_XFS_DEBUG is not set +# CONFIG_XFS_RT is not set +CONFIG_XFS_QUOTA=y +CONFIG_XFS_POSIX_ACL=y +CONFIG_XFS_SECURITY=y +CONFIG_MINIX_FS=m +CONFIG_ROMFS_FS=m +CONFIG_QUOTA=y +CONFIG_QUOTA_NETLINK_INTERFACE=y +# CONFIG_PRINT_QUOTA_WARNING is not set +# CONFIG_QFMT_V1 is not set +CONFIG_QFMT_V2=y +CONFIG_QUOTACTL=y +CONFIG_DNOTIFY=y +# Autofsv3 is obsolete. +# CONFIG_AUTOFS_FS is not set +CONFIG_AUTOFS4_FS=m +CONFIG_EXOFS_FS=m +# CONFIG_EXOFS_DEBUG is not set +CONFIG_NILFS2_FS=m + +CONFIG_FSCACHE=m +CONFIG_FSCACHE_STATS=y +# CONFIG_FSCACHE_HISTOGRAM is not set +# CONFIG_FSCACHE_DEBUG is not set +CONFIG_FSCACHE_OBJECT_LIST=y + +CONFIG_CACHEFILES=m +# CONFIG_CACHEFILES_DEBUG is not set +# CONFIG_CACHEFILES_HISTOGRAM is not set + +# +# CD-ROM/DVD Filesystems +# +CONFIG_ISO9660_FS=y +CONFIG_JOLIET=y +CONFIG_ZISOFS=y +CONFIG_UDF_FS=m + +# +# DOS/FAT/NT Filesystems +# +CONFIG_FAT_FS=m +CONFIG_MSDOS_FS=m +CONFIG_VFAT_FS=m +CONFIG_FAT_DEFAULT_CODEPAGE=437 +CONFIG_FAT_DEFAULT_IOCHARSET="ascii" +# CONFIG_NTFS_FS is not set + +# +# Pseudo filesystems +# +CONFIG_PROC_FS=y +CONFIG_PROC_KCORE=y +CONFIG_PROC_VMCORE=y +CONFIG_TMPFS=y +CONFIG_TMPFS_POSIX_ACL=y +CONFIG_HUGETLBFS=y +CONFIG_HUGETLB_PAGE=y +CONFIG_DEBUG_FS=y + +# +# Miscellaneous filesystems +# +# CONFIG_ADFS_FS is not set +CONFIG_AFFS_FS=m +CONFIG_ECRYPT_FS=m +CONFIG_HFS_FS=m +CONFIG_HFSPLUS_FS=m +CONFIG_BEFS_FS=m +# CONFIG_BEFS_DEBUG is not set +CONFIG_BFS_FS=m +CONFIG_EFS_FS=m +CONFIG_JFFS2_FS=m +CONFIG_JFFS2_FS_DEBUG=0 +# CONFIG_JFFS2_COMPRESSION_OPTIONS is not set +CONFIG_JFFS2_FS_WRITEBUFFER=y +# CONFIG_JFFS2_FS_WBUF_VERIFY is not set +CONFIG_JFFS2_SUMMARY=y +CONFIG_JFFS2_FS_XATTR=y +CONFIG_JFFS2_FS_POSIX_ACL=y +CONFIG_JFFS2_FS_SECURITY=y +CONFIG_CRAMFS=m +CONFIG_SQUASHFS=m +# CONFIG_SQUASHFS_EMBEDDED is not set +CONFIG_VXFS_FS=m +# CONFIG_HPFS_FS is not set +CONFIG_QNX4FS_FS=m +# CONFIG_QNX4FS_RW is not set +CONFIG_SYSV_FS=m +CONFIG_UFS_FS=m +# CONFIG_UFS_FS_WRITE is not set +# CONFIG_UFS_DEBUG is not set +CONFIG_9P_FS=m +CONFIG_9P_FSCACHE=y +CONFIG_FUSE_FS=m +CONFIG_OMFS_FS=m +CONFIG_CUSE=m + +# +# Network File Systems +# +CONFIG_NETWORK_FILESYSTEMS=y +CONFIG_NFS_FS=m +CONFIG_NFS_V3=y +CONFIG_NFS_V3_ACL=y +CONFIG_NFS_V4=y +CONFIG_NFS_V4_1=y +CONFIG_NFS_DIRECTIO=y +CONFIG_NFSD=m +CONFIG_NFSD_V3=y +CONFIG_NFSD_V3_ACL=y +CONFIG_NFSD_V4=y +CONFIG_NFSD_TCP=y +CONFIG_NFS_FSCACHE=y +CONFIG_LOCKD=m +CONFIG_LOCKD_V4=y +CONFIG_EXPORTFS=m +CONFIG_SUNRPC=m +CONFIG_SUNRPC_BIND34=y +CONFIG_SUNRPC_GSS=m +CONFIG_SUNRPC_XPRT_RDMA=m +# CONFIG_SUNRPC_REGISTER_V4 is not set +CONFIG_RPCSEC_GSS_KRB5=m +CONFIG_RPCSEC_GSS_SPKM3=m +# CONFIG_SMB_FS is not set +# CONFIG_SMB_NLS_DEFAULT is not set +CONFIG_CIFS=m +CONFIG_CIFS_STATS=y +# CONFIG_CIFS_STATS2 is not set +CONFIG_CIFS_EXPERIMENTAL=y +CONFIG_CIFS_UPCALL=y +CONFIG_CIFS_XATTR=y +CONFIG_CIFS_POSIX=y +CONFIG_CIFS_WEAK_PW_HASH=y +# CONFIG_CIFS_DEBUG2 is not set +CONFIG_CIFS_DFS_UPCALL=y +CONFIG_NCP_FS=m +CONFIG_NCPFS_PACKET_SIGNING=y +CONFIG_NCPFS_IOCTL_LOCKING=y +CONFIG_NCPFS_STRONG=y +CONFIG_NCPFS_NFS_NS=y +CONFIG_NCPFS_OS2_NS=y +CONFIG_NCPFS_SMALLDOS=y +CONFIG_NCPFS_NLS=y +CONFIG_NCPFS_EXTRAS=y +CONFIG_CODA_FS=m +# CONFIG_CODA_FS_OLD_API is not set +# CONFIG_AFS_FS is not set +# CONFIG_AF_RXRPC is not set + +CONFIG_OCFS2_FS=m +# CONFIG_OCFS2_DEBUG_FS is not set +# CONFIG_OCFS2_DEBUG_MASKLOG is not set +CONFIG_OCFS2_FS_O2CB=m +CONFIG_OCFS2_FS_USERSPACE_CLUSTER=m +# CONFIG_OCFS2_FS_STATS is not set +# CONFIG_OCFS2_COMPAT_JBD is not set +CONFIG_OCFS2_FS_POSIX_ACL=y + +CONFIG_BTRFS_FS=m +CONFIG_BTRFS_FS_POSIX_ACL=y + +CONFIG_CONFIGFS_FS=m + +CONFIG_DLM=m +CONFIG_DLM_DEBUG=y +CONFIG_GFS2_FS=m +CONFIG_GFS2_FS_LOCKING_DLM=y + +CONFIG_UBIFS_FS=m +CONFIG_UBIFS_FS_XATTR=y +# CONFIG_UBIFS_FS_ADVANCED_COMPR is not set +# CONFIG_UBIFS_FS_DEBUG is not set + +# +# Partition Types +# +CONFIG_PARTITION_ADVANCED=y +# CONFIG_ACORN_PARTITION is not set +CONFIG_AMIGA_PARTITION=y +# CONFIG_ATARI_PARTITION is not set +CONFIG_BSD_DISKLABEL=y +CONFIG_EFI_PARTITION=y +CONFIG_KARMA_PARTITION=y +# CONFIG_LDM_PARTITION is not set +CONFIG_MAC_PARTITION=y +CONFIG_MSDOS_PARTITION=y +CONFIG_MINIX_SUBPARTITION=y +CONFIG_OSF_PARTITION=y +CONFIG_SGI_PARTITION=y +CONFIG_SOLARIS_X86_PARTITION=y +CONFIG_SUN_PARTITION=y +# CONFIG_SYSV68_PARTITION is not set +CONFIG_UNIXWARE_DISKLABEL=y +# CONFIG_ULTRIX_PARTITION is not set + +CONFIG_NLS=y + +# +# Native Language Support +# +CONFIG_NLS_DEFAULT="utf8" +CONFIG_NLS_CODEPAGE_437=y +CONFIG_NLS_CODEPAGE_737=m +CONFIG_NLS_CODEPAGE_775=m +CONFIG_NLS_CODEPAGE_850=m +CONFIG_NLS_CODEPAGE_852=m +CONFIG_NLS_CODEPAGE_855=m +CONFIG_NLS_CODEPAGE_857=m +CONFIG_NLS_CODEPAGE_860=m +CONFIG_NLS_CODEPAGE_861=m +CONFIG_NLS_CODEPAGE_862=m +CONFIG_NLS_CODEPAGE_863=m +CONFIG_NLS_CODEPAGE_864=m +CONFIG_NLS_CODEPAGE_865=m +CONFIG_NLS_CODEPAGE_866=m +CONFIG_NLS_CODEPAGE_869=m +CONFIG_NLS_CODEPAGE_936=m +CONFIG_NLS_CODEPAGE_950=m +CONFIG_NLS_CODEPAGE_932=m +CONFIG_NLS_CODEPAGE_949=m +CONFIG_NLS_CODEPAGE_874=m +CONFIG_NLS_ISO8859_8=m +CONFIG_NLS_CODEPAGE_1250=m +CONFIG_NLS_CODEPAGE_1251=m +CONFIG_NLS_ISO8859_1=m +CONFIG_NLS_ISO8859_2=m +CONFIG_NLS_ISO8859_3=m +CONFIG_NLS_ISO8859_4=m +CONFIG_NLS_ISO8859_5=m +CONFIG_NLS_ISO8859_6=m +CONFIG_NLS_ISO8859_7=m +CONFIG_NLS_ISO8859_9=m +CONFIG_NLS_ISO8859_13=m +CONFIG_NLS_ISO8859_14=m +CONFIG_NLS_ISO8859_15=m +CONFIG_NLS_KOI8_R=m +CONFIG_NLS_KOI8_U=m +CONFIG_NLS_UTF8=m +CONFIG_NLS_ASCII=y + +# +# Profiling support +# +CONFIG_PROFILING=y +CONFIG_OPROFILE=m +CONFIG_OPROFILE_EVENT_MULTIPLEX=y + +# +# Kernel hacking +# +CONFIG_DEBUG_KERNEL=y +CONFIG_FRAME_WARN=1024 +CONFIG_MAGIC_SYSRQ=y +CONFIG_DEBUG_INFO=y +CONFIG_FRAME_POINTER=y +CONFIG_CC_OPTIMIZE_FOR_SIZE=y +# CONFIG_DEBUG_DRIVER is not set +CONFIG_HEADERS_CHECK=y +# CONFIG_RCU_TORTURE_TEST is not set +# CONFIG_RCU_TRACE is not set +# CONFIG_LKDTM is not set + +# CONFIG_RT_MUTEX_TESTER is not set +# CONFIG_DEBUG_LOCKDEP is not set +# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set + +CONFIG_KGDB=y +CONFIG_KGDB_SERIAL_CONSOLE=y +CONFIG_KGDB_TESTS=y +# CONFIG_KGDB_TESTS_ON_BOOT is not set + +# +# Security options +# +CONFIG_SECURITY=y +CONFIG_SECURITY_NETWORK=y +CONFIG_SECURITY_NETWORK_XFRM=y +# CONFIG_SECURITY_PATH is not set +CONFIG_SECURITY_CAPABILITIES=y +CONFIG_SECURITY_FILE_CAPABILITIES=y +# CONFIG_SECURITY_ROOTPLUG is not set +CONFIG_SECURITY_SELINUX=y +CONFIG_SECURITY_SELINUX_BOOTPARAM=y +CONFIG_SECURITY_SELINUX_DISABLE=y +CONFIG_SECURITY_SELINUX_DEVELOP=y +CONFIG_SECURITY_SELINUX_BOOTPARAM_VALUE=1 +CONFIG_SECURITY_SELINUX_CHECKREQPROT_VALUE=1 +CONFIG_SECURITY_SELINUX_ENABLE_SECMARK_DEFAULT=y +CONFIG_SECURITY_SELINUX_AVC_STATS=y +CONFIG_SECURITY_DEFAULT_MMAP_MIN_ADDR=65536 +# CONFIG_SECURITY_SMACK is not set +# CONFIG_SECURITY_TOMOYO is not set +CONFIG_AUDIT=y +CONFIG_AUDITSYSCALL=y + +# +# Cryptographic options +# +CONFIG_CRYPTO=y +CONFIG_CRYPTO_FIPS=y +CONFIG_CRYPTO_HW=y +CONFIG_CRYPTO_BLKCIPHER=y +CONFIG_CRYPTO_MANAGER=m +# CONFIG_CRYPTO_CRYPTD is not set +CONFIG_CRYPTO_AES=m +CONFIG_CRYPTO_ARC4=m +CONFIG_CRYPTO_ANUBIS=m +CONFIG_CRYPTO_AUTHENC=m +CONFIG_CRYPTO_BLOWFISH=m +CONFIG_CRYPTO_CAMELLIA=m +CONFIG_CRYPTO_CAST5=m +CONFIG_CRYPTO_CAST6=m +CONFIG_CRYPTO_CBC=m +CONFIG_CRYPTO_CCM=m +CONFIG_CRYPTO_CRC32C=y +CONFIG_CRYPTO_CTR=m +CONFIG_CRYPTO_CTS=m +CONFIG_CRYPTO_DEFLATE=m +CONFIG_CRYPTO_DES=m +CONFIG_CRYPTO_ECB=m +CONFIG_CRYPTO_FCRYPT=m +CONFIG_CRYPTO_GCM=m +CONFIG_CRYPTO_GF128MUL=m +CONFIG_CRYPTO_HMAC=y +CONFIG_CRYPTO_KHAZAD=m +CONFIG_CRYPTO_LRW=m +CONFIG_CRYPTO_LZO=m +CONFIG_CRYPTO_MD4=m +CONFIG_CRYPTO_MD5=m +CONFIG_CRYPTO_MICHAEL_MIC=m +CONFIG_CRYPTO_NULL=m +CONFIG_CRYPTO_PCBC=m +CONFIG_CRYPTO_RMD128=m +CONFIG_CRYPTO_RMD160=m +CONFIG_CRYPTO_RMD256=m +CONFIG_CRYPTO_RMD320=m +CONFIG_CRYPTO_SALSA20=m +CONFIG_CRYPTO_SALSA20_586=m +CONFIG_CRYPTO_SEED=m +CONFIG_CRYPTO_SEQIV=m +CONFIG_CRYPTO_SERPENT=m +CONFIG_CRYPTO_SHA1=y +CONFIG_CRYPTO_SHA256=m +CONFIG_CRYPTO_SHA512=m +CONFIG_CRYPTO_TEA=m +CONFIG_CRYPTO_TGR192=m +CONFIG_CRYPTO_TWOFISH=m +CONFIG_CRYPTO_WP512=m +CONFIG_CRYPTO_XCBC=m +CONFIG_CRYPTO_VMAC=m +CONFIG_CRYPTO_XTS=m +CONFIG_CRYPTO_TEST=m +CONFIG_LIBCRC32C=m +CONFIG_CRYPTO_CRC32C_INTEL=m +CONFIG_CRYPTO_GHASH=m +CONFIG_CRYPTO_ANSI_CPRNG=m +CONFIG_CRYPTO_DEV_HIFN_795X=m +CONFIG_CRYPTO_DEV_HIFN_795X_RNG=y + +# Random number generation +CONFIG_CRYPTO_PRNG=m + +# +# Library routines +# +CONFIG_CRC16=y +CONFIG_CRC32=m +CONFIG_CRC_CCITT=m +CONFIG_CRC_ITU_T=m +CONFIG_CRC_T10DIF=m + +CONFIG_CRYPTO_ZLIB=m +CONFIG_ZLIB_INFLATE=y +CONFIG_ZLIB_DEFLATE=m + +CONFIG_INITRAMFS_SOURCE="" +CONFIG_KEYS=y +CONFIG_KEYS_DEBUG_PROC_KEYS=y +CONFIG_CDROM_PKTCDVD=m +CONFIG_CDROM_PKTCDVD_BUFFERS=8 +# CONFIG_CDROM_PKTCDVD_WCACHE is not set + +CONFIG_ATA_OVER_ETH=m +CONFIG_BACKLIGHT_LCD_SUPPORT=y +CONFIG_BACKLIGHT_CLASS_DEVICE=m +# CONFIG_BACKLIGHT_GENERIC is not set +CONFIG_BACKLIGHT_PROGEAR=m +CONFIG_FB_NVIDIA_BACKLIGHT=y +CONFIG_FB_RIVA_BACKLIGHT=y +CONFIG_FB_RADEON_BACKLIGHT=y +CONFIG_FB_ATY128_BACKLIGHT=y +CONFIG_FB_ATY_BACKLIGHT=y +# CONFIG_BACKLIGHT_SAHARA is not set +CONFIG_BACKLIGHT_WM831X=m + +CONFIG_LCD_CLASS_DEVICE=m +CONFIG_LCD_PLATFORM=m + +CONFIG_SCHEDSTATS=y +CONFIG_SCHED_DEBUG=y +CONFIG_FAIR_GROUP_SCHED=y +CONFIG_SCHED_OMIT_FRAME_POINTER=y +CONFIG_GROUP_SCHED=y +CONFIG_RT_GROUP_SCHED=y +CONFIG_CGROUP_SCHED=y +CONFIG_CGROUP_MEM_RES_CTLR=y +CONFIG_CGROUP_MEM_RES_CTLR_SWAP=y + +CONFIG_CPUSETS=y +CONFIG_CGROUPS=y +# CONFIG_CGROUP_DEBUG is not set +CONFIG_CGROUP_NS=y +CONFIG_CGROUP_CPUACCT=y +CONFIG_CGROUP_DEVICE=y +CONFIG_CGROUP_FREEZER=y +CONFIG_PROC_PID_CPUSET=y + +# CONFIG_SYSFS_DEPRECATED is not set +# CONFIG_SYSFS_DEPRECATED_V2 is not set + +CONFIG_RELAY=y +# CONFIG_PRINTK_TIME is not set + +CONFIG_ENABLE_MUST_CHECK=y +# CONFIG_ENABLE_WARN_DEPRECATED is not set + +CONFIG_KEXEC=y + +CONFIG_HWMON=y +# CONFIG_HWMON_DEBUG_CHIP is not set +CONFIG_INOTIFY=y +CONFIG_INOTIFY_USER=y + +CONFIG_CONNECTOR=y +CONFIG_PROC_EVENTS=y + +CONFIG_IBMASR=m + +CONFIG_PM_LEGACY=y +CONFIG_PM_DEBUG=y +CONFIG_PM_TRACE=y +# CONFIG_PM_VERBOSE is not set +# CONFIG_PM_TEST_SUSPEND is not set +CONFIG_PM_RUNTIME=y + +## BEGIN ISA Junk. + +CONFIG_I82365=m +# CONFIG_TCIC is not set +# CONFIG_PCMCIA_PROBE is not set +# CONFIG_LTPC is not set +# CONFIG_COPS is not set + +CONFIG_SCSI_AHA152X=m +CONFIG_SCSI_AHA1542=m +# CONFIG_SCSI_IN2000 is not set +CONFIG_SCSI_ARCMSR=m +CONFIG_SCSI_ARCMSR_AER=y +# CONFIG_SCSI_DTC3280 is not set +# CONFIG_SCSI_GENERIC_NCR5380 is not set +# CONFIG_SCSI_GENERIC_NCR5380_MMIO is not set +# CONFIG_SCSI_NCR53C406A is not set +# CONFIG_SCSI_PAS16 is not set +# CONFIG_SCSI_PSI240I is not set +# CONFIG_SCSI_QLOGIC_FAS is not set +# CONFIG_SCSI_SYM53C416 is not set +# CONFIG_SCSI_T128 is not set +# CONFIG_SCSI_U14_34F is not set +# CONFIG_SCSI_ULTRASTOR is not set + +# CONFIG_EL1 is not set +# CONFIG_EL2 is not set +# CONFIG_ELPLUS is not set +# CONFIG_EL16 is not set +CONFIG_EL3=m +# CONFIG_3C515 is not set +# CONFIG_LANCE is not set +CONFIG_NET_VENDOR_SMC=y +# CONFIG_WD80x3 is not set +CONFIG_ULTRA=m +# CONFIG_SMC9194 is not set +# CONFIG_NET_VENDOR_RACAL is not set +# CONFIG_NI52 is not set +# CONFIG_NI65 is not set +# CONFIG_AT1700 is not set +# CONFIG_DEPCA is not set +CONFIG_NET_ISA=y +CONFIG_NE2000=m +# CONFIG_E2100 is not set +CONFIG_EWRK3=m +# CONFIG_EEXPRESS is not set +# CONFIG_EEXPRESS_PRO is not set +# CONFIG_HPLAN_PLUS is not set +# CONFIG_HPLAN is not set +# CONFIG_LP486E is not set +# CONFIG_ETH16I is not set +# CONFIG_ZNET is not set +# CONFIG_SEEQ8005 is not set +# CONFIG_AC3200 is not set +# CONFIG_APRICOT is not set +# CONFIG_CS89x0 is not set +# CONFIG_IBMTR is not set +# CONFIG_SKISA is not set +# CONFIG_PROTEON is not set +# CONFIG_SMCTR is not set +# CONFIG_WAVELAN is not set +# CONFIG_HISAX_16_0 is not set +# CONFIG_HISAX_AVM_A1 is not set +# CONFIG_HISAX_IX1MICROR2 is not set +# CONFIG_HISAX_ASUSCOM is not set +# CONFIG_HISAX_TELEINT is not set +# CONFIG_HISAX_HFCS is not set +# CONFIG_HISAX_SPORTSTER is not set +# CONFIG_HISAX_MIC is not set +# CONFIG_HISAX_ISURF is not set +# CONFIG_HISAX_HSTSAPHIR is not set +# CONFIG_ISDN_DRV_ICN is not set +# CONFIG_ISDN_DRV_PCBIT is not set +# CONFIG_ISDN_DRV_SC is not set +# CONFIG_ISDN_DRV_ACT2000 is not set +# CONFIG_ISDN_DRV_AVMB1_B1ISA is not set +# CONFIG_ISDN_DRV_AVMB1_T1ISA is not set + +# CONFIG_MOUSE_INPORT is not set +# CONFIG_MOUSE_ATIXL is not set +# CONFIG_MOUSE_LOGIBM is not set +# CONFIG_MOUSE_PC110PAD is not set + +# CONFIG_SERIAL_8250_FOURPORT is not set +# CONFIG_SERIAL_8250_ACCENT is not set +# CONFIG_SERIAL_8250_BOCA is not set +# CONFIG_SERIAL_8250_HUB6 is not set +# CONFIG_SERIAL_8250_EXAR_ST16C554 is not set + +# CONFIG_PCWATCHDOG is not set +# CONFIG_WDT is not set + +# CONFIG_VIDEO_PMS is not set +CONFIG_RADIO_ADAPTERS=y +# CONFIG_RADIO_CADET is not set +# CONFIG_RADIO_RTRACK is not set +# CONFIG_RADIO_RTRACK2 is not set +# CONFIG_RADIO_AZTECH is not set +# CONFIG_RADIO_GEMTEK is not set +# CONFIG_RADIO_SF16FMI is not set +# CONFIG_RADIO_SF16FMR2 is not set +# CONFIG_RADIO_TERRATEC is not set +# CONFIG_RADIO_TRUST is not set +# CONFIG_RADIO_TEA5764 is not set +# CONFIG_RADIO_TYPHOON is not set +# CONFIG_RADIO_ZOLTRIX is not set + +# CONFIG_SND_OPL4_LIB is not set +# CONFIG_SND_AD1848_LIB is not set +# CONFIG_SND_AD1816A is not set +# CONFIG_SND_AD1848 is not set +# CONFIG_SND_CS4231 is not set +# CONFIG_SND_CS4232 is not set +CONFIG_SND_CS4231_LIB=m +CONFIG_SND_CS4236=m +# CONFIG_SND_ES968 is not set +# CONFIG_SND_ES1688 is not set +# CONFIG_SND_ES18XX is not set +# CONFIG_SND_GUS_SYNTH is not set +# CONFIG_SND_GUSCLASSIC is not set +# CONFIG_SND_GUSEXTREME is not set +# CONFIG_SND_GUSMAX is not set +# CONFIG_SND_INTERWAVE is not set +# CONFIG_SND_INTERWAVE_STB is not set +# CONFIG_SND_OPTI92X_AD1848 is not set +# CONFIG_SND_OPTI92X_CS4231 is not set +# CONFIG_SND_OPTI93X is not set +# CONFIG_SND_SB8 is not set +CONFIG_SND_SB16=m +CONFIG_SND_SBAWE=m +# CONFIG_SND_SB16_CSP is not set +# CONFIG_SND_ALS100 is not set +# CONFIG_SND_AZT2320 is not set +# CONFIG_SND_CMI8330 is not set +# CONFIG_SND_DT019X is not set +CONFIG_SND_OPL3SA2=m +# CONFIG_SND_SGALAXY is not set +# CONFIG_SND_SSCAPE is not set +CONFIG_SND_DARLA20=m +CONFIG_SND_GINA20=m +CONFIG_SND_LAYLA20=m +CONFIG_SND_DARLA24=m +CONFIG_SND_GINA24=m +CONFIG_SND_LAYLA24=m +CONFIG_SND_MONA=m +CONFIG_SND_MIA=m +CONFIG_SND_ECHO3G=m +CONFIG_SND_INDIGO=m +CONFIG_SND_INDIGOIO=m +CONFIG_SND_INDIGODJ=m +CONFIG_SND_INDIGOIOX=m +CONFIG_SND_INDIGODJX=m +# CONFIG_SND_SOC is not set + +## END of ISA options. + +# CONFIG_FORCED_INLINING is not set + +CONFIG_MIGRATION=y +CONFIG_RESOURCES_64BIT=y +CONFIG_NEW_LEDS=y +CONFIG_LEDS_CLASS=y +# CONFIG_LEDS_AMS_DELTA is not set +# CONFIG_LEDS_CORGI is not set +# CONFIG_LEDS_IXP4XX is not set +# CONFIG_LEDS_LOCOMO is not set +# CONFIG_LEDS_NET48XX is not set +# CONFIG_LEDS_PCA9532 is not set +# CONFIG_LEDS_PCA955X is not set +# CONFIG_LEDS_LP5521 is not set +# CONFIG_LEDS_BD2802 is not set +# CONFIG_LEDS_S3C24XX is not set +# CONFIG_LEDS_SPITZ is not set +# CONFIG_LEDS_TOSA is not set +CONFIG_LEDS_HP_DISK=m +CONFIG_LEDS_TRIGGERS=y +CONFIG_LEDS_TRIGGER_TIMER=m +CONFIG_LEDS_TRIGGER_IDE_DISK=y +CONFIG_LEDS_TRIGGER_HEARTBEAT=m +CONFIG_LEDS_TRIGGER_BACKLIGHT=m +CONFIG_LEDS_TRIGGER_DEFAULT_ON=m +CONFIG_LEDS_ALIX2=m +CONFIG_LEDS_WM8350=m +CONFIG_LEDS_LP3944=m +CONFIG_LEDS_WM831X_STATUS=m +CONFIG_LEDS_REGULATOR=m +CONFIG_LEDS_LT3593=m +CONFIG_LEDS_TRIGGER_GPIO=m +CONFIG_LEDS_INTEL_SS4200=m + +CONFIG_DMADEVICES=y +CONFIG_DMA_ENGINE=y +CONFIG_NET_DMA=y +# CONFIG_DMATEST is not set +CONFIG_ASYNC_TX_DMA=y + +CONFIG_UNUSED_SYMBOLS=y + +CONFIG_UTRACE=y + +CONFIG_FTRACE=y +# CONFIG_IRQSOFF_TRACER is not set +CONFIG_SCHED_TRACER=y +CONFIG_PROCESS_TRACER=y +CONFIG_CONTEXT_SWITCH_TRACER=y +CONFIG_WORKQUEUE_TRACER=y +CONFIG_EVENT_TRACER=y +CONFIG_FTRACE_SYSCALLS=y +CONFIG_KMEMTRACE=y +CONFIG_FTRACE_MCOUNT_RECORD=y +# CONFIG_FTRACE_STARTUP_TEST is not set +# CONFIG_TRACE_BRANCH_PROFILING is not set +CONFIG_FUNCTION_PROFILER=y +CONFIG_RING_BUFFER_BENCHMARK=m + +CONFIG_KPROBES=y + +# CONFIG_SECURITY_SELINUX_POLICYDB_VERSION_MAX is not set + +CONFIG_HZ_1000=y + +CONFIG_TIMER_STATS=y + +# Auxillary displays +CONFIG_KS0108=m +CONFIG_KS0108_PORT=0x378 +CONFIG_KS0108_DELAY=2 +CONFIG_CFAG12864B=y +CONFIG_CFAG12864B_RATE=20 + +# CONFIG_PHANTOM is not set + +CONFIG_POWER_SUPPLY=m +# CONFIG_POWER_SUPPLY_DEBUG is not set +CONFIG_APM_POWER=m +CONFIG_WM831X_POWER=m +# CONFIG_BATTERY_DS2760 is not set +# CONFIG_BATTERY_DS2782 is not set +CONFIG_BATTERY_PMU=m +CONFIG_BATTERY_BQ27x00=m +CONFIG_BATTERY_MAX17040=m +# CONFIG_PDA_POWER is not set + +CONFIG_AUXDISPLAY=y + +CONFIG_UIO=m +CONFIG_UIO_CIF=m +CONFIG_UIO_SMX=m +CONFIG_UIO_PDRV=m +CONFIG_UIO_PDRV_GENIRQ=m +CONFIG_UIO_AEC=m +CONFIG_UIO_SERCOS3=m +CONFIG_UIO_PCI_GENERIC=m + +CONFIG_INSTRUMENTATION=y +CONFIG_MARKERS=y +# CONFIG_CRC7 is not set + +CONFIG_DEFAULT_RELATIME=y + +# LIRC +CONFIG_INPUT_LIRC=m +CONFIG_LIRC_BT829=m +CONFIG_LIRC_ENE0100=m +CONFIG_LIRC_I2C=m +CONFIG_LIRC_IGORPLUGUSB=m +CONFIG_LIRC_IMON=m +CONFIG_LIRC_IT87=m +CONFIG_LIRC_ITE8709=m +CONFIG_LIRC_MCEUSB=m +CONFIG_LIRC_ZILOG=m +CONFIG_LIRC_PARALLEL=m +CONFIG_LIRC_SERIAL=m +CONFIG_LIRC_SERIAL_TRANSMITTER=y +CONFIG_LIRC_SASEM=m +CONFIG_LIRC_SIR=m +CONFIG_LIRC_STREAMZAP=m +CONFIG_LIRC_TTUSBIR=m + +# CONFIG_SAMPLES is not set + +# CONFIG_DEVKMEM is not set + +CONFIG_PM_TRACE_RTC=y +CONFIG_R6040=m + +CONFIG_BNX2X=m +CONFIG_NOZOMI=m +CONFIG_PCF8575=m +# CONFIG_TPS65010 is not set +# CONFIG_DEBUG_SECTION_MISMATCH is not set +# CONFIG_KPROBES_SANITY_TEST is not set +# CONFIG_BACKTRACE_SELF_TEST is not set +CONFIG_LATENCYTOP=y +CONFIG_RESOURCE_COUNTERS=y +# CONFIG_COMPAT_BRK is not set + +CONFIG_ACPI_CUSTOM_DSDT_INITRD=y + +#FIXME: x86 generic? +CONFIG_LEDS_CLEVO_MAIL=m +CONFIG_I8K=m +CONFIG_EDAC_I3000=m +CONFIG_EDAC_X38=m +CONFIG_INPUT_APANEL=m + +# CONFIG_INTEL_MENLOW is not set +CONFIG_ENCLOSURE_SERVICES=m +CONFIG_ISL29003=m +CONFIG_IPWIRELESS=m +CONFIG_RTC_DRV_DS1511=m +CONFIG_CGROUP_MEM_CONT=y + +# CONFIG_BLK_DEV_XIP is not set +CONFIG_MEMSTICK=m +# CONFIG_MEMSTICK_DEBUG is not set +# CONFIG_MEMSTICK_UNSAFE_RESUME is not set +CONFIG_MSPRO_BLOCK=m +CONFIG_MEMSTICK_TIFM_MS=m +CONFIG_MEMSTICK_JMICRON_38X=m + +CONFIG_ACCESSIBILITY=y +CONFIG_A11Y_BRAILLE_CONSOLE=y + +# CONFIG_HTC_PASIC3 is not set + +# MT9V022_PCA9536_SWITCH is not set + +CONFIG_THERMAL_HWMON=y + +CONFIG_OPTIMIZE_INLINING=y + +# FIXME: This should be x86/ia64 only +# CONFIG_HP_ILO is not set + +# CONFIG_GPIOLIB is not set + +CONFIG_UNEVICTABLE_LRU=y + +CONFIG_NETFILTER_TPROXY=m +CONFIG_NETFILTER_XT_TARGET_TPROXY=m +CONFIG_NETFILTER_XT_MATCH_RECENT=m +# CONFIG_NETFILTER_XT_MATCH_RECENT_PROC_COMPAT is not set +CONFIG_NETFILTER_XT_MATCH_SOCKET=m + +# CONFIG_IP_VS_IPV6 is not set + +CONFIG_NET_DSA=y +CONFIG_NET_DSA_MV88E6060=y +CONFIG_NET_DSA_MV88E6131=y +CONFIG_NET_DSA_MV88E6123_61_65=y + +CONFIG_NET_SCH_MULTIQ=m +CONFIG_NET_ACT_SKBEDIT=m + +CONFIG_PHONET=m + +CONFIG_ICS932S401=m +# CONFIG_C2PORT is not set +CONFIG_W1_SLAVE_BQ27000=m + + +CONFIG_IT87_WDT=m +CONFIG_W83697UG_WDT=m + +CONFIG_REGULATOR=y +# CONFIG_REGULATOR_DEBUG is not set +CONFIG_REGULATOR_FIXED_VOLTAGE=m +# CONFIG_REGULATOR_VIRTUAL_CONSUMER is not set +CONFIG_REGULATOR_BQ24022=m +CONFIG_REGULATOR_WM8350=m +CONFIG_REGULATOR_WM8400=m +CONFIG_REGULATOR_DA903X=m +CONFIG_REGULATOR_USERSPACE_CONSUMER=m +CONFIG_REGULATOR_MAX1586=m +CONFIG_REGULATOR_LP3971=m +CONFIG_REGULATOR_AB3100=m +CONFIG_REGULATOR_TPS65023=m +CONFIG_REGULATOR_TPS6507X=m +CONFIG_REGULATOR_WM831X=m +CONFIG_REGULATOR_MAX8660=m + +CONFIG_WM8350_POWER=m + +# CONFIG_VIDEO_FIXED_MINOR_RANGES is not set + +CONFIG_USB_WUSB=m +CONFIG_USB_WUSB_CBAF=m +# CONFIG_USB_WUSB_CBAF_DEBUG is not set +CONFIG_USB_WHCI_HCD=m +CONFIG_USB_HWA_HCD=m + +CONFIG_UWB=m +CONFIG_UWB_HWA=m +CONFIG_UWB_WHCI=m +CONFIG_UWB_WLP=m +CONFIG_UWB_I1480U=m +CONFIG_UWB_I1480U_WLP=m + +CONFIG_STAGING=y +# CONFIG_STAGING_EXCLUDE_BUILD is not set +# CONFIG_ET131X is not set +# CONFIG_SLICOSS is not set +# CONFIG_SXG is not set +# CONFIG_ME4000 is not set +# CONFIG_MEILHAUS is not set +# CONFIG_VIDEO_GO7007 is not set +# CONFIG_USB_IP_COMMON is not set +# CONFIG_W35UND is not set +# CONFIG_PRISM2_USB is not set +# CONFIG_ECHO is not set +CONFIG_USB_ATMEL=m +# CONFIG_POCH is not set +# CONFIG_AGNX is not set +# CONFIG_OTUS is not set +# CONFIG_RT2860 is not set +# CONFIG_RT2870 is not set +# CONFIG_BENET is not set +# CONFIG_COMEDI is not set +# CONFIG_ASUS_OLED is not set +# CONFIG_PANEL is not set +# CONFIG_ALTERA_PCIE_CHDMA is not set +# CONFIG_RTL8187SE is not set +# CONFIG_INPUT_MIMIO is not set +# CONFIG_TRANZPORT is not set +# CONFIG_EPL is not set +# CONFIG_POHMELFS is not set +# CONFIG_USB_SERIAL_ATEN2011 is not set +# CONFIG_B3DFG is not set +# CONFIG_DST is not set +# CONFIG_IDE_PHISON is not set +# CONFIG_PLAN9AUTH is not set +# CONFIG_HECI is not set +# CONFIG_LINE6_USB is not set +# CONFIG_USB_SERIAL_QUATECH_ESU100 is not set +# CONFIG_RT3070 is not set +# CONFIG_RTL8192SU is not set +# CONFIG_COWLOOP is not set +# CONFIG_IIO is not set +# CONFIG_VME_BUS is not set +# CONFIG_RAR_REGISTER is not set +# CONFIG_VT6656 is not set +# CONFIG_USB_SERIAL_QUATECH_USB2 is not set +# CONFIG_RTL8192E is not set +# CONFIG_INPUT_GPIO is not set +# CONFIG_VIDEO_CX25821 is not set +# CONFIG_RT3090 is not set +# CONFIG_HYPERV is not set +# CONFIG_R8187SE is not set +# CONFIG_RTL8192U is not set +# CONFIG_RAMZSWAP is not set +# CONFIG_BATMAN_ADV is not set +# CONFIG_FB_SM7XX is not set + +# +# Android +# +# CONFIG_ANDROID is not set +# CONFIG_ANDROID_BINDER_IPC is not set +# CONFIG_ANDROID_LOGGER is not set +# CONFIG_ANDROID_RAM_CONSOLE is not set +# CONFIG_ANDROID_LOW_MEMORY_KILLER is not set +# CONFIG_ANDROID_TIMED_GPIO is not set + +# CONFIG_DEBUG_VIRTUAL is not set +# CONFIG_RCU_CPU_STALL_DETECTOR is not set +# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set +# CONFIG_FUNCTION_GRAPH_TRACER is not set +# CONFIG_BOOT_TRACER is not set +# CONFIG_DYNAMIC_PRINTK_DEBUG is not set +CONFIG_EARLY_PRINTK_DBGP=y + +CONFIG_SECURITYFS=y + +CONFIG_SCSI_CXGB3_ISCSI=m +CONFIG_LIBFC=m +CONFIG_LIBFCOE=m +CONFIG_FCOE=m +CONFIG_FCOE_FNIC=m +# CONFIG_SCSI_LPFC_DEBUG_FS is not set + +CONFIG_NOP_USB_XCEIV=m + +CONFIG_IMA=y +CONFIG_IMA_MEASURE_PCR_IDX=10 +CONFIG_IMA_AUDIT=y +CONFIG_IMA_LSM_RULES=y + +CONFIG_LSM_MMAP_MIN_ADDR=65536 + +# CONFIG_PAGE_POISONING is not set + +CONFIG_SLOW_WORK=y +CONFIG_SLOW_WORK_DEBUG=y + +# CONFIG_CRASH_DUMP is not set +# CONFIG_CRASH is not set + +CONFIG_STRIP_ASM_SYMS=y + +# CONFIG_RCU_FANOUT_EXACT is not set + +CONFIG_KSM=y +CONFIG_DEFAULT_MMAP_MIN_ADDR=4096 + +CONFIG_FSNOTIFY=y + +CONFIG_IEEE802154=m +CONFIG_IEEE802154_DRIVERS=m +CONFIG_IEEE802154_FAKEHARD=m + +# CONFIG_GCOV_KERNEL is not set + +CONFIG_PPS=m +# CONFIG_PPS_DEBUG is not set + +# CONFIG_USB_SERIAL_QUATECH2 is not set +# CONFIG_VT6655 is not set +# CONFIG_USB_CPC is not set +# CONFIG_RDC_17F3101X is not set +# CONFIG_FB_UDL is not set + +# DEBUG options that don't get enabled/disabled with 'make debug/release' +# +# Kmemleak still produces a lot of false positives. +# CONFIG_DEBUG_KMEMLEAK is not set +# +# This generates a huge amount of dmesg spew +# CONFIG_DEBUG_KOBJECT is not set +# +# +# These debug options are deliberatly left on (even in 'make release' kernels). +# They aren't that much of a performance impact, and the value +# from getting useful bug-reports makes it worth leaving them on. +CONFIG_DYNAMIC_DEBUG=y +CONFIG_DEBUG_HIGHMEM=y +CONFIG_DEBUG_SPINLOCK_SLEEP=y +CONFIG_BOOT_PRINTK_DELAY=y +CONFIG_DEBUG_LIST=y +CONFIG_DEBUG_SHIRQ=y +CONFIG_DEBUG_DEVRES=y +CONFIG_DEBUG_RODATA_TEST=y +CONFIG_DEBUG_NX_TEST=m +CONFIG_DEBUG_BOOT_PARAMS=y +CONFIG_DETECT_SOFTLOCKUP=y +# CONFIG_BOOTPARAM_SOFTLOCKUP_PANIC is not set +CONFIG_DETECT_HUNG_TASK=y +# CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set + +CONFIG_MEMORY_FAILURE=y +CONFIG_HWPOISON_INJECT=m + +CONFIG_BLK_DEV_DRBD=m + +# CONFIG_MDIO_GPIO is not set +# CONFIG_KEYBOARD_GPIO is not set +# CONFIG_MOUSE_GPIO is not set +# CONFIG_I2C_GPIO is not set +# CONFIG_DEBUG_GPIO is not set +# CONFIG_W1_MASTER_GPIO is not set +# CONFIG_LEDS_GPIO is not set +# CONFIG_GPIO_SYSFS is not set +# CONFIG_GPIO_MAX732X is not set +# CONFIG_GPIO_PCA953X is not set +# CONFIG_GPIO_PCF857X is not set +# CONFIG_GPIO_CS5535 is not set +# CONFIG_GPIO_ADP5588 is not set +# CONFIG_UCB1400_CORE is not set +# CONFIG_RADIO_MIROPCM20 is not set +# CONFIG_USB_GPIO_VBUS is not set + + +CONFIG_KSYM_TRACER=y +CONFIG_PROFILE_KSYM_TRACER=y +CONFIG_KPROBE_EVENT=y diff --git a/config-i686-PAE b/config-i686-PAE new file mode 100644 index 000000000..1e58e65b2 --- /dev/null +++ b/config-i686-PAE @@ -0,0 +1,5 @@ +# CONFIG_HIGHMEM4G is not set +CONFIG_HIGHMEM64G=y + +CONFIG_XEN_DEV_EVTCHN=m +CONFIG_XEN_SYS_HYPERVISOR=y diff --git a/config-ia64-generic b/config-ia64-generic new file mode 100644 index 000000000..281ce4687 --- /dev/null +++ b/config-ia64-generic @@ -0,0 +1,215 @@ +# +# Automatically generated make config: don't edit +# + +# +# Processor type and features +# +CONFIG_IA64=y +CONFIG_64BIT=y +# CONFIG_XEN is not set +# CONFIG_ARCH_XEN is not set +# CONFIG_XEN_PRIVILEGED_GUEST is not set +# CONFIG_XEN_VT is not set +CONFIG_MMU=y +CONFIG_RWSEM_XCHGADD_ALGORITHM=y +CONFIG_EFI=y +# CONFIG_ITANIUM is not set +CONFIG_MCKINLEY=y +CONFIG_IA64_GENERIC=y +# CONFIG_IA64_DIG is not set +# CONFIG_IA64_HP_ZX1 is not set +# CONFIG_IA64_SGI_SN2 is not set +CONFIG_IA64_ESI=y +CONFIG_IA64_HP_AML_NFW=y +CONFIG_MSPEC=y +# CONFIG_IA64_HP_SIM is not set +# CONFIG_IA64_PAGE_SIZE_4KB is not set +# CONFIG_IA64_PAGE_SIZE_8KB is not set +CONFIG_IA64_PAGE_SIZE_16KB=y +# CONFIG_IA64_PAGE_SIZE_64KB is not set +CONFIG_IA64_L1_CACHE_SHIFT=7 +CONFIG_NUMA=y +# CONFIG_VIRTUAL_MEM_MAP is not set +CONFIG_SPARSEMEM_MANUAL=y +CONFIG_SPARSEMEM=y +CONFIG_MEMORY_HOTPLUG=y +CONFIG_MEMORY_HOTREMOVE=y +CONFIG_IA64_MCA_RECOVERY=m +CONFIG_IA64_CYCLONE=y +CONFIG_MMTIMER=y +CONFIG_IOSAPIC=y +CONFIG_FORCE_MAX_ZONEORDER=18 +CONFIG_NR_CPUS=1024 +# CONFIG_IA32_SUPPORT is not set +# CONFIG_COMPAT is not set +CONFIG_PERFMON=y +CONFIG_IA64_PALINFO=y +CONFIG_EFI_VARS=y +CONFIG_SERIAL_8250_RUNTIME_UARTS=16 +CONFIG_EFI_PCDP=y +# +# Block devices +# +# CONFIG_BLK_DEV_FD is not set + +# +# IDE chipset support/bugfixes +# +CONFIG_IDE_MAX_HWIFS=4 +CONFIG_BLK_DEV_SGIIOC4=y + +# +# Character devices +# +CONFIG_TCG_INFINEON=m + +# +# Watchdog Cards +# +# CONFIG_HW_RANDOM is not set +# CONFIG_GEN_RTC is not set +CONFIG_EFI_RTC=y +CONFIG_RTC_DRV_EFI=y + + +# +# AGP +# +CONFIG_AGP_I460=y +CONFIG_AGP_HP_ZX1=y +CONFIG_AGP_SGI_TIOCA=y + +# +# HP Simulator drivers +# +# CONFIG_HP_SIMETH is not set +# CONFIG_HP_SIMSERIAL is not set +# CONFIG_HP_SIMSCSI is not set + +# +# Kernel hacking +# +# CONFIG_IA64_PRINT_HAZARDS is not set +# CONFIG_DISABLE_VHPT is not set +# CONFIG_IA64_DEBUG_CMPXCHG is not set +# CONFIG_IA64_DEBUG_IRQ is not set + +# +# Memory Technology Devices (MTD) +# +# CONFIG_MTD is not set + +# +# SGI +# +CONFIG_SGI_SNSC=y +CONFIG_IA64_SGI_SN_XP=y +CONFIG_SGI_TIOCX=y +CONFIG_SGI_MBCS=m +CONFIG_SGI_IOC3=m +CONFIG_SGI_IOC4=y +CONFIG_SGI_XP=m +CONFIG_SGI_GRU=m +# CONFIG_SGI_GRU_DEBUG is not set +CONFIG_SERIAL_SGI_L1_CONSOLE=y +CONFIG_SERIAL_SGI_IOC3=m +CONFIG_SERIAL_SGI_IOC4=m + + +# +# SCSI low-level drivers +# +# CONFIG_SCSI_BUSLOGIC is not set + +# +CONFIG_ACPI=y +CONFIG_ACPI_AC=y +# CONFIG_ACPI_ASUS is not set +CONFIG_ACPI_PROCFS_POWER=y +CONFIG_ACPI_SYSFS_POWER=y +# CONFIG_ACPI_BAY is not set +# CONFIG_ACPI_BATTERY is not set +CONFIG_ACPI_BLACKLIST_YEAR=0 +CONFIG_ACPI_BUTTON=y +# CONFIG_ACPI_DOCK is not set +CONFIG_ACPI_EC=y +CONFIG_ACPI_FAN=y +CONFIG_ACPI_HOTPLUG_MEMORY=y +CONFIG_ACPI_NUMA=y +CONFIG_ACPI_POWER=y +CONFIG_ACPI_PROCESSOR=y +CONFIG_ACPI_PROCFS=y +CONFIG_ACPI_SLEEP=y +CONFIG_ACPI_SYSTEM=y +CONFIG_ACPI_THERMAL=y +# CONFIG_ACPI_TOSHIBA is not set +CONFIG_ACPI_VIDEO=m +# CONFIG_ACPI_PROC_EVENT is not set + +CONFIG_PM=y +CONFIG_HOTPLUG_PCI=y +# CONFIG_HPET is not set +# CONFIG_HOTPLUG_PCI_CPCI is not set +CONFIG_HOTPLUG_PCI_SHPC=m +CONFIG_HOTPLUG_PCI_SGI=m +CONFIG_PNPACPI=y + +CONFIG_SCHED_SMT=y + +CONFIG_ARCH_DISCONTIGMEM_ENABLE=y + +CONFIG_CPU_FREQ=y +CONFIG_CPU_FREQ_DEBUG=y +CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y +CONFIG_CPU_FREQ_GOV_POWERSAVE=m +CONFIG_CPU_FREQ_GOV_USERSPACE=m +CONFIG_CPU_FREQ_GOV_ONDEMAND=m +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m +CONFIG_CPU_FREQ_STAT=m +CONFIG_CPU_FREQ_STAT_DETAILS=y + +CONFIG_IA64_ACPI_CPUFREQ=m + +# CONFIG_PERMIT_BSP_REMOVE is not set +# CONFIG_FORCE_CPEI_RETARGET is not set + +CONFIG_NODES_SHIFT=10 + +# CONFIG_BCM43XX is not set + +CONFIG_HW_RANDOM_INTEL=m + +CONFIG_CRASH_DUMP=y +CONFIG_PROC_VMCORE=y + +# drivers/media/video/usbvision/usbvision-i2c.c:64:39: error: macro "outb" passed 4 arguments, but takes just 2 +# CONFIG_VIDEO_USBVISION is not set + +# CONFIG_IA64_MC_ERR_INJECT is not set + +CONFIG_DMIID=y + +CONFIG_SENSORS_I5K_AMB=m + +CONFIG_SPARSEMEM_VMEMMAP=y + +CONFIG_FRAME_WARN=2048 + +CONFIG_VIRT_CPU_ACCOUNTING=y +CONFIG_VIRTUALIZATION=y +CONFIG_KVM=m +CONFIG_KVM_INTEL=m + +CONFIG_HP_ILO=m + +CONFIG_PARAVIRT_GUEST=y +CONFIG_PARAVIRT=y + +CONFIG_DMAR_DEFAULT_ON=y + +CONFIG_RCU_FANOUT=64 + +CONFIG_ACPI_POWER_METER=m +CONFIG_I2C_SCMI=m diff --git a/config-nodebug b/config-nodebug new file mode 100644 index 000000000..107955d68 --- /dev/null +++ b/config-nodebug @@ -0,0 +1,78 @@ +CONFIG_SND_VERBOSE_PRINTK=y +CONFIG_SND_DEBUG=y +CONFIG_SND_PCM_XRUN_DEBUG=y + +# CONFIG_DEBUG_MUTEXES is not set +# CONFIG_DEBUG_RT_MUTEXES is not set +# CONFIG_DEBUG_LOCK_ALLOC is not set +# CONFIG_PROVE_LOCKING is not set +# CONFIG_DEBUG_VM is not set +# CONFIG_DEBUG_SPINLOCK is not set + +# CONFIG_FAULT_INJECTION is not set +# CONFIG_FAILSLAB is not set +# CONFIG_FAIL_PAGE_ALLOC is not set +# CONFIG_FAIL_MAKE_REQUEST is not set +# CONFIG_FAULT_INJECTION_DEBUG_FS is not set +# CONFIG_FAULT_INJECTION_STACKTRACE_FILTER is not set +# CONFIG_FAIL_IO_TIMEOUT is not set + +# CONFIG_SLUB_DEBUG_ON is not set + +# CONFIG_LOCK_STAT is not set + +# CONFIG_DEBUG_STACK_USAGE is not set + +# CONFIG_ACPI_DEBUG is not set +# CONFIG_ACPI_DEBUG_FUNC_TRACE is not set + +# CONFIG_DEBUG_SG is not set + +# CONFIG_DEBUG_PAGEALLOC is not set + +# CONFIG_DEBUG_WRITECOUNT is not set +# CONFIG_DEBUG_OBJECTS is not set +# CONFIG_DEBUG_OBJECTS_SELFTEST is not set +# CONFIG_DEBUG_OBJECTS_FREE is not set +# CONFIG_DEBUG_OBJECTS_TIMERS is not set +CONFIG_DEBUG_OBJECTS_ENABLE_DEFAULT=1 + +# CONFIG_X86_PTDUMP is not set + +# CONFIG_CAN_DEBUG_DEVICES is not set + +# CONFIG_MODULE_FORCE_UNLOAD is not set + +# CONFIG_SYSCTL_SYSCALL_CHECK is not set + +# CONFIG_DEBUG_NOTIFIERS is not set + +# CONFIG_DMA_API_DEBUG is not set + +# CONFIG_MMIOTRACE is not set + +# CONFIG_DEBUG_CREDENTIALS is not set + +# off in both production debug and nodebug builds, +# on in rawhide nodebug builds +# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set + +# CONFIG_EXT4_DEBUG is not set + +# CONFIG_DEBUG_PERF_USE_VMALLOC is not set + +# CONFIG_JBD2_DEBUG is not set + +# CONFIG_FUNCTION_TRACER is not set +# CONFIG_STACK_TRACER is not set +# CONFIG_DYNAMIC_FTRACE is not set + +# CONFIG_DEBUG_CFQ_IOSCHED is not set + +# CONFIG_DRBD_FAULT_INJECTION is not set + +# CONFIG_ATH_DEBUG is not set +# CONFIG_IWLWIFI_DEVICE_TRACING is not set + +# CONFIG_DEBUG_OBJECTS_WORK is not set +# CONFIG_DEBUG_STRICT_USER_COPY_CHECKS is not set diff --git a/config-powerpc-generic b/config-powerpc-generic new file mode 100644 index 000000000..3bcecab9f --- /dev/null +++ b/config-powerpc-generic @@ -0,0 +1,345 @@ +# Most PowerPC kernels we build are SMP +CONFIG_SMP=y +CONFIG_IRQ_ALL_CPUS=y +CONFIG_PPC=y +CONFIG_WATCHDOG_RTAS=m +CONFIG_DEBUGGER=y +CONFIG_GENERIC_NVRAM=y +CONFIG_ALTIVEC=y + +CONFIG_TAU=y +# CONFIG_TAU_INT is not set +CONFIG_TAU_AVERAGE=y + +CONFIG_SECCOMP=y + +CONFIG_CPU_FREQ=y +CONFIG_CPU_FREQ_DEBUG=y +# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set +CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y +CONFIG_CPU_FREQ_GOV_POWERSAVE=m +CONFIG_CPU_FREQ_GOV_USERSPACE=m +CONFIG_CPU_FREQ_GOV_ONDEMAND=m +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m +CONFIG_CPU_FREQ_TABLE=y +CONFIG_CPU_FREQ_STAT=m +CONFIG_CPU_FREQ_STAT_DETAILS=y + +CONFIG_PM=y + +CONFIG_PM_STD_PARTITION="" + +CONFIG_SUSPEND=y +CONFIG_HIBERNATION=y +# CONFIG_RTC is not set +# CONFIG_GEN_RTC is not set +# CONFIG_GEN_RTC_X is not set +CONFIG_RTC_DRV_PPC=y +CONFIG_RTC_DRV_GENERIC=y +CONFIG_PROC_DEVICETREE=y +# CONFIG_CMDLINE_BOOL is not set +CONFIG_ELECTRA_IDE=y + +CONFIG_ADB=y +CONFIG_ADB_PMU=y +CONFIG_WINDFARM=y +CONFIG_WINDFARM_PM112=y +CONFIG_I2C_POWERMAC=y +CONFIG_APPLE_AIRPORT=m +CONFIG_SERIAL_PMACZILOG=m +# CONFIG_SERIAL_PMACZILOG_TTYS is not set +CONFIG_AGP_UNINORTH=y +CONFIG_FB_OF=y +# CONFIG_FB_CONTROL is not set +CONFIG_FB_IBM_GXT4500=y +CONFIG_FB_RADEON=y +CONFIG_FB_MATROX=y +CONFIG_FB_NVIDIA=m +# CONFIG_FB_VGA16 is not set +CONFIG_FB_ATY128_BACKLIGHT=y +CONFIG_FB_ATY_BACKLIGHT=y +CONFIG_FB_RADEON_BACKLIGHT=y +CONFIG_FB_RIVA_BACKLIGHT=y +CONFIG_FB_NVIDIA_BACKLIGHT=y + +CONFIG_SND_POWERMAC=m +CONFIG_SND_POWERMAC_AUTO_DRC=y +CONFIG_SND_AOA=m +CONFIG_SND_AOA_SOUNDBUS=m +CONFIG_SND_AOA_FABRIC_LAYOUT=m +CONFIG_SND_AOA_ONYX=m +CONFIG_SND_AOA_TAS=m +CONFIG_SND_AOA_TOONIE=m +CONFIG_SND_AOA_SOUNDBUS_I2S=m + +CONFIG_XMON=y +# CONFIG_XMON_DEFAULT is not set +CONFIG_XMON_DISASSEMBLY=y + +CONFIG_BOOTX_TEXT=y +CONFIG_MAC_EMUMOUSEBTN=y +CONFIG_CAPI_EICON=y + +CONFIG_NVRAM=y + +# CONFIG_PCMCIA_M8XX is not set +# CONFIG_SCSI_AHA1542 is not set +# CONFIG_SCSI_IN2000 is not set +# CONFIG_SCSI_IPS is not set +# CONFIG_NI52 is not set +# CONFIG_NI65 is not set +# CONFIG_LANCE is not set +# CONFIG_3C515 is not set +# CONFIG_ELPLUS is not set + +CONFIG_MEMORY_HOTPLUG=y + +# Stuff which wants bus_to_virt() or virt_to_bus() +# CONFIG_BLK_CPQ_DA is not set +# CONFIG_VIDEO_STRADIS is not set +# CONFIG_VIDEO_ZORAN is not set +# CONFIG_ATM_HORIZON is not set +# CONFIG_ATM_FIRESTREAM is not set +# CONFIG_ATM_AMBASSADOR is not set +# CONFIG_SCSI_DC390T is not set +# CONFIG_SCSI_BUSLOGIC is not set + +CONFIG_USB_HIDINPUT_POWERBOOK=y + +# CONFIG_PPC_EARLY_DEBUG is not set + +# CONFIG_PMAC_BACKLIGHT_LEGACY is not set +CONFIG_LEDS_TRIGGER_TIMER=m +CONFIG_LEDS_TRIGGER_HEARTBEAT=m +CONFIG_LEDS_TRIGGER_GPIO=m + +# FIXME: Should depend on IA64/x86 +# CONFIG_SGI_IOC4 is not set + +CONFIG_PPC_EFIKA=y +CONFIG_PPC_MEDIA5200=y + +# CONFIG_PPC_LITE5200 is not set +CONFIG_PPC_BESTCOMM=y +CONFIG_PMAC_RACKMETER=m +CONFIG_USB_OHCI_HCD_PPC_SOC=y +CONFIG_USB_OHCI_HCD_PCI=y +CONFIG_USB_OHCI_HCD_PPC_OF=y +CONFIG_USB_OHCI_HCD_PPC_OF_BE=y +CONFIG_USB_OHCI_HCD_PPC_OF_LE=y + +CONFIG_SERIAL_UARTLITE=m +CONFIG_SERIAL_UARTLITE_CONSOLE=y + +CONFIG_SENSORS_AMS=m +CONFIG_SENSORS_AMS_PMU=y +CONFIG_SENSORS_AMS_I2C=y + +CONFIG_IDE=y +CONFIG_BLK_DEV_IDE=y + +# +# Please see Documentation/ide.txt for help/info on IDE drives +# +# CONFIG_BLK_DEV_IDE_SATA is not set +CONFIG_BLK_DEV_IDEDISK=y +CONFIG_IDEDISK_MULTI_MODE=y +# CONFIG_BLK_DEV_IDECS is not set +CONFIG_BLK_DEV_IDECD=m +# CONFIG_BLK_DEV_IDETAPE is not set +CONFIG_BLK_DEV_IDEFLOPPY=m +# CONFIG_BLK_DEV_IDESCSI is not set +CONFIG_IDE_TASK_IOCTL=y +# +# IDE chipset support/bugfixes +# +# CONFIG_IDE_GENERIC is not set +# CONFIG_BLK_DEV_IDEPNP is not set +# CONFIG_BLK_DEV_IDEPCI is not set +CONFIG_IDEPCI_SHARE_IRQ=y +# CONFIG_BLK_DEV_AEC62XX is not set +# CONFIG_BLK_DEV_ALI15X3 is not set +# CONFIG_BLK_DEV_AMD74XX is not set +# CONFIG_BLK_DEV_CMD64X is not set +# CONFIG_BLK_DEV_TRIFLEX is not set +# CONFIG_BLK_DEV_CY82C693 is not set +# CONFIG_BLK_DEV_CS5520 is not set +# CONFIG_BLK_DEV_CS5530 is not set +# CONFIG_BLK_DEV_HPT34X is not set +# CONFIG_BLK_DEV_HPT366 is not set +# CONFIG_BLK_DEV_JMICRON is not set +# CONFIG_BLK_DEV_SC1200 is not set +# CONFIG_BLK_DEV_PIIX is not set +# CONFIG_BLK_DEV_IT821X is not set +# CONFIG_BLK_DEV_NS87415 is not set +# CONFIG_BLK_DEV_PDC202XX_OLD is not set +# CONFIG_BLK_DEV_PDC202XX_NEW is not set +# CONFIG_BLK_DEV_SVWKS is not set +# CONFIG_BLK_DEV_SIIMAGE is not set +# CONFIG_BLK_DEV_SL82C105 is not set +# CONFIG_BLK_DEV_SLC90E66 is not set +# CONFIG_BLK_DEV_TRM290 is not set +# CONFIG_BLK_DEV_VIA82CXXX is not set +CONFIG_BLK_DEV_IDE_PMAC=y +CONFIG_BLK_DEV_IDE_PMAC_ATA100FIRST=y +CONFIG_BLK_DEV_IDEDMA_PMAC=y +# CONFIG_IDE_ARM is not set +CONFIG_BLK_DEV_IDEDMA=y +# CONFIG_BLK_DEV_HD is not set +# CONFIG_USB_STORAGE_ISD200 is not set +CONFIG_MTD_PHYSMAP_OF=m +CONFIG_IDE_PROC_FS=y +CONFIG_MACINTOSH_DRIVERS=y + +CONFIG_PPC_PASEMI_MDIO=m +CONFIG_SPU_FS_64K_LS=y +CONFIG_PPC_PASEMI_CPUFREQ=y +CONFIG_PMAC_APM_EMU=m +CONFIG_HW_RANDOM_PASEMI=m + +CONFIG_EDAC=y +# CONFIG_EDAC_DEBUG is not set +CONFIG_EDAC_MM_EDAC=m +CONFIG_EDAC_PASEMI=m +CONFIG_EDAC_AMD8131=m +CONFIG_EDAC_AMD8111=m + +CONFIG_AXON_RAM=m +CONFIG_OPROFILE_CELL=y + +CONFIG_SUSPEND_FREEZER=y +# CONFIG_IDEPCI_PCIBUS_ORDER is not set +CONFIG_PATA_PLATFORM=m +CONFIG_PATA_OF_PLATFORM=m +CONFIG_USB_EHCI_HCD_PPC_OF=y + +# CONFIG_MPC5121_ADS is not set +# CONFIG_MPC5121_GENERIC is not set +CONFIG_MTD_OF_PARTS=m +# CONFIG_MTD_NAND_FSL_ELBC is not set +CONFIG_THERMAL=y + +# CONFIG_MEMORY_HOTREMOVE is not set + +CONFIG_DMADEVICES=y +# CONFIG_FSL_DMA is not set + +CONFIG_SND_PPC=y + +CONFIG_PPC_82xx=y +CONFIG_PPC_83xx=y +CONFIG_PPC_86xx=y +CONFIG_EXTRA_TARGETS="" +# CONFIG_CODE_PATCHING_SELFTEST is not set +# CONFIG_FTR_FIXUP_SELFTEST is not set + +# CONFIG_MATH_EMULATION is not set +# CONFIG_RAPIDIO is not set +# CONFIG_FS_ENET is not set +# CONFIG_UCC_GETH is not set +# CONFIG_KEYBOARD_MATRIX is not set +# CONFIG_SERIAL_CPM is not set +# CONFIG_SERIAL_QE is not set +# CONFIG_I2C_CPM is not set +# CONFIG_MT9M001_PCA9536_SWITCH is not set +# CONFIG_MT9V022_PCA9536_SWITCH is not set +# CONFIG_KGDB_CONSOLE is not set + +CONFIG_MDIO_OF_GPIO=m + +CONFIG_SERIO_XILINX_XPS_PS2=m + +# CONFIG_PPC_SMLPAR is not set + +CONFIG_MGCOGE=y +CONFIG_GEF_SBC610=y +CONFIG_GEF_PPC9A=y +CONFIG_GEF_SBC310=y + +CONFIG_QUICC_ENGINE=y +CONFIG_QE_GPIO=y +CONFIG_MPC8xxx_GPIO=y + +CONFIG_IDE_GD=y +CONFIG_IDE_GD_ATA=y +CONFIG_IDE_GD_ATAPI=y + +CONFIG_MCU_MPC8349EMITX=m + +CONFIG_GPIO_XILINX=y + +CONFIG_PMIC_DA903X=y +CONFIG_BACKLIGHT_DA903X=m +CONFIG_LEDS_DA903X=m + +CONFIG_MSI_BITMAP_SELFTEST=y + +CONFIG_RELOCATABLE=y + +# CONFIG_HVC_UDBG is not set +CONFIG_PRINT_STACK_DEPTH=64 + +CONFIG_BATTERY_DA9030=m +# CONFIG_TWL4030_CORE is not set + +CONFIG_BLK_DEV_IT8172=m +CONFIG_TOUCHSCREEN_DA9034=m + +CONFIG_SIMPLE_GPIO=y + +CONFIG_FSL_PQ_MDIO=m + +CONFIG_PS3_VRAM=m +CONFIG_MDIO_GPIO=m +CONFIG_SERIAL_OF_PLATFORM_NWPSERIAL=m +# CONFIG_DEBUG_GPIO is not set +CONFIG_GPIO_PCA953X=m +CONFIG_GPIO_PCF857X=m + +# CONFIG_USB_FHCI_HCD is not set +# CONFIG_FHCI_DEBUG is not set + +# CONFIG_DRM_RADEON_KMS is not set + +# CONFIG_AMIGAONE is not set + +CONFIG_PPC_OF_BOOT_TRAMPOLINE=y + +CONFIG_DTL=y + +CONFIG_MMC_SDHCI_OF=m + +# CONFIG_CONSISTENT_SIZE_BOOL is not set + +CONFIG_CAN_SJA1000_OF_PLATFORM=m + +CONFIG_PPC_EMULATED_STATS=y + +CONFIG_SWIOTLB=y + +# CONFIG_RDS is not set + +CONFIG_PPC_DISABLE_WERROR=y + +CONFIG_XILINX_EMACLITE=m + +CONFIG_GPIO_WM831X=m +# CONFIG_GPIO_LANGWELL is not set +# CONFIG_GPIO_UCB1400 is not set +CONFIG_EDAC_MPC85XX=m + +CONFIG_NR_IRQS=512 +CONFIG_SPARSE_IRQ=y + +CONFIG_PPC_MPC5200_LPBFIFO=m +CONFIG_CAN_MSCAN=m +CONFIG_CAN_MPC5XXX=m +CONFIG_PATA_MACIO=m +CONFIG_SERIAL_GRLIB_GAISLER_APBUART=m +# CONFIG_PMIC_ADP5520 is not set +# CONFIG_MFD_88PM8607 is not set +# CONFIG_XPS_USB_HCD_XILINX is not set +# CONFIG_MMC_SDHCI_OF_ESDHC is not set +# CONFIG_MMC_SDHCI_OF_HLWD is not set + diff --git a/config-powerpc32-generic b/config-powerpc32-generic new file mode 100644 index 000000000..ccd4a212d --- /dev/null +++ b/config-powerpc32-generic @@ -0,0 +1,190 @@ +# CONFIG_SMP is not set +CONFIG_PPC32=y +# CONFIG_PPC64 is not set +# CONFIG_RTAS_PROC is not set +# CONFIG_PCMCIA_M8XX is not set +# CONFIG_HOTPLUG_PCI is not set +CONFIG_CLASSIC32=y +CONFIG_CPU_FREQ_PMAC=y +CONFIG_PPC_MULTIPLATFORM=y +CONFIG_PPC_CHRP=y +CONFIG_PPC_PMAC=y +CONFIG_PPC_MPC52xx=y +CONFIG_PPC_PREP=y + +# CONFIG_PPC_MPC5200_SIMPLE is not set +CONFIG_SATA_FSL=m +# CONFIG_SATA_NV is not set + +# busted in .28git1 +# ERROR: "cacheable_memzero" [drivers/net/gianfar_driver.ko] undefined! +# CONFIG_GIANFAR is not set +CONFIG_GFAR_NAPI=y +CONFIG_USB_EHCI_FSL=y + +CONFIG_PMAC_APM_EMU=y +CONFIG_PMAC_BACKLIGHT=y + +CONFIG_HIGHMEM=y +# CONFIG_HIGHMEM_START_BOOL is not set +# CONFIG_LOWMEM_SIZE_BOOL is not set +# CONFIG_TASK_SIZE_BOOL is not set +# CONFIG_KERNEL_START_BOOL is not set +# CONFIG_PPC601_SYNC_FIX is not set +CONFIG_ADVANCED_OPTIONS=y +CONFIG_SCSI_MESH=m +CONFIG_SCSI_MESH_SYNC_RATE=5 +CONFIG_SCSI_MESH_RESET_DELAY_MS=4000 + +CONFIG_SCSI_MAC53C94=m +CONFIG_ADB_CUDA=y +CONFIG_ADB_MACIO=y +CONFIG_INPUT_ADBHID=y +CONFIG_ADB_PMU_LED=y +CONFIG_ADB_PMU_LED_IDE=y + +CONFIG_PMAC_MEDIABAY=y +CONFIG_BMAC=m +CONFIG_MACE=m +# CONFIG_MACE_AAUI_PORT is not set +CONFIG_MV643XX_ETH=m +CONFIG_I2C_HYDRA=m +CONFIG_I2C_MPC=m +CONFIG_THERM_WINDTUNNEL=m +CONFIG_THERM_ADT746X=m +# CONFIG_ANSLCD is not set + +CONFIG_SENSORS_M41T00=m +CONFIG_FB_PLATINUM=y +CONFIG_FB_VALKYRIE=y +CONFIG_FB_CT65550=y +# CONFIG_BDI_SWITCH is not set + +CONFIG_MAC_FLOPPY=m +# CONFIG_BLK_DEV_FD is not set + +CONFIG_FB_ATY128=y +CONFIG_FB_ATY=y +CONFIG_FB_MATROX=y +# CONFIG_KEXEC is not set + +# CONFIG_HVC_RTAS is not set +# CONFIG_MAMBO is not set + +# CONFIG_UDBG_RTAS_CONSOLE is not set +CONFIG_BRIQ_PANEL=m + +# CONFIG_ATA_PIIX is not set +# CONFIG_PATA_AMD is not set +# CONFIG_PATA_ATIIXP is not set +CONFIG_PATA_MPC52xx=m +# CONFIG_PATA_MPIIX is not set +# CONFIG_PATA_OLDPIIX is not set +# CONFIG_PATA_OPTI is not set +# CONFIG_PATA_SERVERWORKS is not set + +CONFIG_SERIAL_MPC52xx=y +CONFIG_SERIAL_MPC52xx_CONSOLE=y +CONFIG_SERIAL_MPC52xx_CONSOLE_BAUD=115200 +# CONFIG_MPC5200_WDT is not set +CONFIG_83xx_WDT=m +CONFIG_8xxx_WDT=m +CONFIG_GEF_WDT=m + +CONFIG_PPC_MPC5200_BUGFIX=y +CONFIG_FEC_MPC52xx=m +#CHECK: This may later become a tristate. +CONFIG_FEC_MPC52xx_MDIO=y +CONFIG_PPC_MPC5200_GPIO=y +CONFIG_MDIO_GPIO=m + +CONFIG_SERIAL_OF_PLATFORM=y +CONFIG_DEBUG_STACKOVERFLOW=y + +# CONFIG_EMBEDDED6xx is not set +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y + +# CONFIG_BLK_DEV_PLATFORM is not set +# CONFIG_BLK_DEV_4DRIVES is not set +# CONFIG_BLK_DEV_ALI14XX is not set +# CONFIG_BLK_DEV_DTC2278 is not set +# CONFIG_BLK_DEV_HT6560B is not set +# CONFIG_BLK_DEV_QD65XX is not set +# CONFIG_BLK_DEV_UMC8672 is not set + +# CONFIG_VIRQ_DEBUG is not set + +CONFIG_PPC_BESTCOMM_ATA=m +CONFIG_PPC_BESTCOMM_FEC=m +CONFIG_PPC_BESTCOMM_GEN_BD=m + +CONFIG_FORCE_MAX_ZONEORDER=11 +# CONFIG_PAGE_OFFSET_BOOL is not set +CONFIG_BLK_DEV_HD_ONLY=y +# CONFIG_FB_FSL_DIU is not set +CONFIG_IRQSTACKS=y +CONFIG_VIRTUALIZATION=y + +# CONFIG_DEBUG_GPIO is not set +# CONFIG_GPIO_PCA953X is not set +# CONFIG_GPIO_PCF857X is not set +# CONFIG_HTC_EGPIO is not set + +# CONFIG_TIFM_CORE is not set + +# CONFIG_BLK_CPQ_CISS_DA is not set +# CONFIG_CISS_SCSI_TAPE is not set + +# CONFIG_I2C_NFORCE2 is not set + +# CONFIG_SND_INTEL8X0 is not set +# CONFIG_SND_INTEL8X0M is not set + +# CONFIG_MEMSTICK is not set + +# CONFIG_IPMI_HANDLER is not set +# CONFIG_TCG_TPM is not set + +# PPC gets sad with debug alloc (bz 448598) +# CONFIG_DEBUG_PAGEALLOC is not set + +CONFIG_SND_ISA=y +CONFIG_CRYPTO_DEV_TALITOS=m + +CONFIG_FSL_EMB_PERFMON=y +CONFIG_MPC8272_ADS=y +CONFIG_PQ2FADS=y +CONFIG_EP8248E=y +CONFIG_MPC831x_RDB=y +CONFIG_MPC832x_MDS=y +CONFIG_MPC832x_RDB=y +CONFIG_MPC834x_MDS=y +CONFIG_MPC834x_ITX=y +CONFIG_MPC836x_MDS=y +CONFIG_MPC836x_RDK=y +CONFIG_MPC837x_MDS=y +CONFIG_MPC837x_RDB=y +CONFIG_SBC834x=y +CONFIG_ASP834x=y +CONFIG_KMETER1=y +CONFIG_MPC8641_HPCN=y +CONFIG_SBC8641D=y +CONFIG_MPC8610_HPCD=y + +# CONFIG_USB_MUSB_HDRC is not set + +# busted in 2.6.27 +# drivers/mtd/maps/sbc8240.c: In function 'init_sbc8240_mtd': +# drivers/mtd/maps/sbc8240.c:172: warning: passing argument 1 of 'simple_map_init' from incompatible pointer type +# drivers/mtd/maps/sbc8240.c:177: error: 'struct mtd_info' has no member named 'module' +# CONFIG_MTD_SBC8240 is not set + +CONFIG_MTD_NAND_FSL_UPM=m + +CONFIG_RCU_FANOUT=32 + +CONFIG_PERF_COUNTERS=y +CONFIG_PERF_EVENTS=y +CONFIG_EVENT_PROFILE=y + diff --git a/config-powerpc32-smp b/config-powerpc32-smp new file mode 100644 index 000000000..e60f59cdf --- /dev/null +++ b/config-powerpc32-smp @@ -0,0 +1,4 @@ +CONFIG_SMP=y +# CONFIG_HOTPLUG_CPU is not set +CONFIG_NR_CPUS=4 +# CONFIG_BATTERY_PMU is not set diff --git a/config-powerpc64 b/config-powerpc64 new file mode 100644 index 000000000..3dd228ad3 --- /dev/null +++ b/config-powerpc64 @@ -0,0 +1,197 @@ +CONFIG_WINDFARM_PM81=y +CONFIG_WINDFARM_PM91=y +CONFIG_WINDFARM_PM121=y +CONFIG_PPC_PMAC64=y +CONFIG_PPC_MAPLE=y +CONFIG_PPC_SYSTEMSIM=y +CONFIG_BLK_DEV_SYSTEMSIM=m +CONFIG_SYSTEMSIM_NET=m +CONFIG_PPC_CELL=y +CONFIG_PPC_IBM_CELL_BLADE=y +CONFIG_PPC_ISERIES=y +CONFIG_PPC_PSERIES=y +CONFIG_PPC_PMAC=y +CONFIG_PPC_PASEMI=y +# CONFIG_PPC_PASEMI_IOMMU_DMA_FORCE is not set +CONFIG_PPC_PS3=y +CONFIG_PPC_CELLEB=y +CONFIG_PPC_CELL_QPACE=y +CONFIG_PS3_HTAB_SIZE=20 +# CONFIG_PS3_DYNAMIC_DMA is not set +# CONFIG_PS3_USE_LPAR_ADDR is not set +CONFIG_PS3_ADVANCED=y +CONFIG_PS3_HTAB_SIZE=20 +# CONFIG_PS3_DYNAMIC_DMA is not set +CONFIG_PS3_USE_LPAR_ADDR=y +CONFIG_PS3_VUART=y +CONFIG_PS3_PS3AV=y +CONFIG_PS3_STORAGE=m +CONFIG_PS3_STORAGE_EXPECTED_NUM_DRIVES=3 +CONFIG_PS3_STORAGE_MAX_SPINUP_WAIT_TIME=10 +CONFIG_PS3_DISK=m +CONFIG_PS3_ROM=m +CONFIG_PS3_FLASH=m +CONFIG_PS3_LPM=y +CONFIG_SND_PS3=m +CONFIG_SND_PS3_DEFAULT_START_DELAY=1000 +CONFIG_GELIC_NET=m +CONFIG_GELIC_WIRELESS=y +CONFIG_GELIC_WIRELESS_OLD_PSK_INTERFACE=y +CONFIG_CBE_THERM=m +CONFIG_CBE_CPUFREQ=m +CONFIG_CBE_CPUFREQ_PMI=m +CONFIG_CBE_CPUFREQ_PMI_ENABLE=y +CONFIG_PMAC_RACKMETER=m +CONFIG_IBMEBUS=y +CONFIG_SPU_FS=m +CONFIG_RTAS_FLASH=y +CONFIG_PPC_SPLPAR=y +CONFIG_SCANLOG=y +CONFIG_LPARCFG=y +CONFIG_SERIAL_ICOM=m +CONFIG_HVCS=m +CONFIG_HVC_CONSOLE=y +CONFIG_HOTPLUG_PCI=y +CONFIG_THERM_PM72=y +CONFIG_IBMVETH=m +CONFIG_SCSI_IBMVSCSI=m +# CONFIG_HOTPLUG_PCI_CPCI is not set +CONFIG_HOTPLUG_PCI_SHPC=m +CONFIG_HOTPLUG_PCI_RPA=m +CONFIG_HOTPLUG_PCI_RPA_DLPAR=y +CONFIG_ADB_PMU_LED=y +CONFIG_ADB_PMU_LED_IDE=y +CONFIG_PMAC_SMU=y +CONFIG_CPU_FREQ_PMAC64=y +CONFIG_SCSI_IPR=m +CONFIG_SCSI_IPR_TRACE=y +CONFIG_SCSI_IPR_DUMP=y +CONFIG_SPIDER_NET=m +CONFIG_HVC_RTAS=y +CONFIG_HVC_ISERIES=y +CONFIG_MAMBO=y +CONFIG_MAMBO_DISK=m +CONFIG_MAMBO_NET=m +CONFIG_CBE_RAS=y + +# iSeries device drivers +# +CONFIG_ISERIES_VETH=m +# CONFIG_VIOCONS is not set +CONFIG_VIODASD=m +CONFIG_VIOCD=m +CONFIG_VIOTAPE=m + +CONFIG_PASEMI_MAC=m +CONFIG_SERIAL_OF_PLATFORM=m + +CONFIG_PPC_PASEMI_IOMMU=y +CONFIG_SERIAL_TXX9=y +CONFIG_SERIAL_TXX9_NR_UARTS=6 +CONFIG_SERIAL_TXX9_CONSOLE=y + +CONFIG_HVC_BEAT=y + +CONFIG_FB_PS3=y +CONFIG_FB_PS3_DEFAULT_SIZE_M=18 + +CONFIG_PPC_PMI=m +CONFIG_PS3_SYS_MANAGER=y +# CONFIG_BLK_DEV_CELLEB is not set + +CONFIG_PATA_SCC=m + +CONFIG_APM_EMULATION=m + +CONFIG_PPC64=y +CONFIG_VIRT_CPU_ACCOUNTING=y +CONFIG_NR_CPUS=128 +# CONFIG_FB_PLATINUM is not set +# CONFIG_FB_VALKYRIE is not set +# CONFIG_FB_CT65550 is not set +# CONFIG_FB_VGA16 is not set +# CONFIG_FB_ATY128 is not set +# CONFIG_FB_ATY is not set + +# CONFIG_POWER4_ONLY is not set + +CONFIG_RTAS_PROC=y +CONFIG_IOMMU_VMERGE=y +CONFIG_NUMA=y +# CONFIG_PPC_64K_PAGES is not set +CONFIG_SCHED_SMT=y + +# CONFIG_MV643XX_ETH is not set +CONFIG_IRQSTACKS=y +CONFIG_DEBUG_STACKOVERFLOW=y +# CONFIG_INPUT_PCSPKR is not set + +CONFIG_EHEA=m +CONFIG_INFINIBAND_EHCA=m + +CONFIG_HCALL_STATS=y + +CONFIG_XMON_DISASSEMBLY=y + +CONFIG_SCSI_IBMVSCSIS=m + +CONFIG_SECCOMP=y + +CONFIG_TUNE_CELL=y +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y +# CONFIG_BLK_DEV_PLATFORM is not set +CONFIG_IBM_NEW_EMAC=m +CONFIG_IBM_NEW_EMAC_RXB=128 +CONFIG_IBM_NEW_EMAC_TXB=64 +CONFIG_IBM_NEW_EMAC_POLL_WEIGHT=32 +CONFIG_IBM_NEW_EMAC_RX_COPY_THRESHOLD=256 +CONFIG_IBM_NEW_EMAC_RX_SKB_HEADROOM=0 +# CONFIG_IBM_NEW_EMAC_DEBUG is not set + +# CONFIG_VIRQ_DEBUG is not set +CONFIG_ELECTRA_CF=m + +CONFIG_SPU_TRACE=m +CONFIG_MTD_NAND_PASEMI=m +CONFIG_EDAC_CELL=m +CONFIG_EDAC_CPC925=m +CONFIG_FRAME_WARN=2048 + +CONFIG_PHYP_DUMP=y +CONFIG_FORCE_MAX_ZONEORDER=13 +CONFIG_BLK_DEV_HD_ONLY=y +CONFIG_VIRTUALIZATION=y + +CONFIG_VSX=y + +CONFIG_SCSI_IBMVFC=m +# CONFIG_SCSI_IBMVFC_TRACE is not set +CONFIG_IBM_BSR=m + +CONFIG_SERIO_XILINX_XPS_PS2=m + +CONFIG_PPC_IBM_CELL_RESETBUTTON=y +CONFIG_PPC_IBM_CELL_POWERBUTTON=m +CONFIG_CBE_CPUFREQ_SPU_GOVERNOR=m + +CONFIG_RTC_DRV_PS3=y + +CONFIG_CRASH_DUMP=y +CONFIG_RELOCATABLE=y + +CONFIG_RCU_FANOUT=64 + +CONFIG_PERF_COUNTERS=y +CONFIG_PERF_EVENTS=y +CONFIG_EVENT_PROFILE=y + +CONFIG_KVM_BOOK3S_64=m +# CONFIG_KVM_EXIT_TIMING is not set + +#-- bz#607175 +#-- active memory sharing +CONFIG_PPC_SMLPAR=y +CONFIG_CMM=y +#-- DLPAR memory remove +# CONFIG_SPARSEMEM_VMEMMAP is not set diff --git a/config-rhel-generic b/config-rhel-generic new file mode 100644 index 000000000..e70447bc6 --- /dev/null +++ b/config-rhel-generic @@ -0,0 +1,213 @@ +# CONFIG_ISA is not set +# CONFIG_ISAPNP is not set +# CONFIG_I2C_PCA_ISA is not set + +# CONFIG_SCSI_BUSLOGIC is not set +# CONFIG_SCSI_INIA100 is not set +# CONFIG_SCSI_ADVANSYS is not set +# CONFIG_SCSI_AHA1542 is not set +# CONFIG_SCSI_FUTURE_DOMAIN is not set +# CONFIG_SCSI_IN2000 is not set +# CONFIG_SCSI_QLOGIC_FAS is not set +# CONFIG_SCSI_DC390T is not set + +# CONFIG_ATALK is not set +# CONFIG_DEV_APPLETALK is not set +# CONFIG_LTPC is not set +# CONFIG_COPS is not set +# CONFIG_IPX is not set +# CONFIG_IPDDP is not set +# CONFIG_DECNET is not set +# CONFIG_PLIP is not set + +# CONFIG_PCMCIA_AHA152X is not set +# CONFIG_PCMCIA_NINJA_SCSI is not set +# CONFIG_PCMCIA_QLOGIC is not set +# CONFIG_PCMCIA_SYM53C500 is not set + +# CONFIG_EL2 is not set +# CONFIG_ELPLUS is not set +# CONFIG_WD80x3 is not set +# CONFIG_I82092 is not set +# CONFIG_YELLOWFIN is not set +# CONFIG_SUNDANCE is not set +# CONFIG_ULTRA is not set +# CONFIG_SKFP is not set +# CONFIG_DE600 is not set +# CONFIG_DE620 is not set +# CONFIG_CS89x0 is not set +# CONFIG_AC3200 is not set +# CONFIG_NI52 is not set +# CONFIG_NI65 is not set +# CONFIG_LANCE is not set +# CONFIG_EL16 is not set +# CONFIG_EL3 is not set +# CONFIG_3C515 is not set +# CONFIG_HAMACHI is not set +# CONFIG_HP100 is not set +# CONFIG_EQUALIZER is not set +# CONFIG_NET_SB1000 is not set +# CONFIG_DEPCA is not set +# CONFIG_ATP is not set + +# CONFIG_TR is not set + +# CONFIG_GAMEPORT is not set + +# CONFIG_SND_AD1816A is not set +# CONFIG_SND_AD1848 is not set +# CONFIG_SND_CS4231 is not set +# CONFIG_SND_CS4232 is not set +# CONFIG_SND_CS4236 is not set +# CONFIG_SND_ES968 is not set +# CONFIG_SND_ES1688 is not set +# CONFIG_SND_ES18XX is not set +# CONFIG_SND_GUSCLASSIC is not set +# CONFIG_SND_GUSEXTREME is not set +# CONFIG_SND_GUSMAX is not set +# CONFIG_SND_INTERWAVE is not set +# CONFIG_SND_INTERWAVE_STB is not set +# CONFIG_SND_OPTI92X_AD1848 is not set +# CONFIG_SND_OPTI92X_CS4231 is not set +# CONFIG_SND_OPTI93X is not set +# CONFIG_SND_MIRO is not set +# CONFIG_SND_SB8 is not set +# CONFIG_SND_SB16 is not set +# CONFIG_SND_SBAWE is not set +# CONFIG_SND_SB16_CSP is not set +# CONFIG_SND_WAVEFRONT is not set +# CONFIG_SND_ALS100 is not set +# CONFIG_SND_AZT2320 is not set +# CONFIG_SND_CMI8330 is not set +# CONFIG_SND_DT019X is not set +# CONFIG_SND_OPL3SA2 is not set +# CONFIG_SND_SGALAXY is not set +# CONFIG_SND_SSCAPE is not set + +# CONFIG_WAN_ROUTER is not set + +# CONFIG_BINFMT_AOUT is not set + +# CONFIG_DRM_TDFX is not set +# CONFIG_DRM_SIS is not set + +# CONFIG_BLK_DEV_UMEM is not set +# CONFIG_BLK_DEV_NBD is not set +# CONFIG_BLK_DEV_DAC960 is not set + +# CONFIG_PARIDE is not set + +# CONFIG_I2O is not set + +# CONFIG_MWAVE is not set + +# CONFIG_ROCKETPORT is not set +# CONFIG_R3964 is not set +# CONFIG_TIPAR is not set + +# CONFIG_JOYSTICK_ANALOG is not set +# CONFIG_JOYSTICK_A3D is not set +# CONFIG_JOYSTICK_ADI is not set +# CONFIG_JOYSTICK_COBRA is not set +# CONFIG_JOYSTICK_GF2K is not set +# CONFIG_JOYSTICK_GRIP is not set +# CONFIG_JOYSTICK_GRIP_MP is not set +# CONFIG_JOYSTICK_GUILLEMOT is not set +# CONFIG_JOYSTICK_INTERACT is not set +# CONFIG_JOYSTICK_SIDEWINDER is not set +# CONFIG_JOYSTICK_TMDC is not set +# CONFIG_JOYSTICK_IFORCE is not set +# CONFIG_JOYSTICK_IFORCE_USB=y +# CONFIG_JOYSTICK_IFORCE_232=y +# CONFIG_JOYSTICK_WARRIOR is not set +# CONFIG_JOYSTICK_MAGELLAN is not set +# CONFIG_JOYSTICK_SPACEORB is not set +# CONFIG_JOYSTICK_SPACEBALL is not set +# CONFIG_JOYSTICK_STINGER is not set +# CONFIG_JOYSTICK_DB9 is not set +# CONFIG_JOYSTICK_GAMECON is not set +# CONFIG_JOYSTICK_TURBOGRAFX is not set + +# CONFIG_RADIO_CADET is not set +# CONFIG_RADIO_RTRACK is not set +# CONFIG_RADIO_RTRACK2 is not set +# CONFIG_RADIO_AZTECH is not set +# CONFIG_RADIO_GEMTEK is not set +# CONFIG_RADIO_GEMTEK_PCI is not set +# CONFIG_RADIO_MAXIRADIO is not set +# CONFIG_RADIO_MAESTRO is not set +# CONFIG_RADIO_MIROPCM20 is not set +# CONFIG_RADIO_MIROPCM20_RDS is not set +# CONFIG_RADIO_SF16FMI is not set +# CONFIG_RADIO_SF16FMR2 is not set +# CONFIG_RADIO_TERRATEC is not set +# CONFIG_RADIO_TRUST is not set +# CONFIG_RADIO_TYPHOON is not set +# CONFIG_RADIO_ZOLTRIX is not set + +# CONFIG_TUNER_3036 is not set + +# CONFIG_VIDEO_PMS is not set +# CONFIG_VIDEO_BWQCAM is not set +# CONFIG_VIDEO_CQCAM is not set +# CONFIG_VIDEO_W9966 is not set +# CONFIG_VIDEO_CPIA is not set +# CONFIG_VIDEO_CPIA_PP is not set +# CONFIG_VIDEO_CPIA_USB is not set +# CONFIG_VIDEO_SAA5249 is not set +# CONFIG_VIDEO_STRADIS is not set +# CONFIG_VIDEO_ZORAN is not set +# CONFIG_VIDEO_ZORAN_BUZ is not set +# CONFIG_VIDEO_ZORAN_DC10 is not set +# CONFIG_VIDEO_ZORAN_DC30 is not set +# CONFIG_VIDEO_ZORAN_LML33 is not set +# CONFIG_VIDEO_ZORAN_LML33R10 is not set +# CONFIG_VIDEO_MEYE is not set +# CONFIG_VIDEO_SAA7134 is not set +# CONFIG_VIDEO_MXB is not set +# CONFIG_VIDEO_DPC is not set +# CONFIG_VIDEO_HEXIUM_ORION is not set +# CONFIG_VIDEO_HEXIUM_GEMINI is not set +# CONFIG_VIDEO_CX88 is not set +# CONFIG_VIDEO_SAA5246A is not set + +# CONFIG_INFTL is not set +# CONFIG_MTD_DOC2000 is not set +# CONFIG_MTD_DOC2001PLUS is not set +# CONFIG_MTD_PMC551 is not set +# CONFIG_MTD_COMPLEX_MAPPINGS is not set +# CONFIG_MTD_PCI is not set + +# CONFIG_FB_MATROX is not set +# CONFIG_FB_3DFX is not set +# CONFIG_FB_HGA is not set +# CONFIG_FB_ATY is not set +# CONFIG_FB_TRIDENT is not set +# CONFIG_FB_VOODOO1 is not set +# CONFIG_FB_ATY128 is not set +# CONFIG_FB_RADEON is not set +# CONFIG_FB_NEOMAGIC is not set +# CONFIG_FB_ASILIANT is not set +# CONFIG_FB_HGA_ACCEL is not set +# CONFIG_FB_3DFX_ACCEL is not set +# CONFIG_FB_TRIDENT_ACCEL is not set + +# CONFIG_JFS_FS is not set +# CONFIG_NCP_FS is not set +# CONFIG_CODA_FS is not set +# CONFIG_REISERFS_FS is not set +# CONFIG_XFS_FS is not set +# CONFIG_AFFS_FS is not set +# CONFIG_BEFS_FS is not set +# CONFIG_EFS_FS is not set +# CONFIG_BFS_FS is not set +# CONFIG_QNX4FS_FS is not set +# CONFIG_SYSV_FS is not set +# CONFIG_UFS_FS is not set +# CONFIG_ROMFS_FS is not set +# CONFIG_MINIX_FS is not set +# CONFIG_9P_FS is not set +# CONFIG_OCFS2_FS is not set +# CONFIG_HFS_FS is not set +# CONFIG_HFSPLUS_FS is not set + diff --git a/config-s390x b/config-s390x new file mode 100644 index 000000000..05910a00a --- /dev/null +++ b/config-s390x @@ -0,0 +1,237 @@ +CONFIG_64BIT=y +# CONFIG_MARCH_G5 is not set +# CONFIG_MARCH_Z900 is not set +CONFIG_MARCH_Z9_109=y +# CONFIG_MARCH_Z990 is not set + +CONFIG_NR_CPUS=64 +CONFIG_COMPAT=y + +# See bug 496596 +CONFIG_HZ_100=y +# See bug 496605 +# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set + +CONFIG_MMU=y +CONFIG_RWSEM_XCHGADD_ALGORITHM=y + +CONFIG_LOG_BUF_SHIFT=16 +CONFIG_NO_IDLE_HZ=y +CONFIG_NO_IDLE_HZ_INIT=y + +CONFIG_SMP=y + +# +# I/O subsystem configuration +# +CONFIG_MACHCHK_WARNING=y +CONFIG_QDIO=m +# CONFIG_QDIO_DEBUG is not set + +# +# Misc +# +CONFIG_IPL=y +# CONFIG_IPL_TAPE is not set +CONFIG_IPL_VM=y +# CONFIG_PROCESS_DEBUG is not set +CONFIG_PFAULT=y +CONFIG_SHARED_KERNEL=y +CONFIG_CMM=m +CONFIG_CMM_PROC=y +CONFIG_VIRT_TIMER=y +# CONFIG_NETIUCV is not set +CONFIG_SMSGIUCV=m + +# +# SCSI low-level drivers +# +CONFIG_ZFCP=m +CONFIG_ZFCPDUMP=y +CONFIG_CCW=y + +# +# S/390 block device drivers +# +CONFIG_DCSSBLK=m +CONFIG_BLK_DEV_XPRAM=m +CONFIG_DASD=m +CONFIG_DASD_PROFILE=y +CONFIG_DASD_ECKD=m +CONFIG_DASD_FBA=m +CONFIG_DASD_DIAG=m +CONFIG_DASD_EER=y + +# +# S/390 character device drivers +# +CONFIG_TN3270=y +CONFIG_TN3270_CONSOLE=y +CONFIG_TN3215=y +CONFIG_TN3215_CONSOLE=y +CONFIG_CCW_CONSOLE=y +CONFIG_SCLP_TTY=y +CONFIG_SCLP_CONSOLE=y +CONFIG_SCLP_VT220_TTY=y +CONFIG_SCLP_VT220_CONSOLE=y +CONFIG_SCLP_CPI=m +CONFIG_SCLP_ASYNC=m +CONFIG_S390_TAPE=m +CONFIG_S390_TAPE_3590=m + +CONFIG_APPLDATA_BASE=y +CONFIG_APPLDATA_MEM=m +CONFIG_APPLDATA_OS=m +CONFIG_APPLDATA_NET_SUM=m +CONFIG_TN3270_TTY=y +CONFIG_TN3270_FS=m + + +# +# S/390 tape interface support +# +CONFIG_S390_TAPE_BLOCK=y + +# +# S/390 tape hardware support +# +CONFIG_S390_TAPE_34XX=m + +# CONFIG_PPP is not set +# CONFIG_SLIP is not set + +# +# Token Ring devices +# +CONFIG_TR=y +# CONFIG_SHAPER is not set +CONFIG_NETCONSOLE=m + +# +# Wan interfaces +# +# CONFIG_WAN is not set + +# +# S/390 network device drivers +# +CONFIG_LCS=m +CONFIG_CTC=m +CONFIG_IUCV=m +CONFIG_QETH=m +CONFIG_QETH_IPV6=y +CONFIG_QETH_VLAN=y +CONFIG_CCWGROUP=m + +# CONFIG_IRDA is not set +# CONFIG_BT is not set +# CONFIG_WIRELESS_EXT is not set +# CONFIG_WLAN_80211 is not set +# CONFIG_MAC80211 is not set +# CONFIG_IEEE80211 is not set +# CONFIG_B44 is not set + +# +# Partition Types +# +CONFIG_PARTITION_ADVANCED=y +# CONFIG_OSF_PARTITION is not set +CONFIG_IBM_PARTITION=y +# CONFIG_MAC_PARTITION is not set +CONFIG_MSDOS_PARTITION=y +# CONFIG_SGI_PARTITION is not set +# CONFIG_SUN_PARTITION is not set + + +# +# S390 crypto hw +# +CONFIG_CRYPTO_SHA1_S390=m +CONFIG_CRYPTO_SHA256_S390=m +CONFIG_CRYPTO_DES_S390=m +CONFIG_CRYPTO_AES_S390=m + +# +# Kernel hacking +# + +# +# S390 specific stack options; needs gcc 3.5 so off for now +# +CONFIG_PACK_STACK=y +CONFIG_CHECK_STACK=y +# CONFIG_WARN_STACK is not set +# CONFIG_SMALL_STACK is not set + +CONFIG_ZVM_WATCHDOG=m +CONFIG_VMLOGRDR=m +CONFIG_MONREADER=m + +CONFIG_VIRT_CPU_ACCOUNTING=y + +# CONFIG_CLAW is not set + +CONFIG_VMCP=m + +# CONFIG_ATMEL is not set + +# CONFIG_CDROM_PKTCDVD is not set +# CONFIG_ATA_OVER_ETH is not set +# CONFIG_MII is not set + +# CONFIG_BOOT_DELAY is not set + +CONFIG_STACK_GUARD=256 +CONFIG_CMM_IUCV=y + +# CONFIG_DETECT_SOFTLOCKUP is not set + +CONFIG_S390_HYPFS_FS=y + +CONFIG_MONWRITER=m +CONFIG_ZCRYPT=m +CONFIG_ZCRYPT_MONOLITHIC=y + +CONFIG_S390_SWITCH_AMODE=y +CONFIG_S390_EXEC_PROTECT=y +CONFIG_AFIUCV=m +CONFIG_S390_PRNG=m + +CONFIG_S390_VMUR=m + +# CONFIG_THERMAL is not set + +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y +CONFIG_PAGE_STATES=y +CONFIG_CTCM=m +CONFIG_QETH_L2=m +CONFIG_QETH_L3=m +CONFIG_CRYPTO_SHA512_S390=m +CONFIG_VIRTUALIZATION=y +CONFIG_KVM=m +CONFIG_S390_GUEST=y + + +CONFIG_MEMORY_HOTPLUG=y +CONFIG_MEMORY_HOTREMOVE=y +CONFIG_CHSC_SCH=m + +# drivers/isdn/hardware/mISDN/hfcmulti.c:5255:2: error: #error "not running on big endian machines now" +# CONFIG_MISDN_HFCMULTI is not set + +CONFIG_HVC_IUCV=y + +CONFIG_RCU_FANOUT=64 + +CONFIG_SECCOMP=y + +CONFIG_PM=y +CONFIG_HIBERNATION=y +CONFIG_PM_STD_PARTITION="/dev/jokes" + +CONFIG_PERF_COUNTERS=y +CONFIG_PERF_EVENTS=y +CONFIG_EVENT_PROFILE=y + +# CONFIG_PREEMPT_TRACER is not set diff --git a/config-sparc64-generic b/config-sparc64-generic new file mode 100644 index 000000000..1cf6d2aaa --- /dev/null +++ b/config-sparc64-generic @@ -0,0 +1,215 @@ +CONFIG_SMP=y +CONFIG_SPARC=y +CONFIG_SPARC64=y +CONFIG_SECCOMP=y +CONFIG_HZ_100=y +# CONFIG_HZ_1000 is not set +CONFIG_HZ=100 + +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y +CONFIG_CPU_FREQ=y +CONFIG_CPU_FREQ_TABLE=m +CONFIG_CPU_FREQ_DEBUG=y +# CONFIG_CPU_FREQ_STAT is not set +# CONFIG_CPU_FREQ_STAT_DETAILS is not set +CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE=y +# CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE is not set +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y +CONFIG_CPU_FREQ_GOV_POWERSAVE=m +CONFIG_CPU_FREQ_GOV_USERSPACE=m +CONFIG_CPU_FREQ_GOV_ONDEMAND=m +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m +CONFIG_US3_FREQ=m +CONFIG_US2E_FREQ=m + +CONFIG_SUN_LDOMS=y +CONFIG_SCHED_SMT=y +CONFIG_SCHED_MC=y +CONFIG_64BIT=y +# CONFIG_BBC_I2C is not set +CONFIG_HUGETLB_PAGE_SIZE_4MB=y +# CONFIG_HUGETLB_PAGE_SIZE_512K is not set +# CONFIG_HUGETLB_PAGE_SIZE_64K is not set +CONFIG_NR_CPUS=256 +CONFIG_US3_FREQ=m +CONFIG_US2E_FREQ=m +CONFIG_SUN_OPENPROMFS=m +CONFIG_SPARC32_COMPAT=y +CONFIG_COMPAT=y +CONFIG_UID16=y +CONFIG_BINFMT_ELF32=y +CONFIG_BINFMT_AOUT32=y +CONFIG_SUNOS_EMUL=y +CONFIG_SOLARIS_EMUL=m +CONFIG_ENVCTRL=m +CONFIG_DISPLAY7SEG=m +CONFIG_WATCHDOG_CP1XXX=m +CONFIG_WATCHDOG_RIO=m +# CONFIG_CMDLINE_BOOL is not set +# CONFIG_PREVENT_FIRMWARE_BUILD is not set +# CONFIG_PARPORT is not set +# CONFIG_BLK_DEV_FD is not set +# CONFIG_LIRC_PVR150 is not set +# CONFIG_LIRC_PARALLEL is not set +# CONFIG_I2C_NFORCE2 is not set +# CONFIG_I2C_PARPORT_LIGHT is not set +# CONFIG_I2C_PROSAVAGE is not set +# CONFIG_I2C_SAVAGE4 is not set +# CONFIG_I2C_SIMTEC is not set +# CONFIG_I2C_VOODOO3 is not set +CONFIG_I2C_ALI1535=m +# CONFIG_VGASTATE is not set +# CONFIG_FB_DDC is not set +# CONFIG_FB_BW2 is not set +CONFIG_FB_CG3=y +CONFIG_FB_CG6=y +# CONFIG_FB_RIVA is not set +# CONFIG_FB_MATROX is not set +# CONFIG_FB_RADEON is not set +CONFIG_FB_ATY=y +# CONFIG_FB_S3 is not set +# CONFIG_FB_SAVAGE is not set +# CONFIG_FB_SIS is not set +# CONFIG_FB_NEOMAGIC is not set +# CONFIG_FB_3DFX is not set +# CONFIG_FB_VOODOO1 is not set +# CONFIG_FB_TRIDENT is not set +CONFIG_FB_SBUS=y +CONFIG_FB_FFB=y +# CONFIG_FB_TCX is not set +# CONFIG_FB_CG14 is not set +CONFIG_FB_PM2=y +CONFIG_FB_P9100=y +# CONFIG_FB_LEO is not set +CONFIG_FB_XVR500=y +CONFIG_FB_XVR1000=y +CONFIG_FB_XVR2500=y +# CONFIG_VGASTATE is not set +# CONFIG_FB_DDC is not set +# CONFIG_FB_CIRRUS is not set +# CONFIG_FB_ATY128 is not set +# CONFIG_FB_KYRO is not set +# CONFIG_AGP is not set +# CONFIG_DRM_NOUVEAU is not set +# CONFIG_MDA_CONSOLE is not set +# CONFIG_PROM_CONSOLE is not set +CONFIG_FONTS=y +# CONFIG_FONT_8x8 is not set +# CONFIG_FONT_8x16 is not set +# CONFIG_FONT_7x14 is not set +# CONFIG_FONT_10x18 is not set +# CONFIG_FONT_6x11 is not set +# CONFIG_FONT_SUN12x22 is not set +# CONFIG_FONT_PEARL_8x8 is not set +# CONFIG_FONT_ACORN_8x8 is not set +CONFIG_FONT_SUN8x16=y +CONFIG_FONT_SUN12x22=y +# CONFIG_LOGO_LINUX_CLUT224 is not set +# CONFIG_SERIAL_8250 is not set +CONFIG_SERIAL_SUNZILOG=y +CONFIG_SERIAL_SUNZILOG_CONSOLE=y +CONFIG_SERIAL_SUNSU=y +CONFIG_SERIAL_SUNSU_CONSOLE=y +CONFIG_SERIAL_SUNSAB=y +CONFIG_SERIAL_SUNSAB_CONSOLE=y +CONFIG_SERIAL_SUNHV=y +CONFIG_SUN_OPENPROMIO=y +CONFIG_SUN_MOSTEK_RTC=y +CONFIG_OBP_FLASH=m +# CONFIG_SUN_VIDEOPIX is not set +# CONFIG_SERIO_SERPORT is not set +CONFIG_BLK_DEV_FD=y +CONFIG_SUNVDC=m +CONFIG_SUNVNET=m +# CONFIG_BLK_DEV_AEC62XX is not set +# CONFIG_BLK_DEV_HPT34X is not set +# CONFIG_BLK_DEV_HPT366 is not set +# CONFIG_BLK_DEV_PDC202XX_OLD is not set +# CONFIG_BLK_DEV_PDC202XX_NEW is not set +# CONFIG_BLK_DEV_SIIMAGE is not set +# CONFIG_BLK_DEV_SLC90E66 is not set +# CONFIG_BLK_DEV_VIA82CXXX is not set +# CONFIG_SCSI_ADVANSYS is not set +# CONFIG_SCSI_BUSLOGIC is not set +# CONFIG_SCSI_EATA is not set +# CONFIG_SCSI_GDTH is not set +# CONFIG_SCSI_AIC7XXX is not set +# CONFIG_SCSI_AIC79XX is not set +# CONFIG_SCSI_FUTURE_DOMAIN is not set +CONFIG_SCSI_QLOGICPTI=m +CONFIG_SCSI_SUNESP=m +CONFIG_SUNLANCE=m +CONFIG_SUNBMAC=m +CONFIG_SUNQE=m +# CONFIG_DM9102 is not set +# CONFIG_HAMACHI is not set +# CONFIG_R8169 is not set +CONFIG_ATM_FORE200E_SBA=y +CONFIG_ATM_FORE200E_SBA_DEFAULT_FW=y +# CONFIG_ATM_FORE200E_SBA_FW is not set +CONFIG_ATM_FORE200E_USE_TASKLET=y +CONFIG_ATM_FORE200E_DEBUG=0 +CONFIG_ATM_FORE200E_TX_RETRY=16 +# CONFIG_DRM_TDFX is not set +CONFIG_KEYBOARD_ATKBD=y +CONFIG_KEYBOARD_SUNKBD=y +# CONFIG_INPUT_PCSPKR is not set +CONFIG_INPUT_SPARCSPKR=m +# CONFIG_SOUND_PRIME is not set +# CONFIG_SND_SUN_AMD7930 is not set +CONFIG_SND_SUN_CS4231=m +# CONFIG_SND_SUN_DBRI is not set +CONFIG_PARPORT_SUNBPP=m +CONFIG_LOGO_SUN_CLUT224=y +CONFIG_SUN_BPP=m +CONFIG_MTD_SUN_UFLASH=m +CONFIG_MYRI_SBUS=m +# CONFIG_SGI_IOC4 is not set +# CONFIG_VIDEO_ZORAN is not set +# CONFIG_VIDEO_STRADIS is not set +# CONFIG_IEEE1394_SBP2 is not set +# CONFIG_USB_NET2280 is not set +# CONFIG_DEBUG_BUGVERBOSE is not set +# CONFIG_DEBUG_DCFLUSH is not set +# CONFIG_DEBUG_BOOTMEM is not set +# CONFIG_DEBUG_LOCK_ALLOC is not set +# CONFIG_PROVE_LOCKING is not set +# CONFIG_LOCK_STAT is not set +# CONFIG_LOCKDEP is not set +# CONFIG_STACK_DEBUG is not set + +CONFIG_SPARSEMEM_VMEMMAP=y + +# CONFIG_THERMAL is not set + +CONFIG_FRAME_WARN=2048 + +CONFIG_NUMA=y + +CONFIG_SND_SPARC=y + +CONFIG_HW_RANDOM_N2RNG=m + +# drivers/isdn/hardware/mISDN/hfcmulti.c:5255:2: error: #error "not running on big endian machines now" +# CONFIG_MISDN_HFCMULTI is not set + +CONFIG_US3_MC=y +CONFIG_SENSORS_ULTRA45=m +CONFIG_LEDS_SUNFIRE=m +CONFIG_TADPOLE_TS102_UCTRL=m + +CONFIG_RCU_FANOUT=64 + +CONFIG_LIRC_ENE0100=m +# CONFIG_BATTERY_DS2782 is not set +CONFIG_USB_GSPCA_SN9C20X=m +CONFIG_USB_GSPCA_SN9C20X_EVDEV=y +CONFIG_LSM_MMAP_MIN_ADDR=65536 + +CONFIG_PERF_COUNTERS=y +CONFIG_PERF_EVENTS=y +CONFIG_EVENT_PROFILE=y + +CONFIG_EARLYFB=y +CONFIG_SERIAL_GRLIB_GAISLER_APBUART=m diff --git a/config-x86-generic b/config-x86-generic new file mode 100644 index 000000000..6a1af3377 --- /dev/null +++ b/config-x86-generic @@ -0,0 +1,513 @@ +CONFIG_UID16=y +# CONFIG_64BIT is not set +# CONFIG_KERNEL_LZMA is not set + +# +# Processor type and features +# +# +# Enable summit and co via the generic arch +# +# CONFIG_X86_PC is not set +CONFIG_X86_GENERICARCH=y +CONFIG_X86_EXTENDED_PLATFORM=y +CONFIG_X86_32_NON_STANDARD=y + +# CONFIG_X86_ELAN is not set +# CONFIG_X86_VOYAGER is not set +# CONFIG_X86_NUMAQ is not set +# CONFIG_X86_SUMMIT is not set +CONFIG_X86_BIGSMP=y +# CONFIG_X86_VISWS is not set +# CONFIG_X86_RDC321X is not set +# CONFIG_X86_ES7000 is not set +# CONFIG_M386 is not set +# CONFIG_M486 is not set +# CONFIG_M586 is not set +# CONFIG_M586TSC is not set +# CONFIG_M586MMX is not set +CONFIG_M686=y +# CONFIG_MPENTIUMII is not set +# CONFIG_MPENTIUMIII is not set +# CONFIG_MPENTIUMM is not set +# CONFIG_MPENTIUM4 is not set +# CONFIG_MK6 is not set +# CONFIG_MK7 is not set +# CONFIG_MK8 is not set +# CONFIG_MCRUSOE is not set +# CONFIG_MWINCHIPC6 is not set +# CONFIG_MWINCHIP2 is not set +# CONFIG_MWINCHIP3D is not set +# CONFIG_MCYRIXIII is not set +# CONFIG_MVIAC3_2 is not set +CONFIG_SMP=y +CONFIG_NR_CPUS=32 +CONFIG_X86_GENERIC=y +CONFIG_X86_CMPXCHG=y +CONFIG_X86_L1_CACHE_SHIFT=7 +CONFIG_RWSEM_XCHGADD_ALGORITHM=y +CONFIG_X86_PPRO_FENCE=y +CONFIG_X86_WP_WORKS_OK=y +CONFIG_X86_INVLPG=y +CONFIG_X86_BSWAP=y +CONFIG_X86_POPAD_OK=y +CONFIG_X86_GOOD_APIC=y +CONFIG_X86_INTEL_USERCOPY=y +CONFIG_X86_USE_PPRO_CHECKSUM=y +CONFIG_HPET=y +CONFIG_HPET_TIMER=y +# CONFIG_HPET_RTC_IRQ is not set +# CONFIG_HPET_MMAP is not set +CONFIG_X86_LOCAL_APIC=y +CONFIG_X86_IO_APIC=y +CONFIG_X86_TSC=y +CONFIG_X86_MCE=y +# CONFIG_X86_MCE_NONFATAL is not set +CONFIG_X86_MCE_P4THERMAL=y +CONFIG_TOSHIBA=m +CONFIG_I8K=m +CONFIG_SONYPI=m +CONFIG_SONYPI_COMPAT=y +CONFIG_MICROCODE=m +CONFIG_X86_MSR=y +CONFIG_X86_CPUID=y +# CONFIG_X86_CPU_DEBUG is not set +CONFIG_EDD=m +# CONFIG_EDD_OFF is not set +# CONFIG_NUMA is not set + +# CONFIG_NOHIGHMEM is not set +CONFIG_HIGHMEM4G=y +# CONFIG_HIGHMEM64G is not set +CONFIG_HIGHMEM=y +CONFIG_HIGHPTE=y + +# CONFIG_MATH_EMULATION is not set +CONFIG_MTRR=y +CONFIG_X86_PAT=y +CONFIG_X86_PM_TIMER=y + +CONFIG_EFI=y +CONFIG_EFI_VARS=y +CONFIG_EFI_PCDP=y +CONFIG_FB_EFI=y +# CONFIG_FB_N411 is not set + +CONFIG_DMAR=y +CONFIG_DMAR_BROKEN_GFX_WA=y +CONFIG_DMAR_FLOPPY_WA=y +CONFIG_DMAR_DEFAULT_ON=y + +CONFIG_FB_GEODE=y +CONFIG_FB_GEODE_LX=y +CONFIG_FB_GEODE_GX=y +# CONFIG_FB_GEODE_GX1 is not set + +# CONFIG_PCI_GOBIOS is not set +# CONFIG_PCI_GODIRECT is not set +# CONFIG_PCI_GOMMCONFIG is not set +CONFIG_PCI_GOANY=y + +# +# x86 specific drivers +# +CONFIG_PCMCIA_FDOMAIN=m +CONFIG_SCSI_FUTURE_DOMAIN=m +CONFIG_SCSI_ADVANSYS=m + +CONFIG_CC_STACKPROTECTOR=y + +CONFIG_SECCOMP=y + +CONFIG_CAPI_EICON=y + +CONFIG_I2O=m +CONFIG_I2O_BLOCK=m +CONFIG_I2O_SCSI=m +CONFIG_I2O_PROC=m +CONFIG_I2O_CONFIG=y +CONFIG_I2O_EXT_ADAPTEC=y +CONFIG_I2O_EXT_ADAPTEC_DMA64=y +CONFIG_I2O_CONFIG_OLD_IOCTL=y +CONFIG_I2O_BUS=m + +# +# APM (Advanced Power Management) BIOS Support +# +CONFIG_APM=y +# CONFIG_APM_IGNORE_USER_SUSPEND is not set +# CONFIG_APM_DO_ENABLE is not set +CONFIG_APM_CPU_IDLE=y +# CONFIG_APM_DISPLAY_BLANK is not set +# CONFIG_APM_ALLOW_INTS is not set +# CONFIG_APM_REAL_MODE_POWER_OFF is not set + +# +# Kernel debugging +# +CONFIG_X86_FIND_SMP_CONFIG=y +CONFIG_X86_MPPARSE=y + +CONFIG_ACPI=y +CONFIG_ACPI_AC=y +# CONFIG_ACPI_ASUS is not set +CONFIG_ACPI_PROCFS_POWER=y +CONFIG_ACPI_SYSFS_POWER=y +CONFIG_ACPI_BATTERY=y +CONFIG_ACPI_BAY=y +CONFIG_ACPI_BLACKLIST_YEAR=1999 +CONFIG_ACPI_BUTTON=y +CONFIG_ACPI_CONTAINER=m +CONFIG_ACPI_DOCK=y +CONFIG_ACPI_EC=y +CONFIG_ACPI_FAN=y +CONFIG_ACPI_NUMA=y +CONFIG_ACPI_PROCESSOR=y +CONFIG_ACPI_POWER=y +CONFIG_ACPI_PROCFS=y +CONFIG_ACPI_SBS=m +CONFIG_ACPI_SLEEP=y +CONFIG_ACPI_SYSTEM=y +CONFIG_ACPI_THERMAL=y +CONFIG_TOPSTAR_LAPTOP=m +CONFIG_ACPI_TOSHIBA=m +CONFIG_ACPI_VIDEO=m +# Disable in F9. +CONFIG_ACPI_PROC_EVENT=y +CONFIG_PNPACPI=y +CONFIG_ACPI_POWER_METER=m +CONFIG_ACPI_PROCESSOR_AGGREGATOR=m + +# +# CPUFreq processor drivers +# +CONFIG_CPU_FREQ=y +CONFIG_CPU_FREQ_DEBUG=y +# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set +CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y +CONFIG_CPU_FREQ_GOV_POWERSAVE=m +CONFIG_CPU_FREQ_GOV_USERSPACE=m +CONFIG_CPU_FREQ_GOV_ONDEMAND=m +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m +CONFIG_CPU_FREQ_TABLE=y +CONFIG_CPU_FREQ_STAT=m +CONFIG_CPU_FREQ_STAT_DETAILS=y + +CONFIG_X86_ACPI_CPUFREQ=m +# CONFIG_X86_ACPI_CPUFREQ_PROC_INTF is not set +# CONFIG_X86_POWERNOW_K6 is not set +CONFIG_X86_POWERNOW_K7=y +CONFIG_X86_POWERNOW_K8=m +CONFIG_X86_POWERNOW_K8_ACPI=y +# CONFIG_X86_GX_SUSPMOD is not set +# CONFIG_X86_SPEEDSTEP_CENTRINO is not set +CONFIG_X86_SPEEDSTEP_ICH=y +CONFIG_X86_SPEEDSTEP_SMI=y +CONFIG_X86_SPEEDSTEP_LIB=y +# CONFIG_X86_SPEEDSTEP_RELAXED_CAP_CHECK is not set +CONFIG_X86_P4_CLOCKMOD=m +CONFIG_X86_LONGRUN=y +# CONFIG_X86_LONGHAUL is not set +# CONFIG_X86_CPUFREQ_NFORCE2 is not set +# e_powersaver is dangerous +# CONFIG_X86_E_POWERSAVER is not set + +CONFIG_X86_SMP=y +CONFIG_X86_HT=y +CONFIG_X86_BIOS_REBOOT=y +CONFIG_X86_TRAMPOLINE=y + +# +# various x86 specific drivers +# +CONFIG_NVRAM=y +CONFIG_IBM_ASM=m +CONFIG_CRYPTO_AES_586=m +CONFIG_CRYPTO_TWOFISH_586=m +CONFIG_CRYPTO_DEV_PADLOCK=m +CONFIG_CRYPTO_DEV_PADLOCK_AES=m +CONFIG_CRYPTO_DEV_PADLOCK_SHA=m + +CONFIG_GENERIC_ISA_DMA=y +CONFIG_SCHED_SMT=y +CONFIG_SUSPEND=y +CONFIG_HIBERNATION=y +CONFIG_PM_STD_PARTITION="" + +CONFIG_DEBUG_RODATA=y +CONFIG_DEBUG_STACKOVERFLOW=y +# CONFIG_4KSTACKS is not set +CONFIG_DEBUG_NMI_TIMEOUT=5 + +CONFIG_PCI_DIRECT=y +CONFIG_PCI_MMCONFIG=y +CONFIG_PCI_BIOS=y + +CONFIG_HOTPLUG_PCI=y +CONFIG_HOTPLUG_PCI_COMPAQ=m +# CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM is not set +CONFIG_HOTPLUG_PCI_IBM=m +# CONFIG_HOTPLUG_PCI_CPCI is not set +# SHPC has half-arsed PCI probing, which makes it load on too many systems +# CONFIG_HOTPLUG_PCI_SHPC is not set +CONFIG_PM=y + +CONFIG_IPW2100=m +CONFIG_IPW2100_MONITOR=y +CONFIG_IPW2200=m +CONFIG_IPW2200_MONITOR=y +CONFIG_IPW2200_RADIOTAP=y +CONFIG_IPW2200_PROMISCUOUS=y +CONFIG_IPW2200_QOS=y + +CONFIG_BLK_DEV_AMD74XX=y + +CONFIG_I2C_ALI1535=m +CONFIG_I2C_ALI15X3=m +CONFIG_I2C_ALI1563=m +CONFIG_I2C_AMD756=m +CONFIG_I2C_AMD756_S4882=m +CONFIG_I2C_AMD8111=m +CONFIG_I2C_I801=m +CONFIG_I2C_I810=m +CONFIG_I2C_ISCH=m +CONFIG_I2C_NFORCE2=m +CONFIG_I2C_NFORCE2_S4985=m +CONFIG_I2C_PIIX4=m +CONFIG_I2C_PROSAVAGE=m +CONFIG_I2C_SAVAGE4=m +CONFIG_I2C_SIS5595=m +CONFIG_I2C_SIS630=m +CONFIG_I2C_SIS96X=m + +CONFIG_I2C_VIA=m +CONFIG_I2C_VIAPRO=m +CONFIG_I2C_VOODOO3=m + +CONFIG_SCx200_ACB=m + +# CONFIG_X86_REBOOTFIXUPS is not set + +CONFIG_DELL_RBU=m +CONFIG_DCDBAS=m + +CONFIG_PC8736x_GPIO=m +# CONFIG_NSC_GPIO is not set +CONFIG_CS5535_GPIO=m + +CONFIG_EDAC=y +# CONFIG_EDAC_DEBUG is not set +CONFIG_EDAC_MM_EDAC=m +CONFIG_EDAC_AMD76X=m +CONFIG_EDAC_E7XXX=m +CONFIG_EDAC_E752X=m +CONFIG_EDAC_I82860=m +CONFIG_EDAC_I82875P=m +CONFIG_EDAC_I82975X=m +CONFIG_EDAC_I3000=m +CONFIG_EDAC_I5000=m +CONFIG_EDAC_I5100=m +CONFIG_EDAC_I5400=m +CONFIG_EDAC_R82600=m +CONFIG_EDAC_AMD8131=m +CONFIG_EDAC_AMD8111=m + +CONFIG_SCHED_MC=y + +CONFIG_SND_ISA=y +CONFIG_SND_ES18XX=m + +CONFIG_TCG_INFINEON=m + +CONFIG_HW_RANDOM_INTEL=m +CONFIG_HW_RANDOM_AMD=m +CONFIG_HW_RANDOM_GEODE=m +CONFIG_HW_RANDOM_VIA=m + +CONFIG_USB_HIDINPUT_POWERBOOK=y + +# CONFIG_COMPAT_VDSO is not set + +# CONFIG_SGI_IOC4 is not set + +CONFIG_X86_PLATFORM_DEVICES=y +CONFIG_ACERHDF=m +CONFIG_ASUS_LAPTOP=m +CONFIG_COMPAL_LAPTOP=m +CONFIG_EEEPC_LAPTOP=m +CONFIG_FUJITSU_LAPTOP=m +# CONFIG_FUJITSU_LAPTOP_DEBUG is not set +CONFIG_MSI_LAPTOP=m +CONFIG_SONY_LAPTOP=m +CONFIG_DELL_LAPTOP=m +CONFIG_ACPI_WMI=m +CONFIG_ACER_WMI=m +CONFIG_TC1100_WMI=m +CONFIG_HP_WMI=m +CONFIG_DELL_WMI=m + +# CONFIG_SMSC37B787_WDT is not set +CONFIG_W83697HF_WDT=m +CONFIG_IB700_WDT=m + +CONFIG_RELOCATABLE=y +CONFIG_PHYSICAL_ALIGN=0x400000 +CONFIG_PHYSICAL_START=0x400000 +CONFIG_CRASH_DUMP=y +# CONFIG_KEXEC_JUMP is not set +CONFIG_PROC_VMCORE=y +CONFIG_CRASH=m + +CONFIG_CRYPTO_DEV_GEODE=m + +CONFIG_VIDEO_CAFE_CCIC=m + +CONFIG_VIRTUALIZATION=y +CONFIG_KVM=m +CONFIG_KVM_INTEL=m +CONFIG_KVM_AMD=m +CONFIG_KVM_TRACE=y +CONFIG_LGUEST=m + +CONFIG_PARAVIRT_GUEST=y +CONFIG_PARAVIRT=y +# CONFIG_PARAVIRT_DEBUG is not set + +# PARAVIRT_SPINLOCKS has a 5% perf hit +# CONFIG_PARAVIRT_SPINLOCKS is not set +CONFIG_KVM_CLOCK=y +CONFIG_KVM_GUEST=y +CONFIG_LGUEST_GUEST=y +CONFIG_VMI=y + +CONFIG_XEN=y +CONFIG_XEN_MAX_DOMAIN_MEMORY=8 +CONFIG_XEN_BALLOON=y +CONFIG_XEN_SCRUB_PAGES=y +CONFIG_XEN_SAVE_RESTORE=y +CONFIG_HVC_XEN=y +CONFIG_XEN_FBDEV_FRONTEND=y +CONFIG_XEN_KBDDEV_FRONTEND=y +CONFIG_XEN_BLKDEV_FRONTEND=m +CONFIG_XEN_NETDEV_FRONTEND=m +CONFIG_XENFS=m +CONFIG_XEN_COMPAT_XENFS=y + +CONFIG_MTD_ESB2ROM=m +CONFIG_MTD_CK804XROM=m +CONFIG_MTD_NAND_CAFE=m + +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y +CONFIG_CPU_IDLE=y +# CONFIG_CPU_IDLE_GOV_LADDER is not set +CONFIG_CPU_IDLE_GOV_MENU=y + +CONFIG_THINKPAD_ACPI=m +# CONFIG_THINKPAD_ACPI_DEBUG is not set +# CONFIG_THINKPAD_ACPI_DEBUGFACILITIES is not set +CONFIG_THINKPAD_ACPI_HOTKEY_POLL=y +CONFIG_THINKPAD_ACPI_BAY=y +CONFIG_THINKPAD_ACPI_VIDEO=y +CONFIG_THINKPAD_ACPI_ALSA_SUPPORT=y +# CONFIG_THINKPAD_ACPI_UNSAFE_LEDS is not set + +CONFIG_MACINTOSH_DRIVERS=y + +CONFIG_DMIID=y +CONFIG_ISCSI_IBFT_FIND=y +CONFIG_ISCSI_IBFT=m + +CONFIG_DMADEVICES=y +CONFIG_INTEL_IOATDMA=m + +CONFIG_SENSORS_I5K_AMB=m + +# CONFIG_CPA_DEBUG is not set +# CONFIG_PROVIDE_OHCI1394_DMA_INIT is not set + +CONFIG_HP_WATCHDOG=m + +CONFIG_OLPC=y +CONFIG_BATTERY_OLPC=y +CONFIG_MOUSE_PS2_OLPC=y + +CONFIG_STRICT_DEVMEM=y + +# CONFIG_MEMTEST is not set +# CONFIG_MAXSMP is not set +CONFIG_MTRR_SANITIZER=y +CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT=1 +CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT=1 +CONFIG_SYSPROF_TRACER=y + +# CONFIG_X86_VERBOSE_BOOTUP is not set +# CONFIG_MMIOTRACE_TEST is not set + +# CONFIG_DEBUG_PER_CPU_MAPS is not set + +CONFIG_HP_ILO=m + +CONFIG_BACKLIGHT_MBP_NVIDIA=m + +CONFIG_OPROFILE_IBS=y +CONFIG_MICROCODE_INTEL=y +CONFIG_MICROCODE_AMD=y + +# CONFIG_X86_CHECK_BIOS_CORRUPTION is not set +CONFIG_X86_RESERVE_LOW_64K=y + +# CONFIG_CMDLINE_BOOL is not set + +CONFIG_PANASONIC_LAPTOP=m + +CONFIG_XEN_DEBUG_FS=y +CONFIG_X86_PTRACE_BTS=y + +CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS=y + +CONFIG_POWER_TRACER=y +CONFIG_HW_BRANCH_TRACER=y + +# CONFIG_SPARSE_IRQ is not set + +CONFIG_RCU_FANOUT=32 + +# CONFIG_IOMMU_STRESS is not set + +CONFIG_PERF_COUNTERS=y +CONFIG_PERF_EVENTS=y +CONFIG_EVENT_PROFILE=y + +# CONFIG_X86_OLD_MCE is not set +CONFIG_X86_MCE_INTEL=y +CONFIG_X86_MCE_AMD=y +# CONFIG_X86_ANCIENT_MCE is not set +# CONFIG_X86_MCE_INJECT is not set + +# CONFIG_X86_MRST is not set +CONFIG_SFI=y + +CONFIG_INPUT_WINBOND_CIR=m +CONFIG_I2C_SCMI=m +CONFIG_SBC_FITPC2_WATCHDOG=m +CONFIG_EDAC_I3200=m +CONFIG_EDAC_DECODE_MCE=m + +CONFIG_GPIO_LANGWELL=y + +# CONFIG_INTEL_TXT is not set + +CONFIG_CS5535_MFGPT=m +CONFIG_GEODE_WDT=m +CONFIG_CS5535_CLOCK_EVENT_SRC=m + +CONFIG_LEDS_INTEL_SS4200=m + +CONFIG_X86_DECODER_SELFTEST=y + +CONFIG_ACPI_CMPC=m +CONFIG_MSI_WMI=m +CONFIG_TOSHIBA_BT_RFKILL=m +# CONFIG_SAMSUNG_LAPTOP is not set diff --git a/config-x86_64-generic b/config-x86_64-generic new file mode 100644 index 000000000..e93881388 --- /dev/null +++ b/config-x86_64-generic @@ -0,0 +1,414 @@ +CONFIG_64BIT=y +CONFIG_UID16=y +# CONFIG_KERNEL_LZMA is not set + +# CONFIG_MK8 is not set +# CONFIG_MPSC is not set +CONFIG_GENERIC_CPU=y +CONFIG_X86_EXTENDED_PLATFORM=y +# CONFIG_X86_VSMP is not set +# CONFIG_X86_UV is not set +CONFIG_X86_MSR=y +CONFIG_X86_CPUID=y +# CONFIG_X86_CPU_DEBUG is not set +CONFIG_MTRR=y +CONFIG_NUMA=y +CONFIG_K8_NUMA=y +CONFIG_X86_64_ACPI_NUMA=y +# CONFIG_NUMA_EMU is not set +CONFIG_NR_CPUS=256 +CONFIG_X86_POWERNOW_K8=m +CONFIG_X86_POWERNOW_K8_ACPI=y +CONFIG_X86_P4_CLOCKMOD=m +CONFIG_IA32_EMULATION=y +# CONFIG_IA32_AOUT is not set +# CONFIG_IOMMU_DEBUG is not set +CONFIG_DEBUG_RODATA=y +CONFIG_MICROCODE=m +CONFIG_SWIOTLB=y +CONFIG_CALGARY_IOMMU=y +CONFIG_CALGARY_IOMMU_ENABLED_BY_DEFAULT=y +CONFIG_X86_PM_TIMER=y +CONFIG_EDD=m +# CONFIG_EDD_OFF is not set +CONFIG_PCI_BIOS=y +CONFIG_PCI_MMCONFIG=y +CONFIG_DMAR=y +CONFIG_DMAR_BROKEN_GFX_WA=y +CONFIG_DMAR_FLOPPY_WA=y +CONFIG_DMAR_DEFAULT_ON=y + +CONFIG_KEXEC_JUMP=y + +CONFIG_EFI=y +CONFIG_EFI_VARS=y +CONFIG_EFI_PCDP=y +CONFIG_FB_EFI=y + +CONFIG_I2O=m +CONFIG_I2O_BLOCK=m +CONFIG_I2O_SCSI=m +CONFIG_I2O_PROC=m +CONFIG_I2O_CONFIG=y +CONFIG_I2O_EXT_ADAPTEC=y +CONFIG_I2O_EXT_ADAPTEC_DMA64=y +CONFIG_I2O_CONFIG_OLD_IOCTL=y +CONFIG_I2O_BUS=m + +CONFIG_SECCOMP=y + +CONFIG_CAPI_EICON=y + +CONFIG_GENERIC_ISA_DMA=y +CONFIG_SCHED_SMT=y +CONFIG_SUSPEND=y +CONFIG_HIBERNATION=y +CONFIG_PM_STD_PARTITION="" + +CONFIG_CPU_FREQ=y +# CONFIG_CPU_FREQ_DEFAULT_GOV_PERFORMANCE is not set +CONFIG_CPU_FREQ_DEFAULT_GOV_USERSPACE=y +CONFIG_CPU_FREQ_GOV_PERFORMANCE=y +CONFIG_CPU_FREQ_GOV_POWERSAVE=m +CONFIG_CPU_FREQ_GOV_USERSPACE=m +CONFIG_CPU_FREQ_GOV_ONDEMAND=m +CONFIG_CPU_FREQ_GOV_CONSERVATIVE=m +CONFIG_CPU_FREQ_TABLE=y +CONFIG_CPU_FREQ_DEBUG=y +# CONFIG_X86_SPEEDSTEP_CENTRINO is not set +CONFIG_X86_ACPI_CPUFREQ=m +# CONFIG_X86_ACPI_CPUFREQ_PROC_INTF is not set +CONFIG_CPU_FREQ_STAT=m +CONFIG_CPU_FREQ_STAT_DETAILS=y + +CONFIG_ACPI=y +CONFIG_ACPI_AC=y +# CONFIG_ACPI_ASUS is not set +CONFIG_ACPI_PROCFS_POWER=y +CONFIG_ACPI_SYSFS_POWER=y +CONFIG_ACPI_BATTERY=y +CONFIG_ACPI_BAY=m +CONFIG_ACPI_BLACKLIST_YEAR=0 +CONFIG_ACPI_BUTTON=y +CONFIG_ACPI_CONTAINER=m +CONFIG_ACPI_DOCK=y +CONFIG_ACPI_EC=y +CONFIG_ACPI_FAN=y +CONFIG_ACPI_HOTPLUG_MEMORY=m +CONFIG_ACPI_NUMA=y +CONFIG_ACPI_PROCESSOR=y +CONFIG_ACPI_PROCFS=y +CONFIG_ACPI_SBS=m +CONFIG_ACPI_SLEEP=y +CONFIG_ACPI_THERMAL=y +CONFIG_ACPI_TOSHIBA=m +CONFIG_ACPI_POWER=y +CONFIG_ACPI_SYSTEM=y +CONFIG_ACPI_VIDEO=m +# Disable in F9. +CONFIG_ACPI_PROC_EVENT=y +CONFIG_ACPI_POWER_METER=m +CONFIG_ACPI_PROCESSOR_AGGREGATOR=m + +CONFIG_X86_PLATFORM_DEVICES=y +CONFIG_ACERHDF=m +CONFIG_ASUS_LAPTOP=m +CONFIG_COMPAL_LAPTOP=m +CONFIG_FUJITSU_LAPTOP=m +# CONFIG_FUJITSU_LAPTOP_DEBUG is not set +CONFIG_MSI_LAPTOP=m +CONFIG_SONY_LAPTOP=m +CONFIG_SONYPI_COMPAT=y +CONFIG_EEEPC_LAPTOP=m +CONFIG_DELL_LAPTOP=m +CONFIG_ACPI_WMI=m +CONFIG_ACER_WMI=m +CONFIG_HP_WMI=m +CONFIG_DELL_WMI=m + +CONFIG_THINKPAD_ACPI=m +# CONFIG_THINKPAD_ACPI_DEBUG is not set +# CONFIG_THINKPAD_ACPI_DEBUGFACILITIES is not set +CONFIG_THINKPAD_ACPI_HOTKEY_POLL=y +CONFIG_THINKPAD_ACPI_BAY=y +CONFIG_THINKPAD_ACPI_VIDEO=y +CONFIG_THINKPAD_ACPI_ALSA_SUPPORT=y +# CONFIG_THINKPAD_ACPI_UNSAFE_LEDS is not set + +CONFIG_HOTPLUG_PCI=y +CONFIG_HOTPLUG_PCI_COMPAQ=m +# CONFIG_HOTPLUG_PCI_COMPAQ_NVRAM is not set +CONFIG_HOTPLUG_PCI_IBM=m +# CONFIG_HOTPLUG_PCI_CPCI is not set +# SHPC has half-arsed PCI probing, which makes it load on too many systems +CONFIG_HOTPLUG_PCI_SHPC=m + +CONFIG_HPET=y +# CONFIG_HPET_MMAP is not set +# CONFIG_HPET_RTC_IRQ is not set +CONFIG_PM=y + +CONFIG_IPW2100=m +CONFIG_IPW2100_MONITOR=y +CONFIG_IPW2200=m +CONFIG_IPW2200_MONITOR=y +CONFIG_IPW2200_RADIOTAP=y +CONFIG_IPW2200_PROMISCUOUS=y +CONFIG_IPW2200_QOS=y + +CONFIG_PNP=y +CONFIG_PNPACPI=y + +CONFIG_BLK_DEV_AMD74XX=y +CONFIG_CRYPTO_DEV_PADLOCK=m +CONFIG_CRYPTO_DEV_PADLOCK_AES=m +CONFIG_CRYPTO_DEV_PADLOCK_SHA=m +# CONFIG_CRYPTO_AES is not set +CONFIG_CRYPTO_AES_X86_64=m +# CONFIG_CRYPTO_TWOFISH is not set +CONFIG_CRYPTO_TWOFISH_X86_64=m +# CONFIG_CRYPTO_SALSA20 is not set +CONFIG_CRYPTO_SALSA20_X86_64=m +CONFIG_CRYPTO_AES_NI_INTEL=m + +CONFIG_X86_MCE=y +CONFIG_X86_MCE_INTEL=y +CONFIG_X86_MCE_AMD=y + +# CONFIG_I2C_ALI1535 is not set +# CONFIG_I2C_ALI1563 is not set +# CONFIG_I2C_ALI15X3 is not set +CONFIG_I2C_AMD756=m +CONFIG_I2C_AMD756_S4882=m +CONFIG_I2C_AMD8111=m +CONFIG_I2C_I801=m +CONFIG_I2C_ISCH=m +# CONFIG_I2C_I810 is not set +CONFIG_I2C_NFORCE2_S4985=m +CONFIG_I2C_PIIX4=m +# CONFIG_I2C_SIS5595 is not set +# CONFIG_I2C_SIS630 is not set + +CONFIG_I2C_SIS96X=m +CONFIG_I2C_VIA=m +CONFIG_I2C_VIAPRO=m + +CONFIG_DELL_RBU=m +CONFIG_DCDBAS=m + +CONFIG_NVRAM=y + +CONFIG_EDAC=y +# CONFIG_EDAC_DEBUG is not set +CONFIG_EDAC_MM_EDAC=m +CONFIG_EDAC_AMD76X=m +CONFIG_EDAC_E7XXX=m +CONFIG_EDAC_E752X=m +CONFIG_EDAC_I5000=m +CONFIG_EDAC_I5100=m +CONFIG_EDAC_I5400=m +CONFIG_EDAC_I82875P=m +CONFIG_EDAC_I82860=m +CONFIG_EDAC_I82975X=m +CONFIG_EDAC_R82600=m +CONFIG_EDAC_AMD8131=m +CONFIG_EDAC_AMD8111=m +CONFIG_EDAC_AMD64=m +# CONFIG_EDAC_AMD64_ERROR_INJECTION is not set +CONFIG_EDAC_DECODE_MCE=m + +CONFIG_SCHED_MC=y + +CONFIG_TCG_INFINEON=m + +CONFIG_HW_RANDOM_INTEL=m +CONFIG_HW_RANDOM_AMD=m +CONFIG_HW_RANDOM_VIA=m + +# CONFIG_HW_RANDOM_GEODE is not set + +CONFIG_USB_HIDINPUT_POWERBOOK=y + +CONFIG_DEBUG_STACKOVERFLOW=y +CONFIG_DEBUG_NMI_TIMEOUT=5 + +# CONFIG_PC8736x_GPIO is not set + +# CONFIG_DISCONTIGMEM_MANUAL is not set +CONFIG_SPARSEMEM_MANUAL=y +CONFIG_SPARSEMEM=y +CONFIG_HAVE_MEMORY_PRESENT=y +CONFIG_SPARSEMEM_EXTREME=y +CONFIG_SPARSEMEM_VMEMMAP=y +CONFIG_MEMORY_HOTPLUG=y +CONFIG_MEMORY_HOTREMOVE=y + +# CONFIG_BLK_DEV_CMD640 is not set +# CONFIG_BLK_DEV_RZ1000 is not set +# CONFIG_BLK_DEV_TRIFLEX is not set +# CONFIG_BLK_DEV_CS5520 is not set +# CONFIG_BLK_DEV_CS5530 is not set +# CONFIG_BLK_DEV_CS5535 is not set + +CONFIG_CC_STACKPROTECTOR=y +# CONFIG_CC_STACKPROTECTOR_ALL is not set + +CONFIG_SGI_IOC4=m +CONFIG_SGI_XP=m +CONFIG_SGI_GRU=m +# CONFIG_SGI_GRU_DEBUG is not set + +# CONFIG_SMSC37B787_WDT is not set +CONFIG_W83697HF_WDT=m + +# CONFIG_VIDEO_CAFE_CCIC is not set + +CONFIG_MTD_ESB2ROM=m +CONFIG_MTD_CK804XROM=m + +CONFIG_RELOCATABLE=y +CONFIG_MACINTOSH_DRIVERS=y + +CONFIG_CRASH_DUMP=y +CONFIG_PHYSICAL_START=0x1000000 +CONFIG_PROC_VMCORE=y +CONFIG_CRASH=m + +CONFIG_DMIID=y +CONFIG_ISCSI_IBFT_FIND=y +CONFIG_ISCSI_IBFT=m + + +CONFIG_NO_HZ=y +CONFIG_HIGH_RES_TIMERS=y +CONFIG_CPU_IDLE=y +# CONFIG_CPU_IDLE_GOV_LADDER is not set +CONFIG_CPU_IDLE_GOV_MENU=y + +CONFIG_VIRTUALIZATION=y +CONFIG_KVM=m +CONFIG_KVM_INTEL=m +CONFIG_KVM_AMD=m +CONFIG_KVM_TRACE=y + +CONFIG_PARAVIRT_GUEST=y +CONFIG_PARAVIRT=y +# CONFIG_PARAVIRT_DEBUG is not set +# PARAVIRT_SPINLOCKS has a 5% perf hit +# CONFIG_PARAVIRT_SPINLOCKS is not set +CONFIG_KVM_CLOCK=y +CONFIG_KVM_GUEST=y + +CONFIG_XEN=y +CONFIG_XEN_MAX_DOMAIN_MEMORY=32 +CONFIG_XEN_BALLOON=y +CONFIG_XEN_SCRUB_PAGES=y +CONFIG_XEN_SAVE_RESTORE=y +CONFIG_HVC_XEN=y +CONFIG_XEN_FBDEV_FRONTEND=y +CONFIG_XEN_KBDDEV_FRONTEND=y +CONFIG_XEN_BLKDEV_FRONTEND=m +CONFIG_XEN_NETDEV_FRONTEND=m +CONFIG_XENFS=m +CONFIG_XEN_COMPAT_XENFS=y +CONFIG_XEN_DEV_EVTCHN=m +CONFIG_XEN_SYS_HYPERVISOR=y + +CONFIG_DMADEVICES=y +CONFIG_INTEL_IOATDMA=m + +CONFIG_SENSORS_I5K_AMB=m + +# CONFIG_COMPAT_VDSO is not set +CONFIG_PROVIDE_OHCI1394_DMA_INIT=y +# CONFIG_DEBUG_PER_CPU_MAPS is not set +# CONFIG_CPA_DEBUG is not set + +CONFIG_HP_WATCHDOG=m + +CONFIG_FRAME_WARN=2048 + +CONFIG_MEMTEST_BOOTPARAM=y +CONFIG_MEMTEST_BOOTPARAM_VALUE=0 +CONFIG_NODES_SHIFT=9 +CONFIG_X86_PAT=y +# FIXME: These should be 32bit only +# CONFIG_FB_N411 is not set +CONFIG_STRICT_DEVMEM=y + +CONFIG_DIRECT_GBPAGES=y + +# CONFIG_MEMTEST is not set +CONFIG_AMD_IOMMU=y +CONFIG_AMD_IOMMU_STATS=y +# CONFIG_MAXSMP is not set +CONFIG_MTRR_SANITIZER=y +CONFIG_MTRR_SANITIZER_ENABLE_DEFAULT=1 +CONFIG_MTRR_SANITIZER_SPARE_REG_NR_DEFAULT=1 +CONFIG_SYSPROF_TRACER=y +# CONFIG_X86_VERBOSE_BOOTUP is not set +# CONFIG_MMIOTRACE_TEST is not set + +CONFIG_X86_MPPARSE=y + +CONFIG_BACKLIGHT_MBP_NVIDIA=m + +CONFIG_OPROFILE_IBS=y +CONFIG_MICROCODE_INTEL=y +CONFIG_MICROCODE_AMD=y + +# CONFIG_X86_CHECK_BIOS_CORRUPTION is not set +CONFIG_X86_RESERVE_LOW_64K=y + +# CONFIG_CMDLINE_BOOL is not set + +CONFIG_PANASONIC_LAPTOP=m + +CONFIG_XEN_DEBUG_FS=y +CONFIG_X86_PTRACE_BTS=y + +CONFIG_I7300_IDLE=m +CONFIG_INTR_REMAP=y + +CONFIG_X86_REROUTE_FOR_BROKEN_BOOT_IRQS=y + +CONFIG_POWER_TRACER=y +CONFIG_HW_BRANCH_TRACER=y + +CONFIG_X86_X2APIC=y +CONFIG_SPARSE_IRQ=y +CONFIG_NUMA_MIGRATE_IRQ_DESC=y + +CONFIG_RCU_FANOUT=64 + +# CONFIG_IOMMU_STRESS is not set + +CONFIG_PERF_COUNTERS=y +CONFIG_PERF_EVENTS=y +CONFIG_EVENT_PROFILE=y + +# CONFIG_X86_MCE_INJECT is not set + +CONFIG_SFI=y +CONFIG_INPUT_WINBOND_CIR=m +CONFIG_I2C_SCMI=m +CONFIG_SBC_FITPC2_WATCHDOG=m +CONFIG_EDAC_I3200=m +CONFIG_TOPSTAR_LAPTOP=m +CONFIG_INTEL_TXT=y +CONFIG_GPIO_LANGWELL=y + +CONFIG_FUNCTION_GRAPH_TRACER=y + +CONFIG_ACPI_CMPC=m +CONFIG_MSI_WMI=m +CONFIG_TOSHIBA_BT_RFKILL=m +# CONFIG_SAMSUNG_LAPTOP is not set + +CONFIG_CS5535_MFGPT=m +CONFIG_GEODE_WDT=m +CONFIG_CS5535_CLOCK_EVENT_SRC=m + +CONFIG_X86_DECODER_SELFTEST=y + +CONFIG_CRYPTO_GHASH_CLMUL_NI_INTEL=m diff --git a/crypto-aesni-kill-module_alias.patch b/crypto-aesni-kill-module_alias.patch new file mode 100644 index 000000000..a3ade8a1e --- /dev/null +++ b/crypto-aesni-kill-module_alias.patch @@ -0,0 +1,9 @@ +diff --git a/arch/x86/crypto/aesni-intel_glue.c b/arch/x86/crypto/aesni-intel_glue.c +index 49c552c..ae88694 100644 +--- a/arch/x86/crypto/aesni-intel_glue.c ++++ b/arch/x86/crypto/aesni-intel_glue.c +@@ -720,4 +720,3 @@ module_exit(aesni_exit); + + MODULE_DESCRIPTION("Rijndael (AES) Cipher Algorithm, Intel AES-NI instructions optimized"); + MODULE_LICENSE("GPL"); +-MODULE_ALIAS("aes"); diff --git a/crystalhd-2.6.34-staging.patch b/crystalhd-2.6.34-staging.patch new file mode 100644 index 000000000..f1eb397a8 --- /dev/null +++ b/crystalhd-2.6.34-staging.patch @@ -0,0 +1,8287 @@ +Broadcom Crystal HD video decoder driver from upstream staging/linux-next. + +Signed-off-by: Jarod Wilson + +--- + drivers/staging/Kconfig | 2 + + drivers/staging/Makefile | 1 + + drivers/staging/crystalhd/Kconfig | 6 + + drivers/staging/crystalhd/Makefile | 6 + + drivers/staging/crystalhd/TODO | 16 + + drivers/staging/crystalhd/bc_dts_defs.h | 498 ++++++ + drivers/staging/crystalhd/bc_dts_glob_lnx.h | 299 ++++ + drivers/staging/crystalhd/bc_dts_types.h | 121 ++ + drivers/staging/crystalhd/bcm_70012_regs.h | 757 +++++++++ + drivers/staging/crystalhd/crystalhd_cmds.c | 1058 ++++++++++++ + drivers/staging/crystalhd/crystalhd_cmds.h | 88 + + drivers/staging/crystalhd/crystalhd_fw_if.h | 369 ++++ + drivers/staging/crystalhd/crystalhd_hw.c | 2395 +++++++++++++++++++++++++++ + drivers/staging/crystalhd/crystalhd_hw.h | 398 +++++ + drivers/staging/crystalhd/crystalhd_lnx.c | 780 +++++++++ + drivers/staging/crystalhd/crystalhd_lnx.h | 96 ++ + drivers/staging/crystalhd/crystalhd_misc.c | 1029 ++++++++++++ + drivers/staging/crystalhd/crystalhd_misc.h | 229 +++ + 18 files changed, 8148 insertions(+), 0 deletions(-) + +diff --git a/drivers/staging/Kconfig b/drivers/staging/Kconfig +index 94eb863..61ec152 100644 +--- a/drivers/staging/Kconfig ++++ b/drivers/staging/Kconfig +@@ -145,5 +145,7 @@ source "drivers/staging/netwave/Kconfig" + + source "drivers/staging/sm7xx/Kconfig" + ++source "drivers/staging/crystalhd/Kconfig" ++ + endif # !STAGING_EXCLUDE_BUILD + endif # STAGING +diff --git a/drivers/staging/Makefile b/drivers/staging/Makefile +index b5e67b8..dc40493 100644 +--- a/drivers/staging/Makefile ++++ b/drivers/staging/Makefile +@@ -53,3 +53,4 @@ obj-$(CONFIG_WAVELAN) += wavelan/ + obj-$(CONFIG_PCMCIA_WAVELAN) += wavelan/ + obj-$(CONFIG_PCMCIA_NETWAVE) += netwave/ + obj-$(CONFIG_FB_SM7XX) += sm7xx/ ++obj-$(CONFIG_CRYSTALHD) += crystalhd/ +diff --git a/drivers/staging/crystalhd/Kconfig b/drivers/staging/crystalhd/Kconfig +new file mode 100644 +index 0000000..56b414b +--- /dev/null ++++ b/drivers/staging/crystalhd/Kconfig +@@ -0,0 +1,6 @@ ++config CRYSTALHD ++ tristate "Broadcom Crystal HD video decoder support" ++ depends on PCI ++ default n ++ help ++ Support for the Broadcom Crystal HD video decoder chipset +diff --git a/drivers/staging/crystalhd/Makefile b/drivers/staging/crystalhd/Makefile +new file mode 100644 +index 0000000..e2af0ce +--- /dev/null ++++ b/drivers/staging/crystalhd/Makefile +@@ -0,0 +1,6 @@ ++obj-$(CONFIG_CRYSTALHD) += crystalhd.o ++ ++crystalhd-objs := crystalhd_cmds.o \ ++ crystalhd_hw.o \ ++ crystalhd_lnx.o \ ++ crystalhd_misc.o +diff --git a/drivers/staging/crystalhd/TODO b/drivers/staging/crystalhd/TODO +new file mode 100644 +index 0000000..69be5d0 +--- /dev/null ++++ b/drivers/staging/crystalhd/TODO +@@ -0,0 +1,16 @@ ++- Testing ++- Cleanup return codes ++- Cleanup typedefs ++- Cleanup all WIN* references ++- Allocate an Accelerator device class specific Major number, ++ since we don't have any other open sourced accelerators, it is the only ++ one in that category for now. ++ A somewhat similar device is the DXR2/3 ++ ++Please send patches to: ++Greg Kroah-Hartman ++Naren Sankar ++Jarod Wilson ++Scott Davilla ++Manu Abraham ++ +diff --git a/drivers/staging/crystalhd/bc_dts_defs.h b/drivers/staging/crystalhd/bc_dts_defs.h +new file mode 100644 +index 0000000..c34cc07 +--- /dev/null ++++ b/drivers/staging/crystalhd/bc_dts_defs.h +@@ -0,0 +1,498 @@ ++/******************************************************************** ++ * Copyright(c) 2006-2009 Broadcom Corporation. ++ * ++ * Name: bc_dts_defs.h ++ * ++ * Description: Common definitions for all components. Only types ++ * is allowed to be included from this file. ++ * ++ * AU ++ * ++ * HISTORY: ++ * ++ ******************************************************************** ++ * This header is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU Lesser General Public License as published ++ * by the Free Software Foundation, either version 2.1 of the License. ++ * ++ * This header is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU Lesser General Public License for more details. ++ * You should have received a copy of the GNU Lesser General Public License ++ * along with this header. If not, see . ++ *******************************************************************/ ++ ++#ifndef _BC_DTS_DEFS_H_ ++#define _BC_DTS_DEFS_H_ ++ ++#include "bc_dts_types.h" ++ ++/* BIT Mask */ ++#define BC_BIT(_x) (1 << (_x)) ++ ++typedef enum _BC_STATUS { ++ BC_STS_SUCCESS = 0, ++ BC_STS_INV_ARG = 1, ++ BC_STS_BUSY = 2, ++ BC_STS_NOT_IMPL = 3, ++ BC_STS_PGM_QUIT = 4, ++ BC_STS_NO_ACCESS = 5, ++ BC_STS_INSUFF_RES = 6, ++ BC_STS_IO_ERROR = 7, ++ BC_STS_NO_DATA = 8, ++ BC_STS_VER_MISMATCH = 9, ++ BC_STS_TIMEOUT = 10, ++ BC_STS_FW_CMD_ERR = 11, ++ BC_STS_DEC_NOT_OPEN = 12, ++ BC_STS_ERR_USAGE = 13, ++ BC_STS_IO_USER_ABORT = 14, ++ BC_STS_IO_XFR_ERROR = 15, ++ BC_STS_DEC_NOT_STARTED = 16, ++ BC_STS_FWHEX_NOT_FOUND = 17, ++ BC_STS_FMT_CHANGE = 18, ++ BC_STS_HIF_ACCESS = 19, ++ BC_STS_CMD_CANCELLED = 20, ++ BC_STS_FW_AUTH_FAILED = 21, ++ BC_STS_BOOTLOADER_FAILED = 22, ++ BC_STS_CERT_VERIFY_ERROR = 23, ++ BC_STS_DEC_EXIST_OPEN = 24, ++ BC_STS_PENDING = 25, ++ BC_STS_CLK_NOCHG = 26, ++ ++ /* Must be the last one.*/ ++ BC_STS_ERROR = -1 ++} BC_STATUS; ++ ++/*------------------------------------------------------* ++ * Registry Key Definitions * ++ *------------------------------------------------------*/ ++#define BC_REG_KEY_MAIN_PATH "Software\\Broadcom\\MediaPC\\70010" ++#define BC_REG_KEY_FWPATH "FirmwareFilePath" ++#define BC_REG_KEY_SEC_OPT "DbgOptions" ++ ++/* ++ * Options: ++ * ++ * b[5] = Enable RSA KEY in EEPROM Support ++ * b[6] = Enable Old PIB scheme. (0 = Use PIB with video scheme) ++ * ++ * b[12] = Enable send message to NotifyIcon ++ * ++ */ ++ ++typedef enum _BC_SW_OPTIONS { ++ BC_OPT_DOSER_OUT_ENCRYPT = BC_BIT(3), ++ BC_OPT_LINK_OUT_ENCRYPT = BC_BIT(29), ++} BC_SW_OPTIONS; ++ ++typedef struct _BC_REG_CONFIG{ ++ uint32_t DbgOptions; ++} BC_REG_CONFIG; ++ ++#if defined(__KERNEL__) || defined(__LINUX_USER__) ++#else ++/* Align data structures */ ++#define ALIGN(x) __declspec(align(x)) ++#endif ++ ++/* mode ++ * b[0]..b[7] = _DtsDeviceOpenMode ++ * b[8] = Load new FW ++ * b[9] = Load file play back FW ++ * b[10] = Disk format (0 for HD DVD and 1 for BLU ray) ++ * b[11]-b[15] = default output resolution ++ * b[16] = Skip TX CPB Buffer Check ++ * b[17] = Adaptive Output Encrypt/Scramble Scheme ++ * b[18]-b[31] = reserved for future use ++ */ ++ ++/* To allow multiple apps to open the device. */ ++enum _DtsDeviceOpenMode { ++ DTS_PLAYBACK_MODE = 0, ++ DTS_DIAG_MODE, ++ DTS_MONITOR_MODE, ++ DTS_HWINIT_MODE ++}; ++ ++/* To enable the filter to selectively enable/disable fixes or erratas */ ++enum _DtsDeviceFixMode { ++ DTS_LOAD_NEW_FW = BC_BIT(8), ++ DTS_LOAD_FILE_PLAY_FW = BC_BIT(9), ++ DTS_DISK_FMT_BD = BC_BIT(10), ++ /* b[11]-b[15] : Default output resolution */ ++ DTS_SKIP_TX_CHK_CPB = BC_BIT(16), ++ DTS_ADAPTIVE_OUTPUT_PER = BC_BIT(17), ++ DTS_INTELLIMAP = BC_BIT(18), ++ /* b[19]-b[21] : select clock frequency */ ++ DTS_PLAYBACK_DROP_RPT_MODE = BC_BIT(22) ++}; ++ ++#define DTS_DFLT_RESOLUTION(x) (x<<11) ++ ++#define DTS_DFLT_CLOCK(x) (x<<19) ++ ++/* F/W File Version corresponding to S/W Releases */ ++enum _FW_FILE_VER { ++ /* S/W release: 02.04.02 F/W release 2.12.2.0 */ ++ BC_FW_VER_020402 = ((12<<16) | (2<<8) | (0)) ++}; ++ ++/*------------------------------------------------------* ++ * Stream Types for DtsOpenDecoder() * ++ *------------------------------------------------------*/ ++enum _DtsOpenDecStreamTypes { ++ BC_STREAM_TYPE_ES = 0, ++ BC_STREAM_TYPE_PES = 1, ++ BC_STREAM_TYPE_TS = 2, ++ BC_STREAM_TYPE_ES_TSTAMP = 6, ++}; ++ ++/*------------------------------------------------------* ++ * Video Algorithms for DtsSetVideoParams() * ++ *------------------------------------------------------*/ ++enum _DtsSetVideoParamsAlgo { ++ BC_VID_ALGO_H264 = 0, ++ BC_VID_ALGO_MPEG2 = 1, ++ BC_VID_ALGO_VC1 = 4, ++ BC_VID_ALGO_VC1MP = 7, ++}; ++ ++/*------------------------------------------------------* ++ * MPEG Extension to the PPB * ++ *------------------------------------------------------*/ ++#define BC_MPEG_VALID_PANSCAN (1) ++ ++typedef struct _BC_PIB_EXT_MPEG { ++ uint32_t valid; ++ /* Always valid, defaults to picture size if no ++ * sequence display extension in the stream. */ ++ uint32_t display_horizontal_size; ++ uint32_t display_vertical_size; ++ ++ /* MPEG_VALID_PANSCAN ++ * Offsets are a copy values from the MPEG stream. */ ++ uint32_t offset_count; ++ int32_t horizontal_offset[3]; ++ int32_t vertical_offset[3]; ++ ++} BC_PIB_EXT_MPEG; ++ ++/*------------------------------------------------------* ++ * H.264 Extension to the PPB * ++ *------------------------------------------------------*/ ++/* Bit definitions for 'other.h264.valid' field */ ++#define H264_VALID_PANSCAN (1) ++#define H264_VALID_SPS_CROP (2) ++#define H264_VALID_VUI (4) ++ ++typedef struct _BC_PIB_EXT_H264 { ++ /* 'valid' specifies which fields (or sets of ++ * fields) below are valid. If the corresponding ++ * bit in 'valid' is NOT set then that field(s) ++ * is (are) not initialized. */ ++ uint32_t valid; ++ ++ /* H264_VALID_PANSCAN */ ++ uint32_t pan_scan_count; ++ int32_t pan_scan_left[3]; ++ int32_t pan_scan_right[3]; ++ int32_t pan_scan_top[3]; ++ int32_t pan_scan_bottom[3]; ++ ++ /* H264_VALID_SPS_CROP */ ++ int32_t sps_crop_left; ++ int32_t sps_crop_right; ++ int32_t sps_crop_top; ++ int32_t sps_crop_bottom; ++ ++ /* H264_VALID_VUI */ ++ uint32_t chroma_top; ++ uint32_t chroma_bottom; ++ ++} BC_PIB_EXT_H264; ++ ++/*------------------------------------------------------* ++ * VC1 Extension to the PPB * ++ *------------------------------------------------------*/ ++#define VC1_VALID_PANSCAN (1) ++ ++typedef struct _BC_PIB_EXT_VC1 { ++ uint32_t valid; ++ ++ /* Always valid, defaults to picture size if no ++ * sequence display extension in the stream. */ ++ uint32_t display_horizontal_size; ++ uint32_t display_vertical_size; ++ ++ /* VC1 pan scan windows */ ++ uint32_t num_panscan_windows; ++ int32_t ps_horiz_offset[4]; ++ int32_t ps_vert_offset[4]; ++ int32_t ps_width[4]; ++ int32_t ps_height[4]; ++ ++} BC_PIB_EXT_VC1; ++ ++ ++/*------------------------------------------------------* ++ * Picture Information Block * ++ *------------------------------------------------------*/ ++#if defined(_WIN32) || defined(_WIN64) || defined(__LINUX_USER__) ++/* Values for 'pulldown' field. '0' means no pulldown information ++ * was present for this picture. */ ++enum { ++ vdecNoPulldownInfo = 0, ++ vdecTop = 1, ++ vdecBottom = 2, ++ vdecTopBottom = 3, ++ vdecBottomTop = 4, ++ vdecTopBottomTop = 5, ++ vdecBottomTopBottom = 6, ++ vdecFrame_X2 = 7, ++ vdecFrame_X3 = 8, ++ vdecFrame_X1 = 9, ++ vdecFrame_X4 = 10, ++}; ++ ++/* Values for the 'frame_rate' field. */ ++enum { ++ vdecFrameRateUnknown = 0, ++ vdecFrameRate23_97, ++ vdecFrameRate24, ++ vdecFrameRate25, ++ vdecFrameRate29_97, ++ vdecFrameRate30, ++ vdecFrameRate50, ++ vdecFrameRate59_94, ++ vdecFrameRate60, ++}; ++ ++/* Values for the 'aspect_ratio' field. */ ++enum { ++ vdecAspectRatioUnknown = 0, ++ vdecAspectRatioSquare, ++ vdecAspectRatio12_11, ++ vdecAspectRatio10_11, ++ vdecAspectRatio16_11, ++ vdecAspectRatio40_33, ++ vdecAspectRatio24_11, ++ vdecAspectRatio20_11, ++ vdecAspectRatio32_11, ++ vdecAspectRatio80_33, ++ vdecAspectRatio18_11, ++ vdecAspectRatio15_11, ++ vdecAspectRatio64_33, ++ vdecAspectRatio160_99, ++ vdecAspectRatio4_3, ++ vdecAspectRatio16_9, ++ vdecAspectRatio221_1, ++ vdecAspectRatioOther = 255, ++}; ++ ++/* Values for the 'colour_primaries' field. */ ++enum { ++ vdecColourPrimariesUnknown = 0, ++ vdecColourPrimariesBT709, ++ vdecColourPrimariesUnspecified, ++ vdecColourPrimariesReserved, ++ vdecColourPrimariesBT470_2M = 4, ++ vdecColourPrimariesBT470_2BG, ++ vdecColourPrimariesSMPTE170M, ++ vdecColourPrimariesSMPTE240M, ++ vdecColourPrimariesGenericFilm, ++}; ++ ++enum { ++ vdecRESOLUTION_CUSTOM = 0x00000000, /* custom */ ++ vdecRESOLUTION_480i = 0x00000001, /* 480i */ ++ vdecRESOLUTION_1080i = 0x00000002, /* 1080i (1920x1080, 60i) */ ++ vdecRESOLUTION_NTSC = 0x00000003, /* NTSC (720x483, 60i) */ ++ vdecRESOLUTION_480p = 0x00000004, /* 480p (720x480, 60p) */ ++ vdecRESOLUTION_720p = 0x00000005, /* 720p (1280x720, 60p) */ ++ vdecRESOLUTION_PAL1 = 0x00000006, /* PAL_1 (720x576, 50i) */ ++ vdecRESOLUTION_1080i25 = 0x00000007, /* 1080i25 (1920x1080, 50i) */ ++ vdecRESOLUTION_720p50 = 0x00000008, /* 720p50 (1280x720, 50p) */ ++ vdecRESOLUTION_576p = 0x00000009, /* 576p (720x576, 50p) */ ++ vdecRESOLUTION_1080i29_97 = 0x0000000A, /* 1080i (1920x1080, 59.94i) */ ++ vdecRESOLUTION_720p59_94 = 0x0000000B, /* 720p (1280x720, 59.94p) */ ++ vdecRESOLUTION_SD_DVD = 0x0000000C, /* SD DVD (720x483, 60i) */ ++ vdecRESOLUTION_480p656 = 0x0000000D, /* 480p (720x480, 60p), output bus width 8 bit, clock 74.25MHz */ ++ vdecRESOLUTION_1080p23_976 = 0x0000000E, /* 1080p23_976 (1920x1080, 23.976p) */ ++ vdecRESOLUTION_720p23_976 = 0x0000000F, /* 720p23_976 (1280x720p, 23.976p) */ ++ vdecRESOLUTION_240p29_97 = 0x00000010, /* 240p (1440x240, 29.97p ) */ ++ vdecRESOLUTION_240p30 = 0x00000011, /* 240p (1440x240, 30p) */ ++ vdecRESOLUTION_288p25 = 0x00000012, /* 288p (1440x288p, 25p) */ ++ vdecRESOLUTION_1080p29_97 = 0x00000013, /* 1080p29_97 (1920x1080, 29.97p) */ ++ vdecRESOLUTION_1080p30 = 0x00000014, /* 1080p30 (1920x1080, 30p) */ ++ vdecRESOLUTION_1080p24 = 0x00000015, /* 1080p24 (1920x1080, 24p) */ ++ vdecRESOLUTION_1080p25 = 0x00000016, /* 1080p25 (1920x1080, 25p) */ ++ vdecRESOLUTION_720p24 = 0x00000017, /* 720p24 (1280x720, 25p) */ ++ vdecRESOLUTION_720p29_97 = 0x00000018, /* 720p29.97 (1280x720, 29.97p) */ ++ vdecRESOLUTION_480p23_976 = 0x00000019, /* 480p23.976 (720*480, 23.976) */ ++ vdecRESOLUTION_480p29_97 = 0x0000001A, /* 480p29.976 (720*480, 29.97p) */ ++ vdecRESOLUTION_576p25 = 0x0000001B, /* 576p25 (720*576, 25p) */ ++ /* For Zero Frame Rate */ ++ vdecRESOLUTION_480p0 = 0x0000001C, /* 480p (720x480, 0p) */ ++ vdecRESOLUTION_480i0 = 0x0000001D, /* 480i (720x480, 0i) */ ++ vdecRESOLUTION_576p0 = 0x0000001E, /* 576p (720x576, 0p) */ ++ vdecRESOLUTION_720p0 = 0x0000001F, /* 720p (1280x720, 0p) */ ++ vdecRESOLUTION_1080p0 = 0x00000020, /* 1080p (1920x1080, 0p) */ ++ vdecRESOLUTION_1080i0 = 0x00000021, /* 1080i (1920x1080, 0i) */ ++}; ++ ++/* Bit definitions for 'flags' field */ ++#define VDEC_FLAG_EOS (0x0004) ++ ++#define VDEC_FLAG_FRAME (0x0000) ++#define VDEC_FLAG_FIELDPAIR (0x0008) ++#define VDEC_FLAG_TOPFIELD (0x0010) ++#define VDEC_FLAG_BOTTOMFIELD (0x0018) ++ ++#define VDEC_FLAG_PROGRESSIVE_SRC (0x0000) ++#define VDEC_FLAG_INTERLACED_SRC (0x0020) ++#define VDEC_FLAG_UNKNOWN_SRC (0x0040) ++ ++#define VDEC_FLAG_BOTTOM_FIRST (0x0080) ++#define VDEC_FLAG_LAST_PICTURE (0x0100) ++ ++#define VDEC_FLAG_PICTURE_META_DATA_PRESENT (0x40000) ++ ++#endif /* _WIN32 || _WIN64 */ ++ ++enum _BC_OUTPUT_FORMAT { ++ MODE420 = 0x0, ++ MODE422_YUY2 = 0x1, ++ MODE422_UYVY = 0x2, ++}; ++ ++typedef struct _BC_PIC_INFO_BLOCK { ++ /* Common fields. */ ++ uint64_t timeStamp; /* Timestamp */ ++ uint32_t picture_number; /* Ordinal display number */ ++ uint32_t width; /* pixels */ ++ uint32_t height; /* pixels */ ++ uint32_t chroma_format; /* 0x420, 0x422 or 0x444 */ ++ uint32_t pulldown; ++ uint32_t flags; ++ uint32_t frame_rate; ++ uint32_t aspect_ratio; ++ uint32_t colour_primaries; ++ uint32_t picture_meta_payload; ++ uint32_t sess_num; ++ uint32_t ycom; ++ uint32_t custom_aspect_ratio_width_height; ++ uint32_t n_drop; /* number of non-reference frames remaining to be dropped */ ++ ++ /* Protocol-specific extensions. */ ++ union { ++ BC_PIB_EXT_H264 h264; ++ BC_PIB_EXT_MPEG mpeg; ++ BC_PIB_EXT_VC1 vc1; ++ } other; ++ ++} BC_PIC_INFO_BLOCK, *PBC_PIC_INFO_BLOCK; ++ ++/*------------------------------------------------------* ++ * ProcOut Info * ++ *------------------------------------------------------*/ ++/* Optional flags for ProcOut Interface.*/ ++enum _POUT_OPTIONAL_IN_FLAGS_{ ++ /* Flags from App to Device */ ++ BC_POUT_FLAGS_YV12 = 0x01, /* Copy Data in YV12 format */ ++ BC_POUT_FLAGS_STRIDE = 0x02, /* Stride size is valid. */ ++ BC_POUT_FLAGS_SIZE = 0x04, /* Take size information from Application */ ++ BC_POUT_FLAGS_INTERLACED = 0x08, /* copy only half the bytes */ ++ BC_POUT_FLAGS_INTERLEAVED = 0x10, /* interleaved frame */ ++ ++ /* Flags from Device to APP */ ++ BC_POUT_FLAGS_FMT_CHANGE = 0x10000, /* Data is not VALID when this flag is set */ ++ BC_POUT_FLAGS_PIB_VALID = 0x20000, /* PIB Information valid */ ++ BC_POUT_FLAGS_ENCRYPTED = 0x40000, /* Data is encrypted. */ ++ BC_POUT_FLAGS_FLD_BOT = 0x80000, /* Bottom Field data */ ++}; ++ ++#if defined(__KERNEL__) || defined(__LINUX_USER__) ++typedef BC_STATUS(*dts_pout_callback)(void *shnd, uint32_t width, uint32_t height, uint32_t stride, void *pOut); ++#else ++typedef BC_STATUS(*dts_pout_callback)(void *shnd, uint32_t width, uint32_t height, uint32_t stride, struct _BC_DTS_PROC_OUT *pOut); ++#endif ++ ++/* Line 21 Closed Caption */ ++/* User Data */ ++#define MAX_UD_SIZE 1792 /* 1920 - 128 */ ++ ++typedef struct _BC_DTS_PROC_OUT { ++ uint8_t *Ybuff; /* Caller Supplied buffer for Y data */ ++ uint32_t YbuffSz; /* Caller Supplied Y buffer size */ ++ uint32_t YBuffDoneSz; /* Transferred Y datasize */ ++ ++ uint8_t *UVbuff; /* Caller Supplied buffer for UV data */ ++ uint32_t UVbuffSz; /* Caller Supplied UV buffer size */ ++ uint32_t UVBuffDoneSz; /* Transferred UV data size */ ++ ++ uint32_t StrideSz; /* Caller supplied Stride Size */ ++ uint32_t PoutFlags; /* Call IN Flags */ ++ ++ uint32_t discCnt; /* Picture discontinuity count */ ++ ++ BC_PIC_INFO_BLOCK PicInfo; /* Picture Information Block Data */ ++ ++ /* Line 21 Closed Caption */ ++ /* User Data */ ++ uint32_t UserDataSz; ++ uint8_t UserData[MAX_UD_SIZE]; ++ ++ void *hnd; ++ dts_pout_callback AppCallBack; ++ uint8_t DropFrames; ++ uint8_t b422Mode; /* Picture output Mode */ ++ uint8_t bPibEnc; /* PIB encrypted */ ++ uint8_t bRevertScramble; ++ ++} BC_DTS_PROC_OUT; ++ ++typedef struct _BC_DTS_STATUS { ++ uint8_t ReadyListCount; /* Number of frames in ready list (reported by driver) */ ++ uint8_t FreeListCount; /* Number of frame buffers free. (reported by driver) */ ++ uint8_t PowerStateChange; /* Number of active state power transitions (reported by driver) */ ++ uint8_t reserved_[1]; ++ ++ uint32_t FramesDropped; /* Number of frames dropped. (reported by DIL) */ ++ uint32_t FramesCaptured; /* Number of frames captured. (reported by DIL) */ ++ uint32_t FramesRepeated; /* Number of frames repeated. (reported by DIL) */ ++ ++ uint32_t InputCount; /* Times compressed video has been sent to the HW. ++ * i.e. Successful DtsProcInput() calls (reported by DIL) */ ++ uint64_t InputTotalSize; /* Amount of compressed video that has been sent to the HW. ++ * (reported by DIL) */ ++ uint32_t InputBusyCount; /* Times compressed video has attempted to be sent to the HW ++ * but the input FIFO was full. (reported by DIL) */ ++ ++ uint32_t PIBMissCount; /* Amount of times a PIB is invalid. (reported by DIL) */ ++ ++ uint32_t cpbEmptySize; /* supported only for H.264, specifically changed for ++ * Adobe. Report size of CPB buffer available. ++ * Reported by DIL */ ++ uint64_t NextTimeStamp; /* TimeStamp of the next picture that will be returned ++ * by a call to ProcOutput. Added for Adobe. Reported ++ * back from the driver */ ++ uint8_t reserved__[16]; ++ ++} BC_DTS_STATUS; ++ ++#define BC_SWAP32(_v) \ ++ ((((_v) & 0xFF000000)>>24)| \ ++ (((_v) & 0x00FF0000)>>8)| \ ++ (((_v) & 0x0000FF00)<<8)| \ ++ (((_v) & 0x000000FF)<<24)) ++ ++#define WM_AGENT_TRAYICON_DECODER_OPEN 10001 ++#define WM_AGENT_TRAYICON_DECODER_CLOSE 10002 ++#define WM_AGENT_TRAYICON_DECODER_START 10003 ++#define WM_AGENT_TRAYICON_DECODER_STOP 10004 ++#define WM_AGENT_TRAYICON_DECODER_RUN 10005 ++#define WM_AGENT_TRAYICON_DECODER_PAUSE 10006 ++ ++ ++#endif /* _BC_DTS_DEFS_H_ */ +diff --git a/drivers/staging/crystalhd/bc_dts_glob_lnx.h b/drivers/staging/crystalhd/bc_dts_glob_lnx.h +new file mode 100644 +index 0000000..b3125e3 +--- /dev/null ++++ b/drivers/staging/crystalhd/bc_dts_glob_lnx.h +@@ -0,0 +1,299 @@ ++/******************************************************************** ++ * Copyright(c) 2006-2009 Broadcom Corporation. ++ * ++ * Name: bc_dts_glob_lnx.h ++ * ++ * Description: Wrapper to Windows dts_glob.h for Link-Linux usage. ++ * The idea is to define additional Linux related defs ++ * in this file to avoid changes to existing Windows ++ * glob file. ++ * ++ * AU ++ * ++ * HISTORY: ++ * ++ ******************************************************************** ++ * This header is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU Lesser General Public License as published ++ * by the Free Software Foundation, either version 2.1 of the License. ++ * ++ * This header is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU Lesser General Public License for more details. ++ * You should have received a copy of the GNU Lesser General Public License ++ * along with this header. If not, see . ++ *******************************************************************/ ++ ++#ifndef _BC_DTS_GLOB_LNX_H_ ++#define _BC_DTS_GLOB_LNX_H_ ++ ++#ifdef __LINUX_USER__ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define DRVIFLIB_INT_API ++ ++#endif ++ ++#include "bc_dts_defs.h" ++#include "bcm_70012_regs.h" /* Link Register defs */ ++ ++#define CRYSTALHD_API_NAME "crystalhd" ++#define CRYSTALHD_API_DEV_NAME "/dev/crystalhd" ++ ++/* ++ * These are SW stack tunable parameters shared ++ * between the driver and the application. ++ */ ++enum _BC_DTS_GLOBALS { ++ BC_MAX_FW_CMD_BUFF_SZ = 0x40, /* FW passthrough cmd/rsp buffer size */ ++ PCI_CFG_SIZE = 256, /* PCI config size buffer */ ++ BC_IOCTL_DATA_POOL_SIZE = 8, /* BC_IOCTL_DATA Pool size */ ++ BC_LINK_MAX_OPENS = 3, /* Maximum simultaneous opens*/ ++ BC_LINK_MAX_SGLS = 1024, /* Maximum SG elements 4M/4K */ ++ BC_TX_LIST_CNT = 2, /* Max Tx DMA Rings */ ++ BC_RX_LIST_CNT = 8, /* Max Rx DMA Rings*/ ++ BC_PROC_OUTPUT_TIMEOUT = 3000, /* Milliseconds */ ++ BC_INFIFO_THRESHOLD = 0x10000, ++}; ++ ++typedef struct _BC_CMD_REG_ACC { ++ uint32_t Offset; ++ uint32_t Value; ++} BC_CMD_REG_ACC; ++ ++typedef struct _BC_CMD_DEV_MEM { ++ uint32_t StartOff; ++ uint32_t NumDwords; ++ uint32_t Rsrd; ++} BC_CMD_DEV_MEM; ++ ++/* FW Passthrough command structure */ ++enum _bc_fw_cmd_flags { ++ BC_FW_CMD_FLAGS_NONE = 0, ++ BC_FW_CMD_PIB_QS = 0x01, ++}; ++ ++typedef struct _BC_FW_CMD { ++ uint32_t cmd[BC_MAX_FW_CMD_BUFF_SZ]; ++ uint32_t rsp[BC_MAX_FW_CMD_BUFF_SZ]; ++ uint32_t flags; ++ uint32_t add_data; ++} BC_FW_CMD, *PBC_FW_CMD; ++ ++typedef struct _BC_HW_TYPE { ++ uint16_t PciDevId; ++ uint16_t PciVenId; ++ uint8_t HwRev; ++ uint8_t Align[3]; ++} BC_HW_TYPE; ++ ++typedef struct _BC_PCI_CFG { ++ uint32_t Size; ++ uint32_t Offset; ++ uint8_t pci_cfg_space[PCI_CFG_SIZE]; ++} BC_PCI_CFG; ++ ++typedef struct _BC_VERSION_INFO_ { ++ uint8_t DriverMajor; ++ uint8_t DriverMinor; ++ uint16_t DriverRevision; ++} BC_VERSION_INFO; ++ ++typedef struct _BC_START_RX_CAP_ { ++ uint32_t Rsrd; ++ uint32_t StartDeliveryThsh; ++ uint32_t PauseThsh; ++ uint32_t ResumeThsh; ++} BC_START_RX_CAP; ++ ++typedef struct _BC_FLUSH_RX_CAP_ { ++ uint32_t Rsrd; ++ uint32_t bDiscardOnly; ++} BC_FLUSH_RX_CAP; ++ ++typedef struct _BC_DTS_STATS { ++ uint8_t drvRLL; ++ uint8_t drvFLL; ++ uint8_t eosDetected; ++ uint8_t pwr_state_change; ++ ++ /* Stats from App */ ++ uint32_t opFrameDropped; ++ uint32_t opFrameCaptured; ++ uint32_t ipSampleCnt; ++ uint64_t ipTotalSize; ++ uint32_t reptdFrames; ++ uint32_t pauseCount; ++ uint32_t pibMisses; ++ uint32_t discCounter; ++ ++ /* Stats from Driver */ ++ uint32_t TxFifoBsyCnt; ++ uint32_t intCount; ++ uint32_t DrvIgnIntrCnt; ++ uint32_t DrvTotalFrmDropped; ++ uint32_t DrvTotalHWErrs; ++ uint32_t DrvTotalPIBFlushCnt; ++ uint32_t DrvTotalFrmCaptured; ++ uint32_t DrvPIBMisses; ++ uint32_t DrvPauseTime; ++ uint32_t DrvRepeatedFrms; ++ uint32_t res1[13]; ++ ++} BC_DTS_STATS; ++ ++typedef struct _BC_PROC_INPUT_ { ++ uint8_t *pDmaBuff; ++ uint32_t BuffSz; ++ uint8_t Mapped; ++ uint8_t Encrypted; ++ uint8_t Rsrd[2]; ++ uint32_t DramOffset; /* For debug use only */ ++} BC_PROC_INPUT, *PBC_PROC_INPUT; ++ ++typedef struct _BC_DEC_YUV_BUFFS { ++ uint32_t b422Mode; ++ uint8_t *YuvBuff; ++ uint32_t YuvBuffSz; ++ uint32_t UVbuffOffset; ++ uint32_t YBuffDoneSz; ++ uint32_t UVBuffDoneSz; ++ uint32_t RefCnt; ++} BC_DEC_YUV_BUFFS; ++ ++enum _DECOUT_COMPLETION_FLAGS{ ++ COMP_FLAG_NO_INFO = 0x00, ++ COMP_FLAG_FMT_CHANGE = 0x01, ++ COMP_FLAG_PIB_VALID = 0x02, ++ COMP_FLAG_DATA_VALID = 0x04, ++ COMP_FLAG_DATA_ENC = 0x08, ++ COMP_FLAG_DATA_BOT = 0x10, ++}; ++ ++typedef struct _BC_DEC_OUT_BUFF{ ++ BC_DEC_YUV_BUFFS OutPutBuffs; ++ BC_PIC_INFO_BLOCK PibInfo; ++ uint32_t Flags; ++ uint32_t BadFrCnt; ++} BC_DEC_OUT_BUFF; ++ ++typedef struct _BC_NOTIFY_MODE { ++ uint32_t Mode; ++ uint32_t Rsvr[3]; ++} BC_NOTIFY_MODE; ++ ++typedef struct _BC_CLOCK { ++ uint32_t clk; ++ uint32_t Rsvr[3]; ++} BC_CLOCK; ++ ++typedef struct _BC_IOCTL_DATA { ++ BC_STATUS RetSts; ++ uint32_t IoctlDataSz; ++ uint32_t Timeout; ++ union { ++ BC_CMD_REG_ACC regAcc; ++ BC_CMD_DEV_MEM devMem; ++ BC_FW_CMD fwCmd; ++ BC_HW_TYPE hwType; ++ BC_PCI_CFG pciCfg; ++ BC_VERSION_INFO VerInfo; ++ BC_PROC_INPUT ProcInput; ++ BC_DEC_YUV_BUFFS RxBuffs; ++ BC_DEC_OUT_BUFF DecOutData; ++ BC_START_RX_CAP RxCap; ++ BC_FLUSH_RX_CAP FlushRxCap; ++ BC_DTS_STATS drvStat; ++ BC_NOTIFY_MODE NotifyMode; ++ BC_CLOCK clockValue; ++ } u; ++ struct _BC_IOCTL_DATA *next; ++} BC_IOCTL_DATA; ++ ++typedef enum _BC_DRV_CMD{ ++ DRV_CMD_VERSION = 0, /* Get SW version */ ++ DRV_CMD_GET_HWTYPE, /* Get HW version and type Dozer/Tank */ ++ DRV_CMD_REG_RD, /* Read Device Register */ ++ DRV_CMD_REG_WR, /* Write Device Register */ ++ DRV_CMD_FPGA_RD, /* Read FPGA Register */ ++ DRV_CMD_FPGA_WR, /* Wrtie FPGA Reister */ ++ DRV_CMD_MEM_RD, /* Read Device Memory */ ++ DRV_CMD_MEM_WR, /* Write Device Memory */ ++ DRV_CMD_RD_PCI_CFG, /* Read PCI Config Space */ ++ DRV_CMD_WR_PCI_CFG, /* Write the PCI Configuration Space*/ ++ DRV_CMD_FW_DOWNLOAD, /* Download Firmware */ ++ DRV_ISSUE_FW_CMD, /* Issue FW Cmd (pass through mode) */ ++ DRV_CMD_PROC_INPUT, /* Process Input Sample */ ++ DRV_CMD_ADD_RXBUFFS, /* Add Rx side buffers to driver pool */ ++ DRV_CMD_FETCH_RXBUFF, /* Get Rx DMAed buffer */ ++ DRV_CMD_START_RX_CAP, /* Start Rx Buffer Capture */ ++ DRV_CMD_FLUSH_RX_CAP, /* Stop the capture for now...we will enhance this later*/ ++ DRV_CMD_GET_DRV_STAT, /* Get Driver Internal Statistics */ ++ DRV_CMD_RST_DRV_STAT, /* Reset Driver Internal Statistics */ ++ DRV_CMD_NOTIFY_MODE, /* Notify the Mode to driver in which the application is Operating*/ ++ DRV_CMD_CHANGE_CLOCK, /* Change the core clock to either save power or improve performance */ ++ ++ /* MUST be the last one.. */ ++ DRV_CMD_END, /* End of the List.. */ ++} BC_DRV_CMD; ++ ++#define BC_IOC_BASE 'b' ++#define BC_IOC_VOID _IOC_NONE ++#define BC_IOC_IOWR(nr, type) _IOWR(BC_IOC_BASE, nr, type) ++#define BC_IOCTL_MB BC_IOCTL_DATA ++ ++#define BCM_IOC_GET_VERSION BC_IOC_IOWR(DRV_CMD_VERSION, BC_IOCTL_MB) ++#define BCM_IOC_GET_HWTYPE BC_IOC_IOWR(DRV_CMD_GET_HWTYPE, BC_IOCTL_MB) ++#define BCM_IOC_REG_RD BC_IOC_IOWR(DRV_CMD_REG_RD, BC_IOCTL_MB) ++#define BCM_IOC_REG_WR BC_IOC_IOWR(DRV_CMD_REG_WR, BC_IOCTL_MB) ++#define BCM_IOC_MEM_RD BC_IOC_IOWR(DRV_CMD_MEM_RD, BC_IOCTL_MB) ++#define BCM_IOC_MEM_WR BC_IOC_IOWR(DRV_CMD_MEM_WR, BC_IOCTL_MB) ++#define BCM_IOC_FPGA_RD BC_IOC_IOWR(DRV_CMD_FPGA_RD, BC_IOCTL_MB) ++#define BCM_IOC_FPGA_WR BC_IOC_IOWR(DRV_CMD_FPGA_WR, BC_IOCTL_MB) ++#define BCM_IOC_RD_PCI_CFG BC_IOC_IOWR(DRV_CMD_RD_PCI_CFG, BC_IOCTL_MB) ++#define BCM_IOC_WR_PCI_CFG BC_IOC_IOWR(DRV_CMD_WR_PCI_CFG, BC_IOCTL_MB) ++#define BCM_IOC_PROC_INPUT BC_IOC_IOWR(DRV_CMD_PROC_INPUT, BC_IOCTL_MB) ++#define BCM_IOC_ADD_RXBUFFS BC_IOC_IOWR(DRV_CMD_ADD_RXBUFFS, BC_IOCTL_MB) ++#define BCM_IOC_FETCH_RXBUFF BC_IOC_IOWR(DRV_CMD_FETCH_RXBUFF, BC_IOCTL_MB) ++#define BCM_IOC_FW_CMD BC_IOC_IOWR(DRV_ISSUE_FW_CMD, BC_IOCTL_MB) ++#define BCM_IOC_START_RX_CAP BC_IOC_IOWR(DRV_CMD_START_RX_CAP, BC_IOCTL_MB) ++#define BCM_IOC_FLUSH_RX_CAP BC_IOC_IOWR(DRV_CMD_FLUSH_RX_CAP, BC_IOCTL_MB) ++#define BCM_IOC_GET_DRV_STAT BC_IOC_IOWR(DRV_CMD_GET_DRV_STAT, BC_IOCTL_MB) ++#define BCM_IOC_RST_DRV_STAT BC_IOC_IOWR(DRV_CMD_RST_DRV_STAT, BC_IOCTL_MB) ++#define BCM_IOC_NOTIFY_MODE BC_IOC_IOWR(DRV_CMD_NOTIFY_MODE, BC_IOCTL_MB) ++#define BCM_IOC_FW_DOWNLOAD BC_IOC_IOWR(DRV_CMD_FW_DOWNLOAD, BC_IOCTL_MB) ++#define BCM_IOC_CHG_CLK BC_IOC_IOWR(DRV_CMD_CHANGE_CLOCK, BC_IOCTL_MB) ++#define BCM_IOC_END BC_IOC_VOID ++ ++/* Wrapper for main IOCTL data */ ++typedef struct _crystalhd_ioctl_data { ++ BC_IOCTL_DATA udata; /* IOCTL from App..*/ ++ uint32_t u_id; /* Driver specific user ID */ ++ uint32_t cmd; /* Cmd ID for driver's use. */ ++ void *add_cdata; /* Additional command specific data..*/ ++ uint32_t add_cdata_sz; /* Additional command specific data size */ ++ struct _crystalhd_ioctl_data *next; /* List/Fifo management */ ++} crystalhd_ioctl_data; ++ ++ ++enum _crystalhd_kmod_ver{ ++ crystalhd_kmod_major = 0, ++ crystalhd_kmod_minor = 9, ++ crystalhd_kmod_rev = 27, ++}; ++ ++#endif +diff --git a/drivers/staging/crystalhd/bc_dts_types.h b/drivers/staging/crystalhd/bc_dts_types.h +new file mode 100644 +index 0000000..ac0c817 +--- /dev/null ++++ b/drivers/staging/crystalhd/bc_dts_types.h +@@ -0,0 +1,121 @@ ++/******************************************************************** ++ * Copyright(c) 2006-2009 Broadcom Corporation. ++ * ++ * Name: bc_dts_types.h ++ * ++ * Description: Data types ++ * ++ * AU ++ * ++ * HISTORY: ++ * ++ ******************************************************************** ++ * This header is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU Lesser General Public License as published ++ * by the Free Software Foundation, either version 2.1 of the License. ++ * ++ * This header is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU Lesser General Public License for more details. ++ * You should have received a copy of the GNU Lesser General Public License ++ * along with this header. If not, see . ++ *******************************************************************/ ++ ++#ifndef _BC_DTS_TYPES_H_ ++#define _BC_DTS_TYPES_H_ ++ ++#ifdef __LINUX_USER__ // Don't include these for KERNEL.. ++#include ++#endif ++ ++#if defined(_WIN64) || defined(_WIN32) ++typedef uint32_t U32; ++typedef int32_t S32; ++typedef uint16_t U16; ++typedef int16_t S16; ++typedef unsigned char U8; ++typedef char S8; ++#endif ++ ++#ifndef PVOID ++typedef void *PVOID; ++#endif ++ ++#ifndef BOOL ++typedef int BOOL; ++#endif ++ ++#ifdef WIN32 ++ typedef unsigned __int64 U64; ++#elif defined(_WIN64) ++ typedef uint64_t U64; ++#endif ++ ++#ifdef _WIN64 ++#if !(defined(POINTER_32)) ++#define POINTER_32 __ptr32 ++#endif ++#else /* _WIN32 */ ++#define POINTER_32 ++#endif ++ ++#if defined(__KERNEL__) || defined(__LINUX_USER__) ++ ++#ifdef __LINUX_USER__ /* Don't include these for KERNEL */ ++typedef uint32_t ULONG; ++typedef int32_t LONG; ++typedef void *HANDLE; ++#ifndef VOID ++typedef void VOID; ++#endif ++typedef void *LPVOID; ++typedef uint32_t DWORD; ++typedef uint32_t UINT32; ++typedef uint32_t *LPDWORD; ++typedef unsigned char *PUCHAR; ++ ++#ifndef TRUE ++ #define TRUE 1 ++#endif ++ ++#ifndef FALSE ++ #define FALSE 0 ++#endif ++ ++#define TEXT ++ ++#else ++ ++/* For Kernel usage.. */ ++typedef bool bc_bool_t; ++#endif ++ ++#else ++ ++#ifndef uint64_t ++typedef struct _uint64_t { ++ uint32_t low_dw; ++ uint32_t hi_dw; ++} uint64_t; ++#endif ++ ++#ifndef int32_t ++typedef signed long int32_t; ++#endif ++ ++#ifndef uint32_t ++typedef unsigned long uint32_t; ++#endif ++ ++#ifndef uint16_t ++typedef unsigned short uint16_t; ++#endif ++ ++#ifndef uint8_t ++typedef unsigned char uint8_t; ++#endif ++#endif ++ ++#endif ++ +diff --git a/drivers/staging/crystalhd/bcm_70012_regs.h b/drivers/staging/crystalhd/bcm_70012_regs.h +new file mode 100644 +index 0000000..6922f54 +--- /dev/null ++++ b/drivers/staging/crystalhd/bcm_70012_regs.h +@@ -0,0 +1,757 @@ ++/*************************************************************************** ++ * Copyright (c) 1999-2009, Broadcom Corporation. ++ * ++ * Name: bcm_70012_regs.h ++ * ++ * Description: BCM70012 registers ++ * ++ ******************************************************************** ++ * This header is free software: you can redistribute it and/or modify ++ * it under the terms of the GNU Lesser General Public License as published ++ * by the Free Software Foundation, either version 2.1 of the License. ++ * ++ * This header is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU Lesser General Public License for more details. ++ * You should have received a copy of the GNU Lesser General Public License ++ * along with this header. If not, see . ++ ***************************************************************************/ ++ ++#ifndef MACFILE_H__ ++#define MACFILE_H__ ++ ++/** ++ * m = memory, c = core, r = register, f = field, d = data. ++ */ ++#if !defined(GET_FIELD) && !defined(SET_FIELD) ++#define BRCM_ALIGN(c,r,f) c##_##r##_##f##_ALIGN ++#define BRCM_BITS(c,r,f) c##_##r##_##f##_BITS ++#define BRCM_MASK(c,r,f) c##_##r##_##f##_MASK ++#define BRCM_SHIFT(c,r,f) c##_##r##_##f##_SHIFT ++ ++#define GET_FIELD(m,c,r,f) \ ++ ((((m) & BRCM_MASK(c,r,f)) >> BRCM_SHIFT(c,r,f)) << BRCM_ALIGN(c,r,f)) ++ ++#define SET_FIELD(m,c,r,f,d) \ ++ ((m) = (((m) & ~BRCM_MASK(c,r,f)) | ((((d) >> BRCM_ALIGN(c,r,f)) << \ ++ BRCM_SHIFT(c,r,f)) & BRCM_MASK(c,r,f))) \ ++ ) ++ ++#define SET_TYPE_FIELD(m,c,r,f,d) SET_FIELD(m,c,r,f,c##_##d) ++#define SET_NAME_FIELD(m,c,r,f,d) SET_FIELD(m,c,r,f,c##_##r##_##f##_##d) ++#define SET_VALUE_FIELD(m,c,r,f,d) SET_FIELD(m,c,r,f,d) ++ ++#endif /* GET & SET */ ++ ++/**************************************************************************** ++ * Core Enums. ++ ***************************************************************************/ ++/**************************************************************************** ++ * Enums: AES_RGR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define AES_RGR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define AES_RGR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: CCE_RGR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define CCE_RGR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define CCE_RGR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: DBU_RGR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define DBU_RGR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define DBU_RGR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: DCI_RGR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define DCI_RGR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define DCI_RGR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: GISB_ARBITER_DEASSERT_ASSERT ++ ***************************************************************************/ ++#define GISB_ARBITER_DEASSERT_ASSERT_DEASSERT 0 ++#define GISB_ARBITER_DEASSERT_ASSERT_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: GISB_ARBITER_UNMASK_MASK ++ ***************************************************************************/ ++#define GISB_ARBITER_UNMASK_MASK_UNMASK 0 ++#define GISB_ARBITER_UNMASK_MASK_MASK 1 ++ ++/**************************************************************************** ++ * Enums: GISB_ARBITER_DISABLE_ENABLE ++ ***************************************************************************/ ++#define GISB_ARBITER_DISABLE_ENABLE_DISABLE 0 ++#define GISB_ARBITER_DISABLE_ENABLE_ENABLE 1 ++ ++/**************************************************************************** ++ * Enums: I2C_GR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define I2C_GR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define I2C_GR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: MISC_GR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define MISC_GR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define MISC_GR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * Enums: OTP_GR_BRIDGE_RESET_CTRL ++ ***************************************************************************/ ++#define OTP_GR_BRIDGE_RESET_CTRL_DEASSERT 0 ++#define OTP_GR_BRIDGE_RESET_CTRL_ASSERT 1 ++ ++/**************************************************************************** ++ * BCM70012_TGT_TOP_PCIE_CFG ++ ***************************************************************************/ ++#define PCIE_CFG_DEVICE_VENDOR_ID 0x00000000 /* DEVICE_VENDOR_ID Register */ ++#define PCIE_CFG_STATUS_COMMAND 0x00000004 /* STATUS_COMMAND Register */ ++#define PCIE_CFG_PCI_CLASSCODE_AND_REVISION_ID 0x00000008 /* PCI_CLASSCODE_AND_REVISION_ID Register */ ++#define PCIE_CFG_BIST_HEADER_TYPE_LATENCY_TIMER_CACHE_LINE_SIZE 0x0000000c /* BIST_HEADER_TYPE_LATENCY_TIMER_CACHE_LINE_SIZE Register */ ++#define PCIE_CFG_BASE_ADDRESS_1 0x00000010 /* BASE_ADDRESS_1 Register */ ++#define PCIE_CFG_BASE_ADDRESS_2 0x00000014 /* BASE_ADDRESS_2 Register */ ++#define PCIE_CFG_BASE_ADDRESS_3 0x00000018 /* BASE_ADDRESS_3 Register */ ++#define PCIE_CFG_BASE_ADDRESS_4 0x0000001c /* BASE_ADDRESS_4 Register */ ++#define PCIE_CFG_CARDBUS_CIS_POINTER 0x00000028 /* CARDBUS_CIS_POINTER Register */ ++#define PCIE_CFG_SUBSYSTEM_DEVICE_VENDOR_ID 0x0000002c /* SUBSYSTEM_DEVICE_VENDOR_ID Register */ ++#define PCIE_CFG_EXPANSION_ROM_BASE_ADDRESS 0x00000030 /* EXPANSION_ROM_BASE_ADDRESS Register */ ++#define PCIE_CFG_CAPABILITIES_POINTER 0x00000034 /* CAPABILITIES_POINTER Register */ ++#define PCIE_CFG_INTERRUPT 0x0000003c /* INTERRUPT Register */ ++#define PCIE_CFG_VPD_CAPABILITIES 0x00000040 /* VPD_CAPABILITIES Register */ ++#define PCIE_CFG_VPD_DATA 0x00000044 /* VPD_DATA Register */ ++#define PCIE_CFG_POWER_MANAGEMENT_CAPABILITY 0x00000048 /* POWER_MANAGEMENT_CAPABILITY Register */ ++#define PCIE_CFG_POWER_MANAGEMENT_CONTROL_STATUS 0x0000004c /* POWER_MANAGEMENT_CONTROL_STATUS Register */ ++#define PCIE_CFG_MSI_CAPABILITY_HEADER 0x00000050 /* MSI_CAPABILITY_HEADER Register */ ++#define PCIE_CFG_MSI_LOWER_ADDRESS 0x00000054 /* MSI_LOWER_ADDRESS Register */ ++#define PCIE_CFG_MSI_UPPER_ADDRESS_REGISTER 0x00000058 /* MSI_UPPER_ADDRESS_REGISTER Register */ ++#define PCIE_CFG_MSI_DATA 0x0000005c /* MSI_DATA Register */ ++#define PCIE_CFG_BROADCOM_VENDOR_SPECIFIC_CAPABILITY_HEADER 0x00000060 /* BROADCOM_VENDOR_SPECIFIC_CAPABILITY_HEADER Register */ ++#define PCIE_CFG_RESET_COUNTERS_INITIAL_VALUES 0x00000064 /* RESET_COUNTERS_INITIAL_VALUES Register */ ++#define PCIE_CFG_MISCELLANEOUS_HOST_CONTROL 0x00000068 /* MISCELLANEOUS_HOST_CONTROL Register */ ++#define PCIE_CFG_SPARE 0x0000006c /* SPARE Register */ ++#define PCIE_CFG_PCI_STATE 0x00000070 /* PCI_STATE Register */ ++#define PCIE_CFG_CLOCK_CONTROL 0x00000074 /* CLOCK_CONTROL Register */ ++#define PCIE_CFG_REGISTER_BASE 0x00000078 /* REGISTER_BASE Register */ ++#define PCIE_CFG_MEMORY_BASE 0x0000007c /* MEMORY_BASE Register */ ++#define PCIE_CFG_REGISTER_DATA 0x00000080 /* REGISTER_DATA Register */ ++#define PCIE_CFG_MEMORY_DATA 0x00000084 /* MEMORY_DATA Register */ ++#define PCIE_CFG_EXPANSION_ROM_BAR_SIZE 0x00000088 /* EXPANSION_ROM_BAR_SIZE Register */ ++#define PCIE_CFG_EXPANSION_ROM_ADDRESS 0x0000008c /* EXPANSION_ROM_ADDRESS Register */ ++#define PCIE_CFG_EXPANSION_ROM_DATA 0x00000090 /* EXPANSION_ROM_DATA Register */ ++#define PCIE_CFG_VPD_INTERFACE 0x00000094 /* VPD_INTERFACE Register */ ++#define PCIE_CFG_UNDI_RECEIVE_BD_STANDARD_PRODUCER_RING_PRODUCER_INDEX_MAILBOX_UPPER 0x00000098 /* UNDI_RECEIVE_BD_STANDARD_PRODUCER_RING_PRODUCER_INDEX_MAILBOX_UPPER Register */ ++#define PCIE_CFG_UNDI_RECEIVE_BD_STANDARD_PRODUCER_RING_PRODUCER_INDEX_MAILBOX_LOWER 0x0000009c /* UNDI_RECEIVE_BD_STANDARD_PRODUCER_RING_PRODUCER_INDEX_MAILBOX_LOWER Register */ ++#define PCIE_CFG_UNDI_RECEIVE_RETURN_RING_CONSUMER_INDEX_UPPER 0x000000a0 /* UNDI_RECEIVE_RETURN_RING_CONSUMER_INDEX_UPPER Register */ ++#define PCIE_CFG_UNDI_RECEIVE_RETURN_RING_CONSUMER_INDEX_LOWER 0x000000a4 /* UNDI_RECEIVE_RETURN_RING_CONSUMER_INDEX_LOWER Register */ ++#define PCIE_CFG_UNDI_SEND_BD_PRODUCER_INDEX_MAILBOX_UPPER 0x000000a8 /* UNDI_SEND_BD_PRODUCER_INDEX_MAILBOX_UPPER Register */ ++#define PCIE_CFG_UNDI_SEND_BD_PRODUCER_INDEX_MAILBOX_LOWER 0x000000ac /* UNDI_SEND_BD_PRODUCER_INDEX_MAILBOX_LOWER Register */ ++#define PCIE_CFG_INT_MAILBOX_UPPER 0x000000b0 /* INT_MAILBOX_UPPER Register */ ++#define PCIE_CFG_INT_MAILBOX_LOWER 0x000000b4 /* INT_MAILBOX_LOWER Register */ ++#define PCIE_CFG_PRODUCT_ID_AND_ASIC_REVISION 0x000000bc /* PRODUCT_ID_AND_ASIC_REVISION Register */ ++#define PCIE_CFG_FUNCTION_EVENT 0x000000c0 /* FUNCTION_EVENT Register */ ++#define PCIE_CFG_FUNCTION_EVENT_MASK 0x000000c4 /* FUNCTION_EVENT_MASK Register */ ++#define PCIE_CFG_FUNCTION_PRESENT 0x000000c8 /* FUNCTION_PRESENT Register */ ++#define PCIE_CFG_PCIE_CAPABILITIES 0x000000cc /* PCIE_CAPABILITIES Register */ ++#define PCIE_CFG_DEVICE_CAPABILITIES 0x000000d0 /* DEVICE_CAPABILITIES Register */ ++#define PCIE_CFG_DEVICE_STATUS_CONTROL 0x000000d4 /* DEVICE_STATUS_CONTROL Register */ ++#define PCIE_CFG_LINK_CAPABILITY 0x000000d8 /* LINK_CAPABILITY Register */ ++#define PCIE_CFG_LINK_STATUS_CONTROL 0x000000dc /* LINK_STATUS_CONTROL Register */ ++#define PCIE_CFG_DEVICE_CAPABILITIES_2 0x000000f0 /* DEVICE_CAPABILITIES_2 Register */ ++#define PCIE_CFG_DEVICE_STATUS_CONTROL_2 0x000000f4 /* DEVICE_STATUS_CONTROL_2 Register */ ++#define PCIE_CFG_LINK_CAPABILITIES_2 0x000000f8 /* LINK_CAPABILITIES_2 Register */ ++#define PCIE_CFG_LINK_STATUS_CONTROL_2 0x000000fc /* LINK_STATUS_CONTROL_2 Register */ ++#define PCIE_CFG_ADVANCED_ERROR_REPORTING_ENHANCED_CAPABILITY_HEADER 0x00000100 /* ADVANCED_ERROR_REPORTING_ENHANCED_CAPABILITY_HEADER Register */ ++#define PCIE_CFG_UNCORRECTABLE_ERROR_STATUS 0x00000104 /* UNCORRECTABLE_ERROR_STATUS Register */ ++#define PCIE_CFG_UNCORRECTABLE_ERROR_MASK 0x00000108 /* UNCORRECTABLE_ERROR_MASK Register */ ++#define PCIE_CFG_UNCORRECTABLE_ERROR_SEVERITY 0x0000010c /* UNCORRECTABLE_ERROR_SEVERITY Register */ ++#define PCIE_CFG_CORRECTABLE_ERROR_STATUS 0x00000110 /* CORRECTABLE_ERROR_STATUS Register */ ++#define PCIE_CFG_CORRECTABLE_ERROR_MASK 0x00000114 /* CORRECTABLE_ERROR_MASK Register */ ++#define PCIE_CFG_ADVANCED_ERROR_CAPABILITIES_AND_CONTROL 0x00000118 /* ADVANCED_ERROR_CAPABILITIES_AND_CONTROL Register */ ++#define PCIE_CFG_HEADER_LOG_1 0x0000011c /* HEADER_LOG_1 Register */ ++#define PCIE_CFG_HEADER_LOG_2 0x00000120 /* HEADER_LOG_2 Register */ ++#define PCIE_CFG_HEADER_LOG_3 0x00000124 /* HEADER_LOG_3 Register */ ++#define PCIE_CFG_HEADER_LOG_4 0x00000128 /* HEADER_LOG_4 Register */ ++#define PCIE_CFG_VIRTUAL_CHANNEL_ENHANCED_CAPABILITY_HEADER 0x0000013c /* VIRTUAL_CHANNEL_ENHANCED_CAPABILITY_HEADER Register */ ++#define PCIE_CFG_PORT_VC_CAPABILITY 0x00000140 /* PORT_VC_CAPABILITY Register */ ++#define PCIE_CFG_PORT_VC_CAPABILITY_2 0x00000144 /* PORT_VC_CAPABILITY_2 Register */ ++#define PCIE_CFG_PORT_VC_STATUS_CONTROL 0x00000148 /* PORT_VC_STATUS_CONTROL Register */ ++#define PCIE_CFG_VC_RESOURCE_CAPABILITY 0x0000014c /* VC_RESOURCE_CAPABILITY Register */ ++#define PCIE_CFG_VC_RESOURCE_CONTROL 0x00000150 /* VC_RESOURCE_CONTROL Register */ ++#define PCIE_CFG_VC_RESOURCE_STATUS 0x00000154 /* VC_RESOURCE_STATUS Register */ ++#define PCIE_CFG_DEVICE_SERIAL_NO_ENHANCED_CAPABILITY_HEADER 0x00000160 /* DEVICE_SERIAL_NO_ENHANCED_CAPABILITY_HEADER Register */ ++#define PCIE_CFG_DEVICE_SERIAL_NO_LOWER_DW 0x00000164 /* DEVICE_SERIAL_NO_LOWER_DW Register */ ++#define PCIE_CFG_DEVICE_SERIAL_NO_UPPER_DW 0x00000168 /* DEVICE_SERIAL_NO_UPPER_DW Register */ ++#define PCIE_CFG_POWER_BUDGETING_ENHANCED_CAPABILITY_HEADER 0x0000016c /* POWER_BUDGETING_ENHANCED_CAPABILITY_HEADER Register */ ++#define PCIE_CFG_POWER_BUDGETING_DATA_SELECT 0x00000170 /* POWER_BUDGETING_DATA_SELECT Register */ ++#define PCIE_CFG_POWER_BUDGETING_DATA 0x00000174 /* POWER_BUDGETING_DATA Register */ ++#define PCIE_CFG_POWER_BUDGETING_CAPABILITY 0x00000178 /* POWER_BUDGETING_CAPABILITY Register */ ++#define PCIE_CFG_FIRMWARE_POWER_BUDGETING_2_1 0x0000017c /* FIRMWARE_POWER_BUDGETING_2_1 Register */ ++#define PCIE_CFG_FIRMWARE_POWER_BUDGETING_4_3 0x00000180 /* FIRMWARE_POWER_BUDGETING_4_3 Register */ ++#define PCIE_CFG_FIRMWARE_POWER_BUDGETING_6_5 0x00000184 /* FIRMWARE_POWER_BUDGETING_6_5 Register */ ++#define PCIE_CFG_FIRMWARE_POWER_BUDGETING_8_7 0x00000188 /* FIRMWARE_POWER_BUDGETING_8_7 Register */ ++#define PCIE_CFG_PCIE_1_1_ADVISORY_NON_FATAL_ERROR_MASKING 0x0000018c /* PCIE_1_1_ADVISORY_NON_FATAL_ERROR_MASKING Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_TGT_TOP_PCIE_TL ++ ***************************************************************************/ ++#define PCIE_TL_TL_CONTROL 0x00000400 /* TL_CONTROL Register */ ++#define PCIE_TL_TRANSACTION_CONFIGURATION 0x00000404 /* TRANSACTION_CONFIGURATION Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_TGT_TOP_PCIE_DLL ++ ***************************************************************************/ ++#define PCIE_DLL_DATA_LINK_CONTROL 0x00000500 /* DATA_LINK_CONTROL Register */ ++#define PCIE_DLL_DATA_LINK_STATUS 0x00000504 /* DATA_LINK_STATUS Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_TGT_TOP_INTR ++ ***************************************************************************/ ++#define INTR_INTR_STATUS 0x00000700 /* Interrupt Status Register */ ++#define INTR_INTR_SET 0x00000704 /* Interrupt Set Register */ ++#define INTR_INTR_CLR_REG 0x00000708 /* Interrupt Clear Register */ ++#define INTR_INTR_MSK_STS_REG 0x0000070c /* Interrupt Mask Status Register */ ++#define INTR_INTR_MSK_SET_REG 0x00000710 /* Interrupt Mask Set Register */ ++#define INTR_INTR_MSK_CLR_REG 0x00000714 /* Interrupt Mask Clear Register */ ++#define INTR_EOI_CTRL 0x00000720 /* End of interrupt control register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_MISC_TOP_MISC1 ++ ***************************************************************************/ ++#define MISC1_TX_FIRST_DESC_L_ADDR_LIST0 0x00000c00 /* Tx DMA Descriptor List0 First Descriptor lower Address */ ++#define MISC1_TX_FIRST_DESC_U_ADDR_LIST0 0x00000c04 /* Tx DMA Descriptor List0 First Descriptor Upper Address */ ++#define MISC1_TX_FIRST_DESC_L_ADDR_LIST1 0x00000c08 /* Tx DMA Descriptor List1 First Descriptor Lower Address */ ++#define MISC1_TX_FIRST_DESC_U_ADDR_LIST1 0x00000c0c /* Tx DMA Descriptor List1 First Descriptor Upper Address */ ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS 0x00000c10 /* Tx DMA Software Descriptor List Control and Status */ ++#define MISC1_TX_DMA_ERROR_STATUS 0x00000c18 /* Tx DMA Engine Error Status */ ++#define MISC1_TX_DMA_LIST0_CUR_DESC_L_ADDR 0x00000c1c /* Tx DMA List0 Current Descriptor Lower Address */ ++#define MISC1_TX_DMA_LIST0_CUR_DESC_U_ADDR 0x00000c20 /* Tx DMA List0 Current Descriptor Upper Address */ ++#define MISC1_TX_DMA_LIST0_CUR_BYTE_CNT_REM 0x00000c24 /* Tx DMA List0 Current Descriptor Upper Address */ ++#define MISC1_TX_DMA_LIST1_CUR_DESC_L_ADDR 0x00000c28 /* Tx DMA List1 Current Descriptor Lower Address */ ++#define MISC1_TX_DMA_LIST1_CUR_DESC_U_ADDR 0x00000c2c /* Tx DMA List1 Current Descriptor Upper Address */ ++#define MISC1_TX_DMA_LIST1_CUR_BYTE_CNT_REM 0x00000c30 /* Tx DMA List1 Current Descriptor Upper Address */ ++#define MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST0 0x00000c34 /* Y Rx Descriptor List0 First Descriptor Lower Address */ ++#define MISC1_Y_RX_FIRST_DESC_U_ADDR_LIST0 0x00000c38 /* Y Rx Descriptor List0 First Descriptor Upper Address */ ++#define MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST1 0x00000c3c /* Y Rx Descriptor List1 First Descriptor Lower Address */ ++#define MISC1_Y_RX_FIRST_DESC_U_ADDR_LIST1 0x00000c40 /* Y Rx Descriptor List1 First Descriptor Upper Address */ ++#define MISC1_Y_RX_SW_DESC_LIST_CTRL_STS 0x00000c44 /* Y Rx Software Descriptor List Control and Status */ ++#define MISC1_Y_RX_ERROR_STATUS 0x00000c4c /* Y Rx Engine Error Status */ ++#define MISC1_Y_RX_LIST0_CUR_DESC_L_ADDR 0x00000c50 /* Y Rx List0 Current Descriptor Lower Address */ ++#define MISC1_Y_RX_LIST0_CUR_DESC_U_ADDR 0x00000c54 /* Y Rx List0 Current Descriptor Upper Address */ ++#define MISC1_Y_RX_LIST0_CUR_BYTE_CNT 0x00000c58 /* Y Rx List0 Current Descriptor Byte Count */ ++#define MISC1_Y_RX_LIST1_CUR_DESC_L_ADDR 0x00000c5c /* Y Rx List1 Current Descriptor Lower address */ ++#define MISC1_Y_RX_LIST1_CUR_DESC_U_ADDR 0x00000c60 /* Y Rx List1 Current Descriptor Upper address */ ++#define MISC1_Y_RX_LIST1_CUR_BYTE_CNT 0x00000c64 /* Y Rx List1 Current Descriptor Byte Count */ ++#define MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST0 0x00000c68 /* UV Rx Descriptor List0 First Descriptor lower Address */ ++#define MISC1_UV_RX_FIRST_DESC_U_ADDR_LIST0 0x00000c6c /* UV Rx Descriptor List0 First Descriptor Upper Address */ ++#define MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST1 0x00000c70 /* UV Rx Descriptor List1 First Descriptor Lower Address */ ++#define MISC1_UV_RX_FIRST_DESC_U_ADDR_LIST1 0x00000c74 /* UV Rx Descriptor List1 First Descriptor Upper Address */ ++#define MISC1_UV_RX_SW_DESC_LIST_CTRL_STS 0x00000c78 /* UV Rx Software Descriptor List Control and Status */ ++#define MISC1_UV_RX_ERROR_STATUS 0x00000c7c /* UV Rx Engine Error Status */ ++#define MISC1_UV_RX_LIST0_CUR_DESC_L_ADDR 0x00000c80 /* UV Rx List0 Current Descriptor Lower Address */ ++#define MISC1_UV_RX_LIST0_CUR_DESC_U_ADDR 0x00000c84 /* UV Rx List0 Current Descriptor Upper Address */ ++#define MISC1_UV_RX_LIST0_CUR_BYTE_CNT 0x00000c88 /* UV Rx List0 Current Descriptor Byte Count */ ++#define MISC1_UV_RX_LIST1_CUR_DESC_L_ADDR 0x00000c8c /* UV Rx List1 Current Descriptor Lower Address */ ++#define MISC1_UV_RX_LIST1_CUR_DESC_U_ADDR 0x00000c90 /* UV Rx List1 Current Descriptor Upper Address */ ++#define MISC1_UV_RX_LIST1_CUR_BYTE_CNT 0x00000c94 /* UV Rx List1 Current Descriptor Byte Count */ ++#define MISC1_DMA_DEBUG_OPTIONS_REG 0x00000c98 /* DMA Debug Options Register */ ++#define MISC1_READ_CHANNEL_ERROR_STATUS 0x00000c9c /* Read Channel Error Status */ ++#define MISC1_PCIE_DMA_CTRL 0x00000ca0 /* PCIE DMA Control Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_MISC_TOP_MISC2 ++ ***************************************************************************/ ++#define MISC2_GLOBAL_CTRL 0x00000d00 /* Global Control Register */ ++#define MISC2_INTERNAL_STATUS 0x00000d04 /* Internal Status Register */ ++#define MISC2_INTERNAL_STATUS_MUX_CTRL 0x00000d08 /* Internal Debug Mux Control */ ++#define MISC2_DEBUG_FIFO_LENGTH 0x00000d0c /* Debug FIFO Length */ ++ ++ ++/**************************************************************************** ++ * BCM70012_MISC_TOP_MISC3 ++ ***************************************************************************/ ++#define MISC3_RESET_CTRL 0x00000e00 /* Reset Control Register */ ++#define MISC3_BIST_CTRL 0x00000e04 /* BIST Control Register */ ++#define MISC3_BIST_STATUS 0x00000e08 /* BIST Status Register */ ++#define MISC3_RX_CHECKSUM 0x00000e0c /* Receive Checksum */ ++#define MISC3_TX_CHECKSUM 0x00000e10 /* Transmit Checksum */ ++#define MISC3_ECO_CTRL_CORE 0x00000e14 /* ECO Core Reset Control Register */ ++#define MISC3_CSI_TEST_CTRL 0x00000e18 /* CSI Test Control Register */ ++#define MISC3_HD_DVI_TEST_CTRL 0x00000e1c /* HD DVI Test Control Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_MISC_TOP_MISC_PERST ++ ***************************************************************************/ ++#define MISC_PERST_ECO_CTRL_PERST 0x00000e80 /* ECO PCIE Reset Control Register */ ++#define MISC_PERST_DECODER_CTRL 0x00000e84 /* Decoder Control Register */ ++#define MISC_PERST_CCE_STATUS 0x00000e88 /* Config Copy Engine Status */ ++#define MISC_PERST_PCIE_DEBUG 0x00000e8c /* PCIE Debug Control Register */ ++#define MISC_PERST_PCIE_DEBUG_STATUS 0x00000e90 /* PCIE Debug Status Register */ ++#define MISC_PERST_VREG_CTRL 0x00000e94 /* Voltage Regulator Control Register */ ++#define MISC_PERST_MEM_CTRL 0x00000e98 /* Memory Control Register */ ++#define MISC_PERST_CLOCK_CTRL 0x00000e9c /* Clock Control Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_MISC_TOP_GISB_ARBITER ++ ***************************************************************************/ ++#define GISB_ARBITER_REVISION 0x00000f00 /* GISB ARBITER REVISION */ ++#define GISB_ARBITER_SCRATCH 0x00000f04 /* GISB ARBITER Scratch Register */ ++#define GISB_ARBITER_REQ_MASK 0x00000f08 /* GISB ARBITER Master Request Mask Register */ ++#define GISB_ARBITER_TIMER 0x00000f0c /* GISB ARBITER Timer Value Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_OTP_TOP_OTP ++ ***************************************************************************/ ++#define OTP_CONFIG_INFO 0x00001400 /* OTP Configuration Register */ ++#define OTP_CMD 0x00001404 /* OTP Command Register */ ++#define OTP_STATUS 0x00001408 /* OTP Status Register */ ++#define OTP_CONTENT_MISC 0x0000140c /* Content : Miscellaneous Register */ ++#define OTP_CONTENT_AES_0 0x00001410 /* Content : AES Key 0 Register */ ++#define OTP_CONTENT_AES_1 0x00001414 /* Content : AES Key 1 Register */ ++#define OTP_CONTENT_AES_2 0x00001418 /* Content : AES Key 2 Register */ ++#define OTP_CONTENT_AES_3 0x0000141c /* Content : AES Key 3 Register */ ++#define OTP_CONTENT_SHA_0 0x00001420 /* Content : SHA Key 0 Register */ ++#define OTP_CONTENT_SHA_1 0x00001424 /* Content : SHA Key 1 Register */ ++#define OTP_CONTENT_SHA_2 0x00001428 /* Content : SHA Key 2 Register */ ++#define OTP_CONTENT_SHA_3 0x0000142c /* Content : SHA Key 3 Register */ ++#define OTP_CONTENT_SHA_4 0x00001430 /* Content : SHA Key 4 Register */ ++#define OTP_CONTENT_SHA_5 0x00001434 /* Content : SHA Key 5 Register */ ++#define OTP_CONTENT_SHA_6 0x00001438 /* Content : SHA Key 6 Register */ ++#define OTP_CONTENT_SHA_7 0x0000143c /* Content : SHA Key 7 Register */ ++#define OTP_CONTENT_CHECKSUM 0x00001440 /* Content : Checksum Register */ ++#define OTP_PROG_CTRL 0x00001444 /* Programming Control Register */ ++#define OTP_PROG_STATUS 0x00001448 /* Programming Status Register */ ++#define OTP_PROG_PULSE 0x0000144c /* Program Pulse Width Register */ ++#define OTP_VERIFY_PULSE 0x00001450 /* Verify Pulse Width Register */ ++#define OTP_PROG_MASK 0x00001454 /* Program Mask Register */ ++#define OTP_DATA_INPUT 0x00001458 /* Data Input Register */ ++#define OTP_DATA_OUTPUT 0x0000145c /* Data Output Register */ ++ ++ ++/**************************************************************************** ++ * BCM70012_AES_TOP_AES ++ ***************************************************************************/ ++#define AES_CONFIG_INFO 0x00001800 /* AES Configuration Information Register */ ++#define AES_CMD 0x00001804 /* AES Command Register */ ++#define AES_STATUS 0x00001808 /* AES Status Register */ ++#define AES_EEPROM_CONFIG 0x0000180c /* AES EEPROM Configuration Register */ ++#define AES_EEPROM_DATA_0 0x00001810 /* AES EEPROM Data Register 0 */ ++#define AES_EEPROM_DATA_1 0x00001814 /* AES EEPROM Data Register 1 */ ++#define AES_EEPROM_DATA_2 0x00001818 /* AES EEPROM Data Register 2 */ ++#define AES_EEPROM_DATA_3 0x0000181c /* AES EEPROM Data Register 3 */ ++ ++ ++/**************************************************************************** ++ * BCM70012_DCI_TOP_DCI ++ ***************************************************************************/ ++#define DCI_CMD 0x00001c00 /* DCI Command Register */ ++#define DCI_STATUS 0x00001c04 /* DCI Status Register */ ++#define DCI_DRAM_BASE_ADDR 0x00001c08 /* DRAM Base Address Register */ ++#define DCI_FIRMWARE_ADDR 0x00001c0c /* Firmware Address Register */ ++#define DCI_FIRMWARE_DATA 0x00001c10 /* Firmware Data Register */ ++#define DCI_SIGNATURE_DATA_0 0x00001c14 /* Signature Data Register 0 */ ++#define DCI_SIGNATURE_DATA_1 0x00001c18 /* Signature Data Register 1 */ ++#define DCI_SIGNATURE_DATA_2 0x00001c1c /* Signature Data Register 2 */ ++#define DCI_SIGNATURE_DATA_3 0x00001c20 /* Signature Data Register 3 */ ++#define DCI_SIGNATURE_DATA_4 0x00001c24 /* Signature Data Register 4 */ ++#define DCI_SIGNATURE_DATA_5 0x00001c28 /* Signature Data Register 5 */ ++#define DCI_SIGNATURE_DATA_6 0x00001c2c /* Signature Data Register 6 */ ++#define DCI_SIGNATURE_DATA_7 0x00001c30 /* Signature Data Register 7 */ ++ ++ ++/**************************************************************************** ++ * BCM70012_TGT_TOP_INTR ++ ***************************************************************************/ ++/**************************************************************************** ++ * INTR :: INTR_STATUS ++ ***************************************************************************/ ++/* INTR :: INTR_STATUS :: reserved0 [31:26] */ ++#define INTR_INTR_STATUS_reserved0_MASK 0xfc000000 ++#define INTR_INTR_STATUS_reserved0_ALIGN 0 ++#define INTR_INTR_STATUS_reserved0_BITS 6 ++#define INTR_INTR_STATUS_reserved0_SHIFT 26 ++ ++/* INTR :: INTR_STATUS :: PCIE_TGT_CA_ATTN [25:25] */ ++#define INTR_INTR_STATUS_PCIE_TGT_CA_ATTN_MASK 0x02000000 ++#define INTR_INTR_STATUS_PCIE_TGT_CA_ATTN_ALIGN 0 ++#define INTR_INTR_STATUS_PCIE_TGT_CA_ATTN_BITS 1 ++#define INTR_INTR_STATUS_PCIE_TGT_CA_ATTN_SHIFT 25 ++ ++/* INTR :: INTR_STATUS :: PCIE_TGT_UR_ATTN [24:24] */ ++#define INTR_INTR_STATUS_PCIE_TGT_UR_ATTN_MASK 0x01000000 ++#define INTR_INTR_STATUS_PCIE_TGT_UR_ATTN_ALIGN 0 ++#define INTR_INTR_STATUS_PCIE_TGT_UR_ATTN_BITS 1 ++#define INTR_INTR_STATUS_PCIE_TGT_UR_ATTN_SHIFT 24 ++ ++/* INTR :: INTR_STATUS :: reserved1 [23:14] */ ++#define INTR_INTR_STATUS_reserved1_MASK 0x00ffc000 ++#define INTR_INTR_STATUS_reserved1_ALIGN 0 ++#define INTR_INTR_STATUS_reserved1_BITS 10 ++#define INTR_INTR_STATUS_reserved1_SHIFT 14 ++ ++/* INTR :: INTR_STATUS :: L1_UV_RX_DMA_ERR_INTR [13:13] */ ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_MASK 0x00002000 ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_BITS 1 ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_SHIFT 13 ++ ++/* INTR :: INTR_STATUS :: L1_UV_RX_DMA_DONE_INTR [12:12] */ ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_MASK 0x00001000 ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_BITS 1 ++#define INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_SHIFT 12 ++ ++/* INTR :: INTR_STATUS :: L1_Y_RX_DMA_ERR_INTR [11:11] */ ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_MASK 0x00000800 ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_BITS 1 ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_SHIFT 11 ++ ++/* INTR :: INTR_STATUS :: L1_Y_RX_DMA_DONE_INTR [10:10] */ ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_MASK 0x00000400 ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_BITS 1 ++#define INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_SHIFT 10 ++ ++/* INTR :: INTR_STATUS :: L1_TX_DMA_ERR_INTR [09:09] */ ++#define INTR_INTR_STATUS_L1_TX_DMA_ERR_INTR_MASK 0x00000200 ++#define INTR_INTR_STATUS_L1_TX_DMA_ERR_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L1_TX_DMA_ERR_INTR_BITS 1 ++#define INTR_INTR_STATUS_L1_TX_DMA_ERR_INTR_SHIFT 9 ++ ++/* INTR :: INTR_STATUS :: L1_TX_DMA_DONE_INTR [08:08] */ ++#define INTR_INTR_STATUS_L1_TX_DMA_DONE_INTR_MASK 0x00000100 ++#define INTR_INTR_STATUS_L1_TX_DMA_DONE_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L1_TX_DMA_DONE_INTR_BITS 1 ++#define INTR_INTR_STATUS_L1_TX_DMA_DONE_INTR_SHIFT 8 ++ ++/* INTR :: INTR_STATUS :: reserved2 [07:06] */ ++#define INTR_INTR_STATUS_reserved2_MASK 0x000000c0 ++#define INTR_INTR_STATUS_reserved2_ALIGN 0 ++#define INTR_INTR_STATUS_reserved2_BITS 2 ++#define INTR_INTR_STATUS_reserved2_SHIFT 6 ++ ++/* INTR :: INTR_STATUS :: L0_UV_RX_DMA_ERR_INTR [05:05] */ ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_MASK 0x00000020 ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_BITS 1 ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_SHIFT 5 ++ ++/* INTR :: INTR_STATUS :: L0_UV_RX_DMA_DONE_INTR [04:04] */ ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_MASK 0x00000010 ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_BITS 1 ++#define INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_SHIFT 4 ++ ++/* INTR :: INTR_STATUS :: L0_Y_RX_DMA_ERR_INTR [03:03] */ ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_MASK 0x00000008 ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_BITS 1 ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_SHIFT 3 ++ ++/* INTR :: INTR_STATUS :: L0_Y_RX_DMA_DONE_INTR [02:02] */ ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_MASK 0x00000004 ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_BITS 1 ++#define INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_SHIFT 2 ++ ++/* INTR :: INTR_STATUS :: L0_TX_DMA_ERR_INTR [01:01] */ ++#define INTR_INTR_STATUS_L0_TX_DMA_ERR_INTR_MASK 0x00000002 ++#define INTR_INTR_STATUS_L0_TX_DMA_ERR_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L0_TX_DMA_ERR_INTR_BITS 1 ++#define INTR_INTR_STATUS_L0_TX_DMA_ERR_INTR_SHIFT 1 ++ ++/* INTR :: INTR_STATUS :: L0_TX_DMA_DONE_INTR [00:00] */ ++#define INTR_INTR_STATUS_L0_TX_DMA_DONE_INTR_MASK 0x00000001 ++#define INTR_INTR_STATUS_L0_TX_DMA_DONE_INTR_ALIGN 0 ++#define INTR_INTR_STATUS_L0_TX_DMA_DONE_INTR_BITS 1 ++#define INTR_INTR_STATUS_L0_TX_DMA_DONE_INTR_SHIFT 0 ++ ++ ++/**************************************************************************** ++ * MISC1 :: TX_SW_DESC_LIST_CTRL_STS ++ ***************************************************************************/ ++/* MISC1 :: TX_SW_DESC_LIST_CTRL_STS :: reserved0 [31:04] */ ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_reserved0_MASK 0xfffffff0 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_reserved0_ALIGN 0 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_reserved0_BITS 28 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_reserved0_SHIFT 4 ++ ++/* MISC1 :: TX_SW_DESC_LIST_CTRL_STS :: DMA_DATA_SERV_PTR [03:03] */ ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DMA_DATA_SERV_PTR_MASK 0x00000008 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DMA_DATA_SERV_PTR_ALIGN 0 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DMA_DATA_SERV_PTR_BITS 1 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DMA_DATA_SERV_PTR_SHIFT 3 ++ ++/* MISC1 :: TX_SW_DESC_LIST_CTRL_STS :: DESC_SERV_PTR [02:02] */ ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DESC_SERV_PTR_MASK 0x00000004 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DESC_SERV_PTR_ALIGN 0 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DESC_SERV_PTR_BITS 1 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_DESC_SERV_PTR_SHIFT 2 ++ ++/* MISC1 :: TX_SW_DESC_LIST_CTRL_STS :: TX_DMA_HALT_ON_ERROR [01:01] */ ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_HALT_ON_ERROR_MASK 0x00000002 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_HALT_ON_ERROR_ALIGN 0 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_HALT_ON_ERROR_BITS 1 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_HALT_ON_ERROR_SHIFT 1 ++ ++/* MISC1 :: TX_SW_DESC_LIST_CTRL_STS :: TX_DMA_RUN_STOP [00:00] */ ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_MASK 0x00000001 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_ALIGN 0 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_BITS 1 ++#define MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_SHIFT 0 ++ ++ ++/**************************************************************************** ++ * MISC1 :: TX_DMA_ERROR_STATUS ++ ***************************************************************************/ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: reserved0 [31:10] */ ++#define MISC1_TX_DMA_ERROR_STATUS_reserved0_MASK 0xfffffc00 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved0_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved0_BITS 22 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved0_SHIFT 10 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: TX_L1_DESC_TX_ABORT_ERRORS [09:09] */ ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DESC_TX_ABORT_ERRORS_MASK 0x00000200 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DESC_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DESC_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DESC_TX_ABORT_ERRORS_SHIFT 9 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: reserved1 [08:08] */ ++#define MISC1_TX_DMA_ERROR_STATUS_reserved1_MASK 0x00000100 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved1_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved1_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved1_SHIFT 8 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: TX_L0_DESC_TX_ABORT_ERRORS [07:07] */ ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DESC_TX_ABORT_ERRORS_MASK 0x00000080 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DESC_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DESC_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DESC_TX_ABORT_ERRORS_SHIFT 7 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: reserved2 [06:06] */ ++#define MISC1_TX_DMA_ERROR_STATUS_reserved2_MASK 0x00000040 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved2_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved2_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved2_SHIFT 6 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: TX_L1_DMA_DATA_TX_ABORT_ERRORS [05:05] */ ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DMA_DATA_TX_ABORT_ERRORS_MASK 0x00000020 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DMA_DATA_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DMA_DATA_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_DMA_DATA_TX_ABORT_ERRORS_SHIFT 5 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: TX_L1_FIFO_FULL_ERRORS [04:04] */ ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_MASK 0x00000010 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_SHIFT 4 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: reserved3 [03:03] */ ++#define MISC1_TX_DMA_ERROR_STATUS_reserved3_MASK 0x00000008 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved3_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved3_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved3_SHIFT 3 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: TX_L0_DMA_DATA_TX_ABORT_ERRORS [02:02] */ ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DMA_DATA_TX_ABORT_ERRORS_MASK 0x00000004 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DMA_DATA_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DMA_DATA_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_DMA_DATA_TX_ABORT_ERRORS_SHIFT 2 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: TX_L0_FIFO_FULL_ERRORS [01:01] */ ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_MASK 0x00000002 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_SHIFT 1 ++ ++/* MISC1 :: TX_DMA_ERROR_STATUS :: reserved4 [00:00] */ ++#define MISC1_TX_DMA_ERROR_STATUS_reserved4_MASK 0x00000001 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved4_ALIGN 0 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved4_BITS 1 ++#define MISC1_TX_DMA_ERROR_STATUS_reserved4_SHIFT 0 ++ ++ ++/**************************************************************************** ++ * MISC1 :: Y_RX_ERROR_STATUS ++ ***************************************************************************/ ++/* MISC1 :: Y_RX_ERROR_STATUS :: reserved0 [31:14] */ ++#define MISC1_Y_RX_ERROR_STATUS_reserved0_MASK 0xffffc000 ++#define MISC1_Y_RX_ERROR_STATUS_reserved0_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_reserved0_BITS 18 ++#define MISC1_Y_RX_ERROR_STATUS_reserved0_SHIFT 14 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L1_UNDERRUN_ERROR [13:13] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK 0x00002000 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_SHIFT 13 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L1_OVERRUN_ERROR [12:12] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK 0x00001000 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_SHIFT 12 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L0_UNDERRUN_ERROR [11:11] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK 0x00000800 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_SHIFT 11 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L0_OVERRUN_ERROR [10:10] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK 0x00000400 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_SHIFT 10 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L1_DESC_TX_ABORT_ERRORS [09:09] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK 0x00000200 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_SHIFT 9 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: reserved1 [08:08] */ ++#define MISC1_Y_RX_ERROR_STATUS_reserved1_MASK 0x00000100 ++#define MISC1_Y_RX_ERROR_STATUS_reserved1_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_reserved1_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_reserved1_SHIFT 8 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L0_DESC_TX_ABORT_ERRORS [07:07] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK 0x00000080 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_SHIFT 7 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: reserved2 [06:05] */ ++#define MISC1_Y_RX_ERROR_STATUS_reserved2_MASK 0x00000060 ++#define MISC1_Y_RX_ERROR_STATUS_reserved2_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_reserved2_BITS 2 ++#define MISC1_Y_RX_ERROR_STATUS_reserved2_SHIFT 5 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L1_FIFO_FULL_ERRORS [04:04] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK 0x00000010 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_SHIFT 4 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: reserved3 [03:02] */ ++#define MISC1_Y_RX_ERROR_STATUS_reserved3_MASK 0x0000000c ++#define MISC1_Y_RX_ERROR_STATUS_reserved3_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_reserved3_BITS 2 ++#define MISC1_Y_RX_ERROR_STATUS_reserved3_SHIFT 2 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: RX_L0_FIFO_FULL_ERRORS [01:01] */ ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK 0x00000002 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_SHIFT 1 ++ ++/* MISC1 :: Y_RX_ERROR_STATUS :: reserved4 [00:00] */ ++#define MISC1_Y_RX_ERROR_STATUS_reserved4_MASK 0x00000001 ++#define MISC1_Y_RX_ERROR_STATUS_reserved4_ALIGN 0 ++#define MISC1_Y_RX_ERROR_STATUS_reserved4_BITS 1 ++#define MISC1_Y_RX_ERROR_STATUS_reserved4_SHIFT 0 ++ ++ ++/**************************************************************************** ++ * MISC1 :: UV_RX_ERROR_STATUS ++ ***************************************************************************/ ++/* MISC1 :: UV_RX_ERROR_STATUS :: reserved0 [31:14] */ ++#define MISC1_UV_RX_ERROR_STATUS_reserved0_MASK 0xffffc000 ++#define MISC1_UV_RX_ERROR_STATUS_reserved0_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_reserved0_BITS 18 ++#define MISC1_UV_RX_ERROR_STATUS_reserved0_SHIFT 14 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L1_UNDERRUN_ERROR [13:13] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK 0x00002000 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_SHIFT 13 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L1_OVERRUN_ERROR [12:12] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK 0x00001000 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_SHIFT 12 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L0_UNDERRUN_ERROR [11:11] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK 0x00000800 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_SHIFT 11 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L0_OVERRUN_ERROR [10:10] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK 0x00000400 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_SHIFT 10 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L1_DESC_TX_ABORT_ERRORS [09:09] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK 0x00000200 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_SHIFT 9 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: reserved1 [08:08] */ ++#define MISC1_UV_RX_ERROR_STATUS_reserved1_MASK 0x00000100 ++#define MISC1_UV_RX_ERROR_STATUS_reserved1_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_reserved1_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_reserved1_SHIFT 8 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L0_DESC_TX_ABORT_ERRORS [07:07] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK 0x00000080 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_SHIFT 7 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: reserved2 [06:05] */ ++#define MISC1_UV_RX_ERROR_STATUS_reserved2_MASK 0x00000060 ++#define MISC1_UV_RX_ERROR_STATUS_reserved2_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_reserved2_BITS 2 ++#define MISC1_UV_RX_ERROR_STATUS_reserved2_SHIFT 5 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L1_FIFO_FULL_ERRORS [04:04] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK 0x00000010 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_SHIFT 4 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: reserved3 [03:02] */ ++#define MISC1_UV_RX_ERROR_STATUS_reserved3_MASK 0x0000000c ++#define MISC1_UV_RX_ERROR_STATUS_reserved3_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_reserved3_BITS 2 ++#define MISC1_UV_RX_ERROR_STATUS_reserved3_SHIFT 2 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: RX_L0_FIFO_FULL_ERRORS [01:01] */ ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK 0x00000002 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_SHIFT 1 ++ ++/* MISC1 :: UV_RX_ERROR_STATUS :: reserved4 [00:00] */ ++#define MISC1_UV_RX_ERROR_STATUS_reserved4_MASK 0x00000001 ++#define MISC1_UV_RX_ERROR_STATUS_reserved4_ALIGN 0 ++#define MISC1_UV_RX_ERROR_STATUS_reserved4_BITS 1 ++#define MISC1_UV_RX_ERROR_STATUS_reserved4_SHIFT 0 ++ ++/**************************************************************************** ++ * Datatype Definitions. ++ ***************************************************************************/ ++#endif /* #ifndef MACFILE_H__ */ ++ ++/* End of File */ ++ +diff --git a/drivers/staging/crystalhd/crystalhd_cmds.c b/drivers/staging/crystalhd/crystalhd_cmds.c +new file mode 100644 +index 0000000..39c641d +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_cmds.c +@@ -0,0 +1,1058 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_cmds . c ++ * ++ * Description: ++ * BCM70010 Linux driver user command interfaces. ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#include "crystalhd_cmds.h" ++#include "crystalhd_hw.h" ++ ++static struct crystalhd_user *bc_cproc_get_uid(struct crystalhd_cmd *ctx) ++{ ++ struct crystalhd_user *user = NULL; ++ int i; ++ ++ for (i = 0; i < BC_LINK_MAX_OPENS; i++) { ++ if (!ctx->user[i].in_use) { ++ user = &ctx->user[i]; ++ break; ++ } ++ } ++ ++ return user; ++} ++ ++static int bc_cproc_get_user_count(struct crystalhd_cmd *ctx) ++{ ++ int i, count = 0; ++ ++ for (i = 0; i < BC_LINK_MAX_OPENS; i++) { ++ if (ctx->user[i].in_use) ++ count++; ++ } ++ ++ return count; ++} ++ ++static void bc_cproc_mark_pwr_state(struct crystalhd_cmd *ctx) ++{ ++ int i; ++ ++ for (i = 0; i < BC_LINK_MAX_OPENS; i++) { ++ if (!ctx->user[i].in_use) ++ continue; ++ if (ctx->user[i].mode == DTS_DIAG_MODE || ++ ctx->user[i].mode == DTS_PLAYBACK_MODE) { ++ ctx->pwr_state_change = 1; ++ break; ++ } ++ } ++} ++ ++static BC_STATUS bc_cproc_notify_mode(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ int rc = 0, i = 0; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (ctx->user[idata->u_id].mode != DTS_MODE_INV) { ++ BCMLOG_ERR("Close the handle first..\n"); ++ return BC_STS_ERR_USAGE; ++ } ++ if (idata->udata.u.NotifyMode.Mode == DTS_MONITOR_MODE) { ++ ctx->user[idata->u_id].mode = idata->udata.u.NotifyMode.Mode; ++ return BC_STS_SUCCESS; ++ } ++ if (ctx->state != BC_LINK_INVALID) { ++ BCMLOG_ERR("Link invalid state %d \n", ctx->state); ++ return BC_STS_ERR_USAGE; ++ } ++ /* Check for duplicate playback sessions..*/ ++ for (i = 0; i < BC_LINK_MAX_OPENS; i++) { ++ if (ctx->user[i].mode == DTS_DIAG_MODE || ++ ctx->user[i].mode == DTS_PLAYBACK_MODE) { ++ BCMLOG_ERR("multiple playback sessions are not " ++ "supported..\n"); ++ return BC_STS_ERR_USAGE; ++ } ++ } ++ ctx->cin_wait_exit = 0; ++ ctx->user[idata->u_id].mode = idata->udata.u.NotifyMode.Mode; ++ /* Setup mmap pool for uaddr sgl mapping..*/ ++ rc = crystalhd_create_dio_pool(ctx->adp, BC_LINK_MAX_SGLS); ++ if (rc) ++ return BC_STS_ERROR; ++ ++ /* Setup Hardware DMA rings */ ++ return crystalhd_hw_setup_dma_rings(&ctx->hw_ctx); ++} ++ ++static BC_STATUS bc_cproc_get_version(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ idata->udata.u.VerInfo.DriverMajor = crystalhd_kmod_major; ++ idata->udata.u.VerInfo.DriverMinor = crystalhd_kmod_minor; ++ idata->udata.u.VerInfo.DriverRevision = crystalhd_kmod_rev; ++ return BC_STS_SUCCESS; ++} ++ ++ ++static BC_STATUS bc_cproc_get_hwtype(struct crystalhd_cmd *ctx, crystalhd_ioctl_data *idata) ++{ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ crystalhd_pci_cfg_rd(ctx->adp, 0, 2, ++ (uint32_t *)&idata->udata.u.hwType.PciVenId); ++ crystalhd_pci_cfg_rd(ctx->adp, 2, 2, ++ (uint32_t *)&idata->udata.u.hwType.PciDevId); ++ crystalhd_pci_cfg_rd(ctx->adp, 8, 1, ++ (uint32_t *)&idata->udata.u.hwType.HwRev); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_reg_rd(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ if (!ctx || !idata) ++ return BC_STS_INV_ARG; ++ idata->udata.u.regAcc.Value = bc_dec_reg_rd(ctx->adp, ++ idata->udata.u.regAcc.Offset); ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_reg_wr(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ if (!ctx || !idata) ++ return BC_STS_INV_ARG; ++ ++ bc_dec_reg_wr(ctx->adp, idata->udata.u.regAcc.Offset, ++ idata->udata.u.regAcc.Value); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_link_reg_rd(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ if (!ctx || !idata) ++ return BC_STS_INV_ARG; ++ ++ idata->udata.u.regAcc.Value = crystalhd_reg_rd(ctx->adp, ++ idata->udata.u.regAcc.Offset); ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_link_reg_wr(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ if (!ctx || !idata) ++ return BC_STS_INV_ARG; ++ ++ crystalhd_reg_wr(ctx->adp, idata->udata.u.regAcc.Offset, ++ idata->udata.u.regAcc.Value); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_mem_rd(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata || !idata->add_cdata) ++ return BC_STS_INV_ARG; ++ ++ if (idata->udata.u.devMem.NumDwords > (idata->add_cdata_sz / 4)) { ++ BCMLOG_ERR("insufficient buffer\n"); ++ return BC_STS_INV_ARG; ++ } ++ sts = crystalhd_mem_rd(ctx->adp, idata->udata.u.devMem.StartOff, ++ idata->udata.u.devMem.NumDwords, ++ (uint32_t *)idata->add_cdata); ++ return sts; ++ ++} ++ ++static BC_STATUS bc_cproc_mem_wr(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata || !idata->add_cdata) ++ return BC_STS_INV_ARG; ++ ++ if (idata->udata.u.devMem.NumDwords > (idata->add_cdata_sz / 4)) { ++ BCMLOG_ERR("insufficient buffer\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ sts = crystalhd_mem_wr(ctx->adp, idata->udata.u.devMem.StartOff, ++ idata->udata.u.devMem.NumDwords, ++ (uint32_t *)idata->add_cdata); ++ return sts; ++} ++ ++static BC_STATUS bc_cproc_cfg_rd(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ uint32_t ix, cnt, off, len; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ uint32_t *temp; ++ ++ if (!ctx || !idata) ++ return BC_STS_INV_ARG; ++ ++ temp = (uint32_t *) idata->udata.u.pciCfg.pci_cfg_space; ++ off = idata->udata.u.pciCfg.Offset; ++ len = idata->udata.u.pciCfg.Size; ++ ++ if (len <= 4) ++ return crystalhd_pci_cfg_rd(ctx->adp, off, len, temp); ++ ++ /* Truncate to dword alignment..*/ ++ len = 4; ++ cnt = idata->udata.u.pciCfg.Size / len; ++ for (ix = 0; ix < cnt; ix++) { ++ sts = crystalhd_pci_cfg_rd(ctx->adp, off, len, &temp[ix]); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("config read : %d\n", sts); ++ return sts; ++ } ++ off += len; ++ } ++ ++ return sts; ++} ++ ++static BC_STATUS bc_cproc_cfg_wr(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ uint32_t ix, cnt, off, len; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ uint32_t *temp; ++ ++ if (!ctx || !idata) ++ return BC_STS_INV_ARG; ++ ++ temp = (uint32_t *) idata->udata.u.pciCfg.pci_cfg_space; ++ off = idata->udata.u.pciCfg.Offset; ++ len = idata->udata.u.pciCfg.Size; ++ ++ if (len <= 4) ++ return crystalhd_pci_cfg_wr(ctx->adp, off, len, temp[0]); ++ ++ /* Truncate to dword alignment..*/ ++ len = 4; ++ cnt = idata->udata.u.pciCfg.Size / len; ++ for (ix = 0; ix < cnt; ix++) { ++ sts = crystalhd_pci_cfg_wr(ctx->adp, off, len, temp[ix]); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("config write : %d\n", sts); ++ return sts; ++ } ++ off += len; ++ } ++ ++ return sts; ++} ++ ++static BC_STATUS bc_cproc_download_fw(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata || !idata->add_cdata || !idata->add_cdata_sz) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (ctx->state != BC_LINK_INVALID) { ++ BCMLOG_ERR("Link invalid state %d \n", ctx->state); ++ return BC_STS_ERR_USAGE; ++ } ++ ++ sts = crystalhd_download_fw(ctx->adp, (uint8_t *)idata->add_cdata, ++ idata->add_cdata_sz); ++ ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("Firmware Download Failure!! - %d\n", sts); ++ } else ++ ctx->state |= BC_LINK_INIT; ++ ++ return sts; ++} ++ ++/* ++ * We use the FW_CMD interface to sync up playback state with application ++ * and firmware. This function will perform the required pre and post ++ * processing of the Firmware commands. ++ * ++ * Pause - ++ * Disable capture after decoder pause. ++ * Resume - ++ * First enable capture and issue decoder resume command. ++ * Flush - ++ * Abort pending input transfers and issue decoder flush command. ++ * ++ */ ++static BC_STATUS bc_cproc_do_fw_cmd(struct crystalhd_cmd *ctx, crystalhd_ioctl_data *idata) ++{ ++ BC_STATUS sts; ++ uint32_t *cmd; ++ ++ if (!(ctx->state & BC_LINK_INIT)) { ++ BCMLOG_ERR("Link invalid state %d \n", ctx->state); ++ return BC_STS_ERR_USAGE; ++ } ++ ++ cmd = idata->udata.u.fwCmd.cmd; ++ ++ /* Pre-Process */ ++ if (cmd[0] == eCMD_C011_DEC_CHAN_PAUSE) { ++ if (!cmd[3]) { ++ ctx->state &= ~BC_LINK_PAUSED; ++ crystalhd_hw_unpause(&ctx->hw_ctx); ++ } ++ } else if (cmd[0] == eCMD_C011_DEC_CHAN_FLUSH) { ++ BCMLOG(BCMLOG_INFO, "Flush issued\n"); ++ if (cmd[3]) ++ ctx->cin_wait_exit = 1; ++ } ++ ++ sts = crystalhd_do_fw_cmd(&ctx->hw_ctx, &idata->udata.u.fwCmd); ++ ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG(BCMLOG_INFO, "fw cmd %x failed\n", cmd[0]); ++ return sts; ++ } ++ ++ /* Post-Process */ ++ if (cmd[0] == eCMD_C011_DEC_CHAN_PAUSE) { ++ if (cmd[3]) { ++ ctx->state |= BC_LINK_PAUSED; ++ crystalhd_hw_pause(&ctx->hw_ctx); ++ } ++ } ++ ++ return sts; ++} ++ ++static void bc_proc_in_completion(crystalhd_dio_req *dio_hnd, ++ wait_queue_head_t *event, BC_STATUS sts) ++{ ++ if (!dio_hnd || !event) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return; ++ } ++ if (sts == BC_STS_IO_USER_ABORT) ++ return; ++ ++ dio_hnd->uinfo.comp_sts = sts; ++ dio_hnd->uinfo.ev_sts = 1; ++ crystalhd_set_event(event); ++} ++ ++static BC_STATUS bc_cproc_codein_sleep(struct crystalhd_cmd *ctx) ++{ ++ wait_queue_head_t sleep_ev; ++ int rc = 0; ++ ++ if (ctx->state & BC_LINK_SUSPEND) ++ return BC_STS_IO_USER_ABORT; ++ ++ if (ctx->cin_wait_exit) { ++ ctx->cin_wait_exit = 0; ++ return BC_STS_CMD_CANCELLED; ++ } ++ crystalhd_create_event(&sleep_ev); ++ crystalhd_wait_on_event(&sleep_ev, 0, 100, rc, 0); ++ if (rc == -EINTR) ++ return BC_STS_IO_USER_ABORT; ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_hw_txdma(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata, ++ crystalhd_dio_req *dio) ++{ ++ uint32_t tx_listid = 0; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ wait_queue_head_t event; ++ int rc = 0; ++ ++ if (!ctx || !idata || !dio) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ crystalhd_create_event(&event); ++ ++ ctx->tx_list_id = 0; ++ /* msleep_interruptible(2000); */ ++ sts = crystalhd_hw_post_tx(&ctx->hw_ctx, dio, bc_proc_in_completion, ++ &event, &tx_listid, ++ idata->udata.u.ProcInput.Encrypted); ++ ++ while (sts == BC_STS_BUSY) { ++ sts = bc_cproc_codein_sleep(ctx); ++ if (sts != BC_STS_SUCCESS) ++ break; ++ sts = crystalhd_hw_post_tx(&ctx->hw_ctx, dio, ++ bc_proc_in_completion, ++ &event, &tx_listid, ++ idata->udata.u.ProcInput.Encrypted); ++ } ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG(BCMLOG_DBG, "_hw_txdma returning sts:%d\n", sts); ++ return sts; ++ } ++ if (ctx->cin_wait_exit) ++ ctx->cin_wait_exit = 0; ++ ++ ctx->tx_list_id = tx_listid; ++ ++ /* _post() succeeded.. wait for the completion. */ ++ crystalhd_wait_on_event(&event, (dio->uinfo.ev_sts), 3000, rc, 0); ++ ctx->tx_list_id = 0; ++ if (!rc) { ++ return dio->uinfo.comp_sts; ++ } else if (rc == -EBUSY) { ++ BCMLOG(BCMLOG_DBG, "_tx_post() T/O \n"); ++ sts = BC_STS_TIMEOUT; ++ } else if (rc == -EINTR) { ++ BCMLOG(BCMLOG_DBG, "Tx Wait Signal int.\n"); ++ sts = BC_STS_IO_USER_ABORT; ++ } else { ++ sts = BC_STS_IO_ERROR; ++ } ++ ++ /* We are cancelling the IO from the same context as the _post(). ++ * so no need to wait on the event again.. the return itself ++ * ensures the release of our resources. ++ */ ++ crystalhd_hw_cancel_tx(&ctx->hw_ctx, tx_listid); ++ ++ return sts; ++} ++ ++/* Helper function to check on user buffers */ ++static BC_STATUS bc_cproc_check_inbuffs(bool pin, void *ubuff, uint32_t ub_sz, ++ uint32_t uv_off, bool en_422) ++{ ++ if (!ubuff || !ub_sz) { ++ BCMLOG_ERR("%s->Invalid Arg %p %x\n", ++ ((pin) ? "TX" : "RX"), ubuff, ub_sz); ++ return BC_STS_INV_ARG; ++ } ++ ++ /* Check for alignment */ ++ if (((uintptr_t)ubuff) & 0x03) { ++ BCMLOG_ERR("%s-->Un-aligned address not implemented yet.. %p \n", ++ ((pin) ? "TX" : "RX"), ubuff); ++ return BC_STS_NOT_IMPL; ++ } ++ if (pin) ++ return BC_STS_SUCCESS; ++ ++ if (!en_422 && !uv_off) { ++ BCMLOG_ERR("Need UV offset for 420 mode.\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (en_422 && uv_off) { ++ BCMLOG_ERR("UV offset in 422 mode ??\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_proc_input(struct crystalhd_cmd *ctx, crystalhd_ioctl_data *idata) ++{ ++ void *ubuff; ++ uint32_t ub_sz; ++ crystalhd_dio_req *dio_hnd = NULL; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ ubuff = idata->udata.u.ProcInput.pDmaBuff; ++ ub_sz = idata->udata.u.ProcInput.BuffSz; ++ ++ sts = bc_cproc_check_inbuffs(1, ubuff, ub_sz, 0, 0); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ ++ sts = crystalhd_map_dio(ctx->adp, ubuff, ub_sz, 0, 0, 1, &dio_hnd); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("dio map - %d \n", sts); ++ return sts; ++ } ++ ++ if (!dio_hnd) ++ return BC_STS_ERROR; ++ ++ sts = bc_cproc_hw_txdma(ctx, idata, dio_hnd); ++ ++ crystalhd_unmap_dio(ctx->adp, dio_hnd); ++ ++ return sts; ++} ++ ++static BC_STATUS bc_cproc_add_cap_buff(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ void *ubuff; ++ uint32_t ub_sz, uv_off; ++ bool en_422; ++ crystalhd_dio_req *dio_hnd = NULL; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ ubuff = idata->udata.u.RxBuffs.YuvBuff; ++ ub_sz = idata->udata.u.RxBuffs.YuvBuffSz; ++ uv_off = idata->udata.u.RxBuffs.UVbuffOffset; ++ en_422 = idata->udata.u.RxBuffs.b422Mode; ++ ++ sts = bc_cproc_check_inbuffs(0, ubuff, ub_sz, uv_off, en_422); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ ++ sts = crystalhd_map_dio(ctx->adp, ubuff, ub_sz, uv_off, ++ en_422, 0, &dio_hnd); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("dio map - %d \n", sts); ++ return sts; ++ } ++ ++ if (!dio_hnd) ++ return BC_STS_ERROR; ++ ++ sts = crystalhd_hw_add_cap_buffer(&ctx->hw_ctx, dio_hnd, (ctx->state == BC_LINK_READY)); ++ if ((sts != BC_STS_SUCCESS) && (sts != BC_STS_BUSY)) { ++ crystalhd_unmap_dio(ctx->adp, dio_hnd); ++ return sts; ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_fmt_change(struct crystalhd_cmd *ctx, ++ crystalhd_dio_req *dio) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ sts = crystalhd_hw_add_cap_buffer(&ctx->hw_ctx, dio, 0); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ ++ ctx->state |= BC_LINK_FMT_CHG; ++ if (ctx->state == BC_LINK_READY) ++ sts = crystalhd_hw_start_capture(&ctx->hw_ctx); ++ ++ return sts; ++} ++ ++static BC_STATUS bc_cproc_fetch_frame(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ crystalhd_dio_req *dio = NULL; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ BC_DEC_OUT_BUFF *frame; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (!(ctx->state & BC_LINK_CAP_EN)) { ++ BCMLOG(BCMLOG_DBG, "Capture not enabled..%x\n", ctx->state); ++ return BC_STS_ERR_USAGE; ++ } ++ ++ frame = &idata->udata.u.DecOutData; ++ ++ sts = crystalhd_hw_get_cap_buffer(&ctx->hw_ctx, &frame->PibInfo, &dio); ++ if (sts != BC_STS_SUCCESS) ++ return (ctx->state & BC_LINK_SUSPEND) ? BC_STS_IO_USER_ABORT : sts; ++ ++ frame->Flags = dio->uinfo.comp_flags; ++ ++ if (frame->Flags & COMP_FLAG_FMT_CHANGE) ++ return bc_cproc_fmt_change(ctx, dio); ++ ++ frame->OutPutBuffs.YuvBuff = dio->uinfo.xfr_buff; ++ frame->OutPutBuffs.YuvBuffSz = dio->uinfo.xfr_len; ++ frame->OutPutBuffs.UVbuffOffset = dio->uinfo.uv_offset; ++ frame->OutPutBuffs.b422Mode = dio->uinfo.b422mode; ++ ++ frame->OutPutBuffs.YBuffDoneSz = dio->uinfo.y_done_sz; ++ frame->OutPutBuffs.UVBuffDoneSz = dio->uinfo.uv_done_sz; ++ ++ crystalhd_unmap_dio(ctx->adp, dio); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_start_capture(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ ctx->state |= BC_LINK_CAP_EN; ++ if (ctx->state == BC_LINK_READY) ++ return crystalhd_hw_start_capture(&ctx->hw_ctx); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_flush_cap_buffs(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ crystalhd_dio_req *dio = NULL; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ BC_DEC_OUT_BUFF *frame; ++ uint32_t count; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (!(ctx->state & BC_LINK_CAP_EN)) ++ return BC_STS_ERR_USAGE; ++ ++ /* We should ack flush even when we are in paused/suspend state */ ++ if (!(ctx->state & BC_LINK_READY)) ++ return crystalhd_hw_stop_capture(&ctx->hw_ctx); ++ ++ ctx->state &= ~(BC_LINK_CAP_EN|BC_LINK_FMT_CHG); ++ ++ frame = &idata->udata.u.DecOutData; ++ for (count = 0; count < BC_RX_LIST_CNT; count++) { ++ ++ sts = crystalhd_hw_get_cap_buffer(&ctx->hw_ctx, &frame->PibInfo, &dio); ++ if (sts != BC_STS_SUCCESS) ++ break; ++ ++ crystalhd_unmap_dio(ctx->adp, dio); ++ } ++ ++ return crystalhd_hw_stop_capture(&ctx->hw_ctx); ++} ++ ++static BC_STATUS bc_cproc_get_stats(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ BC_DTS_STATS *stats; ++ struct crystalhd_hw_stats hw_stats; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ crystalhd_hw_stats(&ctx->hw_ctx, &hw_stats); ++ ++ stats = &idata->udata.u.drvStat; ++ stats->drvRLL = hw_stats.rdyq_count; ++ stats->drvFLL = hw_stats.freeq_count; ++ stats->DrvTotalFrmDropped = hw_stats.rx_errors; ++ stats->DrvTotalHWErrs = hw_stats.rx_errors + hw_stats.tx_errors; ++ stats->intCount = hw_stats.num_interrupts; ++ stats->DrvIgnIntrCnt = hw_stats.num_interrupts - ++ hw_stats.dev_interrupts; ++ stats->TxFifoBsyCnt = hw_stats.cin_busy; ++ stats->pauseCount = hw_stats.pause_cnt; ++ ++ if (ctx->pwr_state_change) ++ stats->pwr_state_change = 1; ++ if (ctx->state & BC_LINK_PAUSED) ++ stats->DrvPauseTime = 1; ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_reset_stats(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ crystalhd_hw_stats(&ctx->hw_ctx, NULL); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS bc_cproc_chg_clk(struct crystalhd_cmd *ctx, ++ crystalhd_ioctl_data *idata) ++{ ++ BC_CLOCK *clock; ++ uint32_t oldClk; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ clock = &idata->udata.u.clockValue; ++ oldClk = ctx->hw_ctx.core_clock_mhz; ++ ctx->hw_ctx.core_clock_mhz = clock->clk; ++ ++ if (ctx->state & BC_LINK_READY) { ++ sts = crystalhd_hw_set_core_clock(&ctx->hw_ctx); ++ if (sts == BC_STS_CLK_NOCHG) ++ ctx->hw_ctx.core_clock_mhz = oldClk; ++ } ++ ++ clock->clk = ctx->hw_ctx.core_clock_mhz; ++ ++ return sts; ++} ++ ++/*=============== Cmd Proc Table.. ======================================*/ ++static const crystalhd_cmd_tbl_t g_crystalhd_cproc_tbl[] = { ++ { BCM_IOC_GET_VERSION, bc_cproc_get_version, 0}, ++ { BCM_IOC_GET_HWTYPE, bc_cproc_get_hwtype, 0}, ++ { BCM_IOC_REG_RD, bc_cproc_reg_rd, 0}, ++ { BCM_IOC_REG_WR, bc_cproc_reg_wr, 0}, ++ { BCM_IOC_FPGA_RD, bc_cproc_link_reg_rd, 0}, ++ { BCM_IOC_FPGA_WR, bc_cproc_link_reg_wr, 0}, ++ { BCM_IOC_MEM_RD, bc_cproc_mem_rd, 0}, ++ { BCM_IOC_MEM_WR, bc_cproc_mem_wr, 0}, ++ { BCM_IOC_RD_PCI_CFG, bc_cproc_cfg_rd, 0}, ++ { BCM_IOC_WR_PCI_CFG, bc_cproc_cfg_wr, 1}, ++ { BCM_IOC_FW_DOWNLOAD, bc_cproc_download_fw, 1}, ++ { BCM_IOC_FW_CMD, bc_cproc_do_fw_cmd, 1}, ++ { BCM_IOC_PROC_INPUT, bc_cproc_proc_input, 1}, ++ { BCM_IOC_ADD_RXBUFFS, bc_cproc_add_cap_buff, 1}, ++ { BCM_IOC_FETCH_RXBUFF, bc_cproc_fetch_frame, 1}, ++ { BCM_IOC_START_RX_CAP, bc_cproc_start_capture, 1}, ++ { BCM_IOC_FLUSH_RX_CAP, bc_cproc_flush_cap_buffs, 1}, ++ { BCM_IOC_GET_DRV_STAT, bc_cproc_get_stats, 0}, ++ { BCM_IOC_RST_DRV_STAT, bc_cproc_reset_stats, 0}, ++ { BCM_IOC_NOTIFY_MODE, bc_cproc_notify_mode, 0}, ++ { BCM_IOC_CHG_CLK, bc_cproc_chg_clk, 0}, ++ { BCM_IOC_END, NULL}, ++}; ++ ++/*=============== Cmd Proc Functions.. ===================================*/ ++ ++/** ++ * crystalhd_suspend - Power management suspend request. ++ * @ctx: Command layer context. ++ * @idata: Iodata - required for internal use. ++ * ++ * Return: ++ * status ++ * ++ * 1. Set the state to Suspend. ++ * 2. Flush the Rx Buffers it will unmap all the buffers and ++ * stop the RxDMA engine. ++ * 3. Cancel The TX Io and Stop Dma Engine. ++ * 4. Put the DDR in to deep sleep. ++ * 5. Stop the hardware putting it in to Reset State. ++ * ++ * Current gstreamer frame work does not provide any power management ++ * related notification to user mode decoder plug-in. As a work-around ++ * we pass on the power mangement notification to our plug-in by completing ++ * all outstanding requests with BC_STS_IO_USER_ABORT return code. ++ */ ++BC_STATUS crystalhd_suspend(struct crystalhd_cmd *ctx, crystalhd_ioctl_data *idata) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!ctx || !idata) { ++ BCMLOG_ERR("Invalid Parameters\n"); ++ return BC_STS_ERROR; ++ } ++ ++ if (ctx->state & BC_LINK_SUSPEND) ++ return BC_STS_SUCCESS; ++ ++ if (ctx->state == BC_LINK_INVALID) { ++ BCMLOG(BCMLOG_DBG, "Nothing To Do Suspend Success\n"); ++ return BC_STS_SUCCESS; ++ } ++ ++ ctx->state |= BC_LINK_SUSPEND; ++ ++ bc_cproc_mark_pwr_state(ctx); ++ ++ if (ctx->state & BC_LINK_CAP_EN) { ++ sts = bc_cproc_flush_cap_buffs(ctx, idata); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ } ++ ++ if (ctx->tx_list_id) { ++ sts = crystalhd_hw_cancel_tx(&ctx->hw_ctx, ctx->tx_list_id); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ } ++ ++ sts = crystalhd_hw_suspend(&ctx->hw_ctx); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ ++ BCMLOG(BCMLOG_DBG, "BCM70012 suspend success\n"); ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_resume - Resume frame capture. ++ * @ctx: Command layer contextx. ++ * ++ * Return: ++ * status ++ * ++ * ++ * Resume frame capture. ++ * ++ * PM_Resume can't resume the playback state back to pre-suspend state ++ * because we don't keep video clip related information within driver. ++ * To get back to the pre-suspend state App will re-open the device and ++ * start a new playback session from the pre-suspend clip position. ++ * ++ */ ++BC_STATUS crystalhd_resume(struct crystalhd_cmd *ctx) ++{ ++ BCMLOG(BCMLOG_DBG, "crystalhd_resume Success %x\n", ctx->state); ++ ++ bc_cproc_mark_pwr_state(ctx); ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_user_open - Create application handle. ++ * @ctx: Command layer contextx. ++ * @user_ctx: User ID context. ++ * ++ * Return: ++ * status ++ * ++ * Creates an application specific UID and allocates ++ * application specific resources. HW layer initialization ++ * is done for the first open request. ++ */ ++BC_STATUS crystalhd_user_open(struct crystalhd_cmd *ctx, ++ struct crystalhd_user **user_ctx) ++{ ++ struct crystalhd_user *uc; ++ ++ if (!ctx || !user_ctx) { ++ BCMLOG_ERR("Invalid arg..\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ uc = bc_cproc_get_uid(ctx); ++ if (!uc) { ++ BCMLOG(BCMLOG_INFO, "No free user context...\n"); ++ return BC_STS_BUSY; ++ } ++ ++ BCMLOG(BCMLOG_INFO, "Opening new user[%x] handle\n", uc->uid); ++ ++ crystalhd_hw_open(&ctx->hw_ctx, ctx->adp); ++ ++ uc->in_use = 1; ++ ++ *user_ctx = uc; ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_user_close - Close application handle. ++ * @ctx: Command layer contextx. ++ * @uc: User ID context. ++ * ++ * Return: ++ * status ++ * ++ * Closer aplication handle and release app specific ++ * resources. ++ */ ++BC_STATUS crystalhd_user_close(struct crystalhd_cmd *ctx, struct crystalhd_user *uc) ++{ ++ uint32_t mode = uc->mode; ++ ++ ctx->user[uc->uid].mode = DTS_MODE_INV; ++ ctx->user[uc->uid].in_use = 0; ++ ctx->cin_wait_exit = 1; ++ ctx->pwr_state_change = 0; ++ ++ BCMLOG(BCMLOG_INFO, "Closing user[%x] handle\n", uc->uid); ++ ++ if ((mode == DTS_DIAG_MODE) || (mode == DTS_PLAYBACK_MODE)) { ++ crystalhd_hw_free_dma_rings(&ctx->hw_ctx); ++ crystalhd_destroy_dio_pool(ctx->adp); ++ } else if (bc_cproc_get_user_count(ctx)) { ++ return BC_STS_SUCCESS; ++ } ++ ++ crystalhd_hw_close(&ctx->hw_ctx); ++ ++ ctx->state = BC_LINK_INVALID; ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_setup_cmd_context - Setup Command layer resources. ++ * @ctx: Command layer contextx. ++ * @adp: Adapter context ++ * ++ * Return: ++ * status ++ * ++ * Called at the time of driver load. ++ */ ++BC_STATUS crystalhd_setup_cmd_context(struct crystalhd_cmd *ctx, ++ struct crystalhd_adp *adp) ++{ ++ int i = 0; ++ ++ if (!ctx || !adp) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (ctx->adp) ++ BCMLOG(BCMLOG_DBG, "Resetting Cmd context delete missing..\n"); ++ ++ ctx->adp = adp; ++ for (i = 0; i < BC_LINK_MAX_OPENS; i++) { ++ ctx->user[i].uid = i; ++ ctx->user[i].in_use = 0; ++ ctx->user[i].mode = DTS_MODE_INV; ++ } ++ ++ /*Open and Close the Hardware to put it in to sleep state*/ ++ crystalhd_hw_open(&ctx->hw_ctx, ctx->adp); ++ crystalhd_hw_close(&ctx->hw_ctx); ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_delete_cmd_context - Release Command layer resources. ++ * @ctx: Command layer contextx. ++ * ++ * Return: ++ * status ++ * ++ * Called at the time of driver un-load. ++ */ ++BC_STATUS crystalhd_delete_cmd_context(struct crystalhd_cmd *ctx) ++{ ++ BCMLOG(BCMLOG_DBG, "Deleting Command context..\n"); ++ ++ ctx->adp = NULL; ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_get_cmd_proc - Cproc table lookup. ++ * @ctx: Command layer contextx. ++ * @cmd: IOCTL command code. ++ * @uc: User ID context. ++ * ++ * Return: ++ * command proc function pointer ++ * ++ * This function checks the process context, application's ++ * mode of operation and returns the function pointer ++ * from the cproc table. ++ */ ++crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, uint32_t cmd, ++ struct crystalhd_user *uc) ++{ ++ crystalhd_cmd_proc cproc = NULL; ++ unsigned int i, tbl_sz; ++ ++ if (!ctx) { ++ BCMLOG_ERR("Invalid arg.. Cmd[%d]\n", cmd); ++ return NULL; ++ } ++ ++ if ((cmd != BCM_IOC_GET_DRV_STAT) && (ctx->state & BC_LINK_SUSPEND)) { ++ BCMLOG_ERR("Invalid State [suspend Set].. Cmd[%d]\n", cmd); ++ return NULL; ++ } ++ ++ tbl_sz = sizeof(g_crystalhd_cproc_tbl) / sizeof(crystalhd_cmd_tbl_t); ++ for (i = 0; i < tbl_sz; i++) { ++ if (g_crystalhd_cproc_tbl[i].cmd_id == cmd) { ++ if ((uc->mode == DTS_MONITOR_MODE) && ++ (g_crystalhd_cproc_tbl[i].block_mon)) { ++ BCMLOG(BCMLOG_INFO, "Blocking cmd %d \n", cmd); ++ break; ++ } ++ cproc = g_crystalhd_cproc_tbl[i].cmd_proc; ++ break; ++ } ++ } ++ ++ return cproc; ++} ++ ++/** ++ * crystalhd_cmd_interrupt - ISR entry point ++ * @ctx: Command layer contextx. ++ * ++ * Return: ++ * TRUE: If interrupt from bcm70012 device. ++ * ++ * ++ * ISR entry point from OS layer. ++ */ ++bool crystalhd_cmd_interrupt(struct crystalhd_cmd *ctx) ++{ ++ if (!ctx) { ++ BCMLOG_ERR("Invalid arg..\n"); ++ return 0; ++ } ++ ++ return crystalhd_hw_interrupt(ctx->adp, &ctx->hw_ctx); ++} +diff --git a/drivers/staging/crystalhd/crystalhd_cmds.h b/drivers/staging/crystalhd/crystalhd_cmds.h +new file mode 100644 +index 0000000..6b290ae +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_cmds.h +@@ -0,0 +1,88 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_cmds . h ++ * ++ * Description: ++ * BCM70010 Linux driver user command interfaces. ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#ifndef _CRYSTALHD_CMDS_H_ ++#define _CRYSTALHD_CMDS_H_ ++ ++/* ++ * NOTE:: This is the main interface file between the Linux layer ++ * and the harware layer. This file will use the definitions ++ * from _dts_glob and dts_defs etc.. which are defined for ++ * windows. ++ */ ++#include "crystalhd_misc.h" ++#include "crystalhd_hw.h" ++ ++enum _crystalhd_state{ ++ BC_LINK_INVALID = 0x00, ++ BC_LINK_INIT = 0x01, ++ BC_LINK_CAP_EN = 0x02, ++ BC_LINK_FMT_CHG = 0x04, ++ BC_LINK_SUSPEND = 0x10, ++ BC_LINK_PAUSED = 0x20, ++ BC_LINK_READY = (BC_LINK_INIT | BC_LINK_CAP_EN | BC_LINK_FMT_CHG), ++}; ++ ++struct crystalhd_user { ++ uint32_t uid; ++ uint32_t in_use; ++ uint32_t mode; ++}; ++ ++#define DTS_MODE_INV (-1) ++ ++struct crystalhd_cmd { ++ uint32_t state; ++ struct crystalhd_adp *adp; ++ struct crystalhd_user user[BC_LINK_MAX_OPENS]; ++ ++ spinlock_t ctx_lock; ++ uint32_t tx_list_id; ++ uint32_t cin_wait_exit; ++ uint32_t pwr_state_change; ++ struct crystalhd_hw hw_ctx; ++}; ++ ++typedef BC_STATUS (*crystalhd_cmd_proc)(struct crystalhd_cmd *, crystalhd_ioctl_data *); ++ ++typedef struct _crystalhd_cmd_tbl { ++ uint32_t cmd_id; ++ const crystalhd_cmd_proc cmd_proc; ++ uint32_t block_mon; ++} crystalhd_cmd_tbl_t; ++ ++ ++BC_STATUS crystalhd_suspend(struct crystalhd_cmd *ctx, crystalhd_ioctl_data *idata); ++BC_STATUS crystalhd_resume(struct crystalhd_cmd *ctx); ++crystalhd_cmd_proc crystalhd_get_cmd_proc(struct crystalhd_cmd *ctx, uint32_t cmd, ++ struct crystalhd_user *uc); ++BC_STATUS crystalhd_user_open(struct crystalhd_cmd *ctx, struct crystalhd_user **user_ctx); ++BC_STATUS crystalhd_user_close(struct crystalhd_cmd *ctx, struct crystalhd_user *uc); ++BC_STATUS crystalhd_setup_cmd_context(struct crystalhd_cmd *ctx, struct crystalhd_adp *adp); ++BC_STATUS crystalhd_delete_cmd_context(struct crystalhd_cmd *ctx); ++bool crystalhd_cmd_interrupt(struct crystalhd_cmd *ctx); ++ ++#endif +diff --git a/drivers/staging/crystalhd/crystalhd_fw_if.h b/drivers/staging/crystalhd/crystalhd_fw_if.h +new file mode 100644 +index 0000000..261cd19 +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_fw_if.h +@@ -0,0 +1,369 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_fw_if . h ++ * ++ * Description: ++ * BCM70012 Firmware interface definitions. ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#ifndef _CRYSTALHD_FW_IF_H_ ++#define _CRYSTALHD_FW_IF_H_ ++ ++/* TBD: Pull in only required defs into this file.. */ ++ ++ ++ ++/* User Data Header */ ++typedef struct user_data { ++ struct user_data *next; ++ uint32_t type; ++ uint32_t size; ++} UD_HDR; ++ ++ ++ ++/*------------------------------------------------------* ++ * MPEG Extension to the PPB * ++ *------------------------------------------------------*/ ++typedef struct { ++ uint32_t to_be_defined; ++ uint32_t valid; ++ ++ /* Always valid, defaults to picture size if no ++ sequence display extension in the stream. */ ++ uint32_t display_horizontal_size; ++ uint32_t display_vertical_size; ++ ++ /* MPEG_VALID_PANSCAN ++ Offsets are a copy values from the MPEG stream. */ ++ uint32_t offset_count; ++ int32_t horizontal_offset[3]; ++ int32_t vertical_offset[3]; ++ ++ /* MPEG_VALID_USERDATA ++ User data is in the form of a linked list. */ ++ int32_t userDataSize; ++ UD_HDR *userData; ++ ++} PPB_MPEG; ++ ++ ++/*------------------------------------------------------* ++ * VC1 Extension to the PPB * ++ *------------------------------------------------------*/ ++typedef struct { ++ uint32_t to_be_defined; ++ uint32_t valid; ++ ++ /* Always valid, defaults to picture size if no ++ sequence display extension in the stream. */ ++ uint32_t display_horizontal_size; ++ uint32_t display_vertical_size; ++ ++ /* VC1 pan scan windows */ ++ uint32_t num_panscan_windows; ++ int32_t ps_horiz_offset[4]; ++ int32_t ps_vert_offset[4]; ++ int32_t ps_width[4]; ++ int32_t ps_height[4]; ++ ++ /* VC1_VALID_USERDATA ++ User data is in the form of a linked list. */ ++ int32_t userDataSize; ++ UD_HDR *userData; ++ ++} PPB_VC1; ++ ++/*------------------------------------------------------* ++ * H.264 Extension to the PPB * ++ *------------------------------------------------------*/ ++ ++/** ++ * @brief Film grain SEI message. ++ * ++ * Content of the film grain SEI message. ++ */ ++ ++/* maximum number of model-values as for Thomson spec(standard says 5) */ ++#define MAX_FGT_MODEL_VALUE (3) ++ ++/* maximum number of intervals(as many as 256 intervals?) */ ++#define MAX_FGT_VALUE_INTERVAL (256) ++ ++typedef struct FGT_SEI { ++ struct FGT_SEI *next; ++ unsigned char model_values[3][MAX_FGT_VALUE_INTERVAL][MAX_FGT_MODEL_VALUE]; ++ unsigned char upper_bound[3][MAX_FGT_VALUE_INTERVAL]; ++ unsigned char lower_bound[3][MAX_FGT_VALUE_INTERVAL]; ++ ++ unsigned char cancel_flag; /* Cancel flag: 1 no film grain. */ ++ unsigned char model_id; /* Model id. */ ++ ++ /* +unused SE based on Thomson spec */ ++ unsigned char color_desc_flag; /* Separate color descrition flag. */ ++ unsigned char bit_depth_luma; /* Bit depth luma minus 8. */ ++ unsigned char bit_depth_chroma; /* Bit depth chroma minus 8. */ ++ unsigned char full_range_flag; /* Full range flag. */ ++ unsigned char color_primaries; /* Color primaries. */ ++ unsigned char transfer_charact; /* Transfer characteristics. */ ++ unsigned char matrix_coeff; /*< Matrix coefficients. */ ++ /* -unused SE based on Thomson spec */ ++ ++ unsigned char blending_mode_id; /* Blending mode. */ ++ unsigned char log2_scale_factor; /* Log2 scale factor (2-7). */ ++ unsigned char comp_flag[3]; /* Components [0,2] parameters present flag. */ ++ unsigned char num_intervals_minus1[3]; /* Number of intensity level intervals. */ ++ unsigned char num_model_values[3]; /* Number of model values. */ ++ uint16_t repetition_period; /* Repetition period (0-16384) */ ++ ++} FGT_SEI; ++ ++typedef struct { ++ /* 'valid' specifies which fields (or sets of ++ * fields) below are valid. If the corresponding ++ * bit in 'valid' is NOT set then that field(s) ++ * is (are) not initialized. */ ++ uint32_t valid; ++ ++ int32_t poc_top; /* POC for Top Field/Frame */ ++ int32_t poc_bottom; /* POC for Bottom Field */ ++ uint32_t idr_pic_id; ++ ++ /* H264_VALID_PANSCAN */ ++ uint32_t pan_scan_count; ++ int32_t pan_scan_left[3]; ++ int32_t pan_scan_right[3]; ++ int32_t pan_scan_top[3]; ++ int32_t pan_scan_bottom[3]; ++ ++ /* H264_VALID_CT_TYPE */ ++ uint32_t ct_type_count; ++ uint32_t ct_type[3]; ++ ++ /* H264_VALID_SPS_CROP */ ++ int32_t sps_crop_left; ++ int32_t sps_crop_right; ++ int32_t sps_crop_top; ++ int32_t sps_crop_bottom; ++ ++ /* H264_VALID_VUI */ ++ uint32_t chroma_top; ++ uint32_t chroma_bottom; ++ ++ /* H264_VALID_USER */ ++ uint32_t user_data_size; ++ UD_HDR *user_data; ++ ++ /* H264 VALID FGT */ ++ FGT_SEI *pfgt; ++ ++} PPB_H264; ++ ++typedef struct { ++ /* Common fields. */ ++ uint32_t picture_number; /* Ordinal display number */ ++ uint32_t video_buffer; /* Video (picbuf) number */ ++ uint32_t video_address; /* Address of picbuf Y */ ++ uint32_t video_address_uv; /* Address of picbuf UV */ ++ uint32_t video_stripe; /* Picbuf stripe */ ++ uint32_t video_width; /* Picbuf width */ ++ uint32_t video_height; /* Picbuf height */ ++ ++ uint32_t channel_id; /* Decoder channel ID */ ++ uint32_t status; /* reserved */ ++ uint32_t width; /* pixels */ ++ uint32_t height; /* pixels */ ++ uint32_t chroma_format; /* see above */ ++ uint32_t pulldown; /* see above */ ++ uint32_t flags; /* see above */ ++ uint32_t pts; /* 32 LSBs of PTS */ ++ uint32_t protocol; /* protocolXXX (above) */ ++ ++ uint32_t frame_rate; /* see above */ ++ uint32_t matrix_coeff; /* see above */ ++ uint32_t aspect_ratio; /* see above */ ++ uint32_t colour_primaries; /* see above */ ++ uint32_t transfer_char; /* see above */ ++ uint32_t pcr_offset; /* 45kHz if PCR type; else 27MHz */ ++ uint32_t n_drop; /* Number of pictures to be dropped */ ++ ++ uint32_t custom_aspect_ratio_width_height; ++ /* upper 16-bits is Y and lower 16-bits is X */ ++ ++ uint32_t picture_tag; /* Indexing tag from BUD packets */ ++ uint32_t picture_done_payload; ++ uint32_t picture_meta_payload; ++ uint32_t reserved[1]; ++ ++ /* Protocol-specific extensions. */ ++ union { ++ PPB_H264 h264; ++ PPB_MPEG mpeg; ++ PPB_VC1 vc1; ++ } other; ++ ++} PPB; ++ ++typedef struct { ++ uint32_t bFormatChange; ++ uint32_t resolution; ++ uint32_t channelId; ++ uint32_t ppbPtr; ++ int32_t ptsStcOffset; ++ uint32_t zeroPanscanValid; ++ uint32_t dramOutBufAddr; ++ uint32_t yComponent; ++ PPB ppb; ++ ++} C011_PIB; ++ ++ ++ ++typedef struct { ++ uint32_t command; ++ uint32_t sequence; ++ uint32_t status; ++ uint32_t picBuf; ++ uint32_t picRelBuf; ++ uint32_t picInfoDeliveryQ; ++ uint32_t picInfoReleaseQ; ++ uint32_t channelStatus; ++ uint32_t userDataDeliveryQ; ++ uint32_t userDataReleaseQ; ++ uint32_t transportStreamCaptureAddr; ++ uint32_t asyncEventQ; ++ ++} DecRspChannelStartVideo; ++ ++#define eCMD_C011_CMD_BASE (0x73763000) ++ ++/* host commands */ ++typedef enum { ++ eCMD_TS_GET_NEXT_PIC = 0x7376F100, /* debug get next picture */ ++ eCMD_TS_GET_LAST_PIC = 0x7376F102, /* debug get last pic status */ ++ eCMD_TS_READ_WRITE_MEM = 0x7376F104, /* debug read write memory */ ++ ++ /* New API commands */ ++ /* General commands */ ++ eCMD_C011_INIT = eCMD_C011_CMD_BASE + 0x01, ++ eCMD_C011_RESET = eCMD_C011_CMD_BASE + 0x02, ++ eCMD_C011_SELF_TEST = eCMD_C011_CMD_BASE + 0x03, ++ eCMD_C011_GET_VERSION = eCMD_C011_CMD_BASE + 0x04, ++ eCMD_C011_GPIO = eCMD_C011_CMD_BASE + 0x05, ++ eCMD_C011_DEBUG_SETUP = eCMD_C011_CMD_BASE + 0x06, ++ ++ /* Decoding commands */ ++ eCMD_C011_DEC_CHAN_OPEN = eCMD_C011_CMD_BASE + 0x100, ++ eCMD_C011_DEC_CHAN_CLOSE = eCMD_C011_CMD_BASE + 0x101, ++ eCMD_C011_DEC_CHAN_ACTIVATE = eCMD_C011_CMD_BASE + 0x102, ++ eCMD_C011_DEC_CHAN_STATUS = eCMD_C011_CMD_BASE + 0x103, ++ eCMD_C011_DEC_CHAN_FLUSH = eCMD_C011_CMD_BASE + 0x104, ++ eCMD_C011_DEC_CHAN_TRICK_PLAY = eCMD_C011_CMD_BASE + 0x105, ++ eCMD_C011_DEC_CHAN_TS_PIDS = eCMD_C011_CMD_BASE + 0x106, ++ eCMD_C011_DEC_CHAN_PS_STREAM_ID = eCMD_C011_CMD_BASE + 0x107, ++ eCMD_C011_DEC_CHAN_INPUT_PARAMS = eCMD_C011_CMD_BASE + 0x108, ++ eCMD_C011_DEC_CHAN_VIDEO_OUTPUT = eCMD_C011_CMD_BASE + 0x109, ++ eCMD_C011_DEC_CHAN_OUTPUT_FORMAT = eCMD_C011_CMD_BASE + 0x10A, ++ eCMD_C011_DEC_CHAN_SCALING_FILTERS = eCMD_C011_CMD_BASE + 0x10B, ++ eCMD_C011_DEC_CHAN_OSD_MODE = eCMD_C011_CMD_BASE + 0x10D, ++ eCMD_C011_DEC_CHAN_DROP = eCMD_C011_CMD_BASE + 0x10E, ++ eCMD_C011_DEC_CHAN_RELEASE = eCMD_C011_CMD_BASE + 0x10F, ++ eCMD_C011_DEC_CHAN_STREAM_SETTINGS = eCMD_C011_CMD_BASE + 0x110, ++ eCMD_C011_DEC_CHAN_PAUSE_OUTPUT = eCMD_C011_CMD_BASE + 0x111, ++ eCMD_C011_DEC_CHAN_CHANGE = eCMD_C011_CMD_BASE + 0x112, ++ eCMD_C011_DEC_CHAN_SET_STC = eCMD_C011_CMD_BASE + 0x113, ++ eCMD_C011_DEC_CHAN_SET_PTS = eCMD_C011_CMD_BASE + 0x114, ++ eCMD_C011_DEC_CHAN_CC_MODE = eCMD_C011_CMD_BASE + 0x115, ++ eCMD_C011_DEC_CREATE_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x116, ++ eCMD_C011_DEC_COPY_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x117, ++ eCMD_C011_DEC_DELETE_AUDIO_CONTEXT = eCMD_C011_CMD_BASE + 0x118, ++ eCMD_C011_DEC_CHAN_SET_DECYPTION = eCMD_C011_CMD_BASE + 0x119, ++ eCMD_C011_DEC_CHAN_START_VIDEO = eCMD_C011_CMD_BASE + 0x11A, ++ eCMD_C011_DEC_CHAN_STOP_VIDEO = eCMD_C011_CMD_BASE + 0x11B, ++ eCMD_C011_DEC_CHAN_PIC_CAPTURE = eCMD_C011_CMD_BASE + 0x11C, ++ eCMD_C011_DEC_CHAN_PAUSE = eCMD_C011_CMD_BASE + 0x11D, ++ eCMD_C011_DEC_CHAN_PAUSE_STATE = eCMD_C011_CMD_BASE + 0x11E, ++ eCMD_C011_DEC_CHAN_SET_SLOWM_RATE = eCMD_C011_CMD_BASE + 0x11F, ++ eCMD_C011_DEC_CHAN_GET_SLOWM_RATE = eCMD_C011_CMD_BASE + 0x120, ++ eCMD_C011_DEC_CHAN_SET_FF_RATE = eCMD_C011_CMD_BASE + 0x121, ++ eCMD_C011_DEC_CHAN_GET_FF_RATE = eCMD_C011_CMD_BASE + 0x122, ++ eCMD_C011_DEC_CHAN_FRAME_ADVANCE = eCMD_C011_CMD_BASE + 0x123, ++ eCMD_C011_DEC_CHAN_SET_SKIP_PIC_MODE = eCMD_C011_CMD_BASE + 0x124, ++ eCMD_C011_DEC_CHAN_GET_SKIP_PIC_MODE = eCMD_C011_CMD_BASE + 0x125, ++ eCMD_C011_DEC_CHAN_FILL_PIC_BUF = eCMD_C011_CMD_BASE + 0x126, ++ eCMD_C011_DEC_CHAN_SET_CONTINUITY_CHECK = eCMD_C011_CMD_BASE + 0x127, ++ eCMD_C011_DEC_CHAN_GET_CONTINUITY_CHECK = eCMD_C011_CMD_BASE + 0x128, ++ eCMD_C011_DEC_CHAN_SET_BRCM_TRICK_MODE = eCMD_C011_CMD_BASE + 0x129, ++ eCMD_C011_DEC_CHAN_GET_BRCM_TRICK_MODE = eCMD_C011_CMD_BASE + 0x12A, ++ eCMD_C011_DEC_CHAN_REVERSE_FIELD_STATUS = eCMD_C011_CMD_BASE + 0x12B, ++ eCMD_C011_DEC_CHAN_I_PICTURE_FOUND = eCMD_C011_CMD_BASE + 0x12C, ++ eCMD_C011_DEC_CHAN_SET_PARAMETER = eCMD_C011_CMD_BASE + 0x12D, ++ eCMD_C011_DEC_CHAN_SET_USER_DATA_MODE = eCMD_C011_CMD_BASE + 0x12E, ++ eCMD_C011_DEC_CHAN_SET_PAUSE_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x12F, ++ eCMD_C011_DEC_CHAN_SET_SLOW_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x130, ++ eCMD_C011_DEC_CHAN_SET_FF_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x131, ++ eCMD_C011_DEC_CHAN_SET_DISPLAY_TIMING_MODE = eCMD_C011_CMD_BASE + 0x132, ++ eCMD_C011_DEC_CHAN_SET_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x133, ++ eCMD_C011_DEC_CHAN_GET_DISPLAY_MODE = eCMD_C011_CMD_BASE + 0x134, ++ eCMD_C011_DEC_CHAN_SET_REVERSE_FIELD = eCMD_C011_CMD_BASE + 0x135, ++ eCMD_C011_DEC_CHAN_STREAM_OPEN = eCMD_C011_CMD_BASE + 0x136, ++ eCMD_C011_DEC_CHAN_SET_PCR_PID = eCMD_C011_CMD_BASE + 0x137, ++ eCMD_C011_DEC_CHAN_SET_VID_PID = eCMD_C011_CMD_BASE + 0x138, ++ eCMD_C011_DEC_CHAN_SET_PAN_SCAN_MODE = eCMD_C011_CMD_BASE + 0x139, ++ eCMD_C011_DEC_CHAN_START_DISPLAY_AT_PTS = eCMD_C011_CMD_BASE + 0x140, ++ eCMD_C011_DEC_CHAN_STOP_DISPLAY_AT_PTS = eCMD_C011_CMD_BASE + 0x141, ++ eCMD_C011_DEC_CHAN_SET_DISPLAY_ORDER = eCMD_C011_CMD_BASE + 0x142, ++ eCMD_C011_DEC_CHAN_GET_DISPLAY_ORDER = eCMD_C011_CMD_BASE + 0x143, ++ eCMD_C011_DEC_CHAN_SET_HOST_TRICK_MODE = eCMD_C011_CMD_BASE + 0x144, ++ eCMD_C011_DEC_CHAN_SET_OPERATION_MODE = eCMD_C011_CMD_BASE + 0x145, ++ eCMD_C011_DEC_CHAN_DISPLAY_PAUSE_UNTO_PTS = eCMD_C011_CMD_BASE + 0x146, ++ eCMD_C011_DEC_CHAN_SET_PTS_STC_DIFF_THRESHOLD = eCMD_C011_CMD_BASE + 0x147, ++ eCMD_C011_DEC_CHAN_SEND_COMPRESSED_BUF = eCMD_C011_CMD_BASE + 0x148, ++ eCMD_C011_DEC_CHAN_SET_CLIPPING = eCMD_C011_CMD_BASE + 0x149, ++ eCMD_C011_DEC_CHAN_SET_PARAMETERS_FOR_HARD_RESET_INTERRUPT_TO_HOST ++ = eCMD_C011_CMD_BASE + 0x150, ++ ++ /* Decoder RevD commands */ ++ eCMD_C011_DEC_CHAN_SET_CSC = eCMD_C011_CMD_BASE + 0x180, /* color space conversion */ ++ eCMD_C011_DEC_CHAN_SET_RANGE_REMAP = eCMD_C011_CMD_BASE + 0x181, ++ eCMD_C011_DEC_CHAN_SET_FGT = eCMD_C011_CMD_BASE + 0x182, ++ /* Note: 0x183 not implemented yet in Rev D main */ ++ eCMD_C011_DEC_CHAN_SET_LASTPICTURE_PADDING = eCMD_C011_CMD_BASE + 0x183, ++ ++ /* Decoder 7412 commands (7412-only) */ ++ eCMD_C011_DEC_CHAN_SET_CONTENT_KEY = eCMD_C011_CMD_BASE + 0x190, ++ eCMD_C011_DEC_CHAN_SET_SESSION_KEY = eCMD_C011_CMD_BASE + 0x191, ++ eCMD_C011_DEC_CHAN_FMT_CHANGE_ACK = eCMD_C011_CMD_BASE + 0x192, ++ ++ eCMD_C011_DEC_CHAN_CUSTOM_VIDOUT = eCMD_C011_CMD_BASE + 0x1FF, ++ ++ /* Encoding commands */ ++ eCMD_C011_ENC_CHAN_OPEN = eCMD_C011_CMD_BASE + 0x200, ++ eCMD_C011_ENC_CHAN_CLOSE = eCMD_C011_CMD_BASE + 0x201, ++ eCMD_C011_ENC_CHAN_ACTIVATE = eCMD_C011_CMD_BASE + 0x202, ++ eCMD_C011_ENC_CHAN_CONTROL = eCMD_C011_CMD_BASE + 0x203, ++ eCMD_C011_ENC_CHAN_STATISTICS = eCMD_C011_CMD_BASE + 0x204, ++ ++ eNOTIFY_C011_ENC_CHAN_EVENT = eCMD_C011_CMD_BASE + 0x210, ++ ++} eC011_TS_CMD; ++ ++#endif +diff --git a/drivers/staging/crystalhd/crystalhd_hw.c b/drivers/staging/crystalhd/crystalhd_hw.c +new file mode 100644 +index 0000000..01819d3 +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_hw.c +@@ -0,0 +1,2395 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_hw . c ++ * ++ * Description: ++ * BCM70010 Linux driver HW layer. ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#include ++#include ++#include "crystalhd_hw.h" ++ ++/* Functions internal to this file */ ++ ++static void crystalhd_enable_uarts(struct crystalhd_adp *adp) ++{ ++ bc_dec_reg_wr(adp, UartSelectA, BSVS_UART_STREAM); ++ bc_dec_reg_wr(adp, UartSelectB, BSVS_UART_DEC_OUTER); ++} ++ ++ ++static void crystalhd_start_dram(struct crystalhd_adp *adp) ++{ ++ bc_dec_reg_wr(adp, SDRAM_PARAM, ((40 / 5 - 1) << 0) | ++ /* tras (40ns tras)/(5ns period) -1 ((15/5 - 1) << 4) | // trcd */ ++ ((15 / 5 - 1) << 7) | /* trp */ ++ ((10 / 5 - 1) << 10) | /* trrd */ ++ ((15 / 5 + 1) << 12) | /* twr */ ++ ((2 + 1) << 16) | /* twtr */ ++ ((70 / 5 - 2) << 19) | /* trfc */ ++ (0 << 23)); ++ ++ bc_dec_reg_wr(adp, SDRAM_PRECHARGE, 0); ++ bc_dec_reg_wr(adp, SDRAM_EXT_MODE, 2); ++ bc_dec_reg_wr(adp, SDRAM_MODE, 0x132); ++ bc_dec_reg_wr(adp, SDRAM_PRECHARGE, 0); ++ bc_dec_reg_wr(adp, SDRAM_REFRESH, 0); ++ bc_dec_reg_wr(adp, SDRAM_REFRESH, 0); ++ bc_dec_reg_wr(adp, SDRAM_MODE, 0x32); ++ /* setting the refresh rate here */ ++ bc_dec_reg_wr(adp, SDRAM_REF_PARAM, ((1 << 12) | 96)); ++} ++ ++ ++static bool crystalhd_bring_out_of_rst(struct crystalhd_adp *adp) ++{ ++ link_misc_perst_deco_ctrl rst_deco_cntrl; ++ link_misc_perst_clk_ctrl rst_clk_cntrl; ++ uint32_t temp; ++ ++ /* ++ * Link clocks: MISC_PERST_CLOCK_CTRL Clear PLL power down bit, ++ * delay to allow PLL to lock Clear alternate clock, stop clock bits ++ */ ++ rst_clk_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_CLOCK_CTRL); ++ rst_clk_cntrl.pll_pwr_dn = 0; ++ crystalhd_reg_wr(adp, MISC_PERST_CLOCK_CTRL, rst_clk_cntrl.whole_reg); ++ msleep_interruptible(50); ++ ++ rst_clk_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_CLOCK_CTRL); ++ rst_clk_cntrl.stop_core_clk = 0; ++ rst_clk_cntrl.sel_alt_clk = 0; ++ ++ crystalhd_reg_wr(adp, MISC_PERST_CLOCK_CTRL, rst_clk_cntrl.whole_reg); ++ msleep_interruptible(50); ++ ++ /* ++ * Bus Arbiter Timeout: GISB_ARBITER_TIMER ++ * Set internal bus arbiter timeout to 40us based on core clock speed ++ * (63MHz * 40us = 0x9D8) ++ */ ++ crystalhd_reg_wr(adp, GISB_ARBITER_TIMER, 0x9D8); ++ ++ /* ++ * Decoder clocks: MISC_PERST_DECODER_CTRL ++ * Enable clocks while 7412 reset is asserted, delay ++ * De-assert 7412 reset ++ */ ++ rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_DECODER_CTRL); ++ rst_deco_cntrl.stop_bcm_7412_clk = 0; ++ rst_deco_cntrl.bcm7412_rst = 1; ++ crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, rst_deco_cntrl.whole_reg); ++ msleep_interruptible(10); ++ ++ rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_DECODER_CTRL); ++ rst_deco_cntrl.bcm7412_rst = 0; ++ crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, rst_deco_cntrl.whole_reg); ++ msleep_interruptible(50); ++ ++ /* Disable OTP_CONTENT_MISC to 0 to disable all secure modes */ ++ crystalhd_reg_wr(adp, OTP_CONTENT_MISC, 0); ++ ++ /* Clear bit 29 of 0x404 */ ++ temp = crystalhd_reg_rd(adp, PCIE_TL_TRANSACTION_CONFIGURATION); ++ temp &= ~BC_BIT(29); ++ crystalhd_reg_wr(adp, PCIE_TL_TRANSACTION_CONFIGURATION, temp); ++ ++ /* 2.5V regulator must be set to 2.6 volts (+6%) */ ++ /* FIXME: jarod: what's the point of this reg read? */ ++ temp = crystalhd_reg_rd(adp, MISC_PERST_VREG_CTRL); ++ crystalhd_reg_wr(adp, MISC_PERST_VREG_CTRL, 0xF3); ++ ++ return true; ++} ++ ++static bool crystalhd_put_in_reset(struct crystalhd_adp *adp) ++{ ++ link_misc_perst_deco_ctrl rst_deco_cntrl; ++ link_misc_perst_clk_ctrl rst_clk_cntrl; ++ uint32_t temp; ++ ++ /* ++ * Decoder clocks: MISC_PERST_DECODER_CTRL ++ * Assert 7412 reset, delay ++ * Assert 7412 stop clock ++ */ ++ rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_DECODER_CTRL); ++ rst_deco_cntrl.stop_bcm_7412_clk = 1; ++ crystalhd_reg_wr(adp, MISC_PERST_DECODER_CTRL, rst_deco_cntrl.whole_reg); ++ msleep_interruptible(50); ++ ++ /* Bus Arbiter Timeout: GISB_ARBITER_TIMER ++ * Set internal bus arbiter timeout to 40us based on core clock speed ++ * (6.75MHZ * 40us = 0x10E) ++ */ ++ crystalhd_reg_wr(adp, GISB_ARBITER_TIMER, 0x10E); ++ ++ /* Link clocks: MISC_PERST_CLOCK_CTRL ++ * Stop core clk, delay ++ * Set alternate clk, delay, set PLL power down ++ */ ++ rst_clk_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_CLOCK_CTRL); ++ rst_clk_cntrl.stop_core_clk = 1; ++ rst_clk_cntrl.sel_alt_clk = 1; ++ crystalhd_reg_wr(adp, MISC_PERST_CLOCK_CTRL, rst_clk_cntrl.whole_reg); ++ msleep_interruptible(50); ++ ++ rst_clk_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC_PERST_CLOCK_CTRL); ++ rst_clk_cntrl.pll_pwr_dn = 1; ++ crystalhd_reg_wr(adp, MISC_PERST_CLOCK_CTRL, rst_clk_cntrl.whole_reg); ++ ++ /* ++ * Read and restore the Transaction Configuration Register ++ * after core reset ++ */ ++ temp = crystalhd_reg_rd(adp, PCIE_TL_TRANSACTION_CONFIGURATION); ++ ++ /* ++ * Link core soft reset: MISC3_RESET_CTRL ++ * - Write BIT[0]=1 and read it back for core reset to take place ++ */ ++ crystalhd_reg_wr(adp, MISC3_RESET_CTRL, 1); ++ rst_deco_cntrl.whole_reg = crystalhd_reg_rd(adp, MISC3_RESET_CTRL); ++ msleep_interruptible(50); ++ ++ /* restore the transaction configuration register */ ++ crystalhd_reg_wr(adp, PCIE_TL_TRANSACTION_CONFIGURATION, temp); ++ ++ return true; ++} ++ ++static void crystalhd_disable_interrupts(struct crystalhd_adp *adp) ++{ ++ intr_mask_reg intr_mask; ++ intr_mask.whole_reg = crystalhd_reg_rd(adp, INTR_INTR_MSK_STS_REG); ++ intr_mask.mask_pcie_err = 1; ++ intr_mask.mask_pcie_rbusmast_err = 1; ++ intr_mask.mask_pcie_rgr_bridge = 1; ++ intr_mask.mask_rx_done = 1; ++ intr_mask.mask_rx_err = 1; ++ intr_mask.mask_tx_done = 1; ++ intr_mask.mask_tx_err = 1; ++ crystalhd_reg_wr(adp, INTR_INTR_MSK_SET_REG, intr_mask.whole_reg); ++ ++ return; ++} ++ ++static void crystalhd_enable_interrupts(struct crystalhd_adp *adp) ++{ ++ intr_mask_reg intr_mask; ++ intr_mask.whole_reg = crystalhd_reg_rd(adp, INTR_INTR_MSK_STS_REG); ++ intr_mask.mask_pcie_err = 1; ++ intr_mask.mask_pcie_rbusmast_err = 1; ++ intr_mask.mask_pcie_rgr_bridge = 1; ++ intr_mask.mask_rx_done = 1; ++ intr_mask.mask_rx_err = 1; ++ intr_mask.mask_tx_done = 1; ++ intr_mask.mask_tx_err = 1; ++ crystalhd_reg_wr(adp, INTR_INTR_MSK_CLR_REG, intr_mask.whole_reg); ++ ++ return; ++} ++ ++static void crystalhd_clear_errors(struct crystalhd_adp *adp) ++{ ++ uint32_t reg; ++ ++ /* FIXME: jarod: wouldn't we want to write a 0 to the reg? Or does the write clear the bits specified? */ ++ reg = crystalhd_reg_rd(adp, MISC1_Y_RX_ERROR_STATUS); ++ if (reg) ++ crystalhd_reg_wr(adp, MISC1_Y_RX_ERROR_STATUS, reg); ++ ++ reg = crystalhd_reg_rd(adp, MISC1_UV_RX_ERROR_STATUS); ++ if (reg) ++ crystalhd_reg_wr(adp, MISC1_UV_RX_ERROR_STATUS, reg); ++ ++ reg = crystalhd_reg_rd(adp, MISC1_TX_DMA_ERROR_STATUS); ++ if (reg) ++ crystalhd_reg_wr(adp, MISC1_TX_DMA_ERROR_STATUS, reg); ++} ++ ++static void crystalhd_clear_interrupts(struct crystalhd_adp *adp) ++{ ++ uint32_t intr_sts = crystalhd_reg_rd(adp, INTR_INTR_STATUS); ++ ++ if (intr_sts) { ++ crystalhd_reg_wr(adp, INTR_INTR_CLR_REG, intr_sts); ++ ++ /* Write End Of Interrupt for PCIE */ ++ crystalhd_reg_wr(adp, INTR_EOI_CTRL, 1); ++ } ++} ++ ++static void crystalhd_soft_rst(struct crystalhd_adp *adp) ++{ ++ uint32_t val; ++ ++ /* Assert c011 soft reset*/ ++ bc_dec_reg_wr(adp, DecHt_HostSwReset, 0x00000001); ++ msleep_interruptible(50); ++ ++ /* Release c011 soft reset*/ ++ bc_dec_reg_wr(adp, DecHt_HostSwReset, 0x00000000); ++ ++ /* Disable Stuffing..*/ ++ val = crystalhd_reg_rd(adp, MISC2_GLOBAL_CTRL); ++ val |= BC_BIT(8); ++ crystalhd_reg_wr(adp, MISC2_GLOBAL_CTRL, val); ++} ++ ++static bool crystalhd_load_firmware_config(struct crystalhd_adp *adp) ++{ ++ uint32_t i = 0, reg; ++ ++ crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (BC_DRAM_FW_CFG_ADDR >> 19)); ++ ++ crystalhd_reg_wr(adp, AES_CMD, 0); ++ crystalhd_reg_wr(adp, AES_CONFIG_INFO, (BC_DRAM_FW_CFG_ADDR & 0x7FFFF)); ++ crystalhd_reg_wr(adp, AES_CMD, 0x1); ++ ++ /* FIXME: jarod: I've seen this fail, and introducing extra delays helps... */ ++ for (i = 0; i < 100; ++i) { ++ reg = crystalhd_reg_rd(adp, AES_STATUS); ++ if (reg & 0x1) ++ return true; ++ msleep_interruptible(10); ++ } ++ ++ return false; ++} ++ ++ ++static bool crystalhd_start_device(struct crystalhd_adp *adp) ++{ ++ uint32_t dbg_options, glb_cntrl = 0, reg_pwrmgmt = 0; ++ ++ BCMLOG(BCMLOG_INFO, "Starting BCM70012 Device\n"); ++ ++ reg_pwrmgmt = crystalhd_reg_rd(adp, PCIE_DLL_DATA_LINK_CONTROL); ++ reg_pwrmgmt &= ~ASPM_L1_ENABLE; ++ ++ crystalhd_reg_wr(adp, PCIE_DLL_DATA_LINK_CONTROL, reg_pwrmgmt); ++ ++ if (!crystalhd_bring_out_of_rst(adp)) { ++ BCMLOG_ERR("Failed To Bring Link Out Of Reset\n"); ++ return false; ++ } ++ ++ crystalhd_disable_interrupts(adp); ++ ++ crystalhd_clear_errors(adp); ++ ++ crystalhd_clear_interrupts(adp); ++ ++ crystalhd_enable_interrupts(adp); ++ ++ /* Enable the option for getting the total no. of DWORDS ++ * that have been transfered by the RXDMA engine ++ */ ++ dbg_options = crystalhd_reg_rd(adp, MISC1_DMA_DEBUG_OPTIONS_REG); ++ dbg_options |= 0x10; ++ crystalhd_reg_wr(adp, MISC1_DMA_DEBUG_OPTIONS_REG, dbg_options); ++ ++ /* Enable PCI Global Control options */ ++ glb_cntrl = crystalhd_reg_rd(adp, MISC2_GLOBAL_CTRL); ++ glb_cntrl |= 0x100; ++ glb_cntrl |= 0x8000; ++ crystalhd_reg_wr(adp, MISC2_GLOBAL_CTRL, glb_cntrl); ++ ++ crystalhd_enable_interrupts(adp); ++ ++ crystalhd_soft_rst(adp); ++ crystalhd_start_dram(adp); ++ crystalhd_enable_uarts(adp); ++ ++ return true; ++} ++ ++static bool crystalhd_stop_device(struct crystalhd_adp *adp) ++{ ++ uint32_t reg; ++ ++ BCMLOG(BCMLOG_INFO, "Stopping BCM70012 Device\n"); ++ /* Clear and disable interrupts */ ++ crystalhd_disable_interrupts(adp); ++ crystalhd_clear_errors(adp); ++ crystalhd_clear_interrupts(adp); ++ ++ if (!crystalhd_put_in_reset(adp)) ++ BCMLOG_ERR("Failed to Put Link To Reset State\n"); ++ ++ reg = crystalhd_reg_rd(adp, PCIE_DLL_DATA_LINK_CONTROL); ++ reg |= ASPM_L1_ENABLE; ++ crystalhd_reg_wr(adp, PCIE_DLL_DATA_LINK_CONTROL, reg); ++ ++ /* Set PCI Clk Req */ ++ reg = crystalhd_reg_rd(adp, PCIE_CLK_REQ_REG); ++ reg |= PCI_CLK_REQ_ENABLE; ++ crystalhd_reg_wr(adp, PCIE_CLK_REQ_REG, reg); ++ ++ return true; ++} ++ ++static crystalhd_rx_dma_pkt *crystalhd_hw_alloc_rx_pkt(struct crystalhd_hw *hw) ++{ ++ unsigned long flags = 0; ++ crystalhd_rx_dma_pkt *temp = NULL; ++ ++ if (!hw) ++ return NULL; ++ ++ spin_lock_irqsave(&hw->lock, flags); ++ temp = hw->rx_pkt_pool_head; ++ if (temp) { ++ hw->rx_pkt_pool_head = hw->rx_pkt_pool_head->next; ++ temp->dio_req = NULL; ++ temp->pkt_tag = 0; ++ temp->flags = 0; ++ } ++ spin_unlock_irqrestore(&hw->lock, flags); ++ ++ return temp; ++} ++ ++static void crystalhd_hw_free_rx_pkt(struct crystalhd_hw *hw, ++ crystalhd_rx_dma_pkt *pkt) ++{ ++ unsigned long flags = 0; ++ ++ if (!hw || !pkt) ++ return; ++ ++ spin_lock_irqsave(&hw->lock, flags); ++ pkt->next = hw->rx_pkt_pool_head; ++ hw->rx_pkt_pool_head = pkt; ++ spin_unlock_irqrestore(&hw->lock, flags); ++} ++ ++/* ++ * Call back from TX - IOQ deletion. ++ * ++ * This routine will release the TX DMA rings allocated ++ * druing setup_dma rings interface. ++ * ++ * Memory is allocated per DMA ring basis. This is just ++ * a place holder to be able to create the dio queues. ++ */ ++static void crystalhd_tx_desc_rel_call_back(void *context, void *data) ++{ ++} ++ ++/* ++ * Rx Packet release callback.. ++ * ++ * Release All user mapped capture buffers and Our DMA packets ++ * back to our free pool. The actual cleanup of the DMA ++ * ring descriptors happen during dma ring release. ++ */ ++static void crystalhd_rx_pkt_rel_call_back(void *context, void *data) ++{ ++ struct crystalhd_hw *hw = (struct crystalhd_hw *)context; ++ crystalhd_rx_dma_pkt *pkt = (crystalhd_rx_dma_pkt *)data; ++ ++ if (!pkt || !hw) { ++ BCMLOG_ERR("Invalid arg - %p %p\n", hw, pkt); ++ return; ++ } ++ ++ if (pkt->dio_req) ++ crystalhd_unmap_dio(hw->adp, pkt->dio_req); ++ else ++ BCMLOG_ERR("Missing dio_req: 0x%x\n", pkt->pkt_tag); ++ ++ crystalhd_hw_free_rx_pkt(hw, pkt); ++} ++ ++#define crystalhd_hw_delete_ioq(adp, q) \ ++ if (q) { \ ++ crystalhd_delete_dioq(adp, q); \ ++ q = NULL; \ ++ } ++ ++static void crystalhd_hw_delete_ioqs(struct crystalhd_hw *hw) ++{ ++ if (!hw) ++ return; ++ ++ BCMLOG(BCMLOG_DBG, "Deleting IOQs \n"); ++ crystalhd_hw_delete_ioq(hw->adp, hw->tx_actq); ++ crystalhd_hw_delete_ioq(hw->adp, hw->tx_freeq); ++ crystalhd_hw_delete_ioq(hw->adp, hw->rx_actq); ++ crystalhd_hw_delete_ioq(hw->adp, hw->rx_freeq); ++ crystalhd_hw_delete_ioq(hw->adp, hw->rx_rdyq); ++} ++ ++#define crystalhd_hw_create_ioq(sts, hw, q, cb) \ ++do { \ ++ sts = crystalhd_create_dioq(hw->adp, &q, cb, hw); \ ++ if (sts != BC_STS_SUCCESS) \ ++ goto hw_create_ioq_err; \ ++} while (0) ++ ++/* ++ * Create IOQs.. ++ * ++ * TX - Active & Free ++ * RX - Active, Ready and Free. ++ */ ++static BC_STATUS crystalhd_hw_create_ioqs(struct crystalhd_hw *hw) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ crystalhd_hw_create_ioq(sts, hw, hw->tx_freeq, ++ crystalhd_tx_desc_rel_call_back); ++ crystalhd_hw_create_ioq(sts, hw, hw->tx_actq, ++ crystalhd_tx_desc_rel_call_back); ++ ++ crystalhd_hw_create_ioq(sts, hw, hw->rx_freeq, ++ crystalhd_rx_pkt_rel_call_back); ++ crystalhd_hw_create_ioq(sts, hw, hw->rx_rdyq, ++ crystalhd_rx_pkt_rel_call_back); ++ crystalhd_hw_create_ioq(sts, hw, hw->rx_actq, ++ crystalhd_rx_pkt_rel_call_back); ++ ++ return sts; ++ ++hw_create_ioq_err: ++ crystalhd_hw_delete_ioqs(hw); ++ ++ return sts; ++} ++ ++ ++static bool crystalhd_code_in_full(struct crystalhd_adp *adp, uint32_t needed_sz, ++ bool b_188_byte_pkts, uint8_t flags) ++{ ++ uint32_t base, end, writep, readp; ++ uint32_t cpbSize, cpbFullness, fifoSize; ++ ++ if (flags & 0x02) { /* ASF Bit is set */ ++ base = bc_dec_reg_rd(adp, REG_Dec_TsAudCDB2Base); ++ end = bc_dec_reg_rd(adp, REG_Dec_TsAudCDB2End); ++ writep = bc_dec_reg_rd(adp, REG_Dec_TsAudCDB2Wrptr); ++ readp = bc_dec_reg_rd(adp, REG_Dec_TsAudCDB2Rdptr); ++ } else if (b_188_byte_pkts) { /*Encrypted 188 byte packets*/ ++ base = bc_dec_reg_rd(adp, REG_Dec_TsUser0Base); ++ end = bc_dec_reg_rd(adp, REG_Dec_TsUser0End); ++ writep = bc_dec_reg_rd(adp, REG_Dec_TsUser0Wrptr); ++ readp = bc_dec_reg_rd(adp, REG_Dec_TsUser0Rdptr); ++ } else { ++ base = bc_dec_reg_rd(adp, REG_DecCA_RegCinBase); ++ end = bc_dec_reg_rd(adp, REG_DecCA_RegCinEnd); ++ writep = bc_dec_reg_rd(adp, REG_DecCA_RegCinWrPtr); ++ readp = bc_dec_reg_rd(adp, REG_DecCA_RegCinRdPtr); ++ } ++ ++ cpbSize = end - base; ++ if (writep >= readp) ++ cpbFullness = writep - readp; ++ else ++ cpbFullness = (end - base) - (readp - writep); ++ ++ fifoSize = cpbSize - cpbFullness; ++ ++ if (fifoSize < BC_INFIFO_THRESHOLD) ++ return true; ++ ++ if (needed_sz > (fifoSize - BC_INFIFO_THRESHOLD)) ++ return true; ++ ++ return false; ++} ++ ++static BC_STATUS crystalhd_hw_tx_req_complete(struct crystalhd_hw *hw, ++ uint32_t list_id, BC_STATUS cs) ++{ ++ tx_dma_pkt *tx_req; ++ ++ if (!hw || !list_id) { ++ BCMLOG_ERR("Invalid Arg..\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ hw->pwr_lock--; ++ ++ tx_req = (tx_dma_pkt *)crystalhd_dioq_find_and_fetch(hw->tx_actq, list_id); ++ if (!tx_req) { ++ if (cs != BC_STS_IO_USER_ABORT) ++ BCMLOG_ERR("Find and Fetch Did not find req\n"); ++ return BC_STS_NO_DATA; ++ } ++ ++ if (tx_req->call_back) { ++ tx_req->call_back(tx_req->dio_req, tx_req->cb_event, cs); ++ tx_req->dio_req = NULL; ++ tx_req->cb_event = NULL; ++ tx_req->call_back = NULL; ++ } else { ++ BCMLOG(BCMLOG_DBG, "Missing Tx Callback - %X\n", ++ tx_req->list_tag); ++ } ++ ++ /* Now put back the tx_list back in FreeQ */ ++ tx_req->list_tag = 0; ++ ++ return crystalhd_dioq_add(hw->tx_freeq, tx_req, false, 0); ++} ++ ++static bool crystalhd_tx_list0_handler(struct crystalhd_hw *hw, uint32_t err_sts) ++{ ++ uint32_t err_mask, tmp; ++ unsigned long flags = 0; ++ ++ err_mask = MISC1_TX_DMA_ERROR_STATUS_TX_L0_DESC_TX_ABORT_ERRORS_MASK | ++ MISC1_TX_DMA_ERROR_STATUS_TX_L0_DMA_DATA_TX_ABORT_ERRORS_MASK | ++ MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_MASK; ++ ++ if (!(err_sts & err_mask)) ++ return false; ++ ++ BCMLOG_ERR("Error on Tx-L0 %x \n", err_sts); ++ ++ tmp = err_mask; ++ ++ if (err_sts & MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_MASK) ++ tmp &= ~MISC1_TX_DMA_ERROR_STATUS_TX_L0_FIFO_FULL_ERRORS_MASK; ++ ++ if (tmp) { ++ spin_lock_irqsave(&hw->lock, flags); ++ /* reset list index.*/ ++ hw->tx_list_post_index = 0; ++ spin_unlock_irqrestore(&hw->lock, flags); ++ } ++ ++ tmp = err_sts & err_mask; ++ crystalhd_reg_wr(hw->adp, MISC1_TX_DMA_ERROR_STATUS, tmp); ++ ++ return true; ++} ++ ++static bool crystalhd_tx_list1_handler(struct crystalhd_hw *hw, uint32_t err_sts) ++{ ++ uint32_t err_mask, tmp; ++ unsigned long flags = 0; ++ ++ err_mask = MISC1_TX_DMA_ERROR_STATUS_TX_L1_DESC_TX_ABORT_ERRORS_MASK | ++ MISC1_TX_DMA_ERROR_STATUS_TX_L1_DMA_DATA_TX_ABORT_ERRORS_MASK | ++ MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_MASK; ++ ++ if (!(err_sts & err_mask)) ++ return false; ++ ++ BCMLOG_ERR("Error on Tx-L1 %x \n", err_sts); ++ ++ tmp = err_mask; ++ ++ if (err_sts & MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_MASK) ++ tmp &= ~MISC1_TX_DMA_ERROR_STATUS_TX_L1_FIFO_FULL_ERRORS_MASK; ++ ++ if (tmp) { ++ spin_lock_irqsave(&hw->lock, flags); ++ /* reset list index.*/ ++ hw->tx_list_post_index = 0; ++ spin_unlock_irqrestore(&hw->lock, flags); ++ } ++ ++ tmp = err_sts & err_mask; ++ crystalhd_reg_wr(hw->adp, MISC1_TX_DMA_ERROR_STATUS, tmp); ++ ++ return true; ++} ++ ++static void crystalhd_tx_isr(struct crystalhd_hw *hw, uint32_t int_sts) ++{ ++ uint32_t err_sts; ++ ++ if (int_sts & INTR_INTR_STATUS_L0_TX_DMA_DONE_INTR_MASK) ++ crystalhd_hw_tx_req_complete(hw, hw->tx_ioq_tag_seed + 0, ++ BC_STS_SUCCESS); ++ ++ if (int_sts & INTR_INTR_STATUS_L1_TX_DMA_DONE_INTR_MASK) ++ crystalhd_hw_tx_req_complete(hw, hw->tx_ioq_tag_seed + 1, ++ BC_STS_SUCCESS); ++ ++ if (!(int_sts & (INTR_INTR_STATUS_L0_TX_DMA_ERR_INTR_MASK | ++ INTR_INTR_STATUS_L1_TX_DMA_ERR_INTR_MASK))) { ++ /* No error mask set.. */ ++ return; ++ } ++ ++ /* Handle Tx errors. */ ++ err_sts = crystalhd_reg_rd(hw->adp, MISC1_TX_DMA_ERROR_STATUS); ++ ++ if (crystalhd_tx_list0_handler(hw, err_sts)) ++ crystalhd_hw_tx_req_complete(hw, hw->tx_ioq_tag_seed + 0, ++ BC_STS_ERROR); ++ ++ if (crystalhd_tx_list1_handler(hw, err_sts)) ++ crystalhd_hw_tx_req_complete(hw, hw->tx_ioq_tag_seed + 1, ++ BC_STS_ERROR); ++ ++ hw->stats.tx_errors++; ++} ++ ++static void crystalhd_hw_dump_desc(pdma_descriptor p_dma_desc, ++ uint32_t ul_desc_index, uint32_t cnt) ++{ ++ uint32_t ix, ll = 0; ++ ++ if (!p_dma_desc || !cnt) ++ return; ++ ++ /* FIXME: jarod: perhaps a modparam desc_debug to enable this, rather than ++ * setting ll (log level, I presume) to non-zero? */ ++ if (!ll) ++ return; ++ ++ for (ix = ul_desc_index; ix < (ul_desc_index + cnt); ix++) { ++ BCMLOG(ll, "%s[%d] Buff[%x:%x] Next:[%x:%x] XferSz:%x Intr:%x,Last:%x\n", ++ ((p_dma_desc[ul_desc_index].dma_dir) ? "TDesc" : "RDesc"), ++ ul_desc_index, ++ p_dma_desc[ul_desc_index].buff_addr_high, ++ p_dma_desc[ul_desc_index].buff_addr_low, ++ p_dma_desc[ul_desc_index].next_desc_addr_high, ++ p_dma_desc[ul_desc_index].next_desc_addr_low, ++ p_dma_desc[ul_desc_index].xfer_size, ++ p_dma_desc[ul_desc_index].intr_enable, ++ p_dma_desc[ul_desc_index].last_rec_indicator); ++ } ++ ++} ++ ++static BC_STATUS crystalhd_hw_fill_desc(crystalhd_dio_req *ioreq, ++ dma_descriptor *desc, ++ dma_addr_t desc_paddr_base, ++ uint32_t sg_cnt, uint32_t sg_st_ix, ++ uint32_t sg_st_off, uint32_t xfr_sz) ++{ ++ uint32_t count = 0, ix = 0, sg_ix = 0, len = 0, last_desc_ix = 0; ++ dma_addr_t desc_phy_addr = desc_paddr_base; ++ addr_64 addr_temp; ++ ++ if (!ioreq || !desc || !desc_paddr_base || !xfr_sz || ++ (!sg_cnt && !ioreq->uinfo.dir_tx)) { ++ BCMLOG_ERR("Invalid Args\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ for (ix = 0; ix < sg_cnt; ix++) { ++ ++ /* Setup SGLE index. */ ++ sg_ix = ix + sg_st_ix; ++ ++ /* Get SGLE length */ ++ len = crystalhd_get_sgle_len(ioreq, sg_ix); ++ if (len % 4) { ++ BCMLOG_ERR(" len in sg %d %d %d\n", len, sg_ix, sg_cnt); ++ return BC_STS_NOT_IMPL; ++ } ++ /* Setup DMA desc with Phy addr & Length at current index. */ ++ addr_temp.full_addr = crystalhd_get_sgle_paddr(ioreq, sg_ix); ++ if (sg_ix == sg_st_ix) { ++ addr_temp.full_addr += sg_st_off; ++ len -= sg_st_off; ++ } ++ memset(&desc[ix], 0, sizeof(desc[ix])); ++ desc[ix].buff_addr_low = addr_temp.low_part; ++ desc[ix].buff_addr_high = addr_temp.high_part; ++ desc[ix].dma_dir = ioreq->uinfo.dir_tx; ++ ++ /* Chain DMA descriptor. */ ++ addr_temp.full_addr = desc_phy_addr + sizeof(dma_descriptor); ++ desc[ix].next_desc_addr_low = addr_temp.low_part; ++ desc[ix].next_desc_addr_high = addr_temp.high_part; ++ ++ if ((count + len) > xfr_sz) ++ len = xfr_sz - count; ++ ++ /* Debug.. */ ++ if ((!len) || (len > crystalhd_get_sgle_len(ioreq, sg_ix))) { ++ BCMLOG_ERR("inv-len(%x) Ix(%d) count:%x xfr_sz:%x sg_cnt:%d\n", ++ len, ix, count, xfr_sz, sg_cnt); ++ return BC_STS_ERROR; ++ } ++ /* Length expects Multiple of 4 */ ++ desc[ix].xfer_size = (len / 4); ++ ++ crystalhd_hw_dump_desc(desc, ix, 1); ++ ++ count += len; ++ desc_phy_addr += sizeof(dma_descriptor); ++ } ++ ++ last_desc_ix = ix - 1; ++ ++ if (ioreq->fb_size) { ++ memset(&desc[ix], 0, sizeof(desc[ix])); ++ addr_temp.full_addr = ioreq->fb_pa; ++ desc[ix].buff_addr_low = addr_temp.low_part; ++ desc[ix].buff_addr_high = addr_temp.high_part; ++ desc[ix].dma_dir = ioreq->uinfo.dir_tx; ++ desc[ix].xfer_size = 1; ++ desc[ix].fill_bytes = 4 - ioreq->fb_size; ++ count += ioreq->fb_size; ++ last_desc_ix++; ++ } ++ ++ /* setup last descriptor..*/ ++ desc[last_desc_ix].last_rec_indicator = 1; ++ desc[last_desc_ix].next_desc_addr_low = 0; ++ desc[last_desc_ix].next_desc_addr_high = 0; ++ desc[last_desc_ix].intr_enable = 1; ++ ++ crystalhd_hw_dump_desc(desc, last_desc_ix, 1); ++ ++ if (count != xfr_sz) { ++ BCMLOG_ERR("interal error sz curr:%x exp:%x\n", count, xfr_sz); ++ return BC_STS_ERROR; ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS crystalhd_xlat_sgl_to_dma_desc(crystalhd_dio_req *ioreq, ++ pdma_desc_mem pdesc_mem, ++ uint32_t *uv_desc_index) ++{ ++ dma_descriptor *desc = NULL; ++ dma_addr_t desc_paddr_base = 0; ++ uint32_t sg_cnt = 0, sg_st_ix = 0, sg_st_off = 0; ++ uint32_t xfr_sz = 0; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ /* Check params.. */ ++ if (!ioreq || !pdesc_mem || !uv_desc_index) { ++ BCMLOG_ERR("Invalid Args\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (!pdesc_mem->sz || !pdesc_mem->pdma_desc_start || ++ !ioreq->sg || (!ioreq->sg_cnt && !ioreq->uinfo.dir_tx)) { ++ BCMLOG_ERR("Invalid Args\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if ((ioreq->uinfo.dir_tx) && (ioreq->uinfo.uv_offset)) { ++ BCMLOG_ERR("UV offset for TX??\n"); ++ return BC_STS_INV_ARG; ++ ++ } ++ ++ desc = pdesc_mem->pdma_desc_start; ++ desc_paddr_base = pdesc_mem->phy_addr; ++ ++ if (ioreq->uinfo.dir_tx || (ioreq->uinfo.uv_offset == 0)) { ++ sg_cnt = ioreq->sg_cnt; ++ xfr_sz = ioreq->uinfo.xfr_len; ++ } else { ++ sg_cnt = ioreq->uinfo.uv_sg_ix + 1; ++ xfr_sz = ioreq->uinfo.uv_offset; ++ } ++ ++ sts = crystalhd_hw_fill_desc(ioreq, desc, desc_paddr_base, sg_cnt, ++ sg_st_ix, sg_st_off, xfr_sz); ++ ++ if ((sts != BC_STS_SUCCESS) || !ioreq->uinfo.uv_offset) ++ return sts; ++ ++ /* Prepare for UV mapping.. */ ++ desc = &pdesc_mem->pdma_desc_start[sg_cnt]; ++ desc_paddr_base = pdesc_mem->phy_addr + ++ (sg_cnt * sizeof(dma_descriptor)); ++ ++ /* Done with desc addr.. now update sg stuff.*/ ++ sg_cnt = ioreq->sg_cnt - ioreq->uinfo.uv_sg_ix; ++ xfr_sz = ioreq->uinfo.xfr_len - ioreq->uinfo.uv_offset; ++ sg_st_ix = ioreq->uinfo.uv_sg_ix; ++ sg_st_off = ioreq->uinfo.uv_sg_off; ++ ++ sts = crystalhd_hw_fill_desc(ioreq, desc, desc_paddr_base, sg_cnt, ++ sg_st_ix, sg_st_off, xfr_sz); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ ++ *uv_desc_index = sg_st_ix; ++ ++ return sts; ++} ++ ++static void crystalhd_start_tx_dma_engine(struct crystalhd_hw *hw) ++{ ++ uint32_t dma_cntrl; ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_TX_SW_DESC_LIST_CTRL_STS); ++ if (!(dma_cntrl & DMA_START_BIT)) { ++ dma_cntrl |= DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_TX_SW_DESC_LIST_CTRL_STS, ++ dma_cntrl); ++ } ++ ++ return; ++} ++ ++/* _CHECK_THIS_ ++ * ++ * Verify if the Stop generates a completion interrupt or not. ++ * if it does not generate an interrupt, then add polling here. ++ */ ++static BC_STATUS crystalhd_stop_tx_dma_engine(struct crystalhd_hw *hw) ++{ ++ uint32_t dma_cntrl, cnt = 30; ++ uint32_t l1 = 1, l2 = 1; ++ unsigned long flags = 0; ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_TX_SW_DESC_LIST_CTRL_STS); ++ ++ BCMLOG(BCMLOG_DBG, "Stopping TX DMA Engine..\n"); ++ ++ /* FIXME: jarod: invert dma_ctrl and check bit? or are there missing parens? */ ++ if (!dma_cntrl & DMA_START_BIT) { ++ BCMLOG(BCMLOG_DBG, "Already Stopped\n"); ++ return BC_STS_SUCCESS; ++ } ++ ++ crystalhd_disable_interrupts(hw->adp); ++ ++ /* Issue stop to HW */ ++ /* This bit when set gave problems. Please check*/ ++ dma_cntrl &= ~DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_TX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ ++ BCMLOG(BCMLOG_DBG, "Cleared the DMA Start bit\n"); ++ ++ /* Poll for 3seconds (30 * 100ms) on both the lists..*/ ++ while ((l1 || l2) && cnt) { ++ ++ if (l1) { ++ l1 = crystalhd_reg_rd(hw->adp, MISC1_TX_FIRST_DESC_L_ADDR_LIST0); ++ l1 &= DMA_START_BIT; ++ } ++ ++ if (l2) { ++ l2 = crystalhd_reg_rd(hw->adp, MISC1_TX_FIRST_DESC_L_ADDR_LIST1); ++ l2 &= DMA_START_BIT; ++ } ++ ++ msleep_interruptible(100); ++ ++ cnt--; ++ } ++ ++ if (!cnt) { ++ BCMLOG_ERR("Failed to stop TX DMA.. l1 %d, l2 %d\n", l1, l2); ++ crystalhd_enable_interrupts(hw->adp); ++ return BC_STS_ERROR; ++ } ++ ++ spin_lock_irqsave(&hw->lock, flags); ++ hw->tx_list_post_index = 0; ++ spin_unlock_irqrestore(&hw->lock, flags); ++ BCMLOG(BCMLOG_DBG, "stopped TX DMA..\n"); ++ crystalhd_enable_interrupts(hw->adp); ++ ++ return BC_STS_SUCCESS; ++} ++ ++static uint32_t crystalhd_get_pib_avail_cnt(struct crystalhd_hw *hw) ++{ ++ /* ++ * Position of the PIB Entries can be found at ++ * 0th and the 1st location of the Circular list. ++ */ ++ uint32_t Q_addr; ++ uint32_t pib_cnt, r_offset, w_offset; ++ ++ Q_addr = hw->pib_del_Q_addr; ++ ++ /* Get the Read Pointer */ ++ crystalhd_mem_rd(hw->adp, Q_addr, 1, &r_offset); ++ ++ /* Get the Write Pointer */ ++ crystalhd_mem_rd(hw->adp, Q_addr + sizeof(uint32_t), 1, &w_offset); ++ ++ if (r_offset == w_offset) ++ return 0; /* Queue is empty */ ++ ++ if (w_offset > r_offset) ++ pib_cnt = w_offset - r_offset; ++ else ++ pib_cnt = (w_offset + MAX_PIB_Q_DEPTH) - ++ (r_offset + MIN_PIB_Q_DEPTH); ++ ++ if (pib_cnt > MAX_PIB_Q_DEPTH) { ++ BCMLOG_ERR("Invalid PIB Count (%u)\n", pib_cnt); ++ return 0; ++ } ++ ++ return pib_cnt; ++} ++ ++static uint32_t crystalhd_get_addr_from_pib_Q(struct crystalhd_hw *hw) ++{ ++ uint32_t Q_addr; ++ uint32_t addr_entry, r_offset, w_offset; ++ ++ Q_addr = hw->pib_del_Q_addr; ++ ++ /* Get the Read Pointer 0Th Location is Read Pointer */ ++ crystalhd_mem_rd(hw->adp, Q_addr, 1, &r_offset); ++ ++ /* Get the Write Pointer 1st Location is Write pointer */ ++ crystalhd_mem_rd(hw->adp, Q_addr + sizeof(uint32_t), 1, &w_offset); ++ ++ /* Queue is empty */ ++ if (r_offset == w_offset) ++ return 0; ++ ++ if ((r_offset < MIN_PIB_Q_DEPTH) || (r_offset >= MAX_PIB_Q_DEPTH)) ++ return 0; ++ ++ /* Get the Actual Address of the PIB */ ++ crystalhd_mem_rd(hw->adp, Q_addr + (r_offset * sizeof(uint32_t)), ++ 1, &addr_entry); ++ ++ /* Increment the Read Pointer */ ++ r_offset++; ++ ++ if (MAX_PIB_Q_DEPTH == r_offset) ++ r_offset = MIN_PIB_Q_DEPTH; ++ ++ /* Write back the read pointer to It's Location */ ++ crystalhd_mem_wr(hw->adp, Q_addr, 1, &r_offset); ++ ++ return addr_entry; ++} ++ ++static bool crystalhd_rel_addr_to_pib_Q(struct crystalhd_hw *hw, uint32_t addr_to_rel) ++{ ++ uint32_t Q_addr; ++ uint32_t r_offset, w_offset, n_offset; ++ ++ Q_addr = hw->pib_rel_Q_addr; ++ ++ /* Get the Read Pointer */ ++ crystalhd_mem_rd(hw->adp, Q_addr, 1, &r_offset); ++ ++ /* Get the Write Pointer */ ++ crystalhd_mem_rd(hw->adp, Q_addr + sizeof(uint32_t), 1, &w_offset); ++ ++ if ((r_offset < MIN_PIB_Q_DEPTH) || ++ (r_offset >= MAX_PIB_Q_DEPTH)) ++ return false; ++ ++ n_offset = w_offset + 1; ++ ++ if (MAX_PIB_Q_DEPTH == n_offset) ++ n_offset = MIN_PIB_Q_DEPTH; ++ ++ if (r_offset == n_offset) ++ return false; /* should never happen */ ++ ++ /* Write the DRAM ADDR to the Queue at Next Offset */ ++ crystalhd_mem_wr(hw->adp, Q_addr + (w_offset * sizeof(uint32_t)), ++ 1, &addr_to_rel); ++ ++ /* Put the New value of the write pointer in Queue */ ++ crystalhd_mem_wr(hw->adp, Q_addr + sizeof(uint32_t), 1, &n_offset); ++ ++ return true; ++} ++ ++static void cpy_pib_to_app(C011_PIB *src_pib, BC_PIC_INFO_BLOCK *dst_pib) ++{ ++ if (!src_pib || !dst_pib) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return; ++ } ++ ++ dst_pib->timeStamp = 0; ++ dst_pib->picture_number = src_pib->ppb.picture_number; ++ dst_pib->width = src_pib->ppb.width; ++ dst_pib->height = src_pib->ppb.height; ++ dst_pib->chroma_format = src_pib->ppb.chroma_format; ++ dst_pib->pulldown = src_pib->ppb.pulldown; ++ dst_pib->flags = src_pib->ppb.flags; ++ dst_pib->sess_num = src_pib->ptsStcOffset; ++ dst_pib->aspect_ratio = src_pib->ppb.aspect_ratio; ++ dst_pib->colour_primaries = src_pib->ppb.colour_primaries; ++ dst_pib->picture_meta_payload = src_pib->ppb.picture_meta_payload; ++ dst_pib->frame_rate = src_pib->resolution ; ++ return; ++} ++ ++static void crystalhd_hw_proc_pib(struct crystalhd_hw *hw) ++{ ++ unsigned int cnt; ++ C011_PIB src_pib; ++ uint32_t pib_addr, pib_cnt; ++ BC_PIC_INFO_BLOCK *AppPib; ++ crystalhd_rx_dma_pkt *rx_pkt = NULL; ++ ++ pib_cnt = crystalhd_get_pib_avail_cnt(hw); ++ ++ if (!pib_cnt) ++ return; ++ ++ for (cnt = 0; cnt < pib_cnt; cnt++) { ++ ++ pib_addr = crystalhd_get_addr_from_pib_Q(hw); ++ crystalhd_mem_rd(hw->adp, pib_addr, sizeof(C011_PIB) / 4, ++ (uint32_t *)&src_pib); ++ ++ if (src_pib.bFormatChange) { ++ rx_pkt = (crystalhd_rx_dma_pkt *)crystalhd_dioq_fetch(hw->rx_freeq); ++ if (!rx_pkt) ++ return; ++ rx_pkt->flags = 0; ++ rx_pkt->flags |= COMP_FLAG_PIB_VALID | COMP_FLAG_FMT_CHANGE; ++ AppPib = &rx_pkt->pib; ++ cpy_pib_to_app(&src_pib, AppPib); ++ ++ BCMLOG(BCMLOG_DBG, ++ "App PIB:%x %x %x %x %x %x %x %x %x %x\n", ++ rx_pkt->pib.picture_number, ++ rx_pkt->pib.aspect_ratio, ++ rx_pkt->pib.chroma_format, ++ rx_pkt->pib.colour_primaries, ++ rx_pkt->pib.frame_rate, ++ rx_pkt->pib.height, ++ rx_pkt->pib.height, ++ rx_pkt->pib.n_drop, ++ rx_pkt->pib.pulldown, ++ rx_pkt->pib.ycom); ++ ++ crystalhd_dioq_add(hw->rx_rdyq, (void *)rx_pkt, true, rx_pkt->pkt_tag); ++ ++ } ++ ++ crystalhd_rel_addr_to_pib_Q(hw, pib_addr); ++ } ++} ++ ++static void crystalhd_start_rx_dma_engine(struct crystalhd_hw *hw) ++{ ++ uint32_t dma_cntrl; ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); ++ if (!(dma_cntrl & DMA_START_BIT)) { ++ dma_cntrl |= DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ } ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); ++ if (!(dma_cntrl & DMA_START_BIT)) { ++ dma_cntrl |= DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ } ++ ++ return; ++} ++ ++static void crystalhd_stop_rx_dma_engine(struct crystalhd_hw *hw) ++{ ++ uint32_t dma_cntrl = 0, count = 30; ++ uint32_t l0y = 1, l0uv = 1, l1y = 1, l1uv = 1; ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); ++ if ((dma_cntrl & DMA_START_BIT)) { ++ dma_cntrl &= ~DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ } ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); ++ if ((dma_cntrl & DMA_START_BIT)) { ++ dma_cntrl &= ~DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ } ++ ++ /* Poll for 3seconds (30 * 100ms) on both the lists..*/ ++ while ((l0y || l0uv || l1y || l1uv) && count) { ++ ++ if (l0y) { ++ l0y = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST0); ++ l0y &= DMA_START_BIT; ++ if (!l0y) { ++ hw->rx_list_sts[0] &= ~rx_waiting_y_intr; ++ } ++ } ++ ++ if (l1y) { ++ l1y = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST1); ++ l1y &= DMA_START_BIT; ++ if (!l1y) { ++ hw->rx_list_sts[1] &= ~rx_waiting_y_intr; ++ } ++ } ++ ++ if (l0uv) { ++ l0uv = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST0); ++ l0uv &= DMA_START_BIT; ++ if (!l0uv) { ++ hw->rx_list_sts[0] &= ~rx_waiting_uv_intr; ++ } ++ } ++ ++ if (l1uv) { ++ l1uv = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST1); ++ l1uv &= DMA_START_BIT; ++ if (!l1uv) { ++ hw->rx_list_sts[1] &= ~rx_waiting_uv_intr; ++ } ++ } ++ msleep_interruptible(100); ++ count--; ++ } ++ ++ hw->rx_list_post_index = 0; ++ ++ BCMLOG(BCMLOG_SSTEP, "Capture Stop: %d List0:Sts:%x List1:Sts:%x\n", ++ count, hw->rx_list_sts[0], hw->rx_list_sts[1]); ++} ++ ++static BC_STATUS crystalhd_hw_prog_rxdma(struct crystalhd_hw *hw, crystalhd_rx_dma_pkt *rx_pkt) ++{ ++ uint32_t y_low_addr_reg, y_high_addr_reg; ++ uint32_t uv_low_addr_reg, uv_high_addr_reg; ++ addr_64 desc_addr; ++ unsigned long flags; ++ ++ if (!hw || !rx_pkt) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (hw->rx_list_post_index >= DMA_ENGINE_CNT) { ++ BCMLOG_ERR("List Out Of bounds %x\n", hw->rx_list_post_index); ++ return BC_STS_INV_ARG; ++ } ++ ++ spin_lock_irqsave(&hw->rx_lock, flags); ++ /* FIXME: jarod: sts_free is an enum for 0, in crystalhd_hw.h... yuk... */ ++ if (sts_free != hw->rx_list_sts[hw->rx_list_post_index]) { ++ spin_unlock_irqrestore(&hw->rx_lock, flags); ++ return BC_STS_BUSY; ++ } ++ ++ if (!hw->rx_list_post_index) { ++ y_low_addr_reg = MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST0; ++ y_high_addr_reg = MISC1_Y_RX_FIRST_DESC_U_ADDR_LIST0; ++ uv_low_addr_reg = MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST0; ++ uv_high_addr_reg = MISC1_UV_RX_FIRST_DESC_U_ADDR_LIST0; ++ } else { ++ y_low_addr_reg = MISC1_Y_RX_FIRST_DESC_L_ADDR_LIST1; ++ y_high_addr_reg = MISC1_Y_RX_FIRST_DESC_U_ADDR_LIST1; ++ uv_low_addr_reg = MISC1_UV_RX_FIRST_DESC_L_ADDR_LIST1; ++ uv_high_addr_reg = MISC1_UV_RX_FIRST_DESC_U_ADDR_LIST1; ++ } ++ rx_pkt->pkt_tag = hw->rx_pkt_tag_seed + hw->rx_list_post_index; ++ hw->rx_list_sts[hw->rx_list_post_index] |= rx_waiting_y_intr; ++ if (rx_pkt->uv_phy_addr) ++ hw->rx_list_sts[hw->rx_list_post_index] |= rx_waiting_uv_intr; ++ hw->rx_list_post_index = (hw->rx_list_post_index + 1) % DMA_ENGINE_CNT; ++ spin_unlock_irqrestore(&hw->rx_lock, flags); ++ ++ crystalhd_dioq_add(hw->rx_actq, (void *)rx_pkt, false, rx_pkt->pkt_tag); ++ ++ crystalhd_start_rx_dma_engine(hw); ++ /* Program the Y descriptor */ ++ desc_addr.full_addr = rx_pkt->desc_mem.phy_addr; ++ crystalhd_reg_wr(hw->adp, y_high_addr_reg, desc_addr.high_part); ++ crystalhd_reg_wr(hw->adp, y_low_addr_reg, desc_addr.low_part | 0x01); ++ ++ if (rx_pkt->uv_phy_addr) { ++ /* Program the UV descriptor */ ++ desc_addr.full_addr = rx_pkt->uv_phy_addr; ++ crystalhd_reg_wr(hw->adp, uv_high_addr_reg, desc_addr.high_part); ++ crystalhd_reg_wr(hw->adp, uv_low_addr_reg, desc_addr.low_part | 0x01); ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++static BC_STATUS crystalhd_hw_post_cap_buff(struct crystalhd_hw *hw, ++ crystalhd_rx_dma_pkt *rx_pkt) ++{ ++ BC_STATUS sts = crystalhd_hw_prog_rxdma(hw, rx_pkt); ++ ++ if (sts == BC_STS_BUSY) ++ crystalhd_dioq_add(hw->rx_freeq, (void *)rx_pkt, ++ false, rx_pkt->pkt_tag); ++ ++ return sts; ++} ++ ++static void crystalhd_get_dnsz(struct crystalhd_hw *hw, uint32_t list_index, ++ uint32_t *y_dw_dnsz, uint32_t *uv_dw_dnsz) ++{ ++ uint32_t y_dn_sz_reg, uv_dn_sz_reg; ++ ++ if (!list_index) { ++ y_dn_sz_reg = MISC1_Y_RX_LIST0_CUR_BYTE_CNT; ++ uv_dn_sz_reg = MISC1_UV_RX_LIST0_CUR_BYTE_CNT; ++ } else { ++ y_dn_sz_reg = MISC1_Y_RX_LIST1_CUR_BYTE_CNT; ++ uv_dn_sz_reg = MISC1_UV_RX_LIST1_CUR_BYTE_CNT; ++ } ++ ++ *y_dw_dnsz = crystalhd_reg_rd(hw->adp, y_dn_sz_reg); ++ *uv_dw_dnsz = crystalhd_reg_rd(hw->adp, uv_dn_sz_reg); ++} ++ ++/* ++ * This function should be called only after making sure that the two DMA ++ * lists are free. This function does not check if DMA's are active, before ++ * turning off the DMA. ++ */ ++static void crystalhd_hw_finalize_pause(struct crystalhd_hw *hw) ++{ ++ uint32_t dma_cntrl, aspm; ++ ++ hw->stop_pending = 0; ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS); ++ if (dma_cntrl & DMA_START_BIT) { ++ dma_cntrl &= ~DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_Y_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ } ++ ++ dma_cntrl = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS); ++ if (dma_cntrl & DMA_START_BIT) { ++ dma_cntrl &= ~DMA_START_BIT; ++ crystalhd_reg_wr(hw->adp, MISC1_UV_RX_SW_DESC_LIST_CTRL_STS, dma_cntrl); ++ } ++ hw->rx_list_post_index = 0; ++ ++ aspm = crystalhd_reg_rd(hw->adp, PCIE_DLL_DATA_LINK_CONTROL); ++ aspm |= ASPM_L1_ENABLE; ++ /* NAREN BCMLOG(BCMLOG_INFO, "aspm on\n"); */ ++ crystalhd_reg_wr(hw->adp, PCIE_DLL_DATA_LINK_CONTROL, aspm); ++} ++ ++static BC_STATUS crystalhd_rx_pkt_done(struct crystalhd_hw *hw, uint32_t list_index, ++ BC_STATUS comp_sts) ++{ ++ crystalhd_rx_dma_pkt *rx_pkt = NULL; ++ uint32_t y_dw_dnsz, uv_dw_dnsz; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ if (!hw || list_index >= DMA_ENGINE_CNT) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ rx_pkt = crystalhd_dioq_find_and_fetch(hw->rx_actq, ++ hw->rx_pkt_tag_seed + list_index); ++ if (!rx_pkt) { ++ BCMLOG_ERR("Act-Q:PostIx:%x L0Sts:%x L1Sts:%x current L:%x tag:%x comp:%x\n", ++ hw->rx_list_post_index, hw->rx_list_sts[0], ++ hw->rx_list_sts[1], list_index, ++ hw->rx_pkt_tag_seed + list_index, comp_sts); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (comp_sts == BC_STS_SUCCESS) { ++ crystalhd_get_dnsz(hw, list_index, &y_dw_dnsz, &uv_dw_dnsz); ++ rx_pkt->dio_req->uinfo.y_done_sz = y_dw_dnsz; ++ rx_pkt->flags = COMP_FLAG_DATA_VALID; ++ if (rx_pkt->uv_phy_addr) ++ rx_pkt->dio_req->uinfo.uv_done_sz = uv_dw_dnsz; ++ crystalhd_dioq_add(hw->rx_rdyq, rx_pkt, true, ++ hw->rx_pkt_tag_seed + list_index); ++ return sts; ++ } ++ ++ /* Check if we can post this DIO again. */ ++ return crystalhd_hw_post_cap_buff(hw, rx_pkt); ++} ++ ++static bool crystalhd_rx_list0_handler(struct crystalhd_hw *hw, uint32_t int_sts, ++ uint32_t y_err_sts, uint32_t uv_err_sts) ++{ ++ uint32_t tmp; ++ list_sts tmp_lsts; ++ ++ if (!(y_err_sts & GET_Y0_ERR_MSK) && !(uv_err_sts & GET_UV0_ERR_MSK)) ++ return false; ++ ++ tmp_lsts = hw->rx_list_sts[0]; ++ ++ /* Y0 - DMA */ ++ tmp = y_err_sts & GET_Y0_ERR_MSK; ++ if (int_sts & INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_MASK) ++ hw->rx_list_sts[0] &= ~rx_waiting_y_intr; ++ ++ if (y_err_sts & MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK) { ++ hw->rx_list_sts[0] &= ~rx_waiting_y_intr; ++ tmp &= ~MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK; ++ } ++ ++ if (y_err_sts & MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) { ++ hw->rx_list_sts[0] &= ~rx_y_mask; ++ hw->rx_list_sts[0] |= rx_y_error; ++ tmp &= ~MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK; ++ } ++ ++ if (tmp) { ++ hw->rx_list_sts[0] &= ~rx_y_mask; ++ hw->rx_list_sts[0] |= rx_y_error; ++ hw->rx_list_post_index = 0; ++ } ++ ++ /* UV0 - DMA */ ++ tmp = uv_err_sts & GET_UV0_ERR_MSK; ++ if (int_sts & INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_MASK) ++ hw->rx_list_sts[0] &= ~rx_waiting_uv_intr; ++ ++ if (uv_err_sts & MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK) { ++ hw->rx_list_sts[0] &= ~rx_waiting_uv_intr; ++ tmp &= ~MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK; ++ } ++ ++ if (uv_err_sts & MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) { ++ hw->rx_list_sts[0] &= ~rx_uv_mask; ++ hw->rx_list_sts[0] |= rx_uv_error; ++ tmp &= ~MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK; ++ } ++ ++ if (tmp) { ++ hw->rx_list_sts[0] &= ~rx_uv_mask; ++ hw->rx_list_sts[0] |= rx_uv_error; ++ hw->rx_list_post_index = 0; ++ } ++ ++ if (y_err_sts & GET_Y0_ERR_MSK) { ++ tmp = y_err_sts & GET_Y0_ERR_MSK; ++ crystalhd_reg_wr(hw->adp, MISC1_Y_RX_ERROR_STATUS, tmp); ++ } ++ ++ if (uv_err_sts & GET_UV0_ERR_MSK) { ++ tmp = uv_err_sts & GET_UV0_ERR_MSK; ++ crystalhd_reg_wr(hw->adp, MISC1_UV_RX_ERROR_STATUS, tmp); ++ } ++ ++ return (tmp_lsts != hw->rx_list_sts[0]); ++} ++ ++static bool crystalhd_rx_list1_handler(struct crystalhd_hw *hw, uint32_t int_sts, ++ uint32_t y_err_sts, uint32_t uv_err_sts) ++{ ++ uint32_t tmp; ++ list_sts tmp_lsts; ++ ++ if (!(y_err_sts & GET_Y1_ERR_MSK) && !(uv_err_sts & GET_UV1_ERR_MSK)) ++ return false; ++ ++ tmp_lsts = hw->rx_list_sts[1]; ++ ++ /* Y1 - DMA */ ++ tmp = y_err_sts & GET_Y1_ERR_MSK; ++ if (int_sts & INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_MASK) ++ hw->rx_list_sts[1] &= ~rx_waiting_y_intr; ++ ++ if (y_err_sts & MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK) { ++ hw->rx_list_sts[1] &= ~rx_waiting_y_intr; ++ tmp &= ~MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK; ++ } ++ ++ if (y_err_sts & MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) { ++ /* Add retry-support..*/ ++ hw->rx_list_sts[1] &= ~rx_y_mask; ++ hw->rx_list_sts[1] |= rx_y_error; ++ tmp &= ~MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK; ++ } ++ ++ if (tmp) { ++ hw->rx_list_sts[1] &= ~rx_y_mask; ++ hw->rx_list_sts[1] |= rx_y_error; ++ hw->rx_list_post_index = 0; ++ } ++ ++ /* UV1 - DMA */ ++ tmp = uv_err_sts & GET_UV1_ERR_MSK; ++ if (int_sts & INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_MASK) { ++ hw->rx_list_sts[1] &= ~rx_waiting_uv_intr; ++ } ++ ++ if (uv_err_sts & MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK) { ++ hw->rx_list_sts[1] &= ~rx_waiting_uv_intr; ++ tmp &= ~MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK; ++ } ++ ++ if (uv_err_sts & MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) { ++ /* Add retry-support*/ ++ hw->rx_list_sts[1] &= ~rx_uv_mask; ++ hw->rx_list_sts[1] |= rx_uv_error; ++ tmp &= ~MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK; ++ } ++ ++ if (tmp) { ++ hw->rx_list_sts[1] &= ~rx_uv_mask; ++ hw->rx_list_sts[1] |= rx_uv_error; ++ hw->rx_list_post_index = 0; ++ } ++ ++ if (y_err_sts & GET_Y1_ERR_MSK) { ++ tmp = y_err_sts & GET_Y1_ERR_MSK; ++ crystalhd_reg_wr(hw->adp, MISC1_Y_RX_ERROR_STATUS, tmp); ++ } ++ ++ if (uv_err_sts & GET_UV1_ERR_MSK) { ++ tmp = uv_err_sts & GET_UV1_ERR_MSK; ++ crystalhd_reg_wr(hw->adp, MISC1_UV_RX_ERROR_STATUS, tmp); ++ } ++ ++ return (tmp_lsts != hw->rx_list_sts[1]); ++} ++ ++ ++static void crystalhd_rx_isr(struct crystalhd_hw *hw, uint32_t intr_sts) ++{ ++ unsigned long flags; ++ uint32_t i, list_avail = 0; ++ BC_STATUS comp_sts = BC_STS_NO_DATA; ++ uint32_t y_err_sts, uv_err_sts, y_dn_sz = 0, uv_dn_sz = 0; ++ bool ret = 0; ++ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return; ++ } ++ ++ if (!(intr_sts & GET_RX_INTR_MASK)) ++ return; ++ ++ y_err_sts = crystalhd_reg_rd(hw->adp, MISC1_Y_RX_ERROR_STATUS); ++ uv_err_sts = crystalhd_reg_rd(hw->adp, MISC1_UV_RX_ERROR_STATUS); ++ ++ for (i = 0; i < DMA_ENGINE_CNT; i++) { ++ /* Update States..*/ ++ spin_lock_irqsave(&hw->rx_lock, flags); ++ if (i == 0) ++ ret = crystalhd_rx_list0_handler(hw, intr_sts, y_err_sts, uv_err_sts); ++ else ++ ret = crystalhd_rx_list1_handler(hw, intr_sts, y_err_sts, uv_err_sts); ++ if (ret) { ++ switch (hw->rx_list_sts[i]) { ++ case sts_free: ++ comp_sts = BC_STS_SUCCESS; ++ list_avail = 1; ++ break; ++ case rx_y_error: ++ case rx_uv_error: ++ case rx_sts_error: ++ /* We got error on both or Y or uv. */ ++ hw->stats.rx_errors++; ++ crystalhd_get_dnsz(hw, i, &y_dn_sz, &uv_dn_sz); ++ /* FIXME: jarod: this is where my mini pci-e card is tripping up */ ++ BCMLOG(BCMLOG_DBG, "list_index:%x rx[%d] Y:%x " ++ "UV:%x Int:%x YDnSz:%x UVDnSz:%x\n", ++ i, hw->stats.rx_errors, y_err_sts, ++ uv_err_sts, intr_sts, y_dn_sz, uv_dn_sz); ++ hw->rx_list_sts[i] = sts_free; ++ comp_sts = BC_STS_ERROR; ++ break; ++ default: ++ /* Wait for completion..*/ ++ comp_sts = BC_STS_NO_DATA; ++ break; ++ } ++ } ++ spin_unlock_irqrestore(&hw->rx_lock, flags); ++ ++ /* handle completion...*/ ++ if (comp_sts != BC_STS_NO_DATA) { ++ crystalhd_rx_pkt_done(hw, i, comp_sts); ++ comp_sts = BC_STS_NO_DATA; ++ } ++ } ++ ++ if (list_avail) { ++ if (hw->stop_pending) { ++ if ((hw->rx_list_sts[0] == sts_free) && ++ (hw->rx_list_sts[1] == sts_free)) ++ crystalhd_hw_finalize_pause(hw); ++ } else { ++ crystalhd_hw_start_capture(hw); ++ } ++ } ++} ++ ++static BC_STATUS crystalhd_fw_cmd_post_proc(struct crystalhd_hw *hw, ++ BC_FW_CMD *fw_cmd) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ DecRspChannelStartVideo *st_rsp = NULL; ++ ++ switch (fw_cmd->cmd[0]) { ++ case eCMD_C011_DEC_CHAN_START_VIDEO: ++ st_rsp = (DecRspChannelStartVideo *)fw_cmd->rsp; ++ hw->pib_del_Q_addr = st_rsp->picInfoDeliveryQ; ++ hw->pib_rel_Q_addr = st_rsp->picInfoReleaseQ; ++ BCMLOG(BCMLOG_DBG, "DelQAddr:%x RelQAddr:%x\n", ++ hw->pib_del_Q_addr, hw->pib_rel_Q_addr); ++ break; ++ case eCMD_C011_INIT: ++ if (!(crystalhd_load_firmware_config(hw->adp))) { ++ BCMLOG_ERR("Invalid Params.\n"); ++ sts = BC_STS_FW_AUTH_FAILED; ++ } ++ break; ++ default: ++ break; ++ } ++ return sts; ++} ++ ++static BC_STATUS crystalhd_put_ddr2sleep(struct crystalhd_hw *hw) ++{ ++ uint32_t reg; ++ link_misc_perst_decoder_ctrl rst_cntrl_reg; ++ ++ /* Pulse reset pin of 7412 (MISC_PERST_DECODER_CTRL) */ ++ rst_cntrl_reg.whole_reg = crystalhd_reg_rd(hw->adp, MISC_PERST_DECODER_CTRL); ++ ++ rst_cntrl_reg.bcm_7412_rst = 1; ++ crystalhd_reg_wr(hw->adp, MISC_PERST_DECODER_CTRL, rst_cntrl_reg.whole_reg); ++ msleep_interruptible(50); ++ ++ rst_cntrl_reg.bcm_7412_rst = 0; ++ crystalhd_reg_wr(hw->adp, MISC_PERST_DECODER_CTRL, rst_cntrl_reg.whole_reg); ++ ++ /* Close all banks, put DDR in idle */ ++ bc_dec_reg_wr(hw->adp, SDRAM_PRECHARGE, 0); ++ ++ /* Set bit 25 (drop CKE pin of DDR) */ ++ reg = bc_dec_reg_rd(hw->adp, SDRAM_PARAM); ++ reg |= 0x02000000; ++ bc_dec_reg_wr(hw->adp, SDRAM_PARAM, reg); ++ ++ /* Reset the audio block */ ++ bc_dec_reg_wr(hw->adp, AUD_DSP_MISC_SOFT_RESET, 0x1); ++ ++ /* Power down Raptor PLL */ ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllCCtl); ++ reg |= 0x00008000; ++ bc_dec_reg_wr(hw->adp, DecHt_PllCCtl, reg); ++ ++ /* Power down all Audio PLL */ ++ bc_dec_reg_wr(hw->adp, AIO_MISC_PLL_RESET, 0x1); ++ ++ /* Power down video clock (75MHz) */ ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllECtl); ++ reg |= 0x00008000; ++ bc_dec_reg_wr(hw->adp, DecHt_PllECtl, reg); ++ ++ /* Power down video clock (75MHz) */ ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllDCtl); ++ reg |= 0x00008000; ++ bc_dec_reg_wr(hw->adp, DecHt_PllDCtl, reg); ++ ++ /* Power down core clock (200MHz) */ ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllACtl); ++ reg |= 0x00008000; ++ bc_dec_reg_wr(hw->adp, DecHt_PllACtl, reg); ++ ++ /* Power down core clock (200MHz) */ ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllBCtl); ++ reg |= 0x00008000; ++ bc_dec_reg_wr(hw->adp, DecHt_PllBCtl, reg); ++ ++ return BC_STS_SUCCESS; ++} ++ ++/************************************************ ++** ++*************************************************/ ++ ++BC_STATUS crystalhd_download_fw(struct crystalhd_adp *adp, void *buffer, uint32_t sz) ++{ ++ uint32_t reg_data, cnt, *temp_buff; ++ uint32_t fw_sig_len = 36; ++ uint32_t dram_offset = BC_FWIMG_ST_ADDR, sig_reg; ++ ++ BCMLOG_ENTER; ++ ++ if (!adp || !buffer || !sz) { ++ BCMLOG_ERR("Invalid Params.\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ reg_data = crystalhd_reg_rd(adp, OTP_CMD); ++ if (!(reg_data & 0x02)) { ++ BCMLOG_ERR("Invalid hw config.. otp not programmed\n"); ++ return BC_STS_ERROR; ++ } ++ ++ reg_data = 0; ++ crystalhd_reg_wr(adp, DCI_CMD, 0); ++ reg_data |= BC_BIT(0); ++ crystalhd_reg_wr(adp, DCI_CMD, reg_data); ++ ++ reg_data = 0; ++ cnt = 1000; ++ msleep_interruptible(10); ++ ++ while (reg_data != BC_BIT(4)) { ++ reg_data = crystalhd_reg_rd(adp, DCI_STATUS); ++ reg_data &= BC_BIT(4); ++ if (--cnt == 0) { ++ BCMLOG_ERR("Firmware Download RDY Timeout.\n"); ++ return BC_STS_TIMEOUT; ++ } ++ } ++ ++ msleep_interruptible(10); ++ /* Load the FW to the FW_ADDR field in the DCI_FIRMWARE_ADDR */ ++ crystalhd_reg_wr(adp, DCI_FIRMWARE_ADDR, dram_offset); ++ temp_buff = (uint32_t *)buffer; ++ for (cnt = 0; cnt < (sz - fw_sig_len); cnt += 4) { ++ crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (dram_offset >> 19)); ++ crystalhd_reg_wr(adp, DCI_FIRMWARE_DATA, *temp_buff); ++ dram_offset += 4; ++ temp_buff++; ++ } ++ msleep_interruptible(10); ++ ++ temp_buff++; ++ ++ sig_reg = (uint32_t)DCI_SIGNATURE_DATA_7; ++ for (cnt = 0; cnt < 8; cnt++) { ++ uint32_t swapped_data = *temp_buff; ++ swapped_data = bswap_32_1(swapped_data); ++ crystalhd_reg_wr(adp, sig_reg, swapped_data); ++ sig_reg -= 4; ++ temp_buff++; ++ } ++ msleep_interruptible(10); ++ ++ reg_data = 0; ++ reg_data |= BC_BIT(1); ++ crystalhd_reg_wr(adp, DCI_CMD, reg_data); ++ msleep_interruptible(10); ++ ++ reg_data = 0; ++ reg_data = crystalhd_reg_rd(adp, DCI_STATUS); ++ ++ if ((reg_data & BC_BIT(9)) == BC_BIT(9)) { ++ cnt = 1000; ++ while ((reg_data & BC_BIT(0)) != BC_BIT(0)) { ++ reg_data = crystalhd_reg_rd(adp, DCI_STATUS); ++ reg_data &= BC_BIT(0); ++ if (!(--cnt)) ++ break; ++ msleep_interruptible(10); ++ } ++ reg_data = 0; ++ reg_data = crystalhd_reg_rd(adp, DCI_CMD); ++ reg_data |= BC_BIT(4); ++ crystalhd_reg_wr(adp, DCI_CMD, reg_data); ++ ++ } else { ++ BCMLOG_ERR("F/w Signature mismatch\n"); ++ return BC_STS_FW_AUTH_FAILED; ++ } ++ ++ BCMLOG(BCMLOG_INFO, "Firmware Downloaded Successfully\n"); ++ return BC_STS_SUCCESS;; ++} ++ ++BC_STATUS crystalhd_do_fw_cmd(struct crystalhd_hw *hw, BC_FW_CMD *fw_cmd) ++{ ++ uint32_t cnt = 0, cmd_res_addr; ++ uint32_t *cmd_buff, *res_buff; ++ wait_queue_head_t fw_cmd_event; ++ int rc = 0; ++ BC_STATUS sts; ++ ++ crystalhd_create_event(&fw_cmd_event); ++ ++ BCMLOG_ENTER; ++ ++ if (!hw || !fw_cmd) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ cmd_buff = fw_cmd->cmd; ++ res_buff = fw_cmd->rsp; ++ ++ if (!cmd_buff || !res_buff) { ++ BCMLOG_ERR("Invalid Parameters for F/W Command \n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ hw->pwr_lock++; ++ ++ hw->fwcmd_evt_sts = 0; ++ hw->pfw_cmd_event = &fw_cmd_event; ++ ++ /*Write the command to the memory*/ ++ crystalhd_mem_wr(hw->adp, TS_Host2CpuSnd, FW_CMD_BUFF_SZ, cmd_buff); ++ ++ /*Memory Read for memory arbitrator flush*/ ++ crystalhd_mem_rd(hw->adp, TS_Host2CpuSnd, 1, &cnt); ++ ++ /* Write the command address to mailbox */ ++ bc_dec_reg_wr(hw->adp, Hst2CpuMbx1, TS_Host2CpuSnd); ++ msleep_interruptible(50); ++ ++ crystalhd_wait_on_event(&fw_cmd_event, hw->fwcmd_evt_sts, 20000, rc, 0); ++ ++ if (!rc) { ++ sts = BC_STS_SUCCESS; ++ } else if (rc == -EBUSY) { ++ BCMLOG_ERR("Firmware command T/O\n"); ++ sts = BC_STS_TIMEOUT; ++ } else if (rc == -EINTR) { ++ BCMLOG(BCMLOG_DBG, "FwCmd Wait Signal int.\n"); ++ sts = BC_STS_IO_USER_ABORT; ++ } else { ++ BCMLOG_ERR("FwCmd IO Error.\n"); ++ sts = BC_STS_IO_ERROR; ++ } ++ ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("FwCmd Failed.\n"); ++ hw->pwr_lock--; ++ return sts; ++ } ++ ++ /*Get the Responce Address*/ ++ cmd_res_addr = bc_dec_reg_rd(hw->adp, Cpu2HstMbx1); ++ ++ /*Read the Response*/ ++ crystalhd_mem_rd(hw->adp, cmd_res_addr, FW_CMD_BUFF_SZ, res_buff); ++ ++ hw->pwr_lock--; ++ ++ if (res_buff[2] != C011_RET_SUCCESS) { ++ BCMLOG_ERR("res_buff[2] != C011_RET_SUCCESS\n"); ++ return BC_STS_FW_CMD_ERR; ++ } ++ ++ sts = crystalhd_fw_cmd_post_proc(hw, fw_cmd); ++ if (sts != BC_STS_SUCCESS) ++ BCMLOG_ERR("crystalhd_fw_cmd_post_proc Failed.\n"); ++ ++ return sts; ++} ++ ++bool crystalhd_hw_interrupt(struct crystalhd_adp *adp, struct crystalhd_hw *hw) ++{ ++ uint32_t intr_sts = 0; ++ uint32_t deco_intr = 0; ++ bool rc = 0; ++ ++ if (!adp || !hw->dev_started) ++ return rc; ++ ++ hw->stats.num_interrupts++; ++ hw->pwr_lock++; ++ ++ deco_intr = bc_dec_reg_rd(adp, Stream2Host_Intr_Sts); ++ intr_sts = crystalhd_reg_rd(adp, INTR_INTR_STATUS); ++ ++ if (intr_sts) { ++ /* let system know we processed interrupt..*/ ++ rc = 1; ++ hw->stats.dev_interrupts++; ++ } ++ ++ if (deco_intr && (deco_intr != 0xdeaddead)) { ++ ++ if (deco_intr & 0x80000000) { ++ /*Set the Event and the status flag*/ ++ if (hw->pfw_cmd_event) { ++ hw->fwcmd_evt_sts = 1; ++ crystalhd_set_event(hw->pfw_cmd_event); ++ } ++ } ++ ++ if (deco_intr & BC_BIT(1)) ++ crystalhd_hw_proc_pib(hw); ++ ++ bc_dec_reg_wr(adp, Stream2Host_Intr_Sts, deco_intr); ++ /* FIXME: jarod: No udelay? might this be the real reason mini pci-e cards were stalling out? */ ++ bc_dec_reg_wr(adp, Stream2Host_Intr_Sts, 0); ++ rc = 1; ++ } ++ ++ /* Rx interrupts */ ++ crystalhd_rx_isr(hw, intr_sts); ++ ++ /* Tx interrupts*/ ++ crystalhd_tx_isr(hw, intr_sts); ++ ++ /* Clear interrupts */ ++ if (rc) { ++ if (intr_sts) ++ crystalhd_reg_wr(adp, INTR_INTR_CLR_REG, intr_sts); ++ ++ crystalhd_reg_wr(adp, INTR_EOI_CTRL, 1); ++ } ++ ++ hw->pwr_lock--; ++ ++ return rc; ++} ++ ++BC_STATUS crystalhd_hw_open(struct crystalhd_hw *hw, struct crystalhd_adp *adp) ++{ ++ if (!hw || !adp) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (hw->dev_started) ++ return BC_STS_SUCCESS; ++ ++ memset(hw, 0, sizeof(struct crystalhd_hw)); ++ ++ hw->adp = adp; ++ spin_lock_init(&hw->lock); ++ spin_lock_init(&hw->rx_lock); ++ /* FIXME: jarod: what are these magic numbers?!? */ ++ hw->tx_ioq_tag_seed = 0x70023070; ++ hw->rx_pkt_tag_seed = 0x70029070; ++ ++ hw->stop_pending = 0; ++ crystalhd_start_device(hw->adp); ++ hw->dev_started = true; ++ ++ /* set initial core clock */ ++ hw->core_clock_mhz = CLOCK_PRESET; ++ hw->prev_n = 0; ++ hw->pwr_lock = 0; ++ crystalhd_hw_set_core_clock(hw); ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_close(struct crystalhd_hw *hw) ++{ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if (!hw->dev_started) ++ return BC_STS_SUCCESS; ++ ++ /* Stop and DDR sleep will happen in here */ ++ crystalhd_hw_suspend(hw); ++ hw->dev_started = false; ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_setup_dma_rings(struct crystalhd_hw *hw) ++{ ++ unsigned int i; ++ void *mem; ++ size_t mem_len; ++ dma_addr_t phy_addr; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ crystalhd_rx_dma_pkt *rpkt; ++ ++ if (!hw || !hw->adp) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ sts = crystalhd_hw_create_ioqs(hw); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("Failed to create IOQs..\n"); ++ return sts; ++ } ++ ++ mem_len = BC_LINK_MAX_SGLS * sizeof(dma_descriptor); ++ ++ for (i = 0; i < BC_TX_LIST_CNT; i++) { ++ mem = bc_kern_dma_alloc(hw->adp, mem_len, &phy_addr); ++ if (mem) { ++ memset(mem, 0, mem_len); ++ } else { ++ BCMLOG_ERR("Insufficient Memory For TX\n"); ++ crystalhd_hw_free_dma_rings(hw); ++ return BC_STS_INSUFF_RES; ++ } ++ /* rx_pkt_pool -- static memory allocation */ ++ hw->tx_pkt_pool[i].desc_mem.pdma_desc_start = mem; ++ hw->tx_pkt_pool[i].desc_mem.phy_addr = phy_addr; ++ hw->tx_pkt_pool[i].desc_mem.sz = BC_LINK_MAX_SGLS * ++ sizeof(dma_descriptor); ++ hw->tx_pkt_pool[i].list_tag = 0; ++ ++ /* Add TX dma requests to Free Queue..*/ ++ sts = crystalhd_dioq_add(hw->tx_freeq, ++ &hw->tx_pkt_pool[i], false, 0); ++ if (sts != BC_STS_SUCCESS) { ++ crystalhd_hw_free_dma_rings(hw); ++ return sts; ++ } ++ } ++ ++ for (i = 0; i < BC_RX_LIST_CNT; i++) { ++ rpkt = kzalloc(sizeof(*rpkt), GFP_KERNEL); ++ if (!rpkt) { ++ BCMLOG_ERR("Insufficient Memory For RX\n"); ++ crystalhd_hw_free_dma_rings(hw); ++ return BC_STS_INSUFF_RES; ++ } ++ ++ mem = bc_kern_dma_alloc(hw->adp, mem_len, &phy_addr); ++ if (mem) { ++ memset(mem, 0, mem_len); ++ } else { ++ BCMLOG_ERR("Insufficient Memory For RX\n"); ++ crystalhd_hw_free_dma_rings(hw); ++ return BC_STS_INSUFF_RES; ++ } ++ rpkt->desc_mem.pdma_desc_start = mem; ++ rpkt->desc_mem.phy_addr = phy_addr; ++ rpkt->desc_mem.sz = BC_LINK_MAX_SGLS * sizeof(dma_descriptor); ++ rpkt->pkt_tag = hw->rx_pkt_tag_seed + i; ++ crystalhd_hw_free_rx_pkt(hw, rpkt); ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_free_dma_rings(struct crystalhd_hw *hw) ++{ ++ unsigned int i; ++ crystalhd_rx_dma_pkt *rpkt = NULL; ++ ++ if (!hw || !hw->adp) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ /* Delete all IOQs.. */ ++ crystalhd_hw_delete_ioqs(hw); ++ ++ for (i = 0; i < BC_TX_LIST_CNT; i++) { ++ if (hw->tx_pkt_pool[i].desc_mem.pdma_desc_start) { ++ bc_kern_dma_free(hw->adp, ++ hw->tx_pkt_pool[i].desc_mem.sz, ++ hw->tx_pkt_pool[i].desc_mem.pdma_desc_start, ++ hw->tx_pkt_pool[i].desc_mem.phy_addr); ++ ++ hw->tx_pkt_pool[i].desc_mem.pdma_desc_start = NULL; ++ } ++ } ++ ++ BCMLOG(BCMLOG_DBG, "Releasing RX Pkt pool\n"); ++ do { ++ rpkt = crystalhd_hw_alloc_rx_pkt(hw); ++ if (!rpkt) ++ break; ++ bc_kern_dma_free(hw->adp, rpkt->desc_mem.sz, ++ rpkt->desc_mem.pdma_desc_start, ++ rpkt->desc_mem.phy_addr); ++ kfree(rpkt); ++ } while (rpkt); ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, crystalhd_dio_req *ioreq, ++ hw_comp_callback call_back, ++ wait_queue_head_t *cb_event, uint32_t *list_id, ++ uint8_t data_flags) ++{ ++ tx_dma_pkt *tx_dma_packet = NULL; ++ uint32_t first_desc_u_addr, first_desc_l_addr; ++ uint32_t low_addr, high_addr; ++ addr_64 desc_addr; ++ BC_STATUS sts, add_sts; ++ uint32_t dummy_index = 0; ++ unsigned long flags; ++ bool rc; ++ ++ if (!hw || !ioreq || !call_back || !cb_event || !list_id) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ /* ++ * Since we hit code in busy condition very frequently, ++ * we will check the code in status first before ++ * checking the availability of free elem. ++ * ++ * This will avoid the Q fetch/add in normal condition. ++ */ ++ rc = crystalhd_code_in_full(hw->adp, ioreq->uinfo.xfr_len, ++ false, data_flags); ++ if (rc) { ++ hw->stats.cin_busy++; ++ return BC_STS_BUSY; ++ } ++ ++ /* Get a list from TxFreeQ */ ++ tx_dma_packet = (tx_dma_pkt *)crystalhd_dioq_fetch(hw->tx_freeq); ++ if (!tx_dma_packet) { ++ BCMLOG_ERR("No empty elements..\n"); ++ return BC_STS_ERR_USAGE; ++ } ++ ++ sts = crystalhd_xlat_sgl_to_dma_desc(ioreq, ++ &tx_dma_packet->desc_mem, ++ &dummy_index); ++ if (sts != BC_STS_SUCCESS) { ++ add_sts = crystalhd_dioq_add(hw->tx_freeq, tx_dma_packet, ++ false, 0); ++ if (add_sts != BC_STS_SUCCESS) ++ BCMLOG_ERR("double fault..\n"); ++ ++ return sts; ++ } ++ ++ hw->pwr_lock++; ++ ++ desc_addr.full_addr = tx_dma_packet->desc_mem.phy_addr; ++ low_addr = desc_addr.low_part; ++ high_addr = desc_addr.high_part; ++ ++ tx_dma_packet->call_back = call_back; ++ tx_dma_packet->cb_event = cb_event; ++ tx_dma_packet->dio_req = ioreq; ++ ++ spin_lock_irqsave(&hw->lock, flags); ++ ++ if (hw->tx_list_post_index == 0) { ++ first_desc_u_addr = MISC1_TX_FIRST_DESC_U_ADDR_LIST0; ++ first_desc_l_addr = MISC1_TX_FIRST_DESC_L_ADDR_LIST0; ++ } else { ++ first_desc_u_addr = MISC1_TX_FIRST_DESC_U_ADDR_LIST1; ++ first_desc_l_addr = MISC1_TX_FIRST_DESC_L_ADDR_LIST1; ++ } ++ ++ *list_id = tx_dma_packet->list_tag = hw->tx_ioq_tag_seed + ++ hw->tx_list_post_index; ++ ++ hw->tx_list_post_index = (hw->tx_list_post_index + 1) % DMA_ENGINE_CNT; ++ ++ spin_unlock_irqrestore(&hw->lock, flags); ++ ++ ++ /* Insert in Active Q..*/ ++ crystalhd_dioq_add(hw->tx_actq, tx_dma_packet, false, ++ tx_dma_packet->list_tag); ++ ++ /* ++ * Interrupt will come as soon as you write ++ * the valid bit. So be ready for that. All ++ * the initialization should happen before that. ++ */ ++ crystalhd_start_tx_dma_engine(hw); ++ crystalhd_reg_wr(hw->adp, first_desc_u_addr, desc_addr.high_part); ++ ++ crystalhd_reg_wr(hw->adp, first_desc_l_addr, desc_addr.low_part | 0x01); ++ /* Be sure we set the valid bit ^^^^ */ ++ ++ return BC_STS_SUCCESS; ++} ++ ++/* ++ * This is a force cancel and we are racing with ISR. ++ * ++ * Will try to remove the req from ActQ before ISR gets it. ++ * If ISR gets it first then the completion happens in the ++ * normal path and we will return _STS_NO_DATA from here. ++ * ++ * FIX_ME: Not Tested the actual condition.. ++ */ ++BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, uint32_t list_id) ++{ ++ if (!hw || !list_id) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ crystalhd_stop_tx_dma_engine(hw); ++ crystalhd_hw_tx_req_complete(hw, list_id, BC_STS_IO_USER_ABORT); ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_add_cap_buffer(struct crystalhd_hw *hw, ++ crystalhd_dio_req *ioreq, bool en_post) ++{ ++ crystalhd_rx_dma_pkt *rpkt; ++ uint32_t tag, uv_desc_ix = 0; ++ BC_STATUS sts; ++ ++ if (!hw || !ioreq) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ rpkt = crystalhd_hw_alloc_rx_pkt(hw); ++ if (!rpkt) { ++ BCMLOG_ERR("Insufficient resources\n"); ++ return BC_STS_INSUFF_RES; ++ } ++ ++ rpkt->dio_req = ioreq; ++ tag = rpkt->pkt_tag; ++ ++ sts = crystalhd_xlat_sgl_to_dma_desc(ioreq, &rpkt->desc_mem, &uv_desc_ix); ++ if (sts != BC_STS_SUCCESS) ++ return sts; ++ ++ rpkt->uv_phy_addr = 0; ++ ++ /* Store the address of UV in the rx packet for post*/ ++ if (uv_desc_ix) ++ rpkt->uv_phy_addr = rpkt->desc_mem.phy_addr + ++ (sizeof(dma_descriptor) * (uv_desc_ix + 1)); ++ ++ if (en_post) ++ sts = crystalhd_hw_post_cap_buff(hw, rpkt); ++ else ++ sts = crystalhd_dioq_add(hw->rx_freeq, rpkt, false, tag); ++ ++ return sts; ++} ++ ++BC_STATUS crystalhd_hw_get_cap_buffer(struct crystalhd_hw *hw, ++ BC_PIC_INFO_BLOCK *pib, ++ crystalhd_dio_req **ioreq) ++{ ++ crystalhd_rx_dma_pkt *rpkt; ++ uint32_t timeout = BC_PROC_OUTPUT_TIMEOUT / 1000; ++ uint32_t sig_pending = 0; ++ ++ ++ if (!hw || !ioreq || !pib) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ rpkt = crystalhd_dioq_fetch_wait(hw->rx_rdyq, timeout, &sig_pending); ++ if (!rpkt) { ++ if (sig_pending) { ++ BCMLOG(BCMLOG_INFO, "wait on frame time out %d\n", sig_pending); ++ return BC_STS_IO_USER_ABORT; ++ } else { ++ return BC_STS_TIMEOUT; ++ } ++ } ++ ++ rpkt->dio_req->uinfo.comp_flags = rpkt->flags; ++ ++ if (rpkt->flags & COMP_FLAG_PIB_VALID) ++ memcpy(pib, &rpkt->pib, sizeof(*pib)); ++ ++ *ioreq = rpkt->dio_req; ++ ++ crystalhd_hw_free_rx_pkt(hw, rpkt); ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_start_capture(struct crystalhd_hw *hw) ++{ ++ crystalhd_rx_dma_pkt *rx_pkt; ++ BC_STATUS sts; ++ uint32_t i; ++ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ /* This is start of capture.. Post to both the lists.. */ ++ for (i = 0; i < DMA_ENGINE_CNT; i++) { ++ rx_pkt = crystalhd_dioq_fetch(hw->rx_freeq); ++ if (!rx_pkt) ++ return BC_STS_NO_DATA; ++ sts = crystalhd_hw_post_cap_buff(hw, rx_pkt); ++ if (BC_STS_SUCCESS != sts) ++ break; ++ ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_stop_capture(struct crystalhd_hw *hw) ++{ ++ void *temp = NULL; ++ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ crystalhd_stop_rx_dma_engine(hw); ++ ++ do { ++ temp = crystalhd_dioq_fetch(hw->rx_freeq); ++ if (temp) ++ crystalhd_rx_pkt_rel_call_back(hw, temp); ++ } while (temp); ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_pause(struct crystalhd_hw *hw) ++{ ++ hw->stats.pause_cnt++; ++ hw->stop_pending = 1; ++ ++ if ((hw->rx_list_sts[0] == sts_free) && ++ (hw->rx_list_sts[1] == sts_free)) ++ crystalhd_hw_finalize_pause(hw); ++ ++ return BC_STS_SUCCESS; ++} ++ ++BC_STATUS crystalhd_hw_unpause(struct crystalhd_hw *hw) ++{ ++ BC_STATUS sts; ++ uint32_t aspm; ++ ++ hw->stop_pending = 0; ++ ++ aspm = crystalhd_reg_rd(hw->adp, PCIE_DLL_DATA_LINK_CONTROL); ++ aspm &= ~ASPM_L1_ENABLE; ++/* NAREN BCMLOG(BCMLOG_INFO, "aspm off\n"); */ ++ crystalhd_reg_wr(hw->adp, PCIE_DLL_DATA_LINK_CONTROL, aspm); ++ ++ sts = crystalhd_hw_start_capture(hw); ++ return sts; ++} ++ ++BC_STATUS crystalhd_hw_suspend(struct crystalhd_hw *hw) ++{ ++ BC_STATUS sts; ++ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ sts = crystalhd_put_ddr2sleep(hw); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("Failed to Put DDR To Sleep!!\n"); ++ return BC_STS_ERROR; ++ } ++ ++ if (!crystalhd_stop_device(hw->adp)) { ++ BCMLOG_ERR("Failed to Stop Device!!\n"); ++ return BC_STS_ERROR; ++ } ++ ++ return BC_STS_SUCCESS; ++} ++ ++void crystalhd_hw_stats(struct crystalhd_hw *hw, struct crystalhd_hw_stats *stats) ++{ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return; ++ } ++ ++ /* if called w/NULL stats, its a req to zero out the stats */ ++ if (!stats) { ++ memset(&hw->stats, 0, sizeof(hw->stats)); ++ return; ++ } ++ ++ hw->stats.freeq_count = crystalhd_dioq_count(hw->rx_freeq); ++ hw->stats.rdyq_count = crystalhd_dioq_count(hw->rx_rdyq); ++ memcpy(stats, &hw->stats, sizeof(*stats)); ++} ++ ++BC_STATUS crystalhd_hw_set_core_clock(struct crystalhd_hw *hw) ++{ ++ uint32_t reg, n, i; ++ uint32_t vco_mg, refresh_reg; ++ ++ if (!hw) { ++ BCMLOG_ERR("Invalid Arguments\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ /* FIXME: jarod: wha? */ ++ /*n = (hw->core_clock_mhz * 3) / 20 + 1; */ ++ n = hw->core_clock_mhz/5; ++ ++ if (n == hw->prev_n) ++ return BC_STS_CLK_NOCHG; ++ ++ if (hw->pwr_lock > 0) { ++ /* BCMLOG(BCMLOG_INFO,"pwr_lock is %u\n", hw->pwr_lock) */ ++ return BC_STS_CLK_NOCHG; ++ } ++ ++ i = n * 27; ++ if (i < 560) ++ vco_mg = 0; ++ else if (i < 900) ++ vco_mg = 1; ++ else if (i < 1030) ++ vco_mg = 2; ++ else ++ vco_mg = 3; ++ ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllACtl); ++ ++ reg &= 0xFFFFCFC0; ++ reg |= n; ++ reg |= vco_mg << 12; ++ ++ BCMLOG(BCMLOG_INFO, "clock is moving to %d with n %d with vco_mg %d\n", ++ hw->core_clock_mhz, n, vco_mg); ++ ++ /* Change the DRAM refresh rate to accomodate the new frequency */ ++ /* refresh reg = ((refresh_rate * clock_rate)/16) - 1; rounding up*/ ++ refresh_reg = (7 * hw->core_clock_mhz / 16); ++ bc_dec_reg_wr(hw->adp, SDRAM_REF_PARAM, ((1 << 12) | refresh_reg)); ++ ++ bc_dec_reg_wr(hw->adp, DecHt_PllACtl, reg); ++ ++ i = 0; ++ ++ for (i = 0; i < 10; i++) { ++ reg = bc_dec_reg_rd(hw->adp, DecHt_PllACtl); ++ ++ if (reg & 0x00020000) { ++ hw->prev_n = n; ++ /* FIXME: jarod: outputting a random "C" is... confusing... */ ++ BCMLOG(BCMLOG_INFO, "C"); ++ return BC_STS_SUCCESS; ++ } else { ++ msleep_interruptible(10); ++ } ++ } ++ BCMLOG(BCMLOG_INFO, "clk change failed\n"); ++ return BC_STS_CLK_NOCHG; ++} +diff --git a/drivers/staging/crystalhd/crystalhd_hw.h b/drivers/staging/crystalhd/crystalhd_hw.h +new file mode 100644 +index 0000000..1c6318e +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_hw.h +@@ -0,0 +1,398 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_hw . h ++ * ++ * Description: ++ * BCM70012 Linux driver hardware layer. ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#ifndef _CRYSTALHD_HW_H_ ++#define _CRYSTALHD_HW_H_ ++ ++#include "crystalhd_misc.h" ++#include "crystalhd_fw_if.h" ++ ++/* HW constants..*/ ++#define DMA_ENGINE_CNT 2 ++#define MAX_PIB_Q_DEPTH 64 ++#define MIN_PIB_Q_DEPTH 2 ++#define WR_POINTER_OFF 4 ++ ++#define ASPM_L1_ENABLE (BC_BIT(27)) ++ ++/************************************************* ++ 7412 Decoder Registers. ++**************************************************/ ++#define FW_CMD_BUFF_SZ 64 ++#define TS_Host2CpuSnd 0x00000100 ++#define Hst2CpuMbx1 0x00100F00 ++#define Cpu2HstMbx1 0x00100F04 ++#define MbxStat1 0x00100F08 ++#define Stream2Host_Intr_Sts 0x00100F24 ++#define C011_RET_SUCCESS 0x0 /* Reutrn status of firmware command. */ ++ ++/* TS input status register */ ++#define TS_StreamAFIFOStatus 0x0010044C ++#define TS_StreamBFIFOStatus 0x0010084C ++ ++/*UART Selection definitions*/ ++#define UartSelectA 0x00100300 ++#define UartSelectB 0x00100304 ++ ++#define BSVS_UART_DEC_NONE 0x00 ++#define BSVS_UART_DEC_OUTER 0x01 ++#define BSVS_UART_DEC_INNER 0x02 ++#define BSVS_UART_STREAM 0x03 ++ ++/* Code-In fifo */ ++#define REG_DecCA_RegCinCTL 0xa00 ++#define REG_DecCA_RegCinBase 0xa0c ++#define REG_DecCA_RegCinEnd 0xa10 ++#define REG_DecCA_RegCinWrPtr 0xa04 ++#define REG_DecCA_RegCinRdPtr 0xa08 ++ ++#define REG_Dec_TsUser0Base 0x100864 ++#define REG_Dec_TsUser0Rdptr 0x100868 ++#define REG_Dec_TsUser0Wrptr 0x10086C ++#define REG_Dec_TsUser0End 0x100874 ++ ++/* ASF Case ...*/ ++#define REG_Dec_TsAudCDB2Base 0x10036c ++#define REG_Dec_TsAudCDB2Rdptr 0x100378 ++#define REG_Dec_TsAudCDB2Wrptr 0x100374 ++#define REG_Dec_TsAudCDB2End 0x100370 ++ ++/* DRAM bringup Registers */ ++#define SDRAM_PARAM 0x00040804 ++#define SDRAM_PRECHARGE 0x000408B0 ++#define SDRAM_EXT_MODE 0x000408A4 ++#define SDRAM_MODE 0x000408A0 ++#define SDRAM_REFRESH 0x00040890 ++#define SDRAM_REF_PARAM 0x00040808 ++ ++#define DecHt_PllACtl 0x34000C ++#define DecHt_PllBCtl 0x340010 ++#define DecHt_PllCCtl 0x340014 ++#define DecHt_PllDCtl 0x340034 ++#define DecHt_PllECtl 0x340038 ++#define AUD_DSP_MISC_SOFT_RESET 0x00240104 ++#define AIO_MISC_PLL_RESET 0x0026000C ++#define PCIE_CLK_REQ_REG 0xDC ++#define PCI_CLK_REQ_ENABLE (BC_BIT(8)) ++ ++/************************************************* ++ F/W Copy engine definitions.. ++**************************************************/ ++#define BC_FWIMG_ST_ADDR 0x00000000 ++/* FIXME: jarod: there's a kernel function that'll do this for us... */ ++#define rotr32_1(x, n) (((x) >> n) | ((x) << (32 - n))) ++#define bswap_32_1(x) ((rotr32_1((x), 24) & 0x00ff00ff) | (rotr32_1((x), 8) & 0xff00ff00)) ++ ++#define DecHt_HostSwReset 0x340000 ++#define BC_DRAM_FW_CFG_ADDR 0x001c2000 ++ ++typedef union _addr_64_ { ++ struct { ++ uint32_t low_part; ++ uint32_t high_part; ++ }; ++ ++ uint64_t full_addr; ++ ++} addr_64; ++ ++typedef union _intr_mask_reg_ { ++ struct { ++ uint32_t mask_tx_done:1; ++ uint32_t mask_tx_err:1; ++ uint32_t mask_rx_done:1; ++ uint32_t mask_rx_err:1; ++ uint32_t mask_pcie_err:1; ++ uint32_t mask_pcie_rbusmast_err:1; ++ uint32_t mask_pcie_rgr_bridge:1; ++ uint32_t reserved:25; ++ }; ++ ++ uint32_t whole_reg; ++ ++} intr_mask_reg; ++ ++typedef union _link_misc_perst_deco_ctrl_ { ++ struct { ++ uint32_t bcm7412_rst:1; /* 1 -> BCM7412 is held in reset. Reset value 1.*/ ++ uint32_t reserved0:3; /* Reserved.No Effect*/ ++ uint32_t stop_bcm_7412_clk:1; /* 1 ->Stops branch of 27MHz clk used to clk BCM7412*/ ++ uint32_t reserved1:27; /* Reseved. No Effect*/ ++ }; ++ ++ uint32_t whole_reg; ++ ++} link_misc_perst_deco_ctrl; ++ ++typedef union _link_misc_perst_clk_ctrl_ { ++ struct { ++ uint32_t sel_alt_clk:1; /* When set, selects a 6.75MHz clock as the source of core_clk */ ++ uint32_t stop_core_clk:1; /* When set, stops the branch of core_clk that is not needed for low power operation */ ++ uint32_t pll_pwr_dn:1; /* When set, powers down the main PLL. The alternate clock bit should be set ++ to select an alternate clock before setting this bit.*/ ++ uint32_t reserved0:5; /* Reserved */ ++ uint32_t pll_mult:8; /* This setting controls the multiplier for the PLL. */ ++ uint32_t pll_div:4; /* This setting controls the divider for the PLL. */ ++ uint32_t reserved1:12; /* Reserved */ ++ }; ++ ++ uint32_t whole_reg; ++ ++} link_misc_perst_clk_ctrl; ++ ++ ++typedef union _link_misc_perst_decoder_ctrl_ { ++ struct { ++ uint32_t bcm_7412_rst:1; /* 1 -> BCM7412 is held in reset. Reset value 1.*/ ++ uint32_t res0:3; /* Reserved.No Effect*/ ++ uint32_t stop_7412_clk:1; /* 1 ->Stops branch of 27MHz clk used to clk BCM7412*/ ++ uint32_t res1:27; /* Reseved. No Effect */ ++ }; ++ ++ uint32_t whole_reg; ++ ++} link_misc_perst_decoder_ctrl; ++ ++ ++typedef union _desc_low_addr_reg_ { ++ struct { ++ uint32_t list_valid:1; ++ uint32_t reserved:4; ++ uint32_t low_addr:27; ++ }; ++ ++ uint32_t whole_reg; ++ ++} desc_low_addr_reg; ++ ++typedef struct _dma_descriptor_ { /* 8 32-bit values */ ++ /* 0th u32 */ ++ uint32_t sdram_buff_addr:28; /* bits 0-27: SDRAM Address */ ++ uint32_t res0:4; /* bits 28-31: Reserved */ ++ ++ /* 1st u32 */ ++ uint32_t buff_addr_low; /* 1 buffer address low */ ++ uint32_t buff_addr_high; /* 2 buffer address high */ ++ ++ /* 3rd u32 */ ++ uint32_t res2:2; /* 0-1 - Reserved */ ++ uint32_t xfer_size:23; /* 2-24 = Xfer size in words */ ++ uint32_t res3:6; /* 25-30 reserved */ ++ uint32_t intr_enable:1; /* 31 - Interrupt After this desc */ ++ ++ /* 4th u32 */ ++ uint32_t endian_xlat_align:2; /* 0-1 Endian Translation */ ++ uint32_t next_desc_cont:1; /* 2 - Next desc is in contig memory */ ++ uint32_t res4:25; /* 3 - 27 Reserved bits */ ++ uint32_t fill_bytes:2; /* 28-29 Bits Fill Bytes */ ++ uint32_t dma_dir:1; /* 30 bit DMA Direction */ ++ uint32_t last_rec_indicator:1; /* 31 bit Last Record Indicator */ ++ ++ /* 5th u32 */ ++ uint32_t next_desc_addr_low; /* 32-bits Next Desc Addr lower */ ++ ++ /* 6th u32 */ ++ uint32_t next_desc_addr_high; /* 32-bits Next Desc Addr Higher */ ++ ++ /* 7th u32 */ ++ uint32_t res8; /* Last 32bits reserved */ ++ ++} dma_descriptor, *pdma_descriptor; ++ ++/* ++ * We will allocate the memory in 4K pages ++ * the linked list will be a list of 32 byte descriptors. ++ * The virtual address will determine what should be freed. ++ */ ++typedef struct _dma_desc_mem_ { ++ pdma_descriptor pdma_desc_start; /* 32-bytes for dma descriptor. should be first element */ ++ dma_addr_t phy_addr; /* physical address of each DMA desc */ ++ uint32_t sz; ++ struct _dma_desc_mem_ *Next; /* points to Next Descriptor in chain */ ++ ++} dma_desc_mem, *pdma_desc_mem; ++ ++ ++ ++typedef enum _list_sts_ { ++ sts_free = 0, ++ ++ /* RX-Y Bits 0:7 */ ++ rx_waiting_y_intr = 0x00000001, ++ rx_y_error = 0x00000004, ++ ++ /* RX-UV Bits 8:16 */ ++ rx_waiting_uv_intr = 0x0000100, ++ rx_uv_error = 0x0000400, ++ ++ rx_sts_waiting = (rx_waiting_y_intr|rx_waiting_uv_intr), ++ rx_sts_error = (rx_y_error|rx_uv_error), ++ ++ rx_y_mask = 0x000000FF, ++ rx_uv_mask = 0x0000FF00, ++ ++} list_sts; ++ ++typedef struct _tx_dma_pkt_ { ++ dma_desc_mem desc_mem; ++ hw_comp_callback call_back; ++ crystalhd_dio_req *dio_req; ++ wait_queue_head_t *cb_event; ++ uint32_t list_tag; ++ ++} tx_dma_pkt; ++ ++typedef struct _crystalhd_rx_dma_pkt { ++ dma_desc_mem desc_mem; ++ crystalhd_dio_req *dio_req; ++ uint32_t pkt_tag; ++ uint32_t flags; ++ BC_PIC_INFO_BLOCK pib; ++ dma_addr_t uv_phy_addr; ++ struct _crystalhd_rx_dma_pkt *next; ++ ++} crystalhd_rx_dma_pkt; ++ ++struct crystalhd_hw_stats{ ++ uint32_t rx_errors; ++ uint32_t tx_errors; ++ uint32_t freeq_count; ++ uint32_t rdyq_count; ++ uint32_t num_interrupts; ++ uint32_t dev_interrupts; ++ uint32_t cin_busy; ++ uint32_t pause_cnt; ++}; ++ ++struct crystalhd_hw { ++ tx_dma_pkt tx_pkt_pool[DMA_ENGINE_CNT]; ++ spinlock_t lock; ++ ++ uint32_t tx_ioq_tag_seed; ++ uint32_t tx_list_post_index; ++ ++ crystalhd_rx_dma_pkt *rx_pkt_pool_head; ++ uint32_t rx_pkt_tag_seed; ++ ++ bool dev_started; ++ void *adp; ++ ++ wait_queue_head_t *pfw_cmd_event; ++ int fwcmd_evt_sts; ++ ++ uint32_t pib_del_Q_addr; ++ uint32_t pib_rel_Q_addr; ++ ++ crystalhd_dioq_t *tx_freeq; ++ crystalhd_dioq_t *tx_actq; ++ ++ /* Rx DMA Engine Specific Locks */ ++ spinlock_t rx_lock; ++ uint32_t rx_list_post_index; ++ list_sts rx_list_sts[DMA_ENGINE_CNT]; ++ crystalhd_dioq_t *rx_rdyq; ++ crystalhd_dioq_t *rx_freeq; ++ crystalhd_dioq_t *rx_actq; ++ uint32_t stop_pending; ++ ++ /* HW counters.. */ ++ struct crystalhd_hw_stats stats; ++ ++ /* Core clock in MHz */ ++ uint32_t core_clock_mhz; ++ uint32_t prev_n; ++ uint32_t pwr_lock; ++}; ++ ++/* Clock defines for power control */ ++#define CLOCK_PRESET 175 ++ ++/* DMA engine register BIT mask wrappers.. */ ++#define DMA_START_BIT MISC1_TX_SW_DESC_LIST_CTRL_STS_TX_DMA_RUN_STOP_MASK ++ ++#define GET_RX_INTR_MASK (INTR_INTR_STATUS_L1_UV_RX_DMA_ERR_INTR_MASK | \ ++ INTR_INTR_STATUS_L1_UV_RX_DMA_DONE_INTR_MASK | \ ++ INTR_INTR_STATUS_L1_Y_RX_DMA_ERR_INTR_MASK | \ ++ INTR_INTR_STATUS_L1_Y_RX_DMA_DONE_INTR_MASK | \ ++ INTR_INTR_STATUS_L0_UV_RX_DMA_ERR_INTR_MASK | \ ++ INTR_INTR_STATUS_L0_UV_RX_DMA_DONE_INTR_MASK | \ ++ INTR_INTR_STATUS_L0_Y_RX_DMA_ERR_INTR_MASK | \ ++ INTR_INTR_STATUS_L0_Y_RX_DMA_DONE_INTR_MASK) ++ ++#define GET_Y0_ERR_MSK (MISC1_Y_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK | \ ++ MISC1_Y_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK | \ ++ MISC1_Y_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK | \ ++ MISC1_Y_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) ++ ++#define GET_UV0_ERR_MSK (MISC1_UV_RX_ERROR_STATUS_RX_L0_OVERRUN_ERROR_MASK | \ ++ MISC1_UV_RX_ERROR_STATUS_RX_L0_UNDERRUN_ERROR_MASK | \ ++ MISC1_UV_RX_ERROR_STATUS_RX_L0_DESC_TX_ABORT_ERRORS_MASK | \ ++ MISC1_UV_RX_ERROR_STATUS_RX_L0_FIFO_FULL_ERRORS_MASK) ++ ++#define GET_Y1_ERR_MSK (MISC1_Y_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK | \ ++ MISC1_Y_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK | \ ++ MISC1_Y_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK | \ ++ MISC1_Y_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) ++ ++#define GET_UV1_ERR_MSK (MISC1_UV_RX_ERROR_STATUS_RX_L1_OVERRUN_ERROR_MASK | \ ++ MISC1_UV_RX_ERROR_STATUS_RX_L1_UNDERRUN_ERROR_MASK | \ ++ MISC1_UV_RX_ERROR_STATUS_RX_L1_DESC_TX_ABORT_ERRORS_MASK | \ ++ MISC1_UV_RX_ERROR_STATUS_RX_L1_FIFO_FULL_ERRORS_MASK) ++ ++ ++/**** API Exposed to the other layers ****/ ++BC_STATUS crystalhd_download_fw(struct crystalhd_adp *adp, ++ void *buffer, uint32_t sz); ++BC_STATUS crystalhd_do_fw_cmd(struct crystalhd_hw *hw, BC_FW_CMD *fw_cmd); ++bool crystalhd_hw_interrupt(struct crystalhd_adp *adp, struct crystalhd_hw *hw); ++BC_STATUS crystalhd_hw_open(struct crystalhd_hw *, struct crystalhd_adp *); ++BC_STATUS crystalhd_hw_close(struct crystalhd_hw *); ++BC_STATUS crystalhd_hw_setup_dma_rings(struct crystalhd_hw *); ++BC_STATUS crystalhd_hw_free_dma_rings(struct crystalhd_hw *); ++ ++ ++BC_STATUS crystalhd_hw_post_tx(struct crystalhd_hw *hw, crystalhd_dio_req *ioreq, ++ hw_comp_callback call_back, ++ wait_queue_head_t *cb_event, ++ uint32_t *list_id, uint8_t data_flags); ++ ++BC_STATUS crystalhd_hw_pause(struct crystalhd_hw *hw); ++BC_STATUS crystalhd_hw_unpause(struct crystalhd_hw *hw); ++BC_STATUS crystalhd_hw_suspend(struct crystalhd_hw *hw); ++BC_STATUS crystalhd_hw_cancel_tx(struct crystalhd_hw *hw, uint32_t list_id); ++BC_STATUS crystalhd_hw_add_cap_buffer(struct crystalhd_hw *hw, ++ crystalhd_dio_req *ioreq, bool en_post); ++BC_STATUS crystalhd_hw_get_cap_buffer(struct crystalhd_hw *hw, ++ BC_PIC_INFO_BLOCK *pib, ++ crystalhd_dio_req **ioreq); ++BC_STATUS crystalhd_hw_stop_capture(struct crystalhd_hw *hw); ++BC_STATUS crystalhd_hw_start_capture(struct crystalhd_hw *hw); ++void crystalhd_hw_stats(struct crystalhd_hw *hw, struct crystalhd_hw_stats *stats); ++ ++/* API to program the core clock on the decoder */ ++BC_STATUS crystalhd_hw_set_core_clock(struct crystalhd_hw *); ++ ++#endif +diff --git a/drivers/staging/crystalhd/crystalhd_lnx.c b/drivers/staging/crystalhd/crystalhd_lnx.c +new file mode 100644 +index 0000000..1f36b4d +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_lnx.c +@@ -0,0 +1,780 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_lnx . c ++ * ++ * Description: ++ * BCM70010 Linux driver ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#include ++ ++#include "crystalhd_lnx.h" ++ ++static struct class *crystalhd_class; ++ ++static struct crystalhd_adp *g_adp_info; ++ ++static irqreturn_t chd_dec_isr(int irq, void *arg) ++{ ++ struct crystalhd_adp *adp = (struct crystalhd_adp *) arg; ++ int rc = 0; ++ if (adp) ++ rc = crystalhd_cmd_interrupt(&adp->cmds); ++ ++ return IRQ_RETVAL(rc); ++} ++ ++static int chd_dec_enable_int(struct crystalhd_adp *adp) ++{ ++ int rc = 0; ++ ++ if (!adp || !adp->pdev) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return -EINVAL; ++ } ++ ++ if (adp->pdev->msi_enabled) ++ adp->msi = 1; ++ else ++ adp->msi = pci_enable_msi(adp->pdev); ++ ++ rc = request_irq(adp->pdev->irq, chd_dec_isr, IRQF_SHARED, ++ adp->name, (void *)adp); ++ if (rc) { ++ BCMLOG_ERR("Interrupt request failed.. \n"); ++ pci_disable_msi(adp->pdev); ++ } ++ ++ return rc; ++} ++ ++static int chd_dec_disable_int(struct crystalhd_adp *adp) ++{ ++ if (!adp || !adp->pdev) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return -EINVAL; ++ } ++ ++ free_irq(adp->pdev->irq, adp); ++ ++ if (adp->msi) ++ pci_disable_msi(adp->pdev); ++ ++ return 0; ++} ++ ++crystalhd_ioctl_data *chd_dec_alloc_iodata(struct crystalhd_adp *adp, bool isr) ++{ ++ unsigned long flags = 0; ++ crystalhd_ioctl_data *temp; ++ ++ if (!adp) ++ return NULL; ++ ++ spin_lock_irqsave(&adp->lock, flags); ++ ++ temp = adp->idata_free_head; ++ if (temp) { ++ adp->idata_free_head = adp->idata_free_head->next; ++ memset(temp, 0, sizeof(*temp)); ++ } ++ ++ spin_unlock_irqrestore(&adp->lock, flags); ++ return temp; ++} ++ ++void chd_dec_free_iodata(struct crystalhd_adp *adp, crystalhd_ioctl_data *iodata, ++ bool isr) ++{ ++ unsigned long flags = 0; ++ ++ if (!adp || !iodata) ++ return; ++ ++ spin_lock_irqsave(&adp->lock, flags); ++ iodata->next = adp->idata_free_head; ++ adp->idata_free_head = iodata; ++ spin_unlock_irqrestore(&adp->lock, flags); ++} ++ ++static inline int crystalhd_user_data(unsigned long ud, void *dr, int size, int set) ++{ ++ int rc; ++ ++ if (!ud || !dr) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return -EINVAL; ++ } ++ ++ if (set) ++ rc = copy_to_user((void *)ud, dr, size); ++ else ++ rc = copy_from_user(dr, (void *)ud, size); ++ ++ if (rc) { ++ BCMLOG_ERR("Invalid args for command \n"); ++ rc = -EFAULT; ++ } ++ ++ return rc; ++} ++ ++static int chd_dec_fetch_cdata(struct crystalhd_adp *adp, crystalhd_ioctl_data *io, ++ uint32_t m_sz, unsigned long ua) ++{ ++ unsigned long ua_off; ++ int rc = 0; ++ ++ if (!adp || !io || !ua || !m_sz) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return -EINVAL; ++ } ++ ++ io->add_cdata = vmalloc(m_sz); ++ if (!io->add_cdata) { ++ BCMLOG_ERR("kalloc fail for sz:%x\n", m_sz); ++ return -ENOMEM; ++ } ++ ++ io->add_cdata_sz = m_sz; ++ ua_off = ua + sizeof(io->udata); ++ rc = crystalhd_user_data(ua_off, io->add_cdata, io->add_cdata_sz, 0); ++ if (rc) { ++ BCMLOG_ERR("failed to pull add_cdata sz:%x ua_off:%x\n", ++ io->add_cdata_sz, (unsigned int)ua_off); ++ if (io->add_cdata) { ++ kfree(io->add_cdata); ++ io->add_cdata = NULL; ++ } ++ return -ENODATA; ++ } ++ ++ return rc; ++} ++ ++static int chd_dec_release_cdata(struct crystalhd_adp *adp, ++ crystalhd_ioctl_data *io, unsigned long ua) ++{ ++ unsigned long ua_off; ++ int rc; ++ ++ if (!adp || !io || !ua) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return -EINVAL; ++ } ++ ++ if (io->cmd != BCM_IOC_FW_DOWNLOAD) { ++ ua_off = ua + sizeof(io->udata); ++ rc = crystalhd_user_data(ua_off, io->add_cdata, ++ io->add_cdata_sz, 1); ++ if (rc) { ++ BCMLOG_ERR("failed to push add_cdata sz:%x ua_off:%x\n", ++ io->add_cdata_sz, (unsigned int)ua_off); ++ return -ENODATA; ++ } ++ } ++ ++ if (io->add_cdata) { ++ vfree(io->add_cdata); ++ io->add_cdata = NULL; ++ } ++ ++ return 0; ++} ++ ++static int chd_dec_proc_user_data(struct crystalhd_adp *adp, ++ crystalhd_ioctl_data *io, ++ unsigned long ua, int set) ++{ ++ int rc; ++ uint32_t m_sz = 0; ++ ++ if (!adp || !io || !ua) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return -EINVAL; ++ } ++ ++ rc = crystalhd_user_data(ua, &io->udata, sizeof(io->udata), set); ++ if (rc) { ++ BCMLOG_ERR("failed to %s iodata \n", (set ? "set" : "get")); ++ return rc; ++ } ++ ++ switch (io->cmd) { ++ case BCM_IOC_MEM_RD: ++ case BCM_IOC_MEM_WR: ++ case BCM_IOC_FW_DOWNLOAD: ++ m_sz = io->udata.u.devMem.NumDwords * 4; ++ if (set) ++ rc = chd_dec_release_cdata(adp, io, ua); ++ else ++ rc = chd_dec_fetch_cdata(adp, io, m_sz, ua); ++ break; ++ default: ++ break; ++ } ++ ++ return rc; ++} ++ ++static int chd_dec_api_cmd(struct crystalhd_adp *adp, unsigned long ua, ++ uint32_t uid, uint32_t cmd, crystalhd_cmd_proc func) ++{ ++ int rc; ++ crystalhd_ioctl_data *temp; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ temp = chd_dec_alloc_iodata(adp, 0); ++ if (!temp) { ++ BCMLOG_ERR("Failed to get iodata..\n"); ++ return -EINVAL; ++ } ++ ++ temp->u_id = uid; ++ temp->cmd = cmd; ++ ++ rc = chd_dec_proc_user_data(adp, temp, ua, 0); ++ if (!rc) { ++ sts = func(&adp->cmds, temp); ++ if (sts == BC_STS_PENDING) ++ sts = BC_STS_NOT_IMPL; ++ temp->udata.RetSts = sts; ++ rc = chd_dec_proc_user_data(adp, temp, ua, 1); ++ } ++ ++ if (temp) { ++ chd_dec_free_iodata(adp, temp, 0); ++ temp = NULL; ++ } ++ ++ return rc; ++} ++ ++/* ========================= API interfaces =================================*/ ++static int chd_dec_ioctl(struct inode *in, struct file *fd, ++ unsigned int cmd, unsigned long ua) ++{ ++ struct crystalhd_adp *adp = chd_get_adp(); ++ crystalhd_cmd_proc cproc; ++ struct crystalhd_user *uc; ++ ++ if (!adp || !fd) { ++ BCMLOG_ERR("Invalid adp\n"); ++ return -EINVAL; ++ } ++ ++ uc = (struct crystalhd_user *)fd->private_data; ++ if (!uc) { ++ BCMLOG_ERR("Failed to get uc\n"); ++ return -ENODATA; ++ } ++ ++ cproc = crystalhd_get_cmd_proc(&adp->cmds, cmd, uc); ++ if (!cproc) { ++ BCMLOG_ERR("Unhandled command: %d\n", cmd); ++ return -EINVAL; ++ } ++ ++ return chd_dec_api_cmd(adp, ua, uc->uid, cmd, cproc); ++} ++ ++static int chd_dec_open(struct inode *in, struct file *fd) ++{ ++ struct crystalhd_adp *adp = chd_get_adp(); ++ int rc = 0; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ struct crystalhd_user *uc = NULL; ++ ++ BCMLOG_ENTER; ++ if (!adp) { ++ BCMLOG_ERR("Invalid adp\n"); ++ return -EINVAL; ++ } ++ ++ if (adp->cfg_users >= BC_LINK_MAX_OPENS) { ++ BCMLOG(BCMLOG_INFO, "Already in use.%d\n", adp->cfg_users); ++ return -EBUSY; ++ } ++ ++ sts = crystalhd_user_open(&adp->cmds, &uc); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("cmd_user_open - %d \n", sts); ++ rc = -EBUSY; ++ } ++ ++ adp->cfg_users++; ++ ++ fd->private_data = uc; ++ ++ return rc; ++} ++ ++static int chd_dec_close(struct inode *in, struct file *fd) ++{ ++ struct crystalhd_adp *adp = chd_get_adp(); ++ struct crystalhd_user *uc; ++ ++ BCMLOG_ENTER; ++ if (!adp) { ++ BCMLOG_ERR("Invalid adp \n"); ++ return -EINVAL; ++ } ++ ++ uc = (struct crystalhd_user *)fd->private_data; ++ if (!uc) { ++ BCMLOG_ERR("Failed to get uc\n"); ++ return -ENODATA; ++ } ++ ++ crystalhd_user_close(&adp->cmds, uc); ++ ++ adp->cfg_users--; ++ ++ return 0; ++} ++ ++static const struct file_operations chd_dec_fops = { ++ .owner = THIS_MODULE, ++ .ioctl = chd_dec_ioctl, ++ .open = chd_dec_open, ++ .release = chd_dec_close, ++}; ++ ++static int chd_dec_init_chdev(struct crystalhd_adp *adp) ++{ ++ crystalhd_ioctl_data *temp; ++ struct device *dev; ++ int rc = -ENODEV, i = 0; ++ ++ if (!adp) ++ goto fail; ++ ++ adp->chd_dec_major = register_chrdev(0, CRYSTALHD_API_NAME, ++ &chd_dec_fops); ++ if (adp->chd_dec_major < 0) { ++ BCMLOG_ERR("Failed to create config dev\n"); ++ rc = adp->chd_dec_major; ++ goto fail; ++ } ++ ++ /* register crystalhd class */ ++ crystalhd_class = class_create(THIS_MODULE, "crystalhd"); ++ if (IS_ERR(crystalhd_class)) { ++ BCMLOG_ERR("failed to create class\n"); ++ goto fail; ++ } ++ ++ dev = device_create(crystalhd_class, NULL, MKDEV(adp->chd_dec_major, 0), ++ NULL, "crystalhd"); ++ if (!dev) { ++ BCMLOG_ERR("failed to create device\n"); ++ goto device_create_fail; ++ } ++ ++ rc = crystalhd_create_elem_pool(adp, BC_LINK_ELEM_POOL_SZ); ++ if (rc) { ++ BCMLOG_ERR("failed to create device\n"); ++ goto elem_pool_fail; ++ } ++ ++ /* Allocate general purpose ioctl pool. */ ++ for (i = 0; i < CHD_IODATA_POOL_SZ; i++) { ++ /* FIXME: jarod: why atomic? */ ++ temp = kzalloc(sizeof(crystalhd_ioctl_data), GFP_ATOMIC); ++ if (!temp) { ++ BCMLOG_ERR("ioctl data pool kzalloc failed\n"); ++ rc = -ENOMEM; ++ goto kzalloc_fail; ++ } ++ /* Add to global pool.. */ ++ chd_dec_free_iodata(adp, temp, 0); ++ } ++ ++ return 0; ++ ++kzalloc_fail: ++ crystalhd_delete_elem_pool(adp); ++elem_pool_fail: ++ device_destroy(crystalhd_class, MKDEV(adp->chd_dec_major, 0)); ++device_create_fail: ++ class_destroy(crystalhd_class); ++fail: ++ return rc; ++} ++ ++static void chd_dec_release_chdev(struct crystalhd_adp *adp) ++{ ++ crystalhd_ioctl_data *temp = NULL; ++ if (!adp) ++ return; ++ ++ if (adp->chd_dec_major > 0) { ++ /* unregister crystalhd class */ ++ device_destroy(crystalhd_class, MKDEV(adp->chd_dec_major, 0)); ++ unregister_chrdev(adp->chd_dec_major, CRYSTALHD_API_NAME); ++ BCMLOG(BCMLOG_INFO, "released api device - %d\n", ++ adp->chd_dec_major); ++ class_destroy(crystalhd_class); ++ } ++ adp->chd_dec_major = 0; ++ ++ /* Clear iodata pool.. */ ++ do { ++ temp = chd_dec_alloc_iodata(adp, 0); ++ if (temp) ++ kfree(temp); ++ } while (temp); ++ ++ crystalhd_delete_elem_pool(adp); ++} ++ ++static int chd_pci_reserve_mem(struct crystalhd_adp *pinfo) ++{ ++ int rc; ++ unsigned long bar2 = pci_resource_start(pinfo->pdev, 2); ++ uint32_t mem_len = pci_resource_len(pinfo->pdev, 2); ++ unsigned long bar0 = pci_resource_start(pinfo->pdev, 0); ++ uint32_t i2o_len = pci_resource_len(pinfo->pdev, 0); ++ ++ BCMLOG(BCMLOG_SSTEP, "bar2:0x%lx-0x%08x bar0:0x%lx-0x%08x\n", ++ bar2, mem_len, bar0, i2o_len); ++ ++ rc = check_mem_region(bar2, mem_len); ++ if (rc) { ++ BCMLOG_ERR("No valid mem region...\n"); ++ return -ENOMEM; ++ } ++ ++ pinfo->addr = ioremap_nocache(bar2, mem_len); ++ if (!pinfo->addr) { ++ BCMLOG_ERR("Failed to remap mem region...\n"); ++ return -ENOMEM; ++ } ++ ++ pinfo->pci_mem_start = bar2; ++ pinfo->pci_mem_len = mem_len; ++ ++ rc = check_mem_region(bar0, i2o_len); ++ if (rc) { ++ BCMLOG_ERR("No valid mem region...\n"); ++ return -ENOMEM; ++ } ++ ++ pinfo->i2o_addr = ioremap_nocache(bar0, i2o_len); ++ if (!pinfo->i2o_addr) { ++ BCMLOG_ERR("Failed to remap mem region...\n"); ++ return -ENOMEM; ++ } ++ ++ pinfo->pci_i2o_start = bar0; ++ pinfo->pci_i2o_len = i2o_len; ++ ++ rc = pci_request_regions(pinfo->pdev, pinfo->name); ++ if (rc < 0) { ++ BCMLOG_ERR("Region request failed: %d\n", rc); ++ return rc; ++ } ++ ++ BCMLOG(BCMLOG_SSTEP, "Mapped addr:0x%08lx i2o_addr:0x%08lx\n", ++ (unsigned long)pinfo->addr, (unsigned long)pinfo->i2o_addr); ++ ++ return 0; ++} ++ ++static void chd_pci_release_mem(struct crystalhd_adp *pinfo) ++{ ++ if (!pinfo) ++ return; ++ ++ if (pinfo->addr) ++ iounmap(pinfo->addr); ++ ++ if (pinfo->i2o_addr) ++ iounmap(pinfo->i2o_addr); ++ ++ pci_release_regions(pinfo->pdev); ++} ++ ++ ++static void chd_dec_pci_remove(struct pci_dev *pdev) ++{ ++ struct crystalhd_adp *pinfo; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ BCMLOG_ENTER; ++ ++ pinfo = (struct crystalhd_adp *) pci_get_drvdata(pdev); ++ if (!pinfo) { ++ BCMLOG_ERR("could not get adp\n"); ++ return; ++ } ++ ++ sts = crystalhd_delete_cmd_context(&pinfo->cmds); ++ if (sts != BC_STS_SUCCESS) ++ BCMLOG_ERR("cmd delete :%d \n", sts); ++ ++ chd_dec_release_chdev(pinfo); ++ ++ chd_dec_disable_int(pinfo); ++ ++ chd_pci_release_mem(pinfo); ++ pci_disable_device(pinfo->pdev); ++ ++ kfree(pinfo); ++ g_adp_info = NULL; ++} ++ ++static int chd_dec_pci_probe(struct pci_dev *pdev, ++ const struct pci_device_id *entry) ++{ ++ struct crystalhd_adp *pinfo; ++ int rc; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ BCMLOG(BCMLOG_DBG, "PCI_INFO: Vendor:0x%04x Device:0x%04x " ++ "s_vendor:0x%04x s_device: 0x%04x\n", ++ pdev->vendor, pdev->device, pdev->subsystem_vendor, ++ pdev->subsystem_device); ++ ++ /* FIXME: jarod: why atomic? */ ++ pinfo = kzalloc(sizeof(struct crystalhd_adp), GFP_ATOMIC); ++ if (!pinfo) { ++ BCMLOG_ERR("Failed to allocate memory\n"); ++ return -ENOMEM; ++ } ++ ++ pinfo->pdev = pdev; ++ ++ rc = pci_enable_device(pdev); ++ if (rc) { ++ BCMLOG_ERR("Failed to enable PCI device\n"); ++ return rc; ++ } ++ ++ snprintf(pinfo->name, 31, "crystalhd_pci_e:%d:%d:%d", ++ pdev->bus->number, PCI_SLOT(pdev->devfn), ++ PCI_FUNC(pdev->devfn)); ++ ++ rc = chd_pci_reserve_mem(pinfo); ++ if (rc) { ++ BCMLOG_ERR("Failed to setup memory regions.\n"); ++ return -ENOMEM; ++ } ++ ++ pinfo->present = 1; ++ pinfo->drv_data = entry->driver_data; ++ ++ /* Setup adapter level lock.. */ ++ spin_lock_init(&pinfo->lock); ++ ++ /* setup api stuff.. */ ++ chd_dec_init_chdev(pinfo); ++ rc = chd_dec_enable_int(pinfo); ++ if (rc) { ++ BCMLOG_ERR("_enable_int err:%d \n", rc); ++ pci_disable_device(pdev); ++ return -ENODEV; ++ } ++ ++ /* Set dma mask... */ ++ if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(64))) { ++ pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(64)); ++ pinfo->dmabits = 64; ++ } else if (!pci_set_dma_mask(pdev, DMA_BIT_MASK(32))) { ++ pci_set_consistent_dma_mask(pdev, DMA_BIT_MASK(32)); ++ pinfo->dmabits = 32; ++ } else { ++ BCMLOG_ERR("Unabled to setup DMA %d\n", rc); ++ pci_disable_device(pdev); ++ return -ENODEV; ++ } ++ ++ sts = crystalhd_setup_cmd_context(&pinfo->cmds, pinfo); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("cmd setup :%d \n", sts); ++ pci_disable_device(pdev); ++ return -ENODEV; ++ } ++ ++ pci_set_master(pdev); ++ ++ pci_set_drvdata(pdev, pinfo); ++ ++ g_adp_info = pinfo; ++ ++ return 0; ++ ++} ++ ++#ifdef CONFIG_PM ++int chd_dec_pci_suspend(struct pci_dev *pdev, pm_message_t state) ++{ ++ struct crystalhd_adp *adp; ++ crystalhd_ioctl_data *temp; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ ++ adp = (struct crystalhd_adp *)pci_get_drvdata(pdev); ++ if (!adp) { ++ BCMLOG_ERR("could not get adp\n"); ++ return -ENODEV; ++ } ++ ++ temp = chd_dec_alloc_iodata(adp, false); ++ if (!temp) { ++ BCMLOG_ERR("could not get ioctl data\n"); ++ return -ENODEV; ++ } ++ ++ sts = crystalhd_suspend(&adp->cmds, temp); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("BCM70012 Suspend %d\n", sts); ++ return -ENODEV; ++ } ++ ++ chd_dec_free_iodata(adp, temp, false); ++ chd_dec_disable_int(adp); ++ pci_save_state(pdev); ++ ++ /* Disable IO/bus master/irq router */ ++ pci_disable_device(pdev); ++ pci_set_power_state(pdev, pci_choose_state(pdev, state)); ++ return 0; ++} ++ ++int chd_dec_pci_resume(struct pci_dev *pdev) ++{ ++ struct crystalhd_adp *adp; ++ BC_STATUS sts = BC_STS_SUCCESS; ++ int rc; ++ ++ adp = (struct crystalhd_adp *)pci_get_drvdata(pdev); ++ if (!adp) { ++ BCMLOG_ERR("could not get adp\n"); ++ return -ENODEV; ++ } ++ ++ pci_set_power_state(pdev, PCI_D0); ++ pci_restore_state(pdev); ++ ++ /* device's irq possibly is changed, driver should take care */ ++ if (pci_enable_device(pdev)) { ++ BCMLOG_ERR("Failed to enable PCI device\n"); ++ return 1; ++ } ++ ++ pci_set_master(pdev); ++ ++ rc = chd_dec_enable_int(adp); ++ if (rc) { ++ BCMLOG_ERR("_enable_int err:%d \n", rc); ++ pci_disable_device(pdev); ++ return -ENODEV; ++ } ++ ++ sts = crystalhd_resume(&adp->cmds); ++ if (sts != BC_STS_SUCCESS) { ++ BCMLOG_ERR("BCM70012 Resume %d\n", sts); ++ pci_disable_device(pdev); ++ return -ENODEV; ++ } ++ ++ return 0; ++} ++#endif ++ ++static struct pci_device_id chd_dec_pci_id_table[] = { ++/* vendor, device, subvendor, subdevice, class, classmask, driver_data */ ++ { 0x14e4, 0x1612, PCI_ANY_ID, PCI_ANY_ID, 0, 0, 8 }, ++ { 0, }, ++}; ++ ++struct pci_driver bc_chd_70012_driver = { ++ .name = "Broadcom 70012 Decoder", ++ .probe = chd_dec_pci_probe, ++ .remove = chd_dec_pci_remove, ++ .id_table = chd_dec_pci_id_table, ++#ifdef CONFIG_PM ++ .suspend = chd_dec_pci_suspend, ++ .resume = chd_dec_pci_resume ++#endif ++}; ++MODULE_DEVICE_TABLE(pci, chd_dec_pci_id_table); ++ ++ ++void chd_set_log_level(struct crystalhd_adp *adp, char *arg) ++{ ++ if ((!arg) || (strlen(arg) < 3)) ++ g_linklog_level = BCMLOG_ERROR | BCMLOG_DATA; ++ else if (!strncmp(arg, "sstep", 5)) ++ g_linklog_level = BCMLOG_INFO | BCMLOG_DATA | BCMLOG_DBG | ++ BCMLOG_SSTEP | BCMLOG_ERROR; ++ else if (!strncmp(arg, "info", 4)) ++ g_linklog_level = BCMLOG_ERROR | BCMLOG_DATA | BCMLOG_INFO; ++ else if (!strncmp(arg, "debug", 5)) ++ g_linklog_level = BCMLOG_ERROR | BCMLOG_DATA | BCMLOG_INFO | ++ BCMLOG_DBG; ++ else if (!strncmp(arg, "pball", 5)) ++ g_linklog_level = 0xFFFFFFFF & ~(BCMLOG_SPINLOCK); ++ else if (!strncmp(arg, "silent", 6)) ++ g_linklog_level = 0; ++ else ++ g_linklog_level = 0; ++} ++ ++struct crystalhd_adp *chd_get_adp(void) ++{ ++ return g_adp_info; ++} ++ ++int __init chd_dec_module_init(void) ++{ ++ int rc; ++ ++ chd_set_log_level(NULL, "debug"); ++ BCMLOG(BCMLOG_DATA, "Loading crystalhd %d.%d.%d \n", ++ crystalhd_kmod_major, crystalhd_kmod_minor, crystalhd_kmod_rev); ++ ++ rc = pci_register_driver(&bc_chd_70012_driver); ++ ++ if (rc < 0) ++ BCMLOG_ERR("Could not find any devices. err:%d \n", rc); ++ ++ return rc; ++} ++ ++void __exit chd_dec_module_cleanup(void) ++{ ++ BCMLOG(BCMLOG_DATA, "unloading crystalhd %d.%d.%d \n", ++ crystalhd_kmod_major, crystalhd_kmod_minor, crystalhd_kmod_rev); ++ ++ pci_unregister_driver(&bc_chd_70012_driver); ++} ++ ++ ++MODULE_AUTHOR("Naren Sankar "); ++MODULE_AUTHOR("Prasad Bolisetty "); ++MODULE_DESCRIPTION(CRYSTAL_HD_NAME); ++MODULE_LICENSE("GPL"); ++MODULE_ALIAS("bcm70012"); ++ ++module_init(chd_dec_module_init); ++module_exit(chd_dec_module_cleanup); ++ +diff --git a/drivers/staging/crystalhd/crystalhd_lnx.h b/drivers/staging/crystalhd/crystalhd_lnx.h +new file mode 100644 +index 0000000..d338ae9 +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_lnx.h +@@ -0,0 +1,96 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_lnx . c ++ * ++ * Description: ++ * BCM70012 Linux driver ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#ifndef _CRYSTALHD_LNX_H_ ++#define _CRYSTALHD_LNX_H_ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include "crystalhd_cmds.h" ++ ++#define CRYSTAL_HD_NAME "Broadcom Crystal HD Decoder (BCM70012) Driver" ++ ++ ++/* OS specific PCI information structure and adapter information. */ ++struct crystalhd_adp { ++ /* Hardware borad/PCI specifics */ ++ char name[32]; ++ struct pci_dev *pdev; ++ ++ unsigned long pci_mem_start; ++ uint32_t pci_mem_len; ++ void *addr; ++ ++ unsigned long pci_i2o_start; ++ uint32_t pci_i2o_len; ++ void *i2o_addr; ++ ++ unsigned int drv_data; ++ unsigned int dmabits; /* 32 | 64 */ ++ unsigned int registered; ++ unsigned int present; ++ unsigned int msi; ++ ++ spinlock_t lock; ++ ++ /* API Related */ ++ unsigned int chd_dec_major; ++ unsigned int cfg_users; ++ ++ crystalhd_ioctl_data *idata_free_head; /* ioctl data pool */ ++ crystalhd_elem_t *elem_pool_head; /* Queue element pool */ ++ ++ struct crystalhd_cmd cmds; ++ ++ crystalhd_dio_req *ua_map_free_head; ++ struct pci_pool *fill_byte_pool; ++}; ++ ++ ++struct crystalhd_adp *chd_get_adp(void); ++void chd_set_log_level(struct crystalhd_adp *adp, char *arg); ++ ++#endif ++ +diff --git a/drivers/staging/crystalhd/crystalhd_misc.c b/drivers/staging/crystalhd/crystalhd_misc.c +new file mode 100644 +index 0000000..32e632c +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_misc.c +@@ -0,0 +1,1029 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_misc . c ++ * ++ * Description: ++ * BCM70012 Linux driver misc routines. ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#include "crystalhd_misc.h" ++#include "crystalhd_lnx.h" ++ ++uint32_t g_linklog_level; ++ ++static inline uint32_t crystalhd_dram_rd(struct crystalhd_adp *adp, uint32_t mem_off) ++{ ++ crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (mem_off >> 19)); ++ return bc_dec_reg_rd(adp, (0x00380000 | (mem_off & 0x0007FFFF))); ++} ++ ++static inline void crystalhd_dram_wr(struct crystalhd_adp *adp, uint32_t mem_off, uint32_t val) ++{ ++ crystalhd_reg_wr(adp, DCI_DRAM_BASE_ADDR, (mem_off >> 19)); ++ bc_dec_reg_wr(adp, (0x00380000 | (mem_off & 0x0007FFFF)), val); ++} ++ ++static inline BC_STATUS bc_chk_dram_range(struct crystalhd_adp *adp, uint32_t start_off, uint32_t cnt) ++{ ++ return BC_STS_SUCCESS; ++} ++ ++static crystalhd_dio_req *crystalhd_alloc_dio(struct crystalhd_adp *adp) ++{ ++ unsigned long flags = 0; ++ crystalhd_dio_req *temp = NULL; ++ ++ if (!adp) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return temp; ++ } ++ ++ spin_lock_irqsave(&adp->lock, flags); ++ temp = adp->ua_map_free_head; ++ if (temp) ++ adp->ua_map_free_head = adp->ua_map_free_head->next; ++ spin_unlock_irqrestore(&adp->lock, flags); ++ ++ return temp; ++} ++ ++static void crystalhd_free_dio(struct crystalhd_adp *adp, crystalhd_dio_req *dio) ++{ ++ unsigned long flags = 0; ++ ++ if (!adp || !dio) ++ return; ++ spin_lock_irqsave(&adp->lock, flags); ++ dio->sig = crystalhd_dio_inv; ++ dio->page_cnt = 0; ++ dio->fb_size = 0; ++ memset(&dio->uinfo, 0, sizeof(dio->uinfo)); ++ dio->next = adp->ua_map_free_head; ++ adp->ua_map_free_head = dio; ++ spin_unlock_irqrestore(&adp->lock, flags); ++} ++ ++static crystalhd_elem_t *crystalhd_alloc_elem(struct crystalhd_adp *adp) ++{ ++ unsigned long flags = 0; ++ crystalhd_elem_t *temp = NULL; ++ ++ if (!adp) ++ return temp; ++ spin_lock_irqsave(&adp->lock, flags); ++ temp = adp->elem_pool_head; ++ if (temp) { ++ adp->elem_pool_head = adp->elem_pool_head->flink; ++ memset(temp, 0, sizeof(*temp)); ++ } ++ spin_unlock_irqrestore(&adp->lock, flags); ++ ++ return temp; ++} ++static void crystalhd_free_elem(struct crystalhd_adp *adp, crystalhd_elem_t *elem) ++{ ++ unsigned long flags = 0; ++ ++ if (!adp || !elem) ++ return; ++ spin_lock_irqsave(&adp->lock, flags); ++ elem->flink = adp->elem_pool_head; ++ adp->elem_pool_head = elem; ++ spin_unlock_irqrestore(&adp->lock, flags); ++} ++ ++static inline void crystalhd_set_sg(struct scatterlist *sg, struct page *page, ++ unsigned int len, unsigned int offset) ++{ ++ sg_set_page(sg, page, len, offset); ++#ifdef CONFIG_X86_64 ++ sg->dma_length = len; ++#endif ++} ++ ++static inline void crystalhd_init_sg(struct scatterlist *sg, unsigned int entries) ++{ ++ /* http://lkml.org/lkml/2007/11/27/68 */ ++ sg_init_table(sg, entries); ++} ++ ++/*========================== Extern ========================================*/ ++/** ++ * bc_dec_reg_rd - Read 7412's device register. ++ * @adp: Adapter instance ++ * @reg_off: Register offset. ++ * ++ * Return: ++ * 32bit value read ++ * ++ * 7412's device register read routine. This interface use ++ * 7412's device access range mapped from BAR-2 (4M) of PCIe ++ * configuration space. ++ */ ++uint32_t bc_dec_reg_rd(struct crystalhd_adp *adp, uint32_t reg_off) ++{ ++ if (!adp || (reg_off > adp->pci_mem_len)) { ++ BCMLOG_ERR("dec_rd_reg_off outof range: 0x%08x\n", reg_off); ++ return 0; ++ } ++ ++ return readl(adp->addr + reg_off); ++} ++ ++/** ++ * bc_dec_reg_wr - Write 7412's device register ++ * @adp: Adapter instance ++ * @reg_off: Register offset. ++ * @val: Dword value to be written. ++ * ++ * Return: ++ * none. ++ * ++ * 7412's device register write routine. This interface use ++ * 7412's device access range mapped from BAR-2 (4M) of PCIe ++ * configuration space. ++ */ ++void bc_dec_reg_wr(struct crystalhd_adp *adp, uint32_t reg_off, uint32_t val) ++{ ++ if (!adp || (reg_off > adp->pci_mem_len)) { ++ BCMLOG_ERR("dec_wr_reg_off outof range: 0x%08x\n", reg_off); ++ return; ++ } ++ writel(val, adp->addr + reg_off); ++ udelay(8); ++} ++ ++/** ++ * crystalhd_reg_rd - Read Link's device register. ++ * @adp: Adapter instance ++ * @reg_off: Register offset. ++ * ++ * Return: ++ * 32bit value read ++ * ++ * Link device register read routine. This interface use ++ * Link's device access range mapped from BAR-1 (64K) of PCIe ++ * configuration space. ++ * ++ */ ++uint32_t crystalhd_reg_rd(struct crystalhd_adp *adp, uint32_t reg_off) ++{ ++ if (!adp || (reg_off > adp->pci_i2o_len)) { ++ BCMLOG_ERR("link_rd_reg_off outof range: 0x%08x\n", reg_off); ++ return 0; ++ } ++ return readl(adp->i2o_addr + reg_off); ++} ++ ++/** ++ * crystalhd_reg_wr - Write Link's device register ++ * @adp: Adapter instance ++ * @reg_off: Register offset. ++ * @val: Dword value to be written. ++ * ++ * Return: ++ * none. ++ * ++ * Link device register write routine. This interface use ++ * Link's device access range mapped from BAR-1 (64K) of PCIe ++ * configuration space. ++ * ++ */ ++void crystalhd_reg_wr(struct crystalhd_adp *adp, uint32_t reg_off, uint32_t val) ++{ ++ if (!adp || (reg_off > adp->pci_i2o_len)) { ++ BCMLOG_ERR("link_wr_reg_off outof range: 0x%08x\n", reg_off); ++ return; ++ } ++ writel(val, adp->i2o_addr + reg_off); ++} ++ ++/** ++ * crystalhd_mem_rd - Read data from 7412's DRAM area. ++ * @adp: Adapter instance ++ * @start_off: Start offset. ++ * @dw_cnt: Count in dwords. ++ * @rd_buff: Buffer to copy the data from dram. ++ * ++ * Return: ++ * Status. ++ * ++ * 7412's Dram read routine. ++ */ ++BC_STATUS crystalhd_mem_rd(struct crystalhd_adp *adp, uint32_t start_off, ++ uint32_t dw_cnt, uint32_t *rd_buff) ++{ ++ uint32_t ix = 0; ++ ++ if (!adp || !rd_buff || ++ (bc_chk_dram_range(adp, start_off, dw_cnt) != BC_STS_SUCCESS)) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return BC_STS_INV_ARG; ++ } ++ for (ix = 0; ix < dw_cnt; ix++) ++ rd_buff[ix] = crystalhd_dram_rd(adp, (start_off + (ix * 4))); ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_mem_wr - Write data to 7412's DRAM area. ++ * @adp: Adapter instance ++ * @start_off: Start offset. ++ * @dw_cnt: Count in dwords. ++ * @wr_buff: Data Buffer to be written. ++ * ++ * Return: ++ * Status. ++ * ++ * 7412's Dram write routine. ++ */ ++BC_STATUS crystalhd_mem_wr(struct crystalhd_adp *adp, uint32_t start_off, ++ uint32_t dw_cnt, uint32_t *wr_buff) ++{ ++ uint32_t ix = 0; ++ ++ if (!adp || !wr_buff || ++ (bc_chk_dram_range(adp, start_off, dw_cnt) != BC_STS_SUCCESS)) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ for (ix = 0; ix < dw_cnt; ix++) ++ crystalhd_dram_wr(adp, (start_off + (ix * 4)), wr_buff[ix]); ++ ++ return BC_STS_SUCCESS; ++} ++/** ++ * crystalhd_pci_cfg_rd - PCIe config read ++ * @adp: Adapter instance ++ * @off: PCI config space offset. ++ * @len: Size -- Byte, Word & dword. ++ * @val: Value read ++ * ++ * Return: ++ * Status. ++ * ++ * Get value from Link's PCIe config space. ++ */ ++BC_STATUS crystalhd_pci_cfg_rd(struct crystalhd_adp *adp, uint32_t off, ++ uint32_t len, uint32_t *val) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ int rc = 0; ++ ++ if (!adp || !val) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ switch (len) { ++ case 1: ++ rc = pci_read_config_byte(adp->pdev, off, (u8 *)val); ++ break; ++ case 2: ++ rc = pci_read_config_word(adp->pdev, off, (u16 *)val); ++ break; ++ case 4: ++ rc = pci_read_config_dword(adp->pdev, off, (u32 *)val); ++ break; ++ default: ++ rc = -EINVAL; ++ sts = BC_STS_INV_ARG; ++ BCMLOG_ERR("Invalid len:%d\n", len); ++ }; ++ ++ if (rc && (sts == BC_STS_SUCCESS)) ++ sts = BC_STS_ERROR; ++ ++ return sts; ++} ++ ++/** ++ * crystalhd_pci_cfg_wr - PCIe config write ++ * @adp: Adapter instance ++ * @off: PCI config space offset. ++ * @len: Size -- Byte, Word & dword. ++ * @val: Value to be written ++ * ++ * Return: ++ * Status. ++ * ++ * Set value to Link's PCIe config space. ++ */ ++BC_STATUS crystalhd_pci_cfg_wr(struct crystalhd_adp *adp, uint32_t off, ++ uint32_t len, uint32_t val) ++{ ++ BC_STATUS sts = BC_STS_SUCCESS; ++ int rc = 0; ++ ++ if (!adp || !val) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ switch (len) { ++ case 1: ++ rc = pci_write_config_byte(adp->pdev, off, (u8)val); ++ break; ++ case 2: ++ rc = pci_write_config_word(adp->pdev, off, (u16)val); ++ break; ++ case 4: ++ rc = pci_write_config_dword(adp->pdev, off, val); ++ break; ++ default: ++ rc = -EINVAL; ++ sts = BC_STS_INV_ARG; ++ BCMLOG_ERR("Invalid len:%d\n", len); ++ }; ++ ++ if (rc && (sts == BC_STS_SUCCESS)) ++ sts = BC_STS_ERROR; ++ ++ return sts; ++} ++ ++/** ++ * bc_kern_dma_alloc - Allocate memory for Dma rings ++ * @adp: Adapter instance ++ * @sz: Size of the memory to allocate. ++ * @phy_addr: Physical address of the memory allocated. ++ * Typedef to system's dma_addr_t (u64) ++ * ++ * Return: ++ * Pointer to allocated memory.. ++ * ++ * Wrapper to Linux kernel interface. ++ * ++ */ ++void *bc_kern_dma_alloc(struct crystalhd_adp *adp, uint32_t sz, ++ dma_addr_t *phy_addr) ++{ ++ void *temp = NULL; ++ ++ if (!adp || !sz || !phy_addr) { ++ BCMLOG_ERR("Invalide Arg..\n"); ++ return temp; ++ } ++ ++ temp = pci_alloc_consistent(adp->pdev, sz, phy_addr); ++ if (temp) ++ memset(temp, 0, sz); ++ ++ return temp; ++} ++ ++/** ++ * bc_kern_dma_free - Release Dma ring memory. ++ * @adp: Adapter instance ++ * @sz: Size of the memory to allocate. ++ * @ka: Kernel virtual address returned during _dio_alloc() ++ * @phy_addr: Physical address of the memory allocated. ++ * Typedef to system's dma_addr_t (u64) ++ * ++ * Return: ++ * none. ++ */ ++void bc_kern_dma_free(struct crystalhd_adp *adp, uint32_t sz, void *ka, ++ dma_addr_t phy_addr) ++{ ++ if (!adp || !ka || !sz || !phy_addr) { ++ BCMLOG_ERR("Invalide Arg..\n"); ++ return; ++ } ++ ++ pci_free_consistent(adp->pdev, sz, ka, phy_addr); ++} ++ ++/** ++ * crystalhd_create_dioq - Create Generic DIO queue ++ * @adp: Adapter instance ++ * @dioq_hnd: Handle to the dio queue created ++ * @cb : Optional - Call back To free the element. ++ * @cbctx: Context to pass to callback. ++ * ++ * Return: ++ * status ++ * ++ * Initialize Generic DIO queue to hold any data. Callback ++ * will be used to free elements while deleting the queue. ++ */ ++BC_STATUS crystalhd_create_dioq(struct crystalhd_adp *adp, ++ crystalhd_dioq_t **dioq_hnd, ++ crystalhd_data_free_cb cb, void *cbctx) ++{ ++ crystalhd_dioq_t *dioq = NULL; ++ ++ if (!adp || !dioq_hnd) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ dioq = kzalloc(sizeof(*dioq), GFP_KERNEL); ++ if (!dioq) ++ return BC_STS_INSUFF_RES; ++ ++ spin_lock_init(&dioq->lock); ++ dioq->sig = BC_LINK_DIOQ_SIG; ++ dioq->head = (crystalhd_elem_t *)&dioq->head; ++ dioq->tail = (crystalhd_elem_t *)&dioq->head; ++ crystalhd_create_event(&dioq->event); ++ dioq->adp = adp; ++ dioq->data_rel_cb = cb; ++ dioq->cb_context = cbctx; ++ *dioq_hnd = dioq; ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_delete_dioq - Delete Generic DIO queue ++ * @adp: Adapter instance ++ * @dioq: DIOQ instance.. ++ * ++ * Return: ++ * None. ++ * ++ * Release Generic DIO queue. This function will remove ++ * all the entries from the Queue and will release data ++ * by calling the call back provided during creation. ++ * ++ */ ++void crystalhd_delete_dioq(struct crystalhd_adp *adp, crystalhd_dioq_t *dioq) ++{ ++ void *temp; ++ ++ if (!dioq || (dioq->sig != BC_LINK_DIOQ_SIG)) ++ return; ++ ++ do { ++ temp = crystalhd_dioq_fetch(dioq); ++ if (temp && dioq->data_rel_cb) ++ dioq->data_rel_cb(dioq->cb_context, temp); ++ } while (temp); ++ dioq->sig = 0; ++ kfree(dioq); ++} ++ ++/** ++ * crystalhd_dioq_add - Add new DIO request element. ++ * @ioq: DIO queue instance ++ * @t: DIO request to be added. ++ * @wake: True - Wake up suspended process. ++ * @tag: Special tag to assign - For search and get. ++ * ++ * Return: ++ * Status. ++ * ++ * Insert new element to Q tail. ++ */ ++BC_STATUS crystalhd_dioq_add(crystalhd_dioq_t *ioq, void *data, ++ bool wake, uint32_t tag) ++{ ++ unsigned long flags = 0; ++ crystalhd_elem_t *tmp; ++ ++ if (!ioq || (ioq->sig != BC_LINK_DIOQ_SIG) || !data) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ tmp = crystalhd_alloc_elem(ioq->adp); ++ if (!tmp) { ++ BCMLOG_ERR("No free elements.\n"); ++ return BC_STS_INSUFF_RES; ++ } ++ ++ tmp->data = data; ++ tmp->tag = tag; ++ spin_lock_irqsave(&ioq->lock, flags); ++ tmp->flink = (crystalhd_elem_t *)&ioq->head; ++ tmp->blink = ioq->tail; ++ tmp->flink->blink = tmp; ++ tmp->blink->flink = tmp; ++ ioq->count++; ++ spin_unlock_irqrestore(&ioq->lock, flags); ++ ++ if (wake) ++ crystalhd_set_event(&ioq->event); ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_dioq_fetch - Fetch element from head. ++ * @ioq: DIO queue instance ++ * ++ * Return: ++ * data element from the head.. ++ * ++ * Remove an element from Queue. ++ */ ++void *crystalhd_dioq_fetch(crystalhd_dioq_t *ioq) ++{ ++ unsigned long flags = 0; ++ crystalhd_elem_t *tmp; ++ crystalhd_elem_t *ret = NULL; ++ void *data = NULL; ++ ++ if (!ioq || (ioq->sig != BC_LINK_DIOQ_SIG)) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return data; ++ } ++ ++ spin_lock_irqsave(&ioq->lock, flags); ++ tmp = ioq->head; ++ if (tmp != (crystalhd_elem_t *)&ioq->head) { ++ ret = tmp; ++ tmp->flink->blink = tmp->blink; ++ tmp->blink->flink = tmp->flink; ++ ioq->count--; ++ } ++ spin_unlock_irqrestore(&ioq->lock, flags); ++ if (ret) { ++ data = ret->data; ++ crystalhd_free_elem(ioq->adp, ret); ++ } ++ ++ return data; ++} ++/** ++ * crystalhd_dioq_find_and_fetch - Search the tag and Fetch element ++ * @ioq: DIO queue instance ++ * @tag: Tag to search for. ++ * ++ * Return: ++ * element from the head.. ++ * ++ * Search TAG and remove the element. ++ */ ++void *crystalhd_dioq_find_and_fetch(crystalhd_dioq_t *ioq, uint32_t tag) ++{ ++ unsigned long flags = 0; ++ crystalhd_elem_t *tmp; ++ crystalhd_elem_t *ret = NULL; ++ void *data = NULL; ++ ++ if (!ioq || (ioq->sig != BC_LINK_DIOQ_SIG)) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return data; ++ } ++ ++ spin_lock_irqsave(&ioq->lock, flags); ++ tmp = ioq->head; ++ while (tmp != (crystalhd_elem_t *)&ioq->head) { ++ if (tmp->tag == tag) { ++ ret = tmp; ++ tmp->flink->blink = tmp->blink; ++ tmp->blink->flink = tmp->flink; ++ ioq->count--; ++ break; ++ } ++ tmp = tmp->flink; ++ } ++ spin_unlock_irqrestore(&ioq->lock, flags); ++ ++ if (ret) { ++ data = ret->data; ++ crystalhd_free_elem(ioq->adp, ret); ++ } ++ ++ return data; ++} ++ ++/** ++ * crystalhd_dioq_fetch_wait - Fetch element from Head. ++ * @ioq: DIO queue instance ++ * @to_secs: Wait timeout in seconds.. ++ * ++ * Return: ++ * element from the head.. ++ * ++ * Return element from head if Q is not empty. Wait for new element ++ * if Q is empty for Timeout seconds. ++ */ ++void *crystalhd_dioq_fetch_wait(crystalhd_dioq_t *ioq, uint32_t to_secs, ++ uint32_t *sig_pend) ++{ ++ unsigned long flags = 0; ++ int rc = 0, count; ++ void *tmp = NULL; ++ ++ if (!ioq || (ioq->sig != BC_LINK_DIOQ_SIG) || !to_secs || !sig_pend) { ++ BCMLOG_ERR("Invalid arg!!\n"); ++ return tmp; ++ } ++ ++ count = to_secs; ++ spin_lock_irqsave(&ioq->lock, flags); ++ while ((ioq->count == 0) && count) { ++ spin_unlock_irqrestore(&ioq->lock, flags); ++ ++ crystalhd_wait_on_event(&ioq->event, (ioq->count > 0), 1000, rc, 0); ++ if (rc == 0) { ++ goto out; ++ } else if (rc == -EINTR) { ++ BCMLOG(BCMLOG_INFO, "Cancelling fetch wait\n"); ++ *sig_pend = 1; ++ return tmp; ++ } ++ spin_lock_irqsave(&ioq->lock, flags); ++ count--; ++ } ++ spin_unlock_irqrestore(&ioq->lock, flags); ++ ++out: ++ return crystalhd_dioq_fetch(ioq); ++} ++ ++/** ++ * crystalhd_map_dio - Map user address for DMA ++ * @adp: Adapter instance ++ * @ubuff: User buffer to map. ++ * @ubuff_sz: User buffer size. ++ * @uv_offset: UV buffer offset. ++ * @en_422mode: TRUE:422 FALSE:420 Capture mode. ++ * @dir_tx: TRUE for Tx (To device from host) ++ * @dio_hnd: Handle to mapped DIO request. ++ * ++ * Return: ++ * Status. ++ * ++ * This routine maps user address and lock pages for DMA. ++ * ++ */ ++BC_STATUS crystalhd_map_dio(struct crystalhd_adp *adp, void *ubuff, ++ uint32_t ubuff_sz, uint32_t uv_offset, ++ bool en_422mode, bool dir_tx, ++ crystalhd_dio_req **dio_hnd) ++{ ++ crystalhd_dio_req *dio; ++ /* FIXME: jarod: should some of these unsigned longs be uint32_t or uintptr_t? */ ++ unsigned long start = 0, end = 0, uaddr = 0, count = 0; ++ unsigned long spsz = 0, uv_start = 0; ++ int i = 0, rw = 0, res = 0, nr_pages = 0, skip_fb_sg = 0; ++ ++ if (!adp || !ubuff || !ubuff_sz || !dio_hnd) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return BC_STS_INV_ARG; ++ } ++ /* Compute pages */ ++ uaddr = (unsigned long)ubuff; ++ count = (unsigned long)ubuff_sz; ++ end = (uaddr + count + PAGE_SIZE - 1) >> PAGE_SHIFT; ++ start = uaddr >> PAGE_SHIFT; ++ nr_pages = end - start; ++ ++ if (!count || ((uaddr + count) < uaddr)) { ++ BCMLOG_ERR("User addr overflow!!\n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ dio = crystalhd_alloc_dio(adp); ++ if (!dio) { ++ BCMLOG_ERR("dio pool empty..\n"); ++ return BC_STS_INSUFF_RES; ++ } ++ ++ if (dir_tx) { ++ rw = WRITE; ++ dio->direction = DMA_TO_DEVICE; ++ } else { ++ rw = READ; ++ dio->direction = DMA_FROM_DEVICE; ++ } ++ ++ if (nr_pages > dio->max_pages) { ++ BCMLOG_ERR("max_pages(%d) exceeded(%d)!!\n", ++ dio->max_pages, nr_pages); ++ crystalhd_unmap_dio(adp, dio); ++ return BC_STS_INSUFF_RES; ++ } ++ ++ if (uv_offset) { ++ uv_start = (uaddr + (unsigned long)uv_offset) >> PAGE_SHIFT; ++ dio->uinfo.uv_sg_ix = uv_start - start; ++ dio->uinfo.uv_sg_off = ((uaddr + (unsigned long)uv_offset) & ~PAGE_MASK); ++ } ++ ++ dio->fb_size = ubuff_sz & 0x03; ++ if (dio->fb_size) { ++ res = copy_from_user(dio->fb_va, ++ (void *)(uaddr + count - dio->fb_size), ++ dio->fb_size); ++ if (res) { ++ BCMLOG_ERR("failed %d to copy %u fill bytes from %p\n", ++ res, dio->fb_size, ++ (void *)(uaddr + count-dio->fb_size)); ++ crystalhd_unmap_dio(adp, dio); ++ return BC_STS_INSUFF_RES; ++ } ++ } ++ ++ down_read(¤t->mm->mmap_sem); ++ res = get_user_pages(current, current->mm, uaddr, nr_pages, rw == READ, ++ 0, dio->pages, NULL); ++ up_read(¤t->mm->mmap_sem); ++ ++ /* Save for release..*/ ++ dio->sig = crystalhd_dio_locked; ++ if (res < nr_pages) { ++ BCMLOG_ERR("get pages failed: %d-%d\n", nr_pages, res); ++ dio->page_cnt = res; ++ crystalhd_unmap_dio(adp, dio); ++ return BC_STS_ERROR; ++ } ++ ++ dio->page_cnt = nr_pages; ++ /* Get scatter/gather */ ++ crystalhd_init_sg(dio->sg, dio->page_cnt); ++ crystalhd_set_sg(&dio->sg[0], dio->pages[0], 0, uaddr & ~PAGE_MASK); ++ if (nr_pages > 1) { ++ dio->sg[0].length = PAGE_SIZE - dio->sg[0].offset; ++ ++#ifdef CONFIG_X86_64 ++ dio->sg[0].dma_length = dio->sg[0].length; ++#endif ++ count -= dio->sg[0].length; ++ for (i = 1; i < nr_pages; i++) { ++ if (count < 4) { ++ spsz = count; ++ skip_fb_sg = 1; ++ } else { ++ spsz = (count < PAGE_SIZE) ? ++ (count & ~0x03) : PAGE_SIZE; ++ } ++ crystalhd_set_sg(&dio->sg[i], dio->pages[i], spsz, 0); ++ count -= spsz; ++ } ++ } else { ++ if (count < 4) { ++ dio->sg[0].length = count; ++ skip_fb_sg = 1; ++ } else { ++ dio->sg[0].length = count - dio->fb_size; ++ } ++#ifdef CONFIG_X86_64 ++ dio->sg[0].dma_length = dio->sg[0].length; ++#endif ++ } ++ dio->sg_cnt = pci_map_sg(adp->pdev, dio->sg, ++ dio->page_cnt, dio->direction); ++ if (dio->sg_cnt <= 0) { ++ BCMLOG_ERR("sg map %d-%d \n", dio->sg_cnt, dio->page_cnt); ++ crystalhd_unmap_dio(adp, dio); ++ return BC_STS_ERROR; ++ } ++ if (dio->sg_cnt && skip_fb_sg) ++ dio->sg_cnt -= 1; ++ dio->sig = crystalhd_dio_sg_mapped; ++ /* Fill in User info.. */ ++ dio->uinfo.xfr_len = ubuff_sz; ++ dio->uinfo.xfr_buff = ubuff; ++ dio->uinfo.uv_offset = uv_offset; ++ dio->uinfo.b422mode = en_422mode; ++ dio->uinfo.dir_tx = dir_tx; ++ ++ *dio_hnd = dio; ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_unmap_sgl - Release mapped resources ++ * @adp: Adapter instance ++ * @dio: DIO request instance ++ * ++ * Return: ++ * Status. ++ * ++ * This routine is to unmap the user buffer pages. ++ */ ++BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *adp, crystalhd_dio_req *dio) ++{ ++ struct page *page = NULL; ++ int j = 0; ++ ++ if (!adp || !dio) { ++ BCMLOG_ERR("Invalid arg \n"); ++ return BC_STS_INV_ARG; ++ } ++ ++ if ((dio->page_cnt > 0) && (dio->sig != crystalhd_dio_inv)) { ++ for (j = 0; j < dio->page_cnt; j++) { ++ page = dio->pages[j]; ++ if (page) { ++ if (!PageReserved(page) && ++ (dio->direction == DMA_FROM_DEVICE)) ++ SetPageDirty(page); ++ page_cache_release(page); ++ } ++ } ++ } ++ if (dio->sig == crystalhd_dio_sg_mapped) ++ pci_unmap_sg(adp->pdev, dio->sg, dio->page_cnt, dio->direction); ++ ++ crystalhd_free_dio(adp, dio); ++ ++ return BC_STS_SUCCESS; ++} ++ ++/** ++ * crystalhd_create_dio_pool - Allocate mem pool for DIO management. ++ * @adp: Adapter instance ++ * @max_pages: Max pages for size calculation. ++ * ++ * Return: ++ * system error. ++ * ++ * This routine creates a memory pool to hold dio context for ++ * for HW Direct IO operation. ++ */ ++int crystalhd_create_dio_pool(struct crystalhd_adp *adp, uint32_t max_pages) ++{ ++ uint32_t asz = 0, i = 0; ++ uint8_t *temp; ++ crystalhd_dio_req *dio; ++ ++ if (!adp || !max_pages) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return -EINVAL; ++ } ++ ++ /* Get dma memory for fill byte handling..*/ ++ adp->fill_byte_pool = pci_pool_create("crystalhd_fbyte", ++ adp->pdev, 8, 8, 0); ++ if (!adp->fill_byte_pool) { ++ BCMLOG_ERR("failed to create fill byte pool\n"); ++ return -ENOMEM; ++ } ++ ++ /* Get the max size from user based on 420/422 modes */ ++ asz = (sizeof(*dio->pages) * max_pages) + ++ (sizeof(*dio->sg) * max_pages) + sizeof(*dio); ++ ++ BCMLOG(BCMLOG_DBG, "Initializing Dio pool %d %d %x %p\n", ++ BC_LINK_SG_POOL_SZ, max_pages, asz, adp->fill_byte_pool); ++ ++ for (i = 0; i < BC_LINK_SG_POOL_SZ; i++) { ++ temp = (uint8_t *)kzalloc(asz, GFP_KERNEL); ++ if ((temp) == NULL) { ++ BCMLOG_ERR("Failed to alloc %d mem\n", asz); ++ return -ENOMEM; ++ } ++ ++ dio = (crystalhd_dio_req *)temp; ++ temp += sizeof(*dio); ++ dio->pages = (struct page **)temp; ++ temp += (sizeof(*dio->pages) * max_pages); ++ dio->sg = (struct scatterlist *)temp; ++ dio->max_pages = max_pages; ++ dio->fb_va = pci_pool_alloc(adp->fill_byte_pool, GFP_KERNEL, ++ &dio->fb_pa); ++ if (!dio->fb_va) { ++ BCMLOG_ERR("fill byte alloc failed.\n"); ++ return -ENOMEM; ++ } ++ ++ crystalhd_free_dio(adp, dio); ++ } ++ ++ return 0; ++} ++ ++/** ++ * crystalhd_destroy_dio_pool - Release DIO mem pool. ++ * @adp: Adapter instance ++ * ++ * Return: ++ * none. ++ * ++ * This routine releases dio memory pool during close. ++ */ ++void crystalhd_destroy_dio_pool(struct crystalhd_adp *adp) ++{ ++ crystalhd_dio_req *dio; ++ int count = 0; ++ ++ if (!adp) { ++ BCMLOG_ERR("Invalid Arg!!\n"); ++ return; ++ } ++ ++ do { ++ dio = crystalhd_alloc_dio(adp); ++ if (dio) { ++ if (dio->fb_va) ++ pci_pool_free(adp->fill_byte_pool, ++ dio->fb_va, dio->fb_pa); ++ count++; ++ kfree(dio); ++ } ++ } while (dio); ++ ++ if (adp->fill_byte_pool) { ++ pci_pool_destroy(adp->fill_byte_pool); ++ adp->fill_byte_pool = NULL; ++ } ++ ++ BCMLOG(BCMLOG_DBG, "Released dio pool %d \n", count); ++} ++ ++/** ++ * crystalhd_create_elem_pool - List element pool creation. ++ * @adp: Adapter instance ++ * @pool_size: Number of elements in the pool. ++ * ++ * Return: ++ * 0 - success, <0 error ++ * ++ * Create general purpose list element pool to hold pending, ++ * and active requests. ++ */ ++int crystalhd_create_elem_pool(struct crystalhd_adp *adp, uint32_t pool_size) ++{ ++ uint32_t i; ++ crystalhd_elem_t *temp; ++ ++ if (!adp || !pool_size) ++ return -EINVAL; ++ ++ for (i = 0; i < pool_size; i++) { ++ temp = kzalloc(sizeof(*temp), GFP_KERNEL); ++ if (!temp) { ++ BCMLOG_ERR("kalloc failed \n"); ++ return -ENOMEM; ++ } ++ crystalhd_free_elem(adp, temp); ++ } ++ BCMLOG(BCMLOG_DBG, "allocated %d elem\n", pool_size); ++ return 0; ++} ++ ++/** ++ * crystalhd_delete_elem_pool - List element pool deletion. ++ * @adp: Adapter instance ++ * ++ * Return: ++ * none ++ * ++ * Delete general purpose list element pool. ++ */ ++void crystalhd_delete_elem_pool(struct crystalhd_adp *adp) ++{ ++ crystalhd_elem_t *temp; ++ int dbg_cnt = 0; ++ ++ if (!adp) ++ return; ++ ++ do { ++ temp = crystalhd_alloc_elem(adp); ++ if (temp) { ++ kfree(temp); ++ dbg_cnt++; ++ } ++ } while (temp); ++ ++ BCMLOG(BCMLOG_DBG, "released %d elem\n", dbg_cnt); ++} ++ ++/*================ Debug support routines.. ================================*/ ++void crystalhd_show_buffer(uint32_t off, uint8_t *buff, uint32_t dwcount) ++{ ++ uint32_t i, k = 1; ++ ++ for (i = 0; i < dwcount; i++) { ++ if (k == 1) ++ BCMLOG(BCMLOG_DATA, "0x%08X : ", off); ++ ++ BCMLOG(BCMLOG_DATA, " 0x%08X ", *((uint32_t *)buff)); ++ ++ buff += sizeof(uint32_t); ++ off += sizeof(uint32_t); ++ k++; ++ if ((i == dwcount - 1) || (k > 4)) { ++ BCMLOG(BCMLOG_DATA, "\n"); ++ k = 1; ++ } ++ } ++} +diff --git a/drivers/staging/crystalhd/crystalhd_misc.h b/drivers/staging/crystalhd/crystalhd_misc.h +new file mode 100644 +index 0000000..a2aa6ad +--- /dev/null ++++ b/drivers/staging/crystalhd/crystalhd_misc.h +@@ -0,0 +1,229 @@ ++/*************************************************************************** ++ * Copyright (c) 2005-2009, Broadcom Corporation. ++ * ++ * Name: crystalhd_misc . h ++ * ++ * Description: ++ * BCM70012 Linux driver general purpose routines. ++ * Includes reg/mem read and write routines. ++ * ++ * HISTORY: ++ * ++ ********************************************************************** ++ * This file is part of the crystalhd device driver. ++ * ++ * This driver is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation, version 2 of the License. ++ * ++ * This driver is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this driver. If not, see . ++ **********************************************************************/ ++ ++#ifndef _CRYSTALHD_MISC_H_ ++#define _CRYSTALHD_MISC_H_ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "bc_dts_glob_lnx.h" ++ ++/* Global log level variable defined in crystal_misc.c file */ ++extern uint32_t g_linklog_level; ++ ++/* Global element pool for all Queue management. ++ * TX: Active = BC_TX_LIST_CNT, Free = BC_TX_LIST_CNT. ++ * RX: Free = BC_RX_LIST_CNT, Active = 2 ++ * FW-CMD: 4 ++ */ ++#define BC_LINK_ELEM_POOL_SZ ((BC_TX_LIST_CNT * 2) + BC_RX_LIST_CNT + 2 + 4) ++ ++/* Driver's IODATA pool count */ ++#define CHD_IODATA_POOL_SZ (BC_IOCTL_DATA_POOL_SIZE * BC_LINK_MAX_OPENS) ++ ++/* Scatter Gather memory pool size for Tx and Rx */ ++#define BC_LINK_SG_POOL_SZ (BC_TX_LIST_CNT + BC_RX_LIST_CNT) ++ ++enum _crystalhd_dio_sig { ++ crystalhd_dio_inv = 0, ++ crystalhd_dio_locked, ++ crystalhd_dio_sg_mapped, ++}; ++ ++struct crystalhd_dio_user_info { ++ void *xfr_buff; ++ uint32_t xfr_len; ++ uint32_t uv_offset; ++ bool dir_tx; ++ ++ uint32_t uv_sg_ix; ++ uint32_t uv_sg_off; ++ int comp_sts; ++ int ev_sts; ++ uint32_t y_done_sz; ++ uint32_t uv_done_sz; ++ uint32_t comp_flags; ++ bool b422mode; ++}; ++ ++typedef struct _crystalhd_dio_req { ++ uint32_t sig; ++ uint32_t max_pages; ++ struct page **pages; ++ struct scatterlist *sg; ++ int sg_cnt; ++ int page_cnt; ++ int direction; ++ struct crystalhd_dio_user_info uinfo; ++ void *fb_va; ++ uint32_t fb_size; ++ dma_addr_t fb_pa; ++ struct _crystalhd_dio_req *next; ++} crystalhd_dio_req; ++ ++#define BC_LINK_DIOQ_SIG (0x09223280) ++ ++typedef struct _crystalhd_elem_s { ++ struct _crystalhd_elem_s *flink; ++ struct _crystalhd_elem_s *blink; ++ void *data; ++ uint32_t tag; ++} crystalhd_elem_t; ++ ++typedef void (*crystalhd_data_free_cb)(void *context, void *data); ++ ++typedef struct _crystalhd_dioq_s { ++ uint32_t sig; ++ struct crystalhd_adp *adp; ++ crystalhd_elem_t *head; ++ crystalhd_elem_t *tail; ++ uint32_t count; ++ spinlock_t lock; ++ wait_queue_head_t event; ++ crystalhd_data_free_cb data_rel_cb; ++ void *cb_context; ++} crystalhd_dioq_t; ++ ++typedef void (*hw_comp_callback)(crystalhd_dio_req *, ++ wait_queue_head_t *event, BC_STATUS sts); ++ ++/*========= Decoder (7412) register access routines.================= */ ++uint32_t bc_dec_reg_rd(struct crystalhd_adp *, uint32_t); ++void bc_dec_reg_wr(struct crystalhd_adp *, uint32_t, uint32_t); ++ ++/*========= Link (70012) register access routines.. =================*/ ++uint32_t crystalhd_reg_rd(struct crystalhd_adp *, uint32_t); ++void crystalhd_reg_wr(struct crystalhd_adp *, uint32_t, uint32_t); ++ ++/*========= Decoder (7412) memory access routines..=================*/ ++BC_STATUS crystalhd_mem_rd(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t *); ++BC_STATUS crystalhd_mem_wr(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t *); ++ ++/*==========Link (70012) PCIe Config access routines.================*/ ++BC_STATUS crystalhd_pci_cfg_rd(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t *); ++BC_STATUS crystalhd_pci_cfg_wr(struct crystalhd_adp *, uint32_t, uint32_t, uint32_t); ++ ++/*========= Linux Kernel Interface routines. ======================= */ ++void *bc_kern_dma_alloc(struct crystalhd_adp *, uint32_t, dma_addr_t *); ++void bc_kern_dma_free(struct crystalhd_adp *, uint32_t, ++ void *, dma_addr_t); ++#define crystalhd_create_event(_ev) init_waitqueue_head(_ev) ++#define crystalhd_set_event(_ev) wake_up_interruptible(_ev) ++#define crystalhd_wait_on_event(ev, condition, timeout, ret, nosig) \ ++do { \ ++ DECLARE_WAITQUEUE(entry, current); \ ++ unsigned long end = jiffies + ((timeout * HZ) / 1000); \ ++ ret = 0; \ ++ add_wait_queue(ev, &entry); \ ++ for (;;) { \ ++ __set_current_state(TASK_INTERRUPTIBLE); \ ++ if (condition) { \ ++ break; \ ++ } \ ++ if (time_after_eq(jiffies, end)) { \ ++ ret = -EBUSY; \ ++ break; \ ++ } \ ++ schedule_timeout((HZ / 100 > 1) ? HZ / 100 : 1); \ ++ if (!nosig && signal_pending(current)) { \ ++ ret = -EINTR; \ ++ break; \ ++ } \ ++ } \ ++ __set_current_state(TASK_RUNNING); \ ++ remove_wait_queue(ev, &entry); \ ++} while (0) ++ ++/*================ Direct IO mapping routines ==================*/ ++extern int crystalhd_create_dio_pool(struct crystalhd_adp *, uint32_t); ++extern void crystalhd_destroy_dio_pool(struct crystalhd_adp *); ++extern BC_STATUS crystalhd_map_dio(struct crystalhd_adp *, void *, uint32_t, ++ uint32_t, bool, bool, crystalhd_dio_req**); ++ ++extern BC_STATUS crystalhd_unmap_dio(struct crystalhd_adp *, crystalhd_dio_req*); ++#define crystalhd_get_sgle_paddr(_dio, _ix) (cpu_to_le64(sg_dma_address(&_dio->sg[_ix]))) ++#define crystalhd_get_sgle_len(_dio, _ix) (cpu_to_le32(sg_dma_len(&_dio->sg[_ix]))) ++ ++/*================ General Purpose Queues ==================*/ ++extern BC_STATUS crystalhd_create_dioq(struct crystalhd_adp *, crystalhd_dioq_t **, crystalhd_data_free_cb , void *); ++extern void crystalhd_delete_dioq(struct crystalhd_adp *, crystalhd_dioq_t *); ++extern BC_STATUS crystalhd_dioq_add(crystalhd_dioq_t *ioq, void *data, bool wake, uint32_t tag); ++extern void *crystalhd_dioq_fetch(crystalhd_dioq_t *ioq); ++extern void *crystalhd_dioq_find_and_fetch(crystalhd_dioq_t *ioq, uint32_t tag); ++extern void *crystalhd_dioq_fetch_wait(crystalhd_dioq_t *ioq, uint32_t to_secs, uint32_t *sig_pend); ++ ++#define crystalhd_dioq_count(_ioq) ((_ioq) ? _ioq->count : 0) ++ ++extern int crystalhd_create_elem_pool(struct crystalhd_adp *, uint32_t); ++extern void crystalhd_delete_elem_pool(struct crystalhd_adp *); ++ ++ ++/*================ Debug routines/macros .. ================================*/ ++extern void crystalhd_show_buffer(uint32_t off, uint8_t *buff, uint32_t dwcount); ++ ++enum _chd_log_levels { ++ BCMLOG_ERROR = 0x80000000, /* Don't disable this option */ ++ BCMLOG_DATA = 0x40000000, /* Data, enable by default */ ++ BCMLOG_SPINLOCK = 0x20000000, /* Spcial case for Spin locks*/ ++ ++ /* Following are allowed only in debug mode */ ++ BCMLOG_INFO = 0x00000001, /* Generic informational */ ++ BCMLOG_DBG = 0x00000002, /* First level Debug info */ ++ BCMLOG_SSTEP = 0x00000004, /* Stepping information */ ++ BCMLOG_ENTER_LEAVE = 0x00000008, /* stack tracking */ ++}; ++ ++#define BCMLOG_ENTER \ ++if (g_linklog_level & BCMLOG_ENTER_LEAVE) { \ ++ printk("Entered %s\n", __func__); \ ++} ++ ++#define BCMLOG_LEAVE \ ++if (g_linklog_level & BCMLOG_ENTER_LEAVE) { \ ++ printk("Leaving %s\n", __func__); \ ++} ++ ++#define BCMLOG(trace, fmt, args...) \ ++if (g_linklog_level & trace) { \ ++ printk(fmt, ##args); \ ++} ++ ++#define BCMLOG_ERR(fmt, args...) \ ++do { \ ++ if (g_linklog_level & BCMLOG_ERROR) { \ ++ printk("*ERR*:%s:%d: "fmt, __FILE__, __LINE__, ##args); \ ++ } \ ++} while (0); ++ ++#endif diff --git a/die-floppy-die.patch b/die-floppy-die.patch new file mode 100644 index 000000000..26beabfc7 --- /dev/null +++ b/die-floppy-die.patch @@ -0,0 +1,18 @@ +Kill the floppy.ko pnp modalias. We were surviving just fine without +autoloading floppy drivers, tyvm. + +Please feel free to register all complaints in the wastepaper bin. + +diff --git a/drivers/block/floppy.c b/drivers/block/floppy.c +index 91b7530..2ea84a6 100644 +--- a/drivers/block/floppy.c ++++ b/drivers/block/floppy.c +@@ -4631,7 +4631,7 @@ static const struct pnp_device_id floppy_pnpids[] = { + { "PNP0700", 0 }, + { } + }; +-MODULE_DEVICE_TABLE(pnp, floppy_pnpids); ++/* MODULE_DEVICE_TABLE(pnp, floppy_pnpids); */ + + #else + diff --git a/disable-i8042-check-on-apple-mac.patch b/disable-i8042-check-on-apple-mac.patch new file mode 100644 index 000000000..693875b7c --- /dev/null +++ b/disable-i8042-check-on-apple-mac.patch @@ -0,0 +1,58 @@ +From d01268ff135052cd40c375c6b7ebadbee3281b4d Mon Sep 17 00:00:00 2001 +From: Bastien Nocera +Date: Wed, 20 Jan 2010 18:23:13 +0000 +Subject: Disable i8042 checks on Intel Apple Macs + +As those computers never had any i8042 controllers, and the +current lookup code could potentially lock up/hang/wait for +timeout for long periods of time. + +Fixes intermittent hangs on boot on a MacbookAir1,1 + +Signed-off-by: Bastien Nocera +--- + drivers/input/serio/i8042.c | 22 ++++++++++++++++++++++ + 1 files changed, 22 insertions(+), 0 deletions(-) + +diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c +index b54aee7..5e1e59c 100644 +--- a/drivers/input/serio/i8042.c ++++ b/drivers/input/serio/i8042.c +@@ -1446,12 +1446,34 @@ static struct platform_driver i8042_driver = { + .shutdown = i8042_shutdown, + }; + ++#ifdef CONFIG_DMI ++static struct dmi_system_id __initdata dmi_system_table[] = { ++ { ++ .matches = { ++ DMI_MATCH(DMI_BIOS_VENDOR, "Apple Computer, Inc.") ++ }, ++ }, ++ { ++ .matches = { ++ DMI_MATCH(DMI_BIOS_VENDOR, "Apple Inc.") ++ }, ++ }, ++ {} ++}; ++#endif /*CONFIG_DMI*/ ++ + static int __init i8042_init(void) + { + int err; + + dbg_init(); + ++#ifdef CONFIG_DMI ++ /* Intel Apple Macs never have an i8042 controller */ ++ if (dmi_check_system(dmi_system_table) > 0) ++ return -ENODEV; ++#endif /*CONFIG_DMI*/ ++ + err = i8042_platform_init(); + if (err) + return err; +-- +1.7.0.1 + diff --git a/drm-1024x768-85.patch b/drm-1024x768-85.patch new file mode 100644 index 000000000..5dacf7282 --- /dev/null +++ b/drm-1024x768-85.patch @@ -0,0 +1,29 @@ +From 65a1d7cab62b4f514eaaf608b2f16e26a0e48042 Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Thu, 13 May 2010 14:55:28 -0400 +Subject: [PATCH] drm/edid: Fix 1024x768@85Hz + +Having hsync both start and end on pixel 1072 ain't gonna work very +well. Matches the X server's list. + +Signed-off-by: Adam Jackson +--- + drivers/gpu/drm/drm_edid.c | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c +index 18f41d7..10348d3 100644 +--- a/drivers/gpu/drm/drm_edid.c ++++ b/drivers/gpu/drm/drm_edid.c +@@ -335,7 +335,7 @@ static struct drm_display_mode drm_dmt_modes[] = { + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, + /* 1024x768@85Hz */ + { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072, +- 1072, 1376, 0, 768, 769, 772, 808, 0, ++ 1168, 1376, 0, 768, 769, 772, 808, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, + /* 1152x864@75Hz */ + { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, +-- +1.7.0.1 + diff --git a/drm-connection-cache.patch b/drm-connection-cache.patch new file mode 100644 index 000000000..d0c544dc7 --- /dev/null +++ b/drm-connection-cache.patch @@ -0,0 +1,65 @@ +diff -up linux-2.6.30.noarch/drivers/gpu/drm/drm_crtc_helper.c.jx linux-2.6.30.noarch/drivers/gpu/drm/drm_crtc_helper.c +--- linux-2.6.30.noarch/drivers/gpu/drm/drm_crtc_helper.c.jx 2009-09-09 08:57:39.000000000 -0400 ++++ linux-2.6.30.noarch/drivers/gpu/drm/drm_crtc_helper.c 2009-09-09 09:35:24.000000000 -0400 +@@ -92,6 +92,18 @@ int drm_helper_probe_single_connector_mo + + connector->status = connector->funcs->detect(connector); + ++ /* fast path if the driver tracks disconnection */ ++ if (connector->status == connector_status_cached) { ++ DRM_DEBUG_KMS("%s still connected\n", ++ drm_get_connector_name(connector)); ++ list_for_each_entry_safe(mode, t, &connector->modes, head) { ++ count++; ++ mode->status = MODE_OK; ++ } ++ connector->status = connector_status_connected; ++ return count; ++ } ++ + if (connector->status == connector_status_disconnected) { + DRM_DEBUG_KMS("%s is disconnected\n", + drm_get_connector_name(connector)); +diff -up linux-2.6.30.noarch/drivers/gpu/drm/i915/intel_lvds.c.jx linux-2.6.30.noarch/drivers/gpu/drm/i915/intel_lvds.c +--- linux-2.6.30.noarch/drivers/gpu/drm/i915/intel_lvds.c.jx 2009-09-09 08:57:39.000000000 -0400 ++++ linux-2.6.30.noarch/drivers/gpu/drm/i915/intel_lvds.c 2009-09-09 09:56:18.000000000 -0400 +@@ -593,7 +593,14 @@ static void intel_lvds_mode_set(struct d + */ + static enum drm_connector_status intel_lvds_detect(struct drm_connector *connector) + { +- return connector_status_connected; ++ static int done; ++ ++ if (!done) { ++ done = 1; ++ return connector_status_connected; ++ } else { ++ return connector_status_cached; ++ } + } + + /** +diff -up linux-2.6.30.noarch/include/drm/drm_crtc.h.jx linux-2.6.30.noarch/include/drm/drm_crtc.h +--- linux-2.6.30.noarch/include/drm/drm_crtc.h.jx 2009-09-09 08:57:39.000000000 -0400 ++++ linux-2.6.30.noarch/include/drm/drm_crtc.h 2009-09-09 09:35:24.000000000 -0400 +@@ -172,6 +172,7 @@ enum drm_connector_status { + connector_status_connected = 1, + connector_status_disconnected = 2, + connector_status_unknown = 3, ++ connector_status_cached = 4, + }; + + enum subpixel_order { +diff -up linux-2.6.30.x86_64/drivers/gpu/drm/drm_crtc.c.jx linux-2.6.30.x86_64/drivers/gpu/drm/drm_crtc.c +--- linux-2.6.30.x86_64/drivers/gpu/drm/drm_crtc.c.jx 2009-09-09 10:10:44.000000000 -0400 ++++ linux-2.6.30.x86_64/drivers/gpu/drm/drm_crtc.c 2009-09-09 11:23:14.000000000 -0400 +@@ -185,7 +185,8 @@ EXPORT_SYMBOL(drm_get_connector_name); + + char *drm_get_connector_status_name(enum drm_connector_status status) + { +- if (status == connector_status_connected) ++ if (status == connector_status_connected || ++ status == connector_status_cached) + return "connected"; + else if (status == connector_status_disconnected) + return "disconnected"; diff --git a/drm-core-next.patch b/drm-core-next.patch new file mode 100644 index 000000000..4620d1eab --- /dev/null +++ b/drm-core-next.patch @@ -0,0 +1,3494 @@ +diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c +index d91fb8c..aa24f2f 100644 +--- a/drivers/gpu/drm/drm_crtc.c ++++ b/drivers/gpu/drm/drm_crtc.c +@@ -33,6 +33,7 @@ + #include "drm.h" + #include "drmP.h" + #include "drm_crtc.h" ++#include "drm_edid.h" + + struct drm_prop_enum_list { + int type; +@@ -2349,7 +2350,7 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector, + struct edid *edid) + { + struct drm_device *dev = connector->dev; +- int ret = 0; ++ int ret = 0, size; + + if (connector->edid_blob_ptr) + drm_property_destroy_blob(dev, connector->edid_blob_ptr); +@@ -2361,7 +2362,9 @@ int drm_mode_connector_update_edid_property(struct drm_connector *connector, + return ret; + } + +- connector->edid_blob_ptr = drm_property_create_blob(connector->dev, 128, edid); ++ size = EDID_LENGTH * (1 + edid->extensions); ++ connector->edid_blob_ptr = drm_property_create_blob(connector->dev, ++ size, edid); + + ret = drm_connector_property_set_value(connector, + dev->mode_config.edid_property, +diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c +index 7d0f00a..51103aa 100644 +--- a/drivers/gpu/drm/drm_crtc_helper.c ++++ b/drivers/gpu/drm/drm_crtc_helper.c +@@ -104,6 +104,7 @@ int drm_helper_probe_single_connector_modes(struct drm_connector *connector, + if (connector->status == connector_status_disconnected) { + DRM_DEBUG_KMS("%s is disconnected\n", + drm_get_connector_name(connector)); ++ drm_mode_connector_update_edid_property(connector, NULL); + goto prune; + } + +@@ -836,11 +837,7 @@ int drm_crtc_helper_set_config(struct drm_mode_set *set) + mode_changed = true; + } else if (set->fb == NULL) { + mode_changed = true; +- } else if ((set->fb->bits_per_pixel != +- set->crtc->fb->bits_per_pixel) || +- set->fb->depth != set->crtc->fb->depth) +- fb_changed = true; +- else ++ } else + fb_changed = true; + } + +diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c +index 766c468..f3c58e2 100644 +--- a/drivers/gpu/drm/drm_drv.c ++++ b/drivers/gpu/drm/drm_drv.c +@@ -125,28 +125,28 @@ static struct drm_ioctl_desc drm_ioctls[] = { + + DRM_IOCTL_DEF(DRM_IOCTL_UPDATE_DRAW, drm_update_drawable_info, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), + +- DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, 0), +- DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH), +- +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR, drm_mode_cursor_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETGAMMA, drm_mode_gamma_get_ioctl, DRM_MASTER), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETGAMMA, drm_mode_gamma_set_ioctl, DRM_MASTER), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETENCODER, drm_mode_getencoder, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCONNECTOR, drm_mode_getconnector, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATTACHMODE, drm_mode_attachmode_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_DETACHMODE, drm_mode_detachmode_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPERTY, drm_mode_getproperty_ioctl, DRM_MASTER | DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_mode_connector_property_set_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW) ++ DRM_IOCTL_DEF(DRM_IOCTL_GEM_CLOSE, drm_gem_close_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_GEM_FLINK, drm_gem_flink_ioctl, DRM_AUTH|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_GEM_OPEN, drm_gem_open_ioctl, DRM_AUTH|DRM_UNLOCKED), ++ ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETRESOURCES, drm_mode_getresources, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCRTC, drm_mode_getcrtc, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETCRTC, drm_mode_setcrtc, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_CURSOR, drm_mode_cursor_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETGAMMA, drm_mode_gamma_get_ioctl, DRM_MASTER|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETGAMMA, drm_mode_gamma_set_ioctl, DRM_MASTER|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETENCODER, drm_mode_getencoder, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETCONNECTOR, drm_mode_getconnector, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_ATTACHMODE, drm_mode_attachmode_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_DETACHMODE, drm_mode_detachmode_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPERTY, drm_mode_getproperty_ioctl, DRM_MASTER | DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_SETPROPERTY, drm_mode_connector_property_set_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETPROPBLOB, drm_mode_getblob_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_GETFB, drm_mode_getfb, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_ADDFB, drm_mode_addfb, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_RMFB, drm_mode_rmfb, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_PAGE_FLIP, drm_mode_page_flip_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_IOCTL_MODE_DIRTYFB, drm_mode_dirtyfb_ioctl, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED) + }; + + #define DRM_CORE_IOCTL_COUNT ARRAY_SIZE( drm_ioctls ) +diff --git a/drivers/gpu/drm/drm_edid.c b/drivers/gpu/drm/drm_edid.c +index ab6c973..4ea2721 100644 +--- a/drivers/gpu/drm/drm_edid.c ++++ b/drivers/gpu/drm/drm_edid.c +@@ -2,6 +2,7 @@ + * Copyright (c) 2006 Luc Verhaegen (quirks list) + * Copyright (c) 2007-2008 Intel Corporation + * Jesse Barnes ++ * Copyright 2010 Red Hat, Inc. + * + * DDC probing routines (drm_ddc_read & drm_do_probe_ddc_edid) originally from + * FB layer. +@@ -32,10 +33,9 @@ + #include "drmP.h" + #include "drm_edid.h" + +-/* +- * TODO: +- * - support EDID 1.4 (incl. CE blocks) +- */ ++#define EDID_EST_TIMINGS 16 ++#define EDID_STD_TIMINGS 8 ++#define EDID_DETAILED_TIMINGS 4 + + /* + * EDID blocks out in the wild have a variety of bugs, try to collect +@@ -65,7 +65,8 @@ + + #define LEVEL_DMT 0 + #define LEVEL_GTF 1 +-#define LEVEL_CVT 2 ++#define LEVEL_GTF2 2 ++#define LEVEL_CVT 3 + + static struct edid_quirk { + char *vendor; +@@ -85,6 +86,8 @@ static struct edid_quirk { + + /* Envision Peripherals, Inc. EN-7100e */ + { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH }, ++ /* Envision EN2028 */ ++ { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 }, + + /* Funai Electronics PM36B */ + { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 | +@@ -107,36 +110,38 @@ static struct edid_quirk { + { "SAM", 638, EDID_QUIRK_PREFER_LARGE_60 }, + }; + ++/*** DDC fetch and block validation ***/ + +-/* Valid EDID header has these bytes */ + static const u8 edid_header[] = { + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 + }; + +-/** +- * edid_is_valid - sanity check EDID data +- * @edid: EDID data +- * +- * Sanity check the EDID block by looking at the header, the version number +- * and the checksum. Return 0 if the EDID doesn't check out, or 1 if it's +- * valid. ++/* ++ * Sanity check the EDID block (base or extension). Return 0 if the block ++ * doesn't check out, or 1 if it's valid. + */ +-static bool edid_is_valid(struct edid *edid) ++static bool ++drm_edid_block_valid(u8 *raw_edid) + { +- int i, score = 0; ++ int i; + u8 csum = 0; +- u8 *raw_edid = (u8 *)edid; ++ struct edid *edid = (struct edid *)raw_edid; + +- for (i = 0; i < sizeof(edid_header); i++) +- if (raw_edid[i] == edid_header[i]) +- score++; ++ if (raw_edid[0] == 0x00) { ++ int score = 0; + +- if (score == 8) ; +- else if (score >= 6) { +- DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); +- memcpy(raw_edid, edid_header, sizeof(edid_header)); +- } else +- goto bad; ++ for (i = 0; i < sizeof(edid_header); i++) ++ if (raw_edid[i] == edid_header[i]) ++ score++; ++ ++ if (score == 8) ; ++ else if (score >= 6) { ++ DRM_DEBUG("Fixing EDID header, your hardware may be failing\n"); ++ memcpy(raw_edid, edid_header, sizeof(edid_header)); ++ } else { ++ goto bad; ++ } ++ } + + for (i = 0; i < EDID_LENGTH; i++) + csum += raw_edid[i]; +@@ -145,13 +150,21 @@ static bool edid_is_valid(struct edid *edid) + goto bad; + } + +- if (edid->version != 1) { +- DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version); +- goto bad; +- } ++ /* per-block-type checks */ ++ switch (raw_edid[0]) { ++ case 0: /* base */ ++ if (edid->version != 1) { ++ DRM_ERROR("EDID has major version %d, instead of 1\n", edid->version); ++ goto bad; ++ } + +- if (edid->revision > 4) +- DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n"); ++ if (edid->revision > 4) ++ DRM_DEBUG("EDID minor > 4, assuming backward compatibility\n"); ++ break; ++ ++ default: ++ break; ++ } + + return 1; + +@@ -165,6 +178,157 @@ bad: + } + + /** ++ * drm_edid_is_valid - sanity check EDID data ++ * @edid: EDID data ++ * ++ * Sanity-check an entire EDID record (including extensions) ++ */ ++bool drm_edid_is_valid(struct edid *edid) ++{ ++ int i; ++ u8 *raw = (u8 *)edid; ++ ++ if (!edid) ++ return false; ++ ++ for (i = 0; i <= edid->extensions; i++) ++ if (!drm_edid_block_valid(raw + i * EDID_LENGTH)) ++ return false; ++ ++ return true; ++} ++EXPORT_SYMBOL(drm_edid_is_valid); ++ ++#define DDC_ADDR 0x50 ++#define DDC_SEGMENT_ADDR 0x30 ++/** ++ * Get EDID information via I2C. ++ * ++ * \param adapter : i2c device adaptor ++ * \param buf : EDID data buffer to be filled ++ * \param len : EDID data buffer length ++ * \return 0 on success or -1 on failure. ++ * ++ * Try to fetch EDID information by calling i2c driver function. ++ */ ++static int ++drm_do_probe_ddc_edid(struct i2c_adapter *adapter, unsigned char *buf, ++ int block, int len) ++{ ++ unsigned char start = block * EDID_LENGTH; ++ struct i2c_msg msgs[] = { ++ { ++ .addr = DDC_ADDR, ++ .flags = 0, ++ .len = 1, ++ .buf = &start, ++ }, { ++ .addr = DDC_ADDR, ++ .flags = I2C_M_RD, ++ .len = len, ++ .buf = buf + start, ++ } ++ }; ++ ++ if (i2c_transfer(adapter, msgs, 2) == 2) ++ return 0; ++ ++ return -1; ++} ++ ++static u8 * ++drm_do_get_edid(struct drm_connector *connector, struct i2c_adapter *adapter) ++{ ++ int i, j = 0; ++ u8 *block, *new; ++ ++ if ((block = kmalloc(EDID_LENGTH, GFP_KERNEL)) == NULL) ++ return NULL; ++ ++ /* base block fetch */ ++ for (i = 0; i < 4; i++) { ++ if (drm_do_probe_ddc_edid(adapter, block, 0, EDID_LENGTH)) ++ goto out; ++ if (drm_edid_block_valid(block)) ++ break; ++ } ++ if (i == 4) ++ goto carp; ++ ++ /* if there's no extensions, we're done */ ++ if (block[0x7e] == 0) ++ return block; ++ ++ new = krealloc(block, (block[0x7e] + 1) * EDID_LENGTH, GFP_KERNEL); ++ if (!new) ++ goto out; ++ block = new; ++ ++ for (j = 1; j <= block[0x7e]; j++) { ++ for (i = 0; i < 4; i++) { ++ if (drm_do_probe_ddc_edid(adapter, block, j, ++ EDID_LENGTH)) ++ goto out; ++ if (drm_edid_block_valid(block + j * EDID_LENGTH)) ++ break; ++ } ++ if (i == 4) ++ goto carp; ++ } ++ ++ return block; ++ ++carp: ++ dev_warn(&connector->dev->pdev->dev, "%s: EDID block %d invalid.\n", ++ drm_get_connector_name(connector), j); ++ ++out: ++ kfree(block); ++ return NULL; ++} ++ ++/** ++ * Probe DDC presence. ++ * ++ * \param adapter : i2c device adaptor ++ * \return 1 on success ++ */ ++static bool ++drm_probe_ddc(struct i2c_adapter *adapter) ++{ ++ unsigned char out; ++ ++ return (drm_do_probe_ddc_edid(adapter, &out, 0, 1) == 0); ++} ++ ++/** ++ * drm_get_edid - get EDID data, if available ++ * @connector: connector we're probing ++ * @adapter: i2c adapter to use for DDC ++ * ++ * Poke the given i2c channel to grab EDID data if possible. If found, ++ * attach it to the connector. ++ * ++ * Return edid data or NULL if we couldn't find any. ++ */ ++struct edid *drm_get_edid(struct drm_connector *connector, ++ struct i2c_adapter *adapter) ++{ ++ struct edid *edid = NULL; ++ ++ if (drm_probe_ddc(adapter)) ++ edid = (struct edid *)drm_do_get_edid(connector, adapter); ++ ++ connector->display_info.raw_edid = (char *)edid; ++ ++ return edid; ++ ++} ++EXPORT_SYMBOL(drm_get_edid); ++ ++/*** EDID parsing ***/ ++ ++/** + * edid_vendor - match a string against EDID's obfuscated vendor field + * @edid: EDID to match + * @vendor: vendor string +@@ -514,6 +678,110 @@ static struct drm_display_mode *drm_find_dmt(struct drm_device *dev, + return mode; + } + ++typedef void detailed_cb(struct detailed_timing *timing, void *closure); ++ ++static void ++drm_for_each_detailed_block(u8 *raw_edid, detailed_cb *cb, void *closure) ++{ ++ int i; ++ struct edid *edid = (struct edid *)raw_edid; ++ ++ if (edid == NULL) ++ return; ++ ++ for (i = 0; i < EDID_DETAILED_TIMINGS; i++) ++ cb(&(edid->detailed_timings[i]), closure); ++ ++ /* XXX extension block walk */ ++} ++ ++static void ++is_rb(struct detailed_timing *t, void *data) ++{ ++ u8 *r = (u8 *)t; ++ if (r[3] == EDID_DETAIL_MONITOR_RANGE) ++ if (r[15] & 0x10) ++ *(bool *)data = true; ++} ++ ++/* EDID 1.4 defines this explicitly. For EDID 1.3, we guess, badly. */ ++static bool ++drm_monitor_supports_rb(struct edid *edid) ++{ ++ if (edid->revision >= 4) { ++ bool ret; ++ drm_for_each_detailed_block((u8 *)edid, is_rb, &ret); ++ return ret; ++ } ++ ++ return ((edid->input & DRM_EDID_INPUT_DIGITAL) != 0); ++} ++ ++static void ++find_gtf2(struct detailed_timing *t, void *data) ++{ ++ u8 *r = (u8 *)t; ++ if (r[3] == EDID_DETAIL_MONITOR_RANGE && r[10] == 0x02) ++ *(u8 **)data = r; ++} ++ ++/* Secondary GTF curve kicks in above some break frequency */ ++static int ++drm_gtf2_hbreak(struct edid *edid) ++{ ++ u8 *r = NULL; ++ drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); ++ return r ? (r[12] * 2) : 0; ++} ++ ++static int ++drm_gtf2_2c(struct edid *edid) ++{ ++ u8 *r = NULL; ++ drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); ++ return r ? r[13] : 0; ++} ++ ++static int ++drm_gtf2_m(struct edid *edid) ++{ ++ u8 *r = NULL; ++ drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); ++ return r ? (r[15] << 8) + r[14] : 0; ++} ++ ++static int ++drm_gtf2_k(struct edid *edid) ++{ ++ u8 *r = NULL; ++ drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); ++ return r ? r[16] : 0; ++} ++ ++static int ++drm_gtf2_2j(struct edid *edid) ++{ ++ u8 *r = NULL; ++ drm_for_each_detailed_block((u8 *)edid, find_gtf2, &r); ++ return r ? r[17] : 0; ++} ++ ++/** ++ * standard_timing_level - get std. timing level(CVT/GTF/DMT) ++ * @edid: EDID block to scan ++ */ ++static int standard_timing_level(struct edid *edid) ++{ ++ if (edid->revision >= 2) { ++ if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)) ++ return LEVEL_CVT; ++ if (drm_gtf2_hbreak(edid)) ++ return LEVEL_GTF2; ++ return LEVEL_GTF; ++ } ++ return LEVEL_DMT; ++} ++ + /* + * 0 is reserved. The spec says 0x01 fill for unused timings. Some old + * monitors fill with ascii space (0x20) instead. +@@ -533,22 +801,20 @@ bad_std_timing(u8 a, u8 b) + * + * Take the standard timing params (in this case width, aspect, and refresh) + * and convert them into a real mode using CVT/GTF/DMT. +- * +- * Punts for now, but should eventually use the FB layer's CVT based mode +- * generation code. + */ +-struct drm_display_mode *drm_mode_std(struct drm_device *dev, +- struct std_timing *t, +- int revision, +- int timing_level) ++static struct drm_display_mode * ++drm_mode_std(struct drm_connector *connector, struct edid *edid, ++ struct std_timing *t, int revision) + { +- struct drm_display_mode *mode; ++ struct drm_device *dev = connector->dev; ++ struct drm_display_mode *m, *mode = NULL; + int hsize, vsize; + int vrefresh_rate; + unsigned aspect_ratio = (t->vfreq_aspect & EDID_TIMING_ASPECT_MASK) + >> EDID_TIMING_ASPECT_SHIFT; + unsigned vfreq = (t->vfreq_aspect & EDID_TIMING_VFREQ_MASK) + >> EDID_TIMING_VFREQ_SHIFT; ++ int timing_level = standard_timing_level(edid); + + if (bad_std_timing(t->hsize, t->vfreq_aspect)) + return NULL; +@@ -569,16 +835,36 @@ struct drm_display_mode *drm_mode_std(struct drm_device *dev, + vsize = (hsize * 4) / 5; + else + vsize = (hsize * 9) / 16; +- /* HDTV hack */ +- if (hsize == 1360 && vsize == 765 && vrefresh_rate == 60) { +- mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, ++ ++ /* HDTV hack, part 1 */ ++ if (vrefresh_rate == 60 && ++ ((hsize == 1360 && vsize == 765) || ++ (hsize == 1368 && vsize == 769))) { ++ hsize = 1366; ++ vsize = 768; ++ } ++ ++ /* ++ * If this connector already has a mode for this size and refresh ++ * rate (because it came from detailed or CVT info), use that ++ * instead. This way we don't have to guess at interlace or ++ * reduced blanking. ++ */ ++ list_for_each_entry(m, &connector->probed_modes, head) ++ if (m->hdisplay == hsize && m->vdisplay == vsize && ++ drm_mode_vrefresh(m) == vrefresh_rate) ++ return NULL; ++ ++ /* HDTV hack, part 2 */ ++ if (hsize == 1366 && vsize == 768 && vrefresh_rate == 60) { ++ mode = drm_cvt_mode(dev, 1366, 768, vrefresh_rate, 0, 0, + false); + mode->hdisplay = 1366; + mode->hsync_start = mode->hsync_start - 1; + mode->hsync_end = mode->hsync_end - 1; + return mode; + } +- mode = NULL; ++ + /* check whether it can be found in default mode table */ + mode = drm_find_dmt(dev, hsize, vsize, vrefresh_rate); + if (mode) +@@ -590,6 +876,23 @@ struct drm_display_mode *drm_mode_std(struct drm_device *dev, + case LEVEL_GTF: + mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); + break; ++ case LEVEL_GTF2: ++ /* ++ * This is potentially wrong if there's ever a monitor with ++ * more than one ranges section, each claiming a different ++ * secondary GTF curve. Please don't do that. ++ */ ++ mode = drm_gtf_mode(dev, hsize, vsize, vrefresh_rate, 0, 0); ++ if (drm_mode_hsync(mode) > drm_gtf2_hbreak(edid)) { ++ kfree(mode); ++ mode = drm_gtf_mode_complex(dev, hsize, vsize, ++ vrefresh_rate, 0, 0, ++ drm_gtf2_m(edid), ++ drm_gtf2_2c(edid), ++ drm_gtf2_k(edid), ++ drm_gtf2_2j(edid)); ++ } ++ break; + case LEVEL_CVT: + mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, + false); +@@ -707,25 +1010,16 @@ static struct drm_display_mode *drm_mode_detailed(struct drm_device *dev, + mode->vsync_end = mode->vsync_start + vsync_pulse_width; + mode->vtotal = mode->vdisplay + vblank; + +- /* perform the basic check for the detailed timing */ +- if (mode->hsync_end > mode->htotal || +- mode->vsync_end > mode->vtotal) { +- drm_mode_destroy(dev, mode); +- DRM_DEBUG_KMS("Incorrect detailed timing. " +- "Sync is beyond the blank.\n"); +- return NULL; +- } +- + /* Some EDIDs have bogus h/vtotal values */ + if (mode->hsync_end > mode->htotal) + mode->htotal = mode->hsync_end + 1; + if (mode->vsync_end > mode->vtotal) + mode->vtotal = mode->vsync_end + 1; + +- drm_mode_set_name(mode); +- + drm_mode_do_interlace_quirk(mode, pt); + ++ drm_mode_set_name(mode); ++ + if (quirks & EDID_QUIRK_DETAILED_SYNC_PP) { + pt->misc |= DRM_EDID_PT_HSYNC_POSITIVE | DRM_EDID_PT_VSYNC_POSITIVE; + } +@@ -808,10 +1102,6 @@ static struct drm_display_mode edid_est_modes[] = { + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, /* 1152x864@75Hz */ + }; + +-#define EDID_EST_TIMINGS 16 +-#define EDID_STD_TIMINGS 8 +-#define EDID_DETAILED_TIMINGS 4 +- + /** + * add_established_modes - get est. modes from EDID and add them + * @edid: EDID block to scan +@@ -839,19 +1129,6 @@ static int add_established_modes(struct drm_connector *connector, struct edid *e + + return modes; + } +-/** +- * stanard_timing_level - get std. timing level(CVT/GTF/DMT) +- * @edid: EDID block to scan +- */ +-static int standard_timing_level(struct edid *edid) +-{ +- if (edid->revision >= 2) { +- if (edid->revision >= 4 && (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF)) +- return LEVEL_CVT; +- return LEVEL_GTF; +- } +- return LEVEL_DMT; +-} + + /** + * add_standard_modes - get std. modes from EDID and add them +@@ -862,22 +1139,14 @@ static int standard_timing_level(struct edid *edid) + */ + static int add_standard_modes(struct drm_connector *connector, struct edid *edid) + { +- struct drm_device *dev = connector->dev; + int i, modes = 0; +- int timing_level; +- +- timing_level = standard_timing_level(edid); + + for (i = 0; i < EDID_STD_TIMINGS; i++) { +- struct std_timing *t = &edid->standard_timings[i]; + struct drm_display_mode *newmode; + +- /* If std timings bytes are 1, 1 it's empty */ +- if (t->hsize == 1 && t->vfreq_aspect == 1) +- continue; +- +- newmode = drm_mode_std(dev, &edid->standard_timings[i], +- edid->revision, timing_level); ++ newmode = drm_mode_std(connector, edid, ++ &edid->standard_timings[i], ++ edid->revision); + if (newmode) { + drm_mode_probed_add(connector, newmode); + modes++; +@@ -887,36 +1156,86 @@ static int add_standard_modes(struct drm_connector *connector, struct edid *edid + return modes; + } + +-/* +- * XXX fix this for: +- * - GTF secondary curve formula +- * - EDID 1.4 range offsets +- * - CVT extended bits +- */ + static bool +-mode_in_range(struct drm_display_mode *mode, struct detailed_timing *timing) ++mode_is_rb(struct drm_display_mode *mode) + { +- struct detailed_data_monitor_range *range; +- int hsync, vrefresh; +- +- range = &timing->data.other_data.data.range; ++ return (mode->htotal - mode->hdisplay == 160) && ++ (mode->hsync_end - mode->hdisplay == 80) && ++ (mode->hsync_end - mode->hsync_start == 32) && ++ (mode->vsync_start - mode->vdisplay == 3); ++} + ++static bool ++mode_in_hsync_range(struct drm_display_mode *mode, struct edid *edid, u8 *t) ++{ ++ int hsync, hmin, hmax; ++ ++ hmin = t[7]; ++ if (edid->revision >= 4) ++ hmin += ((t[4] & 0x04) ? 255 : 0); ++ hmax = t[8]; ++ if (edid->revision >= 4) ++ hmax += ((t[4] & 0x08) ? 255 : 0); + hsync = drm_mode_hsync(mode); +- vrefresh = drm_mode_vrefresh(mode); + +- if (hsync < range->min_hfreq_khz || hsync > range->max_hfreq_khz) ++ return (hsync <= hmax && hsync >= hmin); ++} ++ ++static bool ++mode_in_vsync_range(struct drm_display_mode *mode, struct edid *edid, u8 *t) ++{ ++ int vsync, vmin, vmax; ++ ++ vmin = t[5]; ++ if (edid->revision >= 4) ++ vmin += ((t[4] & 0x01) ? 255 : 0); ++ vmax = t[6]; ++ if (edid->revision >= 4) ++ vmax += ((t[4] & 0x02) ? 255 : 0); ++ vsync = drm_mode_vrefresh(mode); ++ ++ return (vsync <= vmax && vsync >= vmin); ++} ++ ++static u32 ++range_pixel_clock(struct edid *edid, u8 *t) ++{ ++ /* unspecified */ ++ if (t[9] == 0 || t[9] == 255) ++ return 0; ++ ++ /* 1.4 with CVT support gives us real precision, yay */ ++ if (edid->revision >= 4 && t[10] == 0x04) ++ return (t[9] * 10000) - ((t[12] >> 2) * 250); ++ ++ /* 1.3 is pathetic, so fuzz up a bit */ ++ return t[9] * 10000 + 5001; ++} ++ ++static bool ++mode_in_range(struct drm_display_mode *mode, struct edid *edid, ++ struct detailed_timing *timing) ++{ ++ u32 max_clock; ++ u8 *t = (u8 *)timing; ++ ++ if (!mode_in_hsync_range(mode, edid, t)) + return false; + +- if (vrefresh < range->min_vfreq || vrefresh > range->max_vfreq) ++ if (!mode_in_vsync_range(mode, edid, t)) + return false; + +- if (range->pixel_clock_mhz && range->pixel_clock_mhz != 0xff) { +- /* be forgiving since it's in units of 10MHz */ +- int max_clock = range->pixel_clock_mhz * 10 + 9; +- max_clock *= 1000; ++ if ((max_clock = range_pixel_clock(edid, t))) + if (mode->clock > max_clock) + return false; +- } ++ ++ /* 1.4 max horizontal check */ ++ if (edid->revision >= 4 && t[10] == 0x04) ++ if (t[13] && mode->hdisplay > 8 * (t[13] + (256 * (t[12]&0x3)))) ++ return false; ++ ++ if (mode_is_rb(mode) && !drm_monitor_supports_rb(edid)) ++ return false; + + return true; + } +@@ -925,15 +1244,16 @@ mode_in_range(struct drm_display_mode *mode, struct detailed_timing *timing) + * XXX If drm_dmt_modes ever regrows the CVT-R modes (and it will) this will + * need to account for them. + */ +-static int drm_gtf_modes_for_range(struct drm_connector *connector, +- struct detailed_timing *timing) ++static int ++drm_gtf_modes_for_range(struct drm_connector *connector, struct edid *edid, ++ struct detailed_timing *timing) + { + int i, modes = 0; + struct drm_display_mode *newmode; + struct drm_device *dev = connector->dev; + + for (i = 0; i < drm_num_dmt_modes; i++) { +- if (mode_in_range(drm_dmt_modes + i, timing)) { ++ if (mode_in_range(drm_dmt_modes + i, edid, timing)) { + newmode = drm_mode_duplicate(dev, &drm_dmt_modes[i]); + if (newmode) { + drm_mode_probed_add(connector, newmode); +@@ -994,13 +1314,100 @@ static int drm_cvt_modes(struct drm_connector *connector, + return modes; + } + ++static const struct { ++ short w; ++ short h; ++ short r; ++ short rb; ++} est3_modes[] = { ++ /* byte 6 */ ++ { 640, 350, 85, 0 }, ++ { 640, 400, 85, 0 }, ++ { 720, 400, 85, 0 }, ++ { 640, 480, 85, 0 }, ++ { 848, 480, 60, 0 }, ++ { 800, 600, 85, 0 }, ++ { 1024, 768, 85, 0 }, ++ { 1152, 864, 75, 0 }, ++ /* byte 7 */ ++ { 1280, 768, 60, 1 }, ++ { 1280, 768, 60, 0 }, ++ { 1280, 768, 75, 0 }, ++ { 1280, 768, 85, 0 }, ++ { 1280, 960, 60, 0 }, ++ { 1280, 960, 85, 0 }, ++ { 1280, 1024, 60, 0 }, ++ { 1280, 1024, 85, 0 }, ++ /* byte 8 */ ++ { 1360, 768, 60, 0 }, ++ { 1440, 900, 60, 1 }, ++ { 1440, 900, 60, 0 }, ++ { 1440, 900, 75, 0 }, ++ { 1440, 900, 85, 0 }, ++ { 1400, 1050, 60, 1 }, ++ { 1400, 1050, 60, 0 }, ++ { 1400, 1050, 75, 0 }, ++ /* byte 9 */ ++ { 1400, 1050, 85, 0 }, ++ { 1680, 1050, 60, 1 }, ++ { 1680, 1050, 60, 0 }, ++ { 1680, 1050, 75, 0 }, ++ { 1680, 1050, 85, 0 }, ++ { 1600, 1200, 60, 0 }, ++ { 1600, 1200, 65, 0 }, ++ { 1600, 1200, 70, 0 }, ++ /* byte 10 */ ++ { 1600, 1200, 75, 0 }, ++ { 1600, 1200, 85, 0 }, ++ { 1792, 1344, 60, 0 }, ++ { 1792, 1344, 85, 0 }, ++ { 1856, 1392, 60, 0 }, ++ { 1856, 1392, 75, 0 }, ++ { 1920, 1200, 60, 1 }, ++ { 1920, 1200, 60, 0 }, ++ /* byte 11 */ ++ { 1920, 1200, 75, 0 }, ++ { 1920, 1200, 85, 0 }, ++ { 1920, 1440, 60, 0 }, ++ { 1920, 1440, 75, 0 }, ++}; ++static const int num_est3_modes = sizeof(est3_modes) / sizeof(est3_modes[0]); ++ ++static int ++drm_est3_modes(struct drm_connector *connector, struct detailed_timing *timing) ++{ ++ int i, j, m, modes = 0; ++ struct drm_display_mode *mode; ++ u8 *est = ((u8 *)timing) + 5; ++ ++ for (i = 0; i < 6; i++) { ++ for (j = 7; j > 0; j--) { ++ m = (i * 8) + (7 - j); ++ if (m > num_est3_modes) ++ break; ++ if (est[i] & (1 << j)) { ++ mode = drm_find_dmt(connector->dev, ++ est3_modes[m].w, ++ est3_modes[m].h, ++ est3_modes[m].r ++ /*, est3_modes[m].rb */); ++ if (mode) { ++ drm_mode_probed_add(connector, mode); ++ modes++; ++ } ++ } ++ } ++ } ++ ++ return modes; ++} ++ + static int add_detailed_modes(struct drm_connector *connector, + struct detailed_timing *timing, + struct edid *edid, u32 quirks, int preferred) + { + int i, modes = 0; + struct detailed_non_pixel *data = &timing->data.other_data; +- int timing_level = standard_timing_level(edid); + int gtf = (edid->features & DRM_EDID_FEATURE_DEFAULT_GTF); + struct drm_display_mode *newmode; + struct drm_device *dev = connector->dev; +@@ -1021,7 +1428,8 @@ static int add_detailed_modes(struct drm_connector *connector, + switch (data->type) { + case EDID_DETAIL_MONITOR_RANGE: + if (gtf) +- modes += drm_gtf_modes_for_range(connector, timing); ++ modes += drm_gtf_modes_for_range(connector, edid, ++ timing); + break; + case EDID_DETAIL_STD_MODES: + /* Six modes per detailed section */ +@@ -1030,8 +1438,8 @@ static int add_detailed_modes(struct drm_connector *connector, + struct drm_display_mode *newmode; + + std = &data->data.timings[i]; +- newmode = drm_mode_std(dev, std, edid->revision, +- timing_level); ++ newmode = drm_mode_std(connector, edid, std, ++ edid->revision); + if (newmode) { + drm_mode_probed_add(connector, newmode); + modes++; +@@ -1041,6 +1449,9 @@ static int add_detailed_modes(struct drm_connector *connector, + case EDID_DETAIL_CVT_3BYTE: + modes += drm_cvt_modes(connector, timing); + break; ++ case EDID_DETAIL_EST_TIMINGS: ++ modes += drm_est3_modes(connector, timing); ++ break; + default: + break; + } +@@ -1064,7 +1475,10 @@ static int add_detailed_info(struct drm_connector *connector, + + for (i = 0; i < EDID_DETAILED_TIMINGS; i++) { + struct detailed_timing *timing = &edid->detailed_timings[i]; +- int preferred = (i == 0) && (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING); ++ int preferred = (i == 0); ++ ++ if (preferred && edid->version == 1 && edid->revision < 4) ++ preferred = (edid->features & DRM_EDID_FEATURE_PREFERRED_TIMING); + + /* In 1.0, only timings are allowed */ + if (!timing->pixel_clock && edid->version == 1 && +@@ -1094,39 +1508,23 @@ static int add_detailed_info_eedid(struct drm_connector *connector, + int i, modes = 0; + char *edid_ext = NULL; + struct detailed_timing *timing; +- int edid_ext_num; + int start_offset, end_offset; + int timing_level; + +- if (edid->version == 1 && edid->revision < 3) { +- /* If the EDID version is less than 1.3, there is no +- * extension EDID. +- */ ++ if (edid->version == 1 && edid->revision < 3) + return 0; +- } +- if (!edid->extensions) { +- /* if there is no extension EDID, it is unnecessary to +- * parse the E-EDID to get detailed info +- */ ++ if (!edid->extensions) + return 0; +- } +- +- /* Chose real EDID extension number */ +- edid_ext_num = edid->extensions > MAX_EDID_EXT_NUM ? +- MAX_EDID_EXT_NUM : edid->extensions; + + /* Find CEA extension */ +- for (i = 0; i < edid_ext_num; i++) { ++ for (i = 0; i < edid->extensions; i++) { + edid_ext = (char *)edid + EDID_LENGTH * (i + 1); +- /* This block is CEA extension */ + if (edid_ext[0] == 0x02) + break; + } + +- if (i == edid_ext_num) { +- /* if there is no additional timing EDID block, return */ ++ if (i == edid->extensions) + return 0; +- } + + /* Get the start offset of detailed timing block */ + start_offset = edid_ext[2]; +@@ -1150,123 +1548,6 @@ static int add_detailed_info_eedid(struct drm_connector *connector, + return modes; + } + +-#define DDC_ADDR 0x50 +-/** +- * Get EDID information via I2C. +- * +- * \param adapter : i2c device adaptor +- * \param buf : EDID data buffer to be filled +- * \param len : EDID data buffer length +- * \return 0 on success or -1 on failure. +- * +- * Try to fetch EDID information by calling i2c driver function. +- */ +-int drm_do_probe_ddc_edid(struct i2c_adapter *adapter, +- unsigned char *buf, int len) +-{ +- unsigned char start = 0x0; +- struct i2c_msg msgs[] = { +- { +- .addr = DDC_ADDR, +- .flags = 0, +- .len = 1, +- .buf = &start, +- }, { +- .addr = DDC_ADDR, +- .flags = I2C_M_RD, +- .len = len, +- .buf = buf, +- } +- }; +- +- if (i2c_transfer(adapter, msgs, 2) == 2) +- return 0; +- +- return -1; +-} +-EXPORT_SYMBOL(drm_do_probe_ddc_edid); +- +-static int drm_ddc_read_edid(struct drm_connector *connector, +- struct i2c_adapter *adapter, +- char *buf, int len) +-{ +- int i; +- +- for (i = 0; i < 4; i++) { +- if (drm_do_probe_ddc_edid(adapter, buf, len)) +- return -1; +- if (edid_is_valid((struct edid *)buf)) +- return 0; +- } +- +- /* repeated checksum failures; warn, but carry on */ +- dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", +- drm_get_connector_name(connector)); +- return -1; +-} +- +-/** +- * drm_get_edid - get EDID data, if available +- * @connector: connector we're probing +- * @adapter: i2c adapter to use for DDC +- * +- * Poke the given connector's i2c channel to grab EDID data if possible. +- * +- * Return edid data or NULL if we couldn't find any. +- */ +-struct edid *drm_get_edid(struct drm_connector *connector, +- struct i2c_adapter *adapter) +-{ +- int ret; +- struct edid *edid; +- +- edid = kmalloc(EDID_LENGTH * (MAX_EDID_EXT_NUM + 1), +- GFP_KERNEL); +- if (edid == NULL) { +- dev_warn(&connector->dev->pdev->dev, +- "Failed to allocate EDID\n"); +- goto end; +- } +- +- /* Read first EDID block */ +- ret = drm_ddc_read_edid(connector, adapter, +- (unsigned char *)edid, EDID_LENGTH); +- if (ret != 0) +- goto clean_up; +- +- /* There are EDID extensions to be read */ +- if (edid->extensions != 0) { +- int edid_ext_num = edid->extensions; +- +- if (edid_ext_num > MAX_EDID_EXT_NUM) { +- dev_warn(&connector->dev->pdev->dev, +- "The number of extension(%d) is " +- "over max (%d), actually read number (%d)\n", +- edid_ext_num, MAX_EDID_EXT_NUM, +- MAX_EDID_EXT_NUM); +- /* Reset EDID extension number to be read */ +- edid_ext_num = MAX_EDID_EXT_NUM; +- } +- /* Read EDID including extensions too */ +- ret = drm_ddc_read_edid(connector, adapter, (char *)edid, +- EDID_LENGTH * (edid_ext_num + 1)); +- if (ret != 0) +- goto clean_up; +- +- } +- +- connector->display_info.raw_edid = (char *)edid; +- goto end; +- +-clean_up: +- kfree(edid); +- edid = NULL; +-end: +- return edid; +- +-} +-EXPORT_SYMBOL(drm_get_edid); +- + #define HDMI_IDENTIFIER 0x000C03 + #define VENDOR_BLOCK 0x03 + /** +@@ -1279,7 +1560,7 @@ EXPORT_SYMBOL(drm_get_edid); + bool drm_detect_hdmi_monitor(struct edid *edid) + { + char *edid_ext = NULL; +- int i, hdmi_id, edid_ext_num; ++ int i, hdmi_id; + int start_offset, end_offset; + bool is_hdmi = false; + +@@ -1287,19 +1568,15 @@ bool drm_detect_hdmi_monitor(struct edid *edid) + if (edid == NULL || edid->extensions == 0) + goto end; + +- /* Chose real EDID extension number */ +- edid_ext_num = edid->extensions > MAX_EDID_EXT_NUM ? +- MAX_EDID_EXT_NUM : edid->extensions; +- + /* Find CEA extension */ +- for (i = 0; i < edid_ext_num; i++) { ++ for (i = 0; i < edid->extensions; i++) { + edid_ext = (char *)edid + EDID_LENGTH * (i + 1); + /* This block is CEA extension */ + if (edid_ext[0] == 0x02) + break; + } + +- if (i == edid_ext_num) ++ if (i == edid->extensions) + goto end; + + /* Data block offset in CEA extension block */ +@@ -1346,7 +1623,7 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) + if (edid == NULL) { + return 0; + } +- if (!edid_is_valid(edid)) { ++ if (!drm_edid_is_valid(edid)) { + dev_warn(&connector->dev->pdev->dev, "%s: EDID invalid.\n", + drm_get_connector_name(connector)); + return 0; +@@ -1354,10 +1631,24 @@ int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid) + + quirks = edid_get_quirks(edid); + +- num_modes += add_established_modes(connector, edid); +- num_modes += add_standard_modes(connector, edid); ++ /* ++ * EDID spec says modes should be preferred in this order: ++ * - preferred detailed mode ++ * - other detailed modes from base block ++ * - detailed modes from extension blocks ++ * - CVT 3-byte code modes ++ * - standard timing codes ++ * - established timing codes ++ * - modes inferred from GTF or CVT range information ++ * ++ * We don't quite implement this yet, but we're close. ++ * ++ * XXX order for additional mode types in extension blocks? ++ */ + num_modes += add_detailed_info(connector, edid, quirks); + num_modes += add_detailed_info_eedid(connector, edid, quirks); ++ num_modes += add_standard_modes(connector, edid); ++ num_modes += add_established_modes(connector, edid); + + if (quirks & (EDID_QUIRK_PREFER_LARGE_60 | EDID_QUIRK_PREFER_LARGE_75)) + edid_fixup_preferred(connector, quirks); +diff --git a/drivers/gpu/drm/drm_fb_helper.c b/drivers/gpu/drm/drm_fb_helper.c +index 0f9e905..da258ca 100644 +--- a/drivers/gpu/drm/drm_fb_helper.c ++++ b/drivers/gpu/drm/drm_fb_helper.c +@@ -27,6 +27,7 @@ + * Dave Airlie + * Jesse Barnes + */ ++#include + #include + #include + #include "drmP.h" +@@ -50,21 +51,6 @@ int drm_fb_helper_add_connector(struct drm_connector *connector) + } + EXPORT_SYMBOL(drm_fb_helper_add_connector); + +-static int my_atoi(const char *name) +-{ +- int val = 0; +- +- for (;; name++) { +- switch (*name) { +- case '0' ... '9': +- val = 10*val+(*name-'0'); +- break; +- default: +- return val; +- } +- } +-} +- + /** + * drm_fb_helper_connector_parse_command_line - parse command line for connector + * @connector - connector to parse line for +@@ -111,7 +97,7 @@ static bool drm_fb_helper_connector_parse_command_line(struct drm_connector *con + namelen = i; + if (!refresh_specified && !bpp_specified && + !yres_specified) { +- refresh = my_atoi(&name[i+1]); ++ refresh = simple_strtol(&name[i+1], NULL, 10); + refresh_specified = 1; + if (cvt || rb) + cvt = 0; +@@ -121,7 +107,7 @@ static bool drm_fb_helper_connector_parse_command_line(struct drm_connector *con + case '-': + namelen = i; + if (!bpp_specified && !yres_specified) { +- bpp = my_atoi(&name[i+1]); ++ bpp = simple_strtol(&name[i+1], NULL, 10); + bpp_specified = 1; + if (cvt || rb) + cvt = 0; +@@ -130,7 +116,7 @@ static bool drm_fb_helper_connector_parse_command_line(struct drm_connector *con + break; + case 'x': + if (!yres_specified) { +- yres = my_atoi(&name[i+1]); ++ yres = simple_strtol(&name[i+1], NULL, 10); + yres_specified = 1; + } else + goto done; +@@ -170,7 +156,7 @@ static bool drm_fb_helper_connector_parse_command_line(struct drm_connector *con + } + } + if (i < 0 && yres_specified) { +- xres = my_atoi(name); ++ xres = simple_strtol(name, NULL, 10); + res_specified = 1; + } + done: +@@ -297,6 +283,8 @@ static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { + .help_msg = "force-fb(V)", + .action_msg = "Restore framebuffer console", + }; ++#else ++static struct sysrq_key_op sysrq_drm_fb_helper_restore_op = { }; + #endif + + static void drm_fb_helper_on(struct fb_info *info) +diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c +index 08d14df..4804872 100644 +--- a/drivers/gpu/drm/drm_fops.c ++++ b/drivers/gpu/drm/drm_fops.c +@@ -140,14 +140,16 @@ int drm_open(struct inode *inode, struct file *filp) + spin_unlock(&dev->count_lock); + } + out: +- mutex_lock(&dev->struct_mutex); +- if (minor->type == DRM_MINOR_LEGACY) { +- BUG_ON((dev->dev_mapping != NULL) && +- (dev->dev_mapping != inode->i_mapping)); +- if (dev->dev_mapping == NULL) +- dev->dev_mapping = inode->i_mapping; ++ if (!retcode) { ++ mutex_lock(&dev->struct_mutex); ++ if (minor->type == DRM_MINOR_LEGACY) { ++ if (dev->dev_mapping == NULL) ++ dev->dev_mapping = inode->i_mapping; ++ else if (dev->dev_mapping != inode->i_mapping) ++ retcode = -ENODEV; ++ } ++ mutex_unlock(&dev->struct_mutex); + } +- mutex_unlock(&dev->struct_mutex); + + return retcode; + } +diff --git a/drivers/gpu/drm/drm_gem.c b/drivers/gpu/drm/drm_gem.c +index 8bf3770..aa89d4b 100644 +--- a/drivers/gpu/drm/drm_gem.c ++++ b/drivers/gpu/drm/drm_gem.c +@@ -192,9 +192,7 @@ drm_gem_handle_delete(struct drm_file *filp, u32 handle) + idr_remove(&filp->object_idr, handle); + spin_unlock(&filp->table_lock); + +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_handle_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_handle_unreference_unlocked(obj); + + return 0; + } +@@ -325,9 +323,7 @@ again: + } + + err: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + return ret; + } + +@@ -358,9 +354,7 @@ drm_gem_open_ioctl(struct drm_device *dev, void *data, + return -ENOENT; + + ret = drm_gem_handle_create(file_priv, obj, &handle); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + if (ret) + return ret; + +@@ -390,7 +384,7 @@ drm_gem_object_release_handle(int id, void *ptr, void *data) + { + struct drm_gem_object *obj = ptr; + +- drm_gem_object_handle_unreference(obj); ++ drm_gem_object_handle_unreference_unlocked(obj); + + return 0; + } +@@ -403,16 +397,25 @@ drm_gem_object_release_handle(int id, void *ptr, void *data) + void + drm_gem_release(struct drm_device *dev, struct drm_file *file_private) + { +- mutex_lock(&dev->struct_mutex); + idr_for_each(&file_private->object_idr, + &drm_gem_object_release_handle, NULL); + + idr_destroy(&file_private->object_idr); +- mutex_unlock(&dev->struct_mutex); ++} ++ ++static void ++drm_gem_object_free_common(struct drm_gem_object *obj) ++{ ++ struct drm_device *dev = obj->dev; ++ fput(obj->filp); ++ atomic_dec(&dev->object_count); ++ atomic_sub(obj->size, &dev->object_memory); ++ kfree(obj); + } + + /** + * Called after the last reference to the object has been lost. ++ * Must be called holding struct_ mutex + * + * Frees the object + */ +@@ -427,14 +430,40 @@ drm_gem_object_free(struct kref *kref) + if (dev->driver->gem_free_object != NULL) + dev->driver->gem_free_object(obj); + +- fput(obj->filp); +- atomic_dec(&dev->object_count); +- atomic_sub(obj->size, &dev->object_memory); +- kfree(obj); ++ drm_gem_object_free_common(obj); + } + EXPORT_SYMBOL(drm_gem_object_free); + + /** ++ * Called after the last reference to the object has been lost. ++ * Must be called without holding struct_mutex ++ * ++ * Frees the object ++ */ ++void ++drm_gem_object_free_unlocked(struct kref *kref) ++{ ++ struct drm_gem_object *obj = (struct drm_gem_object *) kref; ++ struct drm_device *dev = obj->dev; ++ ++ if (dev->driver->gem_free_object_unlocked != NULL) ++ dev->driver->gem_free_object_unlocked(obj); ++ else if (dev->driver->gem_free_object != NULL) { ++ mutex_lock(&dev->struct_mutex); ++ dev->driver->gem_free_object(obj); ++ mutex_unlock(&dev->struct_mutex); ++ } ++ ++ drm_gem_object_free_common(obj); ++} ++EXPORT_SYMBOL(drm_gem_object_free_unlocked); ++ ++static void drm_gem_object_ref_bug(struct kref *list_kref) ++{ ++ BUG(); ++} ++ ++/** + * Called after the last handle to the object has been closed + * + * Removes any name for the object. Note that this must be +@@ -458,8 +487,10 @@ drm_gem_object_handle_free(struct kref *kref) + /* + * The object name held a reference to this object, drop + * that now. ++ * ++ * This cannot be the last reference, since the handle holds one too. + */ +- drm_gem_object_unreference(obj); ++ kref_put(&obj->refcount, drm_gem_object_ref_bug); + } else + spin_unlock(&dev->object_name_lock); + +@@ -477,11 +508,8 @@ EXPORT_SYMBOL(drm_gem_vm_open); + void drm_gem_vm_close(struct vm_area_struct *vma) + { + struct drm_gem_object *obj = vma->vm_private_data; +- struct drm_device *dev = obj->dev; + +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + } + EXPORT_SYMBOL(drm_gem_vm_close); + +diff --git a/drivers/gpu/drm/drm_modes.c b/drivers/gpu/drm/drm_modes.c +index 76d6339..f1f473e 100644 +--- a/drivers/gpu/drm/drm_modes.c ++++ b/drivers/gpu/drm/drm_modes.c +@@ -258,8 +258,10 @@ struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay, + drm_mode->clock -= drm_mode->clock % CVT_CLOCK_STEP; + /* 18/16. Find actual vertical frame frequency */ + /* ignore - just set the mode flag for interlaced */ +- if (interlaced) ++ if (interlaced) { + drm_mode->vtotal *= 2; ++ drm_mode->flags |= DRM_MODE_FLAG_INTERLACE; ++ } + /* Fill the mode line name */ + drm_mode_set_name(drm_mode); + if (reduced) +@@ -268,43 +270,35 @@ struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, int hdisplay, + else + drm_mode->flags |= (DRM_MODE_FLAG_PVSYNC | + DRM_MODE_FLAG_NHSYNC); +- if (interlaced) +- drm_mode->flags |= DRM_MODE_FLAG_INTERLACE; + +- return drm_mode; ++ return drm_mode; + } + EXPORT_SYMBOL(drm_cvt_mode); + + /** +- * drm_gtf_mode - create the modeline based on GTF algorithm ++ * drm_gtf_mode_complex - create the modeline based on full GTF algorithm + * + * @dev :drm device + * @hdisplay :hdisplay size + * @vdisplay :vdisplay size + * @vrefresh :vrefresh rate. + * @interlaced :whether the interlace is supported +- * @margins :whether the margin is supported ++ * @margins :desired margin size ++ * @GTF_[MCKJ] :extended GTF formula parameters + * + * LOCKING. + * none. + * +- * return the modeline based on GTF algorithm +- * +- * This function is to create the modeline based on the GTF algorithm. +- * Generalized Timing Formula is derived from: +- * GTF Spreadsheet by Andy Morrish (1/5/97) +- * available at http://www.vesa.org ++ * return the modeline based on full GTF algorithm. + * +- * And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c. +- * What I have done is to translate it by using integer calculation. +- * I also refer to the function of fb_get_mode in the file of +- * drivers/video/fbmon.c ++ * GTF feature blocks specify C and J in multiples of 0.5, so we pass them ++ * in here multiplied by two. For a C of 40, pass in 80. + */ +-struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, int hdisplay, +- int vdisplay, int vrefresh, +- bool interlaced, int margins) +-{ +- /* 1) top/bottom margin size (% of height) - default: 1.8, */ ++struct drm_display_mode * ++drm_gtf_mode_complex(struct drm_device *dev, int hdisplay, int vdisplay, ++ int vrefresh, bool interlaced, int margins, ++ int GTF_M, int GTF_2C, int GTF_K, int GTF_2J) ++{ /* 1) top/bottom margin size (% of height) - default: 1.8, */ + #define GTF_MARGIN_PERCENTAGE 18 + /* 2) character cell horizontal granularity (pixels) - default 8 */ + #define GTF_CELL_GRAN 8 +@@ -316,17 +310,9 @@ struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, int hdisplay, + #define H_SYNC_PERCENT 8 + /* min time of vsync + back porch (microsec) */ + #define MIN_VSYNC_PLUS_BP 550 +- /* blanking formula gradient */ +-#define GTF_M 600 +- /* blanking formula offset */ +-#define GTF_C 40 +- /* blanking formula scaling factor */ +-#define GTF_K 128 +- /* blanking formula scaling factor */ +-#define GTF_J 20 + /* C' and M' are part of the Blanking Duty Cycle computation */ +-#define GTF_C_PRIME (((GTF_C - GTF_J) * GTF_K / 256) + GTF_J) +-#define GTF_M_PRIME (GTF_K * GTF_M / 256) ++#define GTF_C_PRIME ((((GTF_2C - GTF_2J) * GTF_K / 256) + GTF_2J) / 2) ++#define GTF_M_PRIME (GTF_K * GTF_M / 256) + struct drm_display_mode *drm_mode; + unsigned int hdisplay_rnd, vdisplay_rnd, vfieldrate_rqd; + int top_margin, bottom_margin; +@@ -460,17 +446,61 @@ struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, int hdisplay, + + drm_mode->clock = pixel_freq; + +- drm_mode_set_name(drm_mode); +- drm_mode->flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC; +- + if (interlaced) { + drm_mode->vtotal *= 2; + drm_mode->flags |= DRM_MODE_FLAG_INTERLACE; + } + ++ drm_mode_set_name(drm_mode); ++ if (GTF_M == 600 && GTF_2C == 80 && GTF_K == 128 && GTF_2J == 40) ++ drm_mode->flags = DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_PVSYNC; ++ else ++ drm_mode->flags = DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_NVSYNC; ++ + return drm_mode; + } ++EXPORT_SYMBOL(drm_gtf_mode_complex); ++ ++/** ++ * drm_gtf_mode - create the modeline based on GTF algorithm ++ * ++ * @dev :drm device ++ * @hdisplay :hdisplay size ++ * @vdisplay :vdisplay size ++ * @vrefresh :vrefresh rate. ++ * @interlaced :whether the interlace is supported ++ * @margins :whether the margin is supported ++ * ++ * LOCKING. ++ * none. ++ * ++ * return the modeline based on GTF algorithm ++ * ++ * This function is to create the modeline based on the GTF algorithm. ++ * Generalized Timing Formula is derived from: ++ * GTF Spreadsheet by Andy Morrish (1/5/97) ++ * available at http://www.vesa.org ++ * ++ * And it is copied from the file of xserver/hw/xfree86/modes/xf86gtf.c. ++ * What I have done is to translate it by using integer calculation. ++ * I also refer to the function of fb_get_mode in the file of ++ * drivers/video/fbmon.c ++ * ++ * Standard GTF parameters: ++ * M = 600 ++ * C = 40 ++ * K = 128 ++ * J = 20 ++ */ ++struct drm_display_mode * ++drm_gtf_mode(struct drm_device *dev, int hdisplay, int vdisplay, int vrefresh, ++ bool lace, int margins) ++{ ++ return drm_gtf_mode_complex(dev, hdisplay, vdisplay, vrefresh, lace, ++ margins, 600, 40 * 2, 128, 20 * 2); ++} + EXPORT_SYMBOL(drm_gtf_mode); ++ + /** + * drm_mode_set_name - set the name on a mode + * @mode: name will be set in this mode +@@ -482,8 +512,11 @@ EXPORT_SYMBOL(drm_gtf_mode); + */ + void drm_mode_set_name(struct drm_display_mode *mode) + { +- snprintf(mode->name, DRM_DISPLAY_MODE_LEN, "%dx%d", mode->hdisplay, +- mode->vdisplay); ++ bool interlaced = !!(mode->flags & DRM_MODE_FLAG_INTERLACE); ++ ++ snprintf(mode->name, DRM_DISPLAY_MODE_LEN, "%dx%d%s", ++ mode->hdisplay, mode->vdisplay, ++ interlaced ? "i" : ""); + } + EXPORT_SYMBOL(drm_mode_set_name); + +diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c +index 7e42b7e..9721513 100644 +--- a/drivers/gpu/drm/drm_sysfs.c ++++ b/drivers/gpu/drm/drm_sysfs.c +@@ -334,7 +334,7 @@ static struct device_attribute connector_attrs_opt1[] = { + static struct bin_attribute edid_attr = { + .attr.name = "edid", + .attr.mode = 0444, +- .size = 128, ++ .size = 0, + .read = edid_show, + }; + +diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c +index fd099a1..1c0cc9e 100644 +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -128,9 +128,7 @@ i915_gem_create_ioctl(struct drm_device *dev, void *data, + return -ENOMEM; + + ret = drm_gem_handle_create(file_priv, obj, &handle); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_handle_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_handle_unreference_unlocked(obj); + + if (ret) + return ret; +@@ -488,7 +486,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, + */ + if (args->offset > obj->size || args->size > obj->size || + args->offset + args->size > obj->size) { +- drm_gem_object_unreference(obj); ++ drm_gem_object_unreference_unlocked(obj); + return -EINVAL; + } + +@@ -501,7 +499,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, + file_priv); + } + +- drm_gem_object_unreference(obj); ++ drm_gem_object_unreference_unlocked(obj); + + return ret; + } +@@ -961,7 +959,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, + */ + if (args->offset > obj->size || args->size > obj->size || + args->offset + args->size > obj->size) { +- drm_gem_object_unreference(obj); ++ drm_gem_object_unreference_unlocked(obj); + return -EINVAL; + } + +@@ -995,7 +993,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, + DRM_INFO("pwrite failed %d\n", ret); + #endif + +- drm_gem_object_unreference(obj); ++ drm_gem_object_unreference_unlocked(obj); + + return ret; + } +@@ -1138,9 +1136,7 @@ i915_gem_mmap_ioctl(struct drm_device *dev, void *data, + PROT_READ | PROT_WRITE, MAP_SHARED, + args->offset); + up_write(¤t->mm->mmap_sem); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + if (IS_ERR((void *)addr)) + return addr; + +diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c +index df278b2..137e888 100644 +--- a/drivers/gpu/drm/i915/i915_gem_tiling.c ++++ b/drivers/gpu/drm/i915/i915_gem_tiling.c +@@ -438,9 +438,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, + obj_priv = obj->driver_private; + + if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) { +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + return -EINVAL; + } + +diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c +index b27202d..c8fd15f 100644 +--- a/drivers/gpu/drm/i915/intel_display.c ++++ b/drivers/gpu/drm/i915/intel_display.c +@@ -3553,11 +3553,10 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, + intel_crtc->cursor_bo = bo; + + return 0; +-fail: +- mutex_lock(&dev->struct_mutex); + fail_locked: +- drm_gem_object_unreference(bo); + mutex_unlock(&dev->struct_mutex); ++fail: ++ drm_gem_object_unreference_unlocked(bo); + return ret; + } + +@@ -4476,9 +4475,7 @@ static void intel_user_framebuffer_destroy(struct drm_framebuffer *fb) + intelfb_remove(dev, fb); + + drm_framebuffer_cleanup(fb); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(intel_fb->obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(intel_fb->obj); + + kfree(intel_fb); + } +@@ -4541,9 +4538,7 @@ intel_user_framebuffer_create(struct drm_device *dev, + + ret = intel_framebuffer_create(dev, mode_cmd, &fb, obj); + if (ret) { +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + return NULL; + } + +diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c +index 63f569b..f8887f6 100644 +--- a/drivers/gpu/drm/i915/intel_overlay.c ++++ b/drivers/gpu/drm/i915/intel_overlay.c +@@ -1183,8 +1183,8 @@ int intel_overlay_put_image(struct drm_device *dev, void *data, + out_unlock: + mutex_unlock(&dev->struct_mutex); + mutex_unlock(&dev->mode_config.mutex); +- drm_gem_object_unreference(new_bo); + out_free: ++ drm_gem_object_unreference_unlocked(new_bo); + kfree(params); + + return ret; +diff --git a/drivers/gpu/drm/nouveau/nouveau_display.c b/drivers/gpu/drm/nouveau/nouveau_display.c +index dfc9439..cf1c5c0 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_display.c ++++ b/drivers/gpu/drm/nouveau/nouveau_display.c +@@ -39,11 +39,8 @@ nouveau_user_framebuffer_destroy(struct drm_framebuffer *drm_fb) + if (drm_fb->fbdev) + nouveau_fbcon_remove(dev, drm_fb); + +- if (fb->nvbo) { +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(fb->nvbo->gem); +- mutex_unlock(&dev->struct_mutex); +- } ++ if (fb->nvbo) ++ drm_gem_object_unreference_unlocked(fb->nvbo->gem); + + drm_framebuffer_cleanup(drm_fb); + kfree(fb); +diff --git a/drivers/gpu/drm/nouveau/nouveau_fbcon.c b/drivers/gpu/drm/nouveau/nouveau_fbcon.c +index ea879a2..d48c59c 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_fbcon.c ++++ b/drivers/gpu/drm/nouveau/nouveau_fbcon.c +@@ -401,10 +401,8 @@ nouveau_fbcon_remove(struct drm_device *dev, struct drm_framebuffer *fb) + + unregister_framebuffer(info); + nouveau_bo_unmap(nouveau_fb->nvbo); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(nouveau_fb->nvbo->gem); ++ drm_gem_object_unreference_unlocked(nouveau_fb->nvbo->gem); + nouveau_fb->nvbo = NULL; +- mutex_unlock(&dev->struct_mutex); + if (par) + drm_fb_helper_free(&par->helper); + framebuffer_release(info); +diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c +index 70cc308..34063c5 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_gem.c ++++ b/drivers/gpu/drm/nouveau/nouveau_gem.c +@@ -167,12 +167,10 @@ nouveau_gem_ioctl_new(struct drm_device *dev, void *data, + + ret = drm_gem_handle_create(file_priv, nvbo->gem, &req->info.handle); + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_handle_unreference(nvbo->gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_handle_unreference_unlocked(nvbo->gem); + + if (ret) +- drm_gem_object_unreference(nvbo->gem); ++ drm_gem_object_unreference_unlocked(nvbo->gem); + return ret; + } + +@@ -865,9 +863,7 @@ nouveau_gem_ioctl_pin(struct drm_device *dev, void *data, + req->domain = NOUVEAU_GEM_DOMAIN_VRAM; + + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + + return ret; + } +@@ -891,9 +887,7 @@ nouveau_gem_ioctl_unpin(struct drm_device *dev, void *data, + + ret = nouveau_bo_unpin(nouveau_gem_object(gem)); + +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + + return ret; + } +@@ -935,9 +929,7 @@ nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data, + } + + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + return ret; + } + +@@ -965,9 +957,7 @@ nouveau_gem_ioctl_cpu_fini(struct drm_device *dev, void *data, + ret = 0; + + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + return ret; + } + +@@ -986,9 +976,7 @@ nouveau_gem_ioctl_info(struct drm_device *dev, void *data, + return -EINVAL; + + ret = nouveau_gem_info(gem, req); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + return ret; + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_notifier.c b/drivers/gpu/drm/nouveau/nouveau_notifier.c +index d99dc08..9537f3e 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_notifier.c ++++ b/drivers/gpu/drm/nouveau/nouveau_notifier.c +@@ -61,11 +61,8 @@ nouveau_notifier_init_channel(struct nouveau_channel *chan) + + chan->notifier_bo = ntfy; + out_err: +- if (ret) { +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(ntfy->gem); +- mutex_unlock(&dev->struct_mutex); +- } ++ if (ret) ++ drm_gem_object_unreference_unlocked(ntfy->gem); + + return ret; + } +@@ -81,8 +78,8 @@ nouveau_notifier_takedown_channel(struct nouveau_channel *chan) + nouveau_bo_unmap(chan->notifier_bo); + mutex_lock(&dev->struct_mutex); + nouveau_bo_unpin(chan->notifier_bo); +- drm_gem_object_unreference(chan->notifier_bo->gem); + mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(chan->notifier_bo->gem); + nouveau_mem_takedown(&chan->notifier_heap); + } + +diff --git a/drivers/gpu/drm/nouveau/nv04_crtc.c b/drivers/gpu/drm/nouveau/nv04_crtc.c +index d2f143e..a1d1ebb 100644 +--- a/drivers/gpu/drm/nouveau/nv04_crtc.c ++++ b/drivers/gpu/drm/nouveau/nv04_crtc.c +@@ -926,9 +926,7 @@ nv04_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, + nv_crtc->cursor.set_offset(nv_crtc, nv_crtc->cursor.offset); + nv_crtc->cursor.show(nv_crtc, true); + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + return ret; + } + +diff --git a/drivers/gpu/drm/nouveau/nv50_crtc.c b/drivers/gpu/drm/nouveau/nv50_crtc.c +index d1a651e..cfabeb9 100644 +--- a/drivers/gpu/drm/nouveau/nv50_crtc.c ++++ b/drivers/gpu/drm/nouveau/nv50_crtc.c +@@ -358,9 +358,7 @@ nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, + nv_crtc->cursor.show(nv_crtc, true); + + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gem); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gem); + return ret; + } + +diff --git a/drivers/gpu/drm/radeon/radeon_cs.c b/drivers/gpu/drm/radeon/radeon_cs.c +index e9d0850..70ba02e 100644 +--- a/drivers/gpu/drm/radeon/radeon_cs.c ++++ b/drivers/gpu/drm/radeon/radeon_cs.c +@@ -194,11 +194,8 @@ static void radeon_cs_parser_fini(struct radeon_cs_parser *parser, int error) + radeon_bo_list_unreserve(&parser->validated); + if (parser->relocs != NULL) { + for (i = 0; i < parser->nrelocs; i++) { +- if (parser->relocs[i].gobj) { +- mutex_lock(&parser->rdev->ddev->struct_mutex); +- drm_gem_object_unreference(parser->relocs[i].gobj); +- mutex_unlock(&parser->rdev->ddev->struct_mutex); +- } ++ if (parser->relocs[i].gobj) ++ drm_gem_object_unreference_unlocked(parser->relocs[i].gobj); + } + } + kfree(parser->track); +diff --git a/drivers/gpu/drm/radeon/radeon_cursor.c b/drivers/gpu/drm/radeon/radeon_cursor.c +index 28772a3..6f4a553 100644 +--- a/drivers/gpu/drm/radeon/radeon_cursor.c ++++ b/drivers/gpu/drm/radeon/radeon_cursor.c +@@ -169,17 +169,13 @@ int radeon_crtc_cursor_set(struct drm_crtc *crtc, + unpin: + if (radeon_crtc->cursor_bo) { + radeon_gem_object_unpin(radeon_crtc->cursor_bo); +- mutex_lock(&crtc->dev->struct_mutex); +- drm_gem_object_unreference(radeon_crtc->cursor_bo); +- mutex_unlock(&crtc->dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(radeon_crtc->cursor_bo); + } + + radeon_crtc->cursor_bo = obj; + return 0; + fail: +- mutex_lock(&crtc->dev->struct_mutex); +- drm_gem_object_unreference(obj); +- mutex_unlock(&crtc->dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(obj); + + return 0; + } +diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c +index 7e17a36..3db8255 100644 +--- a/drivers/gpu/drm/radeon/radeon_display.c ++++ b/drivers/gpu/drm/radeon/radeon_display.c +@@ -679,11 +679,8 @@ static void radeon_user_framebuffer_destroy(struct drm_framebuffer *fb) + if (fb->fbdev) + radeonfb_remove(dev, fb); + +- if (radeon_fb->obj) { +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(radeon_fb->obj); +- mutex_unlock(&dev->struct_mutex); +- } ++ if (radeon_fb->obj) ++ drm_gem_object_unreference_unlocked(radeon_fb->obj); + drm_framebuffer_cleanup(fb); + kfree(radeon_fb); + } +diff --git a/drivers/gpu/drm/radeon/radeon_gem.c b/drivers/gpu/drm/radeon/radeon_gem.c +index db8e9a3..ef92d14 100644 +--- a/drivers/gpu/drm/radeon/radeon_gem.c ++++ b/drivers/gpu/drm/radeon/radeon_gem.c +@@ -69,9 +69,7 @@ int radeon_gem_object_create(struct radeon_device *rdev, int size, + if (r != -ERESTARTSYS) + DRM_ERROR("Failed to allocate GEM object (%d, %d, %u, %d)\n", + size, initial_domain, alignment, r); +- mutex_lock(&rdev->ddev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&rdev->ddev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } + gobj->driver_private = robj; +@@ -202,14 +200,10 @@ int radeon_gem_create_ioctl(struct drm_device *dev, void *data, + } + r = drm_gem_handle_create(filp, gobj, &handle); + if (r) { +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_handle_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_handle_unreference_unlocked(gobj); + args->handle = handle; + return 0; + } +@@ -236,9 +230,7 @@ int radeon_gem_set_domain_ioctl(struct drm_device *dev, void *data, + + r = radeon_gem_set_domain(gobj, args->read_domains, args->write_domain); + +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } + +@@ -255,9 +247,7 @@ int radeon_gem_mmap_ioctl(struct drm_device *dev, void *data, + } + robj = gobj->driver_private; + args->addr_ptr = radeon_bo_mmap_offset(robj); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return 0; + } + +@@ -288,9 +278,7 @@ int radeon_gem_busy_ioctl(struct drm_device *dev, void *data, + default: + break; + } +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } + +@@ -311,9 +299,7 @@ int radeon_gem_wait_idle_ioctl(struct drm_device *dev, void *data, + /* callback hw specific functions if any */ + if (robj->rdev->asic->ioctl_wait_idle) + robj->rdev->asic->ioctl_wait_idle(robj->rdev, robj); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } + +@@ -331,9 +317,7 @@ int radeon_gem_set_tiling_ioctl(struct drm_device *dev, void *data, + return -EINVAL; + robj = gobj->driver_private; + r = radeon_bo_set_tiling_flags(robj, args->tiling_flags, args->pitch); +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } + +@@ -356,8 +340,6 @@ int radeon_gem_get_tiling_ioctl(struct drm_device *dev, void *data, + radeon_bo_get_tiling_flags(rbo, &args->tiling_flags, &args->pitch); + radeon_bo_unreserve(rbo); + out: +- mutex_lock(&dev->struct_mutex); +- drm_gem_object_unreference(gobj); +- mutex_unlock(&dev->struct_mutex); ++ drm_gem_object_unreference_unlocked(gobj); + return r; + } +diff --git a/drivers/gpu/drm/ttm/Makefile b/drivers/gpu/drm/ttm/Makefile +index 1e138f5..4256e20 100644 +--- a/drivers/gpu/drm/ttm/Makefile ++++ b/drivers/gpu/drm/ttm/Makefile +@@ -4,6 +4,6 @@ + ccflags-y := -Iinclude/drm + ttm-y := ttm_agp_backend.o ttm_memory.o ttm_tt.o ttm_bo.o \ + ttm_bo_util.o ttm_bo_vm.o ttm_module.o ttm_global.o \ +- ttm_object.o ttm_lock.o ttm_execbuf_util.o ++ ttm_object.o ttm_lock.o ttm_execbuf_util.o ttm_page_alloc.o + + obj-$(CONFIG_DRM_TTM) += ttm.o +diff --git a/drivers/gpu/drm/ttm/ttm_bo.c b/drivers/gpu/drm/ttm/ttm_bo.c +index c7320ce..9db02bb 100644 +--- a/drivers/gpu/drm/ttm/ttm_bo.c ++++ b/drivers/gpu/drm/ttm/ttm_bo.c +@@ -1425,8 +1425,8 @@ int ttm_bo_global_init(struct ttm_global_reference *ref) + + atomic_set(&glob->bo_count, 0); + +- kobject_init(&glob->kobj, &ttm_bo_glob_kobj_type); +- ret = kobject_add(&glob->kobj, ttm_get_kobj(), "buffer_objects"); ++ ret = kobject_init_and_add( ++ &glob->kobj, &ttm_bo_glob_kobj_type, ttm_get_kobj(), "buffer_objects"); + if (unlikely(ret != 0)) + kobject_put(&glob->kobj); + return ret; +diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c +index f5245c0..4057a17 100644 +--- a/drivers/gpu/drm/ttm/ttm_memory.c ++++ b/drivers/gpu/drm/ttm/ttm_memory.c +@@ -27,6 +27,7 @@ + + #include "ttm/ttm_memory.h" + #include "ttm/ttm_module.h" ++#include "ttm/ttm_page_alloc.h" + #include + #include + #include +@@ -260,8 +261,8 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob, + zone->used_mem = 0; + zone->glob = glob; + glob->zone_kernel = zone; +- kobject_init(&zone->kobj, &ttm_mem_zone_kobj_type); +- ret = kobject_add(&zone->kobj, &glob->kobj, zone->name); ++ ret = kobject_init_and_add( ++ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name); + if (unlikely(ret != 0)) { + kobject_put(&zone->kobj); + return ret; +@@ -296,8 +297,8 @@ static int ttm_mem_init_highmem_zone(struct ttm_mem_global *glob, + zone->used_mem = 0; + zone->glob = glob; + glob->zone_highmem = zone; +- kobject_init(&zone->kobj, &ttm_mem_zone_kobj_type); +- ret = kobject_add(&zone->kobj, &glob->kobj, zone->name); ++ ret = kobject_init_and_add( ++ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name); + if (unlikely(ret != 0)) { + kobject_put(&zone->kobj); + return ret; +@@ -343,8 +344,8 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob, + zone->used_mem = 0; + zone->glob = glob; + glob->zone_dma32 = zone; +- kobject_init(&zone->kobj, &ttm_mem_zone_kobj_type); +- ret = kobject_add(&zone->kobj, &glob->kobj, zone->name); ++ ret = kobject_init_and_add( ++ &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name); + if (unlikely(ret != 0)) { + kobject_put(&zone->kobj); + return ret; +@@ -365,10 +366,8 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) + glob->swap_queue = create_singlethread_workqueue("ttm_swap"); + INIT_WORK(&glob->work, ttm_shrink_work); + init_waitqueue_head(&glob->queue); +- kobject_init(&glob->kobj, &ttm_mem_glob_kobj_type); +- ret = kobject_add(&glob->kobj, +- ttm_get_kobj(), +- "memory_accounting"); ++ ret = kobject_init_and_add( ++ &glob->kobj, &ttm_mem_glob_kobj_type, ttm_get_kobj(), "memory_accounting"); + if (unlikely(ret != 0)) { + kobject_put(&glob->kobj); + return ret; +@@ -394,6 +393,7 @@ int ttm_mem_global_init(struct ttm_mem_global *glob) + "Zone %7s: Available graphics memory: %llu kiB.\n", + zone->name, (unsigned long long) zone->max_mem >> 10); + } ++ ttm_page_alloc_init(glob, glob->zone_kernel->max_mem/(2*PAGE_SIZE)); + return 0; + out_no_zone: + ttm_mem_global_release(glob); +@@ -406,6 +406,9 @@ void ttm_mem_global_release(struct ttm_mem_global *glob) + unsigned int i; + struct ttm_mem_zone *zone; + ++ /* let the page allocator first stop the shrink work. */ ++ ttm_page_alloc_fini(); ++ + flush_workqueue(glob->swap_queue); + destroy_workqueue(glob->swap_queue); + glob->swap_queue = NULL; +@@ -413,7 +416,7 @@ void ttm_mem_global_release(struct ttm_mem_global *glob) + zone = glob->zones[i]; + kobject_del(&zone->kobj); + kobject_put(&zone->kobj); +- } ++ } + kobject_del(&glob->kobj); + kobject_put(&glob->kobj); + } +diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c +new file mode 100644 +index 0000000..03509f8 +--- /dev/null ++++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c +@@ -0,0 +1,855 @@ ++/* ++ * Copyright (c) Red Hat Inc. ++ ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sub license, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice (including the ++ * next paragraph) shall be included in all copies or substantial portions ++ * of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ * DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Dave Airlie ++ * Jerome Glisse ++ * Pauli Nieminen ++ */ ++ ++/* simple list based uncached page pool ++ * - Pool collects resently freed pages for reuse ++ * - Use page->lru to keep a free list ++ * - doesn't track currently in use pages ++ */ ++#include ++#include ++#include ++#include ++#include ++#include ++#include /* for seq_printf */ ++#include ++ ++#include ++#include ++ ++#include "ttm/ttm_bo_driver.h" ++#include "ttm/ttm_page_alloc.h" ++ ++ ++#define NUM_PAGES_TO_ALLOC (PAGE_SIZE/sizeof(struct page *)) ++#define SMALL_ALLOCATION 16 ++#define FREE_ALL_PAGES (~0U) ++/* times are in msecs */ ++#define PAGE_FREE_INTERVAL 1000 ++ ++/** ++ * struct ttm_page_pool - Pool to reuse recently allocated uc/wc pages. ++ * ++ * @lock: Protects the shared pool from concurrnet access. Must be used with ++ * irqsave/irqrestore variants because pool allocator maybe called from ++ * delayed work. ++ * @fill_lock: Prevent concurrent calls to fill. ++ * @list: Pool of free uc/wc pages for fast reuse. ++ * @gfp_flags: Flags to pass for alloc_page. ++ * @npages: Number of pages in pool. ++ */ ++struct ttm_page_pool { ++ spinlock_t lock; ++ bool fill_lock; ++ struct list_head list; ++ int gfp_flags; ++ unsigned npages; ++ char *name; ++ unsigned long nfrees; ++ unsigned long nrefills; ++}; ++ ++/** ++ * Limits for the pool. They are handled without locks because only place where ++ * they may change is in sysfs store. They won't have immediate effect anyway ++ * so forcing serialiazation to access them is pointless. ++ */ ++ ++struct ttm_pool_opts { ++ unsigned alloc_size; ++ unsigned max_size; ++ unsigned small; ++}; ++ ++#define NUM_POOLS 4 ++ ++/** ++ * struct ttm_pool_manager - Holds memory pools for fst allocation ++ * ++ * Manager is read only object for pool code so it doesn't need locking. ++ * ++ * @free_interval: minimum number of jiffies between freeing pages from pool. ++ * @page_alloc_inited: reference counting for pool allocation. ++ * @work: Work that is used to shrink the pool. Work is only run when there is ++ * some pages to free. ++ * @small_allocation: Limit in number of pages what is small allocation. ++ * ++ * @pools: All pool objects in use. ++ **/ ++struct ttm_pool_manager { ++ struct kobject kobj; ++ struct shrinker mm_shrink; ++ atomic_t page_alloc_inited; ++ struct ttm_pool_opts options; ++ ++ union { ++ struct ttm_page_pool pools[NUM_POOLS]; ++ struct { ++ struct ttm_page_pool wc_pool; ++ struct ttm_page_pool uc_pool; ++ struct ttm_page_pool wc_pool_dma32; ++ struct ttm_page_pool uc_pool_dma32; ++ } ; ++ }; ++}; ++ ++static struct attribute ttm_page_pool_max = { ++ .name = "pool_max_size", ++ .mode = S_IRUGO | S_IWUSR ++}; ++static struct attribute ttm_page_pool_small = { ++ .name = "pool_small_allocation", ++ .mode = S_IRUGO | S_IWUSR ++}; ++static struct attribute ttm_page_pool_alloc_size = { ++ .name = "pool_allocation_size", ++ .mode = S_IRUGO | S_IWUSR ++}; ++ ++static struct attribute *ttm_pool_attrs[] = { ++ &ttm_page_pool_max, ++ &ttm_page_pool_small, ++ &ttm_page_pool_alloc_size, ++ NULL ++}; ++ ++static void ttm_pool_kobj_release(struct kobject *kobj) ++{ ++ struct ttm_pool_manager *m = ++ container_of(kobj, struct ttm_pool_manager, kobj); ++ (void)m; ++} ++ ++static ssize_t ttm_pool_store(struct kobject *kobj, ++ struct attribute *attr, const char *buffer, size_t size) ++{ ++ struct ttm_pool_manager *m = ++ container_of(kobj, struct ttm_pool_manager, kobj); ++ int chars; ++ unsigned val; ++ chars = sscanf(buffer, "%u", &val); ++ if (chars == 0) ++ return size; ++ ++ /* Convert kb to number of pages */ ++ val = val / (PAGE_SIZE >> 10); ++ ++ if (attr == &ttm_page_pool_max) ++ m->options.max_size = val; ++ else if (attr == &ttm_page_pool_small) ++ m->options.small = val; ++ else if (attr == &ttm_page_pool_alloc_size) { ++ if (val > NUM_PAGES_TO_ALLOC*8) { ++ printk(KERN_ERR "[ttm] Setting allocation size to %lu " ++ "is not allowed. Recomended size is " ++ "%lu\n", ++ NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 7), ++ NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10)); ++ return size; ++ } else if (val > NUM_PAGES_TO_ALLOC) { ++ printk(KERN_WARNING "[ttm] Setting allocation size to " ++ "larger than %lu is not recomended.\n", ++ NUM_PAGES_TO_ALLOC*(PAGE_SIZE >> 10)); ++ } ++ m->options.alloc_size = val; ++ } ++ ++ return size; ++} ++ ++static ssize_t ttm_pool_show(struct kobject *kobj, ++ struct attribute *attr, char *buffer) ++{ ++ struct ttm_pool_manager *m = ++ container_of(kobj, struct ttm_pool_manager, kobj); ++ unsigned val = 0; ++ ++ if (attr == &ttm_page_pool_max) ++ val = m->options.max_size; ++ else if (attr == &ttm_page_pool_small) ++ val = m->options.small; ++ else if (attr == &ttm_page_pool_alloc_size) ++ val = m->options.alloc_size; ++ ++ val = val * (PAGE_SIZE >> 10); ++ ++ return snprintf(buffer, PAGE_SIZE, "%u\n", val); ++} ++ ++static const struct sysfs_ops ttm_pool_sysfs_ops = { ++ .show = &ttm_pool_show, ++ .store = &ttm_pool_store, ++}; ++ ++static struct kobj_type ttm_pool_kobj_type = { ++ .release = &ttm_pool_kobj_release, ++ .sysfs_ops = &ttm_pool_sysfs_ops, ++ .default_attrs = ttm_pool_attrs, ++}; ++ ++static struct ttm_pool_manager _manager = { ++ .page_alloc_inited = ATOMIC_INIT(0) ++}; ++ ++#ifdef CONFIG_X86 ++/* TODO: add this to x86 like _uc, this version here is inefficient */ ++static int set_pages_array_wc(struct page **pages, int addrinarray) ++{ ++ int i; ++ ++ for (i = 0; i < addrinarray; i++) ++ set_memory_wc((unsigned long)page_address(pages[i]), 1); ++ return 0; ++} ++#else ++static int set_pages_array_wb(struct page **pages, int addrinarray) ++{ ++#ifdef TTM_HAS_AGP ++ int i; ++ ++ for (i = 0; i < addrinarray; i++) ++ unmap_page_from_agp(pages[i]); ++#endif ++ return 0; ++} ++ ++static int set_pages_array_wc(struct page **pages, int addrinarray) ++{ ++#ifdef TTM_HAS_AGP ++ int i; ++ ++ for (i = 0; i < addrinarray; i++) ++ map_page_into_agp(pages[i]); ++#endif ++ return 0; ++} ++ ++static int set_pages_array_uc(struct page **pages, int addrinarray) ++{ ++#ifdef TTM_HAS_AGP ++ int i; ++ ++ for (i = 0; i < addrinarray; i++) ++ map_page_into_agp(pages[i]); ++#endif ++ return 0; ++} ++#endif ++ ++/** ++ * Select the right pool or requested caching state and ttm flags. */ ++static struct ttm_page_pool *ttm_get_pool(int flags, ++ enum ttm_caching_state cstate) ++{ ++ int pool_index; ++ ++ if (cstate == tt_cached) ++ return NULL; ++ ++ if (cstate == tt_wc) ++ pool_index = 0x0; ++ else ++ pool_index = 0x1; ++ ++ if (flags & TTM_PAGE_FLAG_DMA32) ++ pool_index |= 0x2; ++ ++ return &_manager.pools[pool_index]; ++} ++ ++/* set memory back to wb and free the pages. */ ++static void ttm_pages_put(struct page *pages[], unsigned npages) ++{ ++ unsigned i; ++ if (set_pages_array_wb(pages, npages)) ++ printk(KERN_ERR "[ttm] Failed to set %d pages to wb!\n", ++ npages); ++ for (i = 0; i < npages; ++i) ++ __free_page(pages[i]); ++} ++ ++static void ttm_pool_update_free_locked(struct ttm_page_pool *pool, ++ unsigned freed_pages) ++{ ++ pool->npages -= freed_pages; ++ pool->nfrees += freed_pages; ++} ++ ++/** ++ * Free pages from pool. ++ * ++ * To prevent hogging the ttm_swap process we only free NUM_PAGES_TO_ALLOC ++ * number of pages in one go. ++ * ++ * @pool: to free the pages from ++ * @free_all: If set to true will free all pages in pool ++ **/ ++static int ttm_page_pool_free(struct ttm_page_pool *pool, unsigned nr_free) ++{ ++ unsigned long irq_flags; ++ struct page *p; ++ struct page **pages_to_free; ++ unsigned freed_pages = 0, ++ npages_to_free = nr_free; ++ ++ if (NUM_PAGES_TO_ALLOC < nr_free) ++ npages_to_free = NUM_PAGES_TO_ALLOC; ++ ++ pages_to_free = kmalloc(npages_to_free * sizeof(struct page *), ++ GFP_KERNEL); ++ if (!pages_to_free) { ++ printk(KERN_ERR "Failed to allocate memory for pool free operation.\n"); ++ return 0; ++ } ++ ++restart: ++ spin_lock_irqsave(&pool->lock, irq_flags); ++ ++ list_for_each_entry_reverse(p, &pool->list, lru) { ++ if (freed_pages >= npages_to_free) ++ break; ++ ++ pages_to_free[freed_pages++] = p; ++ /* We can only remove NUM_PAGES_TO_ALLOC at a time. */ ++ if (freed_pages >= NUM_PAGES_TO_ALLOC) { ++ /* remove range of pages from the pool */ ++ __list_del(p->lru.prev, &pool->list); ++ ++ ttm_pool_update_free_locked(pool, freed_pages); ++ /** ++ * Because changing page caching is costly ++ * we unlock the pool to prevent stalling. ++ */ ++ spin_unlock_irqrestore(&pool->lock, irq_flags); ++ ++ ttm_pages_put(pages_to_free, freed_pages); ++ if (likely(nr_free != FREE_ALL_PAGES)) ++ nr_free -= freed_pages; ++ ++ if (NUM_PAGES_TO_ALLOC >= nr_free) ++ npages_to_free = nr_free; ++ else ++ npages_to_free = NUM_PAGES_TO_ALLOC; ++ ++ freed_pages = 0; ++ ++ /* free all so restart the processing */ ++ if (nr_free) ++ goto restart; ++ ++ /* Not allowed to fall tough or break because ++ * following context is inside spinlock while we are ++ * outside here. ++ */ ++ goto out; ++ ++ } ++ } ++ ++ /* remove range of pages from the pool */ ++ if (freed_pages) { ++ __list_del(&p->lru, &pool->list); ++ ++ ttm_pool_update_free_locked(pool, freed_pages); ++ nr_free -= freed_pages; ++ } ++ ++ spin_unlock_irqrestore(&pool->lock, irq_flags); ++ ++ if (freed_pages) ++ ttm_pages_put(pages_to_free, freed_pages); ++out: ++ kfree(pages_to_free); ++ return nr_free; ++} ++ ++/* Get good estimation how many pages are free in pools */ ++static int ttm_pool_get_num_unused_pages(void) ++{ ++ unsigned i; ++ int total = 0; ++ for (i = 0; i < NUM_POOLS; ++i) ++ total += _manager.pools[i].npages; ++ ++ return total; ++} ++ ++/** ++ * Calback for mm to request pool to reduce number of page held. ++ */ ++static int ttm_pool_mm_shrink(int shrink_pages, gfp_t gfp_mask) ++{ ++ static atomic_t start_pool = ATOMIC_INIT(0); ++ unsigned i; ++ unsigned pool_offset = atomic_add_return(1, &start_pool); ++ struct ttm_page_pool *pool; ++ ++ pool_offset = pool_offset % NUM_POOLS; ++ /* select start pool in round robin fashion */ ++ for (i = 0; i < NUM_POOLS; ++i) { ++ unsigned nr_free = shrink_pages; ++ if (shrink_pages == 0) ++ break; ++ pool = &_manager.pools[(i + pool_offset)%NUM_POOLS]; ++ shrink_pages = ttm_page_pool_free(pool, nr_free); ++ } ++ /* return estimated number of unused pages in pool */ ++ return ttm_pool_get_num_unused_pages(); ++} ++ ++static void ttm_pool_mm_shrink_init(struct ttm_pool_manager *manager) ++{ ++ manager->mm_shrink.shrink = &ttm_pool_mm_shrink; ++ manager->mm_shrink.seeks = 1; ++ register_shrinker(&manager->mm_shrink); ++} ++ ++static void ttm_pool_mm_shrink_fini(struct ttm_pool_manager *manager) ++{ ++ unregister_shrinker(&manager->mm_shrink); ++} ++ ++static int ttm_set_pages_caching(struct page **pages, ++ enum ttm_caching_state cstate, unsigned cpages) ++{ ++ int r = 0; ++ /* Set page caching */ ++ switch (cstate) { ++ case tt_uncached: ++ r = set_pages_array_uc(pages, cpages); ++ if (r) ++ printk(KERN_ERR "[ttm] Failed to set %d pages to uc!\n", ++ cpages); ++ break; ++ case tt_wc: ++ r = set_pages_array_wc(pages, cpages); ++ if (r) ++ printk(KERN_ERR "[ttm] Failed to set %d pages to wc!\n", ++ cpages); ++ break; ++ default: ++ break; ++ } ++ return r; ++} ++ ++/** ++ * Free pages the pages that failed to change the caching state. If there is ++ * any pages that have changed their caching state already put them to the ++ * pool. ++ */ ++static void ttm_handle_caching_state_failure(struct list_head *pages, ++ int ttm_flags, enum ttm_caching_state cstate, ++ struct page **failed_pages, unsigned cpages) ++{ ++ unsigned i; ++ /* Failed pages has to be reed */ ++ for (i = 0; i < cpages; ++i) { ++ list_del(&failed_pages[i]->lru); ++ __free_page(failed_pages[i]); ++ } ++} ++ ++/** ++ * Allocate new pages with correct caching. ++ * ++ * This function is reentrant if caller updates count depending on number of ++ * pages returned in pages array. ++ */ ++static int ttm_alloc_new_pages(struct list_head *pages, int gfp_flags, ++ int ttm_flags, enum ttm_caching_state cstate, unsigned count) ++{ ++ struct page **caching_array; ++ struct page *p; ++ int r = 0; ++ unsigned i, cpages; ++ unsigned max_cpages = min(count, ++ (unsigned)(PAGE_SIZE/sizeof(struct page *))); ++ ++ /* allocate array for page caching change */ ++ caching_array = kmalloc(max_cpages*sizeof(struct page *), GFP_KERNEL); ++ ++ if (!caching_array) { ++ printk(KERN_ERR "[ttm] unable to allocate table for new pages."); ++ return -ENOMEM; ++ } ++ ++ for (i = 0, cpages = 0; i < count; ++i) { ++ p = alloc_page(gfp_flags); ++ ++ if (!p) { ++ printk(KERN_ERR "[ttm] unable to get page %u\n", i); ++ ++ /* store already allocated pages in the pool after ++ * setting the caching state */ ++ if (cpages) { ++ r = ttm_set_pages_caching(caching_array, cstate, cpages); ++ if (r) ++ ttm_handle_caching_state_failure(pages, ++ ttm_flags, cstate, ++ caching_array, cpages); ++ } ++ r = -ENOMEM; ++ goto out; ++ } ++ ++#ifdef CONFIG_HIGHMEM ++ /* gfp flags of highmem page should never be dma32 so we ++ * we should be fine in such case ++ */ ++ if (!PageHighMem(p)) ++#endif ++ { ++ caching_array[cpages++] = p; ++ if (cpages == max_cpages) { ++ ++ r = ttm_set_pages_caching(caching_array, ++ cstate, cpages); ++ if (r) { ++ ttm_handle_caching_state_failure(pages, ++ ttm_flags, cstate, ++ caching_array, cpages); ++ goto out; ++ } ++ cpages = 0; ++ } ++ } ++ ++ list_add(&p->lru, pages); ++ } ++ ++ if (cpages) { ++ r = ttm_set_pages_caching(caching_array, cstate, cpages); ++ if (r) ++ ttm_handle_caching_state_failure(pages, ++ ttm_flags, cstate, ++ caching_array, cpages); ++ } ++out: ++ kfree(caching_array); ++ ++ return r; ++} ++ ++/** ++ * Fill the given pool if there isn't enough pages and requested number of ++ * pages is small. ++ */ ++static void ttm_page_pool_fill_locked(struct ttm_page_pool *pool, ++ int ttm_flags, enum ttm_caching_state cstate, unsigned count, ++ unsigned long *irq_flags) ++{ ++ struct page *p; ++ int r; ++ unsigned cpages = 0; ++ /** ++ * Only allow one pool fill operation at a time. ++ * If pool doesn't have enough pages for the allocation new pages are ++ * allocated from outside of pool. ++ */ ++ if (pool->fill_lock) ++ return; ++ ++ pool->fill_lock = true; ++ ++ /* If allocation request is small and there is not enough ++ * pages in pool we fill the pool first */ ++ if (count < _manager.options.small ++ && count > pool->npages) { ++ struct list_head new_pages; ++ unsigned alloc_size = _manager.options.alloc_size; ++ ++ /** ++ * Can't change page caching if in irqsave context. We have to ++ * drop the pool->lock. ++ */ ++ spin_unlock_irqrestore(&pool->lock, *irq_flags); ++ ++ INIT_LIST_HEAD(&new_pages); ++ r = ttm_alloc_new_pages(&new_pages, pool->gfp_flags, ttm_flags, ++ cstate, alloc_size); ++ spin_lock_irqsave(&pool->lock, *irq_flags); ++ ++ if (!r) { ++ list_splice(&new_pages, &pool->list); ++ ++pool->nrefills; ++ pool->npages += alloc_size; ++ } else { ++ printk(KERN_ERR "[ttm] Failed to fill pool (%p).", pool); ++ /* If we have any pages left put them to the pool. */ ++ list_for_each_entry(p, &pool->list, lru) { ++ ++cpages; ++ } ++ list_splice(&new_pages, &pool->list); ++ pool->npages += cpages; ++ } ++ ++ } ++ pool->fill_lock = false; ++} ++ ++/** ++ * Cut count nubmer of pages from the pool and put them to return list ++ * ++ * @return count of pages still to allocate to fill the request. ++ */ ++static unsigned ttm_page_pool_get_pages(struct ttm_page_pool *pool, ++ struct list_head *pages, int ttm_flags, ++ enum ttm_caching_state cstate, unsigned count) ++{ ++ unsigned long irq_flags; ++ struct list_head *p; ++ unsigned i; ++ ++ spin_lock_irqsave(&pool->lock, irq_flags); ++ ttm_page_pool_fill_locked(pool, ttm_flags, cstate, count, &irq_flags); ++ ++ if (count >= pool->npages) { ++ /* take all pages from the pool */ ++ list_splice_init(&pool->list, pages); ++ count -= pool->npages; ++ pool->npages = 0; ++ goto out; ++ } ++ /* find the last pages to include for requested number of pages. Split ++ * pool to begin and halves to reduce search space. */ ++ if (count <= pool->npages/2) { ++ i = 0; ++ list_for_each(p, &pool->list) { ++ if (++i == count) ++ break; ++ } ++ } else { ++ i = pool->npages + 1; ++ list_for_each_prev(p, &pool->list) { ++ if (--i == count) ++ break; ++ } ++ } ++ /* Cut count number of pages from pool */ ++ list_cut_position(pages, &pool->list, p); ++ pool->npages -= count; ++ count = 0; ++out: ++ spin_unlock_irqrestore(&pool->lock, irq_flags); ++ return count; ++} ++ ++/* ++ * On success pages list will hold count number of correctly ++ * cached pages. ++ */ ++int ttm_get_pages(struct list_head *pages, int flags, ++ enum ttm_caching_state cstate, unsigned count) ++{ ++ struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); ++ struct page *p = NULL; ++ int gfp_flags = 0; ++ int r; ++ ++ /* set zero flag for page allocation if required */ ++ if (flags & TTM_PAGE_FLAG_ZERO_ALLOC) ++ gfp_flags |= __GFP_ZERO; ++ ++ /* No pool for cached pages */ ++ if (pool == NULL) { ++ if (flags & TTM_PAGE_FLAG_DMA32) ++ gfp_flags |= GFP_DMA32; ++ else ++ gfp_flags |= __GFP_HIGHMEM; ++ ++ for (r = 0; r < count; ++r) { ++ p = alloc_page(gfp_flags); ++ if (!p) { ++ ++ printk(KERN_ERR "[ttm] unable to allocate page."); ++ return -ENOMEM; ++ } ++ ++ list_add(&p->lru, pages); ++ } ++ return 0; ++ } ++ ++ ++ /* combine zero flag to pool flags */ ++ gfp_flags |= pool->gfp_flags; ++ ++ /* First we take pages from the pool */ ++ count = ttm_page_pool_get_pages(pool, pages, flags, cstate, count); ++ ++ /* clear the pages coming from the pool if requested */ ++ if (flags & TTM_PAGE_FLAG_ZERO_ALLOC) { ++ list_for_each_entry(p, pages, lru) { ++ clear_page(page_address(p)); ++ } ++ } ++ ++ /* If pool didn't have enough pages allocate new one. */ ++ if (count > 0) { ++ /* ttm_alloc_new_pages doesn't reference pool so we can run ++ * multiple requests in parallel. ++ **/ ++ r = ttm_alloc_new_pages(pages, gfp_flags, flags, cstate, count); ++ if (r) { ++ /* If there is any pages in the list put them back to ++ * the pool. */ ++ printk(KERN_ERR "[ttm] Failed to allocate extra pages " ++ "for large request."); ++ ttm_put_pages(pages, 0, flags, cstate); ++ return r; ++ } ++ } ++ ++ ++ return 0; ++} ++ ++/* Put all pages in pages list to correct pool to wait for reuse */ ++void ttm_put_pages(struct list_head *pages, unsigned page_count, int flags, ++ enum ttm_caching_state cstate) ++{ ++ unsigned long irq_flags; ++ struct ttm_page_pool *pool = ttm_get_pool(flags, cstate); ++ struct page *p, *tmp; ++ ++ if (pool == NULL) { ++ /* No pool for this memory type so free the pages */ ++ ++ list_for_each_entry_safe(p, tmp, pages, lru) { ++ __free_page(p); ++ } ++ /* Make the pages list empty */ ++ INIT_LIST_HEAD(pages); ++ return; ++ } ++ if (page_count == 0) { ++ list_for_each_entry_safe(p, tmp, pages, lru) { ++ ++page_count; ++ } ++ } ++ ++ spin_lock_irqsave(&pool->lock, irq_flags); ++ list_splice_init(pages, &pool->list); ++ pool->npages += page_count; ++ /* Check that we don't go over the pool limit */ ++ page_count = 0; ++ if (pool->npages > _manager.options.max_size) { ++ page_count = pool->npages - _manager.options.max_size; ++ /* free at least NUM_PAGES_TO_ALLOC number of pages ++ * to reduce calls to set_memory_wb */ ++ if (page_count < NUM_PAGES_TO_ALLOC) ++ page_count = NUM_PAGES_TO_ALLOC; ++ } ++ spin_unlock_irqrestore(&pool->lock, irq_flags); ++ if (page_count) ++ ttm_page_pool_free(pool, page_count); ++} ++ ++static void ttm_page_pool_init_locked(struct ttm_page_pool *pool, int flags, ++ char *name) ++{ ++ spin_lock_init(&pool->lock); ++ pool->fill_lock = false; ++ INIT_LIST_HEAD(&pool->list); ++ pool->npages = pool->nfrees = 0; ++ pool->gfp_flags = flags; ++ pool->name = name; ++} ++ ++int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages) ++{ ++ int ret; ++ if (atomic_add_return(1, &_manager.page_alloc_inited) > 1) ++ return 0; ++ ++ printk(KERN_INFO "[ttm] Initializing pool allocator.\n"); ++ ++ ttm_page_pool_init_locked(&_manager.wc_pool, GFP_HIGHUSER, "wc"); ++ ++ ttm_page_pool_init_locked(&_manager.uc_pool, GFP_HIGHUSER, "uc"); ++ ++ ttm_page_pool_init_locked(&_manager.wc_pool_dma32, GFP_USER | GFP_DMA32, ++ "wc dma"); ++ ++ ttm_page_pool_init_locked(&_manager.uc_pool_dma32, GFP_USER | GFP_DMA32, ++ "uc dma"); ++ ++ _manager.options.max_size = max_pages; ++ _manager.options.small = SMALL_ALLOCATION; ++ _manager.options.alloc_size = NUM_PAGES_TO_ALLOC; ++ ++ kobject_init(&_manager.kobj, &ttm_pool_kobj_type); ++ ret = kobject_add(&_manager.kobj, &glob->kobj, "pool"); ++ if (unlikely(ret != 0)) { ++ kobject_put(&_manager.kobj); ++ return ret; ++ } ++ ++ ttm_pool_mm_shrink_init(&_manager); ++ ++ return 0; ++} ++ ++void ttm_page_alloc_fini() ++{ ++ int i; ++ ++ if (atomic_sub_return(1, &_manager.page_alloc_inited) > 0) ++ return; ++ ++ printk(KERN_INFO "[ttm] Finilizing pool allocator.\n"); ++ ttm_pool_mm_shrink_fini(&_manager); ++ ++ for (i = 0; i < NUM_POOLS; ++i) ++ ttm_page_pool_free(&_manager.pools[i], FREE_ALL_PAGES); ++ ++ kobject_put(&_manager.kobj); ++} ++ ++int ttm_page_alloc_debugfs(struct seq_file *m, void *data) ++{ ++ struct ttm_page_pool *p; ++ unsigned i; ++ char *h[] = {"pool", "refills", "pages freed", "size"}; ++ if (atomic_read(&_manager.page_alloc_inited) == 0) { ++ seq_printf(m, "No pool allocator running.\n"); ++ return 0; ++ } ++ seq_printf(m, "%6s %12s %13s %8s\n", ++ h[0], h[1], h[2], h[3]); ++ for (i = 0; i < NUM_POOLS; ++i) { ++ p = &_manager.pools[i]; ++ ++ seq_printf(m, "%6s %12ld %13ld %8d\n", ++ p->name, p->nrefills, ++ p->nfrees, p->npages); ++ } ++ return 0; ++} ++EXPORT_SYMBOL(ttm_page_alloc_debugfs); +diff --git a/drivers/gpu/drm/ttm/ttm_tt.c b/drivers/gpu/drm/ttm/ttm_tt.c +index a759170..a3269ef 100644 +--- a/drivers/gpu/drm/ttm/ttm_tt.c ++++ b/drivers/gpu/drm/ttm/ttm_tt.c +@@ -28,65 +28,34 @@ + * Authors: Thomas Hellstrom + */ + +-#include + #include + #include + #include + #include + #include + #include "drm_cache.h" ++#include "drm_mem_util.h" + #include "ttm/ttm_module.h" + #include "ttm/ttm_bo_driver.h" + #include "ttm/ttm_placement.h" ++#include "ttm/ttm_page_alloc.h" + + static int ttm_tt_swapin(struct ttm_tt *ttm); + + /** + * Allocates storage for pointers to the pages that back the ttm. +- * +- * Uses kmalloc if possible. Otherwise falls back to vmalloc. + */ + static void ttm_tt_alloc_page_directory(struct ttm_tt *ttm) + { +- unsigned long size = ttm->num_pages * sizeof(*ttm->pages); +- ttm->pages = NULL; +- +- if (size <= PAGE_SIZE) +- ttm->pages = kzalloc(size, GFP_KERNEL); +- +- if (!ttm->pages) { +- ttm->pages = vmalloc_user(size); +- if (ttm->pages) +- ttm->page_flags |= TTM_PAGE_FLAG_VMALLOC; +- } ++ ttm->pages = drm_calloc_large(ttm->num_pages, sizeof(*ttm->pages)); + } + + static void ttm_tt_free_page_directory(struct ttm_tt *ttm) + { +- if (ttm->page_flags & TTM_PAGE_FLAG_VMALLOC) { +- vfree(ttm->pages); +- ttm->page_flags &= ~TTM_PAGE_FLAG_VMALLOC; +- } else { +- kfree(ttm->pages); +- } ++ drm_free_large(ttm->pages); + ttm->pages = NULL; + } + +-static struct page *ttm_tt_alloc_page(unsigned page_flags) +-{ +- gfp_t gfp_flags = GFP_USER; +- +- if (page_flags & TTM_PAGE_FLAG_ZERO_ALLOC) +- gfp_flags |= __GFP_ZERO; +- +- if (page_flags & TTM_PAGE_FLAG_DMA32) +- gfp_flags |= __GFP_DMA32; +- else +- gfp_flags |= __GFP_HIGHMEM; +- +- return alloc_page(gfp_flags); +-} +- + static void ttm_tt_free_user_pages(struct ttm_tt *ttm) + { + int write; +@@ -127,15 +96,21 @@ static void ttm_tt_free_user_pages(struct ttm_tt *ttm) + static struct page *__ttm_tt_get_page(struct ttm_tt *ttm, int index) + { + struct page *p; ++ struct list_head h; + struct ttm_mem_global *mem_glob = ttm->glob->mem_glob; + int ret; + + while (NULL == (p = ttm->pages[index])) { +- p = ttm_tt_alloc_page(ttm->page_flags); + +- if (!p) ++ INIT_LIST_HEAD(&h); ++ ++ ret = ttm_get_pages(&h, ttm->page_flags, ttm->caching_state, 1); ++ ++ if (ret != 0) + return NULL; + ++ p = list_first_entry(&h, struct page, lru); ++ + ret = ttm_mem_global_alloc_page(mem_glob, p, false, false); + if (unlikely(ret != 0)) + goto out_err; +@@ -244,10 +219,10 @@ static int ttm_tt_set_caching(struct ttm_tt *ttm, + if (ttm->caching_state == c_state) + return 0; + +- if (c_state != tt_cached) { +- ret = ttm_tt_populate(ttm); +- if (unlikely(ret != 0)) +- return ret; ++ if (ttm->state == tt_unpopulated) { ++ /* Change caching but don't populate */ ++ ttm->caching_state = c_state; ++ return 0; + } + + if (ttm->caching_state == tt_cached) +@@ -298,13 +273,17 @@ EXPORT_SYMBOL(ttm_tt_set_placement_caching); + static void ttm_tt_free_alloced_pages(struct ttm_tt *ttm) + { + int i; ++ unsigned count = 0; ++ struct list_head h; + struct page *cur_page; + struct ttm_backend *be = ttm->be; + ++ INIT_LIST_HEAD(&h); ++ + if (be) + be->func->clear(be); +- (void)ttm_tt_set_caching(ttm, tt_cached); + for (i = 0; i < ttm->num_pages; ++i) { ++ + cur_page = ttm->pages[i]; + ttm->pages[i] = NULL; + if (cur_page) { +@@ -314,9 +293,11 @@ static void ttm_tt_free_alloced_pages(struct ttm_tt *ttm) + "Leaking pages.\n"); + ttm_mem_global_free_page(ttm->glob->mem_glob, + cur_page); +- __free_page(cur_page); ++ list_add(&cur_page->lru, &h); ++ count++; + } + } ++ ttm_put_pages(&h, count, ttm->page_flags, ttm->caching_state); + ttm->state = tt_unpopulated; + ttm->first_himem_page = ttm->num_pages; + ttm->last_lomem_page = -1; +diff --git a/include/drm/drmP.h b/include/drm/drmP.h +index ffac157..de2f82e 100644 +--- a/include/drm/drmP.h ++++ b/include/drm/drmP.h +@@ -801,6 +801,7 @@ struct drm_driver { + */ + int (*gem_init_object) (struct drm_gem_object *obj); + void (*gem_free_object) (struct drm_gem_object *obj); ++ void (*gem_free_object_unlocked) (struct drm_gem_object *obj); + + /* vga arb irq handler */ + void (*vgaarb_irq)(struct drm_device *dev, bool state); +@@ -1427,6 +1428,7 @@ extern void drm_sysfs_connector_remove(struct drm_connector *connector); + int drm_gem_init(struct drm_device *dev); + void drm_gem_destroy(struct drm_device *dev); + void drm_gem_object_free(struct kref *kref); ++void drm_gem_object_free_unlocked(struct kref *kref); + struct drm_gem_object *drm_gem_object_alloc(struct drm_device *dev, + size_t size); + void drm_gem_object_handle_free(struct kref *kref); +@@ -1443,10 +1445,15 @@ drm_gem_object_reference(struct drm_gem_object *obj) + static inline void + drm_gem_object_unreference(struct drm_gem_object *obj) + { +- if (obj == NULL) +- return; ++ if (obj != NULL) ++ kref_put(&obj->refcount, drm_gem_object_free); ++} + +- kref_put(&obj->refcount, drm_gem_object_free); ++static inline void ++drm_gem_object_unreference_unlocked(struct drm_gem_object *obj) ++{ ++ if (obj != NULL) ++ kref_put(&obj->refcount, drm_gem_object_free_unlocked); + } + + int drm_gem_handle_create(struct drm_file *file_priv, +@@ -1475,6 +1482,21 @@ drm_gem_object_handle_unreference(struct drm_gem_object *obj) + drm_gem_object_unreference(obj); + } + ++static inline void ++drm_gem_object_handle_unreference_unlocked(struct drm_gem_object *obj) ++{ ++ if (obj == NULL) ++ return; ++ ++ /* ++ * Must bump handle count first as this may be the last ++ * ref, in which case the object would disappear before we ++ * checked for a name ++ */ ++ kref_put(&obj->handlecount, drm_gem_object_handle_free); ++ drm_gem_object_unreference_unlocked(obj); ++} ++ + struct drm_gem_object *drm_gem_object_lookup(struct drm_device *dev, + struct drm_file *filp, + u32 handle); +@@ -1523,39 +1545,7 @@ static __inline__ void drm_core_dropmap(struct drm_local_map *map) + { + } + +- +-static __inline__ void *drm_calloc_large(size_t nmemb, size_t size) +-{ +- if (size != 0 && nmemb > ULONG_MAX / size) +- return NULL; +- +- if (size * nmemb <= PAGE_SIZE) +- return kcalloc(nmemb, size, GFP_KERNEL); +- +- return __vmalloc(size * nmemb, +- GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); +-} +- +-/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */ +-static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size) +-{ +- if (size != 0 && nmemb > ULONG_MAX / size) +- return NULL; +- +- if (size * nmemb <= PAGE_SIZE) +- return kmalloc(nmemb * size, GFP_KERNEL); +- +- return __vmalloc(size * nmemb, +- GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL); +-} +- +-static __inline void drm_free_large(void *ptr) +-{ +- if (!is_vmalloc_addr(ptr)) +- return kfree(ptr); +- +- vfree(ptr); +-} ++#include "drm_mem_util.h" + /*@}*/ + + #endif /* __KERNEL__ */ +diff --git a/include/drm/drm_crtc.h b/include/drm/drm_crtc.h +index fdf43ab..f3cc7a6 100644 +--- a/include/drm/drm_crtc.h ++++ b/include/drm/drm_crtc.h +@@ -666,8 +666,6 @@ extern void drm_fb_release(struct drm_file *file_priv); + extern int drm_mode_group_init_legacy_group(struct drm_device *dev, struct drm_mode_group *group); + extern struct edid *drm_get_edid(struct drm_connector *connector, + struct i2c_adapter *adapter); +-extern int drm_do_probe_ddc_edid(struct i2c_adapter *adapter, +- unsigned char *buf, int len); + extern int drm_add_edid_modes(struct drm_connector *connector, struct edid *edid); + extern void drm_mode_probed_add(struct drm_connector *connector, struct drm_display_mode *mode); + extern void drm_mode_remove(struct drm_connector *connector, struct drm_display_mode *mode); +@@ -799,6 +797,10 @@ extern struct drm_display_mode *drm_cvt_mode(struct drm_device *dev, + extern struct drm_display_mode *drm_gtf_mode(struct drm_device *dev, + int hdisplay, int vdisplay, int vrefresh, + bool interlaced, int margins); ++extern struct drm_display_mode *drm_gtf_mode_complex(struct drm_device *dev, ++ int hdisplay, int vdisplay, int vrefresh, ++ bool interlaced, int margins, int GTF_M, ++ int GTF_2C, int GTF_K, int GTF_2J); + extern int drm_add_modes_noedid(struct drm_connector *connector, + int hdisplay, int vdisplay); + #endif /* __DRM_CRTC_H__ */ +diff --git a/include/drm/drm_mem_util.h b/include/drm/drm_mem_util.h +new file mode 100644 +index 0000000..6bd325f +--- /dev/null ++++ b/include/drm/drm_mem_util.h +@@ -0,0 +1,65 @@ ++/* ++ * Copyright © 2008 Intel Corporation ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice (including the next ++ * paragraph) shall be included in all copies or substantial portions of the ++ * Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS ++ * IN THE SOFTWARE. ++ * ++ * Authors: ++ * Jesse Barnes ++ * ++ */ ++#ifndef _DRM_MEM_UTIL_H_ ++#define _DRM_MEM_UTIL_H_ ++ ++#include ++ ++static __inline__ void *drm_calloc_large(size_t nmemb, size_t size) ++{ ++ if (size != 0 && nmemb > ULONG_MAX / size) ++ return NULL; ++ ++ if (size * nmemb <= PAGE_SIZE) ++ return kcalloc(nmemb, size, GFP_KERNEL); ++ ++ return __vmalloc(size * nmemb, ++ GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL); ++} ++ ++/* Modeled after cairo's malloc_ab, it's like calloc but without the zeroing. */ ++static __inline__ void *drm_malloc_ab(size_t nmemb, size_t size) ++{ ++ if (size != 0 && nmemb > ULONG_MAX / size) ++ return NULL; ++ ++ if (size * nmemb <= PAGE_SIZE) ++ return kmalloc(nmemb * size, GFP_KERNEL); ++ ++ return __vmalloc(size * nmemb, ++ GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL); ++} ++ ++static __inline void drm_free_large(void *ptr) ++{ ++ if (!is_vmalloc_addr(ptr)) ++ return kfree(ptr); ++ ++ vfree(ptr); ++} ++ ++#endif +diff --git a/include/drm/ttm/ttm_bo_driver.h b/include/drm/ttm/ttm_bo_driver.h +index 4c4e0f8..fd2c122 100644 +--- a/include/drm/ttm/ttm_bo_driver.h ++++ b/include/drm/ttm/ttm_bo_driver.h +@@ -115,7 +115,6 @@ struct ttm_backend { + struct ttm_backend_func *func; + }; + +-#define TTM_PAGE_FLAG_VMALLOC (1 << 0) + #define TTM_PAGE_FLAG_USER (1 << 1) + #define TTM_PAGE_FLAG_USER_DIRTY (1 << 2) + #define TTM_PAGE_FLAG_WRITE (1 << 3) +diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h +new file mode 100644 +index 0000000..8bb4de5 +--- /dev/null ++++ b/include/drm/ttm/ttm_page_alloc.h +@@ -0,0 +1,74 @@ ++/* ++ * Copyright (c) Red Hat Inc. ++ ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sub license, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice (including the ++ * next paragraph) shall be included in all copies or substantial portions ++ * of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. IN NO EVENT SHALL ++ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER ++ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING ++ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER ++ * DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Dave Airlie ++ * Jerome Glisse ++ */ ++#ifndef TTM_PAGE_ALLOC ++#define TTM_PAGE_ALLOC ++ ++#include "ttm_bo_driver.h" ++#include "ttm_memory.h" ++ ++/** ++ * Get count number of pages from pool to pages list. ++ * ++ * @pages: heado of empty linked list where pages are filled. ++ * @flags: ttm flags for page allocation. ++ * @cstate: ttm caching state for the page. ++ * @count: number of pages to allocate. ++ */ ++int ttm_get_pages(struct list_head *pages, ++ int flags, ++ enum ttm_caching_state cstate, ++ unsigned count); ++/** ++ * Put linked list of pages to pool. ++ * ++ * @pages: list of pages to free. ++ * @page_count: number of pages in the list. Zero can be passed for unknown ++ * count. ++ * @flags: ttm flags for page allocation. ++ * @cstate: ttm caching state. ++ */ ++void ttm_put_pages(struct list_head *pages, ++ unsigned page_count, ++ int flags, ++ enum ttm_caching_state cstate); ++/** ++ * Initialize pool allocator. ++ * ++ * Pool allocator is internaly reference counted so it can be initialized ++ * multiple times but ttm_page_alloc_fini has to be called same number of ++ * times. ++ */ ++int ttm_page_alloc_init(struct ttm_mem_global *glob, unsigned max_pages); ++/** ++ * Free pool allocator. ++ */ ++void ttm_page_alloc_fini(void); ++ ++/** ++ * Output the state of pools to debugfs file ++ */ ++extern int ttm_page_alloc_debugfs(struct seq_file *m, void *data); ++#endif diff --git a/drm-i915-fix-edp-panels.patch b/drm-i915-fix-edp-panels.patch new file mode 100644 index 000000000..d576e31cc --- /dev/null +++ b/drm-i915-fix-edp-panels.patch @@ -0,0 +1,34 @@ +diff -up linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_dp.c.dave linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_dp.c +--- linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_dp.c.dave 2010-06-28 09:50:36.000000000 +1000 ++++ linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_dp.c 2010-06-28 09:53:24.000000000 +1000 +@@ -135,6 +135,12 @@ intel_dp_link_required(struct drm_device + } + + static int ++intel_dp_max_data_rate(int max_link_clock, int max_lanes) ++{ ++ return (max_link_clock * max_lanes * 8) / 10; ++} ++ ++static int + intel_dp_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { +@@ -144,7 +150,7 @@ intel_dp_mode_valid(struct drm_connector + int max_lanes = intel_dp_max_lane_count(intel_encoder); + + if (intel_dp_link_required(connector->dev, intel_encoder, mode->clock) +- > max_link_clock * max_lanes) ++ > intel_dp_max_data_rate(max_link_clock, max_lanes)) + return MODE_CLOCK_HIGH; + + if (mode->clock < 10000) +@@ -505,7 +511,7 @@ intel_dp_mode_fixup(struct drm_encoder * + + for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { + for (clock = 0; clock <= max_clock; clock++) { +- int link_avail = intel_dp_link_clock(bws[clock]) * lane_count; ++ int link_avail = intel_dp_max_data_rate(intel_dp_link_clock(bws[clock]), lane_count); + + if (intel_dp_link_required(encoder->dev, intel_encoder, mode->clock) + <= link_avail) { diff --git a/drm-i915-fix-non-ironlake-965-class-crashes.patch b/drm-i915-fix-non-ironlake-965-class-crashes.patch new file mode 100644 index 000000000..74b65ee0e --- /dev/null +++ b/drm-i915-fix-non-ironlake-965-class-crashes.patch @@ -0,0 +1,43 @@ +From 1918ad77f7f908ed67cf37c505c6ad4ac52f1ecf Mon Sep 17 00:00:00 2001 +From: Jesse Barnes +Date: Fri, 23 Apr 2010 09:32:23 -0700 +Subject: drm/i915: fix non-Ironlake 965 class crashes +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Jesse Barnes + +commit 1918ad77f7f908ed67cf37c505c6ad4ac52f1ecf upstream. + +My PIPE_CONTROL fix (just sent via Eric's tree) was buggy; I was +testing a whole set of patches together and missed a conversion to the +new HAS_PIPE_CONTROL macro, which will cause breakage on non-Ironlake +965 class chips. Fortunately, the fix is trivial and has been tested. + +Be sure to use the HAS_PIPE_CONTROL macro in i915_get_gem_seqno, or +we'll end up reading the wrong graphics memory, likely causing hangs, +crashes, or worse. + +Reported-by: Zdenek Kabelac +Reported-by: Toralf Förster +Tested-by: Toralf Förster +Signed-off-by: Jesse Barnes +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_gem.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -1785,7 +1785,7 @@ i915_get_gem_seqno(struct drm_device *de + { + drm_i915_private_t *dev_priv = dev->dev_private; + +- if (IS_I965G(dev)) ++ if (HAS_PIPE_CONTROL(dev)) + return ((volatile u32 *)(dev_priv->seqno_page))[0]; + else + return READ_HWSP(dev_priv, I915_GEM_HWS_INDEX); diff --git a/drm-i915-use-pipe_control-instruction-on-ironlake-and-sandy-bridge.patch b/drm-i915-use-pipe_control-instruction-on-ironlake-and-sandy-bridge.patch new file mode 100644 index 000000000..20b98e55e --- /dev/null +++ b/drm-i915-use-pipe_control-instruction-on-ironlake-and-sandy-bridge.patch @@ -0,0 +1,333 @@ +From e552eb7038a36d9b18860f525aa02875e313fe16 Mon Sep 17 00:00:00 2001 +From: Jesse Barnes +Date: Wed, 21 Apr 2010 11:39:23 -0700 +Subject: drm/i915: use PIPE_CONTROL instruction on Ironlake and Sandy Bridge + +From: Jesse Barnes + +commit e552eb7038a36d9b18860f525aa02875e313fe16 upstream. + +Since 965, the hardware has supported the PIPE_CONTROL command, which +provides fine grained GPU cache flushing control. On recent chipsets, +this instruction is required for reliable interrupt and sequence number +reporting in the driver. + +So add support for this instruction, including workarounds, on Ironlake +and Sandy Bridge hardware. + +https://bugs.freedesktop.org/show_bug.cgi?id=27108 + +Signed-off-by: Jesse Barnes +Tested-by: Chris Wilson +Signed-off-by: Eric Anholt +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_drv.h | 4 + + drivers/gpu/drm/i915/i915_gem.c | 145 ++++++++++++++++++++++++++++++++++++---- + drivers/gpu/drm/i915/i915_irq.c | 8 +- + drivers/gpu/drm/i915/i915_reg.h | 11 +++ + 4 files changed, 152 insertions(+), 16 deletions(-) + +--- a/drivers/gpu/drm/i915/i915_drv.h ++++ b/drivers/gpu/drm/i915/i915_drv.h +@@ -206,11 +206,14 @@ typedef struct drm_i915_private { + + drm_dma_handle_t *status_page_dmah; + void *hw_status_page; ++ void *seqno_page; + dma_addr_t dma_status_page; + uint32_t counter; + unsigned int status_gfx_addr; ++ unsigned int seqno_gfx_addr; + drm_local_map_t hws_map; + struct drm_gem_object *hws_obj; ++ struct drm_gem_object *seqno_obj; + struct drm_gem_object *pwrctx; + + struct resource mch_res; +@@ -1090,6 +1093,7 @@ extern int i915_wait_ring(struct drm_dev + + #define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type) + #define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT) ++#define HAS_PIPE_CONTROL(dev) (IS_IRONLAKE(dev) || IS_GEN6(dev)) + + #define PRIMARY_RINGBUFFER_SIZE (128*1024) + +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -1559,6 +1559,13 @@ i915_gem_object_move_to_inactive(struct + i915_verify_inactive(dev, __FILE__, __LINE__); + } + ++#define PIPE_CONTROL_FLUSH(addr) \ ++ OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | \ ++ PIPE_CONTROL_DEPTH_STALL); \ ++ OUT_RING(addr | PIPE_CONTROL_GLOBAL_GTT); \ ++ OUT_RING(0); \ ++ OUT_RING(0); \ ++ + /** + * Creates a new sequence number, emitting a write of it to the status page + * plus an interrupt, which will trigger i915_user_interrupt_handler. +@@ -1593,13 +1600,47 @@ i915_add_request(struct drm_device *dev, + if (dev_priv->mm.next_gem_seqno == 0) + dev_priv->mm.next_gem_seqno++; + +- BEGIN_LP_RING(4); +- OUT_RING(MI_STORE_DWORD_INDEX); +- OUT_RING(I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); +- OUT_RING(seqno); ++ if (HAS_PIPE_CONTROL(dev)) { ++ u32 scratch_addr = dev_priv->seqno_gfx_addr + 128; + +- OUT_RING(MI_USER_INTERRUPT); +- ADVANCE_LP_RING(); ++ /* ++ * Workaround qword write incoherence by flushing the ++ * PIPE_NOTIFY buffers out to memory before requesting ++ * an interrupt. ++ */ ++ BEGIN_LP_RING(32); ++ OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | ++ PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH); ++ OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT); ++ OUT_RING(seqno); ++ OUT_RING(0); ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; /* write to separate cachelines */ ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | ++ PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH | ++ PIPE_CONTROL_NOTIFY); ++ OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT); ++ OUT_RING(seqno); ++ OUT_RING(0); ++ ADVANCE_LP_RING(); ++ } else { ++ BEGIN_LP_RING(4); ++ OUT_RING(MI_STORE_DWORD_INDEX); ++ OUT_RING(I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); ++ OUT_RING(seqno); ++ ++ OUT_RING(MI_USER_INTERRUPT); ++ ADVANCE_LP_RING(); ++ } + + DRM_DEBUG_DRIVER("%d\n", seqno); + +@@ -1744,7 +1785,10 @@ i915_get_gem_seqno(struct drm_device *de + { + drm_i915_private_t *dev_priv = dev->dev_private; + +- return READ_HWSP(dev_priv, I915_GEM_HWS_INDEX); ++ if (IS_I965G(dev)) ++ return ((volatile u32 *)(dev_priv->seqno_page))[0]; ++ else ++ return READ_HWSP(dev_priv, I915_GEM_HWS_INDEX); + } + + /** +@@ -4576,6 +4620,49 @@ i915_gem_idle(struct drm_device *dev) + return 0; + } + ++/* ++ * 965+ support PIPE_CONTROL commands, which provide finer grained control ++ * over cache flushing. ++ */ ++static int ++i915_gem_init_pipe_control(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_gem_object *obj; ++ struct drm_i915_gem_object *obj_priv; ++ int ret; ++ ++ obj = drm_gem_object_alloc(dev, 4096); ++ if (obj == NULL) { ++ DRM_ERROR("Failed to allocate seqno page\n"); ++ ret = -ENOMEM; ++ goto err; ++ } ++ obj_priv = obj->driver_private; ++ obj_priv->agp_type = AGP_USER_CACHED_MEMORY; ++ ++ ret = i915_gem_object_pin(obj, 4096); ++ if (ret) ++ goto err_unref; ++ ++ dev_priv->seqno_gfx_addr = obj_priv->gtt_offset; ++ dev_priv->seqno_page = kmap(obj_priv->pages[0]); ++ if (dev_priv->seqno_page == NULL) ++ goto err_unpin; ++ ++ dev_priv->seqno_obj = obj; ++ memset(dev_priv->seqno_page, 0, PAGE_SIZE); ++ ++ return 0; ++ ++err_unpin: ++ i915_gem_object_unpin(obj); ++err_unref: ++ drm_gem_object_unreference(obj); ++err: ++ return ret; ++} ++ + static int + i915_gem_init_hws(struct drm_device *dev) + { +@@ -4593,7 +4680,8 @@ i915_gem_init_hws(struct drm_device *dev + obj = drm_gem_object_alloc(dev, 4096); + if (obj == NULL) { + DRM_ERROR("Failed to allocate status page\n"); +- return -ENOMEM; ++ ret = -ENOMEM; ++ goto err; + } + obj_priv = to_intel_bo(obj); + obj_priv->agp_type = AGP_USER_CACHED_MEMORY; +@@ -4601,7 +4689,7 @@ i915_gem_init_hws(struct drm_device *dev + ret = i915_gem_object_pin(obj, 4096); + if (ret != 0) { + drm_gem_object_unreference(obj); +- return ret; ++ goto err_unref; + } + + dev_priv->status_gfx_addr = obj_priv->gtt_offset; +@@ -4610,10 +4698,16 @@ i915_gem_init_hws(struct drm_device *dev + if (dev_priv->hw_status_page == NULL) { + DRM_ERROR("Failed to map status page.\n"); + memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); +- i915_gem_object_unpin(obj); +- drm_gem_object_unreference(obj); +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_unpin; + } ++ ++ if (HAS_PIPE_CONTROL(dev)) { ++ ret = i915_gem_init_pipe_control(dev); ++ if (ret) ++ goto err_unpin; ++ } ++ + dev_priv->hws_obj = obj; + memset(dev_priv->hw_status_page, 0, PAGE_SIZE); + I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); +@@ -4621,6 +4715,30 @@ i915_gem_init_hws(struct drm_device *dev + DRM_DEBUG_DRIVER("hws offset: 0x%08x\n", dev_priv->status_gfx_addr); + + return 0; ++ ++err_unpin: ++ i915_gem_object_unpin(obj); ++err_unref: ++ drm_gem_object_unreference(obj); ++err: ++ return 0; ++} ++ ++static void ++i915_gem_cleanup_pipe_control(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_gem_object *obj; ++ struct drm_i915_gem_object *obj_priv; ++ ++ obj = dev_priv->seqno_obj; ++ obj_priv = obj->driver_private; ++ kunmap(obj_priv->pages[0]); ++ i915_gem_object_unpin(obj); ++ drm_gem_object_unreference(obj); ++ dev_priv->seqno_obj = NULL; ++ ++ dev_priv->seqno_page = NULL; + } + + static void +@@ -4644,6 +4762,9 @@ i915_gem_cleanup_hws(struct drm_device * + memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); + dev_priv->hw_status_page = NULL; + ++ if (HAS_PIPE_CONTROL(dev)) ++ i915_gem_cleanup_pipe_control(dev); ++ + /* Write high address into HWS_PGA when disabling. */ + I915_WRITE(HWS_PGA, 0x1ffff000); + } +--- a/drivers/gpu/drm/i915/i915_irq.c ++++ b/drivers/gpu/drm/i915/i915_irq.c +@@ -297,7 +297,7 @@ irqreturn_t ironlake_irq_handler(struct + READ_BREADCRUMB(dev_priv); + } + +- if (gt_iir & GT_USER_INTERRUPT) { ++ if (gt_iir & GT_PIPE_NOTIFY) { + u32 seqno = i915_get_gem_seqno(dev); + dev_priv->mm.irq_gem_seqno = seqno; + trace_i915_gem_request_complete(dev, seqno); +@@ -738,7 +738,7 @@ void i915_user_irq_get(struct drm_device + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); + if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { + if (HAS_PCH_SPLIT(dev)) +- ironlake_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); ++ ironlake_enable_graphics_irq(dev_priv, GT_PIPE_NOTIFY); + else + i915_enable_irq(dev_priv, I915_USER_INTERRUPT); + } +@@ -754,7 +754,7 @@ void i915_user_irq_put(struct drm_device + BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); + if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { + if (HAS_PCH_SPLIT(dev)) +- ironlake_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); ++ ironlake_disable_graphics_irq(dev_priv, GT_PIPE_NOTIFY); + else + i915_disable_irq(dev_priv, I915_USER_INTERRUPT); + } +@@ -1034,7 +1034,7 @@ static int ironlake_irq_postinstall(stru + /* enable kind of interrupts always enabled */ + u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | + DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE; +- u32 render_mask = GT_USER_INTERRUPT; ++ u32 render_mask = GT_PIPE_NOTIFY; + u32 hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG | + SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG; + +--- a/drivers/gpu/drm/i915/i915_reg.h ++++ b/drivers/gpu/drm/i915/i915_reg.h +@@ -210,6 +210,16 @@ + #define ASYNC_FLIP (1<<22) + #define DISPLAY_PLANE_A (0<<20) + #define DISPLAY_PLANE_B (1<<20) ++#define GFX_OP_PIPE_CONTROL ((0x3<<29)|(0x3<<27)|(0x2<<24)|2) ++#define PIPE_CONTROL_QW_WRITE (1<<14) ++#define PIPE_CONTROL_DEPTH_STALL (1<<13) ++#define PIPE_CONTROL_WC_FLUSH (1<<12) ++#define PIPE_CONTROL_IS_FLUSH (1<<11) /* MBZ on Ironlake */ ++#define PIPE_CONTROL_TC_FLUSH (1<<10) /* GM45+ only */ ++#define PIPE_CONTROL_ISP_DIS (1<<9) ++#define PIPE_CONTROL_NOTIFY (1<<8) ++#define PIPE_CONTROL_GLOBAL_GTT (1<<2) /* in addr dword */ ++#define PIPE_CONTROL_STALL_EN (1<<1) /* in addr word, Ironlake+ only */ + + /* + * Fence registers +@@ -2111,6 +2121,7 @@ + #define DEIER 0x4400c + + /* GT interrupt */ ++#define GT_PIPE_NOTIFY (1 << 4) + #define GT_SYNC_STATUS (1 << 2) + #define GT_USER_INTERRUPT (1 << 0) + diff --git a/drm-intel-big-hammer.patch b/drm-intel-big-hammer.patch new file mode 100644 index 000000000..63dc016b1 --- /dev/null +++ b/drm-intel-big-hammer.patch @@ -0,0 +1,16 @@ +diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c +index 37427e4..08af9db 100644 +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -2553,6 +2553,11 @@ i915_gem_execbuffer(struct drm_device *dev, void *data, + + mutex_lock(&dev->struct_mutex); + ++ /* We don't get the flushing right for these chipsets, use the ++ * big hamer for now to avoid random crashiness. */ ++ if (IS_I85X(dev) || IS_I865G(dev)) ++ wbinvd(); ++ + i915_verify_inactive(dev, __FILE__, __LINE__); + + if (dev_priv->mm.wedged) { diff --git a/drm-intel-gen5-dither.patch b/drm-intel-gen5-dither.patch new file mode 100644 index 000000000..68df94d6b --- /dev/null +++ b/drm-intel-gen5-dither.patch @@ -0,0 +1,57 @@ +From b44ee8a479c3adb22b818b8b6aff29c6a08c1cb1 Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Mon, 19 Apr 2010 15:52:32 -0400 +Subject: [PATCH] drm/i915: Use spatio-temporal dithering on PCH + +Spatial dither is better than nothing, but ST is even better. + +Signed-off-by: Adam Jackson +--- + drivers/gpu/drm/i915/i915_reg.h | 5 ++++- + drivers/gpu/drm/i915/intel_display.c | 10 ++++++---- + 2 files changed, 10 insertions(+), 5 deletions(-) + +diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h +index 527d30a..0bbbb77 100644 +--- a/drivers/gpu/drm/i915/i915_reg.h ++++ b/drivers/gpu/drm/i915/i915_reg.h +@@ -1922,7 +1922,10 @@ + /* Display & cursor control */ + + /* dithering flag on Ironlake */ +-#define PIPE_ENABLE_DITHER (1 << 4) ++#define PIPE_ENABLE_DITHER (1 << 4) ++#define PIPE_DITHER_TYPE_MASK (3 << 2) ++#define PIPE_DITHER_TYPE_SPATIAL (0 << 2) ++#define PIPE_DITHER_TYPE_ST01 (1 << 2) + /* Pipe A */ + #define PIPEADSL 0x70000 + #define PIPEACONF 0x70008 +diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c +index 58668c4..36ead0e 100644 +--- a/drivers/gpu/drm/i915/intel_display.c ++++ b/drivers/gpu/drm/i915/intel_display.c +@@ -3676,14 +3676,16 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + /* set the dithering flag */ + if (IS_I965G(dev)) { + if (dev_priv->lvds_dither) { +- if (HAS_PCH_SPLIT(dev)) ++ if (HAS_PCH_SPLIT(dev)) { + pipeconf |= PIPE_ENABLE_DITHER; +- else ++ pipeconf |= PIPE_DITHER_TYPE_ST01; ++ } else + lvds |= LVDS_ENABLE_DITHER; + } else { +- if (HAS_PCH_SPLIT(dev)) ++ if (HAS_PCH_SPLIT(dev)) { + pipeconf &= ~PIPE_ENABLE_DITHER; +- else ++ pipeconf &= ~PIPE_DITHER_TYPE_MASK; ++ } else + lvds &= ~LVDS_ENABLE_DITHER; + } + } +-- +1.7.0.1 + diff --git a/drm-intel-make-lvds-work.patch b/drm-intel-make-lvds-work.patch new file mode 100644 index 000000000..d39936aa3 --- /dev/null +++ b/drm-intel-make-lvds-work.patch @@ -0,0 +1,19 @@ +diff -up linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_display.c.jx linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_display.c +--- linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_display.c.jx 2010-04-19 17:13:31.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/gpu/drm/i915/intel_display.c 2010-04-19 17:13:59.753994103 -0400 +@@ -4141,7 +4141,6 @@ void intel_release_load_detect_pipe(stru + struct drm_connector *connector, int dpms_mode) + { + struct drm_encoder *encoder = &intel_encoder->enc; +- struct drm_device *dev = encoder->dev; + struct drm_crtc *crtc = encoder->crtc; + struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; + struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; +@@ -4151,7 +4150,6 @@ void intel_release_load_detect_pipe(stru + connector->encoder = NULL; + intel_encoder->load_detect_temp = false; + crtc->enabled = drm_helper_crtc_in_use(crtc); +- drm_helper_disable_unused_functions(dev); + } + + /* Switch crtc and encoder back off if necessary */ diff --git a/drm-intel-next.patch b/drm-intel-next.patch new file mode 100644 index 000000000..4e2ef1298 --- /dev/null +++ b/drm-intel-next.patch @@ -0,0 +1,13624 @@ +Start from 2.6.33.y, then pull in 2.6.34, then anholt's for-linus, then +anholt's drm-intel-next minus a bogus TV detection patch and the AGP/GTT +splitup. + +commit 61b8a24d45b1c2ccab371b98f077425d0d73ab7e +Author: Chris Wilson +Date: Thu Jan 7 10:39:13 2010 +0000 + + drm/i915: Replace open-coded eviction in i915_gem_idle() + + With the introduction of the hang-check, we can safely expect that + i915_wait_request() will always return even when the GPU hangs, and so + do not need to open code the wait in order to manually check for the + hang. Also we do not need to always evict all buffers, so only flush + the GPU (and wait for it to idle) for KMS, but continue to evict for UMS. + + Signed-off-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit 4b508552539d0a31eb5c62d1bf4847e1fd338eb8 +Author: Zhenyu Wang +Date: Thu Dec 17 14:48:43 2009 +0800 + + drm/i915: Keep MCHBAR always enabled + + As we need more and more controls within MCHBAR for memory config and + power management, this trys to keep MCHBAR enabled from driver load and + only tear down in driver unload. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 4dd298cb92eccc685aace852cab33d36085cffcc +Author: Eric Anholt +Date: Tue Jan 26 09:43:10 2010 -0800 + + drm/i915: Don't reserve compatibility fence regs in KMS mode. + + The fence start is for compatibility with UMS X Servers before fence + management. KMS X Servers only started doing tiling after fence + management appeared. + + Signed-off-by: Eric Anholt + +commit dd4031f49bbce4b4ed4ad6f0ecf3e7da8bd240aa +Author: Li Peng +Date: Wed Jan 27 19:01:11 2010 +0800 + + drm/i915: enable memory self refresh on 9xx + + Enabling memory self refresh (SR) on 9xx needs to set additional + register bits. On 945, we need bit 31 of FW_BLC_SELF to enable the + write to self refresh bit and bit 16 to enable the write of self + refresh watermark. On 915, bit 12 of INSTPM is used to enable SR. + + SR will take effect when CPU enters C3+ state and its entry/exit + should be automatically controlled by H/W, driver only needs to set + SR enable bits in wm update. But this isn't safe in my test on 945 + because GPU is hung. So this patch explicitly enables SR when GPU + is idle, and disables SR when it is busy. In my test on a netbook of + 945GSE chipset, it saves about 0.8W idle power. + + Signed-off-by: Li Peng + [anholt: rebased against 33c5fd121eabbccc9103daf6cda36941eb3c349f + by adding disable of INSTPM SR bit on 915GM for two pipe setup] + Signed-off-by: Eric Anholt + +commit b71e8e4881b7b8d9d0f622ace6db4d0587198b47 +Author: Jesse Barnes +Date: Fri Jan 29 11:27:07 2010 -0800 + + drm/i915: add dynamic performance control support for Ironlake + + Ironlake (and 965GM, which this patch doesn't support) supports a + hardware performance and power management feature that allows it to + adjust to changes in GPU load over time with software help. The goal + if this is to maximize performance/power for a given workload. + + This patch enables that feature, which is also a requirement for + supporting Intelligent Power Sharing, a feature which allows for + dynamic budgeting of power between the CPU and GPU in Arrandale + platforms. + + Tested-by: ykzhao + [anholt: Resolved against the irq handler loop removal] + Signed-off-by: Jesse Barnes + Signed-off-by: Eric Anholt + +commit bb617ddfd5cfbbd2b657550528a8b9d9827c0c5d +Author: Matthew Garrett +Date: Tue Feb 2 18:30:47 2010 +0000 + + drm/i915: Deobfuscate the render p-state obfuscation + + The ironlake render p-state support includes some rather odd variable + names. Clean them up in order to improve the readability of the code. + + Signed-off-by: Matthew Garrett + Signed-off-by: Eric Anholt + +commit 5b497c826bdd1e2834fa5cf34a1a513f99bde04a +Author: Li Peng +Date: Wed Feb 10 01:54:24 2010 +0800 + + drm/i915: Fix OGLC performance regression on 945 + + He Shuang reported an OGLC performance regression introduced in the patch + "enable memory self refresh on 9xx", In that patch, SR on 945 is disabled + everytime when calling intel_mark_busy(), while too much of such operation + will impact performance. Actually disable SR is necessary only when GPU and + Crtc changing from idle to busy. This patch make such optimization. + + It fixes upstream bug + http://bugs.freedesktop.org/show_bug.cgi?id=26422 + + Signed-off-by: Li Peng + Signed-off-by: Eric Anholt + +commit 8b31f2d2d4c38dd98bc8e1b363984a769b4bcc70 +Author: Jesse Barnes +Date: Thu Feb 4 14:17:47 2010 -0800 + + drm/i915: fix drps disable so unload & re-load works + + At unload time, we need to disable DRPS, but we need to do it correctly + or the GPU will hang and we won't be able to load the module again. So + set the SFCAVM bit so we can properly restore the DRPS config at unload. + + Signed-off-by: Jesse Barnes + Signed-off-by: Eric Anholt + +commit 380119c14abe900e7907ba919cd31935c4bd9b26 +Author: Jesse Barnes +Date: Fri Feb 5 12:42:41 2010 -0800 + + drm/i915: provide FBC status in debugfs + + Tools like powertop want to check the current FBC status and report it + to the user. So add a debugfs file indicating whether FBC is enabled, + and if not, why. + + Signed-off-by: Jesse Barnes + Signed-off-by: Eric Anholt + +commit 1a96157856ccbdad57e0b2c0fdda90533a035d5b +Author: Jesse Barnes +Date: Fri Feb 5 12:47:35 2010 -0800 + + drm/i915: provide self-refresh status in debugfs + + Signed-off-by: Jesse Barnes + Signed-off-by: Eric Anholt + +commit cda4b3ba8d82079de2929f637380a6067f446e08 +Author: Daniel Vetter +Date: Thu Feb 11 14:14:42 2010 +0100 + + drm/i915: overlay: nuke readback to flush wc caches + + I retested this and whatever this papered over, the problem doesn't seem + to exist anymore. + + Signed-off-by: Daniel Vetter + Reviewed-by: Eric Anholt + [anholt: fixed up compile warning] + Signed-off-by: Eric Anholt + +commit 80bd60eafb329be40d6e83a4f0e2f2f2b28b900c +Author: Daniel Vetter +Date: Thu Feb 11 14:14:43 2010 +0100 + + drm/i915: overlay: drop superflous gpu flushes + + Cache-coherency is maintained by gem. Drop these leftover MI_FLUSH + commands from the userspace code. + + Signed-off-by: Daniel Vetter + Acked-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit dd4120e04e07feec4275807656a650448b9fd2ae +Author: Zhenyu Wang +Date: Wed Feb 10 10:39:33 2010 +0800 + + agp/intel: official names for Pineview and Ironlake + + Print official names for Pineview and Ironlake, which is Intel + GMA3150 and Intel HD graphics. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 4c0c82c9109dff54cc80493e7b3d39d0ce97b4f0 +Author: Daniel Vetter +Date: Mon Feb 1 13:59:16 2010 +0100 + + drm/i915: move a gtt flush to the correct place + + No functional change, because gtt flushing is a no-op. Still, try + to keep the bookkeeping accurate. The if is still slightly wrong + for with execbuf2 even i915-class hw doesn't always need a fence + reg for gpu access. But that's for somewhen lateron. + + Signed-off-by: Daniel Vetter + Signed-off-by: Eric Anholt + +commit 37da128862c402c8e0f70d42e5f9113dd20ee6e8 +Author: Daniel Vetter +Date: Mon Feb 1 13:59:17 2010 +0100 + + drm/i915: blow away userspace mappings before fence change + + This aligns it with the other user of i915_gem_clear_fence_reg, + which blows away the mapping before changing the fence reg. + + Only affects userspace if it races against itself when changing + tiling parameters, i.e. behaviour is undefined, anyway. + + Signed-off-by: Daniel Vetter + Reviewed-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit 4f0dd6f6fd13ef49a298e1f7d300b3d4f9ca8f16 +Author: Owain Ainsworth +Date: Thu Feb 18 15:33:00 2010 +0000 + + drm/i915: reduce some of the duplication of tiling checking + + i915_gem_object_fenceable was mostly just a repeat of the + i915_gem_object_fence_offset_ok, but also checking the size (which was + checkecd when we allowed that BO to be tiled in the first place). So + instead, export the latter function and use it in place. + + Signed-Off-By: Owain G. Ainsworth + Signed-off-by: Eric Anholt + +commit e627564787847102753d565bd49a47a9fbd2b2ee +Author: Chris Wilson +Date: Thu Feb 18 10:24:56 2010 +0000 + + drm/i915: Record batch buffer following GPU error + + In order to improve our diagnostic capabilities following a GPU hang + and subsequent reset, we need to record the batch buffer that triggered + the error. We assume that the current batch buffer, plus a few details + about what else is on the active list, will be sufficient -- at the very + least an improvement over nothing. + + The extra information is stored in /debug/dri/.../i915_error_state + following an error, and may be decoded using + intel_gpu_tools/tools/intel_error_decode. + + v2: Avoid excessive work under spinlocks. + v3: Include ringbuffer for later analysis. + v4: Use kunmap correctly and record more buffer state. + v5: Search ringbuffer for current batch buffer + v6: Use a work fn for the impossible IRQ error case. + v7: Avoid non-atomic paths whilst in IRQ context. + + Signed-off-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit 132c106ae1af6c5184fca797366efe24a6a5b3ce +Author: Eric Anholt +Date: Thu Oct 22 16:10:52 2009 -0700 + + agp/intel: Add support for Sandybridge. + + Signed-off-by: Eric Anholt + +commit 404fe3988cc0529bee1a7cb6e9e31096ac003e68 +Author: Eric Anholt +Date: Thu Oct 22 16:11:14 2009 -0700 + + drm/i915: Add initial bits for VGA modesetting bringup on Sandybridge. + + Signed-off-by: Eric Anholt + +commit 80e3829ff4b255ab7f05c4baa0a6af3fafd4885c +Author: Eric Anholt +Date: Mon Oct 26 16:44:17 2009 -0700 + + drm/i915: Set up fence registers on sandybridge. + + Signed-off-by: Eric Anholt + +commit fdda47cece044474e38fc234ee86b0ad889b7e25 +Author: Eric Anholt +Date: Mon Nov 2 12:08:22 2009 -0800 + + drm/i915: Fix sandybridge status page setup. + + The register's moved to the same location as the one for the BCS, it seems. + + Signed-off-by: Eric Anholt + +commit 68904b08da632ce82b551bb1c91111343ba6f715 +Author: Eric Anholt +Date: Mon Nov 2 15:33:05 2009 -0800 + + agp/intel: Use a non-reserved value for the cache field of the PTEs. + + I don't know if this is what we'll want to be using long term, we'll see. + + Signed-off-by: Eric Anholt + +commit c6372005734d735fa05442971656a83ba9bc2fe1 +Author: Eric Anholt +Date: Thu Nov 5 15:30:35 2009 -0800 + + drm/i915: Disable the surface tile swizzling on Sandybridge. + + I can't explain this, except that it makes my display correct. + + Signed-off-by: Eric Anholt + +commit e4dc1f5a66bd5e737fe32f8c17c4eef9ed48e2a3 +Author: Eric Anholt +Date: Mon Nov 9 14:57:34 2009 -0800 + + drm/i915: Correct locking in the modesetting failure path, fixing a BUG_ON. + + Signed-off-by: Eric Anholt + +commit 439c85dab263af43eddbf229dfdad7b5763dfc27 +Author: Zhenyu Wang +Date: Wed Nov 11 01:25:25 2009 +0800 + + drm/i915, agp/intel: Fix stolen memory size on Sandybridge + + New memory control config reg at 0x50 should be used for stolen + memory size detection on Sandybridge. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit fa358e1c80893bf82f1d3d924dbfe10a5a7909c1 +Author: Eric Anholt +Date: Thu Jan 7 16:21:46 2010 -0800 + + agp/intel: Add a new Sandybridge HB/IG PCI ID combo. + + Signed-off-by: Eric Anholt + +commit 3fece8822281b539cc61f86fd8e8b42afed9113c +Author: Eric Anholt +Date: Thu Jan 7 15:08:18 2010 -0800 + + drm/i915: Add a new mobile Sandybridge PCI ID. + + Signed-off-by: Eric Anholt + +commit 0cc29ff88697d208b7244d28bdb508b84b4a6acc +Author: Eric Anholt +Date: Fri Jan 8 14:25:16 2010 -0800 + + drm/i915: Disable the hangcheck reset on Sandybridge until we add support. + + Signed-off-by: Eric Anholt + +commit d37679f2b2661a4a05f260bc6677d8f012ad1d3a +Author: Eric Anholt +Date: Thu Jan 28 16:13:29 2010 -0800 + + drm/i915: Correct the Sandybridge chipset info structs. + + Disables CXSR until it's done, and sets the mobile bit on mobile. + + Signed-off-by: Eric Anholt + +commit cc45bac0967148d193bad87edbf20268d474346a +Author: Eric Anholt +Date: Thu Jan 28 16:45:52 2010 -0800 + + drm/i915: More s/IS_IRONLAKE/HAS_PCH_SPLIT for Sandybridge. + + I think this is pretty much correct. Not really tested. + + Signed-off-by: Eric Anholt + +commit 1035cda8796172825f191fc5a53690a60ae79694 +Author: Zhenyu Wang +Date: Tue Feb 23 14:05:24 2010 +0800 + + drm/i915: Add dependency on the intel agp module + + See http://bugzilla.kernel.org/show_bug.cgi?id=15021 + + Make sure that the appropriate AGP module is loaded and probed before + trying to set up the DRM. The DRM already depends on the AGP core, + but in this case we know the specific AGP driver we need too, and can + help users avoid the trap of loading the AGP driver after the DRM + driver. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 749a3068de80d499a4632c20599e18372b150612 +Author: Daniel Vetter +Date: Fri Feb 19 11:51:56 2010 +0100 + + drm/i915: reuse i915_gem_object_put_fence_reg for fence stealing code + + This has a few functional changes against the old code: + + * a few more unnecessary loads and stores to the drm_i915_fence_reg + objects. Also an unnecessary store to the hw fence register. + + * zaps any userspace mappings before doing other flushes. Only changes + anything when userspace does racy stuff against itself. + + * also flush GTT domain. This is a noop, but still try to keep the + bookkeeping correct. + + Signed-off-by: Daniel Vetter + Signed-off-by: Eric Anholt + +commit 8b0f935bf4b29f75849e59a0b51f671bd009b6cb +Author: Daniel Vetter +Date: Fri Feb 19 11:51:57 2010 +0100 + + drm/i915: fixup active list locking in object_unbind + + All other accesses take this spinlock, so do this here, too. + + Signed-off-by: Daniel Vetter + Signed-off-by: Eric Anholt + +commit 4778b6c5ada71ebe9850005d0321a3a1969cef9c +Author: Daniel Vetter +Date: Fri Feb 19 11:51:58 2010 +0100 + + drm/i915: extract fence stealing code + + The spaghetti logic in there tripped up my brain's code parser for a + few secs. Prevent this from happening again by extracting the fence + stealing code into a seperate functions. IMHO this slightly clears up + the code flow. + + v2: Beautified according to ickle's comments. + v3: ickle forgot to flush his comment queue ... Now there's also a + we-are-paranoid BUG_ON in there. + v4: I've forgotten to switch on my brain when doing v3. Now the BUG_ON + actually checks something useful. + v5: Clean up a stale comment as noted by Eric Anholt. + + Signed-off-by: Daniel Vetter + Reviewed-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit 34c761de7a382135d815ea7cb5a979b33d520484 +Author: Daniel Vetter +Date: Fri Feb 19 11:51:59 2010 +0100 + + drm/i915: ensure lru ordering of fence_list + + The fence_list should be lru ordered for otherwise we might try + to steal a fence reg from an active object even though there are + fences from inactive objects available. lru ordering was obeyed + for gpu access everywhere save when moving dirty objects from + flushing_list to active_list. + + Fixing this cause the code to indent way to much, so I've extracted + the flushing_list processing logic into its on function. + + Signed-off-by: Daniel Vetter + Reviewed-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit f85c68a7feb2bb9d59be8d3faee04d0c4a888ef2 +Author: Daniel Vetter +Date: Fri Feb 19 11:52:00 2010 +0100 + + drm/i915: reuse i915_gpu_idle helper + + We have it, so use it. This required moving the function to avoid + a forward declaration. + + Signed-off-by: Daniel Vetter + Signed-off-by: Eric Anholt + +commit 2cbc022b1813cf865a79d051dec0c43f19987168 +Author: Daniel Vetter +Date: Fri Feb 19 11:52:01 2010 +0100 + + drm/i915: clean-up i915_gem_flush_gpu_write_domain + + Now that we have an exact gpu write domain tracking, we don't need + to move objects to the active list ourself. i915_add_request will + take care of that under all circumstances. + + Idea stolen from a patch by Chris Wilson . + + Signed-off-by: Daniel Vetter + Signed-off-by: Chris Wilson + Signed-off-by: Eric Anholt + +commit bee2714db60a22a3e50bedb130bfeb4601eaeaa6 +Author: Daniel Vetter +Date: Fri Feb 19 11:52:02 2010 +0100 + + drm/i915: check for multiple write domains in pin_and_relocate + + The assumption that an object has only ever one write domain is deeply + threaded into gem (it's even encoded the the singular of the variable + name). Don't let userspace screw us over. + + Signed-off-by: Daniel Vetter + Signed-off-by: Eric Anholt + +commit 0a0ab3f65aa8f24d12aada76f46db902b9936762 +Author: Jesse Barnes +Date: Thu Feb 11 12:41:05 2010 -0800 + + drm/i915: enable/disable LVDS port at DPMS time + + It would be good to disable the LVDS port when we shut down the panel + to save power. We haven't done so until now because we had trouble + getting the right LVDS parameters from the BIOS. I think we're past + that now, so enabling and disabling the port should be safe, though it + would probably be made cleaner with some additional changes to the + display code, where we also bang on the LVDS reg to set the pairing + correctly etc. + + Seems to save a bit of power (up to 300mW in my basic wattsup + meter testing). + + Signed-off-by: Jesse Barnes + Signed-off-by: Eric Anholt + +commit 9dab2f83450d574e05d03058dd2c0ce544a47fcd +Author: Eric Anholt +Date: Fri Feb 26 13:32:11 2010 -0800 + + drm/i915: Don't bother with the BKL for GEM ioctls. + + We probably don't need it for most of the other driver ioctls as well, + but we explicitly did locking when doing the GEM pieces. On CPU-bound + graphics tasks, the BKL was showing up as 1-2% of CPU time. + + Signed-off-by: Eric Anholt + +commit eaa175e1942fa941c1047159721f838b3dc56263 +Author: Owain G. Ainsworth +Date: Wed Mar 3 05:34:29 2010 +0000 + + drm/i915: remove an unnecessary wait_request() + + The continue just after this call with loop around and wait for the + request just added just fine. This leads to slightly more compact code. + + Signed-Off-by: Owain G. Ainsworth + Signed-off-by: Eric Anholt + +commit 4ab0ede782d4e161ee75e076344d244847892857 +Author: Priit Laes +Date: Tue Mar 2 11:37:00 2010 +0200 + + drm/i915: Rename FBC_C3_IDLE to FBC_CTL_C3_IDLE to match other registers + + Signed-off-by: Priit Laes + Signed-off-by: Eric Anholt + +commit e213ec072ae610dad353481c654b46904b01f830 +Author: Eric Anholt +Date: Mon Mar 8 23:41:55 2010 -0800 + + drm/i915: Enable VS timer dispatch. + + This could resolve HW deadlocks where a unit downstream of the VS is + waiting for more input, the VS has one vertex queued up but not + dispatched because it hopes to get one more vertex for 2x4 dispatch, + and software isn't handing more vertices down because it's waiting for + rendering to complete. The B-Spec says you should always have this + bit set. + + Signed-off-by: Eric Anholt + +commit ae87627922f7f0f0b16c8b24e120f1d4c5574ed5 +Author: Joe Perches +Date: Thu Mar 11 14:01:38 2010 -0800 + + drivers/gpu/drm/i915/intel_bios.c: fix continuation line formats + + String constants that are continued on subsequent lines with \ will cause + spurious whitespace in the resulting output. + + Signed-off-by: Joe Perches + Cc: Dave Airlie + Cc: Eric Anholt + Cc: Jesse Barnes + Signed-off-by: Andrew Morton + [anholt: whacked it to wrap to 80 columns instead] + Signed-off-by: Eric Anholt + +commit a977b689d5e9163fe9dec0f3c33c4fb76982964e +Author: Zhenyu Wang +Date: Tue Mar 9 23:37:07 2010 +0800 + + drm/i915: Fix check with IS_GEN6 + + IS_GEN6 missed to include SandyBridge mobile chip, which failed in + i915_probe_agp() for memory config detection. Fix it with a device + info flag. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit bced22270e7a871b27cf6df978fbbda1afe010c2 +Author: Dan Carpenter +Date: Sat Mar 6 14:05:39 2010 +0300 + + drm/i915: fix small leak on overlay error path + + We should free "params" before returning. + + Signed-off-by: Dan Carpenter + Reviewed-by: Daniel Vetter + Cc: stable@kernel.org (for .33) + Signed-off-by: Eric Anholt + +commit 9f3dd99fc14b1344a34132011d189e44ca94faab +Author: Eric Anholt +Date: Thu Mar 18 11:24:06 2010 -0700 + + agp/intel: Respect the GTT size on Sandybridge for scratch page setup. + + This is similar to 14bc490bbdf1b194ad1f5f3d2a0a27edfdf78986 which + respected it for how much of the GTT we would actually use. Now we + won't clear beyond allocated memory when filling the GTT with scratch + page addresses. + + Signed-off-by: Eric Anholt + +commit aa46089ff1f59213cfd0cee248485830b60e2ba6 +Author: Eric Anholt +Date: Thu Mar 18 12:19:37 2010 -0700 + + agp/intel: Don't do the chipset flush on Sandybridge. + + This CPU should be coherent with graphics in this direction, though + flushing graphics caches are still required. Fixes a system reset on + module load on Sandybridge with 4G+ memory. + + Signed-off-by: Eric Anholt + +commit 57cf4aac610bac23c5469d6e65d56004be4ebfab +Author: Eric Anholt +Date: Thu Mar 18 13:21:14 2010 -0700 + + drm/i915: Set up the documented clock gating on Sandybridge and Ironlake. + + Signed-off-by: Eric Anholt + +commit 3b0f299bd7b2ecc2ed71f539aff433eb74a59526 +Author: Daniel Vetter +Date: Thu Mar 18 09:22:12 2010 +0100 + + drm/intel: fix up set_tiling for untiled->tiled transition + + Bug introduced in + + commit 10ae9bd25acf394c8fa2f9d795dfa9cec4d19ed6 + Author: Daniel Vetter + Date: Mon Feb 1 13:59:17 2010 +0100 + + drm/i915: blow away userspace mappings before fence change + + The problem is that when there's no fence reg assigned and the object + is mapped at a fenceable offset in the gtt, the userspace mappings won't + be torn down. Which happens on untiled->tiled transition quite often + on 4th gen and later because there fencing does not have any special + alignment constraints (as opposed to 2nd and 3rd gen on which I've tested + the original commit). + + Bugzilla: http://bugs.freedesktop.org/show_bug.cgi?id=26993 + Signed-off-by: Daniel Vetter + Tested-by: Eric Anholt (fixes OpenArena) + Signed-off-by: Eric Anholt + +commit a84f55fc0dfb2d5d5a71b2662cb6a438955865d8 +Author: Eric Anholt +Date: Wed Mar 17 13:48:06 2010 -0700 + + drm/i915: Stop trying to use ACPI lid status to determine LVDS connection. + + I've been getting more and more quirk reports about this. It seems + clear at this point that other OSes are not using this for determining + whether the integrated panel should be turned on, and it is not + reliable for doing so. Better to light up an unintended panel than to + not light up the only usable output on the system. + + Signed-off-by: Eric Anholt + Acked-by: Jesse Barnes + +commit e08daaf2d1c43bf6321fd16ac07a784afcfc3a93 +Author: Robert Hooker +Date: Fri Mar 19 15:13:27 2010 -0400 + + drm/i915: Disable FBC on 915GM and 945GM. + + It is causing hangs after a suspend/resume cycle with the default + powersave=1 module option on these chipsets since 2.6.32-rc. + + BugLink: http://bugs.launchpad.net/bugs/492392 + Signed-off-by: Robert Hooker + Acked-by: Jesse Barnes + Signed-off-by: Eric Anholt + +commit c438e43c09f6c2afe32571a4096e27dbd221a616 +Author: Daniel Vetter +Date: Mon Mar 8 13:35:02 2010 +0100 + + drm/i915: introduce to_intel_bo helper + + This is a purely cosmetic change to make changes in this area easier. + And hey, it's not only clearer and typechecked, but actually shorter, + too! + + [anholt: To clarify, this is a change to let us later make + drm_i915_gem_object subclass drm_gem_object, instead of having + drm_gem_object have a pointer to i915's private data] + + Signed-off-by: Daniel Vetter + Acked-by: Dave Airlie + Signed-off-by: Eric Anholt + +commit 6a891482640b165ac350b83d8f0446f6b09a1a3d +Author: Daniel Vetter +Date: Fri Mar 19 21:46:23 2010 +0100 + + agp/intel: intel_845_driver is an agp driver! + + ... not a GTT driver. So the additional chipset flush introduced in + + commit 2162e6a2b0cd5acbb9bd8a3c94e1c1269b078295 + Author: Dave Airlie + Date: Wed Nov 21 16:36:31 2007 +1000 + + agp/intel: Add chipset flushing support for i8xx chipsets. + + to fix a GTT problem makes absolutely no sense. If this would really be needed + for AGP chipsets, too, we should add it to all i8xx agp drivers, not just one. + + Signed-off-by: Daniel Vetter + Signed-off-by: Eric Anholt + +commit d6a705b18cf0635af7c7b033e46051d9ed62df64 +Author: Eric Anholt +Date: Thu Mar 25 11:11:14 2010 -0700 + + drm/i915: Rename intel_output to intel_encoder. + + The intel_output naming is inherited from the UMS code, which had a + structure of screen -> CRTC -> output. The DRM code has an additional + notion of encoder/connector, so the structure is screen -> CRTC -> + encoder -> connector. This is a useful structure for SDVO encoders + which can support multiple connectors (each of which requires + different programming in the one encoder and could be connected to + different CRTCs), or for DVI-I, where multiple encoders feed into the + connector for whether it's used for digital or analog. Most of our + code is encoder-related, so transition it to talking about encoders + before we start trying to distinguish connectors. + + This patch is produced by sed s/intel_output/intel_encoder/ over the + driver. + + Signed-off-by: Eric Anholt + +commit 9feb424d3e107e74e2ed9dfbce6c34a20d3eff0d +Author: Eric Anholt +Date: Thu Mar 25 11:48:48 2010 -0700 + + drm/i915: Rename many remaining uses of "output" to encoder or connector. + + Signed-off-by: Eric Anholt + +commit fdb1359d8e086da1139424be81dba17596b59c06 +Author: Stefan Bader +Date: Mon Mar 29 17:53:12 2010 +0200 + + drm/i915: Add no_lvds entry for the Clientron U800 + + BugLink: http://bugs.launchpad.net/ubuntu/bugs/544671 + + This system claims to have a LVDS but has not. + + Signed-off-by: Stephane Graber + Signed-off-by: Stefan Bader + CC: stable@kernel.org + Signed-off-by: Eric Anholt + +commit cdff9756ece2333713af35eedefffc58721a0eab +Author: Zhao Yakui +Date: Wed Apr 7 17:11:22 2010 +0800 + + drm/i915: Ignore LVDS EDID when it is unavailabe or invalid + + This trys to shut up complains about invalid LVDS EDID during + mode probe, but uses fixed panel mode directly for panels with + broken EDID. + + https://bugs.freedesktop.org/show_bug.cgi?id=23099 + https://bugs.freedesktop.org/show_bug.cgi?id=26395 + + Signed-off-by: Zhao Yakui + Tested-by: Sitsofe Wheeler + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 827b98413e1ca8c3657fe83b39671c87503702b8 +Author: Adam Jackson +Date: Fri Apr 16 18:20:57 2010 -0400 + + drm/i915: Attempt to fix watermark setup on 85x (v2) + + IS_MOBILE() catches 85x, so we'd always try to use the 9xx FIFO sizing; + since there's an explicit 85x version, this seems wrong. + + v2: Handle 830m correctly too. + + Signed-off-by: Adam Jackson + Reviewed-by: Eric Anholt + Signed-off-by: Eric Anholt + +commit 5c9713caf3a211c7af399036dbc70defa4df09a4 +Author: Adam Jackson +Date: Thu Apr 15 14:03:30 2010 -0400 + + drm/i915: Fix 82854 PCI ID, and treat it like other 85X + + pci.ids and the datasheet both say it's 358e, not 35e8. + + Signed-off-by: Adam Jackson + Signed-off-by: Eric Anholt + +commit 6a399e79b2e61ca95a8b88a6f49e1382aea23f75 +Author: Zhang Rui +Date: Mon Mar 29 15:12:16 2010 +0800 + + drm/i915: set DIDL using the ACPI video output device _ADR method return. + + we used to set the DIDL in the output device detected order. + But some BIOSes requires it to be initialized in the ACPI device order. + e.g. the value of the first field in DIDL stands for the first + ACPI video output device in ACPI namespace. + + Now we initialize the DIDL using the device id, i.e. _ADR return value, + of each ACPI video device, if it is not 0. + https://bugzilla.kernel.org/show_bug.cgi?id=15054 + + Signed-off-by: Zhang Rui + Signed-off-by: Eric Anholt + +commit fabde8feddccbfc88c48e3e1c3e97d58094988c8 +Author: Daniel Vetter +Date: Sat Apr 17 15:12:03 2010 +0200 + + drm/i915: fix tiling limits for i915 class hw v2 + + Current code is definitely crap: Largest pitch allowed spills into + the TILING_Y bit of the fence registers ... :( + + I've rewritten the limits check under the assumption that 3rd gen hw + has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an + otherwise totally misleading XXX comment. + + This bug mostly resulted in tiling-corrupted pixmaps because the kernel + allowed too wide buffers to be tiled. Bug brought to the light by the + xf86-video-intel 2.11 release because that unconditionally enabled + tiling for pixmaps, relying on the kernel to check things. Tiling for + the framebuffer was not affected because the ddx does some additional + checks there ensure the buffer is within hw-limits. + + v2: Instead of computing the value that would be written into the + hw fence registers and then checking the limits simply check whether + the stride is above the 8kb limit. To better document the hw, add + some WARN_ONs in i915_write_fence_reg like I've done for the i830 + case (using the right limits). + + Signed-off-by: Daniel Vetter + Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27449 + Tested-by: Alexander Lam + Cc: stable@kernel.org + Signed-off-by: Eric Anholt + +commit d69abbbe43a7697ed7c12a7c57008023e92cffd2 +Author: Li Zefan +Date: Thu Mar 11 16:41:45 2010 +0800 + + drm/i915: Convert some trace events to DEFINE_TRACE + + Use DECLARE_EVENT_CLASS to remove duplicate code: + + text data bss dec hex filename + 14655 2732 15 17402 43fa i915_trace_points.o.orig + 11625 2732 10 14367 381f i915_trace_points.o + + 8 events are converted: + + i915_gem_object: i915_gem_object_{unbind, destroy} + i915_gem_request: i915_gem_request_{complete, retire, wait_begin, wait_end} + i915_ring: i915_ring_{wait_begin, wait_end} + + No functional change. + + Signed-off-by: Li Zefan + Signed-off-by: Eric Anholt + +commit 2f99e2fb0673252dc3559ed69ff3ec96fb579166 +Author: Zhenyu Wang +Date: Tue Mar 30 14:39:26 2010 +0800 + + drm/i915: use encoder_list for hotplug callback + + Instead of walking through drm connector_list uses encoder_list + for calling hotplug functions which is consistent with intel display + hotplug reporting. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit fefa3dcedc5f630f653bfd6b39ff172a0e5e171e +Author: Zhenyu Wang +Date: Tue Mar 30 14:39:27 2010 +0800 + + drm/i915: more conversion from connector_list walk to encoder_list + + What we really want is encoder info instead of connector, so change + some more list walk in pipeline setup functions from connector_list + to encoder_list. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 49c4aec093be9e3a9fa046211a11b88949cf6792 +Author: Zhenyu Wang +Date: Tue Mar 30 14:39:28 2010 +0800 + + drm/i915: Add new 'intel_connector' structure + + This adds new structure of intel_connector to present drm's + connector object, which is used to convert from origin single + output into encoder/connector model. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 2100929e476cc423d08478432b04ac887e7b6b3b +Author: Zhenyu Wang +Date: Tue Mar 30 14:39:29 2010 +0800 + + drm/i915: Add new helper to return current attached encoder for connector + + For introducing splitted encoder/connector structure, this helper will return + connector's attached encoder when needed. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 0059113e16782b363c65dcf6f3041b37783ba190 +Author: Zhenyu Wang +Date: Tue Mar 30 14:39:30 2010 +0800 + + drm/i915: passing drm connector param for load detection + + In load detection, connector's encoder assignment must be kept + consistent for proper mode setting, and this makes connector as + explicit parameter for load detect function to not require single + data structure to hold both encoder and connector reference, ease + the transition for splitted encoder/connector model. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 17b2b7b441b69c8ddaff50332e2c55a004c791cb +Author: Zhenyu Wang +Date: Tue Mar 30 14:39:31 2010 +0800 + + drm/i915: change intel_ddc_get_modes() function parameters + + This one replaces original param for intel_ddc_get_modes() with + DRM connector and i2c bus adapter instead. With explicit params, + we won't require that a single driver structure must hold connector + and DDC bus reference, which ease the conversion to splitted encoder/ + connector model. + + It also clears up for some cases that we would steal other DDC bus + for mode probe, like VGA analog DDC probe for DVI-I. Also it fixed + a bug in old DVI-I probe handling, that failed to restore origin + analog GPIO port. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 020bcd645be8b7a0837b7a0593430f26ad121844 +Author: Eric Anholt +Date: Fri Apr 2 15:24:27 2010 -0700 + + drm/i915: Remove dead KMS encoder save/restore code. + + This was brought over from UMS, and used for a while until we decided + that drm_helper_resume_force_mode was easier and more reliable, since + it didn't require duplicating all the code deleted here. We just + forgot to delete all that junk for a while. + +commit a51895bee213fc506644305d65f8a7e9bc0a42d7 +Author: Adam Jackson +Date: Wed Mar 31 11:41:51 2010 -0400 + + drm/i915: Allow LVDS on pipe A on gen4+ + + The gen4 docs say it works, so why not. Tested on Ironlake. + + Signed-off-by: Adam Jackson + Signed-off-by: Eric Anholt + +commit f8c7768b50a68991f118aaa9c27039a9f1dfaa16 +Author: Eric Anholt +Date: Fri Apr 9 14:18:55 2010 -0700 + + drm/i915: Clear the LVDS pipe B select bit when moving the LVDS to pipe A. + + Based on a patch by Zhao Yakui. + + Signed-off-by: Eric Anholt + +commit 4b75c3a050bccdd35f4298514571c024bf51c33e +Author: Zhao Yakui +Date: Wed Apr 7 17:11:21 2010 +0800 + + drm/i915: Fix legacy BLC event for pipe A + + OpRegion event on 965G requires legacy BLC event enabled in pipe stat. As LVDS + could be on either pipe now, we should enable BLC event on both pipe. If fail to + do so, we couldn't handle the brightness request triggered from graphics + opregion. + + Signed-off-by: Zhao Yakui + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 1d3d609b68107aad7076244742ddb3bcdcd282eb +Author: Zhenyu Wang +Date: Wed Apr 7 16:15:52 2010 +0800 + + drm/i915: Sandybridge has no integrated TV + + Integrated TV is deprecated in new chips from Ironlake. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit c4418d1fcf08d0ffde92c96f235ac6a23864d709 +Author: Zhenyu Wang +Date: Wed Apr 7 16:15:53 2010 +0800 + + drm/i915: Probe for PCH chipset type + + PCH is the new name for south bridge from Ironlake/Sandybridge, + which contains most of the display outputs except eDP. This one + adds a probe function to detect current PCH type, and method to + detect Cougarpoint PCH. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 528bcb3d7676df9cb29b11b73fcb53be10f8240e +Author: Zhenyu Wang +Date: Wed Apr 7 16:15:54 2010 +0800 + + drm/i915: Support for Cougarpoint PCH display pipeline + + Cougarpoint is the new PCH for Sandybridge CPU. This one resolves the + chipset change for display pipeline compared to previous Ibexpeak PCH. + + Sandybridge/Cougarpoint has different FDI training parameters, so this also + makes seperate FDI training functions for IBX and CPT. Other change includes + new transcoder DPLL select function to set which DPLL for transcoder to pick + up. + + And with another new transcoder C introduced in Cougarpoint, each connector + has new transcoder select bits. This one adds that change to light up VGA. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit c19eb88cd3867b0e5850c322ffeeb2b0f95a61fa +Author: Zhenyu Wang +Date: Wed Apr 7 16:15:55 2010 +0800 + + drm/i915: Fix CRT force detect on Cougarpoint + + To make CRT force detect reliable on Cougarpoint, we need to + disable DAC before force detect, and restore back when trigger + is completed. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit bbe5385748d3514f2ec821af6b0cd1e8b8126788 +Author: Zhenyu Wang +Date: Wed Apr 7 16:15:56 2010 +0800 + + drm/i915: enable LVDS on Cougarpoint + + Fix the transcoder select bit for LVDS on CPT. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 9397e6409c31333c24f2120bc1242e57409b17b1 +Author: Zhenyu Wang +Date: Wed Apr 7 16:15:57 2010 +0800 + + drm/i915: enable HDMI on Cougarpoint + + Fix transcoder select bit for HDMI on CPT. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit b0280fea16c1993823e96ea60732471a673930a9 +Author: Zhenyu Wang +Date: Thu Apr 8 09:43:27 2010 +0800 + + drm/i915: enable DP/eDP for Sandybridge/Cougarpoint + + DP on Cougarpoint has new training pattern definitions, and + new transcoder DP control register is used to determine the mapping + for transcoder and DP digital output. And eDP for Sandybridge has + new voltage and pre-emphasis level definitions. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 34400e21a2ec1862a6aea1d415e16a8973d08009 +Author: Adam Jackson +Date: Mon Apr 5 17:58:00 2010 -0400 + + drm/i915: Un-magic a DPCD register write + + Signed-off-by: Adam Jackson + Signed-off-by: Eric Anholt + +commit d529f2bd3e73af3f58dacc142c8df96b2d8ac3de +Author: Adam Jackson +Date: Mon Apr 5 17:57:59 2010 -0400 + + drm/i915: Set sync polarity correctly on DisplayPort + + Probably only matters for format-converting dongles, but might as well + get it right all the time. + + Signed-off-by: Adam Jackson + Signed-off-by: Eric Anholt + +commit a0cf638b48c4c19531c02b546dc0a65947512588 +Author: Zhenyu Wang +Date: Mon Mar 29 15:53:23 2010 +0800 + + drm/i915: convert VGA driver to new encoder/connector structure + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 19dc930333364cee93468b49f96d93411b2dab93 +Author: Zhenyu Wang +Date: Mon Mar 29 16:40:50 2010 +0800 + + drm/i915: convert LVDS driver to new encoder/connector structure + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit fdb747792398be0bc2574b1e5bb0375a6e1ba709 +Author: Zhenyu Wang +Date: Mon Mar 29 15:57:42 2010 +0800 + + drm/i915: convert HDMI driver to new encoder/connector structure + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 76641985c72921092cb831dd09bc634c2fd89f71 +Author: Zhenyu Wang +Date: Mon Mar 29 16:13:57 2010 +0800 + + drm/i915: convert DP/eDP driver to new encoder/connector structure + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit ce8122f57adb42e80d2c62a6dd2df5660331c769 +Author: Zhenyu Wang +Date: Mon Mar 29 16:17:31 2010 +0800 + + drm/i915: convert DVO driver to new encoder/connector structure + + Also remove old UMS copied code for get_crtc. + + Signed-off-by: Zhenyu Wang + Signed-off-by: Eric Anholt + +commit 6cc8f013f8ebd91eea0667853ed765e1a6532649 +Author: Zhenyu Wang +Date: Mon Mar 29 21:22:55 2010 +0800 + + drm/i915: convert SDVO driver to new encoder/connector structure + + Signed-off-by: Zhenyu Wang + +commit f870c2dc4e9ca7609d9a0948cafb80b5af84158c +Author: Zhenyu Wang +Date: Mon Mar 29 16:38:44 2010 +0800 + + drm/i915: convert TV driver to new encoder/connector structure + + Signed-off-by: Zhenyu Wang + +commit 1be1fd9444588e710ba251400249deda17e6801b +Author: Zhenyu Wang +Date: Mon Mar 29 16:44:15 2010 +0800 + + drm/i915: remove connector object in old output structure + + As all display drivers have been converted, remove the left reference + for connector object in old structure. + + Signed-off-by: Zhenyu Wang + +commit f9949e3847426bd72beb6be9361a0bed32992ac5 +Author: Zhenyu Wang +Date: Mon Mar 29 16:54:31 2010 +0800 + + drm/i915: remove unused intel_pipe_get_connector() + + Added by original eDP support patch, not used any more. + + Signed-off-by: Zhenyu Wang + +commit 50b923cf1150fdf88312fb8616114e3fb5e57e57 +Author: Zhenyu Wang +Date: Tue Mar 30 14:06:33 2010 +0800 + + drm/i915: implement multifunction SDVO device support + + With new intel_encoder/intel_connector structure change, each supported + connector type on SDVO device will be created as a new 'intel_connector', + and all attached to one 'intel_encoder' for its SDVO port. + + The SDVO encoder will handle SDVO protocol stuff, and each connector does + its own part of work now, like detection is only to check if current active + output is itself, etc. + + Update since last submit: + - Fixed SDVO TV property creation failure by incorrect set target output call + + Signed-off-by: Zhenyu Wang + +commit be7b7e1da367289b0998343af837dad531da7fd6 +Author: Zhenyu Wang +Date: Mon Mar 29 23:16:13 2010 +0800 + + Revert "drm/i915: Use a dmi quirk to skip a broken SDVO TV output." + + This reverts commit 6070a4a928f8c92b9fae7d6717ebbb05f425d6b2. + + The quirk for this SDVO device on IBM specific board is just a hack + in old code which showed the broken multifunction SDVO support in + the driver. Multifunction SDVO patch provided the right fix for it. + + Signed-off-by: Zhenyu Wang + +commit fa4cee3074fea74b556864ce25983b79598ba743 +Author: Luca Tettamanti +Date: Thu Apr 8 21:41:59 2010 +0200 + + drm/i915: do not read uninitialized ->dev_private + + ->dev_private at that point is NULL and is initialied only a few lines + later. + + Signed-off-by: Luca Tettamanti + Signed-off-by: Eric Anholt + +commit 52eacfb9897f9a36cc93b587c57b922b8507d900 +Author: Zhao Yakui +Date: Tue Mar 30 15:11:33 2010 +0800 + + drm/i915: Add support of SDVO on Ibexpeak PCH + + SDVO on Ibexpeak PCH with Ironlake is multiplexed with + HDMIB port, and only has SDVOB port. + + Signed-off-by: Zhao Yakui + Signed-off-by: Zhenyu Wang + +commit 9df31d77abdd69427324bd0b4cd7f52eecb4a95a +Author: Zhao Yakui +Date: Tue Mar 30 15:15:02 2010 +0800 + + drm/i915: Fix the incorrect argument for SDVO SET_TV_format command + + Otherwise it will cause that S-video output becomes black/white when + switching to other TV format. + + http://bugs.freedesktop.org/show_bug.cgi?id=23916 + + Signed-off-by: Zhao Yakui + Tested-by: Arnold + Tested-by: Bazin + Tested-by: Nigel + Signed-off-by: Zhenyu Wang + +commit 064e7eadac1c51ce7a675da8b750defd6e82cb4b +Author: Zhao Yakui +Date: Fri Mar 19 17:05:10 2010 +0800 + + drm/i915: Only save/restore FBC on the platform that supports FBC + + Signed-off-by: Zhao Yakui + Signed-off-by: Zhenyu Wang + +commit 8860a05210d493379a9857e10b051f54097d6078 +Author: Zhao Yakui +Date: Mon Mar 22 22:45:36 2010 +0800 + + drm/i915: Move Pineview CxSR and watermark code into update_wm hook. + + Previously, after setting up the Pineview CxSR state, i9xx_update_wm would + get called and overwrite our state. + + BTW: We will disable the self-refresh and never enable it any more if we + can't find the appropriate the latency on pineview plaftorm. In such case + the update_wm callback will be NULL. + + The bitmask macro is also defined to access the corresponding fifo + watermark register. + + Signed-off-by: Zhao Yakui + Signed-off-by: Zhenyu Wang + +commit 8ab60b6bda618cf0ad0cc628bd174a9b9338dd64 +Author: Zhenyu Wang +Date: Thu Apr 1 13:07:53 2010 +0800 + + drm/i915: Add the support of memory self-refresh on Ironlake + + Update the self-refresh watermark for display plane/cursor and enable + the memory self-refresh on Ironlake. The watermark is also updated for + the active display plane. + + More than 1W idle power is saved on one Ironlake laptop after enabling + memory self-refresh. + + Signed-off-by: Zhao Yakui + Signed-off-by: Zhenyu Wang + +commit 55d812048fff0c36c2aed8165dcbd5578adb5807 +Author: Adam Jackson +Date: Mon Apr 12 11:38:44 2010 -0400 + + drm/i915/pch: Use minimal number of FDI lanes (v2) + + This should be a small power savings. Tested on Lenovo T410 (Ironlake), LVDS + VGA and DisplayPort, up to 1920x1200R. + + v2: Add Sandybridge support, fix obvious math error. + + Acked-by: Zhenyu Wang + Signed-off-by: Adam Jackson + Signed-off-by: Eric Anholt + +commit 12f713e6d7a31fb9cad311bbceae592ce1bb77a0 +Author: Karsten Wiese +Date: Sat Mar 27 22:48:33 2010 +0100 + + drm/i915: Don't touch PORT_HOTPLUG_EN in intel_dp_detect() + + PORT_HOTPLUG_EN has allready been setup in i915_driver_irq_postinstall(), + when intel_dp_detect() runs. + + Delete the DP[BCD]_HOTPLUG_INT_EN defines, they are not referenced anymore. + + I found this while searching for a fix for + https://bugzilla.redhat.com/show_bug.cgi?id=528312 + + Signed-off-by: Karsten Wiese + Signed-off-by: Eric Anholt + +diff --git a/drivers/char/agp/intel-agp.c b/drivers/char/agp/intel-agp.c +index 3999a5f..64f8397 100644 +--- a/drivers/char/agp/intel-agp.c ++++ b/drivers/char/agp/intel-agp.c +@@ -10,6 +10,9 @@ + #include + #include "agp.h" + ++int intel_agp_enabled; ++EXPORT_SYMBOL(intel_agp_enabled); ++ + /* + * If we have Intel graphics, we're not going to have anything other than + * an Intel IOMMU. So make the correct use of the PCI DMA API contingent +@@ -64,6 +67,10 @@ + #define PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB 0x0062 + #define PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB 0x006a + #define PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG 0x0046 ++#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB 0x0100 ++#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_IG 0x0102 ++#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB 0x0104 ++#define PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_IG 0x0106 + + /* cover 915 and 945 variants */ + #define IS_I915 (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_E7221_HB || \ +@@ -89,6 +96,9 @@ + #define IS_PINEVIEW (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB || \ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_PINEVIEW_HB) + ++#define IS_SNB (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB || \ ++ agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB) ++ + #define IS_G4X (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_EAGLELAKE_HB || \ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_Q45_HB || \ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_G45_HB || \ +@@ -98,7 +108,8 @@ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB || \ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB || \ + agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB || \ +- agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB) ++ agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB || \ ++ IS_SNB) + + extern int agp_memory_reserved; + +@@ -147,6 +158,29 @@ extern int agp_memory_reserved; + #define INTEL_I7505_AGPCTRL 0x70 + #define INTEL_I7505_MCHCFG 0x50 + ++#define SNB_GMCH_CTRL 0x50 ++#define SNB_GMCH_GMS_STOLEN_MASK 0xF8 ++#define SNB_GMCH_GMS_STOLEN_32M (1 << 3) ++#define SNB_GMCH_GMS_STOLEN_64M (2 << 3) ++#define SNB_GMCH_GMS_STOLEN_96M (3 << 3) ++#define SNB_GMCH_GMS_STOLEN_128M (4 << 3) ++#define SNB_GMCH_GMS_STOLEN_160M (5 << 3) ++#define SNB_GMCH_GMS_STOLEN_192M (6 << 3) ++#define SNB_GMCH_GMS_STOLEN_224M (7 << 3) ++#define SNB_GMCH_GMS_STOLEN_256M (8 << 3) ++#define SNB_GMCH_GMS_STOLEN_288M (9 << 3) ++#define SNB_GMCH_GMS_STOLEN_320M (0xa << 3) ++#define SNB_GMCH_GMS_STOLEN_352M (0xb << 3) ++#define SNB_GMCH_GMS_STOLEN_384M (0xc << 3) ++#define SNB_GMCH_GMS_STOLEN_416M (0xd << 3) ++#define SNB_GMCH_GMS_STOLEN_448M (0xe << 3) ++#define SNB_GMCH_GMS_STOLEN_480M (0xf << 3) ++#define SNB_GMCH_GMS_STOLEN_512M (0x10 << 3) ++#define SNB_GTT_SIZE_0M (0 << 8) ++#define SNB_GTT_SIZE_1M (1 << 8) ++#define SNB_GTT_SIZE_2M (2 << 8) ++#define SNB_GTT_SIZE_MASK (3 << 8) ++ + static const struct aper_size_info_fixed intel_i810_sizes[] = + { + {64, 16384, 4}, +@@ -293,6 +327,13 @@ static void intel_agp_insert_sg_entries(struct agp_memory *mem, + off_t pg_start, int mask_type) + { + int i, j; ++ u32 cache_bits = 0; ++ ++ if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB || ++ agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB) ++ { ++ cache_bits = I830_PTE_SYSTEM_CACHED; ++ } + + for (i = 0, j = pg_start; i < mem->page_count; i++, j++) { + writel(agp_bridge->driver->mask_memory(agp_bridge, +@@ -613,7 +654,7 @@ static struct aper_size_info_fixed intel_i830_sizes[] = + static void intel_i830_init_gtt_entries(void) + { + u16 gmch_ctrl; +- int gtt_entries; ++ int gtt_entries = 0; + u8 rdct; + int local = 0; + static const int ddt[4] = { 0, 16, 32, 64 }; +@@ -705,6 +746,63 @@ static void intel_i830_init_gtt_entries(void) + gtt_entries = 0; + break; + } ++ } else if (agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB || ++ agp_bridge->dev->device == PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB) { ++ /* ++ * SandyBridge has new memory control reg at 0x50.w ++ */ ++ u16 snb_gmch_ctl; ++ pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl); ++ switch (snb_gmch_ctl & SNB_GMCH_GMS_STOLEN_MASK) { ++ case SNB_GMCH_GMS_STOLEN_32M: ++ gtt_entries = MB(32) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_64M: ++ gtt_entries = MB(64) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_96M: ++ gtt_entries = MB(96) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_128M: ++ gtt_entries = MB(128) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_160M: ++ gtt_entries = MB(160) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_192M: ++ gtt_entries = MB(192) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_224M: ++ gtt_entries = MB(224) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_256M: ++ gtt_entries = MB(256) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_288M: ++ gtt_entries = MB(288) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_320M: ++ gtt_entries = MB(320) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_352M: ++ gtt_entries = MB(352) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_384M: ++ gtt_entries = MB(384) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_416M: ++ gtt_entries = MB(416) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_448M: ++ gtt_entries = MB(448) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_480M: ++ gtt_entries = MB(480) - KB(size); ++ break; ++ case SNB_GMCH_GMS_STOLEN_512M: ++ gtt_entries = MB(512) - KB(size); ++ break; ++ } + } else { + switch (gmch_ctrl & I855_GMCH_GMS_MASK) { + case I855_GMCH_GMS_STOLEN_1M: +@@ -1115,6 +1213,9 @@ static void intel_i9xx_setup_flush(void) + if (intel_private.ifp_resource.start) + return; + ++ if (IS_SNB) ++ return; ++ + /* setup a resource for this object */ + intel_private.ifp_resource.name = "Intel Flush Page"; + intel_private.ifp_resource.flags = IORESOURCE_MEM; +@@ -1353,6 +1454,8 @@ static unsigned long intel_i965_mask_memory(struct agp_bridge_data *bridge, + + static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size) + { ++ u16 snb_gmch_ctl; ++ + switch (agp_bridge->dev->device) { + case PCI_DEVICE_ID_INTEL_GM45_HB: + case PCI_DEVICE_ID_INTEL_EAGLELAKE_HB: +@@ -1366,6 +1469,25 @@ static void intel_i965_get_gtt_range(int *gtt_offset, int *gtt_size) + case PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB: + *gtt_offset = *gtt_size = MB(2); + break; ++ case PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB: ++ case PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB: ++ *gtt_offset = MB(2); ++ ++ pci_read_config_word(intel_private.pcidev, SNB_GMCH_CTRL, &snb_gmch_ctl); ++ switch (snb_gmch_ctl & SNB_GTT_SIZE_MASK) { ++ default: ++ case SNB_GTT_SIZE_0M: ++ printk(KERN_ERR "Bad GTT size mask: 0x%04x.\n", snb_gmch_ctl); ++ *gtt_size = MB(0); ++ break; ++ case SNB_GTT_SIZE_1M: ++ *gtt_size = MB(1); ++ break; ++ case SNB_GTT_SIZE_2M: ++ *gtt_size = MB(2); ++ break; ++ } ++ break; + default: + *gtt_offset = *gtt_size = KB(512); + } +@@ -1701,8 +1823,6 @@ static int intel_845_configure(void) + pci_write_config_byte(agp_bridge->dev, INTEL_I845_AGPM, temp2 | (1 << 1)); + /* clear any possible error conditions */ + pci_write_config_word(agp_bridge->dev, INTEL_I845_ERRSTS, 0x001c); +- +- intel_i830_setup_flush(); + return 0; + } + +@@ -2072,7 +2192,6 @@ static const struct agp_bridge_driver intel_845_driver = { + .agp_destroy_page = agp_generic_destroy_page, + .agp_destroy_pages = agp_generic_destroy_pages, + .agp_type_to_mask_type = agp_generic_type_to_mask_type, +- .chipset_flush = intel_i830_chipset_flush, + }; + + static const struct agp_bridge_driver intel_850_driver = { +@@ -2345,9 +2464,9 @@ static const struct intel_driver_description { + NULL, &intel_g33_driver }, + { PCI_DEVICE_ID_INTEL_Q33_HB, PCI_DEVICE_ID_INTEL_Q33_IG, 0, "Q33", + NULL, &intel_g33_driver }, +- { PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, 0, "Pineview", ++ { PCI_DEVICE_ID_INTEL_PINEVIEW_M_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_M_IG, 0, "GMA3150", + NULL, &intel_g33_driver }, +- { PCI_DEVICE_ID_INTEL_PINEVIEW_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_IG, 0, "Pineview", ++ { PCI_DEVICE_ID_INTEL_PINEVIEW_HB, PCI_DEVICE_ID_INTEL_PINEVIEW_IG, 0, "GMA3150", + NULL, &intel_g33_driver }, + { PCI_DEVICE_ID_INTEL_GM45_HB, PCI_DEVICE_ID_INTEL_GM45_IG, 0, + "GM45", NULL, &intel_i965_driver }, +@@ -2362,13 +2481,17 @@ static const struct intel_driver_description { + { PCI_DEVICE_ID_INTEL_G41_HB, PCI_DEVICE_ID_INTEL_G41_IG, 0, + "G41", NULL, &intel_i965_driver }, + { PCI_DEVICE_ID_INTEL_IRONLAKE_D_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_D_IG, 0, +- "Ironlake/D", NULL, &intel_i965_driver }, ++ "HD Graphics", NULL, &intel_i965_driver }, + { PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0, +- "Ironlake/M", NULL, &intel_i965_driver }, ++ "HD Graphics", NULL, &intel_i965_driver }, + { PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0, +- "Ironlake/MA", NULL, &intel_i965_driver }, ++ "HD Graphics", NULL, &intel_i965_driver }, + { PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB, PCI_DEVICE_ID_INTEL_IRONLAKE_M_IG, 0, +- "Ironlake/MC2", NULL, &intel_i965_driver }, ++ "HD Graphics", NULL, &intel_i965_driver }, ++ { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB, PCI_DEVICE_ID_INTEL_SANDYBRIDGE_IG, 0, ++ "Sandybridge", NULL, &intel_i965_driver }, ++ { PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB, PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_IG, 0, ++ "Sandybridge", NULL, &intel_i965_driver }, + { 0, 0, 0, NULL, NULL, NULL } + }; + +@@ -2378,7 +2501,7 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev, + struct agp_bridge_data *bridge; + u8 cap_ptr = 0; + struct resource *r; +- int i; ++ int i, err; + + cap_ptr = pci_find_capability(pdev, PCI_CAP_ID_AGP); + +@@ -2470,7 +2593,10 @@ static int __devinit agp_intel_probe(struct pci_dev *pdev, + } + + pci_set_drvdata(pdev, bridge); +- return agp_add_bridge(bridge); ++ err = agp_add_bridge(bridge); ++ if (!err) ++ intel_agp_enabled = 1; ++ return err; + } + + static void __devexit agp_intel_remove(struct pci_dev *pdev) +@@ -2575,6 +2701,8 @@ static struct pci_device_id agp_intel_pci_table[] = { + ID(PCI_DEVICE_ID_INTEL_IRONLAKE_M_HB), + ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MA_HB), + ID(PCI_DEVICE_ID_INTEL_IRONLAKE_MC2_HB), ++ ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_HB), ++ ID(PCI_DEVICE_ID_INTEL_SANDYBRIDGE_M_HB), + { } + }; + +diff --git a/drivers/gpu/drm/i915/dvo.h b/drivers/gpu/drm/i915/dvo.h +--- a/drivers/gpu/drm/i915/dvo.h ++++ b/drivers/gpu/drm/i915/dvo.h +@@ -70,16 +70,6 @@ struct intel_dvo_dev_ops { + void (*dpms)(struct intel_dvo_device *dvo, int mode); + + /* +- * Saves the output's state for restoration on VT switch. +- */ +- void (*save)(struct intel_dvo_device *dvo); +- +- /* +- * Restore's the output's state at VT switch. +- */ +- void (*restore)(struct intel_dvo_device *dvo); +- +- /* + * Callback for testing a video mode for a given output. + * + * This function should only check for cases where a mode can't +diff --git a/drivers/gpu/drm/i915/dvo_ch7017.c b/drivers/gpu/drm/i915/dvo_ch7017.c +--- a/drivers/gpu/drm/i915/dvo_ch7017.c ++++ b/drivers/gpu/drm/i915/dvo_ch7017.c +@@ -159,16 +159,7 @@ + #define CH7017_BANG_LIMIT_CONTROL 0x7f + + struct ch7017_priv { +- uint8_t save_hapi; +- uint8_t save_vali; +- uint8_t save_valo; +- uint8_t save_ailo; +- uint8_t save_lvds_pll_vco; +- uint8_t save_feedback_div; +- uint8_t save_lvds_control_2; +- uint8_t save_outputs_enable; +- uint8_t save_lvds_power_down; +- uint8_t save_power_management; ++ uint8_t dummy; + }; + + static void ch7017_dump_regs(struct intel_dvo_device *dvo); +@@ -401,39 +392,6 @@ do { \ + DUMP(CH7017_LVDS_POWER_DOWN); + } + +-static void ch7017_save(struct intel_dvo_device *dvo) +-{ +- struct ch7017_priv *priv = dvo->dev_priv; +- +- ch7017_read(dvo, CH7017_HORIZONTAL_ACTIVE_PIXEL_INPUT, &priv->save_hapi); +- ch7017_read(dvo, CH7017_VERTICAL_ACTIVE_LINE_OUTPUT, &priv->save_valo); +- ch7017_read(dvo, CH7017_ACTIVE_INPUT_LINE_OUTPUT, &priv->save_ailo); +- ch7017_read(dvo, CH7017_LVDS_PLL_VCO_CONTROL, &priv->save_lvds_pll_vco); +- ch7017_read(dvo, CH7017_LVDS_PLL_FEEDBACK_DIV, &priv->save_feedback_div); +- ch7017_read(dvo, CH7017_LVDS_CONTROL_2, &priv->save_lvds_control_2); +- ch7017_read(dvo, CH7017_OUTPUTS_ENABLE, &priv->save_outputs_enable); +- ch7017_read(dvo, CH7017_LVDS_POWER_DOWN, &priv->save_lvds_power_down); +- ch7017_read(dvo, CH7017_POWER_MANAGEMENT, &priv->save_power_management); +-} +- +-static void ch7017_restore(struct intel_dvo_device *dvo) +-{ +- struct ch7017_priv *priv = dvo->dev_priv; +- +- /* Power down before changing mode */ +- ch7017_dpms(dvo, DRM_MODE_DPMS_OFF); +- +- ch7017_write(dvo, CH7017_HORIZONTAL_ACTIVE_PIXEL_INPUT, priv->save_hapi); +- ch7017_write(dvo, CH7017_VERTICAL_ACTIVE_LINE_OUTPUT, priv->save_valo); +- ch7017_write(dvo, CH7017_ACTIVE_INPUT_LINE_OUTPUT, priv->save_ailo); +- ch7017_write(dvo, CH7017_LVDS_PLL_VCO_CONTROL, priv->save_lvds_pll_vco); +- ch7017_write(dvo, CH7017_LVDS_PLL_FEEDBACK_DIV, priv->save_feedback_div); +- ch7017_write(dvo, CH7017_LVDS_CONTROL_2, priv->save_lvds_control_2); +- ch7017_write(dvo, CH7017_OUTPUTS_ENABLE, priv->save_outputs_enable); +- ch7017_write(dvo, CH7017_LVDS_POWER_DOWN, priv->save_lvds_power_down); +- ch7017_write(dvo, CH7017_POWER_MANAGEMENT, priv->save_power_management); +-} +- + static void ch7017_destroy(struct intel_dvo_device *dvo) + { + struct ch7017_priv *priv = dvo->dev_priv; +@@ -451,7 +409,5 @@ struct intel_dvo_dev_ops ch7017_ops = { + .mode_set = ch7017_mode_set, + .dpms = ch7017_dpms, + .dump_regs = ch7017_dump_regs, +- .save = ch7017_save, +- .restore = ch7017_restore, + .destroy = ch7017_destroy, + }; +diff --git a/drivers/gpu/drm/i915/dvo_ch7xxx.c b/drivers/gpu/drm/i915/dvo_ch7xxx.c +--- a/drivers/gpu/drm/i915/dvo_ch7xxx.c ++++ b/drivers/gpu/drm/i915/dvo_ch7xxx.c +@@ -92,21 +92,10 @@ static struct ch7xxx_id_struct { + { CH7301_VID, "CH7301" }, + }; + +-struct ch7xxx_reg_state { +- uint8_t regs[CH7xxx_NUM_REGS]; +-}; +- + struct ch7xxx_priv { + bool quiet; +- +- struct ch7xxx_reg_state save_reg; +- struct ch7xxx_reg_state mode_reg; +- uint8_t save_TCTL, save_TPCP, save_TPD, save_TPVT; +- uint8_t save_TLPF, save_TCT, save_PM, save_IDF; + }; + +-static void ch7xxx_save(struct intel_dvo_device *dvo); +- + static char *ch7xxx_get_id(uint8_t vid) + { + int i; +@@ -312,42 +301,17 @@ static void ch7xxx_dpms(struct intel_dvo_device *dvo, int mode) + + static void ch7xxx_dump_regs(struct intel_dvo_device *dvo) + { +- struct ch7xxx_priv *ch7xxx = dvo->dev_priv; + int i; + + for (i = 0; i < CH7xxx_NUM_REGS; i++) { ++ uint8_t val; + if ((i % 8) == 0 ) + DRM_LOG_KMS("\n %02X: ", i); +- DRM_LOG_KMS("%02X ", ch7xxx->mode_reg.regs[i]); ++ ch7xxx_readb(dvo, i, &val); ++ DRM_LOG_KMS("%02X ", val); + } + } + +-static void ch7xxx_save(struct intel_dvo_device *dvo) +-{ +- struct ch7xxx_priv *ch7xxx= dvo->dev_priv; +- +- ch7xxx_readb(dvo, CH7xxx_TCTL, &ch7xxx->save_TCTL); +- ch7xxx_readb(dvo, CH7xxx_TPCP, &ch7xxx->save_TPCP); +- ch7xxx_readb(dvo, CH7xxx_TPD, &ch7xxx->save_TPD); +- ch7xxx_readb(dvo, CH7xxx_TPVT, &ch7xxx->save_TPVT); +- ch7xxx_readb(dvo, CH7xxx_TLPF, &ch7xxx->save_TLPF); +- ch7xxx_readb(dvo, CH7xxx_PM, &ch7xxx->save_PM); +- ch7xxx_readb(dvo, CH7xxx_IDF, &ch7xxx->save_IDF); +-} +- +-static void ch7xxx_restore(struct intel_dvo_device *dvo) +-{ +- struct ch7xxx_priv *ch7xxx = dvo->dev_priv; +- +- ch7xxx_writeb(dvo, CH7xxx_TCTL, ch7xxx->save_TCTL); +- ch7xxx_writeb(dvo, CH7xxx_TPCP, ch7xxx->save_TPCP); +- ch7xxx_writeb(dvo, CH7xxx_TPD, ch7xxx->save_TPD); +- ch7xxx_writeb(dvo, CH7xxx_TPVT, ch7xxx->save_TPVT); +- ch7xxx_writeb(dvo, CH7xxx_TLPF, ch7xxx->save_TLPF); +- ch7xxx_writeb(dvo, CH7xxx_IDF, ch7xxx->save_IDF); +- ch7xxx_writeb(dvo, CH7xxx_PM, ch7xxx->save_PM); +-} +- + static void ch7xxx_destroy(struct intel_dvo_device *dvo) + { + struct ch7xxx_priv *ch7xxx = dvo->dev_priv; +@@ -365,7 +329,5 @@ struct intel_dvo_dev_ops ch7xxx_ops = { + .mode_set = ch7xxx_mode_set, + .dpms = ch7xxx_dpms, + .dump_regs = ch7xxx_dump_regs, +- .save = ch7xxx_save, +- .restore = ch7xxx_restore, + .destroy = ch7xxx_destroy, + }; +diff --git a/drivers/gpu/drm/i915/dvo_ivch.c b/drivers/gpu/drm/i915/dvo_ivch.c +--- a/drivers/gpu/drm/i915/dvo_ivch.c ++++ b/drivers/gpu/drm/i915/dvo_ivch.c +@@ -153,9 +153,6 @@ struct ivch_priv { + bool quiet; + + uint16_t width, height; +- +- uint16_t save_VR01; +- uint16_t save_VR40; + }; + + +@@ -405,22 +402,6 @@ static void ivch_dump_regs(struct intel_dvo_device *dvo) + DRM_LOG_KMS("VR8F: 0x%04x\n", val); + } + +-static void ivch_save(struct intel_dvo_device *dvo) +-{ +- struct ivch_priv *priv = dvo->dev_priv; +- +- ivch_read(dvo, VR01, &priv->save_VR01); +- ivch_read(dvo, VR40, &priv->save_VR40); +-} +- +-static void ivch_restore(struct intel_dvo_device *dvo) +-{ +- struct ivch_priv *priv = dvo->dev_priv; +- +- ivch_write(dvo, VR01, priv->save_VR01); +- ivch_write(dvo, VR40, priv->save_VR40); +-} +- + static void ivch_destroy(struct intel_dvo_device *dvo) + { + struct ivch_priv *priv = dvo->dev_priv; +@@ -434,8 +415,6 @@ static void ivch_destroy(struct intel_dvo_device *dvo) + struct intel_dvo_dev_ops ivch_ops= { + .init = ivch_init, + .dpms = ivch_dpms, +- .save = ivch_save, +- .restore = ivch_restore, + .mode_valid = ivch_mode_valid, + .mode_set = ivch_mode_set, + .detect = ivch_detect, +diff --git a/drivers/gpu/drm/i915/dvo_sil164.c b/drivers/gpu/drm/i915/dvo_sil164.c +--- a/drivers/gpu/drm/i915/dvo_sil164.c ++++ b/drivers/gpu/drm/i915/dvo_sil164.c +@@ -58,17 +58,9 @@ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. + + #define SIL164_REGC 0x0c + +-struct sil164_save_rec { +- uint8_t reg8; +- uint8_t reg9; +- uint8_t regc; +-}; +- + struct sil164_priv { + //I2CDevRec d; + bool quiet; +- struct sil164_save_rec save_regs; +- struct sil164_save_rec mode_regs; + }; + + #define SILPTR(d) ((SIL164Ptr)(d->DriverPrivate.ptr)) +@@ -252,34 +244,6 @@ static void sil164_dump_regs(struct intel_dvo_device *dvo) + DRM_LOG_KMS("SIL164_REGC: 0x%02x\n", val); + } + +-static void sil164_save(struct intel_dvo_device *dvo) +-{ +- struct sil164_priv *sil= dvo->dev_priv; +- +- if (!sil164_readb(dvo, SIL164_REG8, &sil->save_regs.reg8)) +- return; +- +- if (!sil164_readb(dvo, SIL164_REG9, &sil->save_regs.reg9)) +- return; +- +- if (!sil164_readb(dvo, SIL164_REGC, &sil->save_regs.regc)) +- return; +- +- return; +-} +- +-static void sil164_restore(struct intel_dvo_device *dvo) +-{ +- struct sil164_priv *sil = dvo->dev_priv; +- +- /* Restore it powered down initially */ +- sil164_writeb(dvo, SIL164_REG8, sil->save_regs.reg8 & ~0x1); +- +- sil164_writeb(dvo, SIL164_REG9, sil->save_regs.reg9); +- sil164_writeb(dvo, SIL164_REGC, sil->save_regs.regc); +- sil164_writeb(dvo, SIL164_REG8, sil->save_regs.reg8); +-} +- + static void sil164_destroy(struct intel_dvo_device *dvo) + { + struct sil164_priv *sil = dvo->dev_priv; +@@ -297,7 +261,5 @@ struct intel_dvo_dev_ops sil164_ops = { + .mode_set = sil164_mode_set, + .dpms = sil164_dpms, + .dump_regs = sil164_dump_regs, +- .save = sil164_save, +- .restore = sil164_restore, + .destroy = sil164_destroy, + }; +diff --git a/drivers/gpu/drm/i915/dvo_tfp410.c b/drivers/gpu/drm/i915/dvo_tfp410.c +--- a/drivers/gpu/drm/i915/dvo_tfp410.c ++++ b/drivers/gpu/drm/i915/dvo_tfp410.c +@@ -86,16 +86,8 @@ + #define TFP410_V_RES_LO 0x3C + #define TFP410_V_RES_HI 0x3D + +-struct tfp410_save_rec { +- uint8_t ctl1; +- uint8_t ctl2; +-}; +- + struct tfp410_priv { + bool quiet; +- +- struct tfp410_save_rec saved_reg; +- struct tfp410_save_rec mode_reg; + }; + + static bool tfp410_readb(struct intel_dvo_device *dvo, int addr, uint8_t *ch) +@@ -293,28 +285,6 @@ static void tfp410_dump_regs(struct intel_dvo_device *dvo) + DRM_LOG_KMS("TFP410_V_RES: 0x%02X%02X\n", val2, val); + } + +-static void tfp410_save(struct intel_dvo_device *dvo) +-{ +- struct tfp410_priv *tfp = dvo->dev_priv; +- +- if (!tfp410_readb(dvo, TFP410_CTL_1, &tfp->saved_reg.ctl1)) +- return; +- +- if (!tfp410_readb(dvo, TFP410_CTL_2, &tfp->saved_reg.ctl2)) +- return; +-} +- +-static void tfp410_restore(struct intel_dvo_device *dvo) +-{ +- struct tfp410_priv *tfp = dvo->dev_priv; +- +- /* Restore it powered down initially */ +- tfp410_writeb(dvo, TFP410_CTL_1, tfp->saved_reg.ctl1 & ~0x1); +- +- tfp410_writeb(dvo, TFP410_CTL_2, tfp->saved_reg.ctl2); +- tfp410_writeb(dvo, TFP410_CTL_1, tfp->saved_reg.ctl1); +-} +- + static void tfp410_destroy(struct intel_dvo_device *dvo) + { + struct tfp410_priv *tfp = dvo->dev_priv; +@@ -332,7 +302,5 @@ struct intel_dvo_dev_ops tfp410_ops = { + .mode_set = tfp410_mode_set, + .dpms = tfp410_dpms, + .dump_regs = tfp410_dump_regs, +- .save = tfp410_save, +- .restore = tfp410_restore, + .destroy = tfp410_destroy, + }; +diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c +--- a/drivers/gpu/drm/i915/i915_debugfs.c ++++ b/drivers/gpu/drm/i915/i915_debugfs.c +@@ -162,7 +162,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data) + struct drm_device *dev = node->minor->dev; + drm_i915_private_t *dev_priv = dev->dev_private; + +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + seq_printf(m, "Interrupt enable: %08x\n", + I915_READ(IER)); + seq_printf(m, "Interrupt identity: %08x\n", +@@ -225,7 +225,7 @@ static int i915_gem_fence_regs_info(struct seq_file *m, void *data) + } else { + struct drm_i915_gem_object *obj_priv; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + seq_printf(m, "Fenced object[%2d] = %p: %s " + "%08x %08zx %08x %s %08x %08x %d", + i, obj, get_pin_flag(obj_priv), +@@ -350,6 +350,36 @@ static int i915_ringbuffer_info(struct seq_file *m, void *data) + return 0; + } + ++static const char *pin_flag(int pinned) ++{ ++ if (pinned > 0) ++ return " P"; ++ else if (pinned < 0) ++ return " p"; ++ else ++ return ""; ++} ++ ++static const char *tiling_flag(int tiling) ++{ ++ switch (tiling) { ++ default: ++ case I915_TILING_NONE: return ""; ++ case I915_TILING_X: return " X"; ++ case I915_TILING_Y: return " Y"; ++ } ++} ++ ++static const char *dirty_flag(int dirty) ++{ ++ return dirty ? " dirty" : ""; ++} ++ ++static const char *purgeable_flag(int purgeable) ++{ ++ return purgeable ? " purgeable" : ""; ++} ++ + static int i915_error_state(struct seq_file *m, void *unused) + { + struct drm_info_node *node = (struct drm_info_node *) m->private; +@@ -357,6 +387,7 @@ static int i915_error_state(struct seq_file *m, void *unused) + drm_i915_private_t *dev_priv = dev->dev_private; + struct drm_i915_error_state *error; + unsigned long flags; ++ int i, page, offset, elt; + + spin_lock_irqsave(&dev_priv->error_lock, flags); + if (!dev_priv->first_error) { +@@ -368,6 +399,7 @@ static int i915_error_state(struct seq_file *m, void *unused) + + seq_printf(m, "Time: %ld s %ld us\n", error->time.tv_sec, + error->time.tv_usec); ++ seq_printf(m, "PCI ID: 0x%04x\n", dev->pci_device); + seq_printf(m, "EIR: 0x%08x\n", error->eir); + seq_printf(m, " PGTBL_ER: 0x%08x\n", error->pgtbl_er); + seq_printf(m, " INSTPM: 0x%08x\n", error->instpm); +@@ -379,6 +411,59 @@ static int i915_error_state(struct seq_file *m, void *unused) + seq_printf(m, " INSTPS: 0x%08x\n", error->instps); + seq_printf(m, " INSTDONE1: 0x%08x\n", error->instdone1); + } ++ seq_printf(m, "seqno: 0x%08x\n", error->seqno); ++ ++ if (error->active_bo_count) { ++ seq_printf(m, "Buffers [%d]:\n", error->active_bo_count); ++ ++ for (i = 0; i < error->active_bo_count; i++) { ++ seq_printf(m, " %08x %8zd %08x %08x %08x%s%s%s%s", ++ error->active_bo[i].gtt_offset, ++ error->active_bo[i].size, ++ error->active_bo[i].read_domains, ++ error->active_bo[i].write_domain, ++ error->active_bo[i].seqno, ++ pin_flag(error->active_bo[i].pinned), ++ tiling_flag(error->active_bo[i].tiling), ++ dirty_flag(error->active_bo[i].dirty), ++ purgeable_flag(error->active_bo[i].purgeable)); ++ ++ if (error->active_bo[i].name) ++ seq_printf(m, " (name: %d)", error->active_bo[i].name); ++ if (error->active_bo[i].fence_reg != I915_FENCE_REG_NONE) ++ seq_printf(m, " (fence: %d)", error->active_bo[i].fence_reg); ++ ++ seq_printf(m, "\n"); ++ } ++ } ++ ++ for (i = 0; i < ARRAY_SIZE(error->batchbuffer); i++) { ++ if (error->batchbuffer[i]) { ++ struct drm_i915_error_object *obj = error->batchbuffer[i]; ++ ++ seq_printf(m, "--- gtt_offset = 0x%08x\n", obj->gtt_offset); ++ offset = 0; ++ for (page = 0; page < obj->page_count; page++) { ++ for (elt = 0; elt < PAGE_SIZE/4; elt++) { ++ seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]); ++ offset += 4; ++ } ++ } ++ } ++ } ++ ++ if (error->ringbuffer) { ++ struct drm_i915_error_object *obj = error->ringbuffer; ++ ++ seq_printf(m, "--- ringbuffer = 0x%08x\n", obj->gtt_offset); ++ offset = 0; ++ for (page = 0; page < obj->page_count; page++) { ++ for (elt = 0; elt < PAGE_SIZE/4; elt++) { ++ seq_printf(m, "%08x : %08x\n", offset, obj->pages[page][elt]); ++ offset += 4; ++ } ++ } ++ } + + out: + spin_unlock_irqrestore(&dev_priv->error_lock, flags); +@@ -386,6 +471,165 @@ out: + return 0; + } + ++static int i915_rstdby_delays(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ u16 crstanddelay = I915_READ16(CRSTANDVID); ++ ++ seq_printf(m, "w/ctx: %d, w/o ctx: %d\n", (crstanddelay >> 8) & 0x3f, (crstanddelay & 0x3f)); ++ ++ return 0; ++} ++ ++static int i915_cur_delayinfo(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ u16 rgvswctl = I915_READ16(MEMSWCTL); ++ ++ seq_printf(m, "Last command: 0x%01x\n", (rgvswctl >> 13) & 0x3); ++ seq_printf(m, "Command status: %d\n", (rgvswctl >> 12) & 1); ++ seq_printf(m, "P%d DELAY 0x%02x\n", (rgvswctl >> 8) & 0xf, ++ rgvswctl & 0x3f); ++ ++ return 0; ++} ++ ++static int i915_delayfreq_table(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ u32 delayfreq; ++ int i; ++ ++ for (i = 0; i < 16; i++) { ++ delayfreq = I915_READ(PXVFREQ_BASE + i * 4); ++ seq_printf(m, "P%02dVIDFREQ: 0x%08x\n", i, delayfreq); ++ } ++ ++ return 0; ++} ++ ++static inline int MAP_TO_MV(int map) ++{ ++ return 1250 - (map * 25); ++} ++ ++static int i915_inttoext_table(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ u32 inttoext; ++ int i; ++ ++ for (i = 1; i <= 32; i++) { ++ inttoext = I915_READ(INTTOEXT_BASE_ILK + i * 4); ++ seq_printf(m, "INTTOEXT%02d: 0x%08x\n", i, inttoext); ++ } ++ ++ return 0; ++} ++ ++static int i915_drpc_info(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ u32 rgvmodectl = I915_READ(MEMMODECTL); ++ ++ seq_printf(m, "HD boost: %s\n", (rgvmodectl & MEMMODE_BOOST_EN) ? ++ "yes" : "no"); ++ seq_printf(m, "Boost freq: %d\n", ++ (rgvmodectl & MEMMODE_BOOST_FREQ_MASK) >> ++ MEMMODE_BOOST_FREQ_SHIFT); ++ seq_printf(m, "HW control enabled: %s\n", ++ rgvmodectl & MEMMODE_HWIDLE_EN ? "yes" : "no"); ++ seq_printf(m, "SW control enabled: %s\n", ++ rgvmodectl & MEMMODE_SWMODE_EN ? "yes" : "no"); ++ seq_printf(m, "Gated voltage change: %s\n", ++ rgvmodectl & MEMMODE_RCLK_GATE ? "yes" : "no"); ++ seq_printf(m, "Starting frequency: P%d\n", ++ (rgvmodectl & MEMMODE_FSTART_MASK) >> MEMMODE_FSTART_SHIFT); ++ seq_printf(m, "Max frequency: P%d\n", ++ (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT); ++ seq_printf(m, "Min frequency: P%d\n", (rgvmodectl & MEMMODE_FMIN_MASK)); ++ ++ return 0; ++} ++ ++static int i915_fbc_status(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ struct drm_crtc *crtc; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ bool fbc_enabled = false; ++ ++ if (!dev_priv->display.fbc_enabled) { ++ seq_printf(m, "FBC unsupported on this chipset\n"); ++ return 0; ++ } ++ ++ list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { ++ if (!crtc->enabled) ++ continue; ++ if (dev_priv->display.fbc_enabled(crtc)) ++ fbc_enabled = true; ++ } ++ ++ if (fbc_enabled) { ++ seq_printf(m, "FBC enabled\n"); ++ } else { ++ seq_printf(m, "FBC disabled: "); ++ switch (dev_priv->no_fbc_reason) { ++ case FBC_STOLEN_TOO_SMALL: ++ seq_printf(m, "not enough stolen memory"); ++ break; ++ case FBC_UNSUPPORTED_MODE: ++ seq_printf(m, "mode not supported"); ++ break; ++ case FBC_MODE_TOO_LARGE: ++ seq_printf(m, "mode too large"); ++ break; ++ case FBC_BAD_PLANE: ++ seq_printf(m, "FBC unsupported on plane"); ++ break; ++ case FBC_NOT_TILED: ++ seq_printf(m, "scanout buffer not tiled"); ++ break; ++ default: ++ seq_printf(m, "unknown reason"); ++ } ++ seq_printf(m, "\n"); ++ } ++ return 0; ++} ++ ++static int i915_sr_status(struct seq_file *m, void *unused) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_device *dev = node->minor->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ bool sr_enabled = false; ++ ++ if (IS_I965G(dev) || IS_I945G(dev) || IS_I945GM(dev)) ++ sr_enabled = I915_READ(FW_BLC_SELF) & FW_BLC_SELF_EN; ++ else if (IS_I915GM(dev)) ++ sr_enabled = I915_READ(INSTPM) & INSTPM_SELF_EN; ++ else if (IS_PINEVIEW(dev)) ++ sr_enabled = I915_READ(DSPFW3) & PINEVIEW_SELF_REFRESH_EN; ++ ++ seq_printf(m, "self-refresh: %s\n", sr_enabled ? "enabled" : ++ "disabled"); ++ ++ return 0; ++} ++ + static int + i915_wedged_open(struct inode *inode, + struct file *filp) +@@ -503,6 +747,13 @@ static struct drm_info_list i915_debugfs_list[] = { + {"i915_ringbuffer_info", i915_ringbuffer_info, 0}, + {"i915_batchbuffers", i915_batchbuffer_info, 0}, + {"i915_error_state", i915_error_state, 0}, ++ {"i915_rstdby_delays", i915_rstdby_delays, 0}, ++ {"i915_cur_delayinfo", i915_cur_delayinfo, 0}, ++ {"i915_delayfreq_table", i915_delayfreq_table, 0}, ++ {"i915_inttoext_table", i915_inttoext_table, 0}, ++ {"i915_drpc_info", i915_drpc_info, 0}, ++ {"i915_fbc_status", i915_fbc_status, 0}, ++ {"i915_sr_status", i915_sr_status, 0}, + }; + #define I915_DEBUGFS_ENTRIES ARRAY_SIZE(i915_debugfs_list) + +diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c +--- a/drivers/gpu/drm/i915/i915_dma.c ++++ b/drivers/gpu/drm/i915/i915_dma.c +@@ -35,6 +35,8 @@ + #include "i915_drv.h" + #include "i915_trace.h" + #include ++#include ++#include + + /* Really want an OS-independent resettable timer. Would like to have + * this loop run for (eg) 3 sec, but have the timer reset every time +@@ -933,6 +935,120 @@ static int i915_get_bridge_dev(struct drm_device *dev) + return 0; + } + ++#define MCHBAR_I915 0x44 ++#define MCHBAR_I965 0x48 ++#define MCHBAR_SIZE (4*4096) ++ ++#define DEVEN_REG 0x54 ++#define DEVEN_MCHBAR_EN (1 << 28) ++ ++/* Allocate space for the MCH regs if needed, return nonzero on error */ ++static int ++intel_alloc_mchbar_resource(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ int reg = IS_I965G(dev) ? MCHBAR_I965 : MCHBAR_I915; ++ u32 temp_lo, temp_hi = 0; ++ u64 mchbar_addr; ++ int ret = 0; ++ ++ if (IS_I965G(dev)) ++ pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi); ++ pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo); ++ mchbar_addr = ((u64)temp_hi << 32) | temp_lo; ++ ++ /* If ACPI doesn't have it, assume we need to allocate it ourselves */ ++#ifdef CONFIG_PNP ++ if (mchbar_addr && ++ pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) { ++ ret = 0; ++ goto out; ++ } ++#endif ++ ++ /* Get some space for it */ ++ ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus, &dev_priv->mch_res, ++ MCHBAR_SIZE, MCHBAR_SIZE, ++ PCIBIOS_MIN_MEM, ++ 0, pcibios_align_resource, ++ dev_priv->bridge_dev); ++ if (ret) { ++ DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret); ++ dev_priv->mch_res.start = 0; ++ goto out; ++ } ++ ++ if (IS_I965G(dev)) ++ pci_write_config_dword(dev_priv->bridge_dev, reg + 4, ++ upper_32_bits(dev_priv->mch_res.start)); ++ ++ pci_write_config_dword(dev_priv->bridge_dev, reg, ++ lower_32_bits(dev_priv->mch_res.start)); ++out: ++ return ret; ++} ++ ++/* Setup MCHBAR if possible, return true if we should disable it again */ ++static void ++intel_setup_mchbar(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ int mchbar_reg = IS_I965G(dev) ? MCHBAR_I965 : MCHBAR_I915; ++ u32 temp; ++ bool enabled; ++ ++ dev_priv->mchbar_need_disable = false; ++ ++ if (IS_I915G(dev) || IS_I915GM(dev)) { ++ pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); ++ enabled = !!(temp & DEVEN_MCHBAR_EN); ++ } else { ++ pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); ++ enabled = temp & 1; ++ } ++ ++ /* If it's already enabled, don't have to do anything */ ++ if (enabled) ++ return; ++ ++ if (intel_alloc_mchbar_resource(dev)) ++ return; ++ ++ dev_priv->mchbar_need_disable = true; ++ ++ /* Space is allocated or reserved, so enable it. */ ++ if (IS_I915G(dev) || IS_I915GM(dev)) { ++ pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, ++ temp | DEVEN_MCHBAR_EN); ++ } else { ++ pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); ++ pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1); ++ } ++} ++ ++static void ++intel_teardown_mchbar(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ int mchbar_reg = IS_I965G(dev) ? MCHBAR_I965 : MCHBAR_I915; ++ u32 temp; ++ ++ if (dev_priv->mchbar_need_disable) { ++ if (IS_I915G(dev) || IS_I915GM(dev)) { ++ pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); ++ temp &= ~DEVEN_MCHBAR_EN; ++ pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp); ++ } else { ++ pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); ++ temp &= ~1; ++ pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp); ++ } ++ } ++ ++ if (dev_priv->mch_res.start) ++ release_resource(&dev_priv->mch_res); ++} ++ + /** + * i915_probe_agp - get AGP bootup configuration + * @pdev: PCI device +@@ -978,59 +1094,123 @@ static int i915_probe_agp(struct drm_device *dev, uint32_t *aperture_size, + * Some of the preallocated space is taken by the GTT + * and popup. GTT is 1K per MB of aperture size, and popup is 4K. + */ +- if (IS_G4X(dev) || IS_PINEVIEW(dev) || IS_IRONLAKE(dev)) ++ if (IS_G4X(dev) || IS_PINEVIEW(dev) || IS_IRONLAKE(dev) || IS_GEN6(dev)) + overhead = 4096; + else + overhead = (*aperture_size / 1024) + 4096; + +- switch (tmp & INTEL_GMCH_GMS_MASK) { +- case INTEL_855_GMCH_GMS_DISABLED: +- DRM_ERROR("video memory is disabled\n"); +- return -1; +- case INTEL_855_GMCH_GMS_STOLEN_1M: +- stolen = 1 * 1024 * 1024; +- break; +- case INTEL_855_GMCH_GMS_STOLEN_4M: +- stolen = 4 * 1024 * 1024; +- break; +- case INTEL_855_GMCH_GMS_STOLEN_8M: +- stolen = 8 * 1024 * 1024; +- break; +- case INTEL_855_GMCH_GMS_STOLEN_16M: +- stolen = 16 * 1024 * 1024; +- break; +- case INTEL_855_GMCH_GMS_STOLEN_32M: +- stolen = 32 * 1024 * 1024; +- break; +- case INTEL_915G_GMCH_GMS_STOLEN_48M: +- stolen = 48 * 1024 * 1024; +- break; +- case INTEL_915G_GMCH_GMS_STOLEN_64M: +- stolen = 64 * 1024 * 1024; +- break; +- case INTEL_GMCH_GMS_STOLEN_128M: +- stolen = 128 * 1024 * 1024; +- break; +- case INTEL_GMCH_GMS_STOLEN_256M: +- stolen = 256 * 1024 * 1024; +- break; +- case INTEL_GMCH_GMS_STOLEN_96M: +- stolen = 96 * 1024 * 1024; +- break; +- case INTEL_GMCH_GMS_STOLEN_160M: +- stolen = 160 * 1024 * 1024; +- break; +- case INTEL_GMCH_GMS_STOLEN_224M: +- stolen = 224 * 1024 * 1024; +- break; +- case INTEL_GMCH_GMS_STOLEN_352M: +- stolen = 352 * 1024 * 1024; +- break; +- default: +- DRM_ERROR("unexpected GMCH_GMS value: 0x%02x\n", +- tmp & INTEL_GMCH_GMS_MASK); +- return -1; ++ if (IS_GEN6(dev)) { ++ /* SNB has memory control reg at 0x50.w */ ++ pci_read_config_word(dev->pdev, SNB_GMCH_CTRL, &tmp); ++ ++ switch (tmp & SNB_GMCH_GMS_STOLEN_MASK) { ++ case INTEL_855_GMCH_GMS_DISABLED: ++ DRM_ERROR("video memory is disabled\n"); ++ return -1; ++ case SNB_GMCH_GMS_STOLEN_32M: ++ stolen = 32 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_64M: ++ stolen = 64 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_96M: ++ stolen = 96 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_128M: ++ stolen = 128 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_160M: ++ stolen = 160 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_192M: ++ stolen = 192 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_224M: ++ stolen = 224 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_256M: ++ stolen = 256 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_288M: ++ stolen = 288 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_320M: ++ stolen = 320 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_352M: ++ stolen = 352 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_384M: ++ stolen = 384 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_416M: ++ stolen = 416 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_448M: ++ stolen = 448 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_480M: ++ stolen = 480 * 1024 * 1024; ++ break; ++ case SNB_GMCH_GMS_STOLEN_512M: ++ stolen = 512 * 1024 * 1024; ++ break; ++ default: ++ DRM_ERROR("unexpected GMCH_GMS value: 0x%02x\n", ++ tmp & SNB_GMCH_GMS_STOLEN_MASK); ++ return -1; ++ } ++ } else { ++ switch (tmp & INTEL_GMCH_GMS_MASK) { ++ case INTEL_855_GMCH_GMS_DISABLED: ++ DRM_ERROR("video memory is disabled\n"); ++ return -1; ++ case INTEL_855_GMCH_GMS_STOLEN_1M: ++ stolen = 1 * 1024 * 1024; ++ break; ++ case INTEL_855_GMCH_GMS_STOLEN_4M: ++ stolen = 4 * 1024 * 1024; ++ break; ++ case INTEL_855_GMCH_GMS_STOLEN_8M: ++ stolen = 8 * 1024 * 1024; ++ break; ++ case INTEL_855_GMCH_GMS_STOLEN_16M: ++ stolen = 16 * 1024 * 1024; ++ break; ++ case INTEL_855_GMCH_GMS_STOLEN_32M: ++ stolen = 32 * 1024 * 1024; ++ break; ++ case INTEL_915G_GMCH_GMS_STOLEN_48M: ++ stolen = 48 * 1024 * 1024; ++ break; ++ case INTEL_915G_GMCH_GMS_STOLEN_64M: ++ stolen = 64 * 1024 * 1024; ++ break; ++ case INTEL_GMCH_GMS_STOLEN_128M: ++ stolen = 128 * 1024 * 1024; ++ break; ++ case INTEL_GMCH_GMS_STOLEN_256M: ++ stolen = 256 * 1024 * 1024; ++ break; ++ case INTEL_GMCH_GMS_STOLEN_96M: ++ stolen = 96 * 1024 * 1024; ++ break; ++ case INTEL_GMCH_GMS_STOLEN_160M: ++ stolen = 160 * 1024 * 1024; ++ break; ++ case INTEL_GMCH_GMS_STOLEN_224M: ++ stolen = 224 * 1024 * 1024; ++ break; ++ case INTEL_GMCH_GMS_STOLEN_352M: ++ stolen = 352 * 1024 * 1024; ++ break; ++ default: ++ DRM_ERROR("unexpected GMCH_GMS value: 0x%02x\n", ++ tmp & INTEL_GMCH_GMS_MASK); ++ return -1; ++ } + } ++ + *preallocated_size = stolen - overhead; + *start = overhead; + +@@ -1064,7 +1244,7 @@ static unsigned long i915_gtt_to_phys(struct drm_device *dev, + int gtt_offset, gtt_size; + + if (IS_I965G(dev)) { +- if (IS_G4X(dev) || IS_IRONLAKE(dev)) { ++ if (IS_G4X(dev) || IS_IRONLAKE(dev) || IS_GEN6(dev)) { + gtt_offset = 2*1024*1024; + gtt_size = 2*1024*1024; + } else { +@@ -1133,6 +1313,7 @@ static void i915_setup_compression(struct drm_device *dev, int size) + /* Leave 1M for line length buffer & misc. */ + compressed_fb = drm_mm_search_free(&dev_priv->vram, size, 4096, 0); + if (!compressed_fb) { ++ dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL; + i915_warn_stolen(dev); + return; + } +@@ -1140,6 +1321,7 @@ static void i915_setup_compression(struct drm_device *dev, int size) + compressed_fb = drm_mm_get_block(compressed_fb, size, 4096); + if (!compressed_fb) { + i915_warn_stolen(dev); ++ dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL; + return; + } + +@@ -1281,7 +1463,9 @@ static int i915_load_modeset_init(struct drm_device *dev, + return 0; + + destroy_ringbuffer: ++ mutex_lock(&dev->struct_mutex); + i915_gem_cleanup_ringbuffer(dev); ++ mutex_unlock(&dev->struct_mutex); + out: + return ret; + } +@@ -1361,7 +1545,7 @@ static void i915_get_mem_freq(struct drm_device *dev) + */ + int i915_driver_load(struct drm_device *dev, unsigned long flags) + { +- struct drm_i915_private *dev_priv = dev->dev_private; ++ struct drm_i915_private *dev_priv; + resource_size_t base, size; + int ret = 0, mmio_bar; + uint32_t agp_size, prealloc_size, prealloc_start; +@@ -1445,11 +1629,14 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) + + dev->driver->get_vblank_counter = i915_get_vblank_counter; + dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ +- if (IS_G4X(dev) || IS_IRONLAKE(dev)) { ++ if (IS_G4X(dev) || IS_IRONLAKE(dev) || IS_GEN6(dev)) { + dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ + dev->driver->get_vblank_counter = gm45_get_vblank_counter; + } + ++ /* Try to make sure MCHBAR is enabled before poking at it */ ++ intel_setup_mchbar(dev); ++ + i915_gem_load(dev); + + /* Init HWS */ +@@ -1490,6 +1677,8 @@ int i915_driver_load(struct drm_device *dev, unsigned long flags) + /* Start out suspended */ + dev_priv->mm.suspended = 1; + ++ intel_detect_pch(dev); ++ + if (drm_core_check_feature(dev, DRIVER_MODESET)) { + ret = i915_load_modeset_init(dev, prealloc_start, + prealloc_size, agp_size); +@@ -1523,6 +1712,8 @@ int i915_driver_unload(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; + ++ i915_destroy_error_state(dev); ++ + destroy_workqueue(dev_priv->wq); + del_timer_sync(&dev_priv->hangcheck_timer); + +@@ -1569,6 +1760,8 @@ int i915_driver_unload(struct drm_device *dev) + intel_cleanup_overlay(dev); + } + ++ intel_teardown_mchbar(dev); ++ + pci_dev_put(dev_priv->bridge_dev); + kfree(dev->dev_private); + +@@ -1655,29 +1848,29 @@ struct drm_ioctl_desc i915_ioctls[] = { + DRM_IOCTL_DEF(DRM_I915_GET_VBLANK_PIPE, i915_vblank_pipe_get, DRM_AUTH ), + DRM_IOCTL_DEF(DRM_I915_VBLANK_SWAP, i915_vblank_swap, DRM_AUTH), + DRM_IOCTL_DEF(DRM_I915_HWS_ADDR, i915_set_status_page, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), +- DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), +- DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), +- DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY), +- DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), +- DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), +- DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, 0), +- DRM_IOCTL_DEF(DRM_I915_GEM_MADVISE, i915_gem_madvise_ioctl, 0), +- DRM_IOCTL_DEF(DRM_I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW), +- DRM_IOCTL_DEF(DRM_I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW), ++ DRM_IOCTL_DEF(DRM_I915_GEM_INIT, i915_gem_init_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER, i915_gem_execbuffer, DRM_AUTH|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_EXECBUFFER2, i915_gem_execbuffer2, DRM_AUTH|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_PIN, i915_gem_pin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_UNPIN, i915_gem_unpin_ioctl, DRM_AUTH|DRM_ROOT_ONLY|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_BUSY, i915_gem_busy_ioctl, DRM_AUTH|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_THROTTLE, i915_gem_throttle_ioctl, DRM_AUTH|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_ENTERVT, i915_gem_entervt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_LEAVEVT, i915_gem_leavevt_ioctl, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_CREATE, i915_gem_create_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_PREAD, i915_gem_pread_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_PWRITE, i915_gem_pwrite_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_MMAP, i915_gem_mmap_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_MMAP_GTT, i915_gem_mmap_gtt_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_SET_DOMAIN, i915_gem_set_domain_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_SW_FINISH, i915_gem_sw_finish_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_SET_TILING, i915_gem_set_tiling, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_GET_TILING, i915_gem_get_tiling, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_GET_APERTURE, i915_gem_get_aperture_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GET_PIPE_FROM_CRTC_ID, intel_get_pipe_from_crtc_id, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_GEM_MADVISE, i915_gem_madvise_ioctl, DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_OVERLAY_PUT_IMAGE, intel_overlay_put_image, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), ++ DRM_IOCTL_DEF(DRM_I915_OVERLAY_ATTRS, intel_overlay_attrs, DRM_MASTER|DRM_CONTROL_ALLOW|DRM_UNLOCKED), + }; + + int i915_max_ioctl = DRM_ARRAY_SIZE(i915_ioctls); +diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c +--- a/drivers/gpu/drm/i915/i915_drv.c ++++ b/drivers/gpu/drm/i915/i915_drv.c +@@ -49,6 +49,7 @@ unsigned int i915_lvds_downclock = 0; + module_param_named(lvds_downclock, i915_lvds_downclock, int, 0400); + + static struct drm_driver driver; ++extern int intel_agp_enabled; + + #define INTEL_VGA_DEVICE(id, info) { \ + .class = PCI_CLASS_DISPLAY_VGA << 8, \ +@@ -68,7 +69,8 @@ const static struct intel_device_info intel_845g_info = { + }; + + const static struct intel_device_info intel_i85x_info = { +- .is_i8xx = 1, .is_mobile = 1, .cursor_needs_physical = 1, ++ .is_i8xx = 1, .is_i85x = 1, .is_mobile = 1, ++ .cursor_needs_physical = 1, + }; + + const static struct intel_device_info intel_i865g_info = { +@@ -79,14 +81,14 @@ const static struct intel_device_info intel_i915g_info = { + .is_i915g = 1, .is_i9xx = 1, .cursor_needs_physical = 1, + }; + const static struct intel_device_info intel_i915gm_info = { +- .is_i9xx = 1, .is_mobile = 1, .has_fbc = 1, ++ .is_i9xx = 1, .is_mobile = 1, + .cursor_needs_physical = 1, + }; + const static struct intel_device_info intel_i945g_info = { + .is_i9xx = 1, .has_hotplug = 1, .cursor_needs_physical = 1, + }; + const static struct intel_device_info intel_i945gm_info = { +- .is_i945gm = 1, .is_i9xx = 1, .is_mobile = 1, .has_fbc = 1, ++ .is_i945gm = 1, .is_i9xx = 1, .is_mobile = 1, + .has_hotplug = 1, .cursor_needs_physical = 1, + }; + +@@ -136,11 +138,21 @@ const static struct intel_device_info intel_ironlake_m_info = { + .has_hotplug = 1, + }; + ++const static struct intel_device_info intel_sandybridge_d_info = { ++ .is_i965g = 1, .is_i9xx = 1, .need_gfx_hws = 1, ++ .has_hotplug = 1, .is_gen6 = 1, ++}; ++ ++const static struct intel_device_info intel_sandybridge_m_info = { ++ .is_i965g = 1, .is_mobile = 1, .is_i9xx = 1, .need_gfx_hws = 1, ++ .has_hotplug = 1, .is_gen6 = 1, ++}; ++ + const static struct pci_device_id pciidlist[] = { + INTEL_VGA_DEVICE(0x3577, &intel_i830_info), + INTEL_VGA_DEVICE(0x2562, &intel_845g_info), + INTEL_VGA_DEVICE(0x3582, &intel_i85x_info), +- INTEL_VGA_DEVICE(0x35e8, &intel_i85x_info), ++ INTEL_VGA_DEVICE(0x358e, &intel_i85x_info), + INTEL_VGA_DEVICE(0x2572, &intel_i865g_info), + INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), + INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), +@@ -167,6 +179,8 @@ const static struct pci_device_id pciidlist[] = { + INTEL_VGA_DEVICE(0xa011, &intel_pineview_info), + INTEL_VGA_DEVICE(0x0042, &intel_ironlake_d_info), + INTEL_VGA_DEVICE(0x0046, &intel_ironlake_m_info), ++ INTEL_VGA_DEVICE(0x0102, &intel_sandybridge_d_info), ++ INTEL_VGA_DEVICE(0x0106, &intel_sandybridge_m_info), + {0, 0, 0} + }; + +@@ -174,6 +188,35 @@ const static struct pci_device_id pciidlist[] = { + MODULE_DEVICE_TABLE(pci, pciidlist); + #endif + ++#define INTEL_PCH_DEVICE_ID_MASK 0xff00 ++#define INTEL_PCH_CPT_DEVICE_ID_TYPE 0x1c00 ++ ++void intel_detect_pch (struct drm_device *dev) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ struct pci_dev *pch; ++ ++ /* ++ * The reason to probe ISA bridge instead of Dev31:Fun0 is to ++ * make graphics device passthrough work easy for VMM, that only ++ * need to expose ISA bridge to let driver know the real hardware ++ * underneath. This is a requirement from virtualization team. ++ */ ++ pch = pci_get_class(PCI_CLASS_BRIDGE_ISA << 8, NULL); ++ if (pch) { ++ if (pch->vendor == PCI_VENDOR_ID_INTEL) { ++ int id; ++ id = pch->device & INTEL_PCH_DEVICE_ID_MASK; ++ ++ if (id == INTEL_PCH_CPT_DEVICE_ID_TYPE) { ++ dev_priv->pch_type = PCH_CPT; ++ DRM_DEBUG_KMS("Found CougarPoint PCH\n"); ++ } ++ } ++ pci_dev_put(pch); ++ } ++} ++ + static int i915_drm_freeze(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; +@@ -348,7 +391,7 @@ int i965_reset(struct drm_device *dev, u8 flags) + !dev_priv->mm.suspended) { + drm_i915_ring_buffer_t *ring = &dev_priv->ring; + struct drm_gem_object *obj = ring->ring_obj; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + dev_priv->mm.suspended = 0; + + /* Stop the ring if it's running. */ +@@ -546,6 +589,11 @@ static struct drm_driver driver = { + + static int __init i915_init(void) + { ++ if (!intel_agp_enabled) { ++ DRM_ERROR("drm/i915 can't work without intel_agp module!\n"); ++ return -ENODEV; ++ } ++ + driver.num_ioctls = i915_max_ioctl; + + i915_gem_shrinker_init(); +@@ -571,6 +619,11 @@ static int __init i915_init(void) + driver.driver_features &= ~DRIVER_MODESET; + #endif + ++ if (!(driver.driver_features & DRIVER_MODESET)) { ++ driver.suspend = i915_suspend; ++ driver.resume = i915_resume; ++ } ++ + return drm_init(&driver); + } + +diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h +--- a/drivers/gpu/drm/i915/i915_drv.h ++++ b/drivers/gpu/drm/i915/i915_drv.h +@@ -150,7 +150,27 @@ struct drm_i915_error_state { + u32 instps; + u32 instdone1; + u32 seqno; ++ u64 bbaddr; + struct timeval time; ++ struct drm_i915_error_object { ++ int page_count; ++ u32 gtt_offset; ++ u32 *pages[0]; ++ } *ringbuffer, *batchbuffer[2]; ++ struct drm_i915_error_buffer { ++ size_t size; ++ u32 name; ++ u32 seqno; ++ u32 gtt_offset; ++ u32 read_domains; ++ u32 write_domain; ++ u32 fence_reg; ++ s32 pinned:2; ++ u32 tiling:2; ++ u32 dirty:1; ++ u32 purgeable:1; ++ } *active_bo; ++ u32 active_bo_count; + }; + + struct drm_i915_display_funcs { +@@ -175,6 +195,7 @@ struct intel_overlay; + struct intel_device_info { + u8 is_mobile : 1; + u8 is_i8xx : 1; ++ u8 is_i85x : 1; + u8 is_i915g : 1; + u8 is_i9xx : 1; + u8 is_i945gm : 1; +@@ -185,6 +206,7 @@ struct intel_device_info { + u8 is_g4x : 1; + u8 is_pineview : 1; + u8 is_ironlake : 1; ++ u8 is_gen6 : 1; + u8 has_fbc : 1; + u8 has_rc6 : 1; + u8 has_pipe_cxsr : 1; +@@ -192,6 +214,19 @@ struct intel_device_info { + u8 cursor_needs_physical : 1; + }; + ++enum no_fbc_reason { ++ FBC_STOLEN_TOO_SMALL, /* not enough space to hold compressed buffers */ ++ FBC_UNSUPPORTED_MODE, /* interlace or doublescanned mode */ ++ FBC_MODE_TOO_LARGE, /* mode too large for compression */ ++ FBC_BAD_PLANE, /* fbc not supported on plane */ ++ FBC_NOT_TILED, /* buffer not tiled */ ++}; ++ ++enum intel_pch { ++ PCH_IBX, /* Ibexpeak PCH */ ++ PCH_CPT, /* Cougarpoint PCH */ ++}; ++ + typedef struct drm_i915_private { + struct drm_device *dev; + +@@ -302,6 +337,9 @@ typedef struct drm_i915_private { + /* Display functions */ + struct drm_i915_display_funcs display; + ++ /* PCH chipset type */ ++ enum intel_pch pch_type; ++ + /* Register state */ + bool modeset_on_lid; + u8 saveLBB; +@@ -452,6 +490,7 @@ typedef struct drm_i915_private { + u32 savePIPEB_DATA_N1; + u32 savePIPEB_LINK_M1; + u32 savePIPEB_LINK_N1; ++ u32 saveMCHBAR_RENDER_STANDBY; + + struct { + struct drm_mm gtt_space; +@@ -581,6 +620,8 @@ typedef struct drm_i915_private { + /* Reclocking support */ + bool render_reclock_avail; + bool lvds_downclock_avail; ++ /* indicate whether the LVDS EDID is OK */ ++ bool lvds_edid_good; + /* indicates the reduced downclock for LVDS*/ + int lvds_downclock; + struct work_struct idle_work; +@@ -590,6 +631,14 @@ typedef struct drm_i915_private { + int child_dev_num; + struct child_device_config *child_dev; + struct drm_connector *int_lvds_connector; ++ ++ bool mchbar_need_disable; ++ ++ u8 cur_delay; ++ u8 min_delay; ++ u8 max_delay; ++ ++ enum no_fbc_reason no_fbc_reason; + } drm_i915_private_t; + + /** driver private structure attached to each drm_gem_object */ +@@ -693,6 +742,8 @@ struct drm_i915_gem_object { + atomic_t pending_flip; + }; + ++#define to_intel_bo(x) ((struct drm_i915_gem_object *) (x)->driver_private) ++ + /** + * Request queue structure. + * +@@ -761,6 +812,7 @@ extern int i965_reset(struct drm_device *dev, u8 flags); + + /* i915_irq.c */ + void i915_hangcheck_elapsed(unsigned long data); ++void i915_destroy_error_state(struct drm_device *dev); + extern int i915_irq_emit(struct drm_device *dev, void *data, + struct drm_file *file_priv); + extern int i915_irq_wait(struct drm_device *dev, void *data, +@@ -897,7 +949,8 @@ void i915_gem_object_do_bit_17_swizzle(struct drm_gem_object *obj); + void i915_gem_object_save_bit_17_swizzle(struct drm_gem_object *obj); + bool i915_tiling_ok(struct drm_device *dev, int stride, int size, + int tiling_mode); +-bool i915_obj_fenceable(struct drm_device *dev, struct drm_gem_object *obj); ++bool i915_gem_object_fence_offset_ok(struct drm_gem_object *obj, ++ int tiling_mode); + + /* i915_gem_debug.c */ + void i915_gem_dump_object(struct drm_gem_object *obj, int len, +@@ -946,6 +999,9 @@ extern int intel_modeset_vga_set_state(struct drm_device *dev, bool state); + extern void i8xx_disable_fbc(struct drm_device *dev); + extern void g4x_disable_fbc(struct drm_device *dev); + ++extern void intel_detect_pch (struct drm_device *dev); ++extern int intel_trans_dp_port_sel (struct drm_crtc *crtc); ++ + /** + * Lock test for when it's just for synchronization of ring access. + * +@@ -1024,9 +1080,9 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller); + + #define IS_I830(dev) ((dev)->pci_device == 0x3577) + #define IS_845G(dev) ((dev)->pci_device == 0x2562) +-#define IS_I85X(dev) ((dev)->pci_device == 0x3582) ++#define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x) + #define IS_I865G(dev) ((dev)->pci_device == 0x2572) +-#define IS_I8XX(dev) (INTEL_INFO(dev)->is_i8xx) ++#define IS_GEN2(dev) (INTEL_INFO(dev)->is_i8xx) + #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g) + #define IS_I915GM(dev) ((dev)->pci_device == 0x2592) + #define IS_I945G(dev) ((dev)->pci_device == 0x2772) +@@ -1043,8 +1099,28 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller); + #define IS_IRONLAKE_M(dev) ((dev)->pci_device == 0x0046) + #define IS_IRONLAKE(dev) (INTEL_INFO(dev)->is_ironlake) + #define IS_I9XX(dev) (INTEL_INFO(dev)->is_i9xx) ++#define IS_GEN6(dev) (INTEL_INFO(dev)->is_gen6) + #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile) + ++#define IS_GEN3(dev) (IS_I915G(dev) || \ ++ IS_I915GM(dev) || \ ++ IS_I945G(dev) || \ ++ IS_I945GM(dev) || \ ++ IS_G33(dev) || \ ++ IS_PINEVIEW(dev)) ++#define IS_GEN4(dev) ((dev)->pci_device == 0x2972 || \ ++ (dev)->pci_device == 0x2982 || \ ++ (dev)->pci_device == 0x2992 || \ ++ (dev)->pci_device == 0x29A2 || \ ++ (dev)->pci_device == 0x2A02 || \ ++ (dev)->pci_device == 0x2A12 || \ ++ (dev)->pci_device == 0x2E02 || \ ++ (dev)->pci_device == 0x2E12 || \ ++ (dev)->pci_device == 0x2E22 || \ ++ (dev)->pci_device == 0x2E32 || \ ++ (dev)->pci_device == 0x2A42 || \ ++ (dev)->pci_device == 0x2E42) ++ + #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws) + + /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte +@@ -1057,7 +1133,8 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller); + #define SUPPORTS_INTEGRATED_DP(dev) (IS_G4X(dev) || IS_IRONLAKE(dev)) + #define SUPPORTS_EDP(dev) (IS_IRONLAKE_M(dev)) + #define SUPPORTS_TV(dev) (IS_I9XX(dev) && IS_MOBILE(dev) && \ +- !IS_IRONLAKE(dev) && !IS_PINEVIEW(dev)) ++ !IS_IRONLAKE(dev) && !IS_PINEVIEW(dev) && \ ++ !IS_GEN6(dev)) + #define I915_HAS_HOTPLUG(dev) (INTEL_INFO(dev)->has_hotplug) + /* dsparb controlled by hw only */ + #define DSPARB_HWCONTROL(dev) (IS_G4X(dev) || IS_IRONLAKE(dev)) +@@ -1067,6 +1144,12 @@ extern int i915_wait_ring(struct drm_device * dev, int n, const char *caller); + #define I915_HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc) + #define I915_HAS_RC6(dev) (INTEL_INFO(dev)->has_rc6) + ++#define HAS_PCH_SPLIT(dev) (IS_IRONLAKE(dev) || \ ++ IS_GEN6(dev)) ++ ++#define INTEL_PCH_TYPE(dev) (((struct drm_i915_private *)(dev)->dev_private)->pch_type) ++#define HAS_PCH_CPT(dev) (INTEL_PCH_TYPE(dev) == PCH_CPT) ++ + #define PRIMARY_RINGBUFFER_SIZE (128*1024) + + #endif +diff --git a/drivers/gpu/drm/i915/i915_gem.c b/drivers/gpu/drm/i915/i915_gem.c +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -162,7 +162,7 @@ fast_shmem_read(struct page **pages, + static int i915_gem_object_needs_bit17_swizzle(struct drm_gem_object *obj) + { + drm_i915_private_t *dev_priv = obj->dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + return dev_priv->mm.bit_6_swizzle_x == I915_BIT_6_SWIZZLE_9_10_17 && + obj_priv->tiling_mode != I915_TILING_NONE; +@@ -263,7 +263,7 @@ i915_gem_shmem_pread_fast(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pread *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + ssize_t remain; + loff_t offset, page_base; + char __user *user_data; +@@ -284,7 +284,7 @@ i915_gem_shmem_pread_fast(struct drm_device *dev, struct drm_gem_object *obj, + if (ret != 0) + goto fail_put_pages; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + offset = args->offset; + + while (remain > 0) { +@@ -353,7 +353,7 @@ i915_gem_shmem_pread_slow(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pread *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct mm_struct *mm = current->mm; + struct page **user_pages; + ssize_t remain; +@@ -402,7 +402,7 @@ i915_gem_shmem_pread_slow(struct drm_device *dev, struct drm_gem_object *obj, + if (ret != 0) + goto fail_put_pages; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + offset = args->offset; + + while (remain > 0) { +@@ -478,7 +478,7 @@ i915_gem_pread_ioctl(struct drm_device *dev, void *data, + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (obj == NULL) + return -EBADF; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + /* Bounds check source. + * +@@ -580,7 +580,7 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pwrite *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + drm_i915_private_t *dev_priv = dev->dev_private; + ssize_t remain; + loff_t offset, page_base; +@@ -604,7 +604,7 @@ i915_gem_gtt_pwrite_fast(struct drm_device *dev, struct drm_gem_object *obj, + if (ret) + goto fail; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + offset = obj_priv->gtt_offset + args->offset; + + while (remain > 0) { +@@ -654,7 +654,7 @@ i915_gem_gtt_pwrite_slow(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pwrite *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + drm_i915_private_t *dev_priv = dev->dev_private; + ssize_t remain; + loff_t gtt_page_base, offset; +@@ -698,7 +698,7 @@ i915_gem_gtt_pwrite_slow(struct drm_device *dev, struct drm_gem_object *obj, + if (ret) + goto out_unpin_object; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + offset = obj_priv->gtt_offset + args->offset; + + while (remain > 0) { +@@ -760,7 +760,7 @@ i915_gem_shmem_pwrite_fast(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pwrite *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + ssize_t remain; + loff_t offset, page_base; + char __user *user_data; +@@ -780,7 +780,7 @@ i915_gem_shmem_pwrite_fast(struct drm_device *dev, struct drm_gem_object *obj, + if (ret != 0) + goto fail_put_pages; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + offset = args->offset; + obj_priv->dirty = 1; + +@@ -828,7 +828,7 @@ i915_gem_shmem_pwrite_slow(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pwrite *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct mm_struct *mm = current->mm; + struct page **user_pages; + ssize_t remain; +@@ -876,7 +876,7 @@ i915_gem_shmem_pwrite_slow(struct drm_device *dev, struct drm_gem_object *obj, + if (ret != 0) + goto fail_put_pages; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + offset = args->offset; + obj_priv->dirty = 1; + +@@ -951,7 +951,7 @@ i915_gem_pwrite_ioctl(struct drm_device *dev, void *data, + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (obj == NULL) + return -EBADF; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + /* Bounds check destination. + * +@@ -1033,7 +1033,7 @@ i915_gem_set_domain_ioctl(struct drm_device *dev, void *data, + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (obj == NULL) + return -EBADF; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + mutex_lock(&dev->struct_mutex); + +@@ -1095,7 +1095,7 @@ i915_gem_sw_finish_ioctl(struct drm_device *dev, void *data, + DRM_INFO("%s: sw_finish %d (%p %zd)\n", + __func__, args->handle, obj, obj->size); + #endif +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + /* Pinned buffers may be scanout, so flush the cache */ + if (obj_priv->pin_count) +@@ -1166,7 +1166,7 @@ int i915_gem_fault(struct vm_area_struct *vma, struct vm_fault *vmf) + struct drm_gem_object *obj = vma->vm_private_data; + struct drm_device *dev = obj->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + pgoff_t page_offset; + unsigned long pfn; + int ret = 0; +@@ -1233,7 +1233,7 @@ i915_gem_create_mmap_offset(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + struct drm_gem_mm *mm = dev->mm_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct drm_map_list *list; + struct drm_local_map *map; + int ret = 0; +@@ -1304,7 +1304,7 @@ void + i915_gem_release_mmap(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + if (dev->dev_mapping) + unmap_mapping_range(dev->dev_mapping, +@@ -1315,7 +1315,7 @@ static void + i915_gem_free_mmap_offset(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct drm_gem_mm *mm = dev->mm_private; + struct drm_map_list *list; + +@@ -1346,7 +1346,7 @@ static uint32_t + i915_gem_get_gtt_alignment(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int start, i; + + /* +@@ -1405,7 +1405,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data, + + mutex_lock(&dev->struct_mutex); + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + if (obj_priv->madv != I915_MADV_WILLNEED) { + DRM_ERROR("Attempting to mmap a purgeable buffer\n"); +@@ -1449,7 +1449,7 @@ i915_gem_mmap_gtt_ioctl(struct drm_device *dev, void *data, + void + i915_gem_object_put_pages(struct drm_gem_object *obj) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int page_count = obj->size / PAGE_SIZE; + int i; + +@@ -1485,7 +1485,7 @@ i915_gem_object_move_to_active(struct drm_gem_object *obj, uint32_t seqno) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + /* Add a reference if we're newly entering the active list. */ + if (!obj_priv->active) { +@@ -1505,7 +1505,7 @@ i915_gem_object_move_to_flushing(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + BUG_ON(!obj_priv->active); + list_move_tail(&obj_priv->list, &dev_priv->mm.flushing_list); +@@ -1516,7 +1516,7 @@ i915_gem_object_move_to_flushing(struct drm_gem_object *obj) + static void + i915_gem_object_truncate(struct drm_gem_object *obj) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct inode *inode; + + inode = obj->filp->f_path.dentry->d_inode; +@@ -1537,7 +1537,7 @@ i915_gem_object_move_to_inactive(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + i915_verify_inactive(dev, __FILE__, __LINE__); + if (obj_priv->pin_count != 0) +@@ -1555,6 +1555,38 @@ i915_gem_object_move_to_inactive(struct drm_gem_object *obj) + i915_verify_inactive(dev, __FILE__, __LINE__); + } + ++static void ++i915_gem_process_flushing_list(struct drm_device *dev, ++ uint32_t flush_domains, uint32_t seqno) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_i915_gem_object *obj_priv, *next; ++ ++ list_for_each_entry_safe(obj_priv, next, ++ &dev_priv->mm.gpu_write_list, ++ gpu_write_list) { ++ struct drm_gem_object *obj = obj_priv->obj; ++ ++ if ((obj->write_domain & flush_domains) == ++ obj->write_domain) { ++ uint32_t old_write_domain = obj->write_domain; ++ ++ obj->write_domain = 0; ++ list_del_init(&obj_priv->gpu_write_list); ++ i915_gem_object_move_to_active(obj, seqno); ++ ++ /* update the fence lru list */ ++ if (obj_priv->fence_reg != I915_FENCE_REG_NONE) ++ list_move_tail(&obj_priv->fence_list, ++ &dev_priv->mm.fence_list); ++ ++ trace_i915_gem_object_change_domain(obj, ++ obj->read_domains, ++ old_write_domain); ++ } ++ } ++} ++ + /** + * Creates a new sequence number, emitting a write of it to the status page + * plus an interrupt, which will trigger i915_user_interrupt_handler. +@@ -1613,29 +1645,8 @@ i915_add_request(struct drm_device *dev, struct drm_file *file_priv, + /* Associate any objects on the flushing list matching the write + * domain we're flushing with our flush. + */ +- if (flush_domains != 0) { +- struct drm_i915_gem_object *obj_priv, *next; +- +- list_for_each_entry_safe(obj_priv, next, +- &dev_priv->mm.gpu_write_list, +- gpu_write_list) { +- struct drm_gem_object *obj = obj_priv->obj; +- +- if ((obj->write_domain & flush_domains) == +- obj->write_domain) { +- uint32_t old_write_domain = obj->write_domain; +- +- obj->write_domain = 0; +- list_del_init(&obj_priv->gpu_write_list); +- i915_gem_object_move_to_active(obj, seqno); +- +- trace_i915_gem_object_change_domain(obj, +- obj->read_domains, +- old_write_domain); +- } +- } +- +- } ++ if (flush_domains != 0) ++ i915_gem_process_flushing_list(dev, flush_domains, seqno); + + if (!dev_priv->mm.suspended) { + mod_timer(&dev_priv->hangcheck_timer, jiffies + DRM_I915_HANGCHECK_PERIOD); +@@ -1815,7 +1826,7 @@ i915_do_wait_request(struct drm_device *dev, uint32_t seqno, int interruptible) + return -EIO; + + if (!i915_seqno_passed(i915_get_gem_seqno(dev), seqno)) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ier = I915_READ(DEIER) | I915_READ(GTIER); + else + ier = I915_READ(IER); +@@ -1953,7 +1964,7 @@ static int + i915_gem_object_wait_rendering(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int ret; + + /* This function only exists to support waiting for existing rendering, +@@ -1984,7 +1995,8 @@ int + i915_gem_object_unbind(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int ret = 0; + + #if WATCH_BUF +@@ -2039,8 +2051,10 @@ i915_gem_object_unbind(struct drm_gem_object *obj) + } + + /* Remove ourselves from the LRU list if present. */ ++ spin_lock(&dev_priv->mm.active_list_lock); + if (!list_empty(&obj_priv->list)) + list_del_init(&obj_priv->list); ++ spin_unlock(&dev_priv->mm.active_list_lock); + + if (i915_gem_object_is_purgeable(obj_priv)) + i915_gem_object_truncate(obj); +@@ -2078,11 +2092,34 @@ i915_gem_find_inactive_object(struct drm_device *dev, int min_size) + } + + static int ++i915_gpu_idle(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ bool lists_empty; ++ uint32_t seqno; ++ ++ spin_lock(&dev_priv->mm.active_list_lock); ++ lists_empty = list_empty(&dev_priv->mm.flushing_list) && ++ list_empty(&dev_priv->mm.active_list); ++ spin_unlock(&dev_priv->mm.active_list_lock); ++ ++ if (lists_empty) ++ return 0; ++ ++ /* Flush everything onto the inactive list. */ ++ i915_gem_flush(dev, I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS); ++ seqno = i915_add_request(dev, NULL, I915_GEM_GPU_DOMAINS); ++ if (seqno == 0) ++ return -ENOMEM; ++ ++ return i915_wait_request(dev, seqno); ++} ++ ++static int + i915_gem_evict_everything(struct drm_device *dev) + { + drm_i915_private_t *dev_priv = dev->dev_private; + int ret; +- uint32_t seqno; + bool lists_empty; + + spin_lock(&dev_priv->mm.active_list_lock); +@@ -2095,12 +2132,7 @@ i915_gem_evict_everything(struct drm_device *dev) + return -ENOSPC; + + /* Flush everything (on to the inactive lists) and evict */ +- i915_gem_flush(dev, I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS); +- seqno = i915_add_request(dev, NULL, I915_GEM_GPU_DOMAINS); +- if (seqno == 0) +- return -ENOMEM; +- +- ret = i915_wait_request(dev, seqno); ++ ret = i915_gpu_idle(dev); + if (ret) + return ret; + +@@ -2140,7 +2172,7 @@ i915_gem_evict_something(struct drm_device *dev, int min_size) + #if WATCH_LRU + DRM_INFO("%s: evicting %p\n", __func__, obj); + #endif +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + BUG_ON(obj_priv->pin_count != 0); + BUG_ON(obj_priv->active); + +@@ -2192,11 +2224,6 @@ i915_gem_evict_something(struct drm_device *dev, int min_size) + seqno = i915_add_request(dev, NULL, obj->write_domain); + if (seqno == 0) + return -ENOMEM; +- +- ret = i915_wait_request(dev, seqno); +- if (ret) +- return ret; +- + continue; + } + } +@@ -2216,7 +2243,7 @@ int + i915_gem_object_get_pages(struct drm_gem_object *obj, + gfp_t gfpmask) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int page_count, i; + struct address_space *mapping; + struct inode *inode; +@@ -2264,12 +2291,34 @@ err_pages: + return PTR_ERR(page); + } + ++static void sandybridge_write_fence_reg(struct drm_i915_fence_reg *reg) ++{ ++ struct drm_gem_object *obj = reg->obj; ++ struct drm_device *dev = obj->dev; ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); ++ int regnum = obj_priv->fence_reg; ++ uint64_t val; ++ ++ val = (uint64_t)((obj_priv->gtt_offset + obj->size - 4096) & ++ 0xfffff000) << 32; ++ val |= obj_priv->gtt_offset & 0xfffff000; ++ val |= (uint64_t)((obj_priv->stride / 128) - 1) << ++ SANDYBRIDGE_FENCE_PITCH_SHIFT; ++ ++ if (obj_priv->tiling_mode == I915_TILING_Y) ++ val |= 1 << I965_FENCE_TILING_Y_SHIFT; ++ val |= I965_FENCE_REG_VALID; ++ ++ I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + (regnum * 8), val); ++} ++ + static void i965_write_fence_reg(struct drm_i915_fence_reg *reg) + { + struct drm_gem_object *obj = reg->obj; + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int regnum = obj_priv->fence_reg; + uint64_t val; + +@@ -2289,7 +2338,7 @@ static void i915_write_fence_reg(struct drm_i915_fence_reg *reg) + struct drm_gem_object *obj = reg->obj; + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int regnum = obj_priv->fence_reg; + int tile_width; + uint32_t fence_reg, val; +@@ -2312,6 +2361,12 @@ static void i915_write_fence_reg(struct drm_i915_fence_reg *reg) + pitch_val = obj_priv->stride / tile_width; + pitch_val = ffs(pitch_val) - 1; + ++ if (obj_priv->tiling_mode == I915_TILING_Y && ++ HAS_128_BYTE_Y_TILING(dev)) ++ WARN_ON(pitch_val > I830_FENCE_MAX_PITCH_VAL); ++ else ++ WARN_ON(pitch_val > I915_FENCE_MAX_PITCH_VAL); ++ + val = obj_priv->gtt_offset; + if (obj_priv->tiling_mode == I915_TILING_Y) + val |= 1 << I830_FENCE_TILING_Y_SHIFT; +@@ -2331,7 +2386,7 @@ static void i830_write_fence_reg(struct drm_i915_fence_reg *reg) + struct drm_gem_object *obj = reg->obj; + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int regnum = obj_priv->fence_reg; + uint32_t val; + uint32_t pitch_val; +@@ -2360,6 +2415,58 @@ static void i830_write_fence_reg(struct drm_i915_fence_reg *reg) + I915_WRITE(FENCE_REG_830_0 + (regnum * 4), val); + } + ++static int i915_find_fence_reg(struct drm_device *dev) ++{ ++ struct drm_i915_fence_reg *reg = NULL; ++ struct drm_i915_gem_object *obj_priv = NULL; ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ struct drm_gem_object *obj = NULL; ++ int i, avail, ret; ++ ++ /* First try to find a free reg */ ++ avail = 0; ++ for (i = dev_priv->fence_reg_start; i < dev_priv->num_fence_regs; i++) { ++ reg = &dev_priv->fence_regs[i]; ++ if (!reg->obj) ++ return i; ++ ++ obj_priv = to_intel_bo(reg->obj); ++ if (!obj_priv->pin_count) ++ avail++; ++ } ++ ++ if (avail == 0) ++ return -ENOSPC; ++ ++ /* None available, try to steal one or wait for a user to finish */ ++ i = I915_FENCE_REG_NONE; ++ list_for_each_entry(obj_priv, &dev_priv->mm.fence_list, ++ fence_list) { ++ obj = obj_priv->obj; ++ ++ if (obj_priv->pin_count) ++ continue; ++ ++ /* found one! */ ++ i = obj_priv->fence_reg; ++ break; ++ } ++ ++ BUG_ON(i == I915_FENCE_REG_NONE); ++ ++ /* We only have a reference on obj from the active list. put_fence_reg ++ * might drop that one, causing a use-after-free in it. So hold a ++ * private reference to obj like the other callers of put_fence_reg ++ * (set_tiling ioctl) do. */ ++ drm_gem_object_reference(obj); ++ ret = i915_gem_object_put_fence_reg(obj); ++ drm_gem_object_unreference(obj); ++ if (ret != 0) ++ return ret; ++ ++ return i; ++} ++ + /** + * i915_gem_object_get_fence_reg - set up a fence reg for an object + * @obj: object to map through a fence reg +@@ -2378,10 +2485,9 @@ i915_gem_object_get_fence_reg(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct drm_i915_fence_reg *reg = NULL; +- struct drm_i915_gem_object *old_obj_priv = NULL; +- int i, ret, avail; ++ int ret; + + /* Just update our place in the LRU if our fence is getting used. */ + if (obj_priv->fence_reg != I915_FENCE_REG_NONE) { +@@ -2409,86 +2515,27 @@ i915_gem_object_get_fence_reg(struct drm_gem_object *obj) + break; + } + +- /* First try to find a free reg */ +- avail = 0; +- for (i = dev_priv->fence_reg_start; i < dev_priv->num_fence_regs; i++) { +- reg = &dev_priv->fence_regs[i]; +- if (!reg->obj) +- break; +- +- old_obj_priv = reg->obj->driver_private; +- if (!old_obj_priv->pin_count) +- avail++; +- } +- +- /* None available, try to steal one or wait for a user to finish */ +- if (i == dev_priv->num_fence_regs) { +- struct drm_gem_object *old_obj = NULL; +- +- if (avail == 0) +- return -ENOSPC; +- +- list_for_each_entry(old_obj_priv, &dev_priv->mm.fence_list, +- fence_list) { +- old_obj = old_obj_priv->obj; +- +- if (old_obj_priv->pin_count) +- continue; +- +- /* Take a reference, as otherwise the wait_rendering +- * below may cause the object to get freed out from +- * under us. +- */ +- drm_gem_object_reference(old_obj); +- +- /* i915 uses fences for GPU access to tiled buffers */ +- if (IS_I965G(dev) || !old_obj_priv->active) +- break; +- +- /* This brings the object to the head of the LRU if it +- * had been written to. The only way this should +- * result in us waiting longer than the expected +- * optimal amount of time is if there was a +- * fence-using buffer later that was read-only. +- */ +- i915_gem_object_flush_gpu_write_domain(old_obj); +- ret = i915_gem_object_wait_rendering(old_obj); +- if (ret != 0) { +- drm_gem_object_unreference(old_obj); +- return ret; +- } +- +- break; +- } +- +- /* +- * Zap this virtual mapping so we can set up a fence again +- * for this object next time we need it. +- */ +- i915_gem_release_mmap(old_obj); +- +- i = old_obj_priv->fence_reg; +- reg = &dev_priv->fence_regs[i]; +- +- old_obj_priv->fence_reg = I915_FENCE_REG_NONE; +- list_del_init(&old_obj_priv->fence_list); +- +- drm_gem_object_unreference(old_obj); +- } ++ ret = i915_find_fence_reg(dev); ++ if (ret < 0) ++ return ret; + +- obj_priv->fence_reg = i; ++ obj_priv->fence_reg = ret; ++ reg = &dev_priv->fence_regs[obj_priv->fence_reg]; + list_add_tail(&obj_priv->fence_list, &dev_priv->mm.fence_list); + + reg->obj = obj; + +- if (IS_I965G(dev)) ++ if (IS_GEN6(dev)) ++ sandybridge_write_fence_reg(reg); ++ else if (IS_I965G(dev)) + i965_write_fence_reg(reg); + else if (IS_I9XX(dev)) + i915_write_fence_reg(reg); + else + i830_write_fence_reg(reg); + +- trace_i915_gem_object_get_fence(obj, i, obj_priv->tiling_mode); ++ trace_i915_gem_object_get_fence(obj, obj_priv->fence_reg, ++ obj_priv->tiling_mode); + + return 0; + } +@@ -2505,11 +2552,14 @@ i915_gem_clear_fence_reg(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + +- if (IS_I965G(dev)) ++ if (IS_GEN6(dev)) { ++ I915_WRITE64(FENCE_REG_SANDYBRIDGE_0 + ++ (obj_priv->fence_reg * 8), 0); ++ } else if (IS_I965G(dev)) { + I915_WRITE64(FENCE_REG_965_0 + (obj_priv->fence_reg * 8), 0); +- else { ++ } else { + uint32_t fence_reg; + + if (obj_priv->fence_reg < 8) +@@ -2538,11 +2588,17 @@ int + i915_gem_object_put_fence_reg(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + if (obj_priv->fence_reg == I915_FENCE_REG_NONE) + return 0; + ++ /* If we've changed tiling, GTT-mappings of the object ++ * need to re-fault to ensure that the correct fence register ++ * setup is in place. ++ */ ++ i915_gem_release_mmap(obj); ++ + /* On the i915, GPU access to tiled buffers is via a fence, + * therefore we must wait for any outstanding access to complete + * before clearing the fence. +@@ -2551,12 +2607,12 @@ i915_gem_object_put_fence_reg(struct drm_gem_object *obj) + int ret; + + i915_gem_object_flush_gpu_write_domain(obj); +- i915_gem_object_flush_gtt_write_domain(obj); + ret = i915_gem_object_wait_rendering(obj); + if (ret != 0) + return ret; + } + ++ i915_gem_object_flush_gtt_write_domain(obj); + i915_gem_clear_fence_reg (obj); + + return 0; +@@ -2570,7 +2626,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + struct drm_mm_node *free_space; + gfp_t gfpmask = __GFP_NORETRY | __GFP_NOWARN; + int ret; +@@ -2677,7 +2733,7 @@ i915_gem_object_bind_to_gtt(struct drm_gem_object *obj, unsigned alignment) + void + i915_gem_clflush_object(struct drm_gem_object *obj) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + /* If we don't have a page list set up, then we're not pinned + * to GPU, and we can ignore the cache flush because it'll happen +@@ -2696,7 +2752,6 @@ static void + i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- uint32_t seqno; + uint32_t old_write_domain; + + if ((obj->write_domain & I915_GEM_GPU_DOMAINS) == 0) +@@ -2705,9 +2760,8 @@ i915_gem_object_flush_gpu_write_domain(struct drm_gem_object *obj) + /* Queue the GPU write cache flushing we need. */ + old_write_domain = obj->write_domain; + i915_gem_flush(dev, 0, obj->write_domain); +- seqno = i915_add_request(dev, NULL, obj->write_domain); ++ (void) i915_add_request(dev, NULL, obj->write_domain); + BUG_ON(obj->write_domain); +- i915_gem_object_move_to_active(obj, seqno); + + trace_i915_gem_object_change_domain(obj, + obj->read_domains, +@@ -2780,7 +2834,7 @@ i915_gem_object_flush_write_domain(struct drm_gem_object *obj) + int + i915_gem_object_set_to_gtt_domain(struct drm_gem_object *obj, int write) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + uint32_t old_write_domain, old_read_domains; + int ret; + +@@ -2830,7 +2884,7 @@ int + i915_gem_object_set_to_display_plane(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + uint32_t old_write_domain, old_read_domains; + int ret; + +@@ -3043,7 +3097,7 @@ static void + i915_gem_object_set_to_gpu_domain(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + uint32_t invalidate_domains = 0; + uint32_t flush_domains = 0; + uint32_t old_read_domains; +@@ -3128,7 +3182,7 @@ i915_gem_object_set_to_gpu_domain(struct drm_gem_object *obj) + static void + i915_gem_object_set_to_full_cpu_read_domain(struct drm_gem_object *obj) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + if (!obj_priv->page_cpu_valid) + return; +@@ -3168,7 +3222,7 @@ static int + i915_gem_object_set_cpu_read_domain_range(struct drm_gem_object *obj, + uint64_t offset, uint64_t size) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + uint32_t old_read_domains; + int i, ret; + +@@ -3237,7 +3291,7 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj, + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int i, ret; + void __iomem *reloc_page; + bool need_fence; +@@ -3246,7 +3300,8 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj, + obj_priv->tiling_mode != I915_TILING_NONE; + + /* Check fence reg constraints and rebind if necessary */ +- if (need_fence && !i915_obj_fenceable(dev, obj)) ++ if (need_fence && !i915_gem_object_fence_offset_ok(obj, ++ obj_priv->tiling_mode)) + i915_gem_object_unbind(obj); + + /* Choose the GTT offset for our buffer and put it there. */ +@@ -3287,7 +3342,7 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj, + i915_gem_object_unpin(obj); + return -EBADF; + } +- target_obj_priv = target_obj->driver_private; ++ target_obj_priv = to_intel_bo(target_obj); + + #if WATCH_RELOC + DRM_INFO("%s: obj %p offset %08x target %d " +@@ -3316,6 +3371,16 @@ i915_gem_object_pin_and_relocate(struct drm_gem_object *obj, + } + + /* Validate that the target is in a valid r/w GPU domain */ ++ if (reloc->write_domain & (reloc->write_domain - 1)) { ++ DRM_ERROR("reloc with multiple write domains: " ++ "obj %p target %d offset %d " ++ "read %08x write %08x", ++ obj, reloc->target_handle, ++ (int) reloc->offset, ++ reloc->read_domains, ++ reloc->write_domain); ++ return -EINVAL; ++ } + if (reloc->write_domain & I915_GEM_DOMAIN_CPU || + reloc->read_domains & I915_GEM_DOMAIN_CPU) { + DRM_ERROR("reloc with read/write CPU domains: " +@@ -3629,7 +3694,7 @@ i915_gem_wait_for_pending_flip(struct drm_device *dev, + prepare_to_wait(&dev_priv->pending_flip_queue, + &wait, TASK_INTERRUPTIBLE); + for (i = 0; i < count; i++) { +- obj_priv = object_list[i]->driver_private; ++ obj_priv = to_intel_bo(object_list[i]); + if (atomic_read(&obj_priv->pending_flip) > 0) + break; + } +@@ -3738,7 +3803,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, + goto err; + } + +- obj_priv = object_list[i]->driver_private; ++ obj_priv = to_intel_bo(object_list[i]); + if (obj_priv->in_execbuffer) { + DRM_ERROR("Object %p appears more than once in object list\n", + object_list[i]); +@@ -3864,7 +3929,7 @@ i915_gem_do_execbuffer(struct drm_device *dev, void *data, + + for (i = 0; i < args->buffer_count; i++) { + struct drm_gem_object *obj = object_list[i]; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + uint32_t old_write_domain = obj->write_domain; + + obj->write_domain = obj->pending_write_domain; +@@ -3939,7 +4004,7 @@ err: + + for (i = 0; i < args->buffer_count; i++) { + if (object_list[i]) { +- obj_priv = object_list[i]->driver_private; ++ obj_priv = to_intel_bo(object_list[i]); + obj_priv->in_execbuffer = false; + } + drm_gem_object_unreference(object_list[i]); +@@ -4117,7 +4182,7 @@ int + i915_gem_object_pin(struct drm_gem_object *obj, uint32_t alignment) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int ret; + + i915_verify_inactive(dev, __FILE__, __LINE__); +@@ -4150,7 +4215,7 @@ i915_gem_object_unpin(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + i915_verify_inactive(dev, __FILE__, __LINE__); + obj_priv->pin_count--; +@@ -4190,7 +4255,7 @@ i915_gem_pin_ioctl(struct drm_device *dev, void *data, + mutex_unlock(&dev->struct_mutex); + return -EBADF; + } +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + if (obj_priv->madv != I915_MADV_WILLNEED) { + DRM_ERROR("Attempting to pin a purgeable buffer\n"); +@@ -4247,7 +4312,7 @@ i915_gem_unpin_ioctl(struct drm_device *dev, void *data, + return -EBADF; + } + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + if (obj_priv->pin_filp != file_priv) { + DRM_ERROR("Not pinned by caller in i915_gem_pin_ioctl(): %d\n", + args->handle); +@@ -4289,7 +4354,7 @@ i915_gem_busy_ioctl(struct drm_device *dev, void *data, + */ + i915_gem_retire_requests(dev); + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + /* Don't count being on the flushing list against the object being + * done. Otherwise, a buffer left on the flushing list but not getting + * flushed (because nobody's flushing that domain) won't ever return +@@ -4335,7 +4400,7 @@ i915_gem_madvise_ioctl(struct drm_device *dev, void *data, + } + + mutex_lock(&dev->struct_mutex); +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + if (obj_priv->pin_count) { + drm_gem_object_unreference(obj); +@@ -4396,7 +4461,7 @@ int i915_gem_init_object(struct drm_gem_object *obj) + void i915_gem_free_object(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + trace_i915_gem_object_destroy(obj); + +@@ -4444,8 +4509,7 @@ int + i915_gem_idle(struct drm_device *dev) + { + drm_i915_private_t *dev_priv = dev->dev_private; +- uint32_t seqno, cur_seqno, last_seqno; +- int stuck, ret; ++ int ret; + + mutex_lock(&dev->struct_mutex); + +@@ -4454,115 +4518,36 @@ i915_gem_idle(struct drm_device *dev) + return 0; + } + +- /* Hack! Don't let anybody do execbuf while we don't control the chip. +- * We need to replace this with a semaphore, or something. +- */ +- dev_priv->mm.suspended = 1; +- del_timer(&dev_priv->hangcheck_timer); +- +- /* Cancel the retire work handler, wait for it to finish if running +- */ +- mutex_unlock(&dev->struct_mutex); +- cancel_delayed_work_sync(&dev_priv->mm.retire_work); +- mutex_lock(&dev->struct_mutex); +- +- i915_kernel_lost_context(dev); +- +- /* Flush the GPU along with all non-CPU write domains +- */ +- i915_gem_flush(dev, I915_GEM_GPU_DOMAINS, I915_GEM_GPU_DOMAINS); +- seqno = i915_add_request(dev, NULL, I915_GEM_GPU_DOMAINS); +- +- if (seqno == 0) { ++ ret = i915_gpu_idle(dev); ++ if (ret) { + mutex_unlock(&dev->struct_mutex); +- return -ENOMEM; ++ return ret; + } + +- dev_priv->mm.waiting_gem_seqno = seqno; +- last_seqno = 0; +- stuck = 0; +- for (;;) { +- cur_seqno = i915_get_gem_seqno(dev); +- if (i915_seqno_passed(cur_seqno, seqno)) +- break; +- if (last_seqno == cur_seqno) { +- if (stuck++ > 100) { +- DRM_ERROR("hardware wedged\n"); +- atomic_set(&dev_priv->mm.wedged, 1); +- DRM_WAKEUP(&dev_priv->irq_queue); +- break; +- } ++ /* Under UMS, be paranoid and evict. */ ++ if (!drm_core_check_feature(dev, DRIVER_MODESET)) { ++ ret = i915_gem_evict_from_inactive_list(dev); ++ if (ret) { ++ mutex_unlock(&dev->struct_mutex); ++ return ret; + } +- msleep(10); +- last_seqno = cur_seqno; + } +- dev_priv->mm.waiting_gem_seqno = 0; +- +- i915_gem_retire_requests(dev); + +- spin_lock(&dev_priv->mm.active_list_lock); +- if (!atomic_read(&dev_priv->mm.wedged)) { +- /* Active and flushing should now be empty as we've +- * waited for a sequence higher than any pending execbuffer +- */ +- WARN_ON(!list_empty(&dev_priv->mm.active_list)); +- WARN_ON(!list_empty(&dev_priv->mm.flushing_list)); +- /* Request should now be empty as we've also waited +- * for the last request in the list +- */ +- WARN_ON(!list_empty(&dev_priv->mm.request_list)); +- } +- +- /* Empty the active and flushing lists to inactive. If there's +- * anything left at this point, it means that we're wedged and +- * nothing good's going to happen by leaving them there. So strip +- * the GPU domains and just stuff them onto inactive. ++ /* Hack! Don't let anybody do execbuf while we don't control the chip. ++ * We need to replace this with a semaphore, or something. ++ * And not confound mm.suspended! + */ +- while (!list_empty(&dev_priv->mm.active_list)) { +- struct drm_gem_object *obj; +- uint32_t old_write_domain; +- +- obj = list_first_entry(&dev_priv->mm.active_list, +- struct drm_i915_gem_object, +- list)->obj; +- old_write_domain = obj->write_domain; +- obj->write_domain &= ~I915_GEM_GPU_DOMAINS; +- i915_gem_object_move_to_inactive(obj); +- +- trace_i915_gem_object_change_domain(obj, +- obj->read_domains, +- old_write_domain); +- } +- spin_unlock(&dev_priv->mm.active_list_lock); +- +- while (!list_empty(&dev_priv->mm.flushing_list)) { +- struct drm_gem_object *obj; +- uint32_t old_write_domain; +- +- obj = list_first_entry(&dev_priv->mm.flushing_list, +- struct drm_i915_gem_object, +- list)->obj; +- old_write_domain = obj->write_domain; +- obj->write_domain &= ~I915_GEM_GPU_DOMAINS; +- i915_gem_object_move_to_inactive(obj); +- +- trace_i915_gem_object_change_domain(obj, +- obj->read_domains, +- old_write_domain); +- } +- +- +- /* Move all inactive buffers out of the GTT. */ +- ret = i915_gem_evict_from_inactive_list(dev); +- WARN_ON(!list_empty(&dev_priv->mm.inactive_list)); +- if (ret) { +- mutex_unlock(&dev->struct_mutex); +- return ret; +- } ++ dev_priv->mm.suspended = 1; ++ del_timer(&dev_priv->hangcheck_timer); + ++ i915_kernel_lost_context(dev); + i915_gem_cleanup_ringbuffer(dev); ++ + mutex_unlock(&dev->struct_mutex); + ++ /* Cancel the retire work handler, which should be idle now. */ ++ cancel_delayed_work_sync(&dev_priv->mm.retire_work); ++ + return 0; + } + +@@ -4585,7 +4570,7 @@ i915_gem_init_hws(struct drm_device *dev) + DRM_ERROR("Failed to allocate status page\n"); + return -ENOMEM; + } +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + obj_priv->agp_type = AGP_USER_CACHED_MEMORY; + + ret = i915_gem_object_pin(obj, 4096); +@@ -4606,8 +4591,13 @@ i915_gem_init_hws(struct drm_device *dev) + } + dev_priv->hws_obj = obj; + memset(dev_priv->hw_status_page, 0, PAGE_SIZE); +- I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); +- I915_READ(HWS_PGA); /* posting read */ ++ if (IS_GEN6(dev)) { ++ I915_WRITE(HWS_PGA_GEN6, dev_priv->status_gfx_addr); ++ I915_READ(HWS_PGA_GEN6); /* posting read */ ++ } else { ++ I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); ++ I915_READ(HWS_PGA); /* posting read */ ++ } + DRM_DEBUG_DRIVER("hws offset: 0x%08x\n", dev_priv->status_gfx_addr); + + return 0; +@@ -4624,7 +4614,7 @@ i915_gem_cleanup_hws(struct drm_device *dev) + return; + + obj = dev_priv->hws_obj; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + kunmap(obj_priv->pages[0]); + i915_gem_object_unpin(obj); +@@ -4658,7 +4648,7 @@ i915_gem_init_ringbuffer(struct drm_device *dev) + i915_gem_cleanup_hws(dev); + return -ENOMEM; + } +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + ret = i915_gem_object_pin(obj, 4096); + if (ret != 0) { +@@ -4744,6 +4734,11 @@ i915_gem_init_ringbuffer(struct drm_device *dev) + ring->space += ring->Size; + } + ++ if (IS_I9XX(dev) && !IS_GEN3(dev)) { ++ I915_WRITE(MI_MODE, ++ (VS_TIMER_DISPATCH) << 16 | VS_TIMER_DISPATCH); ++ } ++ + return 0; + } + +@@ -4849,7 +4844,8 @@ i915_gem_load(struct drm_device *dev) + spin_unlock(&shrink_list_lock); + + /* Old X drivers will take 0-2 for front, back, depth buffers */ +- dev_priv->fence_reg_start = 3; ++ if (!drm_core_check_feature(dev, DRIVER_MODESET)) ++ dev_priv->fence_reg_start = 3; + + if (IS_I965G(dev) || IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) + dev_priv->num_fence_regs = 16; +@@ -4945,7 +4941,7 @@ void i915_gem_detach_phys_object(struct drm_device *dev, + int ret; + int page_count; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + if (!obj_priv->phys_obj) + return; + +@@ -4984,7 +4980,7 @@ i915_gem_attach_phys_object(struct drm_device *dev, + if (id > I915_MAX_PHYS_OBJECT) + return -EINVAL; + +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + if (obj_priv->phys_obj) { + if (obj_priv->phys_obj->id == id) +@@ -5035,7 +5031,7 @@ i915_gem_phys_pwrite(struct drm_device *dev, struct drm_gem_object *obj, + struct drm_i915_gem_pwrite *args, + struct drm_file *file_priv) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + void *obj_addr; + int ret; + char __user *user_data; +diff --git a/drivers/gpu/drm/i915/i915_gem_debug.c b/drivers/gpu/drm/i915/i915_gem_debug.c +--- a/drivers/gpu/drm/i915/i915_gem_debug.c ++++ b/drivers/gpu/drm/i915/i915_gem_debug.c +@@ -72,7 +72,7 @@ void + i915_gem_dump_object(struct drm_gem_object *obj, int len, + const char *where, uint32_t mark) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int page; + + DRM_INFO("%s: object at offset %08x\n", where, obj_priv->gtt_offset); +@@ -137,7 +137,7 @@ void + i915_gem_object_check_coherency(struct drm_gem_object *obj, int handle) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int page; + uint32_t *gtt_mapping; + uint32_t *backing_map = NULL; +diff --git a/drivers/gpu/drm/i915/i915_gem_tiling.c b/drivers/gpu/drm/i915/i915_gem_tiling.c +--- a/drivers/gpu/drm/i915/i915_gem_tiling.c ++++ b/drivers/gpu/drm/i915/i915_gem_tiling.c +@@ -25,8 +25,6 @@ + * + */ + +-#include +-#include + #include "linux/string.h" + #include "linux/bitops.h" + #include "drmP.h" +@@ -83,120 +81,6 @@ + * to match what the GPU expects. + */ + +-#define MCHBAR_I915 0x44 +-#define MCHBAR_I965 0x48 +-#define MCHBAR_SIZE (4*4096) +- +-#define DEVEN_REG 0x54 +-#define DEVEN_MCHBAR_EN (1 << 28) +- +-/* Allocate space for the MCH regs if needed, return nonzero on error */ +-static int +-intel_alloc_mchbar_resource(struct drm_device *dev) +-{ +- drm_i915_private_t *dev_priv = dev->dev_private; +- int reg = IS_I965G(dev) ? MCHBAR_I965 : MCHBAR_I915; +- u32 temp_lo, temp_hi = 0; +- u64 mchbar_addr; +- int ret = 0; +- +- if (IS_I965G(dev)) +- pci_read_config_dword(dev_priv->bridge_dev, reg + 4, &temp_hi); +- pci_read_config_dword(dev_priv->bridge_dev, reg, &temp_lo); +- mchbar_addr = ((u64)temp_hi << 32) | temp_lo; +- +- /* If ACPI doesn't have it, assume we need to allocate it ourselves */ +-#ifdef CONFIG_PNP +- if (mchbar_addr && +- pnp_range_reserved(mchbar_addr, mchbar_addr + MCHBAR_SIZE)) { +- ret = 0; +- goto out; +- } +-#endif +- +- /* Get some space for it */ +- ret = pci_bus_alloc_resource(dev_priv->bridge_dev->bus, &dev_priv->mch_res, +- MCHBAR_SIZE, MCHBAR_SIZE, +- PCIBIOS_MIN_MEM, +- 0, pcibios_align_resource, +- dev_priv->bridge_dev); +- if (ret) { +- DRM_DEBUG_DRIVER("failed bus alloc: %d\n", ret); +- dev_priv->mch_res.start = 0; +- goto out; +- } +- +- if (IS_I965G(dev)) +- pci_write_config_dword(dev_priv->bridge_dev, reg + 4, +- upper_32_bits(dev_priv->mch_res.start)); +- +- pci_write_config_dword(dev_priv->bridge_dev, reg, +- lower_32_bits(dev_priv->mch_res.start)); +-out: +- return ret; +-} +- +-/* Setup MCHBAR if possible, return true if we should disable it again */ +-static bool +-intel_setup_mchbar(struct drm_device *dev) +-{ +- drm_i915_private_t *dev_priv = dev->dev_private; +- int mchbar_reg = IS_I965G(dev) ? MCHBAR_I965 : MCHBAR_I915; +- u32 temp; +- bool need_disable = false, enabled; +- +- if (IS_I915G(dev) || IS_I915GM(dev)) { +- pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); +- enabled = !!(temp & DEVEN_MCHBAR_EN); +- } else { +- pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); +- enabled = temp & 1; +- } +- +- /* If it's already enabled, don't have to do anything */ +- if (enabled) +- goto out; +- +- if (intel_alloc_mchbar_resource(dev)) +- goto out; +- +- need_disable = true; +- +- /* Space is allocated or reserved, so enable it. */ +- if (IS_I915G(dev) || IS_I915GM(dev)) { +- pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, +- temp | DEVEN_MCHBAR_EN); +- } else { +- pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); +- pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp | 1); +- } +-out: +- return need_disable; +-} +- +-static void +-intel_teardown_mchbar(struct drm_device *dev, bool disable) +-{ +- drm_i915_private_t *dev_priv = dev->dev_private; +- int mchbar_reg = IS_I965G(dev) ? MCHBAR_I965 : MCHBAR_I915; +- u32 temp; +- +- if (disable) { +- if (IS_I915G(dev) || IS_I915GM(dev)) { +- pci_read_config_dword(dev_priv->bridge_dev, DEVEN_REG, &temp); +- temp &= ~DEVEN_MCHBAR_EN; +- pci_write_config_dword(dev_priv->bridge_dev, DEVEN_REG, temp); +- } else { +- pci_read_config_dword(dev_priv->bridge_dev, mchbar_reg, &temp); +- temp &= ~1; +- pci_write_config_dword(dev_priv->bridge_dev, mchbar_reg, temp); +- } +- } +- +- if (dev_priv->mch_res.start) +- release_resource(&dev_priv->mch_res); +-} +- + /** + * Detects bit 6 swizzling of address lookup between IGD access and CPU + * access through main memory. +@@ -207,9 +91,8 @@ i915_gem_detect_bit_6_swizzle(struct drm_device *dev) + drm_i915_private_t *dev_priv = dev->dev_private; + uint32_t swizzle_x = I915_BIT_6_SWIZZLE_UNKNOWN; + uint32_t swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN; +- bool need_disable; + +- if (IS_IRONLAKE(dev)) { ++ if (IS_IRONLAKE(dev) || IS_GEN6(dev)) { + /* On Ironlake whatever DRAM config, GPU always do + * same swizzling setup. + */ +@@ -224,9 +107,6 @@ i915_gem_detect_bit_6_swizzle(struct drm_device *dev) + } else if (IS_MOBILE(dev)) { + uint32_t dcc; + +- /* Try to make sure MCHBAR is enabled before poking at it */ +- need_disable = intel_setup_mchbar(dev); +- + /* On mobile 9xx chipsets, channel interleave by the CPU is + * determined by DCC. For single-channel, neither the CPU + * nor the GPU do swizzling. For dual channel interleaved, +@@ -266,8 +146,6 @@ i915_gem_detect_bit_6_swizzle(struct drm_device *dev) + swizzle_x = I915_BIT_6_SWIZZLE_UNKNOWN; + swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN; + } +- +- intel_teardown_mchbar(dev, need_disable); + } else { + /* The 965, G33, and newer, have a very flexible memory + * configuration. It will enable dual-channel mode +@@ -302,39 +180,6 @@ i915_gem_detect_bit_6_swizzle(struct drm_device *dev) + dev_priv->mm.bit_6_swizzle_y = swizzle_y; + } + +- +-/** +- * Returns whether an object is currently fenceable. If not, it may need +- * to be unbound and have its pitch adjusted. +- */ +-bool +-i915_obj_fenceable(struct drm_device *dev, struct drm_gem_object *obj) +-{ +- struct drm_i915_gem_object *obj_priv = obj->driver_private; +- +- if (IS_I965G(dev)) { +- /* The 965 can have fences at any page boundary. */ +- if (obj->size & 4095) +- return false; +- return true; +- } else if (IS_I9XX(dev)) { +- if (obj_priv->gtt_offset & ~I915_FENCE_START_MASK) +- return false; +- } else { +- if (obj_priv->gtt_offset & ~I830_FENCE_START_MASK) +- return false; +- } +- +- /* Power of two sized... */ +- if (obj->size & (obj->size - 1)) +- return false; +- +- /* Objects must be size aligned as well */ +- if (obj_priv->gtt_offset & (obj->size - 1)) +- return false; +- return true; +-} +- + /* Check pitch constriants for all chips & tiling formats */ + bool + i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode) +@@ -357,21 +202,17 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode) + * reg, so dont bother to check the size */ + if (stride / 128 > I965_FENCE_MAX_PITCH_VAL) + return false; +- } else if (IS_I9XX(dev)) { +- uint32_t pitch_val = ffs(stride / tile_width) - 1; +- +- /* XXX: For Y tiling, FENCE_MAX_PITCH_VAL is actually 6 (8KB) +- * instead of 4 (2KB) on 945s. +- */ +- if (pitch_val > I915_FENCE_MAX_PITCH_VAL || +- size > (I830_FENCE_MAX_SIZE_VAL << 20)) ++ } else if (IS_GEN3(dev) || IS_GEN2(dev)) { ++ if (stride > 8192) + return false; +- } else { +- uint32_t pitch_val = ffs(stride / tile_width) - 1; + +- if (pitch_val > I830_FENCE_MAX_PITCH_VAL || +- size > (I830_FENCE_MAX_SIZE_VAL << 19)) +- return false; ++ if (IS_GEN3(dev)) { ++ if (size > I830_FENCE_MAX_SIZE_VAL << 20) ++ return false; ++ } else { ++ if (size > I830_FENCE_MAX_SIZE_VAL << 19) ++ return false; ++ } + } + + /* 965+ just needs multiples of tile width */ +@@ -391,11 +232,11 @@ i915_tiling_ok(struct drm_device *dev, int stride, int size, int tiling_mode) + return true; + } + +-static bool ++bool + i915_gem_object_fence_offset_ok(struct drm_gem_object *obj, int tiling_mode) + { + struct drm_device *dev = obj->dev; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + + if (obj_priv->gtt_space == NULL) + return true; +@@ -435,7 +276,7 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (obj == NULL) + return -EINVAL; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + if (!i915_tiling_ok(dev, args->stride, obj->size, args->tiling_mode)) { + drm_gem_object_unreference_unlocked(obj); +@@ -480,9 +321,12 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, + * need to ensure that any fence register is cleared. + */ + if (!i915_gem_object_fence_offset_ok(obj, args->tiling_mode)) +- ret = i915_gem_object_unbind(obj); ++ ret = i915_gem_object_unbind(obj); ++ else if (obj_priv->fence_reg != I915_FENCE_REG_NONE) ++ ret = i915_gem_object_put_fence_reg(obj); + else +- ret = i915_gem_object_put_fence_reg(obj); ++ i915_gem_release_mmap(obj); ++ + if (ret != 0) { + WARN(ret != -ERESTARTSYS, + "failed to reset object for tiling switch"); +@@ -491,12 +335,6 @@ i915_gem_set_tiling(struct drm_device *dev, void *data, + goto err; + } + +- /* If we've changed tiling, GTT-mappings of the object +- * need to re-fault to ensure that the correct fence register +- * setup is in place. +- */ +- i915_gem_release_mmap(obj); +- + obj_priv->tiling_mode = args->tiling_mode; + obj_priv->stride = args->stride; + } +@@ -522,7 +360,7 @@ i915_gem_get_tiling(struct drm_device *dev, void *data, + obj = drm_gem_object_lookup(dev, file_priv, args->handle); + if (obj == NULL) + return -EINVAL; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + mutex_lock(&dev->struct_mutex); + +@@ -585,7 +423,7 @@ i915_gem_object_do_bit_17_swizzle(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int page_count = obj->size >> PAGE_SHIFT; + int i; + +@@ -614,7 +452,7 @@ i915_gem_object_save_bit_17_swizzle(struct drm_gem_object *obj) + { + struct drm_device *dev = obj->dev; + drm_i915_private_t *dev_priv = dev->dev_private; +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + int page_count = obj->size >> PAGE_SHIFT; + int i; + +diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c +--- a/drivers/gpu/drm/i915/i915_irq.c ++++ b/drivers/gpu/drm/i915/i915_irq.c +@@ -166,11 +166,15 @@ void intel_enable_asle (struct drm_device *dev) + { + drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_enable_display_irq(dev_priv, DE_GSE); +- else ++ else { + i915_enable_pipestat(dev_priv, 1, + I915_LEGACY_BLC_EVENT_ENABLE); ++ if (IS_I965G(dev)) ++ i915_enable_pipestat(dev_priv, 0, ++ I915_LEGACY_BLC_EVENT_ENABLE); ++ } + } + + /** +@@ -255,20 +259,71 @@ static void i915_hotplug_work_func(struct work_struct *work) + hotplug_work); + struct drm_device *dev = dev_priv->dev; + struct drm_mode_config *mode_config = &dev->mode_config; +- struct drm_connector *connector; ++ struct drm_encoder *encoder; + +- if (mode_config->num_connector) { +- list_for_each_entry(connector, &mode_config->connector_list, head) { +- struct intel_output *intel_output = to_intel_output(connector); ++ if (mode_config->num_encoder) { ++ list_for_each_entry(encoder, &mode_config->encoder_list, head) { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + +- if (intel_output->hot_plug) +- (*intel_output->hot_plug) (intel_output); ++ if (intel_encoder->hot_plug) ++ (*intel_encoder->hot_plug) (intel_encoder); + } + } + /* Just fire off a uevent and let userspace tell us what to do */ + drm_sysfs_hotplug_event(dev); + } + ++static void i915_handle_rps_change(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ u32 busy_up, busy_down, max_avg, min_avg; ++ u16 rgvswctl; ++ u8 new_delay = dev_priv->cur_delay; ++ ++ I915_WRITE(MEMINTRSTS, I915_READ(MEMINTRSTS) & ~MEMINT_EVAL_CHG); ++ busy_up = I915_READ(RCPREVBSYTUPAVG); ++ busy_down = I915_READ(RCPREVBSYTDNAVG); ++ max_avg = I915_READ(RCBMAXAVG); ++ min_avg = I915_READ(RCBMINAVG); ++ ++ /* Handle RCS change request from hw */ ++ if (busy_up > max_avg) { ++ if (dev_priv->cur_delay != dev_priv->max_delay) ++ new_delay = dev_priv->cur_delay - 1; ++ if (new_delay < dev_priv->max_delay) ++ new_delay = dev_priv->max_delay; ++ } else if (busy_down < min_avg) { ++ if (dev_priv->cur_delay != dev_priv->min_delay) ++ new_delay = dev_priv->cur_delay + 1; ++ if (new_delay > dev_priv->min_delay) ++ new_delay = dev_priv->min_delay; ++ } ++ ++ DRM_DEBUG("rps change requested: %d -> %d\n", ++ dev_priv->cur_delay, new_delay); ++ ++ rgvswctl = I915_READ(MEMSWCTL); ++ if (rgvswctl & MEMCTL_CMD_STS) { ++ DRM_ERROR("gpu busy, RCS change rejected\n"); ++ return; /* still busy with another command */ ++ } ++ ++ /* Program the new state */ ++ rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | ++ (new_delay << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; ++ I915_WRITE(MEMSWCTL, rgvswctl); ++ POSTING_READ(MEMSWCTL); ++ ++ rgvswctl |= MEMCTL_CMD_STS; ++ I915_WRITE(MEMSWCTL, rgvswctl); ++ ++ dev_priv->cur_delay = new_delay; ++ ++ DRM_DEBUG("rps changed\n"); ++ ++ return; ++} ++ + irqreturn_t ironlake_irq_handler(struct drm_device *dev) + { + drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private; +@@ -331,6 +386,11 @@ irqreturn_t ironlake_irq_handler(struct drm_device *dev) + queue_work(dev_priv->wq, &dev_priv->hotplug_work); + } + ++ if (de_iir & DE_PCU_EVENT) { ++ I915_WRITE(MEMINTRSTS, I915_READ(MEMINTRSTS)); ++ i915_handle_rps_change(dev); ++ } ++ + /* should clear PCH hotplug event before clear CPU irq */ + I915_WRITE(SDEIIR, pch_iir); + I915_WRITE(GTIIR, gt_iir); +@@ -376,6 +436,121 @@ static void i915_error_work_func(struct work_struct *work) + } + } + ++static struct drm_i915_error_object * ++i915_error_object_create(struct drm_device *dev, ++ struct drm_gem_object *src) ++{ ++ struct drm_i915_error_object *dst; ++ struct drm_i915_gem_object *src_priv; ++ int page, page_count; ++ ++ if (src == NULL) ++ return NULL; ++ ++ src_priv = to_intel_bo(src); ++ if (src_priv->pages == NULL) ++ return NULL; ++ ++ page_count = src->size / PAGE_SIZE; ++ ++ dst = kmalloc(sizeof(*dst) + page_count * sizeof (u32 *), GFP_ATOMIC); ++ if (dst == NULL) ++ return NULL; ++ ++ for (page = 0; page < page_count; page++) { ++ void *s, *d = kmalloc(PAGE_SIZE, GFP_ATOMIC); ++ if (d == NULL) ++ goto unwind; ++ s = kmap_atomic(src_priv->pages[page], KM_USER0); ++ memcpy(d, s, PAGE_SIZE); ++ kunmap_atomic(s, KM_USER0); ++ dst->pages[page] = d; ++ } ++ dst->page_count = page_count; ++ dst->gtt_offset = src_priv->gtt_offset; ++ ++ return dst; ++ ++unwind: ++ while (page--) ++ kfree(dst->pages[page]); ++ kfree(dst); ++ return NULL; ++} ++ ++static void ++i915_error_object_free(struct drm_i915_error_object *obj) ++{ ++ int page; ++ ++ if (obj == NULL) ++ return; ++ ++ for (page = 0; page < obj->page_count; page++) ++ kfree(obj->pages[page]); ++ ++ kfree(obj); ++} ++ ++static void ++i915_error_state_free(struct drm_device *dev, ++ struct drm_i915_error_state *error) ++{ ++ i915_error_object_free(error->batchbuffer[0]); ++ i915_error_object_free(error->batchbuffer[1]); ++ i915_error_object_free(error->ringbuffer); ++ kfree(error->active_bo); ++ kfree(error); ++} ++ ++static u32 ++i915_get_bbaddr(struct drm_device *dev, u32 *ring) ++{ ++ u32 cmd; ++ ++ if (IS_I830(dev) || IS_845G(dev)) ++ cmd = MI_BATCH_BUFFER; ++ else if (IS_I965G(dev)) ++ cmd = (MI_BATCH_BUFFER_START | (2 << 6) | ++ MI_BATCH_NON_SECURE_I965); ++ else ++ cmd = (MI_BATCH_BUFFER_START | (2 << 6)); ++ ++ return ring[0] == cmd ? ring[1] : 0; ++} ++ ++static u32 ++i915_ringbuffer_last_batch(struct drm_device *dev) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ u32 head, bbaddr; ++ u32 *ring; ++ ++ /* Locate the current position in the ringbuffer and walk back ++ * to find the most recently dispatched batch buffer. ++ */ ++ bbaddr = 0; ++ head = I915_READ(PRB0_HEAD) & HEAD_ADDR; ++ ring = (u32 *)(dev_priv->ring.virtual_start + head); ++ ++ while (--ring >= (u32 *)dev_priv->ring.virtual_start) { ++ bbaddr = i915_get_bbaddr(dev, ring); ++ if (bbaddr) ++ break; ++ } ++ ++ if (bbaddr == 0) { ++ ring = (u32 *)(dev_priv->ring.virtual_start + dev_priv->ring.Size); ++ while (--ring >= (u32 *)dev_priv->ring.virtual_start) { ++ bbaddr = i915_get_bbaddr(dev, ring); ++ if (bbaddr) ++ break; ++ } ++ } ++ ++ return bbaddr; ++} ++ + /** + * i915_capture_error_state - capture an error record for later analysis + * @dev: drm device +@@ -388,19 +563,26 @@ static void i915_error_work_func(struct work_struct *work) + static void i915_capture_error_state(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; ++ struct drm_i915_gem_object *obj_priv; + struct drm_i915_error_state *error; ++ struct drm_gem_object *batchbuffer[2]; + unsigned long flags; ++ u32 bbaddr; ++ int count; + + spin_lock_irqsave(&dev_priv->error_lock, flags); +- if (dev_priv->first_error) +- goto out; ++ error = dev_priv->first_error; ++ spin_unlock_irqrestore(&dev_priv->error_lock, flags); ++ if (error) ++ return; + + error = kmalloc(sizeof(*error), GFP_ATOMIC); + if (!error) { +- DRM_DEBUG_DRIVER("out ot memory, not capturing error state\n"); +- goto out; ++ DRM_DEBUG_DRIVER("out of memory, not capturing error state\n"); ++ return; + } + ++ error->seqno = i915_get_gem_seqno(dev); + error->eir = I915_READ(EIR); + error->pgtbl_er = I915_READ(PGTBL_ER); + error->pipeastat = I915_READ(PIPEASTAT); +@@ -411,6 +593,7 @@ static void i915_capture_error_state(struct drm_device *dev) + error->ipehr = I915_READ(IPEHR); + error->instdone = I915_READ(INSTDONE); + error->acthd = I915_READ(ACTHD); ++ error->bbaddr = 0; + } else { + error->ipeir = I915_READ(IPEIR_I965); + error->ipehr = I915_READ(IPEHR_I965); +@@ -418,14 +601,101 @@ static void i915_capture_error_state(struct drm_device *dev) + error->instps = I915_READ(INSTPS); + error->instdone1 = I915_READ(INSTDONE1); + error->acthd = I915_READ(ACTHD_I965); ++ error->bbaddr = I915_READ64(BB_ADDR); + } + +- do_gettimeofday(&error->time); ++ bbaddr = i915_ringbuffer_last_batch(dev); + +- dev_priv->first_error = error; ++ /* Grab the current batchbuffer, most likely to have crashed. */ ++ batchbuffer[0] = NULL; ++ batchbuffer[1] = NULL; ++ count = 0; ++ list_for_each_entry(obj_priv, &dev_priv->mm.active_list, list) { ++ struct drm_gem_object *obj = obj_priv->obj; + +-out: ++ if (batchbuffer[0] == NULL && ++ bbaddr >= obj_priv->gtt_offset && ++ bbaddr < obj_priv->gtt_offset + obj->size) ++ batchbuffer[0] = obj; ++ ++ if (batchbuffer[1] == NULL && ++ error->acthd >= obj_priv->gtt_offset && ++ error->acthd < obj_priv->gtt_offset + obj->size && ++ batchbuffer[0] != obj) ++ batchbuffer[1] = obj; ++ ++ count++; ++ } ++ ++ /* We need to copy these to an anonymous buffer as the simplest ++ * method to avoid being overwritten by userpace. ++ */ ++ error->batchbuffer[0] = i915_error_object_create(dev, batchbuffer[0]); ++ error->batchbuffer[1] = i915_error_object_create(dev, batchbuffer[1]); ++ ++ /* Record the ringbuffer */ ++ error->ringbuffer = i915_error_object_create(dev, dev_priv->ring.ring_obj); ++ ++ /* Record buffers on the active list. */ ++ error->active_bo = NULL; ++ error->active_bo_count = 0; ++ ++ if (count) ++ error->active_bo = kmalloc(sizeof(*error->active_bo)*count, ++ GFP_ATOMIC); ++ ++ if (error->active_bo) { ++ int i = 0; ++ list_for_each_entry(obj_priv, &dev_priv->mm.active_list, list) { ++ struct drm_gem_object *obj = obj_priv->obj; ++ ++ error->active_bo[i].size = obj->size; ++ error->active_bo[i].name = obj->name; ++ error->active_bo[i].seqno = obj_priv->last_rendering_seqno; ++ error->active_bo[i].gtt_offset = obj_priv->gtt_offset; ++ error->active_bo[i].read_domains = obj->read_domains; ++ error->active_bo[i].write_domain = obj->write_domain; ++ error->active_bo[i].fence_reg = obj_priv->fence_reg; ++ error->active_bo[i].pinned = 0; ++ if (obj_priv->pin_count > 0) ++ error->active_bo[i].pinned = 1; ++ if (obj_priv->user_pin_count > 0) ++ error->active_bo[i].pinned = -1; ++ error->active_bo[i].tiling = obj_priv->tiling_mode; ++ error->active_bo[i].dirty = obj_priv->dirty; ++ error->active_bo[i].purgeable = obj_priv->madv != I915_MADV_WILLNEED; ++ ++ if (++i == count) ++ break; ++ } ++ error->active_bo_count = i; ++ } ++ ++ do_gettimeofday(&error->time); ++ ++ spin_lock_irqsave(&dev_priv->error_lock, flags); ++ if (dev_priv->first_error == NULL) { ++ dev_priv->first_error = error; ++ error = NULL; ++ } + spin_unlock_irqrestore(&dev_priv->error_lock, flags); ++ ++ if (error) ++ i915_error_state_free(dev, error); ++} ++ ++void i915_destroy_error_state(struct drm_device *dev) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ struct drm_i915_error_state *error; ++ ++ spin_lock(&dev_priv->error_lock); ++ error = dev_priv->first_error; ++ dev_priv->first_error = NULL; ++ spin_unlock(&dev_priv->error_lock); ++ ++ if (error) ++ i915_error_state_free(dev, error); + } + + /** +@@ -576,7 +846,7 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) + + atomic_inc(&dev_priv->irq_received); + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return ironlake_irq_handler(dev); + + iir = I915_READ(IIR); +@@ -679,7 +949,8 @@ irqreturn_t i915_driver_irq_handler(DRM_IRQ_ARGS) + intel_finish_page_flip(dev, 1); + } + +- if ((pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) || ++ if ((pipea_stats & I915_LEGACY_BLC_EVENT_STATUS) || ++ (pipeb_stats & I915_LEGACY_BLC_EVENT_STATUS) || + (iir & I915_ASLE_INTERRUPT)) + opregion_asle_intr(dev); + +@@ -737,7 +1008,7 @@ void i915_user_irq_get(struct drm_device *dev) + + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); + if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); + else + i915_enable_irq(dev_priv, I915_USER_INTERRUPT); +@@ -753,7 +1024,7 @@ void i915_user_irq_put(struct drm_device *dev) + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); + BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); + if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); + else + i915_disable_irq(dev_priv, I915_USER_INTERRUPT); +@@ -861,7 +1132,7 @@ int i915_enable_vblank(struct drm_device *dev, int pipe) + return -EINVAL; + + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_enable_display_irq(dev_priv, (pipe == 0) ? + DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); + else if (IS_I965G(dev)) +@@ -883,7 +1154,7 @@ void i915_disable_vblank(struct drm_device *dev, int pipe) + unsigned long irqflags; + + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_disable_display_irq(dev_priv, (pipe == 0) ? + DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); + else +@@ -897,7 +1168,7 @@ void i915_enable_interrupt (struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; + +- if (!IS_IRONLAKE(dev)) ++ if (!HAS_PCH_SPLIT(dev)) + opregion_enable_asle(dev); + dev_priv->irq_enabled = 1; + } +@@ -973,7 +1244,11 @@ void i915_hangcheck_elapsed(unsigned long data) + struct drm_device *dev = (struct drm_device *)data; + drm_i915_private_t *dev_priv = dev->dev_private; + uint32_t acthd; +- ++ ++ /* No reset support on this chip yet. */ ++ if (IS_GEN6(dev)) ++ return; ++ + if (!IS_I965G(dev)) + acthd = I915_READ(ACTHD); + else +@@ -1064,6 +1339,13 @@ static int ironlake_irq_postinstall(struct drm_device *dev) + I915_WRITE(SDEIER, dev_priv->pch_irq_enable_reg); + (void) I915_READ(SDEIER); + ++ if (IS_IRONLAKE_M(dev)) { ++ /* Clear & enable PCU event interrupts */ ++ I915_WRITE(DEIIR, DE_PCU_EVENT); ++ I915_WRITE(DEIER, I915_READ(DEIER) | DE_PCU_EVENT); ++ ironlake_enable_display_irq(dev_priv, DE_PCU_EVENT); ++ } ++ + return 0; + } + +@@ -1076,7 +1358,7 @@ void i915_driver_irq_preinstall(struct drm_device * dev) + INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); + INIT_WORK(&dev_priv->error_work, i915_error_work_func); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + ironlake_irq_preinstall(dev); + return; + } +@@ -1108,7 +1390,7 @@ int i915_driver_irq_postinstall(struct drm_device *dev) + + dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return ironlake_irq_postinstall(dev); + + /* Unmask the interrupts that we always want on. */ +@@ -1196,7 +1478,7 @@ void i915_driver_irq_uninstall(struct drm_device * dev) + + dev_priv->vblank_pipe = 0; + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + ironlake_irq_uninstall(dev); + return; + } +diff --git a/drivers/gpu/drm/i915/i915_opregion.c b/drivers/gpu/drm/i915/i915_opregion.c +--- a/drivers/gpu/drm/i915/i915_opregion.c ++++ b/drivers/gpu/drm/i915/i915_opregion.c +@@ -382,8 +382,57 @@ static void intel_didl_outputs(struct drm_device *dev) + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_opregion *opregion = &dev_priv->opregion; + struct drm_connector *connector; ++ acpi_handle handle; ++ struct acpi_device *acpi_dev, *acpi_cdev, *acpi_video_bus = NULL; ++ unsigned long long device_id; ++ acpi_status status; + int i = 0; + ++ handle = DEVICE_ACPI_HANDLE(&dev->pdev->dev); ++ if (!handle || ACPI_FAILURE(acpi_bus_get_device(handle, &acpi_dev))) ++ return; ++ ++ if (acpi_is_video_device(acpi_dev)) ++ acpi_video_bus = acpi_dev; ++ else { ++ list_for_each_entry(acpi_cdev, &acpi_dev->children, node) { ++ if (acpi_is_video_device(acpi_cdev)) { ++ acpi_video_bus = acpi_cdev; ++ break; ++ } ++ } ++ } ++ ++ if (!acpi_video_bus) { ++ printk(KERN_WARNING "No ACPI video bus found\n"); ++ return; ++ } ++ ++ list_for_each_entry(acpi_cdev, &acpi_video_bus->children, node) { ++ if (i >= 8) { ++ dev_printk (KERN_ERR, &dev->pdev->dev, ++ "More than 8 outputs detected\n"); ++ return; ++ } ++ status = ++ acpi_evaluate_integer(acpi_cdev->handle, "_ADR", ++ NULL, &device_id); ++ if (ACPI_SUCCESS(status)) { ++ if (!device_id) ++ goto blind_set; ++ opregion->acpi->didl[i] = (u32)(device_id & 0x0f0f); ++ i++; ++ } ++ } ++ ++end: ++ /* If fewer than 8 outputs, the list must be null terminated */ ++ if (i < 8) ++ opregion->acpi->didl[i] = 0; ++ return; ++ ++blind_set: ++ i = 0; + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { + int output_type = ACPI_OTHER_OUTPUT; + if (i >= 8) { +@@ -416,10 +465,7 @@ static void intel_didl_outputs(struct drm_device *dev) + opregion->acpi->didl[i] |= (1<<31) | output_type | i; + i++; + } +- +- /* If fewer than 8 outputs, the list must be null terminated */ +- if (i < 8) +- opregion->acpi->didl[i] = 0; ++ goto end; + } + + int intel_opregion_init(struct drm_device *dev, int resume) +diff --git a/drivers/gpu/drm/i915/i915_reg.h b/drivers/gpu/drm/i915/i915_reg.h +--- a/drivers/gpu/drm/i915/i915_reg.h ++++ b/drivers/gpu/drm/i915/i915_reg.h +@@ -53,6 +53,25 @@ + #define INTEL_GMCH_GMS_STOLEN_224M (0xc << 4) + #define INTEL_GMCH_GMS_STOLEN_352M (0xd << 4) + ++#define SNB_GMCH_CTRL 0x50 ++#define SNB_GMCH_GMS_STOLEN_MASK 0xF8 ++#define SNB_GMCH_GMS_STOLEN_32M (1 << 3) ++#define SNB_GMCH_GMS_STOLEN_64M (2 << 3) ++#define SNB_GMCH_GMS_STOLEN_96M (3 << 3) ++#define SNB_GMCH_GMS_STOLEN_128M (4 << 3) ++#define SNB_GMCH_GMS_STOLEN_160M (5 << 3) ++#define SNB_GMCH_GMS_STOLEN_192M (6 << 3) ++#define SNB_GMCH_GMS_STOLEN_224M (7 << 3) ++#define SNB_GMCH_GMS_STOLEN_256M (8 << 3) ++#define SNB_GMCH_GMS_STOLEN_288M (9 << 3) ++#define SNB_GMCH_GMS_STOLEN_320M (0xa << 3) ++#define SNB_GMCH_GMS_STOLEN_352M (0xb << 3) ++#define SNB_GMCH_GMS_STOLEN_384M (0xc << 3) ++#define SNB_GMCH_GMS_STOLEN_416M (0xd << 3) ++#define SNB_GMCH_GMS_STOLEN_448M (0xe << 3) ++#define SNB_GMCH_GMS_STOLEN_480M (0xf << 3) ++#define SNB_GMCH_GMS_STOLEN_512M (0x10 << 3) ++ + /* PCI config space */ + + #define HPLLCC 0xc0 /* 855 only */ +@@ -61,6 +80,7 @@ + #define GC_CLOCK_100_200 (1 << 0) + #define GC_CLOCK_100_133 (2 << 0) + #define GC_CLOCK_166_250 (3 << 0) ++#define GCFGC2 0xda + #define GCFGC 0xf0 /* 915+ only */ + #define GC_LOW_FREQUENCY_ENABLE (1 << 7) + #define GC_DISPLAY_CLOCK_190_200_MHZ (0 << 4) +@@ -221,7 +241,7 @@ + #define I830_FENCE_SIZE_BITS(size) ((ffs((size) >> 19) - 1) << 8) + #define I830_FENCE_PITCH_SHIFT 4 + #define I830_FENCE_REG_VALID (1<<0) +-#define I915_FENCE_MAX_PITCH_VAL 0x10 ++#define I915_FENCE_MAX_PITCH_VAL 4 + #define I830_FENCE_MAX_PITCH_VAL 6 + #define I830_FENCE_MAX_SIZE_VAL (1<<8) + +@@ -234,6 +254,9 @@ + #define I965_FENCE_REG_VALID (1<<0) + #define I965_FENCE_MAX_PITCH_VAL 0x0400 + ++#define FENCE_REG_SANDYBRIDGE_0 0x100000 ++#define SANDYBRIDGE_FENCE_PITCH_SHIFT 32 ++ + /* + * Instruction and interrupt control regs + */ +@@ -265,6 +288,7 @@ + #define INSTDONE1 0x0207c /* 965+ only */ + #define ACTHD_I965 0x02074 + #define HWS_PGA 0x02080 ++#define HWS_PGA_GEN6 0x04080 + #define HWS_ADDRESS_MASK 0xfffff000 + #define HWS_START_ADDRESS_SHIFT 4 + #define PWRCTXA 0x2088 /* 965GM+ only */ +@@ -274,6 +298,10 @@ + #define INSTDONE 0x02090 + #define NOPID 0x02094 + #define HWSTAM 0x02098 ++ ++#define MI_MODE 0x0209c ++# define VS_TIMER_DISPATCH (1 << 6) ++ + #define SCPD0 0x0209c /* 915+ only */ + #define IER 0x020a0 + #define IIR 0x020a4 +@@ -282,7 +310,7 @@ + #define I915_PIPE_CONTROL_NOTIFY_INTERRUPT (1<<18) + #define I915_DISPLAY_PORT_INTERRUPT (1<<17) + #define I915_RENDER_COMMAND_PARSER_ERROR_INTERRUPT (1<<15) +-#define I915_GMCH_THERMAL_SENSOR_EVENT_INTERRUPT (1<<14) ++#define I915_GMCH_THERMAL_SENSOR_EVENT_INTERRUPT (1<<14) /* p-state */ + #define I915_HWB_OOM_INTERRUPT (1<<13) + #define I915_SYNC_STATUS_INTERRUPT (1<<12) + #define I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT (1<<11) +@@ -306,11 +334,14 @@ + #define I915_ERROR_MEMORY_REFRESH (1<<1) + #define I915_ERROR_INSTRUCTION (1<<0) + #define INSTPM 0x020c0 ++#define INSTPM_SELF_EN (1<<12) /* 915GM only */ + #define ACTHD 0x020c8 + #define FW_BLC 0x020d8 + #define FW_BLC2 0x020dc + #define FW_BLC_SELF 0x020e0 /* 915+ only */ +-#define FW_BLC_SELF_EN (1<<15) ++#define FW_BLC_SELF_EN_MASK (1<<31) ++#define FW_BLC_SELF_FIFO_MASK (1<<16) /* 945 only */ ++#define FW_BLC_SELF_EN (1<<15) /* 945 only */ + #define MM_BURST_LENGTH 0x00700000 + #define MM_FIFO_WATERMARK 0x0001F000 + #define LM_BURST_LENGTH 0x00000700 +@@ -324,6 +355,7 @@ + #define CM0_COLOR_EVICT_DISABLE (1<<3) + #define CM0_DEPTH_WRITE_DISABLE (1<<1) + #define CM0_RC_OP_FLUSH_DISABLE (1<<0) ++#define BB_ADDR 0x02140 /* 8 bytes */ + #define GFX_FLSH_CNTL 0x02170 /* 915+ only */ + + +@@ -338,7 +370,7 @@ + #define FBC_CTL_PERIODIC (1<<30) + #define FBC_CTL_INTERVAL_SHIFT (16) + #define FBC_CTL_UNCOMPRESSIBLE (1<<14) +-#define FBC_C3_IDLE (1<<13) ++#define FBC_CTL_C3_IDLE (1<<13) + #define FBC_CTL_STRIDE_SHIFT (5) + #define FBC_CTL_FENCENO (1<<0) + #define FBC_COMMAND 0x0320c +@@ -784,10 +816,144 @@ + #define CLKCFG_MEM_800 (3 << 4) + #define CLKCFG_MEM_MASK (7 << 4) + +-/** GM965 GM45 render standby register */ +-#define MCHBAR_RENDER_STANDBY 0x111B8 ++#define CRSTANDVID 0x11100 ++#define PXVFREQ_BASE 0x11110 /* P[0-15]VIDFREQ (0x1114c) (Ironlake) */ ++#define PXVFREQ_PX_MASK 0x7f000000 ++#define PXVFREQ_PX_SHIFT 24 ++#define VIDFREQ_BASE 0x11110 ++#define VIDFREQ1 0x11110 /* VIDFREQ1-4 (0x1111c) (Cantiga) */ ++#define VIDFREQ2 0x11114 ++#define VIDFREQ3 0x11118 ++#define VIDFREQ4 0x1111c ++#define VIDFREQ_P0_MASK 0x1f000000 ++#define VIDFREQ_P0_SHIFT 24 ++#define VIDFREQ_P0_CSCLK_MASK 0x00f00000 ++#define VIDFREQ_P0_CSCLK_SHIFT 20 ++#define VIDFREQ_P0_CRCLK_MASK 0x000f0000 ++#define VIDFREQ_P0_CRCLK_SHIFT 16 ++#define VIDFREQ_P1_MASK 0x00001f00 ++#define VIDFREQ_P1_SHIFT 8 ++#define VIDFREQ_P1_CSCLK_MASK 0x000000f0 ++#define VIDFREQ_P1_CSCLK_SHIFT 4 ++#define VIDFREQ_P1_CRCLK_MASK 0x0000000f ++#define INTTOEXT_BASE_ILK 0x11300 ++#define INTTOEXT_BASE 0x11120 /* INTTOEXT1-8 (0x1113c) */ ++#define INTTOEXT_MAP3_SHIFT 24 ++#define INTTOEXT_MAP3_MASK (0x1f << INTTOEXT_MAP3_SHIFT) ++#define INTTOEXT_MAP2_SHIFT 16 ++#define INTTOEXT_MAP2_MASK (0x1f << INTTOEXT_MAP2_SHIFT) ++#define INTTOEXT_MAP1_SHIFT 8 ++#define INTTOEXT_MAP1_MASK (0x1f << INTTOEXT_MAP1_SHIFT) ++#define INTTOEXT_MAP0_SHIFT 0 ++#define INTTOEXT_MAP0_MASK (0x1f << INTTOEXT_MAP0_SHIFT) ++#define MEMSWCTL 0x11170 /* Ironlake only */ ++#define MEMCTL_CMD_MASK 0xe000 ++#define MEMCTL_CMD_SHIFT 13 ++#define MEMCTL_CMD_RCLK_OFF 0 ++#define MEMCTL_CMD_RCLK_ON 1 ++#define MEMCTL_CMD_CHFREQ 2 ++#define MEMCTL_CMD_CHVID 3 ++#define MEMCTL_CMD_VMMOFF 4 ++#define MEMCTL_CMD_VMMON 5 ++#define MEMCTL_CMD_STS (1<<12) /* write 1 triggers command, clears ++ when command complete */ ++#define MEMCTL_FREQ_MASK 0x0f00 /* jitter, from 0-15 */ ++#define MEMCTL_FREQ_SHIFT 8 ++#define MEMCTL_SFCAVM (1<<7) ++#define MEMCTL_TGT_VID_MASK 0x007f ++#define MEMIHYST 0x1117c ++#define MEMINTREN 0x11180 /* 16 bits */ ++#define MEMINT_RSEXIT_EN (1<<8) ++#define MEMINT_CX_SUPR_EN (1<<7) ++#define MEMINT_CONT_BUSY_EN (1<<6) ++#define MEMINT_AVG_BUSY_EN (1<<5) ++#define MEMINT_EVAL_CHG_EN (1<<4) ++#define MEMINT_MON_IDLE_EN (1<<3) ++#define MEMINT_UP_EVAL_EN (1<<2) ++#define MEMINT_DOWN_EVAL_EN (1<<1) ++#define MEMINT_SW_CMD_EN (1<<0) ++#define MEMINTRSTR 0x11182 /* 16 bits */ ++#define MEM_RSEXIT_MASK 0xc000 ++#define MEM_RSEXIT_SHIFT 14 ++#define MEM_CONT_BUSY_MASK 0x3000 ++#define MEM_CONT_BUSY_SHIFT 12 ++#define MEM_AVG_BUSY_MASK 0x0c00 ++#define MEM_AVG_BUSY_SHIFT 10 ++#define MEM_EVAL_CHG_MASK 0x0300 ++#define MEM_EVAL_BUSY_SHIFT 8 ++#define MEM_MON_IDLE_MASK 0x00c0 ++#define MEM_MON_IDLE_SHIFT 6 ++#define MEM_UP_EVAL_MASK 0x0030 ++#define MEM_UP_EVAL_SHIFT 4 ++#define MEM_DOWN_EVAL_MASK 0x000c ++#define MEM_DOWN_EVAL_SHIFT 2 ++#define MEM_SW_CMD_MASK 0x0003 ++#define MEM_INT_STEER_GFX 0 ++#define MEM_INT_STEER_CMR 1 ++#define MEM_INT_STEER_SMI 2 ++#define MEM_INT_STEER_SCI 3 ++#define MEMINTRSTS 0x11184 ++#define MEMINT_RSEXIT (1<<7) ++#define MEMINT_CONT_BUSY (1<<6) ++#define MEMINT_AVG_BUSY (1<<5) ++#define MEMINT_EVAL_CHG (1<<4) ++#define MEMINT_MON_IDLE (1<<3) ++#define MEMINT_UP_EVAL (1<<2) ++#define MEMINT_DOWN_EVAL (1<<1) ++#define MEMINT_SW_CMD (1<<0) ++#define MEMMODECTL 0x11190 ++#define MEMMODE_BOOST_EN (1<<31) ++#define MEMMODE_BOOST_FREQ_MASK 0x0f000000 /* jitter for boost, 0-15 */ ++#define MEMMODE_BOOST_FREQ_SHIFT 24 ++#define MEMMODE_IDLE_MODE_MASK 0x00030000 ++#define MEMMODE_IDLE_MODE_SHIFT 16 ++#define MEMMODE_IDLE_MODE_EVAL 0 ++#define MEMMODE_IDLE_MODE_CONT 1 ++#define MEMMODE_HWIDLE_EN (1<<15) ++#define MEMMODE_SWMODE_EN (1<<14) ++#define MEMMODE_RCLK_GATE (1<<13) ++#define MEMMODE_HW_UPDATE (1<<12) ++#define MEMMODE_FSTART_MASK 0x00000f00 /* starting jitter, 0-15 */ ++#define MEMMODE_FSTART_SHIFT 8 ++#define MEMMODE_FMAX_MASK 0x000000f0 /* max jitter, 0-15 */ ++#define MEMMODE_FMAX_SHIFT 4 ++#define MEMMODE_FMIN_MASK 0x0000000f /* min jitter, 0-15 */ ++#define RCBMAXAVG 0x1119c ++#define MEMSWCTL2 0x1119e /* Cantiga only */ ++#define SWMEMCMD_RENDER_OFF (0 << 13) ++#define SWMEMCMD_RENDER_ON (1 << 13) ++#define SWMEMCMD_SWFREQ (2 << 13) ++#define SWMEMCMD_TARVID (3 << 13) ++#define SWMEMCMD_VRM_OFF (4 << 13) ++#define SWMEMCMD_VRM_ON (5 << 13) ++#define CMDSTS (1<<12) ++#define SFCAVM (1<<11) ++#define SWFREQ_MASK 0x0380 /* P0-7 */ ++#define SWFREQ_SHIFT 7 ++#define TARVID_MASK 0x001f ++#define MEMSTAT_CTG 0x111a0 ++#define RCBMINAVG 0x111a0 ++#define RCUPEI 0x111b0 ++#define RCDNEI 0x111b4 ++#define MCHBAR_RENDER_STANDBY 0x111b8 + #define RCX_SW_EXIT (1<<23) + #define RSX_STATUS_MASK 0x00700000 ++#define VIDCTL 0x111c0 ++#define VIDSTS 0x111c8 ++#define VIDSTART 0x111cc /* 8 bits */ ++#define MEMSTAT_ILK 0x111f8 ++#define MEMSTAT_VID_MASK 0x7f00 ++#define MEMSTAT_VID_SHIFT 8 ++#define MEMSTAT_PSTATE_MASK 0x00f8 ++#define MEMSTAT_PSTATE_SHIFT 3 ++#define MEMSTAT_MON_ACTV (1<<2) ++#define MEMSTAT_SRC_CTL_MASK 0x0003 ++#define MEMSTAT_SRC_CTL_CORE 0 ++#define MEMSTAT_SRC_CTL_TRB 1 ++#define MEMSTAT_SRC_CTL_THM 2 ++#define MEMSTAT_SRC_CTL_STDBY 3 ++#define RCPREVBSYTUPAVG 0x113b8 ++#define RCPREVBSYTDNAVG 0x113bc + #define PEG_BAND_GAP_DATA 0x14d68 + + /* +@@ -1588,6 +1754,14 @@ + #define DP_LINK_TRAIN_MASK (3 << 28) + #define DP_LINK_TRAIN_SHIFT 28 + ++/* CPT Link training mode */ ++#define DP_LINK_TRAIN_PAT_1_CPT (0 << 8) ++#define DP_LINK_TRAIN_PAT_2_CPT (1 << 8) ++#define DP_LINK_TRAIN_PAT_IDLE_CPT (2 << 8) ++#define DP_LINK_TRAIN_OFF_CPT (3 << 8) ++#define DP_LINK_TRAIN_MASK_CPT (7 << 8) ++#define DP_LINK_TRAIN_SHIFT_CPT 8 ++ + /* Signal voltages. These are mostly controlled by the other end */ + #define DP_VOLTAGE_0_4 (0 << 25) + #define DP_VOLTAGE_0_6 (1 << 25) +@@ -1812,15 +1986,24 @@ + + #define DSPFW1 0x70034 + #define DSPFW_SR_SHIFT 23 ++#define DSPFW_SR_MASK (0x1ff<<23) + #define DSPFW_CURSORB_SHIFT 16 ++#define DSPFW_CURSORB_MASK (0x3f<<16) + #define DSPFW_PLANEB_SHIFT 8 ++#define DSPFW_PLANEB_MASK (0x7f<<8) ++#define DSPFW_PLANEA_MASK (0x7f) + #define DSPFW2 0x70038 + #define DSPFW_CURSORA_MASK 0x00003f00 + #define DSPFW_CURSORA_SHIFT 8 ++#define DSPFW_PLANEC_MASK (0x7f) + #define DSPFW3 0x7003c + #define DSPFW_HPLL_SR_EN (1<<31) + #define DSPFW_CURSOR_SR_SHIFT 24 + #define PINEVIEW_SELF_REFRESH_EN (1<<30) ++#define DSPFW_CURSOR_SR_MASK (0x3f<<24) ++#define DSPFW_HPLL_CURSOR_SHIFT 16 ++#define DSPFW_HPLL_CURSOR_MASK (0x3f<<16) ++#define DSPFW_HPLL_SR_MASK (0x1ff) + + /* FIFO watermark sizes etc */ + #define G4X_FIFO_LINE_SIZE 64 +@@ -1847,6 +2030,43 @@ + #define PINEVIEW_CURSOR_DFT_WM 0 + #define PINEVIEW_CURSOR_GUARD_WM 5 + ++ ++/* define the Watermark register on Ironlake */ ++#define WM0_PIPEA_ILK 0x45100 ++#define WM0_PIPE_PLANE_MASK (0x7f<<16) ++#define WM0_PIPE_PLANE_SHIFT 16 ++#define WM0_PIPE_SPRITE_MASK (0x3f<<8) ++#define WM0_PIPE_SPRITE_SHIFT 8 ++#define WM0_PIPE_CURSOR_MASK (0x1f) ++ ++#define WM0_PIPEB_ILK 0x45104 ++#define WM1_LP_ILK 0x45108 ++#define WM1_LP_SR_EN (1<<31) ++#define WM1_LP_LATENCY_SHIFT 24 ++#define WM1_LP_LATENCY_MASK (0x7f<<24) ++#define WM1_LP_SR_MASK (0x1ff<<8) ++#define WM1_LP_SR_SHIFT 8 ++#define WM1_LP_CURSOR_MASK (0x3f) ++ ++/* Memory latency timer register */ ++#define MLTR_ILK 0x11222 ++/* the unit of memory self-refresh latency time is 0.5us */ ++#define ILK_SRLT_MASK 0x3f ++ ++/* define the fifo size on Ironlake */ ++#define ILK_DISPLAY_FIFO 128 ++#define ILK_DISPLAY_MAXWM 64 ++#define ILK_DISPLAY_DFTWM 8 ++ ++#define ILK_DISPLAY_SR_FIFO 512 ++#define ILK_DISPLAY_MAX_SRWM 0x1ff ++#define ILK_DISPLAY_DFT_SRWM 0x3f ++#define ILK_CURSOR_SR_FIFO 64 ++#define ILK_CURSOR_MAX_SRWM 0x3f ++#define ILK_CURSOR_DFT_SRWM 8 ++ ++#define ILK_FIFO_LINE_SIZE 64 ++ + /* + * The two pipe frame counter registers are not synchronized, so + * reading a stable value is somewhat tricky. The following code +@@ -2010,6 +2230,14 @@ + #define DISPLAY_PORT_PLL_BIOS_1 0x46010 + #define DISPLAY_PORT_PLL_BIOS_2 0x46014 + ++#define PCH_DSPCLK_GATE_D 0x42020 ++# define DPFDUNIT_CLOCK_GATE_DISABLE (1 << 7) ++# define DPARBUNIT_CLOCK_GATE_DISABLE (1 << 5) ++ ++#define PCH_3DCGDIS0 0x46020 ++# define MARIUNIT_CLOCK_GATE_DISABLE (1 << 18) ++# define SVSMUNIT_CLOCK_GATE_DISABLE (1 << 1) ++ + #define FDI_PLL_FREQ_CTL 0x46030 + #define FDI_PLL_FREQ_CHANGE_REQUEST (1<<24) + #define FDI_PLL_FREQ_LOCK_LIMIT_MASK 0xfff00 +@@ -2119,8 +2347,15 @@ + #define GTIIR 0x44018 + #define GTIER 0x4401c + ++#define ILK_DISPLAY_CHICKEN2 0x42004 ++#define ILK_DPARB_GATE (1<<22) ++#define ILK_VSDPFD_FULL (1<<21) ++#define ILK_DSPCLK_GATE 0x42020 ++#define ILK_DPARB_CLK_GATE (1<<5) ++ + #define DISP_ARB_CTL 0x45000 + #define DISP_TILE_SURFACE_SWIZZLING (1<<13) ++#define DISP_FBC_WM_DIS (1<<15) + + /* PCH */ + +@@ -2131,6 +2366,11 @@ + #define SDE_PORTB_HOTPLUG (1 << 8) + #define SDE_SDVOB_HOTPLUG (1 << 6) + #define SDE_HOTPLUG_MASK (0xf << 8) ++/* CPT */ ++#define SDE_CRT_HOTPLUG_CPT (1 << 19) ++#define SDE_PORTD_HOTPLUG_CPT (1 << 23) ++#define SDE_PORTC_HOTPLUG_CPT (1 << 22) ++#define SDE_PORTB_HOTPLUG_CPT (1 << 21) + + #define SDEISR 0xc4000 + #define SDEIMR 0xc4004 +@@ -2222,6 +2462,17 @@ + #define PCH_SSC4_PARMS 0xc6210 + #define PCH_SSC4_AUX_PARMS 0xc6214 + ++#define PCH_DPLL_SEL 0xc7000 ++#define TRANSA_DPLL_ENABLE (1<<3) ++#define TRANSA_DPLLB_SEL (1<<0) ++#define TRANSA_DPLLA_SEL 0 ++#define TRANSB_DPLL_ENABLE (1<<7) ++#define TRANSB_DPLLB_SEL (1<<4) ++#define TRANSB_DPLLA_SEL (0) ++#define TRANSC_DPLL_ENABLE (1<<11) ++#define TRANSC_DPLLB_SEL (1<<8) ++#define TRANSC_DPLLA_SEL (0) ++ + /* transcoder */ + + #define TRANS_HTOTAL_A 0xe0000 +@@ -2308,6 +2559,19 @@ + #define FDI_LINK_TRAIN_PRE_EMPHASIS_1_5X (1<<22) + #define FDI_LINK_TRAIN_PRE_EMPHASIS_2X (2<<22) + #define FDI_LINK_TRAIN_PRE_EMPHASIS_3X (3<<22) ++/* ILK always use 400mV 0dB for voltage swing and pre-emphasis level. ++ SNB has different settings. */ ++/* SNB A-stepping */ ++#define FDI_LINK_TRAIN_400MV_0DB_SNB_A (0x38<<22) ++#define FDI_LINK_TRAIN_400MV_6DB_SNB_A (0x02<<22) ++#define FDI_LINK_TRAIN_600MV_3_5DB_SNB_A (0x01<<22) ++#define FDI_LINK_TRAIN_800MV_0DB_SNB_A (0x0<<22) ++/* SNB B-stepping */ ++#define FDI_LINK_TRAIN_400MV_0DB_SNB_B (0x0<<22) ++#define FDI_LINK_TRAIN_400MV_6DB_SNB_B (0x3a<<22) ++#define FDI_LINK_TRAIN_600MV_3_5DB_SNB_B (0x39<<22) ++#define FDI_LINK_TRAIN_800MV_0DB_SNB_B (0x38<<22) ++#define FDI_LINK_TRAIN_VOL_EMP_MASK (0x3f<<22) + #define FDI_DP_PORT_WIDTH_X1 (0<<19) + #define FDI_DP_PORT_WIDTH_X2 (1<<19) + #define FDI_DP_PORT_WIDTH_X3 (2<<19) +@@ -2340,6 +2604,13 @@ + #define FDI_RX_ENHANCE_FRAME_ENABLE (1<<6) + #define FDI_SEL_RAWCLK (0<<4) + #define FDI_SEL_PCDCLK (1<<4) ++/* CPT */ ++#define FDI_AUTO_TRAINING (1<<10) ++#define FDI_LINK_TRAIN_PATTERN_1_CPT (0<<8) ++#define FDI_LINK_TRAIN_PATTERN_2_CPT (1<<8) ++#define FDI_LINK_TRAIN_PATTERN_IDLE_CPT (2<<8) ++#define FDI_LINK_TRAIN_NORMAL_CPT (3<<8) ++#define FDI_LINK_TRAIN_PATTERN_MASK_CPT (3<<8) + + #define FDI_RXA_MISC 0xf0010 + #define FDI_RXB_MISC 0xf1010 +@@ -2411,6 +2682,9 @@ + #define HSYNC_ACTIVE_HIGH (1 << 3) + #define PORT_DETECTED (1 << 2) + ++/* PCH SDVOB multiplex with HDMIB */ ++#define PCH_SDVOB HDMIB ++ + #define HDMIC 0xe1150 + #define HDMID 0xe1160 + +@@ -2468,4 +2742,42 @@ + #define PCH_DPD_AUX_CH_DATA4 0xe4320 + #define PCH_DPD_AUX_CH_DATA5 0xe4324 + ++/* CPT */ ++#define PORT_TRANS_A_SEL_CPT 0 ++#define PORT_TRANS_B_SEL_CPT (1<<29) ++#define PORT_TRANS_C_SEL_CPT (2<<29) ++#define PORT_TRANS_SEL_MASK (3<<29) ++ ++#define TRANS_DP_CTL_A 0xe0300 ++#define TRANS_DP_CTL_B 0xe1300 ++#define TRANS_DP_CTL_C 0xe2300 ++#define TRANS_DP_OUTPUT_ENABLE (1<<31) ++#define TRANS_DP_PORT_SEL_B (0<<29) ++#define TRANS_DP_PORT_SEL_C (1<<29) ++#define TRANS_DP_PORT_SEL_D (2<<29) ++#define TRANS_DP_PORT_SEL_MASK (3<<29) ++#define TRANS_DP_AUDIO_ONLY (1<<26) ++#define TRANS_DP_ENH_FRAMING (1<<18) ++#define TRANS_DP_8BPC (0<<9) ++#define TRANS_DP_10BPC (1<<9) ++#define TRANS_DP_6BPC (2<<9) ++#define TRANS_DP_12BPC (3<<9) ++#define TRANS_DP_VSYNC_ACTIVE_HIGH (1<<4) ++#define TRANS_DP_VSYNC_ACTIVE_LOW 0 ++#define TRANS_DP_HSYNC_ACTIVE_HIGH (1<<3) ++#define TRANS_DP_HSYNC_ACTIVE_LOW 0 ++ ++/* SNB eDP training params */ ++/* SNB A-stepping */ ++#define EDP_LINK_TRAIN_400MV_0DB_SNB_A (0x38<<22) ++#define EDP_LINK_TRAIN_400MV_6DB_SNB_A (0x02<<22) ++#define EDP_LINK_TRAIN_600MV_3_5DB_SNB_A (0x01<<22) ++#define EDP_LINK_TRAIN_800MV_0DB_SNB_A (0x0<<22) ++/* SNB B-stepping */ ++#define EDP_LINK_TRAIN_400MV_0DB_SNB_B (0x0<<22) ++#define EDP_LINK_TRAIN_400MV_6DB_SNB_B (0x3a<<22) ++#define EDP_LINK_TRAIN_600MV_3_5DB_SNB_B (0x39<<22) ++#define EDP_LINK_TRAIN_800MV_0DB_SNB_B (0x38<<22) ++#define EDP_LINK_TRAIN_VOL_EMP_MASK_SNB (0x3f<<22) ++ + #endif /* _I915_REG_H_ */ +diff --git a/drivers/gpu/drm/i915/i915_suspend.c b/drivers/gpu/drm/i915/i915_suspend.c +--- a/drivers/gpu/drm/i915/i915_suspend.c ++++ b/drivers/gpu/drm/i915/i915_suspend.c +@@ -600,14 +600,16 @@ void i915_save_display(struct drm_device *dev) + } + /* FIXME: save TV & SDVO state */ + +- /* FBC state */ +- if (IS_GM45(dev)) { +- dev_priv->saveDPFC_CB_BASE = I915_READ(DPFC_CB_BASE); +- } else { +- dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE); +- dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE); +- dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2); +- dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL); ++ /* Only save FBC state on the platform that supports FBC */ ++ if (I915_HAS_FBC(dev)) { ++ if (IS_GM45(dev)) { ++ dev_priv->saveDPFC_CB_BASE = I915_READ(DPFC_CB_BASE); ++ } else { ++ dev_priv->saveFBC_CFB_BASE = I915_READ(FBC_CFB_BASE); ++ dev_priv->saveFBC_LL_BASE = I915_READ(FBC_LL_BASE); ++ dev_priv->saveFBC_CONTROL2 = I915_READ(FBC_CONTROL2); ++ dev_priv->saveFBC_CONTROL = I915_READ(FBC_CONTROL); ++ } + } + + /* VGA state */ +@@ -682,6 +684,8 @@ void i915_restore_display(struct drm_device *dev) + I915_WRITE(PCH_PP_OFF_DELAYS, dev_priv->savePP_OFF_DELAYS); + I915_WRITE(PCH_PP_DIVISOR, dev_priv->savePP_DIVISOR); + I915_WRITE(PCH_PP_CONTROL, dev_priv->savePP_CONTROL); ++ I915_WRITE(MCHBAR_RENDER_STANDBY, ++ dev_priv->saveMCHBAR_RENDER_STANDBY); + } else { + I915_WRITE(PFIT_PGM_RATIOS, dev_priv->savePFIT_PGM_RATIOS); + I915_WRITE(BLC_PWM_CTL, dev_priv->saveBLC_PWM_CTL); +@@ -700,18 +704,19 @@ void i915_restore_display(struct drm_device *dev) + } + /* FIXME: restore TV & SDVO state */ + +- /* FBC info */ +- if (IS_GM45(dev)) { +- g4x_disable_fbc(dev); +- I915_WRITE(DPFC_CB_BASE, dev_priv->saveDPFC_CB_BASE); +- } else { +- i8xx_disable_fbc(dev); +- I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE); +- I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE); +- I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2); +- I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL); ++ /* only restore FBC info on the platform that supports FBC*/ ++ if (I915_HAS_FBC(dev)) { ++ if (IS_GM45(dev)) { ++ g4x_disable_fbc(dev); ++ I915_WRITE(DPFC_CB_BASE, dev_priv->saveDPFC_CB_BASE); ++ } else { ++ i8xx_disable_fbc(dev); ++ I915_WRITE(FBC_CFB_BASE, dev_priv->saveFBC_CFB_BASE); ++ I915_WRITE(FBC_LL_BASE, dev_priv->saveFBC_LL_BASE); ++ I915_WRITE(FBC_CONTROL2, dev_priv->saveFBC_CONTROL2); ++ I915_WRITE(FBC_CONTROL, dev_priv->saveFBC_CONTROL); ++ } + } +- + /* VGA state */ + if (IS_IRONLAKE(dev)) + I915_WRITE(CPU_VGACNTRL, dev_priv->saveVGACNTRL); +@@ -745,11 +750,16 @@ int i915_save_state(struct drm_device *dev) + dev_priv->saveGTIMR = I915_READ(GTIMR); + dev_priv->saveFDI_RXA_IMR = I915_READ(FDI_RXA_IMR); + dev_priv->saveFDI_RXB_IMR = I915_READ(FDI_RXB_IMR); ++ dev_priv->saveMCHBAR_RENDER_STANDBY = ++ I915_READ(MCHBAR_RENDER_STANDBY); + } else { + dev_priv->saveIER = I915_READ(IER); + dev_priv->saveIMR = I915_READ(IMR); + } + ++ if (IS_IRONLAKE_M(dev)) ++ ironlake_disable_drps(dev); ++ + /* Cache mode state */ + dev_priv->saveCACHE_MODE_0 = I915_READ(CACHE_MODE_0); + +@@ -820,6 +830,9 @@ int i915_restore_state(struct drm_device *dev) + /* Clock gating state */ + intel_init_clock_gating(dev); + ++ if (IS_IRONLAKE_M(dev)) ++ ironlake_enable_drps(dev); ++ + /* Cache mode state */ + I915_WRITE (CACHE_MODE_0, dev_priv->saveCACHE_MODE_0 | 0xffff0000); + +diff --git a/drivers/gpu/drm/i915/i915_trace.h b/drivers/gpu/drm/i915/i915_trace.h +--- a/drivers/gpu/drm/i915/i915_trace.h ++++ b/drivers/gpu/drm/i915/i915_trace.h +@@ -115,7 +115,7 @@ TRACE_EVENT(i915_gem_object_get_fence, + __entry->obj, __entry->fence, __entry->tiling_mode) + ); + +-TRACE_EVENT(i915_gem_object_unbind, ++DECLARE_EVENT_CLASS(i915_gem_object, + + TP_PROTO(struct drm_gem_object *obj), + +@@ -132,21 +132,18 @@ TRACE_EVENT(i915_gem_object_unbind, + TP_printk("obj=%p", __entry->obj) + ); + +-TRACE_EVENT(i915_gem_object_destroy, ++DEFINE_EVENT(i915_gem_object, i915_gem_object_unbind, + + TP_PROTO(struct drm_gem_object *obj), + +- TP_ARGS(obj), ++ TP_ARGS(obj) ++); + +- TP_STRUCT__entry( +- __field(struct drm_gem_object *, obj) +- ), ++DEFINE_EVENT(i915_gem_object, i915_gem_object_destroy, + +- TP_fast_assign( +- __entry->obj = obj; +- ), ++ TP_PROTO(struct drm_gem_object *obj), + +- TP_printk("obj=%p", __entry->obj) ++ TP_ARGS(obj) + ); + + /* batch tracing */ +@@ -197,8 +194,7 @@ TRACE_EVENT(i915_gem_request_flush, + __entry->flush_domains, __entry->invalidate_domains) + ); + +- +-TRACE_EVENT(i915_gem_request_complete, ++DECLARE_EVENT_CLASS(i915_gem_request, + + TP_PROTO(struct drm_device *dev, u32 seqno), + +@@ -217,64 +213,35 @@ TRACE_EVENT(i915_gem_request_complete, + TP_printk("dev=%u, seqno=%u", __entry->dev, __entry->seqno) + ); + +-TRACE_EVENT(i915_gem_request_retire, ++DEFINE_EVENT(i915_gem_request, i915_gem_request_complete, + + TP_PROTO(struct drm_device *dev, u32 seqno), + +- TP_ARGS(dev, seqno), +- +- TP_STRUCT__entry( +- __field(u32, dev) +- __field(u32, seqno) +- ), +- +- TP_fast_assign( +- __entry->dev = dev->primary->index; +- __entry->seqno = seqno; +- ), +- +- TP_printk("dev=%u, seqno=%u", __entry->dev, __entry->seqno) ++ TP_ARGS(dev, seqno) + ); + +-TRACE_EVENT(i915_gem_request_wait_begin, ++DEFINE_EVENT(i915_gem_request, i915_gem_request_retire, + + TP_PROTO(struct drm_device *dev, u32 seqno), + +- TP_ARGS(dev, seqno), +- +- TP_STRUCT__entry( +- __field(u32, dev) +- __field(u32, seqno) +- ), +- +- TP_fast_assign( +- __entry->dev = dev->primary->index; +- __entry->seqno = seqno; +- ), +- +- TP_printk("dev=%u, seqno=%u", __entry->dev, __entry->seqno) ++ TP_ARGS(dev, seqno) + ); + +-TRACE_EVENT(i915_gem_request_wait_end, ++DEFINE_EVENT(i915_gem_request, i915_gem_request_wait_begin, + + TP_PROTO(struct drm_device *dev, u32 seqno), + +- TP_ARGS(dev, seqno), ++ TP_ARGS(dev, seqno) ++); + +- TP_STRUCT__entry( +- __field(u32, dev) +- __field(u32, seqno) +- ), ++DEFINE_EVENT(i915_gem_request, i915_gem_request_wait_end, + +- TP_fast_assign( +- __entry->dev = dev->primary->index; +- __entry->seqno = seqno; +- ), ++ TP_PROTO(struct drm_device *dev, u32 seqno), + +- TP_printk("dev=%u, seqno=%u", __entry->dev, __entry->seqno) ++ TP_ARGS(dev, seqno) + ); + +-TRACE_EVENT(i915_ring_wait_begin, ++DECLARE_EVENT_CLASS(i915_ring, + + TP_PROTO(struct drm_device *dev), + +@@ -291,21 +258,18 @@ TRACE_EVENT(i915_ring_wait_begin, + TP_printk("dev=%u", __entry->dev) + ); + +-TRACE_EVENT(i915_ring_wait_end, ++DEFINE_EVENT(i915_ring, i915_ring_wait_begin, + + TP_PROTO(struct drm_device *dev), + +- TP_ARGS(dev), ++ TP_ARGS(dev) ++); + +- TP_STRUCT__entry( +- __field(u32, dev) +- ), ++DEFINE_EVENT(i915_ring, i915_ring_wait_end, + +- TP_fast_assign( +- __entry->dev = dev->primary->index; +- ), ++ TP_PROTO(struct drm_device *dev), + +- TP_printk("dev=%u", __entry->dev) ++ TP_ARGS(dev) + ); + + #endif /* _I915_TRACE_H_ */ +diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c +--- a/drivers/gpu/drm/i915/intel_bios.c ++++ b/drivers/gpu/drm/i915/intel_bios.c +@@ -247,6 +247,7 @@ static void + parse_general_features(struct drm_i915_private *dev_priv, + struct bdb_header *bdb) + { ++ struct drm_device *dev = dev_priv->dev; + struct bdb_general_features *general; + + /* Set sensible defaults in case we can't find the general block */ +@@ -263,7 +264,7 @@ parse_general_features(struct drm_i915_private *dev_priv, + if (IS_I85X(dev_priv->dev)) + dev_priv->lvds_ssc_freq = + general->ssc_freq ? 66 : 48; +- else if (IS_IRONLAKE(dev_priv->dev)) ++ else if (IS_IRONLAKE(dev_priv->dev) || IS_GEN6(dev)) + dev_priv->lvds_ssc_freq = + general->ssc_freq ? 100 : 120; + else +@@ -416,8 +417,9 @@ parse_edp(struct drm_i915_private *dev_priv, struct bdb_header *bdb) + edp = find_section(bdb, BDB_EDP); + if (!edp) { + if (SUPPORTS_EDP(dev_priv->dev) && dev_priv->edp_support) { +- DRM_DEBUG_KMS("No eDP BDB found but eDP panel supported,\ +- assume 18bpp panel color depth.\n"); ++ DRM_DEBUG_KMS("No eDP BDB found but eDP panel " ++ "supported, assume 18bpp panel color " ++ "depth.\n"); + dev_priv->edp_bpp = 18; + } + return; +diff --git a/drivers/gpu/drm/i915/intel_crt.c b/drivers/gpu/drm/i915/intel_crt.c +--- a/drivers/gpu/drm/i915/intel_crt.c ++++ b/drivers/gpu/drm/i915/intel_crt.c +@@ -39,7 +39,7 @@ static void intel_crt_dpms(struct drm_encoder *encoder, int mode) + struct drm_i915_private *dev_priv = dev->dev_private; + u32 temp, reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + reg = PCH_ADPA; + else + reg = ADPA; +@@ -113,7 +113,7 @@ static void intel_crt_mode_set(struct drm_encoder *encoder, + else + dpll_md_reg = DPLL_B_MD; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + adpa_reg = PCH_ADPA; + else + adpa_reg = ADPA; +@@ -122,7 +122,7 @@ static void intel_crt_mode_set(struct drm_encoder *encoder, + * Disable separate mode multiplier used when cloning SDVO to CRT + * XXX this needs to be adjusted when we really are cloning + */ +- if (IS_I965G(dev) && !IS_IRONLAKE(dev)) { ++ if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) { + dpll_md = I915_READ(dpll_md_reg); + I915_WRITE(dpll_md_reg, + dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK); +@@ -135,12 +135,18 @@ static void intel_crt_mode_set(struct drm_encoder *encoder, + adpa |= ADPA_VSYNC_ACTIVE_HIGH; + + if (intel_crtc->pipe == 0) { +- adpa |= ADPA_PIPE_A_SELECT; +- if (!IS_IRONLAKE(dev)) ++ if (HAS_PCH_CPT(dev)) ++ adpa |= PORT_TRANS_A_SEL_CPT; ++ else ++ adpa |= ADPA_PIPE_A_SELECT; ++ if (!HAS_PCH_SPLIT(dev)) + I915_WRITE(BCLRPAT_A, 0); + } else { +- adpa |= ADPA_PIPE_B_SELECT; +- if (!IS_IRONLAKE(dev)) ++ if (HAS_PCH_CPT(dev)) ++ adpa |= PORT_TRANS_B_SEL_CPT; ++ else ++ adpa |= ADPA_PIPE_B_SELECT; ++ if (!HAS_PCH_SPLIT(dev)) + I915_WRITE(BCLRPAT_B, 0); + } + +@@ -151,15 +157,21 @@ static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector) + { + struct drm_device *dev = connector->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- u32 adpa; ++ u32 adpa, temp; + bool ret; + +- adpa = I915_READ(PCH_ADPA); ++ temp = adpa = I915_READ(PCH_ADPA); + +- adpa &= ~ADPA_CRT_HOTPLUG_MASK; +- /* disable HPD first */ +- I915_WRITE(PCH_ADPA, adpa); +- (void)I915_READ(PCH_ADPA); ++ if (HAS_PCH_CPT(dev)) { ++ /* Disable DAC before force detect */ ++ I915_WRITE(PCH_ADPA, adpa & ~ADPA_DAC_ENABLE); ++ (void)I915_READ(PCH_ADPA); ++ } else { ++ adpa &= ~ADPA_CRT_HOTPLUG_MASK; ++ /* disable HPD first */ ++ I915_WRITE(PCH_ADPA, adpa); ++ (void)I915_READ(PCH_ADPA); ++ } + + adpa |= (ADPA_CRT_HOTPLUG_PERIOD_128 | + ADPA_CRT_HOTPLUG_WARMUP_10MS | +@@ -175,6 +187,11 @@ static bool intel_ironlake_crt_detect_hotplug(struct drm_connector *connector) + while ((I915_READ(PCH_ADPA) & ADPA_CRT_HOTPLUG_FORCE_TRIGGER) != 0) + ; + ++ if (HAS_PCH_CPT(dev)) { ++ I915_WRITE(PCH_ADPA, temp); ++ (void)I915_READ(PCH_ADPA); ++ } ++ + /* Check the status to see if both blue and green are on now */ + adpa = I915_READ(PCH_ADPA); + adpa &= ADPA_CRT_HOTPLUG_MONITOR_MASK; +@@ -202,7 +219,7 @@ static bool intel_crt_detect_hotplug(struct drm_connector *connector) + u32 hotplug_en; + int i, tries = 0; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return intel_ironlake_crt_detect_hotplug(connector); + + /* +@@ -244,21 +261,21 @@ static bool intel_crt_detect_hotplug(struct drm_connector *connector) + return false; + } + +-static bool intel_crt_detect_ddc(struct drm_connector *connector) ++static bool intel_crt_detect_ddc(struct drm_encoder *encoder) + { +- struct intel_output *intel_output = to_intel_output(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + + /* CRT should always be at 0, but check anyway */ +- if (intel_output->type != INTEL_OUTPUT_ANALOG) ++ if (intel_encoder->type != INTEL_OUTPUT_ANALOG) + return false; + +- return intel_ddc_probe(intel_output); ++ return intel_ddc_probe(intel_encoder); + } + + static enum drm_connector_status +-intel_crt_load_detect(struct drm_crtc *crtc, struct intel_output *intel_output) ++intel_crt_load_detect(struct drm_crtc *crtc, struct intel_encoder *intel_encoder) + { +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = &intel_encoder->enc; + struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); +@@ -386,8 +403,8 @@ intel_crt_load_detect(struct drm_crtc *crtc, struct intel_output *intel_output) + static enum drm_connector_status intel_crt_detect(struct drm_connector *connector) + { + struct drm_device *dev = connector->dev; +- struct intel_output *intel_output = to_intel_output(connector); +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + struct drm_crtc *crtc; + int dpms_mode; + enum drm_connector_status status; +@@ -399,18 +416,19 @@ static enum drm_connector_status intel_crt_detect(struct drm_connector *connecto + return connector_status_disconnected; + } + +- if (intel_crt_detect_ddc(connector)) ++ if (intel_crt_detect_ddc(encoder)) + return connector_status_connected; + + /* for pre-945g platforms use load detect */ + if (encoder->crtc && encoder->crtc->enabled) { +- status = intel_crt_load_detect(encoder->crtc, intel_output); ++ status = intel_crt_load_detect(encoder->crtc, intel_encoder); + } else { +- crtc = intel_get_load_detect_pipe(intel_output, ++ crtc = intel_get_load_detect_pipe(intel_encoder, connector, + NULL, &dpms_mode); + if (crtc) { +- status = intel_crt_load_detect(crtc, intel_output); +- intel_release_load_detect_pipe(intel_output, dpms_mode); ++ status = intel_crt_load_detect(crtc, intel_encoder); ++ intel_release_load_detect_pipe(intel_encoder, ++ connector, dpms_mode); + } else + status = connector_status_unknown; + } +@@ -420,9 +438,6 @@ static enum drm_connector_status intel_crt_detect(struct drm_connector *connecto + + static void intel_crt_destroy(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- +- intel_i2c_destroy(intel_output->ddc_bus); + drm_sysfs_connector_remove(connector); + drm_connector_cleanup(connector); + kfree(connector); +@@ -431,29 +446,27 @@ static void intel_crt_destroy(struct drm_connector *connector) + static int intel_crt_get_modes(struct drm_connector *connector) + { + int ret; +- struct intel_output *intel_output = to_intel_output(connector); +- struct i2c_adapter *ddcbus; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct i2c_adapter *ddc_bus; + struct drm_device *dev = connector->dev; + + +- ret = intel_ddc_get_modes(intel_output); ++ ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + if (ret || !IS_G4X(dev)) + goto end; + +- ddcbus = intel_output->ddc_bus; + /* Try to probe digital port for output in DVI-I -> VGA mode. */ +- intel_output->ddc_bus = +- intel_i2c_create(connector->dev, GPIOD, "CRTDDC_D"); ++ ddc_bus = intel_i2c_create(connector->dev, GPIOD, "CRTDDC_D"); + +- if (!intel_output->ddc_bus) { +- intel_output->ddc_bus = ddcbus; ++ if (!ddc_bus) { + dev_printk(KERN_ERR, &connector->dev->pdev->dev, + "DDC bus registration failed for CRTDDC_D.\n"); + goto end; + } + /* Try to get modes by GPIOD port */ +- ret = intel_ddc_get_modes(intel_output); +- intel_i2c_destroy(ddcbus); ++ ret = intel_ddc_get_modes(connector, ddc_bus); ++ intel_i2c_destroy(ddc_bus); + + end: + return ret; +@@ -490,12 +503,16 @@ static const struct drm_connector_funcs intel_crt_connector_funcs = { + static const struct drm_connector_helper_funcs intel_crt_connector_helper_funcs = { + .mode_valid = intel_crt_mode_valid, + .get_modes = intel_crt_get_modes, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static void intel_crt_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ ++ intel_i2c_destroy(intel_encoder->ddc_bus); + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_crt_enc_funcs = { +@@ -505,26 +522,33 @@ static const struct drm_encoder_funcs intel_crt_enc_funcs = { + void intel_crt_init(struct drm_device *dev) + { + struct drm_connector *connector; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; ++ struct intel_connector *intel_connector; + struct drm_i915_private *dev_priv = dev->dev_private; + u32 i2c_reg; + +- intel_output = kzalloc(sizeof(struct intel_output), GFP_KERNEL); +- if (!intel_output) ++ intel_encoder = kzalloc(sizeof(struct intel_encoder), GFP_KERNEL); ++ if (!intel_encoder) + return; + +- connector = &intel_output->base; +- drm_connector_init(dev, &intel_output->base, ++ intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); ++ if (!intel_connector) { ++ kfree(intel_encoder); ++ return; ++ } ++ ++ connector = &intel_connector->base; ++ drm_connector_init(dev, &intel_connector->base, + &intel_crt_connector_funcs, DRM_MODE_CONNECTOR_VGA); + +- drm_encoder_init(dev, &intel_output->enc, &intel_crt_enc_funcs, ++ drm_encoder_init(dev, &intel_encoder->enc, &intel_crt_enc_funcs, + DRM_MODE_ENCODER_DAC); + +- drm_mode_connector_attach_encoder(&intel_output->base, +- &intel_output->enc); ++ drm_mode_connector_attach_encoder(&intel_connector->base, ++ &intel_encoder->enc); + + /* Set up the DDC bus. */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + i2c_reg = PCH_GPIOA; + else { + i2c_reg = GPIOA; +@@ -532,22 +556,22 @@ void intel_crt_init(struct drm_device *dev) + if (dev_priv->crt_ddc_bus != 0) + i2c_reg = dev_priv->crt_ddc_bus; + } +- intel_output->ddc_bus = intel_i2c_create(dev, i2c_reg, "CRTDDC_A"); +- if (!intel_output->ddc_bus) { ++ intel_encoder->ddc_bus = intel_i2c_create(dev, i2c_reg, "CRTDDC_A"); ++ if (!intel_encoder->ddc_bus) { + dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " + "failed.\n"); + return; + } + +- intel_output->type = INTEL_OUTPUT_ANALOG; +- intel_output->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | ++ intel_encoder->type = INTEL_OUTPUT_ANALOG; ++ intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | + (1 << INTEL_ANALOG_CLONE_BIT) | + (1 << INTEL_SDVO_LVDS_CLONE_BIT); +- intel_output->crtc_mask = (1 << 0) | (1 << 1); ++ intel_encoder->crtc_mask = (1 << 0) | (1 << 1); + connector->interlace_allowed = 0; + connector->doublescan_allowed = 0; + +- drm_encoder_helper_add(&intel_output->enc, &intel_crt_helper_funcs); ++ drm_encoder_helper_add(&intel_encoder->enc, &intel_crt_helper_funcs); + drm_connector_helper_add(connector, &intel_crt_connector_helper_funcs); + + drm_sysfs_connector_add(connector); +diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c +--- a/drivers/gpu/drm/i915/intel_display.c ++++ b/drivers/gpu/drm/i915/intel_display.c +@@ -232,7 +232,7 @@ struct intel_limit { + #define G4X_P2_DISPLAY_PORT_FAST 10 + #define G4X_P2_DISPLAY_PORT_LIMIT 0 + +-/* Ironlake */ ++/* Ironlake / Sandybridge */ + /* as we calculate clock using (register_value + 2) for + N/M1/M2, so here the range value for them is (actual_value-2). + */ +@@ -690,7 +690,7 @@ static const intel_limit_t *intel_limit(struct drm_crtc *crtc) + struct drm_device *dev = crtc->dev; + const intel_limit_t *limit; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + limit = intel_ironlake_limit(crtc); + else if (IS_G4X(dev)) { + limit = intel_g4x_limit(crtc); +@@ -741,36 +741,18 @@ bool intel_pipe_has_type (struct drm_crtc *crtc, int type) + { + struct drm_device *dev = crtc->dev; + struct drm_mode_config *mode_config = &dev->mode_config; +- struct drm_connector *l_entry; ++ struct drm_encoder *l_entry; + +- list_for_each_entry(l_entry, &mode_config->connector_list, head) { +- if (l_entry->encoder && +- l_entry->encoder->crtc == crtc) { +- struct intel_output *intel_output = to_intel_output(l_entry); +- if (intel_output->type == type) ++ list_for_each_entry(l_entry, &mode_config->encoder_list, head) { ++ if (l_entry && l_entry->crtc == crtc) { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(l_entry); ++ if (intel_encoder->type == type) + return true; + } + } + return false; + } + +-struct drm_connector * +-intel_pipe_get_output (struct drm_crtc *crtc) +-{ +- struct drm_device *dev = crtc->dev; +- struct drm_mode_config *mode_config = &dev->mode_config; +- struct drm_connector *l_entry, *ret = NULL; +- +- list_for_each_entry(l_entry, &mode_config->connector_list, head) { +- if (l_entry->encoder && +- l_entry->encoder->crtc == crtc) { +- ret = l_entry; +- break; +- } +- } +- return ret; +-} +- + #define INTELPllInvalid(s) do { /* DRM_DEBUG(s); */ return false; } while (0) + /** + * Returns whether the given set of divisors are valid for a given refclk with +@@ -886,7 +868,7 @@ intel_g4x_find_best_PLL(const intel_limit_t *limit, struct drm_crtc *crtc, + if (intel_pipe_has_type(crtc, INTEL_OUTPUT_LVDS)) { + int lvds_reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + lvds_reg = PCH_LVDS; + else + lvds_reg = LVDS; +@@ -1002,7 +984,7 @@ static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_framebuffer *fb = crtc->fb; + struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); +- struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(intel_fb->obj); + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); + int plane, i; + u32 fbc_ctl, fbc_ctl2; +@@ -1032,7 +1014,7 @@ static void i8xx_enable_fbc(struct drm_crtc *crtc, unsigned long interval) + /* enable it... */ + fbc_ctl = FBC_CTL_EN | FBC_CTL_PERIODIC; + if (IS_I945GM(dev)) +- fbc_ctl |= FBC_C3_IDLE; /* 945 needs special SR handling */ ++ fbc_ctl |= FBC_CTL_C3_IDLE; /* 945 needs special SR handling */ + fbc_ctl |= (dev_priv->cfb_pitch & 0xff) << FBC_CTL_STRIDE_SHIFT; + fbc_ctl |= (interval & 0x2fff) << FBC_CTL_INTERVAL_SHIFT; + if (obj_priv->tiling_mode != I915_TILING_NONE) +@@ -1079,7 +1061,7 @@ static void g4x_enable_fbc(struct drm_crtc *crtc, unsigned long interval) + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_framebuffer *fb = crtc->fb; + struct intel_framebuffer *intel_fb = to_intel_framebuffer(fb); +- struct drm_i915_gem_object *obj_priv = intel_fb->obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(intel_fb->obj); + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); + int plane = (intel_crtc->plane == 0 ? DPFC_CTL_PLANEA : + DPFC_CTL_PLANEB); +@@ -1175,7 +1157,7 @@ static void intel_update_fbc(struct drm_crtc *crtc, + return; + + intel_fb = to_intel_framebuffer(fb); +- obj_priv = intel_fb->obj->driver_private; ++ obj_priv = to_intel_bo(intel_fb->obj); + + /* + * If FBC is already on, we just have to verify that we can +@@ -1188,25 +1170,30 @@ static void intel_update_fbc(struct drm_crtc *crtc, + if (intel_fb->obj->size > dev_priv->cfb_size) { + DRM_DEBUG_KMS("framebuffer too large, disabling " + "compression\n"); ++ dev_priv->no_fbc_reason = FBC_STOLEN_TOO_SMALL; + goto out_disable; + } + if ((mode->flags & DRM_MODE_FLAG_INTERLACE) || + (mode->flags & DRM_MODE_FLAG_DBLSCAN)) { + DRM_DEBUG_KMS("mode incompatible with compression, " + "disabling\n"); ++ dev_priv->no_fbc_reason = FBC_UNSUPPORTED_MODE; + goto out_disable; + } + if ((mode->hdisplay > 2048) || + (mode->vdisplay > 1536)) { + DRM_DEBUG_KMS("mode too large for compression, disabling\n"); ++ dev_priv->no_fbc_reason = FBC_MODE_TOO_LARGE; + goto out_disable; + } + if ((IS_I915GM(dev) || IS_I945GM(dev)) && plane != 0) { + DRM_DEBUG_KMS("plane not 0, disabling compression\n"); ++ dev_priv->no_fbc_reason = FBC_BAD_PLANE; + goto out_disable; + } + if (obj_priv->tiling_mode != I915_TILING_X) { + DRM_DEBUG_KMS("framebuffer not tiled, disabling compression\n"); ++ dev_priv->no_fbc_reason = FBC_NOT_TILED; + goto out_disable; + } + +@@ -1237,7 +1224,7 @@ out_disable: + static int + intel_pin_and_fence_fb_obj(struct drm_device *dev, struct drm_gem_object *obj) + { +- struct drm_i915_gem_object *obj_priv = obj->driver_private; ++ struct drm_i915_gem_object *obj_priv = to_intel_bo(obj); + u32 alignment; + int ret; + +@@ -1317,7 +1304,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, + + intel_fb = to_intel_framebuffer(crtc->fb); + obj = intel_fb->obj; +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + + mutex_lock(&dev->struct_mutex); + ret = intel_pin_and_fence_fb_obj(dev, obj); +@@ -1366,7 +1353,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, + dspcntr &= ~DISPPLANE_TILED; + } + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + /* must disable */ + dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; + +@@ -1395,7 +1382,7 @@ intel_pipe_set_base(struct drm_crtc *crtc, int x, int y, + + if (old_fb) { + intel_fb = to_intel_framebuffer(old_fb); +- obj_priv = intel_fb->obj->driver_private; ++ obj_priv = to_intel_bo(intel_fb->obj); + i915_gem_object_unpin(intel_fb->obj); + } + intel_increase_pllclock(crtc, true); +@@ -1427,7 +1414,7 @@ static void i915_disable_vga (struct drm_device *dev) + u8 sr1; + u32 vga_reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + vga_reg = CPU_VGACNTRL; + else + vga_reg = VGACNTRL; +@@ -1504,6 +1491,219 @@ static void ironlake_set_pll_edp (struct drm_crtc *crtc, int clock) + udelay(500); + } + ++/* The FDI link training functions for ILK/Ibexpeak. */ ++static void ironlake_fdi_link_train(struct drm_crtc *crtc) ++{ ++ struct drm_device *dev = crtc->dev; ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ struct intel_crtc *intel_crtc = to_intel_crtc(crtc); ++ int pipe = intel_crtc->pipe; ++ int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL; ++ int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; ++ int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR; ++ int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR; ++ u32 temp, tries = 0; ++ ++ /* enable CPU FDI TX and PCH FDI RX */ ++ temp = I915_READ(fdi_tx_reg); ++ temp |= FDI_TX_ENABLE; ++ temp &= ~(7 << 19); ++ temp |= (intel_crtc->fdi_lanes - 1) << 19; ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_1; ++ I915_WRITE(fdi_tx_reg, temp); ++ I915_READ(fdi_tx_reg); ++ ++ temp = I915_READ(fdi_rx_reg); ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_1; ++ I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE); ++ I915_READ(fdi_rx_reg); ++ udelay(150); ++ ++ /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit ++ for train result */ ++ temp = I915_READ(fdi_rx_imr_reg); ++ temp &= ~FDI_RX_SYMBOL_LOCK; ++ temp &= ~FDI_RX_BIT_LOCK; ++ I915_WRITE(fdi_rx_imr_reg, temp); ++ I915_READ(fdi_rx_imr_reg); ++ udelay(150); ++ ++ for (;;) { ++ temp = I915_READ(fdi_rx_iir_reg); ++ DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); ++ ++ if ((temp & FDI_RX_BIT_LOCK)) { ++ DRM_DEBUG_KMS("FDI train 1 done.\n"); ++ I915_WRITE(fdi_rx_iir_reg, ++ temp | FDI_RX_BIT_LOCK); ++ break; ++ } ++ ++ tries++; ++ ++ if (tries > 5) { ++ DRM_DEBUG_KMS("FDI train 1 fail!\n"); ++ break; ++ } ++ } ++ ++ /* Train 2 */ ++ temp = I915_READ(fdi_tx_reg); ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_2; ++ I915_WRITE(fdi_tx_reg, temp); ++ ++ temp = I915_READ(fdi_rx_reg); ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_2; ++ I915_WRITE(fdi_rx_reg, temp); ++ udelay(150); ++ ++ tries = 0; ++ ++ for (;;) { ++ temp = I915_READ(fdi_rx_iir_reg); ++ DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); ++ ++ if (temp & FDI_RX_SYMBOL_LOCK) { ++ I915_WRITE(fdi_rx_iir_reg, ++ temp | FDI_RX_SYMBOL_LOCK); ++ DRM_DEBUG_KMS("FDI train 2 done.\n"); ++ break; ++ } ++ ++ tries++; ++ ++ if (tries > 5) { ++ DRM_DEBUG_KMS("FDI train 2 fail!\n"); ++ break; ++ } ++ } ++ ++ DRM_DEBUG_KMS("FDI train done\n"); ++} ++ ++static int snb_b_fdi_train_param [] = { ++ FDI_LINK_TRAIN_400MV_0DB_SNB_B, ++ FDI_LINK_TRAIN_400MV_6DB_SNB_B, ++ FDI_LINK_TRAIN_600MV_3_5DB_SNB_B, ++ FDI_LINK_TRAIN_800MV_0DB_SNB_B, ++}; ++ ++/* The FDI link training functions for SNB/Cougarpoint. */ ++static void gen6_fdi_link_train(struct drm_crtc *crtc) ++{ ++ struct drm_device *dev = crtc->dev; ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ struct intel_crtc *intel_crtc = to_intel_crtc(crtc); ++ int pipe = intel_crtc->pipe; ++ int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL; ++ int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; ++ int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR; ++ int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR; ++ u32 temp, i; ++ ++ /* enable CPU FDI TX and PCH FDI RX */ ++ temp = I915_READ(fdi_tx_reg); ++ temp |= FDI_TX_ENABLE; ++ temp &= ~(7 << 19); ++ temp |= (intel_crtc->fdi_lanes - 1) << 19; ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_1; ++ temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; ++ /* SNB-B */ ++ temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; ++ I915_WRITE(fdi_tx_reg, temp); ++ I915_READ(fdi_tx_reg); ++ ++ temp = I915_READ(fdi_rx_reg); ++ if (HAS_PCH_CPT(dev)) { ++ temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; ++ temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; ++ } else { ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_1; ++ } ++ I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE); ++ I915_READ(fdi_rx_reg); ++ udelay(150); ++ ++ /* Train 1: umask FDI RX Interrupt symbol_lock and bit_lock bit ++ for train result */ ++ temp = I915_READ(fdi_rx_imr_reg); ++ temp &= ~FDI_RX_SYMBOL_LOCK; ++ temp &= ~FDI_RX_BIT_LOCK; ++ I915_WRITE(fdi_rx_imr_reg, temp); ++ I915_READ(fdi_rx_imr_reg); ++ udelay(150); ++ ++ for (i = 0; i < 4; i++ ) { ++ temp = I915_READ(fdi_tx_reg); ++ temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; ++ temp |= snb_b_fdi_train_param[i]; ++ I915_WRITE(fdi_tx_reg, temp); ++ udelay(500); ++ ++ temp = I915_READ(fdi_rx_iir_reg); ++ DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); ++ ++ if (temp & FDI_RX_BIT_LOCK) { ++ I915_WRITE(fdi_rx_iir_reg, ++ temp | FDI_RX_BIT_LOCK); ++ DRM_DEBUG_KMS("FDI train 1 done.\n"); ++ break; ++ } ++ } ++ if (i == 4) ++ DRM_DEBUG_KMS("FDI train 1 fail!\n"); ++ ++ /* Train 2 */ ++ temp = I915_READ(fdi_tx_reg); ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_2; ++ if (IS_GEN6(dev)) { ++ temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; ++ /* SNB-B */ ++ temp |= FDI_LINK_TRAIN_400MV_0DB_SNB_B; ++ } ++ I915_WRITE(fdi_tx_reg, temp); ++ ++ temp = I915_READ(fdi_rx_reg); ++ if (HAS_PCH_CPT(dev)) { ++ temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; ++ temp |= FDI_LINK_TRAIN_PATTERN_2_CPT; ++ } else { ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_2; ++ } ++ I915_WRITE(fdi_rx_reg, temp); ++ udelay(150); ++ ++ for (i = 0; i < 4; i++ ) { ++ temp = I915_READ(fdi_tx_reg); ++ temp &= ~FDI_LINK_TRAIN_VOL_EMP_MASK; ++ temp |= snb_b_fdi_train_param[i]; ++ I915_WRITE(fdi_tx_reg, temp); ++ udelay(500); ++ ++ temp = I915_READ(fdi_rx_iir_reg); ++ DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); ++ ++ if (temp & FDI_RX_SYMBOL_LOCK) { ++ I915_WRITE(fdi_rx_iir_reg, ++ temp | FDI_RX_SYMBOL_LOCK); ++ DRM_DEBUG_KMS("FDI train 2 done.\n"); ++ break; ++ } ++ } ++ if (i == 4) ++ DRM_DEBUG_KMS("FDI train 2 fail!\n"); ++ ++ DRM_DEBUG_KMS("FDI train done.\n"); ++} ++ + static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + { + struct drm_device *dev = crtc->dev; +@@ -1517,8 +1717,6 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + int dspbase_reg = (plane == 0) ? DSPAADDR : DSPBADDR; + int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL; + int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; +- int fdi_rx_iir_reg = (pipe == 0) ? FDI_RXA_IIR : FDI_RXB_IIR; +- int fdi_rx_imr_reg = (pipe == 0) ? FDI_RXA_IMR : FDI_RXB_IMR; + int transconf_reg = (pipe == 0) ? TRANSACONF : TRANSBCONF; + int pf_ctl_reg = (pipe == 0) ? PFA_CTL_1 : PFB_CTL_1; + int pf_win_size = (pipe == 0) ? PFA_WIN_SZ : PFB_WIN_SZ; +@@ -1535,8 +1733,9 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + int trans_vtot_reg = (pipe == 0) ? TRANS_VTOTAL_A : TRANS_VTOTAL_B; + int trans_vblank_reg = (pipe == 0) ? TRANS_VBLANK_A : TRANS_VBLANK_B; + int trans_vsync_reg = (pipe == 0) ? TRANS_VSYNC_A : TRANS_VSYNC_B; ++ int trans_dpll_sel = (pipe == 0) ? 0 : 1; + u32 temp; +- int tries = 5, j, n; ++ int n; + u32 pipe_bpc; + + temp = I915_READ(pipeconf_reg); +@@ -1563,12 +1762,6 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + /* enable eDP PLL */ + ironlake_enable_pll_edp(crtc); + } else { +- /* enable PCH DPLL */ +- temp = I915_READ(pch_dpll_reg); +- if ((temp & DPLL_VCO_ENABLE) == 0) { +- I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE); +- I915_READ(pch_dpll_reg); +- } + + /* enable PCH FDI RX PLL, wait warmup plus DMI latency */ + temp = I915_READ(fdi_rx_reg); +@@ -1578,9 +1771,15 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + */ + temp &= ~(0x7 << 16); + temp |= (pipe_bpc << 11); +- I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE | +- FDI_SEL_PCDCLK | +- FDI_DP_PORT_WIDTH_X4); /* default 4 lanes */ ++ temp &= ~(7 << 19); ++ temp |= (intel_crtc->fdi_lanes - 1) << 19; ++ I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE); ++ I915_READ(fdi_rx_reg); ++ udelay(200); ++ ++ /* Switch from Rawclk to PCDclk */ ++ temp = I915_READ(fdi_rx_reg); ++ I915_WRITE(fdi_rx_reg, temp | FDI_SEL_PCDCLK); + I915_READ(fdi_rx_reg); + udelay(200); + +@@ -1623,91 +1822,32 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + } + + if (!HAS_eDP) { +- /* enable CPU FDI TX and PCH FDI RX */ +- temp = I915_READ(fdi_tx_reg); +- temp |= FDI_TX_ENABLE; +- temp |= FDI_DP_PORT_WIDTH_X4; /* default */ +- temp &= ~FDI_LINK_TRAIN_NONE; +- temp |= FDI_LINK_TRAIN_PATTERN_1; +- I915_WRITE(fdi_tx_reg, temp); +- I915_READ(fdi_tx_reg); +- +- temp = I915_READ(fdi_rx_reg); +- temp &= ~FDI_LINK_TRAIN_NONE; +- temp |= FDI_LINK_TRAIN_PATTERN_1; +- I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENABLE); +- I915_READ(fdi_rx_reg); +- +- udelay(150); +- +- /* Train FDI. */ +- /* umask FDI RX Interrupt symbol_lock and bit_lock bit +- for train result */ +- temp = I915_READ(fdi_rx_imr_reg); +- temp &= ~FDI_RX_SYMBOL_LOCK; +- temp &= ~FDI_RX_BIT_LOCK; +- I915_WRITE(fdi_rx_imr_reg, temp); +- I915_READ(fdi_rx_imr_reg); +- udelay(150); ++ /* For PCH output, training FDI link */ ++ if (IS_GEN6(dev)) ++ gen6_fdi_link_train(crtc); ++ else ++ ironlake_fdi_link_train(crtc); + +- temp = I915_READ(fdi_rx_iir_reg); +- DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); +- +- if ((temp & FDI_RX_BIT_LOCK) == 0) { +- for (j = 0; j < tries; j++) { +- temp = I915_READ(fdi_rx_iir_reg); +- DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", +- temp); +- if (temp & FDI_RX_BIT_LOCK) +- break; +- udelay(200); +- } +- if (j != tries) +- I915_WRITE(fdi_rx_iir_reg, +- temp | FDI_RX_BIT_LOCK); +- else +- DRM_DEBUG_KMS("train 1 fail\n"); +- } else { +- I915_WRITE(fdi_rx_iir_reg, +- temp | FDI_RX_BIT_LOCK); +- DRM_DEBUG_KMS("train 1 ok 2!\n"); ++ /* enable PCH DPLL */ ++ temp = I915_READ(pch_dpll_reg); ++ if ((temp & DPLL_VCO_ENABLE) == 0) { ++ I915_WRITE(pch_dpll_reg, temp | DPLL_VCO_ENABLE); ++ I915_READ(pch_dpll_reg); + } +- temp = I915_READ(fdi_tx_reg); +- temp &= ~FDI_LINK_TRAIN_NONE; +- temp |= FDI_LINK_TRAIN_PATTERN_2; +- I915_WRITE(fdi_tx_reg, temp); +- +- temp = I915_READ(fdi_rx_reg); +- temp &= ~FDI_LINK_TRAIN_NONE; +- temp |= FDI_LINK_TRAIN_PATTERN_2; +- I915_WRITE(fdi_rx_reg, temp); +- +- udelay(150); ++ udelay(200); + +- temp = I915_READ(fdi_rx_iir_reg); +- DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", temp); +- +- if ((temp & FDI_RX_SYMBOL_LOCK) == 0) { +- for (j = 0; j < tries; j++) { +- temp = I915_READ(fdi_rx_iir_reg); +- DRM_DEBUG_KMS("FDI_RX_IIR 0x%x\n", +- temp); +- if (temp & FDI_RX_SYMBOL_LOCK) +- break; +- udelay(200); +- } +- if (j != tries) { +- I915_WRITE(fdi_rx_iir_reg, +- temp | FDI_RX_SYMBOL_LOCK); +- DRM_DEBUG_KMS("train 2 ok 1!\n"); +- } else +- DRM_DEBUG_KMS("train 2 fail\n"); +- } else { +- I915_WRITE(fdi_rx_iir_reg, +- temp | FDI_RX_SYMBOL_LOCK); +- DRM_DEBUG_KMS("train 2 ok 2!\n"); ++ if (HAS_PCH_CPT(dev)) { ++ /* Be sure PCH DPLL SEL is set */ ++ temp = I915_READ(PCH_DPLL_SEL); ++ if (trans_dpll_sel == 0 && ++ (temp & TRANSA_DPLL_ENABLE) == 0) ++ temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL); ++ else if (trans_dpll_sel == 1 && ++ (temp & TRANSB_DPLL_ENABLE) == 0) ++ temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL); ++ I915_WRITE(PCH_DPLL_SEL, temp); ++ I915_READ(PCH_DPLL_SEL); + } +- DRM_DEBUG_KMS("train done\n"); + + /* set transcoder timing */ + I915_WRITE(trans_htot_reg, I915_READ(cpu_htot_reg)); +@@ -1718,6 +1858,60 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + I915_WRITE(trans_vblank_reg, I915_READ(cpu_vblank_reg)); + I915_WRITE(trans_vsync_reg, I915_READ(cpu_vsync_reg)); + ++ /* enable normal train */ ++ temp = I915_READ(fdi_tx_reg); ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE | ++ FDI_TX_ENHANCE_FRAME_ENABLE); ++ I915_READ(fdi_tx_reg); ++ ++ temp = I915_READ(fdi_rx_reg); ++ if (HAS_PCH_CPT(dev)) { ++ temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; ++ temp |= FDI_LINK_TRAIN_NORMAL_CPT; ++ } else { ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_NONE; ++ } ++ I915_WRITE(fdi_rx_reg, temp | FDI_RX_ENHANCE_FRAME_ENABLE); ++ I915_READ(fdi_rx_reg); ++ ++ /* wait one idle pattern time */ ++ udelay(100); ++ ++ /* For PCH DP, enable TRANS_DP_CTL */ ++ if (HAS_PCH_CPT(dev) && ++ intel_pipe_has_type(crtc, INTEL_OUTPUT_DISPLAYPORT)) { ++ int trans_dp_ctl = (pipe == 0) ? TRANS_DP_CTL_A : TRANS_DP_CTL_B; ++ int reg; ++ ++ reg = I915_READ(trans_dp_ctl); ++ reg &= ~TRANS_DP_PORT_SEL_MASK; ++ reg = TRANS_DP_OUTPUT_ENABLE | ++ TRANS_DP_ENH_FRAMING | ++ TRANS_DP_VSYNC_ACTIVE_HIGH | ++ TRANS_DP_HSYNC_ACTIVE_HIGH; ++ ++ switch (intel_trans_dp_port_sel(crtc)) { ++ case PCH_DP_B: ++ reg |= TRANS_DP_PORT_SEL_B; ++ break; ++ case PCH_DP_C: ++ reg |= TRANS_DP_PORT_SEL_C; ++ break; ++ case PCH_DP_D: ++ reg |= TRANS_DP_PORT_SEL_D; ++ break; ++ default: ++ DRM_DEBUG_KMS("Wrong PCH DP port return. Guess port B\n"); ++ reg |= TRANS_DP_PORT_SEL_B; ++ break; ++ } ++ ++ I915_WRITE(trans_dp_ctl, reg); ++ POSTING_READ(trans_dp_ctl); ++ } ++ + /* enable PCH transcoder */ + temp = I915_READ(transconf_reg); + /* +@@ -1732,23 +1926,6 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + while ((I915_READ(transconf_reg) & TRANS_STATE_ENABLE) == 0) + ; + +- /* enable normal */ +- +- temp = I915_READ(fdi_tx_reg); +- temp &= ~FDI_LINK_TRAIN_NONE; +- I915_WRITE(fdi_tx_reg, temp | FDI_LINK_TRAIN_NONE | +- FDI_TX_ENHANCE_FRAME_ENABLE); +- I915_READ(fdi_tx_reg); +- +- temp = I915_READ(fdi_rx_reg); +- temp &= ~FDI_LINK_TRAIN_NONE; +- I915_WRITE(fdi_rx_reg, temp | FDI_LINK_TRAIN_NONE | +- FDI_RX_ENHANCE_FRAME_ENABLE); +- I915_READ(fdi_rx_reg); +- +- /* wait one idle pattern time */ +- udelay(100); +- + } + + intel_crtc_load_lut(crtc); +@@ -1799,6 +1976,8 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + I915_READ(pf_ctl_reg); + } + I915_WRITE(pf_win_size, 0); ++ POSTING_READ(pf_win_size); ++ + + /* disable CPU FDI tx and PCH FDI rx */ + temp = I915_READ(fdi_tx_reg); +@@ -1819,11 +1998,18 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + temp &= ~FDI_LINK_TRAIN_NONE; + temp |= FDI_LINK_TRAIN_PATTERN_1; + I915_WRITE(fdi_tx_reg, temp); ++ POSTING_READ(fdi_tx_reg); + + temp = I915_READ(fdi_rx_reg); +- temp &= ~FDI_LINK_TRAIN_NONE; +- temp |= FDI_LINK_TRAIN_PATTERN_1; ++ if (HAS_PCH_CPT(dev)) { ++ temp &= ~FDI_LINK_TRAIN_PATTERN_MASK_CPT; ++ temp |= FDI_LINK_TRAIN_PATTERN_1_CPT; ++ } else { ++ temp &= ~FDI_LINK_TRAIN_NONE; ++ temp |= FDI_LINK_TRAIN_PATTERN_1; ++ } + I915_WRITE(fdi_rx_reg, temp); ++ POSTING_READ(fdi_rx_reg); + + udelay(100); + +@@ -1853,6 +2039,7 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + } + } + } ++ + temp = I915_READ(transconf_reg); + /* BPC in transcoder is consistent with that in pipeconf */ + temp &= ~PIPE_BPC_MASK; +@@ -1861,35 +2048,53 @@ static void ironlake_crtc_dpms(struct drm_crtc *crtc, int mode) + I915_READ(transconf_reg); + udelay(100); + ++ if (HAS_PCH_CPT(dev)) { ++ /* disable TRANS_DP_CTL */ ++ int trans_dp_ctl = (pipe == 0) ? TRANS_DP_CTL_A : TRANS_DP_CTL_B; ++ int reg; ++ ++ reg = I915_READ(trans_dp_ctl); ++ reg &= ~(TRANS_DP_OUTPUT_ENABLE | TRANS_DP_PORT_SEL_MASK); ++ I915_WRITE(trans_dp_ctl, reg); ++ POSTING_READ(trans_dp_ctl); ++ ++ /* disable DPLL_SEL */ ++ temp = I915_READ(PCH_DPLL_SEL); ++ if (trans_dpll_sel == 0) ++ temp &= ~(TRANSA_DPLL_ENABLE | TRANSA_DPLLB_SEL); ++ else ++ temp &= ~(TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL); ++ I915_WRITE(PCH_DPLL_SEL, temp); ++ I915_READ(PCH_DPLL_SEL); ++ ++ } ++ + /* disable PCH DPLL */ + temp = I915_READ(pch_dpll_reg); +- if ((temp & DPLL_VCO_ENABLE) != 0) { +- I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE); +- I915_READ(pch_dpll_reg); +- } ++ I915_WRITE(pch_dpll_reg, temp & ~DPLL_VCO_ENABLE); ++ I915_READ(pch_dpll_reg); + + if (HAS_eDP) { + ironlake_disable_pll_edp(crtc); + } + ++ /* Switch from PCDclk to Rawclk */ + temp = I915_READ(fdi_rx_reg); + temp &= ~FDI_SEL_PCDCLK; + I915_WRITE(fdi_rx_reg, temp); + I915_READ(fdi_rx_reg); + ++ /* Disable CPU FDI TX PLL */ ++ temp = I915_READ(fdi_tx_reg); ++ I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE); ++ I915_READ(fdi_tx_reg); ++ udelay(100); ++ + temp = I915_READ(fdi_rx_reg); + temp &= ~FDI_RX_PLL_ENABLE; + I915_WRITE(fdi_rx_reg, temp); + I915_READ(fdi_rx_reg); + +- /* Disable CPU FDI TX PLL */ +- temp = I915_READ(fdi_tx_reg); +- if ((temp & FDI_TX_PLL_ENABLE) != 0) { +- I915_WRITE(fdi_tx_reg, temp & ~FDI_TX_PLL_ENABLE); +- I915_READ(fdi_tx_reg); +- udelay(100); +- } +- + /* Wait for the clocks to turn off. */ + udelay(100); + break; +@@ -2111,7 +2316,7 @@ static bool intel_crtc_mode_fixup(struct drm_crtc *crtc, + struct drm_display_mode *adjusted_mode) + { + struct drm_device *dev = crtc->dev; +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + /* FDI link clock is fixed at 2.7G */ + if (mode->clock * 3 > 27000 * 4) + return MODE_CLOCK_HIGH; +@@ -2325,6 +2530,30 @@ static struct intel_watermark_params i830_wm_info = { + I830_FIFO_LINE_SIZE + }; + ++static struct intel_watermark_params ironlake_display_wm_info = { ++ ILK_DISPLAY_FIFO, ++ ILK_DISPLAY_MAXWM, ++ ILK_DISPLAY_DFTWM, ++ 2, ++ ILK_FIFO_LINE_SIZE ++}; ++ ++static struct intel_watermark_params ironlake_display_srwm_info = { ++ ILK_DISPLAY_SR_FIFO, ++ ILK_DISPLAY_MAX_SRWM, ++ ILK_DISPLAY_DFT_SRWM, ++ 2, ++ ILK_FIFO_LINE_SIZE ++}; ++ ++static struct intel_watermark_params ironlake_cursor_srwm_info = { ++ ILK_CURSOR_SR_FIFO, ++ ILK_CURSOR_MAX_SRWM, ++ ILK_CURSOR_DFT_SRWM, ++ 2, ++ ILK_FIFO_LINE_SIZE ++}; ++ + /** + * intel_calculate_wm - calculate watermark level + * @clock_in_khz: pixel clock +@@ -2443,66 +2672,6 @@ static void pineview_disable_cxsr(struct drm_device *dev) + DRM_INFO("Big FIFO is disabled\n"); + } + +-static void pineview_enable_cxsr(struct drm_device *dev, unsigned long clock, +- int pixel_size) +-{ +- struct drm_i915_private *dev_priv = dev->dev_private; +- u32 reg; +- unsigned long wm; +- struct cxsr_latency *latency; +- +- latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->fsb_freq, +- dev_priv->mem_freq); +- if (!latency) { +- DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); +- pineview_disable_cxsr(dev); +- return; +- } +- +- /* Display SR */ +- wm = intel_calculate_wm(clock, &pineview_display_wm, pixel_size, +- latency->display_sr); +- reg = I915_READ(DSPFW1); +- reg &= 0x7fffff; +- reg |= wm << 23; +- I915_WRITE(DSPFW1, reg); +- DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); +- +- /* cursor SR */ +- wm = intel_calculate_wm(clock, &pineview_cursor_wm, pixel_size, +- latency->cursor_sr); +- reg = I915_READ(DSPFW3); +- reg &= ~(0x3f << 24); +- reg |= (wm & 0x3f) << 24; +- I915_WRITE(DSPFW3, reg); +- +- /* Display HPLL off SR */ +- wm = intel_calculate_wm(clock, &pineview_display_hplloff_wm, +- latency->display_hpll_disable, I915_FIFO_LINE_SIZE); +- reg = I915_READ(DSPFW3); +- reg &= 0xfffffe00; +- reg |= wm & 0x1ff; +- I915_WRITE(DSPFW3, reg); +- +- /* cursor HPLL off SR */ +- wm = intel_calculate_wm(clock, &pineview_cursor_hplloff_wm, pixel_size, +- latency->cursor_hpll_disable); +- reg = I915_READ(DSPFW3); +- reg &= ~(0x3f << 16); +- reg |= (wm & 0x3f) << 16; +- I915_WRITE(DSPFW3, reg); +- DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); +- +- /* activate cxsr */ +- reg = I915_READ(DSPFW3); +- reg |= PINEVIEW_SELF_REFRESH_EN; +- I915_WRITE(DSPFW3, reg); +- +- DRM_INFO("Big FIFO is enabled\n"); +- +- return; +-} +- + /* + * Latency for FIFO fetches is dependent on several factors: + * - memory configuration (speed, channels) +@@ -2587,6 +2756,71 @@ static int i830_get_fifo_size(struct drm_device *dev, int plane) + return size; + } + ++static void pineview_update_wm(struct drm_device *dev, int planea_clock, ++ int planeb_clock, int sr_hdisplay, int pixel_size) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ u32 reg; ++ unsigned long wm; ++ struct cxsr_latency *latency; ++ int sr_clock; ++ ++ latency = intel_get_cxsr_latency(IS_PINEVIEW_G(dev), dev_priv->fsb_freq, ++ dev_priv->mem_freq); ++ if (!latency) { ++ DRM_DEBUG_KMS("Unknown FSB/MEM found, disable CxSR\n"); ++ pineview_disable_cxsr(dev); ++ return; ++ } ++ ++ if (!planea_clock || !planeb_clock) { ++ sr_clock = planea_clock ? planea_clock : planeb_clock; ++ ++ /* Display SR */ ++ wm = intel_calculate_wm(sr_clock, &pineview_display_wm, ++ pixel_size, latency->display_sr); ++ reg = I915_READ(DSPFW1); ++ reg &= ~DSPFW_SR_MASK; ++ reg |= wm << DSPFW_SR_SHIFT; ++ I915_WRITE(DSPFW1, reg); ++ DRM_DEBUG_KMS("DSPFW1 register is %x\n", reg); ++ ++ /* cursor SR */ ++ wm = intel_calculate_wm(sr_clock, &pineview_cursor_wm, ++ pixel_size, latency->cursor_sr); ++ reg = I915_READ(DSPFW3); ++ reg &= ~DSPFW_CURSOR_SR_MASK; ++ reg |= (wm & 0x3f) << DSPFW_CURSOR_SR_SHIFT; ++ I915_WRITE(DSPFW3, reg); ++ ++ /* Display HPLL off SR */ ++ wm = intel_calculate_wm(sr_clock, &pineview_display_hplloff_wm, ++ pixel_size, latency->display_hpll_disable); ++ reg = I915_READ(DSPFW3); ++ reg &= ~DSPFW_HPLL_SR_MASK; ++ reg |= wm & DSPFW_HPLL_SR_MASK; ++ I915_WRITE(DSPFW3, reg); ++ ++ /* cursor HPLL off SR */ ++ wm = intel_calculate_wm(sr_clock, &pineview_cursor_hplloff_wm, ++ pixel_size, latency->cursor_hpll_disable); ++ reg = I915_READ(DSPFW3); ++ reg &= ~DSPFW_HPLL_CURSOR_MASK; ++ reg |= (wm & 0x3f) << DSPFW_HPLL_CURSOR_SHIFT; ++ I915_WRITE(DSPFW3, reg); ++ DRM_DEBUG_KMS("DSPFW3 register is %x\n", reg); ++ ++ /* activate cxsr */ ++ reg = I915_READ(DSPFW3); ++ reg |= PINEVIEW_SELF_REFRESH_EN; ++ I915_WRITE(DSPFW3, reg); ++ DRM_DEBUG_KMS("Self-refresh is enabled\n"); ++ } else { ++ pineview_disable_cxsr(dev); ++ DRM_DEBUG_KMS("Self-refresh is disabled\n"); ++ } ++} ++ + static void g4x_update_wm(struct drm_device *dev, int planea_clock, + int planeb_clock, int sr_hdisplay, int pixel_size) + { +@@ -2757,11 +2991,22 @@ static void i9xx_update_wm(struct drm_device *dev, int planea_clock, + srwm = total_size - sr_entries; + if (srwm < 0) + srwm = 1; +- I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN | (srwm & 0x3f)); ++ ++ if (IS_I945G(dev) || IS_I945GM(dev)) ++ I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_FIFO_MASK | (srwm & 0xff)); ++ else if (IS_I915GM(dev)) { ++ /* 915M has a smaller SRWM field */ ++ I915_WRITE(FW_BLC_SELF, srwm & 0x3f); ++ I915_WRITE(INSTPM, I915_READ(INSTPM) | INSTPM_SELF_EN); ++ } + } else { + /* Turn off self refresh if both pipes are enabled */ +- I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) +- & ~FW_BLC_SELF_EN); ++ if (IS_I945G(dev) || IS_I945GM(dev)) { ++ I915_WRITE(FW_BLC_SELF, I915_READ(FW_BLC_SELF) ++ & ~FW_BLC_SELF_EN); ++ } else if (IS_I915GM(dev)) { ++ I915_WRITE(INSTPM, I915_READ(INSTPM) & ~INSTPM_SELF_EN); ++ } + } + + DRM_DEBUG_KMS("Setting FIFO watermarks - A: %d, B: %d, C: %d, SR %d\n", +@@ -2796,6 +3041,108 @@ static void i830_update_wm(struct drm_device *dev, int planea_clock, int unused, + I915_WRITE(FW_BLC, fwater_lo); + } + ++#define ILK_LP0_PLANE_LATENCY 700 ++ ++static void ironlake_update_wm(struct drm_device *dev, int planea_clock, ++ int planeb_clock, int sr_hdisplay, int pixel_size) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ int planea_wm, planeb_wm, cursora_wm, cursorb_wm; ++ int sr_wm, cursor_wm; ++ unsigned long line_time_us; ++ int sr_clock, entries_required; ++ u32 reg_value; ++ ++ /* Calculate and update the watermark for plane A */ ++ if (planea_clock) { ++ entries_required = ((planea_clock / 1000) * pixel_size * ++ ILK_LP0_PLANE_LATENCY) / 1000; ++ entries_required = DIV_ROUND_UP(entries_required, ++ ironlake_display_wm_info.cacheline_size); ++ planea_wm = entries_required + ++ ironlake_display_wm_info.guard_size; ++ ++ if (planea_wm > (int)ironlake_display_wm_info.max_wm) ++ planea_wm = ironlake_display_wm_info.max_wm; ++ ++ cursora_wm = 16; ++ reg_value = I915_READ(WM0_PIPEA_ILK); ++ reg_value &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK); ++ reg_value |= (planea_wm << WM0_PIPE_PLANE_SHIFT) | ++ (cursora_wm & WM0_PIPE_CURSOR_MASK); ++ I915_WRITE(WM0_PIPEA_ILK, reg_value); ++ DRM_DEBUG_KMS("FIFO watermarks For pipe A - plane %d, " ++ "cursor: %d\n", planea_wm, cursora_wm); ++ } ++ /* Calculate and update the watermark for plane B */ ++ if (planeb_clock) { ++ entries_required = ((planeb_clock / 1000) * pixel_size * ++ ILK_LP0_PLANE_LATENCY) / 1000; ++ entries_required = DIV_ROUND_UP(entries_required, ++ ironlake_display_wm_info.cacheline_size); ++ planeb_wm = entries_required + ++ ironlake_display_wm_info.guard_size; ++ ++ if (planeb_wm > (int)ironlake_display_wm_info.max_wm) ++ planeb_wm = ironlake_display_wm_info.max_wm; ++ ++ cursorb_wm = 16; ++ reg_value = I915_READ(WM0_PIPEB_ILK); ++ reg_value &= ~(WM0_PIPE_PLANE_MASK | WM0_PIPE_CURSOR_MASK); ++ reg_value |= (planeb_wm << WM0_PIPE_PLANE_SHIFT) | ++ (cursorb_wm & WM0_PIPE_CURSOR_MASK); ++ I915_WRITE(WM0_PIPEB_ILK, reg_value); ++ DRM_DEBUG_KMS("FIFO watermarks For pipe B - plane %d, " ++ "cursor: %d\n", planeb_wm, cursorb_wm); ++ } ++ ++ /* ++ * Calculate and update the self-refresh watermark only when one ++ * display plane is used. ++ */ ++ if (!planea_clock || !planeb_clock) { ++ int line_count; ++ /* Read the self-refresh latency. The unit is 0.5us */ ++ int ilk_sr_latency = I915_READ(MLTR_ILK) & ILK_SRLT_MASK; ++ ++ sr_clock = planea_clock ? planea_clock : planeb_clock; ++ line_time_us = ((sr_hdisplay * 1000) / sr_clock); ++ ++ /* Use ns/us then divide to preserve precision */ ++ line_count = ((ilk_sr_latency * 500) / line_time_us + 1000) ++ / 1000; ++ ++ /* calculate the self-refresh watermark for display plane */ ++ entries_required = line_count * sr_hdisplay * pixel_size; ++ entries_required = DIV_ROUND_UP(entries_required, ++ ironlake_display_srwm_info.cacheline_size); ++ sr_wm = entries_required + ++ ironlake_display_srwm_info.guard_size; ++ ++ /* calculate the self-refresh watermark for display cursor */ ++ entries_required = line_count * pixel_size * 64; ++ entries_required = DIV_ROUND_UP(entries_required, ++ ironlake_cursor_srwm_info.cacheline_size); ++ cursor_wm = entries_required + ++ ironlake_cursor_srwm_info.guard_size; ++ ++ /* configure watermark and enable self-refresh */ ++ reg_value = I915_READ(WM1_LP_ILK); ++ reg_value &= ~(WM1_LP_LATENCY_MASK | WM1_LP_SR_MASK | ++ WM1_LP_CURSOR_MASK); ++ reg_value |= WM1_LP_SR_EN | ++ (ilk_sr_latency << WM1_LP_LATENCY_SHIFT) | ++ (sr_wm << WM1_LP_SR_SHIFT) | cursor_wm; ++ ++ I915_WRITE(WM1_LP_ILK, reg_value); ++ DRM_DEBUG_KMS("self-refresh watermark: display plane %d " ++ "cursor %d\n", sr_wm, cursor_wm); ++ ++ } else { ++ /* Turn off self refresh if both pipes are enabled */ ++ I915_WRITE(WM1_LP_ILK, I915_READ(WM1_LP_ILK) & ~WM1_LP_SR_EN); ++ } ++} + /** + * intel_update_watermarks - update FIFO watermark values based on current modes + * +@@ -2865,12 +3212,6 @@ static void intel_update_watermarks(struct drm_device *dev) + if (enabled <= 0) + return; + +- /* Single plane configs can enable self refresh */ +- if (enabled == 1 && IS_PINEVIEW(dev)) +- pineview_enable_cxsr(dev, sr_clock, pixel_size); +- else if (IS_PINEVIEW(dev)) +- pineview_disable_cxsr(dev); +- + dev_priv->display.update_wm(dev, planea_clock, planeb_clock, + sr_hdisplay, pixel_size); + } +@@ -2900,14 +3241,15 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + int dspsize_reg = (plane == 0) ? DSPASIZE : DSPBSIZE; + int dsppos_reg = (plane == 0) ? DSPAPOS : DSPBPOS; + int pipesrc_reg = (pipe == 0) ? PIPEASRC : PIPEBSRC; +- int refclk, num_outputs = 0; ++ int refclk, num_connectors = 0; + intel_clock_t clock, reduced_clock; + u32 dpll = 0, fp = 0, fp2 = 0, dspcntr, pipeconf; + bool ok, has_reduced_clock = false, is_sdvo = false, is_dvo = false; + bool is_crt = false, is_lvds = false, is_tv = false, is_dp = false; + bool is_edp = false; + struct drm_mode_config *mode_config = &dev->mode_config; +- struct drm_connector *connector; ++ struct drm_encoder *encoder; ++ struct intel_encoder *intel_encoder = NULL; + const intel_limit_t *limit; + int ret; + struct fdi_m_n m_n = {0}; +@@ -2918,6 +3260,8 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + int pch_fp_reg = (pipe == 0) ? PCH_FPA0 : PCH_FPB0; + int pch_dpll_reg = (pipe == 0) ? PCH_DPLL_A : PCH_DPLL_B; + int fdi_rx_reg = (pipe == 0) ? FDI_RXA_CTL : FDI_RXB_CTL; ++ int fdi_tx_reg = (pipe == 0) ? FDI_TXA_CTL : FDI_TXB_CTL; ++ int trans_dpll_sel = (pipe == 0) ? 0 : 1; + int lvds_reg = LVDS; + u32 temp; + int sdvo_pixel_multiply; +@@ -2925,20 +3269,21 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + + drm_vblank_pre_modeset(dev, pipe); + +- list_for_each_entry(connector, &mode_config->connector_list, head) { +- struct intel_output *intel_output = to_intel_output(connector); ++ list_for_each_entry(encoder, &mode_config->encoder_list, head) { + +- if (!connector->encoder || connector->encoder->crtc != crtc) ++ if (!encoder || encoder->crtc != crtc) + continue; + +- switch (intel_output->type) { ++ intel_encoder = enc_to_intel_encoder(encoder); ++ ++ switch (intel_encoder->type) { + case INTEL_OUTPUT_LVDS: + is_lvds = true; + break; + case INTEL_OUTPUT_SDVO: + case INTEL_OUTPUT_HDMI: + is_sdvo = true; +- if (intel_output->needs_tv_clock) ++ if (intel_encoder->needs_tv_clock) + is_tv = true; + break; + case INTEL_OUTPUT_DVO: +@@ -2958,16 +3303,16 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + break; + } + +- num_outputs++; ++ num_connectors++; + } + +- if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) { ++ if (is_lvds && dev_priv->lvds_use_ssc && num_connectors < 2) { + refclk = dev_priv->lvds_ssc_freq * 1000; + DRM_DEBUG_KMS("using SSC reference clock of %d MHz\n", + refclk / 1000); + } else if (IS_I9XX(dev)) { + refclk = 96000; +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + refclk = 120000; /* 120Mhz refclk */ + } else { + refclk = 48000; +@@ -3025,15 +3370,13 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + } + + /* FDI link */ +- if (IS_IRONLAKE(dev)) { +- int lane, link_bw, bpp; ++ if (HAS_PCH_SPLIT(dev)) { ++ int lane = 0, link_bw, bpp; + /* eDP doesn't require FDI link, so just set DP M/N + according to current link config */ + if (is_edp) { +- struct drm_connector *edp; + target_clock = mode->clock; +- edp = intel_pipe_get_output(crtc); +- intel_edp_link_config(to_intel_output(edp), ++ intel_edp_link_config(intel_encoder, + &lane, &link_bw); + } else { + /* DP over FDI requires target mode clock +@@ -3042,7 +3385,6 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + target_clock = mode->clock; + else + target_clock = adjusted_mode->clock; +- lane = 4; + link_bw = 270000; + } + +@@ -3094,6 +3436,18 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + bpp = 24; + } + ++ if (!lane) { ++ /* ++ * Account for spread spectrum to avoid ++ * oversubscribing the link. Max center spread ++ * is 2.5%; use 5% for safety's sake. ++ */ ++ u32 bps = target_clock * bpp * 21 / 20; ++ lane = bps / (link_bw * 8) + 1; ++ } ++ ++ intel_crtc->fdi_lanes = lane; ++ + ironlake_compute_m_n(bpp, lane, target_clock, link_bw, &m_n); + } + +@@ -3102,7 +3456,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + * PCH B stepping, previous chipset stepping should be + * ignoring this setting. + */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + temp = I915_READ(PCH_DREF_CONTROL); + /* Always enable nonspread source */ + temp &= ~DREF_NONSPREAD_SOURCE_MASK; +@@ -3149,7 +3503,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + reduced_clock.m2; + } + +- if (!IS_IRONLAKE(dev)) ++ if (!HAS_PCH_SPLIT(dev)) + dpll = DPLL_VGA_MODE_DIS; + + if (IS_I9XX(dev)) { +@@ -3162,7 +3516,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; + if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) + dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; +- else if (IS_IRONLAKE(dev)) ++ else if (HAS_PCH_SPLIT(dev)) + dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; + } + if (is_dp) +@@ -3174,7 +3528,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + else { + dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; + /* also FPA1 */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; + if (IS_G4X(dev) && has_reduced_clock) + dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; +@@ -3193,7 +3547,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; + break; + } +- if (IS_I965G(dev) && !IS_IRONLAKE(dev)) ++ if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) + dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); + } else { + if (is_lvds) { +@@ -3214,7 +3568,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + /* XXX: just matching BIOS for now */ + /* dpll |= PLL_REF_INPUT_TVCLKINBC; */ + dpll |= 3; +- else if (is_lvds && dev_priv->lvds_use_ssc && num_outputs < 2) ++ else if (is_lvds && dev_priv->lvds_use_ssc && num_connectors < 2) + dpll |= PLLB_REF_INPUT_SPREADSPECTRUMIN; + else + dpll |= PLL_REF_INPUT_DREFCLK; +@@ -3227,7 +3581,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + + /* Ironlake's plane is forced to pipe, bit 24 is to + enable color space conversion */ +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + if (pipe == 0) + dspcntr &= ~DISPPLANE_SEL_PIPE_MASK; + else +@@ -3249,14 +3603,14 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + } + + /* Disable the panel fitter if it was on our pipe */ +- if (!IS_IRONLAKE(dev) && intel_panel_fitter_pipe(dev) == pipe) ++ if (!HAS_PCH_SPLIT(dev) && intel_panel_fitter_pipe(dev) == pipe) + I915_WRITE(PFIT_CONTROL, 0); + + DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); + drm_mode_debug_printmodeline(mode); + + /* assign to Ironlake registers */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + fp_reg = pch_fp_reg; + dpll_reg = pch_dpll_reg; + } +@@ -3275,6 +3629,18 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + udelay(150); + } + ++ /* enable transcoder DPLL */ ++ if (HAS_PCH_CPT(dev)) { ++ temp = I915_READ(PCH_DPLL_SEL); ++ if (trans_dpll_sel == 0) ++ temp |= (TRANSA_DPLL_ENABLE | TRANSA_DPLLA_SEL); ++ else ++ temp |= (TRANSB_DPLL_ENABLE | TRANSB_DPLLB_SEL); ++ I915_WRITE(PCH_DPLL_SEL, temp); ++ I915_READ(PCH_DPLL_SEL); ++ udelay(150); ++ } ++ + /* The LVDS pin pair needs to be on before the DPLLs are enabled. + * This is an exception to the general rule that mode_set doesn't turn + * things on. +@@ -3282,11 +3648,22 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + if (is_lvds) { + u32 lvds; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + lvds_reg = PCH_LVDS; + + lvds = I915_READ(lvds_reg); +- lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP | LVDS_PIPEB_SELECT; ++ lvds |= LVDS_PORT_EN | LVDS_A0A2_CLKA_POWER_UP; ++ if (pipe == 1) { ++ if (HAS_PCH_CPT(dev)) ++ lvds |= PORT_TRANS_B_SEL_CPT; ++ else ++ lvds |= LVDS_PIPEB_SELECT; ++ } else { ++ if (HAS_PCH_CPT(dev)) ++ lvds &= ~PORT_TRANS_SEL_MASK; ++ else ++ lvds &= ~LVDS_PIPEB_SELECT; ++ } + /* set the corresponsding LVDS_BORDER bit */ + lvds |= dev_priv->lvds_border_bits; + /* Set the B0-B3 data pairs corresponding to whether we're going to +@@ -3304,12 +3681,12 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + /* set the dithering flag */ + if (IS_I965G(dev)) { + if (dev_priv->lvds_dither) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + pipeconf |= PIPE_ENABLE_DITHER; + else + lvds |= LVDS_ENABLE_DITHER; + } else { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + pipeconf &= ~PIPE_ENABLE_DITHER; + else + lvds &= ~LVDS_ENABLE_DITHER; +@@ -3320,6 +3697,20 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + } + if (is_dp) + intel_dp_set_m_n(crtc, mode, adjusted_mode); ++ else if (HAS_PCH_SPLIT(dev)) { ++ /* For non-DP output, clear any trans DP clock recovery setting.*/ ++ if (pipe == 0) { ++ I915_WRITE(TRANSA_DATA_M1, 0); ++ I915_WRITE(TRANSA_DATA_N1, 0); ++ I915_WRITE(TRANSA_DP_LINK_M1, 0); ++ I915_WRITE(TRANSA_DP_LINK_N1, 0); ++ } else { ++ I915_WRITE(TRANSB_DATA_M1, 0); ++ I915_WRITE(TRANSB_DATA_N1, 0); ++ I915_WRITE(TRANSB_DP_LINK_M1, 0); ++ I915_WRITE(TRANSB_DP_LINK_N1, 0); ++ } ++ } + + if (!is_edp) { + I915_WRITE(fp_reg, fp); +@@ -3328,7 +3719,7 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + /* Wait for the clocks to stabilize. */ + udelay(150); + +- if (IS_I965G(dev) && !IS_IRONLAKE(dev)) { ++ if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) { + if (is_sdvo) { + sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; + I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | +@@ -3375,14 +3766,14 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + /* pipesrc and dspsize control the size that is scaled from, which should + * always be the user's requested size. + */ +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | + (mode->hdisplay - 1)); + I915_WRITE(dsppos_reg, 0); + } + I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m); + I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n); + I915_WRITE(link_m1_reg, m_n.link_m); +@@ -3394,6 +3785,18 @@ static int intel_crtc_mode_set(struct drm_crtc *crtc, + /* enable FDI RX PLL too */ + temp = I915_READ(fdi_rx_reg); + I915_WRITE(fdi_rx_reg, temp | FDI_RX_PLL_ENABLE); ++ I915_READ(fdi_rx_reg); ++ udelay(200); ++ ++ /* enable FDI TX PLL too */ ++ temp = I915_READ(fdi_tx_reg); ++ I915_WRITE(fdi_tx_reg, temp | FDI_TX_PLL_ENABLE); ++ I915_READ(fdi_tx_reg); ++ ++ /* enable FDI RX PCDCLK */ ++ temp = I915_READ(fdi_rx_reg); ++ I915_WRITE(fdi_rx_reg, temp | FDI_SEL_PCDCLK); ++ I915_READ(fdi_rx_reg); + udelay(200); + } + } +@@ -3438,7 +3841,7 @@ void intel_crtc_load_lut(struct drm_crtc *crtc) + return; + + /* use legacy palette for Ironlake */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A : + LGC_PALETTE_B; + +@@ -3494,7 +3897,7 @@ static int intel_crtc_cursor_set(struct drm_crtc *crtc, + if (!bo) + return -ENOENT; + +- obj_priv = bo->driver_private; ++ obj_priv = to_intel_bo(bo); + + if (bo->size < width * height * 4) { + DRM_ERROR("buffer is to small\n"); +@@ -3638,9 +4041,9 @@ static void intel_crtc_gamma_set(struct drm_crtc *crtc, u16 *red, u16 *green, + * detection. + * + * It will be up to the load-detect code to adjust the pipe as appropriate for +- * its requirements. The pipe will be connected to no other outputs. ++ * its requirements. The pipe will be connected to no other encoders. + * +- * Currently this code will only succeed if there is a pipe with no outputs ++ * Currently this code will only succeed if there is a pipe with no encoders + * configured for it. In the future, it could choose to temporarily disable + * some outputs to free up a pipe for its use. + * +@@ -3653,14 +4056,15 @@ static struct drm_display_mode load_detect_mode = { + 704, 832, 0, 480, 489, 491, 520, 0, DRM_MODE_FLAG_NHSYNC | DRM_MODE_FLAG_NVSYNC), + }; + +-struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output, ++struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder, ++ struct drm_connector *connector, + struct drm_display_mode *mode, + int *dpms_mode) + { + struct intel_crtc *intel_crtc; + struct drm_crtc *possible_crtc; + struct drm_crtc *supported_crtc =NULL; +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = &intel_encoder->enc; + struct drm_crtc *crtc = NULL; + struct drm_device *dev = encoder->dev; + struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; +@@ -3712,8 +4116,8 @@ struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output, + } + + encoder->crtc = crtc; +- intel_output->base.encoder = encoder; +- intel_output->load_detect_temp = true; ++ connector->encoder = encoder; ++ intel_encoder->load_detect_temp = true; + + intel_crtc = to_intel_crtc(crtc); + *dpms_mode = intel_crtc->dpms_mode; +@@ -3738,23 +4142,24 @@ struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output, + return crtc; + } + +-void intel_release_load_detect_pipe(struct intel_output *intel_output, int dpms_mode) ++void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder, ++ struct drm_connector *connector, int dpms_mode) + { +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = &intel_encoder->enc; + struct drm_device *dev = encoder->dev; + struct drm_crtc *crtc = encoder->crtc; + struct drm_encoder_helper_funcs *encoder_funcs = encoder->helper_private; + struct drm_crtc_helper_funcs *crtc_funcs = crtc->helper_private; + +- if (intel_output->load_detect_temp) { ++ if (intel_encoder->load_detect_temp) { + encoder->crtc = NULL; +- intel_output->base.encoder = NULL; +- intel_output->load_detect_temp = false; ++ connector->encoder = NULL; ++ intel_encoder->load_detect_temp = false; + crtc->enabled = drm_helper_crtc_in_use(crtc); + drm_helper_disable_unused_functions(dev); + } + +- /* Switch crtc and output back off if necessary */ ++ /* Switch crtc and encoder back off if necessary */ + if (crtc->enabled && dpms_mode != DRM_MODE_DPMS_ON) { + if (encoder->crtc == crtc) + encoder_funcs->dpms(encoder, dpms_mode); +@@ -3921,7 +4326,7 @@ static void intel_increase_pllclock(struct drm_crtc *crtc, bool schedule) + int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; + int dpll = I915_READ(dpll_reg); + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return; + + if (!dev_priv->lvds_downclock_avail) +@@ -3960,7 +4365,7 @@ static void intel_decrease_pllclock(struct drm_crtc *crtc) + int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; + int dpll = I915_READ(dpll_reg); + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return; + + if (!dev_priv->lvds_downclock_avail) +@@ -4010,6 +4415,11 @@ static void intel_idle_update(struct work_struct *work) + + mutex_lock(&dev->struct_mutex); + ++ if (IS_I945G(dev) || IS_I945GM(dev)) { ++ DRM_DEBUG_DRIVER("enable memory self refresh on 945\n"); ++ I915_WRITE(FW_BLC_SELF, FW_BLC_SELF_EN_MASK | FW_BLC_SELF_EN); ++ } ++ + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + /* Skip inactive CRTCs */ + if (!crtc->fb) +@@ -4043,9 +4453,17 @@ void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj) + if (!drm_core_check_feature(dev, DRIVER_MODESET)) + return; + +- if (!dev_priv->busy) ++ if (!dev_priv->busy) { ++ if (IS_I945G(dev) || IS_I945GM(dev)) { ++ u32 fw_blc_self; ++ ++ DRM_DEBUG_DRIVER("disable memory self refresh on 945\n"); ++ fw_blc_self = I915_READ(FW_BLC_SELF); ++ fw_blc_self &= ~FW_BLC_SELF_EN; ++ I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK); ++ } + dev_priv->busy = true; +- else ++ } else + mod_timer(&dev_priv->idle_timer, jiffies + + msecs_to_jiffies(GPU_IDLE_TIMEOUT)); + +@@ -4057,6 +4475,14 @@ void intel_mark_busy(struct drm_device *dev, struct drm_gem_object *obj) + intel_fb = to_intel_framebuffer(crtc->fb); + if (intel_fb->obj == obj) { + if (!intel_crtc->busy) { ++ if (IS_I945G(dev) || IS_I945GM(dev)) { ++ u32 fw_blc_self; ++ ++ DRM_DEBUG_DRIVER("disable memory self refresh on 945\n"); ++ fw_blc_self = I915_READ(FW_BLC_SELF); ++ fw_blc_self &= ~FW_BLC_SELF_EN; ++ I915_WRITE(FW_BLC_SELF, fw_blc_self | FW_BLC_SELF_EN_MASK); ++ } + /* Non-busy -> busy, upclock */ + intel_increase_pllclock(crtc, true); + intel_crtc->busy = true; +@@ -4118,7 +4544,7 @@ void intel_finish_page_flip(struct drm_device *dev, int pipe) + work = intel_crtc->unpin_work; + if (work == NULL || !work->pending) { + if (work && !work->pending) { +- obj_priv = work->pending_flip_obj->driver_private; ++ obj_priv = to_intel_bo(work->pending_flip_obj); + DRM_DEBUG_DRIVER("flip finish: %p (%d) not pending?\n", + obj_priv, + atomic_read(&obj_priv->pending_flip)); +@@ -4143,7 +4569,7 @@ void intel_finish_page_flip(struct drm_device *dev, int pipe) + + spin_unlock_irqrestore(&dev->event_lock, flags); + +- obj_priv = work->pending_flip_obj->driver_private; ++ obj_priv = to_intel_bo(work->pending_flip_obj); + + /* Initial scanout buffer will have a 0 pending flip count */ + if ((atomic_read(&obj_priv->pending_flip) == 0) || +@@ -4214,7 +4640,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, + ret = intel_pin_and_fence_fb_obj(dev, obj); + if (ret != 0) { + DRM_DEBUG_DRIVER("flip queue: %p pin & fence failed\n", +- obj->driver_private); ++ to_intel_bo(obj)); + kfree(work); + intel_crtc->unpin_work = NULL; + mutex_unlock(&dev->struct_mutex); +@@ -4228,7 +4654,7 @@ static int intel_crtc_page_flip(struct drm_crtc *crtc, + crtc->fb = fb; + i915_gem_object_flush_write_domain(obj); + drm_vblank_get(dev, intel_crtc->pipe); +- obj_priv = obj->driver_private; ++ obj_priv = to_intel_bo(obj); + atomic_inc(&obj_priv->pending_flip); + work->pending_flip_obj = obj; + +@@ -4354,15 +4780,15 @@ struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe) + return crtc; + } + +-static int intel_connector_clones(struct drm_device *dev, int type_mask) ++static int intel_encoder_clones(struct drm_device *dev, int type_mask) + { + int index_mask = 0; +- struct drm_connector *connector; ++ struct drm_encoder *encoder; + int entry = 0; + +- list_for_each_entry(connector, &dev->mode_config.connector_list, head) { +- struct intel_output *intel_output = to_intel_output(connector); +- if (type_mask & intel_output->clone_mask) ++ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ if (type_mask & intel_encoder->clone_mask) + index_mask |= (1 << entry); + entry++; + } +@@ -4373,7 +4799,7 @@ static int intel_connector_clones(struct drm_device *dev, int type_mask) + static void intel_setup_outputs(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; +- struct drm_connector *connector; ++ struct drm_encoder *encoder; + + intel_crt_init(dev); + +@@ -4381,16 +4807,15 @@ static void intel_setup_outputs(struct drm_device *dev) + if (IS_MOBILE(dev) && !IS_I830(dev)) + intel_lvds_init(dev); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + int found; + + if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED)) + intel_dp_init(dev, DP_A); + + if (I915_READ(HDMIB) & PORT_DETECTED) { +- /* check SDVOB */ +- /* found = intel_sdvo_init(dev, HDMIB); */ +- found = 0; ++ /* PCH SDVOB multiplex with HDMIB */ ++ found = intel_sdvo_init(dev, PCH_SDVOB); + if (!found) + intel_hdmi_init(dev, HDMIB); + if (!found && (I915_READ(PCH_DP_B) & DP_DETECTED)) +@@ -4450,19 +4875,18 @@ static void intel_setup_outputs(struct drm_device *dev) + DRM_DEBUG_KMS("probing DP_D\n"); + intel_dp_init(dev, DP_D); + } +- } else if (IS_I8XX(dev)) ++ } else if (IS_GEN2(dev)) + intel_dvo_init(dev); + + if (SUPPORTS_TV(dev)) + intel_tv_init(dev); + +- list_for_each_entry(connector, &dev->mode_config.connector_list, head) { +- struct intel_output *intel_output = to_intel_output(connector); +- struct drm_encoder *encoder = &intel_output->enc; ++ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + +- encoder->possible_crtcs = intel_output->crtc_mask; +- encoder->possible_clones = intel_connector_clones(dev, +- intel_output->clone_mask); ++ encoder->possible_crtcs = intel_encoder->crtc_mask; ++ encoder->possible_clones = intel_encoder_clones(dev, ++ intel_encoder->clone_mask); + } + } + +@@ -4586,6 +5010,91 @@ err_unref: + return NULL; + } + ++void ironlake_enable_drps(struct drm_device *dev) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ u32 rgvmodectl = I915_READ(MEMMODECTL), rgvswctl; ++ u8 fmax, fmin, fstart, vstart; ++ int i = 0; ++ ++ /* 100ms RC evaluation intervals */ ++ I915_WRITE(RCUPEI, 100000); ++ I915_WRITE(RCDNEI, 100000); ++ ++ /* Set max/min thresholds to 90ms and 80ms respectively */ ++ I915_WRITE(RCBMAXAVG, 90000); ++ I915_WRITE(RCBMINAVG, 80000); ++ ++ I915_WRITE(MEMIHYST, 1); ++ ++ /* Set up min, max, and cur for interrupt handling */ ++ fmax = (rgvmodectl & MEMMODE_FMAX_MASK) >> MEMMODE_FMAX_SHIFT; ++ fmin = (rgvmodectl & MEMMODE_FMIN_MASK); ++ fstart = (rgvmodectl & MEMMODE_FSTART_MASK) >> ++ MEMMODE_FSTART_SHIFT; ++ vstart = (I915_READ(PXVFREQ_BASE + (fstart * 4)) & PXVFREQ_PX_MASK) >> ++ PXVFREQ_PX_SHIFT; ++ ++ dev_priv->max_delay = fstart; /* can't go to fmax w/o IPS */ ++ dev_priv->min_delay = fmin; ++ dev_priv->cur_delay = fstart; ++ ++ I915_WRITE(MEMINTREN, MEMINT_CX_SUPR_EN | MEMINT_EVAL_CHG_EN); ++ ++ /* ++ * Interrupts will be enabled in ironlake_irq_postinstall ++ */ ++ ++ I915_WRITE(VIDSTART, vstart); ++ POSTING_READ(VIDSTART); ++ ++ rgvmodectl |= MEMMODE_SWMODE_EN; ++ I915_WRITE(MEMMODECTL, rgvmodectl); ++ ++ while (I915_READ(MEMSWCTL) & MEMCTL_CMD_STS) { ++ if (i++ > 100) { ++ DRM_ERROR("stuck trying to change perf mode\n"); ++ break; ++ } ++ msleep(1); ++ } ++ msleep(1); ++ ++ rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | ++ (fstart << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; ++ I915_WRITE(MEMSWCTL, rgvswctl); ++ POSTING_READ(MEMSWCTL); ++ ++ rgvswctl |= MEMCTL_CMD_STS; ++ I915_WRITE(MEMSWCTL, rgvswctl); ++} ++ ++void ironlake_disable_drps(struct drm_device *dev) ++{ ++ struct drm_i915_private *dev_priv = dev->dev_private; ++ u32 rgvswctl; ++ u8 fstart; ++ ++ /* Ack interrupts, disable EFC interrupt */ ++ I915_WRITE(MEMINTREN, I915_READ(MEMINTREN) & ~MEMINT_EVAL_CHG_EN); ++ I915_WRITE(MEMINTRSTS, MEMINT_EVAL_CHG); ++ I915_WRITE(DEIER, I915_READ(DEIER) & ~DE_PCU_EVENT); ++ I915_WRITE(DEIIR, DE_PCU_EVENT); ++ I915_WRITE(DEIMR, I915_READ(DEIMR) | DE_PCU_EVENT); ++ ++ /* Go back to the starting frequency */ ++ fstart = (I915_READ(MEMMODECTL) & MEMMODE_FSTART_MASK) >> ++ MEMMODE_FSTART_SHIFT; ++ rgvswctl = (MEMCTL_CMD_CHFREQ << MEMCTL_CMD_SHIFT) | ++ (fstart << MEMCTL_FREQ_SHIFT) | MEMCTL_SFCAVM; ++ I915_WRITE(MEMSWCTL, rgvswctl); ++ msleep(1); ++ rgvswctl |= MEMCTL_CMD_STS; ++ I915_WRITE(MEMSWCTL, rgvswctl); ++ msleep(1); ++ ++} ++ + void intel_init_clock_gating(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; +@@ -4594,7 +5103,40 @@ void intel_init_clock_gating(struct drm_device *dev) + * Disable clock gating reported to work incorrectly according to the + * specs, but enable as much else as we can. + */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { ++ uint32_t dspclk_gate = VRHUNIT_CLOCK_GATE_DISABLE; ++ ++ if (IS_IRONLAKE(dev)) { ++ /* Required for FBC */ ++ dspclk_gate |= DPFDUNIT_CLOCK_GATE_DISABLE; ++ /* Required for CxSR */ ++ dspclk_gate |= DPARBUNIT_CLOCK_GATE_DISABLE; ++ ++ I915_WRITE(PCH_3DCGDIS0, ++ MARIUNIT_CLOCK_GATE_DISABLE | ++ SVSMUNIT_CLOCK_GATE_DISABLE); ++ } ++ ++ I915_WRITE(PCH_DSPCLK_GATE_D, dspclk_gate); ++ ++ /* ++ * According to the spec the following bits should be set in ++ * order to enable memory self-refresh ++ * The bit 22/21 of 0x42004 ++ * The bit 5 of 0x42020 ++ * The bit 15 of 0x45000 ++ */ ++ if (IS_IRONLAKE(dev)) { ++ I915_WRITE(ILK_DISPLAY_CHICKEN2, ++ (I915_READ(ILK_DISPLAY_CHICKEN2) | ++ ILK_DPARB_GATE | ILK_VSDPFD_FULL)); ++ I915_WRITE(ILK_DSPCLK_GATE, ++ (I915_READ(ILK_DSPCLK_GATE) | ++ ILK_DPARB_CLK_GATE)); ++ I915_WRITE(DISP_ARB_CTL, ++ (I915_READ(DISP_ARB_CTL) | ++ DISP_FBC_WM_DIS)); ++ } + return; + } else if (IS_G4X(dev)) { + uint32_t dspclk_gate; +@@ -4642,14 +5184,14 @@ void intel_init_clock_gating(struct drm_device *dev) + struct drm_i915_gem_object *obj_priv = NULL; + + if (dev_priv->pwrctx) { +- obj_priv = dev_priv->pwrctx->driver_private; ++ obj_priv = to_intel_bo(dev_priv->pwrctx); + } else { + struct drm_gem_object *pwrctx; + + pwrctx = intel_alloc_power_context(dev); + if (pwrctx) { + dev_priv->pwrctx = pwrctx; +- obj_priv = pwrctx->driver_private; ++ obj_priv = to_intel_bo(pwrctx); + } + } + +@@ -4667,7 +5209,7 @@ static void intel_init_display(struct drm_device *dev) + struct drm_i915_private *dev_priv = dev->dev_private; + + /* We always want a DPMS function */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + dev_priv->display.dpms = ironlake_crtc_dpms; + else + dev_priv->display.dpms = i9xx_crtc_dpms; +@@ -4678,7 +5220,7 @@ static void intel_init_display(struct drm_device *dev) + dev_priv->display.fbc_enabled = g4x_fbc_enabled; + dev_priv->display.enable_fbc = g4x_enable_fbc; + dev_priv->display.disable_fbc = g4x_disable_fbc; +- } else if (IS_I965GM(dev) || IS_I945GM(dev) || IS_I915GM(dev)) { ++ } else if (IS_I965GM(dev)) { + dev_priv->display.fbc_enabled = i8xx_fbc_enabled; + dev_priv->display.enable_fbc = i8xx_enable_fbc; + dev_priv->display.disable_fbc = i8xx_disable_fbc; +@@ -4710,23 +5252,46 @@ static void intel_init_display(struct drm_device *dev) + i830_get_display_clock_speed; + + /* For FIFO watermark updates */ +- if (IS_IRONLAKE(dev)) +- dev_priv->display.update_wm = NULL; +- else if (IS_G4X(dev)) ++ if (HAS_PCH_SPLIT(dev)) { ++ if (IS_IRONLAKE(dev)) { ++ if (I915_READ(MLTR_ILK) & ILK_SRLT_MASK) ++ dev_priv->display.update_wm = ironlake_update_wm; ++ else { ++ DRM_DEBUG_KMS("Failed to get proper latency. " ++ "Disable CxSR\n"); ++ dev_priv->display.update_wm = NULL; ++ } ++ } else ++ dev_priv->display.update_wm = NULL; ++ } else if (IS_PINEVIEW(dev)) { ++ if (!intel_get_cxsr_latency(IS_PINEVIEW_G(dev), ++ dev_priv->fsb_freq, ++ dev_priv->mem_freq)) { ++ DRM_INFO("failed to find known CxSR latency " ++ "(found fsb freq %d, mem freq %d), " ++ "disabling CxSR\n", ++ dev_priv->fsb_freq, dev_priv->mem_freq); ++ /* Disable CxSR and never update its watermark again */ ++ pineview_disable_cxsr(dev); ++ dev_priv->display.update_wm = NULL; ++ } else ++ dev_priv->display.update_wm = pineview_update_wm; ++ } else if (IS_G4X(dev)) + dev_priv->display.update_wm = g4x_update_wm; + else if (IS_I965G(dev)) + dev_priv->display.update_wm = i965_update_wm; +- else if (IS_I9XX(dev) || IS_MOBILE(dev)) { ++ else if (IS_I9XX(dev)) { + dev_priv->display.update_wm = i9xx_update_wm; + dev_priv->display.get_fifo_size = i9xx_get_fifo_size; ++ } else if (IS_I85X(dev)) { ++ dev_priv->display.update_wm = i9xx_update_wm; ++ dev_priv->display.get_fifo_size = i85x_get_fifo_size; + } else { +- if (IS_I85X(dev)) +- dev_priv->display.get_fifo_size = i85x_get_fifo_size; +- else if (IS_845G(dev)) ++ dev_priv->display.update_wm = i830_update_wm; ++ if (IS_845G(dev)) + dev_priv->display.get_fifo_size = i845_get_fifo_size; + else + dev_priv->display.get_fifo_size = i830_get_fifo_size; +- dev_priv->display.update_wm = i830_update_wm; + } + } + +@@ -4769,11 +5334,6 @@ void intel_modeset_init(struct drm_device *dev) + DRM_DEBUG_KMS("%d display pipe%s available.\n", + num_pipe, num_pipe > 1 ? "s" : ""); + +- if (IS_I85X(dev)) +- pci_read_config_word(dev->pdev, HPLLCC, &dev_priv->orig_clock); +- else if (IS_I9XX(dev) || IS_G4X(dev)) +- pci_read_config_word(dev->pdev, GCFGC, &dev_priv->orig_clock); +- + for (i = 0; i < num_pipe; i++) { + intel_crtc_init(dev, i); + } +@@ -4782,18 +5342,14 @@ void intel_modeset_init(struct drm_device *dev) + + intel_init_clock_gating(dev); + ++ if (IS_IRONLAKE_M(dev)) ++ ironlake_enable_drps(dev); ++ + INIT_WORK(&dev_priv->idle_work, intel_idle_update); + setup_timer(&dev_priv->idle_timer, intel_gpu_idle_timer, + (unsigned long)dev); + + intel_setup_overlay(dev); +- +- if (IS_PINEVIEW(dev) && !intel_get_cxsr_latency(IS_PINEVIEW_G(dev), +- dev_priv->fsb_freq, +- dev_priv->mem_freq)) +- DRM_INFO("failed to find known CxSR latency " +- "(found fsb freq %d, mem freq %d), disabling CxSR\n", +- dev_priv->fsb_freq, dev_priv->mem_freq); + } + + void intel_modeset_cleanup(struct drm_device *dev) +@@ -4822,27 +5378,45 @@ void intel_modeset_cleanup(struct drm_device *dev) + if (dev_priv->pwrctx) { + struct drm_i915_gem_object *obj_priv; + +- obj_priv = dev_priv->pwrctx->driver_private; ++ obj_priv = to_intel_bo(dev_priv->pwrctx); + I915_WRITE(PWRCTXA, obj_priv->gtt_offset &~ PWRCTX_EN); + I915_READ(PWRCTXA); + i915_gem_object_unpin(dev_priv->pwrctx); + drm_gem_object_unreference(dev_priv->pwrctx); + } + ++ if (IS_IRONLAKE_M(dev)) ++ ironlake_disable_drps(dev); ++ + mutex_unlock(&dev->struct_mutex); + + drm_mode_config_cleanup(dev); + } + + +-/* current intel driver doesn't take advantage of encoders +- always give back the encoder for the connector +-*/ +-struct drm_encoder *intel_best_encoder(struct drm_connector *connector) ++/* ++ * Return which encoder is currently attached for connector. ++ */ ++struct drm_encoder *intel_attached_encoder (struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); ++ struct drm_mode_object *obj; ++ struct drm_encoder *encoder; ++ int i; + +- return &intel_output->enc; ++ for (i = 0; i < DRM_CONNECTOR_MAX_ENCODER; i++) { ++ if (connector->encoder_ids[i] == 0) ++ break; ++ ++ obj = drm_mode_object_find(connector->dev, ++ connector->encoder_ids[i], ++ DRM_MODE_OBJECT_ENCODER); ++ if (!obj) ++ continue; ++ ++ encoder = obj_to_encoder(obj); ++ return encoder; ++ } ++ return NULL; + } + + /* +diff --git a/drivers/gpu/drm/i915/intel_dp.c b/drivers/gpu/drm/i915/intel_dp.c +--- a/drivers/gpu/drm/i915/intel_dp.c ++++ b/drivers/gpu/drm/i915/intel_dp.c +@@ -47,30 +47,28 @@ struct intel_dp_priv { + uint32_t output_reg; + uint32_t DP; + uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]; +- uint32_t save_DP; +- uint8_t save_link_configuration[DP_LINK_CONFIGURATION_SIZE]; + bool has_audio; + int dpms_mode; + uint8_t link_bw; + uint8_t lane_count; + uint8_t dpcd[4]; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; + struct i2c_adapter adapter; + struct i2c_algo_dp_aux_data algo; + }; + + static void +-intel_dp_link_train(struct intel_output *intel_output, uint32_t DP, ++intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, + uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]); + + static void +-intel_dp_link_down(struct intel_output *intel_output, uint32_t DP); ++intel_dp_link_down(struct intel_encoder *intel_encoder, uint32_t DP); + + void +-intel_edp_link_config (struct intel_output *intel_output, ++intel_edp_link_config (struct intel_encoder *intel_encoder, + int *lane_num, int *link_bw) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + + *lane_num = dp_priv->lane_count; + if (dp_priv->link_bw == DP_LINK_BW_1_62) +@@ -80,9 +78,9 @@ intel_edp_link_config (struct intel_output *intel_output, + } + + static int +-intel_dp_max_lane_count(struct intel_output *intel_output) ++intel_dp_max_lane_count(struct intel_encoder *intel_encoder) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + int max_lane_count = 4; + + if (dp_priv->dpcd[0] >= 0x11) { +@@ -98,9 +96,9 @@ intel_dp_max_lane_count(struct intel_output *intel_output) + } + + static int +-intel_dp_max_link_bw(struct intel_output *intel_output) ++intel_dp_max_link_bw(struct intel_encoder *intel_encoder) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + int max_link_bw = dp_priv->dpcd[1]; + + switch (max_link_bw) { +@@ -126,11 +124,11 @@ intel_dp_link_clock(uint8_t link_bw) + /* I think this is a fiction */ + static int + intel_dp_link_required(struct drm_device *dev, +- struct intel_output *intel_output, int pixel_clock) ++ struct intel_encoder *intel_encoder, int pixel_clock) + { + struct drm_i915_private *dev_priv = dev->dev_private; + +- if (IS_eDP(intel_output)) ++ if (IS_eDP(intel_encoder)) + return (pixel_clock * dev_priv->edp_bpp) / 8; + else + return pixel_clock * 3; +@@ -140,11 +138,12 @@ static int + intel_dp_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { +- struct intel_output *intel_output = to_intel_output(connector); +- int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_output)); +- int max_lanes = intel_dp_max_lane_count(intel_output); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ int max_link_clock = intel_dp_link_clock(intel_dp_max_link_bw(intel_encoder)); ++ int max_lanes = intel_dp_max_lane_count(intel_encoder); + +- if (intel_dp_link_required(connector->dev, intel_output, mode->clock) ++ if (intel_dp_link_required(connector->dev, intel_encoder, mode->clock) + > max_link_clock * max_lanes) + return MODE_CLOCK_HIGH; + +@@ -208,13 +207,13 @@ intel_hrawclk(struct drm_device *dev) + } + + static int +-intel_dp_aux_ch(struct intel_output *intel_output, ++intel_dp_aux_ch(struct intel_encoder *intel_encoder, + uint8_t *send, int send_bytes, + uint8_t *recv, int recv_size) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + uint32_t output_reg = dp_priv->output_reg; +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; + uint32_t ch_ctl = output_reg + 0x10; + uint32_t ch_data = ch_ctl + 4; +@@ -223,19 +222,27 @@ intel_dp_aux_ch(struct intel_output *intel_output, + uint32_t ctl; + uint32_t status; + uint32_t aux_clock_divider; +- int try; ++ int try, precharge; + + /* The clock divider is based off the hrawclk, + * and would like to run at 2MHz. So, take the + * hrawclk value and divide by 2 and use that + */ +- if (IS_eDP(intel_output)) +- aux_clock_divider = 225; /* eDP input clock at 450Mhz */ +- else if (IS_IRONLAKE(dev)) ++ if (IS_eDP(intel_encoder)) { ++ if (IS_GEN6(dev)) ++ aux_clock_divider = 200; /* SNB eDP input clock at 400Mhz */ ++ else ++ aux_clock_divider = 225; /* eDP input clock at 450Mhz */ ++ } else if (HAS_PCH_SPLIT(dev)) + aux_clock_divider = 62; /* IRL input clock fixed at 125Mhz */ + else + aux_clock_divider = intel_hrawclk(dev) / 2; + ++ if (IS_GEN6(dev)) ++ precharge = 3; ++ else ++ precharge = 5; ++ + /* Must try at least 3 times according to DP spec */ + for (try = 0; try < 5; try++) { + /* Load the send data into the aux channel data registers */ +@@ -248,7 +255,7 @@ intel_dp_aux_ch(struct intel_output *intel_output, + ctl = (DP_AUX_CH_CTL_SEND_BUSY | + DP_AUX_CH_CTL_TIME_OUT_400us | + (send_bytes << DP_AUX_CH_CTL_MESSAGE_SIZE_SHIFT) | +- (5 << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | ++ (precharge << DP_AUX_CH_CTL_PRECHARGE_2US_SHIFT) | + (aux_clock_divider << DP_AUX_CH_CTL_BIT_CLOCK_2X_SHIFT) | + DP_AUX_CH_CTL_DONE | + DP_AUX_CH_CTL_TIME_OUT_ERROR | +@@ -312,7 +319,7 @@ intel_dp_aux_ch(struct intel_output *intel_output, + + /* Write data to the aux channel in native mode */ + static int +-intel_dp_aux_native_write(struct intel_output *intel_output, ++intel_dp_aux_native_write(struct intel_encoder *intel_encoder, + uint16_t address, uint8_t *send, int send_bytes) + { + int ret; +@@ -329,7 +336,7 @@ intel_dp_aux_native_write(struct intel_output *intel_output, + memcpy(&msg[4], send, send_bytes); + msg_bytes = send_bytes + 4; + for (;;) { +- ret = intel_dp_aux_ch(intel_output, msg, msg_bytes, &ack, 1); ++ ret = intel_dp_aux_ch(intel_encoder, msg, msg_bytes, &ack, 1); + if (ret < 0) + return ret; + if ((ack & AUX_NATIVE_REPLY_MASK) == AUX_NATIVE_REPLY_ACK) +@@ -344,15 +351,15 @@ intel_dp_aux_native_write(struct intel_output *intel_output, + + /* Write a single byte to the aux channel in native mode */ + static int +-intel_dp_aux_native_write_1(struct intel_output *intel_output, ++intel_dp_aux_native_write_1(struct intel_encoder *intel_encoder, + uint16_t address, uint8_t byte) + { +- return intel_dp_aux_native_write(intel_output, address, &byte, 1); ++ return intel_dp_aux_native_write(intel_encoder, address, &byte, 1); + } + + /* read bytes from a native aux channel */ + static int +-intel_dp_aux_native_read(struct intel_output *intel_output, ++intel_dp_aux_native_read(struct intel_encoder *intel_encoder, + uint16_t address, uint8_t *recv, int recv_bytes) + { + uint8_t msg[4]; +@@ -371,7 +378,7 @@ intel_dp_aux_native_read(struct intel_output *intel_output, + reply_bytes = recv_bytes + 1; + + for (;;) { +- ret = intel_dp_aux_ch(intel_output, msg, msg_bytes, ++ ret = intel_dp_aux_ch(intel_encoder, msg, msg_bytes, + reply, reply_bytes); + if (ret == 0) + return -EPROTO; +@@ -397,7 +404,7 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, + struct intel_dp_priv *dp_priv = container_of(adapter, + struct intel_dp_priv, + adapter); +- struct intel_output *intel_output = dp_priv->intel_output; ++ struct intel_encoder *intel_encoder = dp_priv->intel_encoder; + uint16_t address = algo_data->address; + uint8_t msg[5]; + uint8_t reply[2]; +@@ -436,7 +443,7 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, + } + + for (;;) { +- ret = intel_dp_aux_ch(intel_output, ++ ret = intel_dp_aux_ch(intel_encoder, + msg, msg_bytes, + reply, reply_bytes); + if (ret < 0) { +@@ -464,9 +471,10 @@ intel_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, + } + + static int +-intel_dp_i2c_init(struct intel_output *intel_output, const char *name) ++intel_dp_i2c_init(struct intel_encoder *intel_encoder, ++ struct intel_connector *intel_connector, const char *name) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + + DRM_DEBUG_KMS("i2c_init %s\n", name); + dp_priv->algo.running = false; +@@ -479,7 +487,7 @@ intel_dp_i2c_init(struct intel_output *intel_output, const char *name) + strncpy (dp_priv->adapter.name, name, sizeof(dp_priv->adapter.name) - 1); + dp_priv->adapter.name[sizeof(dp_priv->adapter.name) - 1] = '\0'; + dp_priv->adapter.algo_data = &dp_priv->algo; +- dp_priv->adapter.dev.parent = &intel_output->base.kdev; ++ dp_priv->adapter.dev.parent = &intel_connector->base.kdev; + + return i2c_dp_aux_add_bus(&dp_priv->adapter); + } +@@ -488,18 +496,18 @@ static bool + intel_dp_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) + { +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + int lane_count, clock; +- int max_lane_count = intel_dp_max_lane_count(intel_output); +- int max_clock = intel_dp_max_link_bw(intel_output) == DP_LINK_BW_2_7 ? 1 : 0; ++ int max_lane_count = intel_dp_max_lane_count(intel_encoder); ++ int max_clock = intel_dp_max_link_bw(intel_encoder) == DP_LINK_BW_2_7 ? 1 : 0; + static int bws[2] = { DP_LINK_BW_1_62, DP_LINK_BW_2_7 }; + + for (lane_count = 1; lane_count <= max_lane_count; lane_count <<= 1) { + for (clock = 0; clock <= max_clock; clock++) { + int link_avail = intel_dp_link_clock(bws[clock]) * lane_count; + +- if (intel_dp_link_required(encoder->dev, intel_output, mode->clock) ++ if (intel_dp_link_required(encoder->dev, intel_encoder, mode->clock) + <= link_avail) { + dp_priv->link_bw = bws[clock]; + dp_priv->lane_count = lane_count; +@@ -554,23 +562,26 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, + { + struct drm_device *dev = crtc->dev; + struct drm_mode_config *mode_config = &dev->mode_config; +- struct drm_connector *connector; ++ struct drm_encoder *encoder; + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); + int lane_count = 4; + struct intel_dp_m_n m_n; + + /* +- * Find the lane count in the intel_output private ++ * Find the lane count in the intel_encoder private + */ +- list_for_each_entry(connector, &mode_config->connector_list, head) { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ list_for_each_entry(encoder, &mode_config->encoder_list, head) { ++ struct intel_encoder *intel_encoder; ++ struct intel_dp_priv *dp_priv; + +- if (!connector->encoder || connector->encoder->crtc != crtc) ++ if (!encoder || encoder->crtc != crtc) + continue; + +- if (intel_output->type == INTEL_OUTPUT_DISPLAYPORT) { ++ intel_encoder = enc_to_intel_encoder(encoder); ++ dp_priv = intel_encoder->dev_priv; ++ ++ if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) { + lane_count = dp_priv->lane_count; + break; + } +@@ -584,7 +595,7 @@ intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, + intel_dp_compute_m_n(3, lane_count, + mode->clock, adjusted_mode->clock, &m_n); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + if (intel_crtc->pipe == 0) { + I915_WRITE(TRANSA_DATA_M1, + ((m_n.tu - 1) << PIPE_GMCH_DATA_M_TU_SIZE_SHIFT) | +@@ -625,16 +636,24 @@ static void + intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) + { +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; +- struct drm_crtc *crtc = intel_output->enc.crtc; ++ struct drm_device *dev = encoder->dev; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; ++ struct drm_crtc *crtc = intel_encoder->enc.crtc; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); + +- dp_priv->DP = (DP_LINK_TRAIN_OFF | +- DP_VOLTAGE_0_4 | +- DP_PRE_EMPHASIS_0 | +- DP_SYNC_VS_HIGH | +- DP_SYNC_HS_HIGH); ++ dp_priv->DP = (DP_VOLTAGE_0_4 | ++ DP_PRE_EMPHASIS_0); ++ ++ if (adjusted_mode->flags & DRM_MODE_FLAG_PHSYNC) ++ dp_priv->DP |= DP_SYNC_HS_HIGH; ++ if (adjusted_mode->flags & DRM_MODE_FLAG_PVSYNC) ++ dp_priv->DP |= DP_SYNC_VS_HIGH; ++ ++ if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) ++ dp_priv->DP |= DP_LINK_TRAIN_OFF_CPT; ++ else ++ dp_priv->DP |= DP_LINK_TRAIN_OFF; + + switch (dp_priv->lane_count) { + case 1: +@@ -663,10 +682,11 @@ intel_dp_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, + dp_priv->DP |= DP_ENHANCED_FRAMING; + } + +- if (intel_crtc->pipe == 1) ++ /* CPT DP's pipe select is decided in TRANS_DP_CTL */ ++ if (intel_crtc->pipe == 1 && !HAS_PCH_CPT(dev)) + dp_priv->DP |= DP_PIPEB_SELECT; + +- if (IS_eDP(intel_output)) { ++ if (IS_eDP(intel_encoder)) { + /* don't miss out required setting for eDP */ + dp_priv->DP |= DP_PLL_ENABLE; + if (adjusted_mode->clock < 200000) +@@ -701,22 +721,22 @@ static void ironlake_edp_backlight_off (struct drm_device *dev) + static void + intel_dp_dpms(struct drm_encoder *encoder, int mode) + { +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; +- struct drm_device *dev = intel_output->base.dev; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; ++ struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; + uint32_t dp_reg = I915_READ(dp_priv->output_reg); + + if (mode != DRM_MODE_DPMS_ON) { + if (dp_reg & DP_PORT_EN) { +- intel_dp_link_down(intel_output, dp_priv->DP); +- if (IS_eDP(intel_output)) ++ intel_dp_link_down(intel_encoder, dp_priv->DP); ++ if (IS_eDP(intel_encoder)) + ironlake_edp_backlight_off(dev); + } + } else { + if (!(dp_reg & DP_PORT_EN)) { +- intel_dp_link_train(intel_output, dp_priv->DP, dp_priv->link_configuration); +- if (IS_eDP(intel_output)) ++ intel_dp_link_train(intel_encoder, dp_priv->DP, dp_priv->link_configuration); ++ if (IS_eDP(intel_encoder)) + ironlake_edp_backlight_on(dev); + } + } +@@ -728,12 +748,12 @@ intel_dp_dpms(struct drm_encoder *encoder, int mode) + * link status information + */ + static bool +-intel_dp_get_link_status(struct intel_output *intel_output, ++intel_dp_get_link_status(struct intel_encoder *intel_encoder, + uint8_t link_status[DP_LINK_STATUS_SIZE]) + { + int ret; + +- ret = intel_dp_aux_native_read(intel_output, ++ ret = intel_dp_aux_native_read(intel_encoder, + DP_LANE0_1_STATUS, + link_status, DP_LINK_STATUS_SIZE); + if (ret != DP_LINK_STATUS_SIZE) +@@ -748,20 +768,6 @@ intel_dp_link_status(uint8_t link_status[DP_LINK_STATUS_SIZE], + return link_status[r - DP_LANE0_1_STATUS]; + } + +-static void +-intel_dp_save(struct drm_connector *connector) +-{ +- struct intel_output *intel_output = to_intel_output(connector); +- struct drm_device *dev = intel_output->base.dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; +- +- dp_priv->save_DP = I915_READ(dp_priv->output_reg); +- intel_dp_aux_native_read(intel_output, DP_LINK_BW_SET, +- dp_priv->save_link_configuration, +- sizeof (dp_priv->save_link_configuration)); +-} +- + static uint8_t + intel_get_adjust_request_voltage(uint8_t link_status[DP_LINK_STATUS_SIZE], + int lane) +@@ -824,7 +830,7 @@ intel_dp_pre_emphasis_max(uint8_t voltage_swing) + } + + static void +-intel_get_adjust_train(struct intel_output *intel_output, ++intel_get_adjust_train(struct intel_encoder *intel_encoder, + uint8_t link_status[DP_LINK_STATUS_SIZE], + int lane_count, + uint8_t train_set[4]) +@@ -891,6 +897,25 @@ intel_dp_signal_levels(uint8_t train_set, int lane_count) + return signal_levels; + } + ++/* Gen6's DP voltage swing and pre-emphasis control */ ++static uint32_t ++intel_gen6_edp_signal_levels(uint8_t train_set) ++{ ++ switch (train_set & (DP_TRAIN_VOLTAGE_SWING_MASK|DP_TRAIN_PRE_EMPHASIS_MASK)) { ++ case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_0: ++ return EDP_LINK_TRAIN_400MV_0DB_SNB_B; ++ case DP_TRAIN_VOLTAGE_SWING_400 | DP_TRAIN_PRE_EMPHASIS_6: ++ return EDP_LINK_TRAIN_400MV_6DB_SNB_B; ++ case DP_TRAIN_VOLTAGE_SWING_600 | DP_TRAIN_PRE_EMPHASIS_3_5: ++ return EDP_LINK_TRAIN_600MV_3_5DB_SNB_B; ++ case DP_TRAIN_VOLTAGE_SWING_800 | DP_TRAIN_PRE_EMPHASIS_0: ++ return EDP_LINK_TRAIN_800MV_0DB_SNB_B; ++ default: ++ DRM_DEBUG_KMS("Unsupported voltage swing/pre-emphasis level\n"); ++ return EDP_LINK_TRAIN_400MV_0DB_SNB_B; ++ } ++} ++ + static uint8_t + intel_get_lane_status(uint8_t link_status[DP_LINK_STATUS_SIZE], + int lane) +@@ -941,15 +966,15 @@ intel_channel_eq_ok(uint8_t link_status[DP_LINK_STATUS_SIZE], int lane_count) + } + + static bool +-intel_dp_set_link_train(struct intel_output *intel_output, ++intel_dp_set_link_train(struct intel_encoder *intel_encoder, + uint32_t dp_reg_value, + uint8_t dp_train_pat, + uint8_t train_set[4], + bool first) + { +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + int ret; + + I915_WRITE(dp_priv->output_reg, dp_reg_value); +@@ -957,11 +982,11 @@ intel_dp_set_link_train(struct intel_output *intel_output, + if (first) + intel_wait_for_vblank(dev); + +- intel_dp_aux_native_write_1(intel_output, ++ intel_dp_aux_native_write_1(intel_encoder, + DP_TRAINING_PATTERN_SET, + dp_train_pat); + +- ret = intel_dp_aux_native_write(intel_output, ++ ret = intel_dp_aux_native_write(intel_encoder, + DP_TRAINING_LANE0_SET, train_set, 4); + if (ret != 4) + return false; +@@ -970,12 +995,12 @@ intel_dp_set_link_train(struct intel_output *intel_output, + } + + static void +-intel_dp_link_train(struct intel_output *intel_output, uint32_t DP, ++intel_dp_link_train(struct intel_encoder *intel_encoder, uint32_t DP, + uint8_t link_configuration[DP_LINK_CONFIGURATION_SIZE]) + { +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + uint8_t train_set[4]; + uint8_t link_status[DP_LINK_STATUS_SIZE]; + int i; +@@ -984,30 +1009,45 @@ intel_dp_link_train(struct intel_output *intel_output, uint32_t DP, + bool channel_eq = false; + bool first = true; + int tries; ++ u32 reg; + + /* Write the link configuration data */ +- intel_dp_aux_native_write(intel_output, 0x100, ++ intel_dp_aux_native_write(intel_encoder, DP_LINK_BW_SET, + link_configuration, DP_LINK_CONFIGURATION_SIZE); + + DP |= DP_PORT_EN; +- DP &= ~DP_LINK_TRAIN_MASK; ++ if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) ++ DP &= ~DP_LINK_TRAIN_MASK_CPT; ++ else ++ DP &= ~DP_LINK_TRAIN_MASK; + memset(train_set, 0, 4); + voltage = 0xff; + tries = 0; + clock_recovery = false; + for (;;) { + /* Use train_set[0] to set the voltage and pre emphasis values */ +- uint32_t signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count); +- DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; ++ uint32_t signal_levels; ++ if (IS_GEN6(dev) && IS_eDP(intel_encoder)) { ++ signal_levels = intel_gen6_edp_signal_levels(train_set[0]); ++ DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; ++ } else { ++ signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count); ++ DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; ++ } + +- if (!intel_dp_set_link_train(intel_output, DP | DP_LINK_TRAIN_PAT_1, ++ if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) ++ reg = DP | DP_LINK_TRAIN_PAT_1_CPT; ++ else ++ reg = DP | DP_LINK_TRAIN_PAT_1; ++ ++ if (!intel_dp_set_link_train(intel_encoder, reg, + DP_TRAINING_PATTERN_1, train_set, first)) + break; + first = false; + /* Set training pattern 1 */ + + udelay(100); +- if (!intel_dp_get_link_status(intel_output, link_status)) ++ if (!intel_dp_get_link_status(intel_encoder, link_status)) + break; + + if (intel_clock_recovery_ok(link_status, dp_priv->lane_count)) { +@@ -1032,7 +1072,7 @@ intel_dp_link_train(struct intel_output *intel_output, uint32_t DP, + voltage = train_set[0] & DP_TRAIN_VOLTAGE_SWING_MASK; + + /* Compute new train_set as requested by target */ +- intel_get_adjust_train(intel_output, link_status, dp_priv->lane_count, train_set); ++ intel_get_adjust_train(intel_encoder, link_status, dp_priv->lane_count, train_set); + } + + /* channel equalization */ +@@ -1040,17 +1080,29 @@ intel_dp_link_train(struct intel_output *intel_output, uint32_t DP, + channel_eq = false; + for (;;) { + /* Use train_set[0] to set the voltage and pre emphasis values */ +- uint32_t signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count); +- DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; ++ uint32_t signal_levels; ++ ++ if (IS_GEN6(dev) && IS_eDP(intel_encoder)) { ++ signal_levels = intel_gen6_edp_signal_levels(train_set[0]); ++ DP = (DP & ~EDP_LINK_TRAIN_VOL_EMP_MASK_SNB) | signal_levels; ++ } else { ++ signal_levels = intel_dp_signal_levels(train_set[0], dp_priv->lane_count); ++ DP = (DP & ~(DP_VOLTAGE_MASK|DP_PRE_EMPHASIS_MASK)) | signal_levels; ++ } ++ ++ if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) ++ reg = DP | DP_LINK_TRAIN_PAT_2_CPT; ++ else ++ reg = DP | DP_LINK_TRAIN_PAT_2; + + /* channel eq pattern */ +- if (!intel_dp_set_link_train(intel_output, DP | DP_LINK_TRAIN_PAT_2, ++ if (!intel_dp_set_link_train(intel_encoder, reg, + DP_TRAINING_PATTERN_2, train_set, + false)) + break; + + udelay(400); +- if (!intel_dp_get_link_status(intel_output, link_status)) ++ if (!intel_dp_get_link_status(intel_encoder, link_status)) + break; + + if (intel_channel_eq_ok(link_status, dp_priv->lane_count)) { +@@ -1063,56 +1115,55 @@ intel_dp_link_train(struct intel_output *intel_output, uint32_t DP, + break; + + /* Compute new train_set as requested by target */ +- intel_get_adjust_train(intel_output, link_status, dp_priv->lane_count, train_set); ++ intel_get_adjust_train(intel_encoder, link_status, dp_priv->lane_count, train_set); + ++tries; + } + +- I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_OFF); ++ if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) ++ reg = DP | DP_LINK_TRAIN_OFF_CPT; ++ else ++ reg = DP | DP_LINK_TRAIN_OFF; ++ ++ I915_WRITE(dp_priv->output_reg, reg); + POSTING_READ(dp_priv->output_reg); +- intel_dp_aux_native_write_1(intel_output, ++ intel_dp_aux_native_write_1(intel_encoder, + DP_TRAINING_PATTERN_SET, DP_TRAINING_PATTERN_DISABLE); + } + + static void +-intel_dp_link_down(struct intel_output *intel_output, uint32_t DP) ++intel_dp_link_down(struct intel_encoder *intel_encoder, uint32_t DP) + { +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + + DRM_DEBUG_KMS("\n"); + +- if (IS_eDP(intel_output)) { ++ if (IS_eDP(intel_encoder)) { + DP &= ~DP_PLL_ENABLE; + I915_WRITE(dp_priv->output_reg, DP); + POSTING_READ(dp_priv->output_reg); + udelay(100); + } + +- DP &= ~DP_LINK_TRAIN_MASK; +- I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE); +- POSTING_READ(dp_priv->output_reg); ++ if (HAS_PCH_CPT(dev) && !IS_eDP(intel_encoder)) { ++ DP &= ~DP_LINK_TRAIN_MASK_CPT; ++ I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE_CPT); ++ POSTING_READ(dp_priv->output_reg); ++ } else { ++ DP &= ~DP_LINK_TRAIN_MASK; ++ I915_WRITE(dp_priv->output_reg, DP | DP_LINK_TRAIN_PAT_IDLE); ++ POSTING_READ(dp_priv->output_reg); ++ } + + udelay(17000); + +- if (IS_eDP(intel_output)) ++ if (IS_eDP(intel_encoder)) + DP |= DP_LINK_TRAIN_OFF; + I915_WRITE(dp_priv->output_reg, DP & ~DP_PORT_EN); + POSTING_READ(dp_priv->output_reg); + } + +-static void +-intel_dp_restore(struct drm_connector *connector) +-{ +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; +- +- if (dp_priv->save_DP & DP_PORT_EN) +- intel_dp_link_train(intel_output, dp_priv->save_DP, dp_priv->save_link_configuration); +- else +- intel_dp_link_down(intel_output, dp_priv->save_DP); +-} +- + /* + * According to DP spec + * 5.1.2: +@@ -1123,32 +1174,33 @@ intel_dp_restore(struct drm_connector *connector) + */ + + static void +-intel_dp_check_link_status(struct intel_output *intel_output) ++intel_dp_check_link_status(struct intel_encoder *intel_encoder) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + uint8_t link_status[DP_LINK_STATUS_SIZE]; + +- if (!intel_output->enc.crtc) ++ if (!intel_encoder->enc.crtc) + return; + +- if (!intel_dp_get_link_status(intel_output, link_status)) { +- intel_dp_link_down(intel_output, dp_priv->DP); ++ if (!intel_dp_get_link_status(intel_encoder, link_status)) { ++ intel_dp_link_down(intel_encoder, dp_priv->DP); + return; + } + + if (!intel_channel_eq_ok(link_status, dp_priv->lane_count)) +- intel_dp_link_train(intel_output, dp_priv->DP, dp_priv->link_configuration); ++ intel_dp_link_train(intel_encoder, dp_priv->DP, dp_priv->link_configuration); + } + + static enum drm_connector_status + ironlake_dp_detect(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + enum drm_connector_status status; + + status = connector_status_disconnected; +- if (intel_dp_aux_native_read(intel_output, ++ if (intel_dp_aux_native_read(intel_encoder, + 0x000, dp_priv->dpcd, + sizeof (dp_priv->dpcd)) == sizeof (dp_priv->dpcd)) + { +@@ -1167,28 +1219,19 @@ ironlake_dp_detect(struct drm_connector *connector) + static enum drm_connector_status + intel_dp_detect(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + uint32_t temp, bit; + enum drm_connector_status status; + + dp_priv->has_audio = false; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return ironlake_dp_detect(connector); + +- temp = I915_READ(PORT_HOTPLUG_EN); +- +- I915_WRITE(PORT_HOTPLUG_EN, +- temp | +- DPB_HOTPLUG_INT_EN | +- DPC_HOTPLUG_INT_EN | +- DPD_HOTPLUG_INT_EN); +- +- POSTING_READ(PORT_HOTPLUG_EN); +- + switch (dp_priv->output_reg) { + case DP_B: + bit = DPB_HOTPLUG_INT_STATUS; +@@ -1209,7 +1252,7 @@ intel_dp_detect(struct drm_connector *connector) + return connector_status_disconnected; + + status = connector_status_disconnected; +- if (intel_dp_aux_native_read(intel_output, ++ if (intel_dp_aux_native_read(intel_encoder, + 0x000, dp_priv->dpcd, + sizeof (dp_priv->dpcd)) == sizeof (dp_priv->dpcd)) + { +@@ -1221,20 +1264,21 @@ intel_dp_detect(struct drm_connector *connector) + + static int intel_dp_get_modes(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; + int ret; + + /* We should parse the EDID data and find out if it has an audio sink + */ + +- ret = intel_ddc_get_modes(intel_output); ++ ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + if (ret) + return ret; + + /* if eDP has no EDID, try to use fixed panel mode from VBT */ +- if (IS_eDP(intel_output)) { ++ if (IS_eDP(intel_encoder)) { + if (dev_priv->panel_fixed_mode != NULL) { + struct drm_display_mode *mode; + mode = drm_mode_duplicate(dev, dev_priv->panel_fixed_mode); +@@ -1248,13 +1292,9 @@ static int intel_dp_get_modes(struct drm_connector *connector) + static void + intel_dp_destroy (struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- +- if (intel_output->i2c_bus) +- intel_i2c_destroy(intel_output->i2c_bus); + drm_sysfs_connector_remove(connector); + drm_connector_cleanup(connector); +- kfree(intel_output); ++ kfree(connector); + } + + static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { +@@ -1267,8 +1307,6 @@ static const struct drm_encoder_helper_funcs intel_dp_helper_funcs = { + + static const struct drm_connector_funcs intel_dp_connector_funcs = { + .dpms = drm_helper_connector_dpms, +- .save = intel_dp_save, +- .restore = intel_dp_restore, + .detect = intel_dp_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = intel_dp_destroy, +@@ -1277,12 +1315,17 @@ static const struct drm_connector_funcs intel_dp_connector_funcs = { + static const struct drm_connector_helper_funcs intel_dp_connector_helper_funcs = { + .get_modes = intel_dp_get_modes, + .mode_valid = intel_dp_mode_valid, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static void intel_dp_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ ++ if (intel_encoder->i2c_bus) ++ intel_i2c_destroy(intel_encoder->i2c_bus); + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_dp_enc_funcs = { +@@ -1290,12 +1333,34 @@ static const struct drm_encoder_funcs intel_dp_enc_funcs = { + }; + + void +-intel_dp_hot_plug(struct intel_output *intel_output) ++intel_dp_hot_plug(struct intel_encoder *intel_encoder) + { +- struct intel_dp_priv *dp_priv = intel_output->dev_priv; ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; + + if (dp_priv->dpms_mode == DRM_MODE_DPMS_ON) +- intel_dp_check_link_status(intel_output); ++ intel_dp_check_link_status(intel_encoder); ++} ++ ++/* Return which DP Port should be selected for Transcoder DP control */ ++int ++intel_trans_dp_port_sel (struct drm_crtc *crtc) ++{ ++ struct drm_device *dev = crtc->dev; ++ struct drm_mode_config *mode_config = &dev->mode_config; ++ struct drm_encoder *encoder; ++ struct intel_encoder *intel_encoder = NULL; ++ ++ list_for_each_entry(encoder, &mode_config->encoder_list, head) { ++ if (!encoder || encoder->crtc != crtc) ++ continue; ++ ++ intel_encoder = enc_to_intel_encoder(encoder); ++ if (intel_encoder->type == INTEL_OUTPUT_DISPLAYPORT) { ++ struct intel_dp_priv *dp_priv = intel_encoder->dev_priv; ++ return dp_priv->output_reg; ++ } ++ } ++ return -1; + } + + void +@@ -1303,53 +1368,60 @@ intel_dp_init(struct drm_device *dev, int output_reg) + { + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_connector *connector; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; ++ struct intel_connector *intel_connector; + struct intel_dp_priv *dp_priv; + const char *name = NULL; + +- intel_output = kcalloc(sizeof(struct intel_output) + ++ intel_encoder = kcalloc(sizeof(struct intel_encoder) + + sizeof(struct intel_dp_priv), 1, GFP_KERNEL); +- if (!intel_output) ++ if (!intel_encoder) + return; + +- dp_priv = (struct intel_dp_priv *)(intel_output + 1); ++ intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); ++ if (!intel_connector) { ++ kfree(intel_encoder); ++ return; ++ } ++ ++ dp_priv = (struct intel_dp_priv *)(intel_encoder + 1); + +- connector = &intel_output->base; ++ connector = &intel_connector->base; + drm_connector_init(dev, connector, &intel_dp_connector_funcs, + DRM_MODE_CONNECTOR_DisplayPort); + drm_connector_helper_add(connector, &intel_dp_connector_helper_funcs); + + if (output_reg == DP_A) +- intel_output->type = INTEL_OUTPUT_EDP; ++ intel_encoder->type = INTEL_OUTPUT_EDP; + else +- intel_output->type = INTEL_OUTPUT_DISPLAYPORT; ++ intel_encoder->type = INTEL_OUTPUT_DISPLAYPORT; + + if (output_reg == DP_B || output_reg == PCH_DP_B) +- intel_output->clone_mask = (1 << INTEL_DP_B_CLONE_BIT); ++ intel_encoder->clone_mask = (1 << INTEL_DP_B_CLONE_BIT); + else if (output_reg == DP_C || output_reg == PCH_DP_C) +- intel_output->clone_mask = (1 << INTEL_DP_C_CLONE_BIT); ++ intel_encoder->clone_mask = (1 << INTEL_DP_C_CLONE_BIT); + else if (output_reg == DP_D || output_reg == PCH_DP_D) +- intel_output->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); ++ intel_encoder->clone_mask = (1 << INTEL_DP_D_CLONE_BIT); + +- if (IS_eDP(intel_output)) +- intel_output->clone_mask = (1 << INTEL_EDP_CLONE_BIT); ++ if (IS_eDP(intel_encoder)) ++ intel_encoder->clone_mask = (1 << INTEL_EDP_CLONE_BIT); + +- intel_output->crtc_mask = (1 << 0) | (1 << 1); ++ intel_encoder->crtc_mask = (1 << 0) | (1 << 1); + connector->interlace_allowed = true; + connector->doublescan_allowed = 0; + +- dp_priv->intel_output = intel_output; ++ dp_priv->intel_encoder = intel_encoder; + dp_priv->output_reg = output_reg; + dp_priv->has_audio = false; + dp_priv->dpms_mode = DRM_MODE_DPMS_ON; +- intel_output->dev_priv = dp_priv; ++ intel_encoder->dev_priv = dp_priv; + +- drm_encoder_init(dev, &intel_output->enc, &intel_dp_enc_funcs, ++ drm_encoder_init(dev, &intel_encoder->enc, &intel_dp_enc_funcs, + DRM_MODE_ENCODER_TMDS); +- drm_encoder_helper_add(&intel_output->enc, &intel_dp_helper_funcs); ++ drm_encoder_helper_add(&intel_encoder->enc, &intel_dp_helper_funcs); + +- drm_mode_connector_attach_encoder(&intel_output->base, +- &intel_output->enc); ++ drm_mode_connector_attach_encoder(&intel_connector->base, ++ &intel_encoder->enc); + drm_sysfs_connector_add(connector); + + /* Set up the DDC bus. */ +@@ -1377,10 +1449,10 @@ intel_dp_init(struct drm_device *dev, int output_reg) + break; + } + +- intel_dp_i2c_init(intel_output, name); ++ intel_dp_i2c_init(intel_encoder, intel_connector, name); + +- intel_output->ddc_bus = &dp_priv->adapter; +- intel_output->hot_plug = intel_dp_hot_plug; ++ intel_encoder->ddc_bus = &dp_priv->adapter; ++ intel_encoder->hot_plug = intel_dp_hot_plug; + + if (output_reg == DP_A) { + /* initialize panel mode from VBT if available for eDP */ +diff --git a/drivers/gpu/drm/i915/intel_drv.h b/drivers/gpu/drm/i915/intel_drv.h +--- a/drivers/gpu/drm/i915/intel_drv.h ++++ b/drivers/gpu/drm/i915/intel_drv.h +@@ -95,9 +95,7 @@ struct intel_framebuffer { + }; + + +-struct intel_output { +- struct drm_connector base; +- ++struct intel_encoder { + struct drm_encoder enc; + int type; + struct i2c_adapter *i2c_bus; +@@ -105,11 +103,16 @@ struct intel_output { + bool load_detect_temp; + bool needs_tv_clock; + void *dev_priv; +- void (*hot_plug)(struct intel_output *); ++ void (*hot_plug)(struct intel_encoder *); + int crtc_mask; + int clone_mask; + }; + ++struct intel_connector { ++ struct drm_connector base; ++ void *dev_priv; ++}; ++ + struct intel_crtc; + struct intel_overlay { + struct drm_device *dev; +@@ -149,18 +152,19 @@ struct intel_crtc { + bool lowfreq_avail; + struct intel_overlay *overlay; + struct intel_unpin_work *unpin_work; ++ int fdi_lanes; + }; + + #define to_intel_crtc(x) container_of(x, struct intel_crtc, base) +-#define to_intel_output(x) container_of(x, struct intel_output, base) +-#define enc_to_intel_output(x) container_of(x, struct intel_output, enc) ++#define to_intel_connector(x) container_of(x, struct intel_connector, base) ++#define enc_to_intel_encoder(x) container_of(x, struct intel_encoder, enc) + #define to_intel_framebuffer(x) container_of(x, struct intel_framebuffer, base) + + struct i2c_adapter *intel_i2c_create(struct drm_device *dev, const u32 reg, + const char *name); + void intel_i2c_destroy(struct i2c_adapter *adapter); +-int intel_ddc_get_modes(struct intel_output *intel_output); +-extern bool intel_ddc_probe(struct intel_output *intel_output); ++int intel_ddc_get_modes(struct drm_connector *c, struct i2c_adapter *adapter); ++extern bool intel_ddc_probe(struct intel_encoder *intel_encoder); + void intel_i2c_quirk_set(struct drm_device *dev, bool enable); + void intel_i2c_reset_gmbus(struct drm_device *dev); + +@@ -175,7 +179,7 @@ extern void intel_dp_init(struct drm_device *dev, int dp_reg); + void + intel_dp_set_m_n(struct drm_crtc *crtc, struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode); +-extern void intel_edp_link_config (struct intel_output *, int *, int *); ++extern void intel_edp_link_config (struct intel_encoder *, int *, int *); + + + extern int intel_panel_fitter_pipe (struct drm_device *dev); +@@ -183,7 +187,7 @@ extern void intel_crtc_load_lut(struct drm_crtc *crtc); + extern void intel_encoder_prepare (struct drm_encoder *encoder); + extern void intel_encoder_commit (struct drm_encoder *encoder); + +-extern struct drm_encoder *intel_best_encoder(struct drm_connector *connector); ++extern struct drm_encoder *intel_attached_encoder(struct drm_connector *connector); + + extern struct drm_display_mode *intel_crtc_mode_get(struct drm_device *dev, + struct drm_crtc *crtc); +@@ -191,10 +195,12 @@ int intel_get_pipe_from_crtc_id(struct drm_device *dev, void *data, + struct drm_file *file_priv); + extern void intel_wait_for_vblank(struct drm_device *dev); + extern struct drm_crtc *intel_get_crtc_from_pipe(struct drm_device *dev, int pipe); +-extern struct drm_crtc *intel_get_load_detect_pipe(struct intel_output *intel_output, ++extern struct drm_crtc *intel_get_load_detect_pipe(struct intel_encoder *intel_encoder, ++ struct drm_connector *connector, + struct drm_display_mode *mode, + int *dpms_mode); +-extern void intel_release_load_detect_pipe(struct intel_output *intel_output, ++extern void intel_release_load_detect_pipe(struct intel_encoder *intel_encoder, ++ struct drm_connector *connector, + int dpms_mode); + + extern struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB); +@@ -209,6 +215,8 @@ extern void intel_crtc_fb_gamma_set(struct drm_crtc *crtc, u16 red, u16 green, + extern void intel_crtc_fb_gamma_get(struct drm_crtc *crtc, u16 *red, u16 *green, + u16 *blue, int regno); + extern void intel_init_clock_gating(struct drm_device *dev); ++extern void ironlake_enable_drps(struct drm_device *dev); ++extern void ironlake_disable_drps(struct drm_device *dev); + + extern int intel_framebuffer_create(struct drm_device *dev, + struct drm_mode_fb_cmd *mode_cmd, +diff --git a/drivers/gpu/drm/i915/intel_dvo.c b/drivers/gpu/drm/i915/intel_dvo.c +--- a/drivers/gpu/drm/i915/intel_dvo.c ++++ b/drivers/gpu/drm/i915/intel_dvo.c +@@ -79,8 +79,8 @@ static struct intel_dvo_device intel_dvo_devices[] = { + static void intel_dvo_dpms(struct drm_encoder *encoder, int mode) + { + struct drm_i915_private *dev_priv = encoder->dev->dev_private; +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + u32 dvo_reg = dvo->dvo_reg; + u32 temp = I915_READ(dvo_reg); + +@@ -95,40 +95,12 @@ static void intel_dvo_dpms(struct drm_encoder *encoder, int mode) + } + } + +-static void intel_dvo_save(struct drm_connector *connector) +-{ +- struct drm_i915_private *dev_priv = connector->dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; +- +- /* Each output should probably just save the registers it touches, +- * but for now, use more overkill. +- */ +- dev_priv->saveDVOA = I915_READ(DVOA); +- dev_priv->saveDVOB = I915_READ(DVOB); +- dev_priv->saveDVOC = I915_READ(DVOC); +- +- dvo->dev_ops->save(dvo); +-} +- +-static void intel_dvo_restore(struct drm_connector *connector) +-{ +- struct drm_i915_private *dev_priv = connector->dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; +- +- dvo->dev_ops->restore(dvo); +- +- I915_WRITE(DVOA, dev_priv->saveDVOA); +- I915_WRITE(DVOB, dev_priv->saveDVOB); +- I915_WRITE(DVOC, dev_priv->saveDVOC); +-} +- + static int intel_dvo_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + + if (mode->flags & DRM_MODE_FLAG_DBLSCAN) + return MODE_NO_DBLESCAN; +@@ -149,8 +121,8 @@ static bool intel_dvo_mode_fixup(struct drm_encoder *encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) + { +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + + /* If we have timings from the BIOS for the panel, put them in + * to the adjusted mode. The CRTC will be set up for this mode, +@@ -185,8 +157,8 @@ static void intel_dvo_mode_set(struct drm_encoder *encoder, + struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + int pipe = intel_crtc->pipe; + u32 dvo_val; + u32 dvo_reg = dvo->dvo_reg, dvo_srcdim_reg; +@@ -240,23 +212,25 @@ static void intel_dvo_mode_set(struct drm_encoder *encoder, + */ + static enum drm_connector_status intel_dvo_detect(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + + return dvo->dev_ops->detect(dvo); + } + + static int intel_dvo_get_modes(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + + /* We should probably have an i2c driver get_modes function for those + * devices which will have a fixed set of modes determined by the chip + * (TV-out, for example), but for now with just TMDS and LVDS, + * that's not the case. + */ +- intel_ddc_get_modes(intel_output); ++ intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + if (!list_empty(&connector->probed_modes)) + return 1; + +@@ -274,39 +248,11 @@ static int intel_dvo_get_modes(struct drm_connector *connector) + + static void intel_dvo_destroy (struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; +- +- if (dvo) { +- if (dvo->dev_ops->destroy) +- dvo->dev_ops->destroy(dvo); +- if (dvo->panel_fixed_mode) +- kfree(dvo->panel_fixed_mode); +- /* no need, in i830_dvoices[] now */ +- //kfree(dvo); +- } +- if (intel_output->i2c_bus) +- intel_i2c_destroy(intel_output->i2c_bus); +- if (intel_output->ddc_bus) +- intel_i2c_destroy(intel_output->ddc_bus); + drm_sysfs_connector_remove(connector); + drm_connector_cleanup(connector); +- kfree(intel_output); ++ kfree(connector); + } + +-#ifdef RANDR_GET_CRTC_INTERFACE +-static struct drm_crtc *intel_dvo_get_crtc(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; +- int pipe = !!(I915_READ(dvo->dvo_reg) & SDVO_PIPE_B_SELECT); +- +- return intel_pipe_to_crtc(pScrn, pipe); +-} +-#endif +- + static const struct drm_encoder_helper_funcs intel_dvo_helper_funcs = { + .dpms = intel_dvo_dpms, + .mode_fixup = intel_dvo_mode_fixup, +@@ -317,8 +263,6 @@ static const struct drm_encoder_helper_funcs intel_dvo_helper_funcs = { + + static const struct drm_connector_funcs intel_dvo_connector_funcs = { + .dpms = drm_helper_connector_dpms, +- .save = intel_dvo_save, +- .restore = intel_dvo_restore, + .detect = intel_dvo_detect, + .destroy = intel_dvo_destroy, + .fill_modes = drm_helper_probe_single_connector_modes, +@@ -327,12 +271,26 @@ static const struct drm_connector_funcs intel_dvo_connector_funcs = { + static const struct drm_connector_helper_funcs intel_dvo_connector_helper_funcs = { + .mode_valid = intel_dvo_mode_valid, + .get_modes = intel_dvo_get_modes, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static void intel_dvo_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; ++ ++ if (dvo) { ++ if (dvo->dev_ops->destroy) ++ dvo->dev_ops->destroy(dvo); ++ if (dvo->panel_fixed_mode) ++ kfree(dvo->panel_fixed_mode); ++ } ++ if (intel_encoder->i2c_bus) ++ intel_i2c_destroy(intel_encoder->i2c_bus); ++ if (intel_encoder->ddc_bus) ++ intel_i2c_destroy(intel_encoder->ddc_bus); + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_dvo_enc_funcs = { +@@ -351,8 +309,9 @@ intel_dvo_get_current_mode (struct drm_connector *connector) + { + struct drm_device *dev = connector->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_dvo_device *dvo = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_dvo_device *dvo = intel_encoder->dev_priv; + uint32_t dvo_reg = dvo->dvo_reg; + uint32_t dvo_val = I915_READ(dvo_reg); + struct drm_display_mode *mode = NULL; +@@ -382,24 +341,31 @@ intel_dvo_get_current_mode (struct drm_connector *connector) + + void intel_dvo_init(struct drm_device *dev) + { +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; ++ struct intel_connector *intel_connector; + struct intel_dvo_device *dvo; + struct i2c_adapter *i2cbus = NULL; + int ret = 0; + int i; + int encoder_type = DRM_MODE_ENCODER_NONE; +- intel_output = kzalloc (sizeof(struct intel_output), GFP_KERNEL); +- if (!intel_output) ++ intel_encoder = kzalloc (sizeof(struct intel_encoder), GFP_KERNEL); ++ if (!intel_encoder) ++ return; ++ ++ intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); ++ if (!intel_connector) { ++ kfree(intel_encoder); + return; ++ } + + /* Set up the DDC bus */ +- intel_output->ddc_bus = intel_i2c_create(dev, GPIOD, "DVODDC_D"); +- if (!intel_output->ddc_bus) ++ intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOD, "DVODDC_D"); ++ if (!intel_encoder->ddc_bus) + goto free_intel; + + /* Now, try to find a controller */ + for (i = 0; i < ARRAY_SIZE(intel_dvo_devices); i++) { +- struct drm_connector *connector = &intel_output->base; ++ struct drm_connector *connector = &intel_connector->base; + int gpio; + + dvo = &intel_dvo_devices[i]; +@@ -434,11 +400,11 @@ void intel_dvo_init(struct drm_device *dev) + if (!ret) + continue; + +- intel_output->type = INTEL_OUTPUT_DVO; +- intel_output->crtc_mask = (1 << 0) | (1 << 1); ++ intel_encoder->type = INTEL_OUTPUT_DVO; ++ intel_encoder->crtc_mask = (1 << 0) | (1 << 1); + switch (dvo->type) { + case INTEL_DVO_CHIP_TMDS: +- intel_output->clone_mask = ++ intel_encoder->clone_mask = + (1 << INTEL_DVO_TMDS_CLONE_BIT) | + (1 << INTEL_ANALOG_CLONE_BIT); + drm_connector_init(dev, connector, +@@ -447,7 +413,7 @@ void intel_dvo_init(struct drm_device *dev) + encoder_type = DRM_MODE_ENCODER_TMDS; + break; + case INTEL_DVO_CHIP_LVDS: +- intel_output->clone_mask = ++ intel_encoder->clone_mask = + (1 << INTEL_DVO_LVDS_CLONE_BIT); + drm_connector_init(dev, connector, + &intel_dvo_connector_funcs, +@@ -462,16 +428,16 @@ void intel_dvo_init(struct drm_device *dev) + connector->interlace_allowed = false; + connector->doublescan_allowed = false; + +- intel_output->dev_priv = dvo; +- intel_output->i2c_bus = i2cbus; ++ intel_encoder->dev_priv = dvo; ++ intel_encoder->i2c_bus = i2cbus; + +- drm_encoder_init(dev, &intel_output->enc, ++ drm_encoder_init(dev, &intel_encoder->enc, + &intel_dvo_enc_funcs, encoder_type); +- drm_encoder_helper_add(&intel_output->enc, ++ drm_encoder_helper_add(&intel_encoder->enc, + &intel_dvo_helper_funcs); + +- drm_mode_connector_attach_encoder(&intel_output->base, +- &intel_output->enc); ++ drm_mode_connector_attach_encoder(&intel_connector->base, ++ &intel_encoder->enc); + if (dvo->type == INTEL_DVO_CHIP_LVDS) { + /* For our LVDS chipsets, we should hopefully be able + * to dig the fixed panel mode out of the BIOS data. +@@ -489,10 +455,11 @@ void intel_dvo_init(struct drm_device *dev) + return; + } + +- intel_i2c_destroy(intel_output->ddc_bus); ++ intel_i2c_destroy(intel_encoder->ddc_bus); + /* Didn't find a chip, so tear down. */ + if (i2cbus != NULL) + intel_i2c_destroy(i2cbus); + free_intel: +- kfree(intel_output); ++ kfree(intel_encoder); ++ kfree(intel_connector); + } +diff --git a/drivers/gpu/drm/i915/intel_fb.c b/drivers/gpu/drm/i915/intel_fb.c +--- a/drivers/gpu/drm/i915/intel_fb.c ++++ b/drivers/gpu/drm/i915/intel_fb.c +@@ -144,7 +144,7 @@ static int intelfb_create(struct drm_device *dev, uint32_t fb_width, + ret = -ENOMEM; + goto out; + } +- obj_priv = fbo->driver_private; ++ obj_priv = to_intel_bo(fbo); + + mutex_lock(&dev->struct_mutex); + +diff --git a/drivers/gpu/drm/i915/intel_hdmi.c b/drivers/gpu/drm/i915/intel_hdmi.c +--- a/drivers/gpu/drm/i915/intel_hdmi.c ++++ b/drivers/gpu/drm/i915/intel_hdmi.c +@@ -38,7 +38,6 @@ + + struct intel_hdmi_priv { + u32 sdvox_reg; +- u32 save_SDVOX; + bool has_hdmi_sink; + }; + +@@ -50,8 +49,8 @@ static void intel_hdmi_mode_set(struct drm_encoder *encoder, + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_crtc *crtc = encoder->crtc; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_hdmi_priv *hdmi_priv = intel_encoder->dev_priv; + u32 sdvox; + + sdvox = SDVO_ENCODING_HDMI | +@@ -62,8 +61,12 @@ static void intel_hdmi_mode_set(struct drm_encoder *encoder, + if (hdmi_priv->has_hdmi_sink) + sdvox |= SDVO_AUDIO_ENABLE; + +- if (intel_crtc->pipe == 1) +- sdvox |= SDVO_PIPE_B_SELECT; ++ if (intel_crtc->pipe == 1) { ++ if (HAS_PCH_CPT(dev)) ++ sdvox |= PORT_TRANS_B_SEL_CPT; ++ else ++ sdvox |= SDVO_PIPE_B_SELECT; ++ } + + I915_WRITE(hdmi_priv->sdvox_reg, sdvox); + POSTING_READ(hdmi_priv->sdvox_reg); +@@ -73,8 +76,8 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) + { + struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_hdmi_priv *hdmi_priv = intel_encoder->dev_priv; + u32 temp; + + temp = I915_READ(hdmi_priv->sdvox_reg); +@@ -82,7 +85,7 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) + /* HW workaround, need to toggle enable bit off and on for 12bpc, but + * we do this anyway which shows more stable in testing. + */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + I915_WRITE(hdmi_priv->sdvox_reg, temp & ~SDVO_ENABLE); + POSTING_READ(hdmi_priv->sdvox_reg); + } +@@ -99,33 +102,12 @@ static void intel_hdmi_dpms(struct drm_encoder *encoder, int mode) + /* HW workaround, need to write this twice for issue that may result + * in first write getting masked. + */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + I915_WRITE(hdmi_priv->sdvox_reg, temp); + POSTING_READ(hdmi_priv->sdvox_reg); + } + } + +-static void intel_hdmi_save(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; +- +- hdmi_priv->save_SDVOX = I915_READ(hdmi_priv->sdvox_reg); +-} +- +-static void intel_hdmi_restore(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; +- +- I915_WRITE(hdmi_priv->sdvox_reg, hdmi_priv->save_SDVOX); +- POSTING_READ(hdmi_priv->sdvox_reg); +-} +- + static int intel_hdmi_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { +@@ -150,21 +132,22 @@ static bool intel_hdmi_mode_fixup(struct drm_encoder *encoder, + static enum drm_connector_status + intel_hdmi_detect(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_hdmi_priv *hdmi_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_hdmi_priv *hdmi_priv = intel_encoder->dev_priv; + struct edid *edid = NULL; + enum drm_connector_status status = connector_status_disconnected; + + hdmi_priv->has_hdmi_sink = false; +- edid = drm_get_edid(&intel_output->base, +- intel_output->ddc_bus); ++ edid = drm_get_edid(connector, ++ intel_encoder->ddc_bus); + + if (edid) { + if (edid->input & DRM_EDID_INPUT_DIGITAL) { + status = connector_status_connected; + hdmi_priv->has_hdmi_sink = drm_detect_hdmi_monitor(edid); + } +- intel_output->base.display_info.raw_edid = NULL; ++ connector->display_info.raw_edid = NULL; + kfree(edid); + } + +@@ -173,24 +156,21 @@ intel_hdmi_detect(struct drm_connector *connector) + + static int intel_hdmi_get_modes(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + + /* We should parse the EDID data and find out if it's an HDMI sink so + * we can send audio to it. + */ + +- return intel_ddc_get_modes(intel_output); ++ return intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + } + + static void intel_hdmi_destroy(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- +- if (intel_output->i2c_bus) +- intel_i2c_destroy(intel_output->i2c_bus); + drm_sysfs_connector_remove(connector); + drm_connector_cleanup(connector); +- kfree(intel_output); ++ kfree(connector); + } + + static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { +@@ -203,8 +183,6 @@ static const struct drm_encoder_helper_funcs intel_hdmi_helper_funcs = { + + static const struct drm_connector_funcs intel_hdmi_connector_funcs = { + .dpms = drm_helper_connector_dpms, +- .save = intel_hdmi_save, +- .restore = intel_hdmi_restore, + .detect = intel_hdmi_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .destroy = intel_hdmi_destroy, +@@ -213,12 +191,17 @@ static const struct drm_connector_funcs intel_hdmi_connector_funcs = { + static const struct drm_connector_helper_funcs intel_hdmi_connector_helper_funcs = { + .get_modes = intel_hdmi_get_modes, + .mode_valid = intel_hdmi_mode_valid, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static void intel_hdmi_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ ++ if (intel_encoder->i2c_bus) ++ intel_i2c_destroy(intel_encoder->i2c_bus); + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_hdmi_enc_funcs = { +@@ -229,63 +212,71 @@ void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) + { + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_connector *connector; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; ++ struct intel_connector *intel_connector; + struct intel_hdmi_priv *hdmi_priv; + +- intel_output = kcalloc(sizeof(struct intel_output) + ++ intel_encoder = kcalloc(sizeof(struct intel_encoder) + + sizeof(struct intel_hdmi_priv), 1, GFP_KERNEL); +- if (!intel_output) ++ if (!intel_encoder) + return; +- hdmi_priv = (struct intel_hdmi_priv *)(intel_output + 1); + +- connector = &intel_output->base; ++ intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); ++ if (!intel_connector) { ++ kfree(intel_encoder); ++ return; ++ } ++ ++ hdmi_priv = (struct intel_hdmi_priv *)(intel_encoder + 1); ++ ++ connector = &intel_connector->base; + drm_connector_init(dev, connector, &intel_hdmi_connector_funcs, + DRM_MODE_CONNECTOR_HDMIA); + drm_connector_helper_add(connector, &intel_hdmi_connector_helper_funcs); + +- intel_output->type = INTEL_OUTPUT_HDMI; ++ intel_encoder->type = INTEL_OUTPUT_HDMI; + + connector->interlace_allowed = 0; + connector->doublescan_allowed = 0; +- intel_output->crtc_mask = (1 << 0) | (1 << 1); ++ intel_encoder->crtc_mask = (1 << 0) | (1 << 1); + + /* Set up the DDC bus. */ + if (sdvox_reg == SDVOB) { +- intel_output->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); +- intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "HDMIB"); ++ intel_encoder->clone_mask = (1 << INTEL_HDMIB_CLONE_BIT); ++ intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOE, "HDMIB"); + dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; + } else if (sdvox_reg == SDVOC) { +- intel_output->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); +- intel_output->ddc_bus = intel_i2c_create(dev, GPIOD, "HDMIC"); ++ intel_encoder->clone_mask = (1 << INTEL_HDMIC_CLONE_BIT); ++ intel_encoder->ddc_bus = intel_i2c_create(dev, GPIOD, "HDMIC"); + dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; + } else if (sdvox_reg == HDMIB) { +- intel_output->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); +- intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOE, ++ intel_encoder->clone_mask = (1 << INTEL_HDMID_CLONE_BIT); ++ intel_encoder->ddc_bus = intel_i2c_create(dev, PCH_GPIOE, + "HDMIB"); + dev_priv->hotplug_supported_mask |= HDMIB_HOTPLUG_INT_STATUS; + } else if (sdvox_reg == HDMIC) { +- intel_output->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); +- intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOD, ++ intel_encoder->clone_mask = (1 << INTEL_HDMIE_CLONE_BIT); ++ intel_encoder->ddc_bus = intel_i2c_create(dev, PCH_GPIOD, + "HDMIC"); + dev_priv->hotplug_supported_mask |= HDMIC_HOTPLUG_INT_STATUS; + } else if (sdvox_reg == HDMID) { +- intel_output->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); +- intel_output->ddc_bus = intel_i2c_create(dev, PCH_GPIOF, ++ intel_encoder->clone_mask = (1 << INTEL_HDMIF_CLONE_BIT); ++ intel_encoder->ddc_bus = intel_i2c_create(dev, PCH_GPIOF, + "HDMID"); + dev_priv->hotplug_supported_mask |= HDMID_HOTPLUG_INT_STATUS; + } +- if (!intel_output->ddc_bus) ++ if (!intel_encoder->ddc_bus) + goto err_connector; + + hdmi_priv->sdvox_reg = sdvox_reg; +- intel_output->dev_priv = hdmi_priv; ++ intel_encoder->dev_priv = hdmi_priv; + +- drm_encoder_init(dev, &intel_output->enc, &intel_hdmi_enc_funcs, ++ drm_encoder_init(dev, &intel_encoder->enc, &intel_hdmi_enc_funcs, + DRM_MODE_ENCODER_TMDS); +- drm_encoder_helper_add(&intel_output->enc, &intel_hdmi_helper_funcs); ++ drm_encoder_helper_add(&intel_encoder->enc, &intel_hdmi_helper_funcs); + +- drm_mode_connector_attach_encoder(&intel_output->base, +- &intel_output->enc); ++ drm_mode_connector_attach_encoder(&intel_connector->base, ++ &intel_encoder->enc); + drm_sysfs_connector_add(connector); + + /* For G4X desktop chip, PEG_BAND_GAP_DATA 3:0 must first be written +@@ -301,7 +292,8 @@ void intel_hdmi_init(struct drm_device *dev, int sdvox_reg) + + err_connector: + drm_connector_cleanup(connector); +- kfree(intel_output); ++ kfree(intel_encoder); ++ kfree(intel_connector); + + return; + } +diff --git a/drivers/gpu/drm/i915/intel_i2c.c b/drivers/gpu/drm/i915/intel_i2c.c +--- a/drivers/gpu/drm/i915/intel_i2c.c ++++ b/drivers/gpu/drm/i915/intel_i2c.c +@@ -128,7 +128,7 @@ intel_i2c_reset_gmbus(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + I915_WRITE(PCH_GMBUS0, 0); + } else { + I915_WRITE(GMBUS0, 0); +diff --git a/drivers/gpu/drm/i915/intel_lvds.c b/drivers/gpu/drm/i915/intel_lvds.c +--- a/drivers/gpu/drm/i915/intel_lvds.c ++++ b/drivers/gpu/drm/i915/intel_lvds.c +@@ -56,7 +56,7 @@ static void intel_lvds_set_backlight(struct drm_device *dev, int level) + struct drm_i915_private *dev_priv = dev->dev_private; + u32 blc_pwm_ctl, reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + reg = BLC_PWM_CPU_CTL; + else + reg = BLC_PWM_CTL; +@@ -74,7 +74,7 @@ static u32 intel_lvds_get_max_backlight(struct drm_device *dev) + struct drm_i915_private *dev_priv = dev->dev_private; + u32 reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + reg = BLC_PWM_PCH_CTL2; + else + reg = BLC_PWM_CTL; +@@ -89,17 +89,22 @@ static u32 intel_lvds_get_max_backlight(struct drm_device *dev) + static void intel_lvds_set_power(struct drm_device *dev, bool on) + { + struct drm_i915_private *dev_priv = dev->dev_private; +- u32 pp_status, ctl_reg, status_reg; ++ u32 pp_status, ctl_reg, status_reg, lvds_reg; + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + ctl_reg = PCH_PP_CONTROL; + status_reg = PCH_PP_STATUS; ++ lvds_reg = PCH_LVDS; + } else { + ctl_reg = PP_CONTROL; + status_reg = PP_STATUS; ++ lvds_reg = LVDS; + } + + if (on) { ++ I915_WRITE(lvds_reg, I915_READ(lvds_reg) | LVDS_PORT_EN); ++ POSTING_READ(lvds_reg); ++ + I915_WRITE(ctl_reg, I915_READ(ctl_reg) | + POWER_TARGET_ON); + do { +@@ -115,6 +120,9 @@ static void intel_lvds_set_power(struct drm_device *dev, bool on) + do { + pp_status = I915_READ(status_reg); + } while (pp_status & PP_ON); ++ ++ I915_WRITE(lvds_reg, I915_READ(lvds_reg) & ~LVDS_PORT_EN); ++ POSTING_READ(lvds_reg); + } + } + +@@ -130,75 +138,6 @@ static void intel_lvds_dpms(struct drm_encoder *encoder, int mode) + /* XXX: We never power down the LVDS pairs. */ + } + +-static void intel_lvds_save(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg; +- u32 pwm_ctl_reg; +- +- if (IS_IRONLAKE(dev)) { +- pp_on_reg = PCH_PP_ON_DELAYS; +- pp_off_reg = PCH_PP_OFF_DELAYS; +- pp_ctl_reg = PCH_PP_CONTROL; +- pp_div_reg = PCH_PP_DIVISOR; +- pwm_ctl_reg = BLC_PWM_CPU_CTL; +- } else { +- pp_on_reg = PP_ON_DELAYS; +- pp_off_reg = PP_OFF_DELAYS; +- pp_ctl_reg = PP_CONTROL; +- pp_div_reg = PP_DIVISOR; +- pwm_ctl_reg = BLC_PWM_CTL; +- } +- +- dev_priv->savePP_ON = I915_READ(pp_on_reg); +- dev_priv->savePP_OFF = I915_READ(pp_off_reg); +- dev_priv->savePP_CONTROL = I915_READ(pp_ctl_reg); +- dev_priv->savePP_DIVISOR = I915_READ(pp_div_reg); +- dev_priv->saveBLC_PWM_CTL = I915_READ(pwm_ctl_reg); +- dev_priv->backlight_duty_cycle = (dev_priv->saveBLC_PWM_CTL & +- BACKLIGHT_DUTY_CYCLE_MASK); +- +- /* +- * If the light is off at server startup, just make it full brightness +- */ +- if (dev_priv->backlight_duty_cycle == 0) +- dev_priv->backlight_duty_cycle = +- intel_lvds_get_max_backlight(dev); +-} +- +-static void intel_lvds_restore(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- u32 pp_on_reg, pp_off_reg, pp_ctl_reg, pp_div_reg; +- u32 pwm_ctl_reg; +- +- if (IS_IRONLAKE(dev)) { +- pp_on_reg = PCH_PP_ON_DELAYS; +- pp_off_reg = PCH_PP_OFF_DELAYS; +- pp_ctl_reg = PCH_PP_CONTROL; +- pp_div_reg = PCH_PP_DIVISOR; +- pwm_ctl_reg = BLC_PWM_CPU_CTL; +- } else { +- pp_on_reg = PP_ON_DELAYS; +- pp_off_reg = PP_OFF_DELAYS; +- pp_ctl_reg = PP_CONTROL; +- pp_div_reg = PP_DIVISOR; +- pwm_ctl_reg = BLC_PWM_CTL; +- } +- +- I915_WRITE(pwm_ctl_reg, dev_priv->saveBLC_PWM_CTL); +- I915_WRITE(pp_on_reg, dev_priv->savePP_ON); +- I915_WRITE(pp_off_reg, dev_priv->savePP_OFF); +- I915_WRITE(pp_div_reg, dev_priv->savePP_DIVISOR); +- I915_WRITE(pp_ctl_reg, dev_priv->savePP_CONTROL); +- if (dev_priv->savePP_CONTROL & POWER_TARGET_ON) +- intel_lvds_set_power(dev, true); +- else +- intel_lvds_set_power(dev, false); +-} +- + static int intel_lvds_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { +@@ -230,8 +169,8 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder, + struct drm_i915_private *dev_priv = dev->dev_private; + struct intel_crtc *intel_crtc = to_intel_crtc(encoder->crtc); + struct drm_encoder *tmp_encoder; +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_lvds_priv *lvds_priv = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_lvds_priv *lvds_priv = intel_encoder->dev_priv; + u32 pfit_control = 0, pfit_pgm_ratios = 0; + int left_border = 0, right_border = 0, top_border = 0; + int bottom_border = 0; +@@ -297,7 +236,7 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder, + } + + /* full screen scale for now */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + goto out; + + /* 965+ wants fuzzy fitting */ +@@ -327,7 +266,7 @@ static bool intel_lvds_mode_fixup(struct drm_encoder *encoder, + * to register description and PRM. + * Change the value here to see the borders for debugging + */ +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + I915_WRITE(BCLRPAT_A, 0); + I915_WRITE(BCLRPAT_B, 0); + } +@@ -548,7 +487,7 @@ static void intel_lvds_prepare(struct drm_encoder *encoder) + struct drm_i915_private *dev_priv = dev->dev_private; + u32 reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + reg = BLC_PWM_CPU_CTL; + else + reg = BLC_PWM_CTL; +@@ -578,8 +517,8 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder, + { + struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_lvds_priv *lvds_priv = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_lvds_priv *lvds_priv = intel_encoder->dev_priv; + + /* + * The LVDS pin pair will already have been turned on in the +@@ -587,7 +526,7 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder, + * settings. + */ + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return; + + /* +@@ -599,53 +538,6 @@ static void intel_lvds_mode_set(struct drm_encoder *encoder, + I915_WRITE(PFIT_CONTROL, lvds_priv->pfit_control); + } + +-/* Some lid devices report incorrect lid status, assume they're connected */ +-static const struct dmi_system_id bad_lid_status[] = { +- { +- .ident = "Compaq nx9020", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "Hewlett-Packard"), +- DMI_MATCH(DMI_BOARD_NAME, "3084"), +- }, +- }, +- { +- .ident = "Samsung SX20S", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "Samsung Electronics"), +- DMI_MATCH(DMI_BOARD_NAME, "SX20S"), +- }, +- }, +- { +- .ident = "Aspire One", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "Acer"), +- DMI_MATCH(DMI_PRODUCT_NAME, "Aspire one"), +- }, +- }, +- { +- .ident = "Aspire 1810T", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "Acer"), +- DMI_MATCH(DMI_PRODUCT_NAME, "Aspire 1810T"), +- }, +- }, +- { +- .ident = "PC-81005", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "MALATA"), +- DMI_MATCH(DMI_PRODUCT_NAME, "PC-81005"), +- }, +- }, +- { +- .ident = "Clevo M5x0N", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "CLEVO Co."), +- DMI_MATCH(DMI_BOARD_NAME, "M5x0N"), +- }, +- }, +- { } +-}; +- + /** + * Detect the LVDS connection. + * +@@ -661,12 +553,9 @@ static enum drm_connector_status intel_lvds_detect(struct drm_connector *connect + /* ACPI lid methods were generally unreliable in this generation, so + * don't even bother. + */ +- if (IS_I8XX(dev)) ++ if (IS_GEN2(dev) || IS_GEN3(dev)) + return connector_status_connected; + +- if (!dmi_check_system(bad_lid_status) && !acpi_lid_open()) +- status = connector_status_disconnected; +- + return status; + } + +@@ -676,14 +565,17 @@ static enum drm_connector_status intel_lvds_detect(struct drm_connector *connect + static int intel_lvds_get_modes(struct drm_connector *connector) + { + struct drm_device *dev = connector->dev; +- struct intel_output *intel_output = to_intel_output(connector); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + struct drm_i915_private *dev_priv = dev->dev_private; + int ret = 0; + +- ret = intel_ddc_get_modes(intel_output); ++ if (dev_priv->lvds_edid_good) { ++ ret = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + +- if (ret) +- return ret; ++ if (ret) ++ return ret; ++ } + + /* Didn't get an EDID, so + * Set wide sync ranges so we get all modes +@@ -756,11 +648,8 @@ static int intel_lid_notify(struct notifier_block *nb, unsigned long val, + static void intel_lvds_destroy(struct drm_connector *connector) + { + struct drm_device *dev = connector->dev; +- struct intel_output *intel_output = to_intel_output(connector); + struct drm_i915_private *dev_priv = dev->dev_private; + +- if (intel_output->ddc_bus) +- intel_i2c_destroy(intel_output->ddc_bus); + if (dev_priv->lid_notifier.notifier_call) + acpi_lid_notifier_unregister(&dev_priv->lid_notifier); + drm_sysfs_connector_remove(connector); +@@ -773,13 +662,14 @@ static int intel_lvds_set_property(struct drm_connector *connector, + uint64_t value) + { + struct drm_device *dev = connector->dev; +- struct intel_output *intel_output = +- to_intel_output(connector); + + if (property == dev->mode_config.scaling_mode_property && + connector->encoder) { + struct drm_crtc *crtc = connector->encoder->crtc; +- struct intel_lvds_priv *lvds_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = connector->encoder; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_lvds_priv *lvds_priv = intel_encoder->dev_priv; ++ + if (value == DRM_MODE_SCALE_NONE) { + DRM_DEBUG_KMS("no scaling not supported\n"); + return 0; +@@ -813,13 +703,11 @@ static const struct drm_encoder_helper_funcs intel_lvds_helper_funcs = { + static const struct drm_connector_helper_funcs intel_lvds_connector_helper_funcs = { + .get_modes = intel_lvds_get_modes, + .mode_valid = intel_lvds_mode_valid, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static const struct drm_connector_funcs intel_lvds_connector_funcs = { + .dpms = drm_helper_connector_dpms, +- .save = intel_lvds_save, +- .restore = intel_lvds_restore, + .detect = intel_lvds_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .set_property = intel_lvds_set_property, +@@ -829,7 +717,12 @@ static const struct drm_connector_funcs intel_lvds_connector_funcs = { + + static void intel_lvds_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ ++ if (intel_encoder->ddc_bus) ++ intel_i2c_destroy(intel_encoder->ddc_bus); + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_lvds_enc_funcs = { +@@ -899,6 +792,14 @@ static const struct dmi_system_id intel_no_lvds[] = { + DMI_MATCH(DMI_PRODUCT_VERSION, "AO00001JW"), + }, + }, ++ { ++ .callback = intel_no_lvds_dmi_callback, ++ .ident = "Clientron U800", ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "Clientron"), ++ DMI_MATCH(DMI_PRODUCT_NAME, "U800"), ++ }, ++ }, + + { } /* terminating entry */ + }; +@@ -1009,7 +910,8 @@ static int lvds_is_present_in_vbt(struct drm_device *dev) + void intel_lvds_init(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; ++ struct intel_connector *intel_connector; + struct drm_connector *connector; + struct drm_encoder *encoder; + struct drm_display_mode *scan; /* *modes, *bios_mode; */ +@@ -1027,7 +929,7 @@ void intel_lvds_init(struct drm_device *dev) + return; + } + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + if ((I915_READ(PCH_LVDS) & LVDS_DETECTED) == 0) + return; + if (dev_priv->edp_support) { +@@ -1037,40 +939,48 @@ void intel_lvds_init(struct drm_device *dev) + gpio = PCH_GPIOC; + } + +- intel_output = kzalloc(sizeof(struct intel_output) + ++ intel_encoder = kzalloc(sizeof(struct intel_encoder) + + sizeof(struct intel_lvds_priv), GFP_KERNEL); +- if (!intel_output) { ++ if (!intel_encoder) { ++ return; ++ } ++ ++ intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); ++ if (!intel_connector) { ++ kfree(intel_encoder); + return; + } + +- connector = &intel_output->base; +- encoder = &intel_output->enc; +- drm_connector_init(dev, &intel_output->base, &intel_lvds_connector_funcs, ++ connector = &intel_connector->base; ++ encoder = &intel_encoder->enc; ++ drm_connector_init(dev, &intel_connector->base, &intel_lvds_connector_funcs, + DRM_MODE_CONNECTOR_LVDS); + +- drm_encoder_init(dev, &intel_output->enc, &intel_lvds_enc_funcs, ++ drm_encoder_init(dev, &intel_encoder->enc, &intel_lvds_enc_funcs, + DRM_MODE_ENCODER_LVDS); + +- drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc); +- intel_output->type = INTEL_OUTPUT_LVDS; ++ drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc); ++ intel_encoder->type = INTEL_OUTPUT_LVDS; + +- intel_output->clone_mask = (1 << INTEL_LVDS_CLONE_BIT); +- intel_output->crtc_mask = (1 << 1); ++ intel_encoder->clone_mask = (1 << INTEL_LVDS_CLONE_BIT); ++ intel_encoder->crtc_mask = (1 << 1); ++ if (IS_I965G(dev)) ++ intel_encoder->crtc_mask |= (1 << 0); + drm_encoder_helper_add(encoder, &intel_lvds_helper_funcs); + drm_connector_helper_add(connector, &intel_lvds_connector_helper_funcs); + connector->display_info.subpixel_order = SubPixelHorizontalRGB; + connector->interlace_allowed = false; + connector->doublescan_allowed = false; + +- lvds_priv = (struct intel_lvds_priv *)(intel_output + 1); +- intel_output->dev_priv = lvds_priv; ++ lvds_priv = (struct intel_lvds_priv *)(intel_encoder + 1); ++ intel_encoder->dev_priv = lvds_priv; + /* create the scaling mode property */ + drm_mode_create_scaling_mode_property(dev); + /* + * the initial panel fitting mode will be FULL_SCREEN. + */ + +- drm_connector_attach_property(&intel_output->base, ++ drm_connector_attach_property(&intel_connector->base, + dev->mode_config.scaling_mode_property, + DRM_MODE_SCALE_FULLSCREEN); + lvds_priv->fitting_mode = DRM_MODE_SCALE_FULLSCREEN; +@@ -1085,8 +995,8 @@ void intel_lvds_init(struct drm_device *dev) + */ + + /* Set up the DDC bus. */ +- intel_output->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C"); +- if (!intel_output->ddc_bus) { ++ intel_encoder->ddc_bus = intel_i2c_create(dev, gpio, "LVDSDDC_C"); ++ if (!intel_encoder->ddc_bus) { + dev_printk(KERN_ERR, &dev->pdev->dev, "DDC bus registration " + "failed.\n"); + goto failed; +@@ -1096,7 +1006,10 @@ void intel_lvds_init(struct drm_device *dev) + * Attempt to get the fixed panel mode from DDC. Assume that the + * preferred mode is the right one. + */ +- intel_ddc_get_modes(intel_output); ++ dev_priv->lvds_edid_good = true; ++ ++ if (!intel_ddc_get_modes(connector, intel_encoder->ddc_bus)) ++ dev_priv->lvds_edid_good = false; + + list_for_each_entry(scan, &connector->probed_modes, head) { + mutex_lock(&dev->mode_config.mutex); +@@ -1130,7 +1043,7 @@ void intel_lvds_init(struct drm_device *dev) + */ + + /* Ironlake: FIXME if still fail, not try pipe mode now */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + goto failed; + + lvds = I915_READ(LVDS); +@@ -1151,7 +1064,7 @@ void intel_lvds_init(struct drm_device *dev) + goto failed; + + out: +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + u32 pwm; + /* make sure PWM is enabled */ + pwm = I915_READ(BLC_PWM_CPU_CTL2); +@@ -1174,9 +1087,10 @@ out: + + failed: + DRM_DEBUG_KMS("No LVDS modes found, disabling.\n"); +- if (intel_output->ddc_bus) +- intel_i2c_destroy(intel_output->ddc_bus); ++ if (intel_encoder->ddc_bus) ++ intel_i2c_destroy(intel_encoder->ddc_bus); + drm_connector_cleanup(connector); + drm_encoder_cleanup(encoder); +- kfree(intel_output); ++ kfree(intel_encoder); ++ kfree(intel_connector); + } +diff --git a/drivers/gpu/drm/i915/intel_modes.c b/drivers/gpu/drm/i915/intel_modes.c +--- a/drivers/gpu/drm/i915/intel_modes.c ++++ b/drivers/gpu/drm/i915/intel_modes.c +@@ -33,7 +33,7 @@ + * intel_ddc_probe + * + */ +-bool intel_ddc_probe(struct intel_output *intel_output) ++bool intel_ddc_probe(struct intel_encoder *intel_encoder) + { + u8 out_buf[] = { 0x0, 0x0}; + u8 buf[2]; +@@ -53,9 +53,9 @@ bool intel_ddc_probe(struct intel_output *intel_output) + } + }; + +- intel_i2c_quirk_set(intel_output->base.dev, true); +- ret = i2c_transfer(intel_output->ddc_bus, msgs, 2); +- intel_i2c_quirk_set(intel_output->base.dev, false); ++ intel_i2c_quirk_set(intel_encoder->enc.dev, true); ++ ret = i2c_transfer(intel_encoder->ddc_bus, msgs, 2); ++ intel_i2c_quirk_set(intel_encoder->enc.dev, false); + if (ret == 2) + return true; + +@@ -65,22 +65,23 @@ bool intel_ddc_probe(struct intel_output *intel_output) + /** + * intel_ddc_get_modes - get modelist from monitor + * @connector: DRM connector device to use ++ * @adapter: i2c adapter + * + * Fetch the EDID information from @connector using the DDC bus. + */ +-int intel_ddc_get_modes(struct intel_output *intel_output) ++int intel_ddc_get_modes(struct drm_connector *connector, ++ struct i2c_adapter *adapter) + { + struct edid *edid; + int ret = 0; + +- intel_i2c_quirk_set(intel_output->base.dev, true); +- edid = drm_get_edid(&intel_output->base, intel_output->ddc_bus); +- intel_i2c_quirk_set(intel_output->base.dev, false); ++ intel_i2c_quirk_set(connector->dev, true); ++ edid = drm_get_edid(connector, adapter); ++ intel_i2c_quirk_set(connector->dev, false); + if (edid) { +- drm_mode_connector_update_edid_property(&intel_output->base, +- edid); +- ret = drm_add_edid_modes(&intel_output->base, edid); +- intel_output->base.display_info.raw_edid = NULL; ++ drm_mode_connector_update_edid_property(connector, edid); ++ ret = drm_add_edid_modes(connector, edid); ++ connector->display_info.raw_edid = NULL; + kfree(edid); + } + +diff --git a/drivers/gpu/drm/i915/intel_overlay.c b/drivers/gpu/drm/i915/intel_overlay.c +--- a/drivers/gpu/drm/i915/intel_overlay.c ++++ b/drivers/gpu/drm/i915/intel_overlay.c +@@ -172,7 +172,7 @@ struct overlay_registers { + #define OFC_UPDATE 0x1 + + #define OVERLAY_NONPHYSICAL(dev) (IS_G33(dev) || IS_I965G(dev)) +-#define OVERLAY_EXISTS(dev) (!IS_G4X(dev) && !IS_IRONLAKE(dev)) ++#define OVERLAY_EXISTS(dev) (!IS_G4X(dev) && !IS_IRONLAKE(dev) && !IS_GEN6(dev)) + + + static struct overlay_registers *intel_overlay_map_regs_atomic(struct intel_overlay *overlay) +@@ -199,16 +199,11 @@ static struct overlay_registers *intel_overlay_map_regs_atomic(struct intel_over + + static void intel_overlay_unmap_regs_atomic(struct intel_overlay *overlay) + { +- struct drm_device *dev = overlay->dev; +- drm_i915_private_t *dev_priv = dev->dev_private; +- + if (OVERLAY_NONPHYSICAL(overlay->dev)) + io_mapping_unmap_atomic(overlay->virt_addr); + + overlay->virt_addr = NULL; + +- I915_READ(OVADD); /* flush wc cashes */ +- + return; + } + +@@ -225,9 +220,7 @@ static int intel_overlay_on(struct intel_overlay *overlay) + overlay->active = 1; + overlay->hw_wedged = NEEDS_WAIT_FOR_FLIP; + +- BEGIN_LP_RING(6); +- OUT_RING(MI_FLUSH); +- OUT_RING(MI_NOOP); ++ BEGIN_LP_RING(4); + OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_ON); + OUT_RING(overlay->flip_addr | OFC_UPDATE); + OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); +@@ -267,9 +260,7 @@ static void intel_overlay_continue(struct intel_overlay *overlay, + if (tmp & (1 << 17)) + DRM_DEBUG("overlay underrun, DOVSTA: %x\n", tmp); + +- BEGIN_LP_RING(4); +- OUT_RING(MI_FLUSH); +- OUT_RING(MI_NOOP); ++ BEGIN_LP_RING(2); + OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); + OUT_RING(flip_addr); + ADVANCE_LP_RING(); +@@ -338,9 +329,7 @@ static int intel_overlay_off(struct intel_overlay *overlay) + /* wait for overlay to go idle */ + overlay->hw_wedged = SWITCH_OFF_STAGE_1; + +- BEGIN_LP_RING(6); +- OUT_RING(MI_FLUSH); +- OUT_RING(MI_NOOP); ++ BEGIN_LP_RING(4); + OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_CONTINUE); + OUT_RING(flip_addr); + OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); +@@ -358,9 +347,7 @@ static int intel_overlay_off(struct intel_overlay *overlay) + /* turn overlay off */ + overlay->hw_wedged = SWITCH_OFF_STAGE_2; + +- BEGIN_LP_RING(6); +- OUT_RING(MI_FLUSH); +- OUT_RING(MI_NOOP); ++ BEGIN_LP_RING(4); + OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_OFF); + OUT_RING(flip_addr); + OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); +@@ -435,9 +422,7 @@ int intel_overlay_recover_from_interrupt(struct intel_overlay *overlay, + + overlay->hw_wedged = SWITCH_OFF_STAGE_2; + +- BEGIN_LP_RING(6); +- OUT_RING(MI_FLUSH); +- OUT_RING(MI_NOOP); ++ BEGIN_LP_RING(4); + OUT_RING(MI_OVERLAY_FLIP | MI_OVERLAY_OFF); + OUT_RING(flip_addr); + OUT_RING(MI_WAIT_FOR_EVENT | MI_WAIT_FOR_OVERLAY_FLIP); +@@ -739,7 +724,7 @@ int intel_overlay_do_put_image(struct intel_overlay *overlay, + int ret, tmp_width; + struct overlay_registers *regs; + bool scale_changed = false; +- struct drm_i915_gem_object *bo_priv = new_bo->driver_private; ++ struct drm_i915_gem_object *bo_priv = to_intel_bo(new_bo); + struct drm_device *dev = overlay->dev; + + BUG_ON(!mutex_is_locked(&dev->struct_mutex)); +@@ -824,7 +809,7 @@ int intel_overlay_do_put_image(struct intel_overlay *overlay, + intel_overlay_continue(overlay, scale_changed); + + overlay->old_vid_bo = overlay->vid_bo; +- overlay->vid_bo = new_bo->driver_private; ++ overlay->vid_bo = to_intel_bo(new_bo); + + return 0; + +@@ -1183,8 +1168,8 @@ int intel_overlay_put_image(struct drm_device *dev, void *data, + out_unlock: + mutex_unlock(&dev->struct_mutex); + mutex_unlock(&dev->mode_config.mutex); +-out_free: + drm_gem_object_unreference_unlocked(new_bo); ++out_free: + kfree(params); + + return ret; +@@ -1359,7 +1344,7 @@ void intel_setup_overlay(struct drm_device *dev) + reg_bo = drm_gem_object_alloc(dev, PAGE_SIZE); + if (!reg_bo) + goto out_free; +- overlay->reg_bo = reg_bo->driver_private; ++ overlay->reg_bo = to_intel_bo(reg_bo); + + if (OVERLAY_NONPHYSICAL(dev)) { + ret = i915_gem_object_pin(reg_bo, PAGE_SIZE); +diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c +--- a/drivers/gpu/drm/i915/intel_sdvo.c ++++ b/drivers/gpu/drm/i915/intel_sdvo.c +@@ -35,7 +35,18 @@ + #include "i915_drm.h" + #include "i915_drv.h" + #include "intel_sdvo_regs.h" +-#include ++ ++#define SDVO_TMDS_MASK (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1) ++#define SDVO_RGB_MASK (SDVO_OUTPUT_RGB0 | SDVO_OUTPUT_RGB1) ++#define SDVO_LVDS_MASK (SDVO_OUTPUT_LVDS0 | SDVO_OUTPUT_LVDS1) ++#define SDVO_TV_MASK (SDVO_OUTPUT_CVBS0 | SDVO_OUTPUT_SVID0) ++ ++#define SDVO_OUTPUT_MASK (SDVO_TMDS_MASK | SDVO_RGB_MASK | SDVO_LVDS_MASK |\ ++ SDVO_TV_MASK) ++ ++#define IS_TV(c) (c->output_flag & SDVO_TV_MASK) ++#define IS_LVDS(c) (c->output_flag & SDVO_LVDS_MASK) ++ + + static char *tv_format_names[] = { + "NTSC_M" , "NTSC_J" , "NTSC_443", +@@ -53,7 +64,7 @@ struct intel_sdvo_priv { + u8 slave_addr; + + /* Register for the SDVO device: SDVOB or SDVOC */ +- int output_device; ++ int sdvo_reg; + + /* Active outputs controlled by this SDVO output */ + uint16_t controlled_output; +@@ -85,12 +96,6 @@ struct intel_sdvo_priv { + /* This is for current tv format name */ + char *tv_format_name; + +- /* This contains all current supported TV format */ +- char *tv_format_supported[TV_FORMAT_NUM]; +- int format_supported_num; +- struct drm_property *tv_format_property; +- struct drm_property *tv_format_name_property[TV_FORMAT_NUM]; +- + /** + * This is set if we treat the device as HDMI, instead of DVI. + */ +@@ -111,29 +116,36 @@ struct intel_sdvo_priv { + */ + struct drm_display_mode *sdvo_lvds_fixed_mode; + +- /** +- * Returned SDTV resolutions allowed for the current format, if the +- * device reported it. +- */ +- struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions; +- + /* + * supported encoding mode, used to determine whether HDMI is + * supported + */ + struct intel_sdvo_encode encode; + +- /* DDC bus used by this SDVO output */ ++ /* DDC bus used by this SDVO encoder */ + uint8_t ddc_bus; + + /* Mac mini hack -- use the same DDC as the analog connector */ + struct i2c_adapter *analog_ddc_bus; + +- int save_sdvo_mult; +- u16 save_active_outputs; +- struct intel_sdvo_dtd save_input_dtd_1, save_input_dtd_2; +- struct intel_sdvo_dtd save_output_dtd[16]; +- u32 save_SDVOX; ++}; ++ ++struct intel_sdvo_connector { ++ /* Mark the type of connector */ ++ uint16_t output_flag; ++ ++ /* This contains all current supported TV format */ ++ char *tv_format_supported[TV_FORMAT_NUM]; ++ int format_supported_num; ++ struct drm_property *tv_format_property; ++ struct drm_property *tv_format_name_property[TV_FORMAT_NUM]; ++ ++ /** ++ * Returned SDTV resolutions allowed for the current format, if the ++ * device reported it. ++ */ ++ struct intel_sdvo_sdtv_resolution_reply sdtv_resolutions; ++ + /* add the property for the SDVO-TV */ + struct drm_property *left_property; + struct drm_property *right_property; +@@ -161,22 +173,33 @@ struct intel_sdvo_priv { + }; + + static bool +-intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags); ++intel_sdvo_output_setup(struct intel_encoder *intel_encoder, ++ uint16_t flags); ++static void ++intel_sdvo_tv_create_property(struct drm_connector *connector, int type); ++static void ++intel_sdvo_create_enhance_property(struct drm_connector *connector); + + /** + * Writes the SDVOB or SDVOC with the given value, but always writes both + * SDVOB and SDVOC to work around apparent hardware issues (according to + * comments in the BIOS). + */ +-static void intel_sdvo_write_sdvox(struct intel_output *intel_output, u32 val) ++static void intel_sdvo_write_sdvox(struct intel_encoder *intel_encoder, u32 val) + { +- struct drm_device *dev = intel_output->base.dev; ++ struct drm_device *dev = intel_encoder->enc.dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + u32 bval = val, cval = val; + int i; + +- if (sdvo_priv->output_device == SDVOB) { ++ if (sdvo_priv->sdvo_reg == PCH_SDVOB) { ++ I915_WRITE(sdvo_priv->sdvo_reg, val); ++ I915_READ(sdvo_priv->sdvo_reg); ++ return; ++ } ++ ++ if (sdvo_priv->sdvo_reg == SDVOB) { + cval = I915_READ(SDVOC); + } else { + bval = I915_READ(SDVOB); +@@ -195,10 +218,10 @@ static void intel_sdvo_write_sdvox(struct intel_output *intel_output, u32 val) + } + } + +-static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr, ++static bool intel_sdvo_read_byte(struct intel_encoder *intel_encoder, u8 addr, + u8 *ch) + { +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + u8 out_buf[2]; + u8 buf[2]; + int ret; +@@ -221,7 +244,7 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr, + out_buf[0] = addr; + out_buf[1] = 0; + +- if ((ret = i2c_transfer(intel_output->i2c_bus, msgs, 2)) == 2) ++ if ((ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 2)) == 2) + { + *ch = buf[0]; + return true; +@@ -231,10 +254,10 @@ static bool intel_sdvo_read_byte(struct intel_output *intel_output, u8 addr, + return false; + } + +-static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr, ++static bool intel_sdvo_write_byte(struct intel_encoder *intel_encoder, int addr, + u8 ch) + { +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + u8 out_buf[2]; + struct i2c_msg msgs[] = { + { +@@ -248,7 +271,7 @@ static bool intel_sdvo_write_byte(struct intel_output *intel_output, int addr, + out_buf[0] = addr; + out_buf[1] = ch; + +- if (i2c_transfer(intel_output->i2c_bus, msgs, 1) == 1) ++ if (i2c_transfer(intel_encoder->i2c_bus, msgs, 1) == 1) + { + return true; + } +@@ -352,13 +375,14 @@ static const struct _sdvo_cmd_name { + SDVO_CMD_NAME_ENTRY(SDVO_CMD_GET_HBUF_DATA), + }; + +-#define SDVO_NAME(dev_priv) ((dev_priv)->output_device == SDVOB ? "SDVOB" : "SDVOC") +-#define SDVO_PRIV(output) ((struct intel_sdvo_priv *) (output)->dev_priv) ++#define IS_SDVOB(reg) (reg == SDVOB || reg == PCH_SDVOB) ++#define SDVO_NAME(dev_priv) (IS_SDVOB((dev_priv)->sdvo_reg) ? "SDVOB" : "SDVOC") ++#define SDVO_PRIV(encoder) ((struct intel_sdvo_priv *) (encoder)->dev_priv) + +-static void intel_sdvo_debug_write(struct intel_output *intel_output, u8 cmd, ++static void intel_sdvo_debug_write(struct intel_encoder *intel_encoder, u8 cmd, + void *args, int args_len) + { +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + int i; + + DRM_DEBUG_KMS("%s: W: %02X ", +@@ -378,19 +402,19 @@ static void intel_sdvo_debug_write(struct intel_output *intel_output, u8 cmd, + DRM_LOG_KMS("\n"); + } + +-static void intel_sdvo_write_cmd(struct intel_output *intel_output, u8 cmd, ++static void intel_sdvo_write_cmd(struct intel_encoder *intel_encoder, u8 cmd, + void *args, int args_len) + { + int i; + +- intel_sdvo_debug_write(intel_output, cmd, args, args_len); ++ intel_sdvo_debug_write(intel_encoder, cmd, args, args_len); + + for (i = 0; i < args_len; i++) { +- intel_sdvo_write_byte(intel_output, SDVO_I2C_ARG_0 - i, ++ intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0 - i, + ((u8*)args)[i]); + } + +- intel_sdvo_write_byte(intel_output, SDVO_I2C_OPCODE, cmd); ++ intel_sdvo_write_byte(intel_encoder, SDVO_I2C_OPCODE, cmd); + } + + static const char *cmd_status_names[] = { +@@ -403,11 +427,11 @@ static const char *cmd_status_names[] = { + "Scaling not supported" + }; + +-static void intel_sdvo_debug_response(struct intel_output *intel_output, ++static void intel_sdvo_debug_response(struct intel_encoder *intel_encoder, + void *response, int response_len, + u8 status) + { +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + int i; + + DRM_DEBUG_KMS("%s: R: ", SDVO_NAME(sdvo_priv)); +@@ -422,7 +446,7 @@ static void intel_sdvo_debug_response(struct intel_output *intel_output, + DRM_LOG_KMS("\n"); + } + +-static u8 intel_sdvo_read_response(struct intel_output *intel_output, ++static u8 intel_sdvo_read_response(struct intel_encoder *intel_encoder, + void *response, int response_len) + { + int i; +@@ -432,16 +456,16 @@ static u8 intel_sdvo_read_response(struct intel_output *intel_output, + while (retry--) { + /* Read the command response */ + for (i = 0; i < response_len; i++) { +- intel_sdvo_read_byte(intel_output, ++ intel_sdvo_read_byte(intel_encoder, + SDVO_I2C_RETURN_0 + i, + &((u8 *)response)[i]); + } + + /* read the return status */ +- intel_sdvo_read_byte(intel_output, SDVO_I2C_CMD_STATUS, ++ intel_sdvo_read_byte(intel_encoder, SDVO_I2C_CMD_STATUS, + &status); + +- intel_sdvo_debug_response(intel_output, response, response_len, ++ intel_sdvo_debug_response(intel_encoder, response, response_len, + status); + if (status != SDVO_CMD_STATUS_PENDING) + return status; +@@ -469,10 +493,10 @@ static int intel_sdvo_get_pixel_multiplier(struct drm_display_mode *mode) + * another I2C transaction after issuing the DDC bus switch, it will be + * switched to the internal SDVO register. + */ +-static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output, ++static void intel_sdvo_set_control_bus_switch(struct intel_encoder *intel_encoder, + u8 target) + { +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + u8 out_buf[2], cmd_buf[2], ret_value[2], ret; + struct i2c_msg msgs[] = { + { +@@ -496,10 +520,10 @@ static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output, + }, + }; + +- intel_sdvo_debug_write(intel_output, SDVO_CMD_SET_CONTROL_BUS_SWITCH, ++ intel_sdvo_debug_write(intel_encoder, SDVO_CMD_SET_CONTROL_BUS_SWITCH, + &target, 1); + /* write the DDC switch command argument */ +- intel_sdvo_write_byte(intel_output, SDVO_I2C_ARG_0, target); ++ intel_sdvo_write_byte(intel_encoder, SDVO_I2C_ARG_0, target); + + out_buf[0] = SDVO_I2C_OPCODE; + out_buf[1] = SDVO_CMD_SET_CONTROL_BUS_SWITCH; +@@ -508,7 +532,7 @@ static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output, + ret_value[0] = 0; + ret_value[1] = 0; + +- ret = i2c_transfer(intel_output->i2c_bus, msgs, 3); ++ ret = i2c_transfer(intel_encoder->i2c_bus, msgs, 3); + if (ret != 3) { + /* failure in I2C transfer */ + DRM_DEBUG_KMS("I2c transfer returned %d\n", ret); +@@ -522,7 +546,7 @@ static void intel_sdvo_set_control_bus_switch(struct intel_output *intel_output, + return; + } + +-static bool intel_sdvo_set_target_input(struct intel_output *intel_output, bool target_0, bool target_1) ++static bool intel_sdvo_set_target_input(struct intel_encoder *intel_encoder, bool target_0, bool target_1) + { + struct intel_sdvo_set_target_input_args targets = {0}; + u8 status; +@@ -533,10 +557,10 @@ static bool intel_sdvo_set_target_input(struct intel_output *intel_output, bool + if (target_1) + targets.target_1 = 1; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_INPUT, &targets, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_INPUT, &targets, + sizeof(targets)); + +- status = intel_sdvo_read_response(intel_output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + + return (status == SDVO_CMD_STATUS_SUCCESS); + } +@@ -547,13 +571,13 @@ static bool intel_sdvo_set_target_input(struct intel_output *intel_output, bool + * This function is making an assumption about the layout of the response, + * which should be checked against the docs. + */ +-static bool intel_sdvo_get_trained_inputs(struct intel_output *intel_output, bool *input_1, bool *input_2) ++static bool intel_sdvo_get_trained_inputs(struct intel_encoder *intel_encoder, bool *input_1, bool *input_2) + { + struct intel_sdvo_get_trained_inputs_response response; + u8 status; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0); +- status = intel_sdvo_read_response(intel_output, &response, sizeof(response)); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_TRAINED_INPUTS, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, &response, sizeof(response)); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + +@@ -562,29 +586,18 @@ static bool intel_sdvo_get_trained_inputs(struct intel_output *intel_output, boo + return true; + } + +-static bool intel_sdvo_get_active_outputs(struct intel_output *intel_output, +- u16 *outputs) +-{ +- u8 status; +- +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_OUTPUTS, NULL, 0); +- status = intel_sdvo_read_response(intel_output, outputs, sizeof(*outputs)); +- +- return (status == SDVO_CMD_STATUS_SUCCESS); +-} +- +-static bool intel_sdvo_set_active_outputs(struct intel_output *intel_output, ++static bool intel_sdvo_set_active_outputs(struct intel_encoder *intel_encoder, + u16 outputs) + { + u8 status; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_OUTPUTS, &outputs, + sizeof(outputs)); +- status = intel_sdvo_read_response(intel_output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + return (status == SDVO_CMD_STATUS_SUCCESS); + } + +-static bool intel_sdvo_set_encoder_power_state(struct intel_output *intel_output, ++static bool intel_sdvo_set_encoder_power_state(struct intel_encoder *intel_encoder, + int mode) + { + u8 status, state = SDVO_ENCODER_STATE_ON; +@@ -604,24 +617,24 @@ static bool intel_sdvo_set_encoder_power_state(struct intel_output *intel_output + break; + } + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ENCODER_POWER_STATE, &state, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODER_POWER_STATE, &state, + sizeof(state)); +- status = intel_sdvo_read_response(intel_output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + + return (status == SDVO_CMD_STATUS_SUCCESS); + } + +-static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output *intel_output, ++static bool intel_sdvo_get_input_pixel_clock_range(struct intel_encoder *intel_encoder, + int *clock_min, + int *clock_max) + { + struct intel_sdvo_pixel_clock_range clocks; + u8 status; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_INPUT_PIXEL_CLOCK_RANGE, + NULL, 0); + +- status = intel_sdvo_read_response(intel_output, &clocks, sizeof(clocks)); ++ status = intel_sdvo_read_response(intel_encoder, &clocks, sizeof(clocks)); + + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; +@@ -633,92 +646,58 @@ static bool intel_sdvo_get_input_pixel_clock_range(struct intel_output *intel_ou + return true; + } + +-static bool intel_sdvo_set_target_output(struct intel_output *intel_output, ++static bool intel_sdvo_set_target_output(struct intel_encoder *intel_encoder, + u16 outputs) + { + u8 status; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_TARGET_OUTPUT, &outputs, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TARGET_OUTPUT, &outputs, + sizeof(outputs)); + +- status = intel_sdvo_read_response(intel_output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + return (status == SDVO_CMD_STATUS_SUCCESS); + } + +-static bool intel_sdvo_get_timing(struct intel_output *intel_output, u8 cmd, ++static bool intel_sdvo_set_timing(struct intel_encoder *intel_encoder, u8 cmd, + struct intel_sdvo_dtd *dtd) + { + u8 status; + +- intel_sdvo_write_cmd(intel_output, cmd, NULL, 0); +- status = intel_sdvo_read_response(intel_output, &dtd->part1, +- sizeof(dtd->part1)); ++ intel_sdvo_write_cmd(intel_encoder, cmd, &dtd->part1, sizeof(dtd->part1)); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + +- intel_sdvo_write_cmd(intel_output, cmd + 1, NULL, 0); +- status = intel_sdvo_read_response(intel_output, &dtd->part2, +- sizeof(dtd->part2)); ++ intel_sdvo_write_cmd(intel_encoder, cmd + 1, &dtd->part2, sizeof(dtd->part2)); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + + return true; + } + +-static bool intel_sdvo_get_input_timing(struct intel_output *intel_output, ++static bool intel_sdvo_set_input_timing(struct intel_encoder *intel_encoder, + struct intel_sdvo_dtd *dtd) + { +- return intel_sdvo_get_timing(intel_output, +- SDVO_CMD_GET_INPUT_TIMINGS_PART1, dtd); +-} +- +-static bool intel_sdvo_get_output_timing(struct intel_output *intel_output, +- struct intel_sdvo_dtd *dtd) +-{ +- return intel_sdvo_get_timing(intel_output, +- SDVO_CMD_GET_OUTPUT_TIMINGS_PART1, dtd); +-} +- +-static bool intel_sdvo_set_timing(struct intel_output *intel_output, u8 cmd, +- struct intel_sdvo_dtd *dtd) +-{ +- u8 status; +- +- intel_sdvo_write_cmd(intel_output, cmd, &dtd->part1, sizeof(dtd->part1)); +- status = intel_sdvo_read_response(intel_output, NULL, 0); +- if (status != SDVO_CMD_STATUS_SUCCESS) +- return false; +- +- intel_sdvo_write_cmd(intel_output, cmd + 1, &dtd->part2, sizeof(dtd->part2)); +- status = intel_sdvo_read_response(intel_output, NULL, 0); +- if (status != SDVO_CMD_STATUS_SUCCESS) +- return false; +- +- return true; +-} +- +-static bool intel_sdvo_set_input_timing(struct intel_output *intel_output, +- struct intel_sdvo_dtd *dtd) +-{ +- return intel_sdvo_set_timing(intel_output, ++ return intel_sdvo_set_timing(intel_encoder, + SDVO_CMD_SET_INPUT_TIMINGS_PART1, dtd); + } + +-static bool intel_sdvo_set_output_timing(struct intel_output *intel_output, ++static bool intel_sdvo_set_output_timing(struct intel_encoder *intel_encoder, + struct intel_sdvo_dtd *dtd) + { +- return intel_sdvo_set_timing(intel_output, ++ return intel_sdvo_set_timing(intel_encoder, + SDVO_CMD_SET_OUTPUT_TIMINGS_PART1, dtd); + } + + static bool +-intel_sdvo_create_preferred_input_timing(struct intel_output *output, ++intel_sdvo_create_preferred_input_timing(struct intel_encoder *intel_encoder, + uint16_t clock, + uint16_t width, + uint16_t height) + { + struct intel_sdvo_preferred_input_timing_args args; +- struct intel_sdvo_priv *sdvo_priv = output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + uint8_t status; + + memset(&args, 0, sizeof(args)); +@@ -732,32 +711,33 @@ intel_sdvo_create_preferred_input_timing(struct intel_output *output, + sdvo_priv->sdvo_lvds_fixed_mode->vdisplay != height)) + args.scaled = 1; + +- intel_sdvo_write_cmd(output, SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, ++ intel_sdvo_write_cmd(intel_encoder, ++ SDVO_CMD_CREATE_PREFERRED_INPUT_TIMING, + &args, sizeof(args)); +- status = intel_sdvo_read_response(output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + + return true; + } + +-static bool intel_sdvo_get_preferred_input_timing(struct intel_output *output, ++static bool intel_sdvo_get_preferred_input_timing(struct intel_encoder *intel_encoder, + struct intel_sdvo_dtd *dtd) + { + bool status; + +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART1, + NULL, 0); + +- status = intel_sdvo_read_response(output, &dtd->part1, ++ status = intel_sdvo_read_response(intel_encoder, &dtd->part1, + sizeof(dtd->part1)); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_PREFERRED_INPUT_TIMING_PART2, + NULL, 0); + +- status = intel_sdvo_read_response(output, &dtd->part2, ++ status = intel_sdvo_read_response(intel_encoder, &dtd->part2, + sizeof(dtd->part2)); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; +@@ -765,29 +745,12 @@ static bool intel_sdvo_get_preferred_input_timing(struct intel_output *output, + return false; + } + +-static int intel_sdvo_get_clock_rate_mult(struct intel_output *intel_output) +-{ +- u8 response, status; +- +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_CLOCK_RATE_MULT, NULL, 0); +- status = intel_sdvo_read_response(intel_output, &response, 1); +- +- if (status != SDVO_CMD_STATUS_SUCCESS) { +- DRM_DEBUG_KMS("Couldn't get SDVO clock rate multiplier\n"); +- return SDVO_CLOCK_RATE_MULT_1X; +- } else { +- DRM_DEBUG_KMS("Current clock rate multiplier: %d\n", response); +- } +- +- return response; +-} +- +-static bool intel_sdvo_set_clock_rate_mult(struct intel_output *intel_output, u8 val) ++static bool intel_sdvo_set_clock_rate_mult(struct intel_encoder *intel_encoder, u8 val) + { + u8 status; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1); +- status = intel_sdvo_read_response(intel_output, NULL, 0); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_CLOCK_RATE_MULT, &val, 1); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + +@@ -876,13 +839,13 @@ static void intel_sdvo_get_mode_from_dtd(struct drm_display_mode * mode, + mode->flags |= DRM_MODE_FLAG_PVSYNC; + } + +-static bool intel_sdvo_get_supp_encode(struct intel_output *output, ++static bool intel_sdvo_get_supp_encode(struct intel_encoder *intel_encoder, + struct intel_sdvo_encode *encode) + { + uint8_t status; + +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0); +- status = intel_sdvo_read_response(output, encode, sizeof(*encode)); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPP_ENCODE, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, encode, sizeof(*encode)); + if (status != SDVO_CMD_STATUS_SUCCESS) { /* non-support means DVI */ + memset(encode, 0, sizeof(*encode)); + return false; +@@ -891,29 +854,30 @@ static bool intel_sdvo_get_supp_encode(struct intel_output *output, + return true; + } + +-static bool intel_sdvo_set_encode(struct intel_output *output, uint8_t mode) ++static bool intel_sdvo_set_encode(struct intel_encoder *intel_encoder, ++ uint8_t mode) + { + uint8_t status; + +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_ENCODE, &mode, 1); +- status = intel_sdvo_read_response(output, NULL, 0); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ENCODE, &mode, 1); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + + return (status == SDVO_CMD_STATUS_SUCCESS); + } + +-static bool intel_sdvo_set_colorimetry(struct intel_output *output, ++static bool intel_sdvo_set_colorimetry(struct intel_encoder *intel_encoder, + uint8_t mode) + { + uint8_t status; + +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_COLORIMETRY, &mode, 1); +- status = intel_sdvo_read_response(output, NULL, 0); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_COLORIMETRY, &mode, 1); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + + return (status == SDVO_CMD_STATUS_SUCCESS); + } + + #if 0 +-static void intel_sdvo_dump_hdmi_buf(struct intel_output *output) ++static void intel_sdvo_dump_hdmi_buf(struct intel_encoder *intel_encoder) + { + int i, j; + uint8_t set_buf_index[2]; +@@ -922,43 +886,45 @@ static void intel_sdvo_dump_hdmi_buf(struct intel_output *output) + uint8_t buf[48]; + uint8_t *pos; + +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0); +- intel_sdvo_read_response(output, &av_split, 1); ++ intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_AV_SPLIT, NULL, 0); ++ intel_sdvo_read_response(encoder, &av_split, 1); + + for (i = 0; i <= av_split; i++) { + set_buf_index[0] = i; set_buf_index[1] = 0; +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX, ++ intel_sdvo_write_cmd(encoder, SDVO_CMD_SET_HBUF_INDEX, + set_buf_index, 2); +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_INFO, NULL, 0); +- intel_sdvo_read_response(output, &buf_size, 1); ++ intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_INFO, NULL, 0); ++ intel_sdvo_read_response(encoder, &buf_size, 1); + + pos = buf; + for (j = 0; j <= buf_size; j += 8) { +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_HBUF_DATA, ++ intel_sdvo_write_cmd(encoder, SDVO_CMD_GET_HBUF_DATA, + NULL, 0); +- intel_sdvo_read_response(output, pos, 8); ++ intel_sdvo_read_response(encoder, pos, 8); + pos += 8; + } + } + } + #endif + +-static void intel_sdvo_set_hdmi_buf(struct intel_output *output, int index, +- uint8_t *data, int8_t size, uint8_t tx_rate) ++static void intel_sdvo_set_hdmi_buf(struct intel_encoder *intel_encoder, ++ int index, ++ uint8_t *data, int8_t size, uint8_t tx_rate) + { + uint8_t set_buf_index[2]; + + set_buf_index[0] = index; + set_buf_index[1] = 0; + +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_INDEX, set_buf_index, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_INDEX, ++ set_buf_index, 2); + + for (; size > 0; size -= 8) { +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_DATA, data, 8); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_DATA, data, 8); + data += 8; + } + +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_HBUF_TXRATE, &tx_rate, 1); + } + + static uint8_t intel_sdvo_calc_hbuf_csum(uint8_t *data, uint8_t size) +@@ -1033,7 +999,7 @@ struct dip_infoframe { + } __attribute__ ((packed)) u; + } __attribute__((packed)); + +-static void intel_sdvo_set_avi_infoframe(struct intel_output *output, ++static void intel_sdvo_set_avi_infoframe(struct intel_encoder *intel_encoder, + struct drm_display_mode * mode) + { + struct dip_infoframe avi_if = { +@@ -1044,15 +1010,16 @@ static void intel_sdvo_set_avi_infoframe(struct intel_output *output, + + avi_if.checksum = intel_sdvo_calc_hbuf_csum((uint8_t *)&avi_if, + 4 + avi_if.len); +- intel_sdvo_set_hdmi_buf(output, 1, (uint8_t *)&avi_if, 4 + avi_if.len, ++ intel_sdvo_set_hdmi_buf(intel_encoder, 1, (uint8_t *)&avi_if, ++ 4 + avi_if.len, + SDVO_HBUF_TX_VSYNC); + } + +-static void intel_sdvo_set_tv_format(struct intel_output *output) ++static void intel_sdvo_set_tv_format(struct intel_encoder *intel_encoder) + { + + struct intel_sdvo_tv_format format; +- struct intel_sdvo_priv *sdvo_priv = output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + uint32_t format_map, i; + uint8_t status; + +@@ -1065,10 +1032,10 @@ static void intel_sdvo_set_tv_format(struct intel_output *output) + memcpy(&format, &format_map, sizeof(format_map) > sizeof(format) ? + sizeof(format) : sizeof(format_map)); + +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_TV_FORMAT, &format_map, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_TV_FORMAT, &format, + sizeof(format)); + +- status = intel_sdvo_read_response(output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + if (status != SDVO_CMD_STATUS_SUCCESS) + DRM_DEBUG_KMS("%s: Failed to set TV format\n", + SDVO_NAME(sdvo_priv)); +@@ -1078,8 +1045,8 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) + { +- struct intel_output *output = enc_to_intel_output(encoder); +- struct intel_sdvo_priv *dev_priv = output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *dev_priv = intel_encoder->dev_priv; + + if (dev_priv->is_tv) { + struct intel_sdvo_dtd output_dtd; +@@ -1094,22 +1061,22 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, + + /* Set output timings */ + intel_sdvo_get_dtd_from_mode(&output_dtd, mode); +- intel_sdvo_set_target_output(output, +- dev_priv->controlled_output); +- intel_sdvo_set_output_timing(output, &output_dtd); ++ intel_sdvo_set_target_output(intel_encoder, ++ dev_priv->attached_output); ++ intel_sdvo_set_output_timing(intel_encoder, &output_dtd); + + /* Set the input timing to the screen. Assume always input 0. */ +- intel_sdvo_set_target_input(output, true, false); ++ intel_sdvo_set_target_input(intel_encoder, true, false); + + +- success = intel_sdvo_create_preferred_input_timing(output, ++ success = intel_sdvo_create_preferred_input_timing(intel_encoder, + mode->clock / 10, + mode->hdisplay, + mode->vdisplay); + if (success) { + struct intel_sdvo_dtd input_dtd; + +- intel_sdvo_get_preferred_input_timing(output, ++ intel_sdvo_get_preferred_input_timing(intel_encoder, + &input_dtd); + intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); + dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags; +@@ -1132,16 +1099,16 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, + intel_sdvo_get_dtd_from_mode(&output_dtd, + dev_priv->sdvo_lvds_fixed_mode); + +- intel_sdvo_set_target_output(output, +- dev_priv->controlled_output); +- intel_sdvo_set_output_timing(output, &output_dtd); ++ intel_sdvo_set_target_output(intel_encoder, ++ dev_priv->attached_output); ++ intel_sdvo_set_output_timing(intel_encoder, &output_dtd); + + /* Set the input timing to the screen. Assume always input 0. */ +- intel_sdvo_set_target_input(output, true, false); ++ intel_sdvo_set_target_input(intel_encoder, true, false); + + + success = intel_sdvo_create_preferred_input_timing( +- output, ++ intel_encoder, + mode->clock / 10, + mode->hdisplay, + mode->vdisplay); +@@ -1149,7 +1116,7 @@ static bool intel_sdvo_mode_fixup(struct drm_encoder *encoder, + if (success) { + struct intel_sdvo_dtd input_dtd; + +- intel_sdvo_get_preferred_input_timing(output, ++ intel_sdvo_get_preferred_input_timing(intel_encoder, + &input_dtd); + intel_sdvo_get_mode_from_dtd(adjusted_mode, &input_dtd); + dev_priv->sdvo_flags = input_dtd.part2.sdvo_flags; +@@ -1181,8 +1148,8 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_crtc *crtc = encoder->crtc; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); +- struct intel_output *output = enc_to_intel_output(encoder); +- struct intel_sdvo_priv *sdvo_priv = output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + u32 sdvox = 0; + int sdvo_pixel_multiply; + struct intel_sdvo_in_out_map in_out; +@@ -1198,15 +1165,15 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, + * channel on the motherboard. In a two-input device, the first input + * will be SDVOB and the second SDVOC. + */ +- in_out.in0 = sdvo_priv->controlled_output; ++ in_out.in0 = sdvo_priv->attached_output; + in_out.in1 = 0; + +- intel_sdvo_write_cmd(output, SDVO_CMD_SET_IN_OUT_MAP, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_IN_OUT_MAP, + &in_out, sizeof(in_out)); +- status = intel_sdvo_read_response(output, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, NULL, 0); + + if (sdvo_priv->is_hdmi) { +- intel_sdvo_set_avi_infoframe(output, mode); ++ intel_sdvo_set_avi_infoframe(intel_encoder, mode); + sdvox |= SDVO_AUDIO_ENABLE; + } + +@@ -1223,16 +1190,16 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, + */ + if (!sdvo_priv->is_tv && !sdvo_priv->is_lvds) { + /* Set the output timing to the screen */ +- intel_sdvo_set_target_output(output, +- sdvo_priv->controlled_output); +- intel_sdvo_set_output_timing(output, &input_dtd); ++ intel_sdvo_set_target_output(intel_encoder, ++ sdvo_priv->attached_output); ++ intel_sdvo_set_output_timing(intel_encoder, &input_dtd); + } + + /* Set the input timing to the screen. Assume always input 0. */ +- intel_sdvo_set_target_input(output, true, false); ++ intel_sdvo_set_target_input(intel_encoder, true, false); + + if (sdvo_priv->is_tv) +- intel_sdvo_set_tv_format(output); ++ intel_sdvo_set_tv_format(intel_encoder); + + /* We would like to use intel_sdvo_create_preferred_input_timing() to + * provide the device with a timing it can support, if it supports that +@@ -1240,29 +1207,29 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, + * output the preferred timing, and we don't support that currently. + */ + #if 0 +- success = intel_sdvo_create_preferred_input_timing(output, clock, ++ success = intel_sdvo_create_preferred_input_timing(encoder, clock, + width, height); + if (success) { + struct intel_sdvo_dtd *input_dtd; + +- intel_sdvo_get_preferred_input_timing(output, &input_dtd); +- intel_sdvo_set_input_timing(output, &input_dtd); ++ intel_sdvo_get_preferred_input_timing(encoder, &input_dtd); ++ intel_sdvo_set_input_timing(encoder, &input_dtd); + } + #else +- intel_sdvo_set_input_timing(output, &input_dtd); ++ intel_sdvo_set_input_timing(intel_encoder, &input_dtd); + #endif + + switch (intel_sdvo_get_pixel_multiplier(mode)) { + case 1: +- intel_sdvo_set_clock_rate_mult(output, ++ intel_sdvo_set_clock_rate_mult(intel_encoder, + SDVO_CLOCK_RATE_MULT_1X); + break; + case 2: +- intel_sdvo_set_clock_rate_mult(output, ++ intel_sdvo_set_clock_rate_mult(intel_encoder, + SDVO_CLOCK_RATE_MULT_2X); + break; + case 4: +- intel_sdvo_set_clock_rate_mult(output, ++ intel_sdvo_set_clock_rate_mult(intel_encoder, + SDVO_CLOCK_RATE_MULT_4X); + break; + } +@@ -1273,8 +1240,8 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, + SDVO_VSYNC_ACTIVE_HIGH | + SDVO_HSYNC_ACTIVE_HIGH; + } else { +- sdvox |= I915_READ(sdvo_priv->output_device); +- switch (sdvo_priv->output_device) { ++ sdvox |= I915_READ(sdvo_priv->sdvo_reg); ++ switch (sdvo_priv->sdvo_reg) { + case SDVOB: + sdvox &= SDVOB_PRESERVE_MASK; + break; +@@ -1298,26 +1265,26 @@ static void intel_sdvo_mode_set(struct drm_encoder *encoder, + + if (sdvo_priv->sdvo_flags & SDVO_NEED_TO_STALL) + sdvox |= SDVO_STALL_SELECT; +- intel_sdvo_write_sdvox(output, sdvox); ++ intel_sdvo_write_sdvox(intel_encoder, sdvox); + } + + static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) + { + struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + u32 temp; + + if (mode != DRM_MODE_DPMS_ON) { +- intel_sdvo_set_active_outputs(intel_output, 0); ++ intel_sdvo_set_active_outputs(intel_encoder, 0); + if (0) +- intel_sdvo_set_encoder_power_state(intel_output, mode); ++ intel_sdvo_set_encoder_power_state(intel_encoder, mode); + + if (mode == DRM_MODE_DPMS_OFF) { +- temp = I915_READ(sdvo_priv->output_device); ++ temp = I915_READ(sdvo_priv->sdvo_reg); + if ((temp & SDVO_ENABLE) != 0) { +- intel_sdvo_write_sdvox(intel_output, temp & ~SDVO_ENABLE); ++ intel_sdvo_write_sdvox(intel_encoder, temp & ~SDVO_ENABLE); + } + } + } else { +@@ -1325,13 +1292,13 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) + int i; + u8 status; + +- temp = I915_READ(sdvo_priv->output_device); ++ temp = I915_READ(sdvo_priv->sdvo_reg); + if ((temp & SDVO_ENABLE) == 0) +- intel_sdvo_write_sdvox(intel_output, temp | SDVO_ENABLE); ++ intel_sdvo_write_sdvox(intel_encoder, temp | SDVO_ENABLE); + for (i = 0; i < 2; i++) + intel_wait_for_vblank(dev); + +- status = intel_sdvo_get_trained_inputs(intel_output, &input1, ++ status = intel_sdvo_get_trained_inputs(intel_encoder, &input1, + &input2); + + +@@ -1345,109 +1312,18 @@ static void intel_sdvo_dpms(struct drm_encoder *encoder, int mode) + } + + if (0) +- intel_sdvo_set_encoder_power_state(intel_output, mode); +- intel_sdvo_set_active_outputs(intel_output, sdvo_priv->controlled_output); ++ intel_sdvo_set_encoder_power_state(intel_encoder, mode); ++ intel_sdvo_set_active_outputs(intel_encoder, sdvo_priv->attached_output); + } + return; + } + +-static void intel_sdvo_save(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; +- int o; +- +- sdvo_priv->save_sdvo_mult = intel_sdvo_get_clock_rate_mult(intel_output); +- intel_sdvo_get_active_outputs(intel_output, &sdvo_priv->save_active_outputs); +- +- if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) { +- intel_sdvo_set_target_input(intel_output, true, false); +- intel_sdvo_get_input_timing(intel_output, +- &sdvo_priv->save_input_dtd_1); +- } +- +- if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) { +- intel_sdvo_set_target_input(intel_output, false, true); +- intel_sdvo_get_input_timing(intel_output, +- &sdvo_priv->save_input_dtd_2); +- } +- +- for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++) +- { +- u16 this_output = (1 << o); +- if (sdvo_priv->caps.output_flags & this_output) +- { +- intel_sdvo_set_target_output(intel_output, this_output); +- intel_sdvo_get_output_timing(intel_output, +- &sdvo_priv->save_output_dtd[o]); +- } +- } +- if (sdvo_priv->is_tv) { +- /* XXX: Save TV format/enhancements. */ +- } +- +- sdvo_priv->save_SDVOX = I915_READ(sdvo_priv->output_device); +-} +- +-static void intel_sdvo_restore(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; +- int o; +- int i; +- bool input1, input2; +- u8 status; +- +- intel_sdvo_set_active_outputs(intel_output, 0); +- +- for (o = SDVO_OUTPUT_FIRST; o <= SDVO_OUTPUT_LAST; o++) +- { +- u16 this_output = (1 << o); +- if (sdvo_priv->caps.output_flags & this_output) { +- intel_sdvo_set_target_output(intel_output, this_output); +- intel_sdvo_set_output_timing(intel_output, &sdvo_priv->save_output_dtd[o]); +- } +- } +- +- if (sdvo_priv->caps.sdvo_inputs_mask & 0x1) { +- intel_sdvo_set_target_input(intel_output, true, false); +- intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_1); +- } +- +- if (sdvo_priv->caps.sdvo_inputs_mask & 0x2) { +- intel_sdvo_set_target_input(intel_output, false, true); +- intel_sdvo_set_input_timing(intel_output, &sdvo_priv->save_input_dtd_2); +- } +- +- intel_sdvo_set_clock_rate_mult(intel_output, sdvo_priv->save_sdvo_mult); +- +- if (sdvo_priv->is_tv) { +- /* XXX: Restore TV format/enhancements. */ +- } +- +- intel_sdvo_write_sdvox(intel_output, sdvo_priv->save_SDVOX); +- +- if (sdvo_priv->save_SDVOX & SDVO_ENABLE) +- { +- for (i = 0; i < 2; i++) +- intel_wait_for_vblank(dev); +- status = intel_sdvo_get_trained_inputs(intel_output, &input1, &input2); +- if (status == SDVO_CMD_STATUS_SUCCESS && !input1) +- DRM_DEBUG_KMS("First %s output reported failure to " +- "sync\n", SDVO_NAME(sdvo_priv)); +- } +- +- intel_sdvo_set_active_outputs(intel_output, sdvo_priv->save_active_outputs); +-} +- + static int intel_sdvo_mode_valid(struct drm_connector *connector, + struct drm_display_mode *mode) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + + if (mode->flags & DRM_MODE_FLAG_DBLSCAN) + return MODE_NO_DBLESCAN; +@@ -1472,37 +1348,39 @@ static int intel_sdvo_mode_valid(struct drm_connector *connector, + return MODE_OK; + } + +-static bool intel_sdvo_get_capabilities(struct intel_output *intel_output, struct intel_sdvo_caps *caps) ++static bool intel_sdvo_get_capabilities(struct intel_encoder *intel_encoder, struct intel_sdvo_caps *caps) + { + u8 status; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0); +- status = intel_sdvo_read_response(intel_output, caps, sizeof(*caps)); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_DEVICE_CAPS, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, caps, sizeof(*caps)); + if (status != SDVO_CMD_STATUS_SUCCESS) + return false; + + return true; + } + ++/* No use! */ ++#if 0 + struct drm_connector* intel_sdvo_find(struct drm_device *dev, int sdvoB) + { + struct drm_connector *connector = NULL; +- struct intel_output *iout = NULL; ++ struct intel_encoder *iout = NULL; + struct intel_sdvo_priv *sdvo; + + /* find the sdvo connector */ + list_for_each_entry(connector, &dev->mode_config.connector_list, head) { +- iout = to_intel_output(connector); ++ iout = to_intel_encoder(connector); + + if (iout->type != INTEL_OUTPUT_SDVO) + continue; + + sdvo = iout->dev_priv; + +- if (sdvo->output_device == SDVOB && sdvoB) ++ if (sdvo->sdvo_reg == SDVOB && sdvoB) + return connector; + +- if (sdvo->output_device == SDVOC && !sdvoB) ++ if (sdvo->sdvo_reg == SDVOC && !sdvoB) + return connector; + + } +@@ -1514,16 +1392,16 @@ int intel_sdvo_supports_hotplug(struct drm_connector *connector) + { + u8 response[2]; + u8 status; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; + DRM_DEBUG_KMS("\n"); + + if (!connector) + return 0; + +- intel_output = to_intel_output(connector); ++ intel_encoder = to_intel_encoder(connector); + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); +- status = intel_sdvo_read_response(intel_output, &response, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, &response, 2); + + if (response[0] !=0) + return 1; +@@ -1535,30 +1413,31 @@ void intel_sdvo_set_hotplug(struct drm_connector *connector, int on) + { + u8 response[2]; + u8 status; +- struct intel_output *intel_output = to_intel_output(connector); ++ struct intel_encoder *intel_encoder = to_intel_encoder(connector); + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); +- intel_sdvo_read_response(intel_output, &response, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); ++ intel_sdvo_read_response(intel_encoder, &response, 2); + + if (on) { +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); +- status = intel_sdvo_read_response(intel_output, &response, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_HOT_PLUG_SUPPORT, NULL, 0); ++ status = intel_sdvo_read_response(intel_encoder, &response, 2); + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); + } else { + response[0] = 0; + response[1] = 0; +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_SET_ACTIVE_HOT_PLUG, &response, 2); + } + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); +- intel_sdvo_read_response(intel_output, &response, 2); ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_ACTIVE_HOT_PLUG, NULL, 0); ++ intel_sdvo_read_response(intel_encoder, &response, 2); + } ++#endif + + static bool +-intel_sdvo_multifunc_encoder(struct intel_output *intel_output) ++intel_sdvo_multifunc_encoder(struct intel_encoder *intel_encoder) + { +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + int caps = 0; + + if (sdvo_priv->caps.output_flags & +@@ -1592,12 +1471,17 @@ static struct drm_connector * + intel_find_analog_connector(struct drm_device *dev) + { + struct drm_connector *connector; +- struct intel_output *intel_output; +- +- list_for_each_entry(connector, &dev->mode_config.connector_list, head) { +- intel_output = to_intel_output(connector); +- if (intel_output->type == INTEL_OUTPUT_ANALOG) +- return connector; ++ struct drm_encoder *encoder; ++ struct intel_encoder *intel_encoder; ++ ++ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { ++ intel_encoder = enc_to_intel_encoder(encoder); ++ if (intel_encoder->type == INTEL_OUTPUT_ANALOG) { ++ list_for_each_entry(connector, &dev->mode_config.connector_list, head) { ++ if (connector && encoder == intel_attached_encoder(connector)) ++ return connector; ++ } ++ } + } + return NULL; + } +@@ -1621,16 +1505,17 @@ intel_analog_is_connected(struct drm_device *dev) + enum drm_connector_status + intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + enum drm_connector_status status = connector_status_connected; + struct edid *edid = NULL; + +- edid = drm_get_edid(&intel_output->base, +- intel_output->ddc_bus); ++ edid = drm_get_edid(connector, ++ intel_encoder->ddc_bus); + + /* This is only applied to SDVO cards with multiple outputs */ +- if (edid == NULL && intel_sdvo_multifunc_encoder(intel_output)) { ++ if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) { + uint8_t saved_ddc, temp_ddc; + saved_ddc = sdvo_priv->ddc_bus; + temp_ddc = sdvo_priv->ddc_bus >> 1; +@@ -1640,8 +1525,8 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) + */ + while(temp_ddc > 1) { + sdvo_priv->ddc_bus = temp_ddc; +- edid = drm_get_edid(&intel_output->base, +- intel_output->ddc_bus); ++ edid = drm_get_edid(connector, ++ intel_encoder->ddc_bus); + if (edid) { + /* + * When we can get the EDID, maybe it is the +@@ -1660,8 +1545,8 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) + */ + if (edid == NULL && + sdvo_priv->analog_ddc_bus && +- !intel_analog_is_connected(intel_output->base.dev)) +- edid = drm_get_edid(&intel_output->base, ++ !intel_analog_is_connected(connector->dev)) ++ edid = drm_get_edid(connector, + sdvo_priv->analog_ddc_bus); + if (edid != NULL) { + /* Don't report the output as connected if it's a DVI-I +@@ -1676,7 +1561,7 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) + } + + kfree(edid); +- intel_output->base.display_info.raw_edid = NULL; ++ connector->display_info.raw_edid = NULL; + + } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) + status = connector_status_disconnected; +@@ -1688,16 +1573,20 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect + { + uint16_t response; + u8 status; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; +- +- intel_sdvo_write_cmd(intel_output, ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; ++ enum drm_connector_status ret; ++ ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_ATTACHED_DISPLAYS, NULL, 0); + if (sdvo_priv->is_tv) { + /* add 30ms delay when the output type is SDVO-TV */ + mdelay(30); + } +- status = intel_sdvo_read_response(intel_output, &response, 2); ++ status = intel_sdvo_read_response(intel_encoder, &response, 2); + + DRM_DEBUG_KMS("SDVO response %d %d\n", response & 0xff, response >> 8); + +@@ -1707,24 +1596,41 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect + if (response == 0) + return connector_status_disconnected; + +- if (intel_sdvo_multifunc_encoder(intel_output) && +- sdvo_priv->attached_output != response) { +- if (sdvo_priv->controlled_output != response && +- intel_sdvo_output_setup(intel_output, response) != true) +- return connector_status_unknown; +- sdvo_priv->attached_output = response; ++ sdvo_priv->attached_output = response; ++ ++ if ((sdvo_connector->output_flag & response) == 0) ++ ret = connector_status_disconnected; ++ else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) ++ ret = intel_sdvo_hdmi_sink_detect(connector, response); ++ else ++ ret = connector_status_connected; ++ ++ /* May update encoder flag for like clock for SDVO TV, etc.*/ ++ if (ret == connector_status_connected) { ++ sdvo_priv->is_tv = false; ++ sdvo_priv->is_lvds = false; ++ intel_encoder->needs_tv_clock = false; ++ ++ if (response & SDVO_TV_MASK) { ++ sdvo_priv->is_tv = true; ++ intel_encoder->needs_tv_clock = true; ++ } ++ if (response & SDVO_LVDS_MASK) ++ sdvo_priv->is_lvds = true; + } +- return intel_sdvo_hdmi_sink_detect(connector, response); ++ ++ return ret; + } + + static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + int num_modes; + + /* set the bus switch and get the modes */ +- num_modes = intel_ddc_get_modes(intel_output); ++ num_modes = intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + + /* + * Mac mini hack. On this device, the DVI-I connector shares one DDC +@@ -1734,17 +1640,10 @@ static void intel_sdvo_get_ddc_modes(struct drm_connector *connector) + */ + if (num_modes == 0 && + sdvo_priv->analog_ddc_bus && +- !intel_analog_is_connected(intel_output->base.dev)) { +- struct i2c_adapter *digital_ddc_bus; +- ++ !intel_analog_is_connected(connector->dev)) { + /* Switch to the analog ddc bus and try that + */ +- digital_ddc_bus = intel_output->ddc_bus; +- intel_output->ddc_bus = sdvo_priv->analog_ddc_bus; +- +- (void) intel_ddc_get_modes(intel_output); +- +- intel_output->ddc_bus = digital_ddc_bus; ++ (void) intel_ddc_get_modes(connector, sdvo_priv->analog_ddc_bus); + } + } + +@@ -1815,8 +1714,9 @@ struct drm_display_mode sdvo_tv_modes[] = { + + static void intel_sdvo_get_tv_modes(struct drm_connector *connector) + { +- struct intel_output *output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + struct intel_sdvo_sdtv_resolution_request tv_res; + uint32_t reply = 0, format_map = 0; + int i; +@@ -1836,11 +1736,11 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) + sizeof(format_map) ? sizeof(format_map) : + sizeof(struct intel_sdvo_sdtv_resolution_request)); + +- intel_sdvo_set_target_output(output, sdvo_priv->controlled_output); ++ intel_sdvo_set_target_output(intel_encoder, sdvo_priv->attached_output); + +- intel_sdvo_write_cmd(output, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SDTV_RESOLUTION_SUPPORT, + &tv_res, sizeof(tv_res)); +- status = intel_sdvo_read_response(output, &reply, 3); ++ status = intel_sdvo_read_response(intel_encoder, &reply, 3); + if (status != SDVO_CMD_STATUS_SUCCESS) + return; + +@@ -1857,9 +1757,10 @@ static void intel_sdvo_get_tv_modes(struct drm_connector *connector) + + static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + struct drm_i915_private *dev_priv = connector->dev->dev_private; +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + struct drm_display_mode *newmode; + + /* +@@ -1867,7 +1768,7 @@ static void intel_sdvo_get_lvds_modes(struct drm_connector *connector) + * Assume that the preferred modes are + * arranged in priority order. + */ +- intel_ddc_get_modes(intel_output); ++ intel_ddc_get_modes(connector, intel_encoder->ddc_bus); + if (list_empty(&connector->probed_modes) == false) + goto end; + +@@ -1896,12 +1797,12 @@ end: + + static int intel_sdvo_get_modes(struct drm_connector *connector) + { +- struct intel_output *output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = output->dev_priv; ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; + +- if (sdvo_priv->is_tv) ++ if (IS_TV(sdvo_connector)) + intel_sdvo_get_tv_modes(connector); +- else if (sdvo_priv->is_lvds == true) ++ else if (IS_LVDS(sdvo_connector)) + intel_sdvo_get_lvds_modes(connector); + else + intel_sdvo_get_ddc_modes(connector); +@@ -1914,11 +1815,11 @@ static int intel_sdvo_get_modes(struct drm_connector *connector) + static + void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv; + struct drm_device *dev = connector->dev; + +- if (sdvo_priv->is_tv) { ++ if (IS_TV(sdvo_priv)) { + if (sdvo_priv->left_property) + drm_property_destroy(dev, sdvo_priv->left_property); + if (sdvo_priv->right_property) +@@ -1931,8 +1832,6 @@ void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) + drm_property_destroy(dev, sdvo_priv->hpos_property); + if (sdvo_priv->vpos_property) + drm_property_destroy(dev, sdvo_priv->vpos_property); +- } +- if (sdvo_priv->is_tv) { + if (sdvo_priv->saturation_property) + drm_property_destroy(dev, + sdvo_priv->saturation_property); +@@ -1942,7 +1841,7 @@ void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) + if (sdvo_priv->hue_property) + drm_property_destroy(dev, sdvo_priv->hue_property); + } +- if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { ++ if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) { + if (sdvo_priv->brightness_property) + drm_property_destroy(dev, + sdvo_priv->brightness_property); +@@ -1952,31 +1851,17 @@ void intel_sdvo_destroy_enhance_property(struct drm_connector *connector) + + static void intel_sdvo_destroy(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; +- +- if (intel_output->i2c_bus) +- intel_i2c_destroy(intel_output->i2c_bus); +- if (intel_output->ddc_bus) +- intel_i2c_destroy(intel_output->ddc_bus); +- if (sdvo_priv->analog_ddc_bus) +- intel_i2c_destroy(sdvo_priv->analog_ddc_bus); ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; + +- if (sdvo_priv->sdvo_lvds_fixed_mode != NULL) +- drm_mode_destroy(connector->dev, +- sdvo_priv->sdvo_lvds_fixed_mode); +- +- if (sdvo_priv->tv_format_property) ++ if (sdvo_connector->tv_format_property) + drm_property_destroy(connector->dev, +- sdvo_priv->tv_format_property); +- +- if (sdvo_priv->is_tv || sdvo_priv->is_lvds) +- intel_sdvo_destroy_enhance_property(connector); ++ sdvo_connector->tv_format_property); + ++ intel_sdvo_destroy_enhance_property(connector); + drm_sysfs_connector_remove(connector); + drm_connector_cleanup(connector); +- +- kfree(intel_output); ++ kfree(connector); + } + + static int +@@ -1984,9 +1869,11 @@ intel_sdvo_set_property(struct drm_connector *connector, + struct drm_property *property, + uint64_t val) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; + struct drm_crtc *crtc = encoder->crtc; + int ret = 0; + bool changed = false; +@@ -1997,105 +1884,105 @@ intel_sdvo_set_property(struct drm_connector *connector, + if (ret < 0) + goto out; + +- if (property == sdvo_priv->tv_format_property) { ++ if (property == sdvo_connector->tv_format_property) { + if (val >= TV_FORMAT_NUM) { + ret = -EINVAL; + goto out; + } + if (sdvo_priv->tv_format_name == +- sdvo_priv->tv_format_supported[val]) ++ sdvo_connector->tv_format_supported[val]) + goto out; + +- sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[val]; ++ sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[val]; + changed = true; + } + +- if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { ++ if (IS_TV(sdvo_connector) || IS_LVDS(sdvo_connector)) { + cmd = 0; + temp_value = val; +- if (sdvo_priv->left_property == property) { ++ if (sdvo_connector->left_property == property) { + drm_connector_property_set_value(connector, +- sdvo_priv->right_property, val); +- if (sdvo_priv->left_margin == temp_value) ++ sdvo_connector->right_property, val); ++ if (sdvo_connector->left_margin == temp_value) + goto out; + +- sdvo_priv->left_margin = temp_value; +- sdvo_priv->right_margin = temp_value; +- temp_value = sdvo_priv->max_hscan - +- sdvo_priv->left_margin; ++ sdvo_connector->left_margin = temp_value; ++ sdvo_connector->right_margin = temp_value; ++ temp_value = sdvo_connector->max_hscan - ++ sdvo_connector->left_margin; + cmd = SDVO_CMD_SET_OVERSCAN_H; +- } else if (sdvo_priv->right_property == property) { ++ } else if (sdvo_connector->right_property == property) { + drm_connector_property_set_value(connector, +- sdvo_priv->left_property, val); +- if (sdvo_priv->right_margin == temp_value) ++ sdvo_connector->left_property, val); ++ if (sdvo_connector->right_margin == temp_value) + goto out; + +- sdvo_priv->left_margin = temp_value; +- sdvo_priv->right_margin = temp_value; +- temp_value = sdvo_priv->max_hscan - +- sdvo_priv->left_margin; ++ sdvo_connector->left_margin = temp_value; ++ sdvo_connector->right_margin = temp_value; ++ temp_value = sdvo_connector->max_hscan - ++ sdvo_connector->left_margin; + cmd = SDVO_CMD_SET_OVERSCAN_H; +- } else if (sdvo_priv->top_property == property) { ++ } else if (sdvo_connector->top_property == property) { + drm_connector_property_set_value(connector, +- sdvo_priv->bottom_property, val); +- if (sdvo_priv->top_margin == temp_value) ++ sdvo_connector->bottom_property, val); ++ if (sdvo_connector->top_margin == temp_value) + goto out; + +- sdvo_priv->top_margin = temp_value; +- sdvo_priv->bottom_margin = temp_value; +- temp_value = sdvo_priv->max_vscan - +- sdvo_priv->top_margin; ++ sdvo_connector->top_margin = temp_value; ++ sdvo_connector->bottom_margin = temp_value; ++ temp_value = sdvo_connector->max_vscan - ++ sdvo_connector->top_margin; + cmd = SDVO_CMD_SET_OVERSCAN_V; +- } else if (sdvo_priv->bottom_property == property) { ++ } else if (sdvo_connector->bottom_property == property) { + drm_connector_property_set_value(connector, +- sdvo_priv->top_property, val); +- if (sdvo_priv->bottom_margin == temp_value) ++ sdvo_connector->top_property, val); ++ if (sdvo_connector->bottom_margin == temp_value) + goto out; +- sdvo_priv->top_margin = temp_value; +- sdvo_priv->bottom_margin = temp_value; +- temp_value = sdvo_priv->max_vscan - +- sdvo_priv->top_margin; ++ sdvo_connector->top_margin = temp_value; ++ sdvo_connector->bottom_margin = temp_value; ++ temp_value = sdvo_connector->max_vscan - ++ sdvo_connector->top_margin; + cmd = SDVO_CMD_SET_OVERSCAN_V; +- } else if (sdvo_priv->hpos_property == property) { +- if (sdvo_priv->cur_hpos == temp_value) ++ } else if (sdvo_connector->hpos_property == property) { ++ if (sdvo_connector->cur_hpos == temp_value) + goto out; + + cmd = SDVO_CMD_SET_POSITION_H; +- sdvo_priv->cur_hpos = temp_value; +- } else if (sdvo_priv->vpos_property == property) { +- if (sdvo_priv->cur_vpos == temp_value) ++ sdvo_connector->cur_hpos = temp_value; ++ } else if (sdvo_connector->vpos_property == property) { ++ if (sdvo_connector->cur_vpos == temp_value) + goto out; + + cmd = SDVO_CMD_SET_POSITION_V; +- sdvo_priv->cur_vpos = temp_value; +- } else if (sdvo_priv->saturation_property == property) { +- if (sdvo_priv->cur_saturation == temp_value) ++ sdvo_connector->cur_vpos = temp_value; ++ } else if (sdvo_connector->saturation_property == property) { ++ if (sdvo_connector->cur_saturation == temp_value) + goto out; + + cmd = SDVO_CMD_SET_SATURATION; +- sdvo_priv->cur_saturation = temp_value; +- } else if (sdvo_priv->contrast_property == property) { +- if (sdvo_priv->cur_contrast == temp_value) ++ sdvo_connector->cur_saturation = temp_value; ++ } else if (sdvo_connector->contrast_property == property) { ++ if (sdvo_connector->cur_contrast == temp_value) + goto out; + + cmd = SDVO_CMD_SET_CONTRAST; +- sdvo_priv->cur_contrast = temp_value; +- } else if (sdvo_priv->hue_property == property) { +- if (sdvo_priv->cur_hue == temp_value) ++ sdvo_connector->cur_contrast = temp_value; ++ } else if (sdvo_connector->hue_property == property) { ++ if (sdvo_connector->cur_hue == temp_value) + goto out; + + cmd = SDVO_CMD_SET_HUE; +- sdvo_priv->cur_hue = temp_value; +- } else if (sdvo_priv->brightness_property == property) { +- if (sdvo_priv->cur_brightness == temp_value) ++ sdvo_connector->cur_hue = temp_value; ++ } else if (sdvo_connector->brightness_property == property) { ++ if (sdvo_connector->cur_brightness == temp_value) + goto out; + + cmd = SDVO_CMD_SET_BRIGHTNESS; +- sdvo_priv->cur_brightness = temp_value; ++ sdvo_connector->cur_brightness = temp_value; + } + if (cmd) { +- intel_sdvo_write_cmd(intel_output, cmd, &temp_value, 2); +- status = intel_sdvo_read_response(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, cmd, &temp_value, 2); ++ status = intel_sdvo_read_response(intel_encoder, + NULL, 0); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO command \n"); +@@ -2121,8 +2008,6 @@ static const struct drm_encoder_helper_funcs intel_sdvo_helper_funcs = { + + static const struct drm_connector_funcs intel_sdvo_connector_funcs = { + .dpms = drm_helper_connector_dpms, +- .save = intel_sdvo_save, +- .restore = intel_sdvo_restore, + .detect = intel_sdvo_detect, + .fill_modes = drm_helper_probe_single_connector_modes, + .set_property = intel_sdvo_set_property, +@@ -2132,12 +2017,27 @@ static const struct drm_connector_funcs intel_sdvo_connector_funcs = { + static const struct drm_connector_helper_funcs intel_sdvo_connector_helper_funcs = { + .get_modes = intel_sdvo_get_modes, + .mode_valid = intel_sdvo_mode_valid, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static void intel_sdvo_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ ++ if (intel_encoder->i2c_bus) ++ intel_i2c_destroy(intel_encoder->i2c_bus); ++ if (intel_encoder->ddc_bus) ++ intel_i2c_destroy(intel_encoder->ddc_bus); ++ if (sdvo_priv->analog_ddc_bus) ++ intel_i2c_destroy(sdvo_priv->analog_ddc_bus); ++ ++ if (sdvo_priv->sdvo_lvds_fixed_mode != NULL) ++ drm_mode_destroy(encoder->dev, ++ sdvo_priv->sdvo_lvds_fixed_mode); ++ + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_sdvo_enc_funcs = { +@@ -2190,12 +2090,15 @@ intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv) + } + + static bool +-intel_sdvo_get_digital_encoding_mode(struct intel_output *output) ++intel_sdvo_get_digital_encoding_mode(struct intel_encoder *output, int device) + { + struct intel_sdvo_priv *sdvo_priv = output->dev_priv; + uint8_t status; + +- intel_sdvo_set_target_output(output, sdvo_priv->controlled_output); ++ if (device == 0) ++ intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS0); ++ else ++ intel_sdvo_set_target_output(output, SDVO_OUTPUT_TMDS1); + + intel_sdvo_write_cmd(output, SDVO_CMD_GET_ENCODE, NULL, 0); + status = intel_sdvo_read_response(output, &sdvo_priv->is_hdmi, 1); +@@ -2204,42 +2107,40 @@ intel_sdvo_get_digital_encoding_mode(struct intel_output *output) + return true; + } + +-static struct intel_output * +-intel_sdvo_chan_to_intel_output(struct intel_i2c_chan *chan) ++static struct intel_encoder * ++intel_sdvo_chan_to_intel_encoder(struct intel_i2c_chan *chan) + { + struct drm_device *dev = chan->drm_dev; +- struct drm_connector *connector; +- struct intel_output *intel_output = NULL; ++ struct drm_encoder *encoder; ++ struct intel_encoder *intel_encoder = NULL; + +- list_for_each_entry(connector, +- &dev->mode_config.connector_list, head) { +- if (to_intel_output(connector)->ddc_bus == &chan->adapter) { +- intel_output = to_intel_output(connector); ++ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { ++ intel_encoder = enc_to_intel_encoder(encoder); ++ if (intel_encoder->ddc_bus == &chan->adapter) + break; +- } + } +- return intel_output; ++ return intel_encoder; + } + + static int intel_sdvo_master_xfer(struct i2c_adapter *i2c_adap, + struct i2c_msg msgs[], int num) + { +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; + struct intel_sdvo_priv *sdvo_priv; + struct i2c_algo_bit_data *algo_data; + const struct i2c_algorithm *algo; + + algo_data = (struct i2c_algo_bit_data *)i2c_adap->algo_data; +- intel_output = +- intel_sdvo_chan_to_intel_output( ++ intel_encoder = ++ intel_sdvo_chan_to_intel_encoder( + (struct intel_i2c_chan *)(algo_data->data)); +- if (intel_output == NULL) ++ if (intel_encoder == NULL) + return -EINVAL; + +- sdvo_priv = intel_output->dev_priv; +- algo = intel_output->i2c_bus->algo; ++ sdvo_priv = intel_encoder->dev_priv; ++ algo = intel_encoder->i2c_bus->algo; + +- intel_sdvo_set_control_bus_switch(intel_output, sdvo_priv->ddc_bus); ++ intel_sdvo_set_control_bus_switch(intel_encoder, sdvo_priv->ddc_bus); + return algo->master_xfer(i2c_adap, msgs, num); + } + +@@ -2248,12 +2149,12 @@ static struct i2c_algorithm intel_sdvo_i2c_bit_algo = { + }; + + static u8 +-intel_sdvo_get_slave_addr(struct drm_device *dev, int output_device) ++intel_sdvo_get_slave_addr(struct drm_device *dev, int sdvo_reg) + { + struct drm_i915_private *dev_priv = dev->dev_private; + struct sdvo_device_mapping *my_mapping, *other_mapping; + +- if (output_device == SDVOB) { ++ if (IS_SDVOB(sdvo_reg)) { + my_mapping = &dev_priv->sdvo_mappings[0]; + other_mapping = &dev_priv->sdvo_mappings[1]; + } else { +@@ -2278,120 +2179,235 @@ intel_sdvo_get_slave_addr(struct drm_device *dev, int output_device) + /* No SDVO device info is found for another DVO port, + * so use mapping assumption we had before BIOS parsing. + */ +- if (output_device == SDVOB) ++ if (IS_SDVOB(sdvo_reg)) + return 0x70; + else + return 0x72; + } + +-static int intel_sdvo_bad_tv_callback(const struct dmi_system_id *id) ++static bool ++intel_sdvo_connector_alloc (struct intel_connector **ret) + { +- DRM_DEBUG_KMS("Ignoring bad SDVO TV connector for %s\n", id->ident); +- return 1; ++ struct intel_connector *intel_connector; ++ struct intel_sdvo_connector *sdvo_connector; ++ ++ *ret = kzalloc(sizeof(*intel_connector) + ++ sizeof(*sdvo_connector), GFP_KERNEL); ++ if (!*ret) ++ return false; ++ ++ intel_connector = *ret; ++ sdvo_connector = (struct intel_sdvo_connector *)(intel_connector + 1); ++ intel_connector->dev_priv = sdvo_connector; ++ ++ return true; + } + +-static struct dmi_system_id intel_sdvo_bad_tv[] = { +- { +- .callback = intel_sdvo_bad_tv_callback, +- .ident = "IntelG45/ICH10R/DME1737", +- .matches = { +- DMI_MATCH(DMI_SYS_VENDOR, "IBM CORPORATION"), +- DMI_MATCH(DMI_PRODUCT_NAME, "4800784"), +- }, +- }, ++static void ++intel_sdvo_connector_create (struct drm_encoder *encoder, ++ struct drm_connector *connector) ++{ ++ drm_connector_init(encoder->dev, connector, &intel_sdvo_connector_funcs, ++ connector->connector_type); + +- { } /* terminating entry */ +-}; ++ drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); ++ ++ connector->interlace_allowed = 0; ++ connector->doublescan_allowed = 0; ++ connector->display_info.subpixel_order = SubPixelHorizontalRGB; ++ ++ drm_mode_connector_attach_encoder(connector, encoder); ++ drm_sysfs_connector_add(connector); ++} ++ ++static bool ++intel_sdvo_dvi_init(struct intel_encoder *intel_encoder, int device) ++{ ++ struct drm_encoder *encoder = &intel_encoder->enc; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct drm_connector *connector; ++ struct intel_connector *intel_connector; ++ struct intel_sdvo_connector *sdvo_connector; ++ ++ if (!intel_sdvo_connector_alloc(&intel_connector)) ++ return false; ++ ++ sdvo_connector = intel_connector->dev_priv; ++ ++ if (device == 0) { ++ sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS0; ++ sdvo_connector->output_flag = SDVO_OUTPUT_TMDS0; ++ } else if (device == 1) { ++ sdvo_priv->controlled_output |= SDVO_OUTPUT_TMDS1; ++ sdvo_connector->output_flag = SDVO_OUTPUT_TMDS1; ++ } ++ ++ connector = &intel_connector->base; ++ encoder->encoder_type = DRM_MODE_ENCODER_TMDS; ++ connector->connector_type = DRM_MODE_CONNECTOR_DVID; ++ ++ if (intel_sdvo_get_supp_encode(intel_encoder, &sdvo_priv->encode) ++ && intel_sdvo_get_digital_encoding_mode(intel_encoder, device) ++ && sdvo_priv->is_hdmi) { ++ /* enable hdmi encoding mode if supported */ ++ intel_sdvo_set_encode(intel_encoder, SDVO_ENCODE_HDMI); ++ intel_sdvo_set_colorimetry(intel_encoder, ++ SDVO_COLORIMETRY_RGB256); ++ connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; ++ } ++ intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | ++ (1 << INTEL_ANALOG_CLONE_BIT); ++ ++ intel_sdvo_connector_create(encoder, connector); ++ ++ return true; ++} ++ ++static bool ++intel_sdvo_tv_init(struct intel_encoder *intel_encoder, int type) ++{ ++ struct drm_encoder *encoder = &intel_encoder->enc; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct drm_connector *connector; ++ struct intel_connector *intel_connector; ++ struct intel_sdvo_connector *sdvo_connector; ++ ++ if (!intel_sdvo_connector_alloc(&intel_connector)) ++ return false; ++ ++ connector = &intel_connector->base; ++ encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; ++ connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; ++ sdvo_connector = intel_connector->dev_priv; ++ ++ sdvo_priv->controlled_output |= type; ++ sdvo_connector->output_flag = type; ++ ++ sdvo_priv->is_tv = true; ++ intel_encoder->needs_tv_clock = true; ++ intel_encoder->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; ++ ++ intel_sdvo_connector_create(encoder, connector); ++ ++ intel_sdvo_tv_create_property(connector, type); ++ ++ intel_sdvo_create_enhance_property(connector); ++ ++ return true; ++} ++ ++static bool ++intel_sdvo_analog_init(struct intel_encoder *intel_encoder, int device) ++{ ++ struct drm_encoder *encoder = &intel_encoder->enc; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct drm_connector *connector; ++ struct intel_connector *intel_connector; ++ struct intel_sdvo_connector *sdvo_connector; ++ ++ if (!intel_sdvo_connector_alloc(&intel_connector)) ++ return false; ++ ++ connector = &intel_connector->base; ++ encoder->encoder_type = DRM_MODE_ENCODER_DAC; ++ connector->connector_type = DRM_MODE_CONNECTOR_VGA; ++ sdvo_connector = intel_connector->dev_priv; ++ ++ if (device == 0) { ++ sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB0; ++ sdvo_connector->output_flag = SDVO_OUTPUT_RGB0; ++ } else if (device == 1) { ++ sdvo_priv->controlled_output |= SDVO_OUTPUT_RGB1; ++ sdvo_connector->output_flag = SDVO_OUTPUT_RGB1; ++ } ++ ++ intel_encoder->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | ++ (1 << INTEL_ANALOG_CLONE_BIT); ++ ++ intel_sdvo_connector_create(encoder, connector); ++ return true; ++} ++ ++static bool ++intel_sdvo_lvds_init(struct intel_encoder *intel_encoder, int device) ++{ ++ struct drm_encoder *encoder = &intel_encoder->enc; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct drm_connector *connector; ++ struct intel_connector *intel_connector; ++ struct intel_sdvo_connector *sdvo_connector; ++ ++ if (!intel_sdvo_connector_alloc(&intel_connector)) ++ return false; ++ ++ connector = &intel_connector->base; ++ encoder->encoder_type = DRM_MODE_ENCODER_LVDS; ++ connector->connector_type = DRM_MODE_CONNECTOR_LVDS; ++ sdvo_connector = intel_connector->dev_priv; ++ ++ sdvo_priv->is_lvds = true; ++ ++ if (device == 0) { ++ sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS0; ++ sdvo_connector->output_flag = SDVO_OUTPUT_LVDS0; ++ } else if (device == 1) { ++ sdvo_priv->controlled_output |= SDVO_OUTPUT_LVDS1; ++ sdvo_connector->output_flag = SDVO_OUTPUT_LVDS1; ++ } ++ ++ intel_encoder->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | ++ (1 << INTEL_SDVO_LVDS_CLONE_BIT); ++ ++ intel_sdvo_connector_create(encoder, connector); ++ intel_sdvo_create_enhance_property(connector); ++ return true; ++} + + static bool +-intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags) ++intel_sdvo_output_setup(struct intel_encoder *intel_encoder, uint16_t flags) + { +- struct drm_connector *connector = &intel_output->base; +- struct drm_encoder *encoder = &intel_output->enc; +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; +- bool ret = true, registered = false; ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; + + sdvo_priv->is_tv = false; +- intel_output->needs_tv_clock = false; ++ intel_encoder->needs_tv_clock = false; + sdvo_priv->is_lvds = false; + +- if (device_is_registered(&connector->kdev)) { +- drm_sysfs_connector_remove(connector); +- registered = true; +- } ++ /* SDVO requires XXX1 function may not exist unless it has XXX0 function.*/ + +- if (flags & +- (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) { +- if (sdvo_priv->caps.output_flags & SDVO_OUTPUT_TMDS0) +- sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS0; +- else +- sdvo_priv->controlled_output = SDVO_OUTPUT_TMDS1; +- +- encoder->encoder_type = DRM_MODE_ENCODER_TMDS; +- connector->connector_type = DRM_MODE_CONNECTOR_DVID; +- +- if (intel_sdvo_get_supp_encode(intel_output, +- &sdvo_priv->encode) && +- intel_sdvo_get_digital_encoding_mode(intel_output) && +- sdvo_priv->is_hdmi) { +- /* enable hdmi encoding mode if supported */ +- intel_sdvo_set_encode(intel_output, SDVO_ENCODE_HDMI); +- intel_sdvo_set_colorimetry(intel_output, +- SDVO_COLORIMETRY_RGB256); +- connector->connector_type = DRM_MODE_CONNECTOR_HDMIA; +- intel_output->clone_mask = +- (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | +- (1 << INTEL_ANALOG_CLONE_BIT); +- } +- } else if ((flags & SDVO_OUTPUT_SVID0) && +- !dmi_check_system(intel_sdvo_bad_tv)) { +- +- sdvo_priv->controlled_output = SDVO_OUTPUT_SVID0; +- encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; +- connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; +- sdvo_priv->is_tv = true; +- intel_output->needs_tv_clock = true; +- intel_output->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; +- } else if (flags & SDVO_OUTPUT_RGB0) { +- +- sdvo_priv->controlled_output = SDVO_OUTPUT_RGB0; +- encoder->encoder_type = DRM_MODE_ENCODER_DAC; +- connector->connector_type = DRM_MODE_CONNECTOR_VGA; +- intel_output->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | +- (1 << INTEL_ANALOG_CLONE_BIT); +- } else if (flags & SDVO_OUTPUT_RGB1) { +- +- sdvo_priv->controlled_output = SDVO_OUTPUT_RGB1; +- encoder->encoder_type = DRM_MODE_ENCODER_DAC; +- connector->connector_type = DRM_MODE_CONNECTOR_VGA; +- intel_output->clone_mask = (1 << INTEL_SDVO_NON_TV_CLONE_BIT) | +- (1 << INTEL_ANALOG_CLONE_BIT); +- } else if (flags & SDVO_OUTPUT_CVBS0) { +- +- sdvo_priv->controlled_output = SDVO_OUTPUT_CVBS0; +- encoder->encoder_type = DRM_MODE_ENCODER_TVDAC; +- connector->connector_type = DRM_MODE_CONNECTOR_SVIDEO; +- sdvo_priv->is_tv = true; +- intel_output->needs_tv_clock = true; +- intel_output->clone_mask = 1 << INTEL_SDVO_TV_CLONE_BIT; +- } else if (flags & SDVO_OUTPUT_LVDS0) { +- +- sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS0; +- encoder->encoder_type = DRM_MODE_ENCODER_LVDS; +- connector->connector_type = DRM_MODE_CONNECTOR_LVDS; +- sdvo_priv->is_lvds = true; +- intel_output->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | +- (1 << INTEL_SDVO_LVDS_CLONE_BIT); +- } else if (flags & SDVO_OUTPUT_LVDS1) { +- +- sdvo_priv->controlled_output = SDVO_OUTPUT_LVDS1; +- encoder->encoder_type = DRM_MODE_ENCODER_LVDS; +- connector->connector_type = DRM_MODE_CONNECTOR_LVDS; +- sdvo_priv->is_lvds = true; +- intel_output->clone_mask = (1 << INTEL_ANALOG_CLONE_BIT) | +- (1 << INTEL_SDVO_LVDS_CLONE_BIT); +- } else { ++ if (flags & SDVO_OUTPUT_TMDS0) ++ if (!intel_sdvo_dvi_init(intel_encoder, 0)) ++ return false; ++ ++ if ((flags & SDVO_TMDS_MASK) == SDVO_TMDS_MASK) ++ if (!intel_sdvo_dvi_init(intel_encoder, 1)) ++ return false; ++ ++ /* TV has no XXX1 function block */ ++ if (flags & SDVO_OUTPUT_SVID0) ++ if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_SVID0)) ++ return false; ++ ++ if (flags & SDVO_OUTPUT_CVBS0) ++ if (!intel_sdvo_tv_init(intel_encoder, SDVO_OUTPUT_CVBS0)) ++ return false; ++ ++ if (flags & SDVO_OUTPUT_RGB0) ++ if (!intel_sdvo_analog_init(intel_encoder, 0)) ++ return false; ++ ++ if ((flags & SDVO_RGB_MASK) == SDVO_RGB_MASK) ++ if (!intel_sdvo_analog_init(intel_encoder, 1)) ++ return false; + ++ if (flags & SDVO_OUTPUT_LVDS0) ++ if (!intel_sdvo_lvds_init(intel_encoder, 0)) ++ return false; ++ ++ if ((flags & SDVO_LVDS_MASK) == SDVO_LVDS_MASK) ++ if (!intel_sdvo_lvds_init(intel_encoder, 1)) ++ return false; ++ ++ if ((flags & SDVO_OUTPUT_MASK) == 0) { + unsigned char bytes[2]; + + sdvo_priv->controlled_output = 0; +@@ -2399,32 +2415,29 @@ intel_sdvo_output_setup(struct intel_output *intel_output, uint16_t flags) + DRM_DEBUG_KMS("%s: Unknown SDVO output type (0x%02x%02x)\n", + SDVO_NAME(sdvo_priv), + bytes[0], bytes[1]); +- ret = false; ++ return false; + } +- intel_output->crtc_mask = (1 << 0) | (1 << 1); +- +- if (ret && registered) +- ret = drm_sysfs_connector_add(connector) == 0 ? true : false; +- +- +- return ret; ++ intel_encoder->crtc_mask = (1 << 0) | (1 << 1); + ++ return true; + } + +-static void intel_sdvo_tv_create_property(struct drm_connector *connector) ++static void intel_sdvo_tv_create_property(struct drm_connector *connector, int type) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; + struct intel_sdvo_tv_format format; + uint32_t format_map, i; + uint8_t status; + +- intel_sdvo_set_target_output(intel_output, +- sdvo_priv->controlled_output); ++ intel_sdvo_set_target_output(intel_encoder, type); + +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_SUPPORTED_TV_FORMATS, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &format, sizeof(format)); + if (status != SDVO_CMD_STATUS_SUCCESS) + return; +@@ -2435,43 +2448,45 @@ static void intel_sdvo_tv_create_property(struct drm_connector *connector) + if (format_map == 0) + return; + +- sdvo_priv->format_supported_num = 0; ++ sdvo_connector->format_supported_num = 0; + for (i = 0 ; i < TV_FORMAT_NUM; i++) + if (format_map & (1 << i)) { +- sdvo_priv->tv_format_supported +- [sdvo_priv->format_supported_num++] = ++ sdvo_connector->tv_format_supported ++ [sdvo_connector->format_supported_num++] = + tv_format_names[i]; + } + + +- sdvo_priv->tv_format_property = ++ sdvo_connector->tv_format_property = + drm_property_create( + connector->dev, DRM_MODE_PROP_ENUM, +- "mode", sdvo_priv->format_supported_num); ++ "mode", sdvo_connector->format_supported_num); + +- for (i = 0; i < sdvo_priv->format_supported_num; i++) ++ for (i = 0; i < sdvo_connector->format_supported_num; i++) + drm_property_add_enum( +- sdvo_priv->tv_format_property, i, +- i, sdvo_priv->tv_format_supported[i]); ++ sdvo_connector->tv_format_property, i, ++ i, sdvo_connector->tv_format_supported[i]); + +- sdvo_priv->tv_format_name = sdvo_priv->tv_format_supported[0]; ++ sdvo_priv->tv_format_name = sdvo_connector->tv_format_supported[0]; + drm_connector_attach_property( +- connector, sdvo_priv->tv_format_property, 0); ++ connector, sdvo_connector->tv_format_property, 0); + + } + + static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_sdvo_priv *sdvo_priv = intel_output->dev_priv; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_priv = intel_connector->dev_priv; + struct intel_sdvo_enhancements_reply sdvo_data; + struct drm_device *dev = connector->dev; + uint8_t status; + uint16_t response, data_value[2]; + +- intel_sdvo_write_cmd(intel_output, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, ++ intel_sdvo_write_cmd(intel_encoder, SDVO_CMD_GET_SUPPORTED_ENHANCEMENTS, + NULL, 0); +- status = intel_sdvo_read_response(intel_output, &sdvo_data, ++ status = intel_sdvo_read_response(intel_encoder, &sdvo_data, + sizeof(sdvo_data)); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS(" incorrect response is returned\n"); +@@ -2482,23 +2497,23 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + DRM_DEBUG_KMS("No enhancement is supported\n"); + return; + } +- if (sdvo_priv->is_tv) { ++ if (IS_TV(sdvo_priv)) { + /* when horizontal overscan is supported, Add the left/right + * property + */ + if (sdvo_data.overscan_h) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_OVERSCAN_H, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO max " + "h_overscan\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_OVERSCAN_H, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO h_overscan\n"); +@@ -2528,18 +2543,18 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + data_value[0], data_value[1], response); + } + if (sdvo_data.overscan_v) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_OVERSCAN_V, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO max " + "v_overscan\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_OVERSCAN_V, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO v_overscan\n"); +@@ -2569,17 +2584,17 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + data_value[0], data_value[1], response); + } + if (sdvo_data.position_h) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_POSITION_H, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO Max h_pos\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_POSITION_H, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO get h_postion\n"); +@@ -2600,17 +2615,17 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + data_value[0], data_value[1], response); + } + if (sdvo_data.position_v) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_POSITION_V, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO Max v_pos\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_POSITION_V, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO get v_postion\n"); +@@ -2630,20 +2645,18 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + "default %d, current %d\n", + data_value[0], data_value[1], response); + } +- } +- if (sdvo_priv->is_tv) { + if (sdvo_data.saturation) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_SATURATION, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO Max sat\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_SATURATION, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO get sat\n"); +@@ -2665,17 +2678,17 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + data_value[0], data_value[1], response); + } + if (sdvo_data.contrast) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_CONTRAST, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO Max contrast\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_CONTRAST, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO get contrast\n"); +@@ -2696,17 +2709,17 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + data_value[0], data_value[1], response); + } + if (sdvo_data.hue) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_HUE, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO Max hue\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_HUE, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO get hue\n"); +@@ -2727,19 +2740,19 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + data_value[0], data_value[1], response); + } + } +- if (sdvo_priv->is_tv || sdvo_priv->is_lvds) { ++ if (IS_TV(sdvo_priv) || IS_LVDS(sdvo_priv)) { + if (sdvo_data.brightness) { +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_MAX_BRIGHTNESS, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &data_value, 4); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO Max bright\n"); + return; + } +- intel_sdvo_write_cmd(intel_output, ++ intel_sdvo_write_cmd(intel_encoder, + SDVO_CMD_GET_BRIGHTNESS, NULL, 0); +- status = intel_sdvo_read_response(intel_output, ++ status = intel_sdvo_read_response(intel_encoder, + &response, 2); + if (status != SDVO_CMD_STATUS_SUCCESS) { + DRM_DEBUG_KMS("Incorrect SDVO get brigh\n"); +@@ -2764,109 +2777,98 @@ static void intel_sdvo_create_enhance_property(struct drm_connector *connector) + return; + } + +-bool intel_sdvo_init(struct drm_device *dev, int output_device) ++bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) + { + struct drm_i915_private *dev_priv = dev->dev_private; +- struct drm_connector *connector; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; + struct intel_sdvo_priv *sdvo_priv; +- + u8 ch[0x40]; + int i; ++ u32 i2c_reg, ddc_reg, analog_ddc_reg; + +- intel_output = kcalloc(sizeof(struct intel_output)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); +- if (!intel_output) { ++ intel_encoder = kcalloc(sizeof(struct intel_encoder)+sizeof(struct intel_sdvo_priv), 1, GFP_KERNEL); ++ if (!intel_encoder) { + return false; + } + +- sdvo_priv = (struct intel_sdvo_priv *)(intel_output + 1); +- sdvo_priv->output_device = output_device; ++ sdvo_priv = (struct intel_sdvo_priv *)(intel_encoder + 1); ++ sdvo_priv->sdvo_reg = sdvo_reg; + +- intel_output->dev_priv = sdvo_priv; +- intel_output->type = INTEL_OUTPUT_SDVO; ++ intel_encoder->dev_priv = sdvo_priv; ++ intel_encoder->type = INTEL_OUTPUT_SDVO; ++ ++ if (HAS_PCH_SPLIT(dev)) { ++ i2c_reg = PCH_GPIOE; ++ ddc_reg = PCH_GPIOE; ++ analog_ddc_reg = PCH_GPIOA; ++ } else { ++ i2c_reg = GPIOE; ++ ddc_reg = GPIOE; ++ analog_ddc_reg = GPIOA; ++ } + + /* setup the DDC bus. */ +- if (output_device == SDVOB) +- intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOB"); ++ if (IS_SDVOB(sdvo_reg)) ++ intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOB"); + else +- intel_output->i2c_bus = intel_i2c_create(dev, GPIOE, "SDVOCTRL_E for SDVOC"); ++ intel_encoder->i2c_bus = intel_i2c_create(dev, i2c_reg, "SDVOCTRL_E for SDVOC"); + +- if (!intel_output->i2c_bus) ++ if (!intel_encoder->i2c_bus) + goto err_inteloutput; + +- sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, output_device); ++ sdvo_priv->slave_addr = intel_sdvo_get_slave_addr(dev, sdvo_reg); + + /* Save the bit-banging i2c functionality for use by the DDC wrapper */ +- intel_sdvo_i2c_bit_algo.functionality = intel_output->i2c_bus->algo->functionality; ++ intel_sdvo_i2c_bit_algo.functionality = intel_encoder->i2c_bus->algo->functionality; + + /* Read the regs to test if we can talk to the device */ + for (i = 0; i < 0x40; i++) { +- if (!intel_sdvo_read_byte(intel_output, i, &ch[i])) { ++ if (!intel_sdvo_read_byte(intel_encoder, i, &ch[i])) { + DRM_DEBUG_KMS("No SDVO device found on SDVO%c\n", +- output_device == SDVOB ? 'B' : 'C'); ++ IS_SDVOB(sdvo_reg) ? 'B' : 'C'); + goto err_i2c; + } + } + + /* setup the DDC bus. */ +- if (output_device == SDVOB) { +- intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOB DDC BUS"); +- sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA, ++ if (IS_SDVOB(sdvo_reg)) { ++ intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOB DDC BUS"); ++ sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, + "SDVOB/VGA DDC BUS"); + dev_priv->hotplug_supported_mask |= SDVOB_HOTPLUG_INT_STATUS; + } else { +- intel_output->ddc_bus = intel_i2c_create(dev, GPIOE, "SDVOC DDC BUS"); +- sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, GPIOA, ++ intel_encoder->ddc_bus = intel_i2c_create(dev, ddc_reg, "SDVOC DDC BUS"); ++ sdvo_priv->analog_ddc_bus = intel_i2c_create(dev, analog_ddc_reg, + "SDVOC/VGA DDC BUS"); + dev_priv->hotplug_supported_mask |= SDVOC_HOTPLUG_INT_STATUS; + } + +- if (intel_output->ddc_bus == NULL) ++ if (intel_encoder->ddc_bus == NULL) + goto err_i2c; + + /* Wrap with our custom algo which switches to DDC mode */ +- intel_output->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; ++ intel_encoder->ddc_bus->algo = &intel_sdvo_i2c_bit_algo; ++ ++ /* encoder type will be decided later */ ++ drm_encoder_init(dev, &intel_encoder->enc, &intel_sdvo_enc_funcs, 0); ++ drm_encoder_helper_add(&intel_encoder->enc, &intel_sdvo_helper_funcs); + + /* In default case sdvo lvds is false */ +- intel_sdvo_get_capabilities(intel_output, &sdvo_priv->caps); ++ intel_sdvo_get_capabilities(intel_encoder, &sdvo_priv->caps); + +- if (intel_sdvo_output_setup(intel_output, ++ if (intel_sdvo_output_setup(intel_encoder, + sdvo_priv->caps.output_flags) != true) { + DRM_DEBUG_KMS("SDVO output failed to setup on SDVO%c\n", +- output_device == SDVOB ? 'B' : 'C'); ++ IS_SDVOB(sdvo_reg) ? 'B' : 'C'); + goto err_i2c; + } + +- +- connector = &intel_output->base; +- drm_connector_init(dev, connector, &intel_sdvo_connector_funcs, +- connector->connector_type); +- +- drm_connector_helper_add(connector, &intel_sdvo_connector_helper_funcs); +- connector->interlace_allowed = 0; +- connector->doublescan_allowed = 0; +- connector->display_info.subpixel_order = SubPixelHorizontalRGB; +- +- drm_encoder_init(dev, &intel_output->enc, +- &intel_sdvo_enc_funcs, intel_output->enc.encoder_type); +- +- drm_encoder_helper_add(&intel_output->enc, &intel_sdvo_helper_funcs); +- +- drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc); +- if (sdvo_priv->is_tv) +- intel_sdvo_tv_create_property(connector); +- +- if (sdvo_priv->is_tv || sdvo_priv->is_lvds) +- intel_sdvo_create_enhance_property(connector); +- +- drm_sysfs_connector_add(connector); +- + intel_sdvo_select_ddc_bus(sdvo_priv); + + /* Set the input timing to the screen. Assume always input 0. */ +- intel_sdvo_set_target_input(intel_output, true, false); ++ intel_sdvo_set_target_input(intel_encoder, true, false); + +- intel_sdvo_get_input_pixel_clock_range(intel_output, ++ intel_sdvo_get_input_pixel_clock_range(intel_encoder, + &sdvo_priv->pixel_clock_min, + &sdvo_priv->pixel_clock_max); + +@@ -2893,12 +2895,12 @@ bool intel_sdvo_init(struct drm_device *dev, int output_device) + err_i2c: + if (sdvo_priv->analog_ddc_bus != NULL) + intel_i2c_destroy(sdvo_priv->analog_ddc_bus); +- if (intel_output->ddc_bus != NULL) +- intel_i2c_destroy(intel_output->ddc_bus); +- if (intel_output->i2c_bus != NULL) +- intel_i2c_destroy(intel_output->i2c_bus); ++ if (intel_encoder->ddc_bus != NULL) ++ intel_i2c_destroy(intel_encoder->ddc_bus); ++ if (intel_encoder->i2c_bus != NULL) ++ intel_i2c_destroy(intel_encoder->i2c_bus); + err_inteloutput: +- kfree(intel_output); ++ kfree(intel_encoder); + + return false; + } +diff --git a/drivers/gpu/drm/i915/intel_tv.c b/drivers/gpu/drm/i915/intel_tv.c +--- a/drivers/gpu/drm/i915/intel_tv.c ++++ b/drivers/gpu/drm/i915/intel_tv.c +@@ -916,143 +916,6 @@ intel_tv_dpms(struct drm_encoder *encoder, int mode) + } + } + +-static void +-intel_tv_save(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; +- int i; +- +- tv_priv->save_TV_H_CTL_1 = I915_READ(TV_H_CTL_1); +- tv_priv->save_TV_H_CTL_2 = I915_READ(TV_H_CTL_2); +- tv_priv->save_TV_H_CTL_3 = I915_READ(TV_H_CTL_3); +- tv_priv->save_TV_V_CTL_1 = I915_READ(TV_V_CTL_1); +- tv_priv->save_TV_V_CTL_2 = I915_READ(TV_V_CTL_2); +- tv_priv->save_TV_V_CTL_3 = I915_READ(TV_V_CTL_3); +- tv_priv->save_TV_V_CTL_4 = I915_READ(TV_V_CTL_4); +- tv_priv->save_TV_V_CTL_5 = I915_READ(TV_V_CTL_5); +- tv_priv->save_TV_V_CTL_6 = I915_READ(TV_V_CTL_6); +- tv_priv->save_TV_V_CTL_7 = I915_READ(TV_V_CTL_7); +- tv_priv->save_TV_SC_CTL_1 = I915_READ(TV_SC_CTL_1); +- tv_priv->save_TV_SC_CTL_2 = I915_READ(TV_SC_CTL_2); +- tv_priv->save_TV_SC_CTL_3 = I915_READ(TV_SC_CTL_3); +- +- tv_priv->save_TV_CSC_Y = I915_READ(TV_CSC_Y); +- tv_priv->save_TV_CSC_Y2 = I915_READ(TV_CSC_Y2); +- tv_priv->save_TV_CSC_U = I915_READ(TV_CSC_U); +- tv_priv->save_TV_CSC_U2 = I915_READ(TV_CSC_U2); +- tv_priv->save_TV_CSC_V = I915_READ(TV_CSC_V); +- tv_priv->save_TV_CSC_V2 = I915_READ(TV_CSC_V2); +- tv_priv->save_TV_CLR_KNOBS = I915_READ(TV_CLR_KNOBS); +- tv_priv->save_TV_CLR_LEVEL = I915_READ(TV_CLR_LEVEL); +- tv_priv->save_TV_WIN_POS = I915_READ(TV_WIN_POS); +- tv_priv->save_TV_WIN_SIZE = I915_READ(TV_WIN_SIZE); +- tv_priv->save_TV_FILTER_CTL_1 = I915_READ(TV_FILTER_CTL_1); +- tv_priv->save_TV_FILTER_CTL_2 = I915_READ(TV_FILTER_CTL_2); +- tv_priv->save_TV_FILTER_CTL_3 = I915_READ(TV_FILTER_CTL_3); +- +- for (i = 0; i < 60; i++) +- tv_priv->save_TV_H_LUMA[i] = I915_READ(TV_H_LUMA_0 + (i <<2)); +- for (i = 0; i < 60; i++) +- tv_priv->save_TV_H_CHROMA[i] = I915_READ(TV_H_CHROMA_0 + (i <<2)); +- for (i = 0; i < 43; i++) +- tv_priv->save_TV_V_LUMA[i] = I915_READ(TV_V_LUMA_0 + (i <<2)); +- for (i = 0; i < 43; i++) +- tv_priv->save_TV_V_CHROMA[i] = I915_READ(TV_V_CHROMA_0 + (i <<2)); +- +- tv_priv->save_TV_DAC = I915_READ(TV_DAC); +- tv_priv->save_TV_CTL = I915_READ(TV_CTL); +-} +- +-static void +-intel_tv_restore(struct drm_connector *connector) +-{ +- struct drm_device *dev = connector->dev; +- struct drm_i915_private *dev_priv = dev->dev_private; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; +- struct drm_crtc *crtc = connector->encoder->crtc; +- struct intel_crtc *intel_crtc; +- int i; +- +- /* FIXME: No CRTC? */ +- if (!crtc) +- return; +- +- intel_crtc = to_intel_crtc(crtc); +- I915_WRITE(TV_H_CTL_1, tv_priv->save_TV_H_CTL_1); +- I915_WRITE(TV_H_CTL_2, tv_priv->save_TV_H_CTL_2); +- I915_WRITE(TV_H_CTL_3, tv_priv->save_TV_H_CTL_3); +- I915_WRITE(TV_V_CTL_1, tv_priv->save_TV_V_CTL_1); +- I915_WRITE(TV_V_CTL_2, tv_priv->save_TV_V_CTL_2); +- I915_WRITE(TV_V_CTL_3, tv_priv->save_TV_V_CTL_3); +- I915_WRITE(TV_V_CTL_4, tv_priv->save_TV_V_CTL_4); +- I915_WRITE(TV_V_CTL_5, tv_priv->save_TV_V_CTL_5); +- I915_WRITE(TV_V_CTL_6, tv_priv->save_TV_V_CTL_6); +- I915_WRITE(TV_V_CTL_7, tv_priv->save_TV_V_CTL_7); +- I915_WRITE(TV_SC_CTL_1, tv_priv->save_TV_SC_CTL_1); +- I915_WRITE(TV_SC_CTL_2, tv_priv->save_TV_SC_CTL_2); +- I915_WRITE(TV_SC_CTL_3, tv_priv->save_TV_SC_CTL_3); +- +- I915_WRITE(TV_CSC_Y, tv_priv->save_TV_CSC_Y); +- I915_WRITE(TV_CSC_Y2, tv_priv->save_TV_CSC_Y2); +- I915_WRITE(TV_CSC_U, tv_priv->save_TV_CSC_U); +- I915_WRITE(TV_CSC_U2, tv_priv->save_TV_CSC_U2); +- I915_WRITE(TV_CSC_V, tv_priv->save_TV_CSC_V); +- I915_WRITE(TV_CSC_V2, tv_priv->save_TV_CSC_V2); +- I915_WRITE(TV_CLR_KNOBS, tv_priv->save_TV_CLR_KNOBS); +- I915_WRITE(TV_CLR_LEVEL, tv_priv->save_TV_CLR_LEVEL); +- +- { +- int pipeconf_reg = (intel_crtc->pipe == 0) ? +- PIPEACONF : PIPEBCONF; +- int dspcntr_reg = (intel_crtc->plane == 0) ? +- DSPACNTR : DSPBCNTR; +- int pipeconf = I915_READ(pipeconf_reg); +- int dspcntr = I915_READ(dspcntr_reg); +- int dspbase_reg = (intel_crtc->plane == 0) ? +- DSPAADDR : DSPBADDR; +- /* Pipe must be off here */ +- I915_WRITE(dspcntr_reg, dspcntr & ~DISPLAY_PLANE_ENABLE); +- /* Flush the plane changes */ +- I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); +- +- if (!IS_I9XX(dev)) { +- /* Wait for vblank for the disable to take effect */ +- intel_wait_for_vblank(dev); +- } +- +- I915_WRITE(pipeconf_reg, pipeconf & ~PIPEACONF_ENABLE); +- /* Wait for vblank for the disable to take effect. */ +- intel_wait_for_vblank(dev); +- +- /* Filter ctl must be set before TV_WIN_SIZE */ +- I915_WRITE(TV_FILTER_CTL_1, tv_priv->save_TV_FILTER_CTL_1); +- I915_WRITE(TV_FILTER_CTL_2, tv_priv->save_TV_FILTER_CTL_2); +- I915_WRITE(TV_FILTER_CTL_3, tv_priv->save_TV_FILTER_CTL_3); +- I915_WRITE(TV_WIN_POS, tv_priv->save_TV_WIN_POS); +- I915_WRITE(TV_WIN_SIZE, tv_priv->save_TV_WIN_SIZE); +- I915_WRITE(pipeconf_reg, pipeconf); +- I915_WRITE(dspcntr_reg, dspcntr); +- /* Flush the plane changes */ +- I915_WRITE(dspbase_reg, I915_READ(dspbase_reg)); +- } +- +- for (i = 0; i < 60; i++) +- I915_WRITE(TV_H_LUMA_0 + (i <<2), tv_priv->save_TV_H_LUMA[i]); +- for (i = 0; i < 60; i++) +- I915_WRITE(TV_H_CHROMA_0 + (i <<2), tv_priv->save_TV_H_CHROMA[i]); +- for (i = 0; i < 43; i++) +- I915_WRITE(TV_V_LUMA_0 + (i <<2), tv_priv->save_TV_V_LUMA[i]); +- for (i = 0; i < 43; i++) +- I915_WRITE(TV_V_CHROMA_0 + (i <<2), tv_priv->save_TV_V_CHROMA[i]); +- +- I915_WRITE(TV_DAC, tv_priv->save_TV_DAC); +- I915_WRITE(TV_CTL, tv_priv->save_TV_CTL); +-} +- + static const struct tv_mode * + intel_tv_mode_lookup (char *tv_format) + { +@@ -1068,9 +931,9 @@ intel_tv_mode_lookup (char *tv_format) + } + + static const struct tv_mode * +-intel_tv_mode_find (struct intel_output *intel_output) ++intel_tv_mode_find (struct intel_encoder *intel_encoder) + { +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; ++ struct intel_tv_priv *tv_priv = intel_encoder->dev_priv; + + return intel_tv_mode_lookup(tv_priv->tv_format); + } +@@ -1078,8 +941,9 @@ intel_tv_mode_find (struct intel_output *intel_output) + static enum drm_mode_status + intel_tv_mode_valid(struct drm_connector *connector, struct drm_display_mode *mode) + { +- struct intel_output *intel_output = to_intel_output(connector); +- const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ const struct tv_mode *tv_mode = intel_tv_mode_find(intel_encoder); + + /* Ensure TV refresh is close to desired refresh */ + if (tv_mode && abs(tv_mode->refresh - drm_mode_vrefresh(mode) * 1000) +@@ -1095,8 +959,8 @@ intel_tv_mode_fixup(struct drm_encoder *encoder, struct drm_display_mode *mode, + { + struct drm_device *dev = encoder->dev; + struct drm_mode_config *drm_config = &dev->mode_config; +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- const struct tv_mode *tv_mode = intel_tv_mode_find (intel_output); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ const struct tv_mode *tv_mode = intel_tv_mode_find (intel_encoder); + struct drm_encoder *other_encoder; + + if (!tv_mode) +@@ -1121,9 +985,9 @@ intel_tv_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_crtc *crtc = encoder->crtc; + struct intel_crtc *intel_crtc = to_intel_crtc(crtc); +- struct intel_output *intel_output = enc_to_intel_output(encoder); +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; +- const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_tv_priv *tv_priv = intel_encoder->dev_priv; ++ const struct tv_mode *tv_mode = intel_tv_mode_find(intel_encoder); + u32 tv_ctl; + u32 hctl1, hctl2, hctl3; + u32 vctl1, vctl2, vctl3, vctl4, vctl5, vctl6, vctl7; +@@ -1360,9 +1224,9 @@ static const struct drm_display_mode reported_modes[] = { + * \return false if TV is disconnected. + */ + static int +-intel_tv_detect_type (struct drm_crtc *crtc, struct intel_output *intel_output) ++intel_tv_detect_type (struct drm_crtc *crtc, struct intel_encoder *intel_encoder) + { +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = &intel_encoder->enc; + struct drm_device *dev = encoder->dev; + struct drm_i915_private *dev_priv = dev->dev_private; + unsigned long irqflags; +@@ -1441,9 +1305,10 @@ intel_tv_detect_type (struct drm_crtc *crtc, struct intel_output *intel_output) + */ + static void intel_tv_find_better_format(struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; +- const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_tv_priv *tv_priv = intel_encoder->dev_priv; ++ const struct tv_mode *tv_mode = intel_tv_mode_find(intel_encoder); + int i; + + if ((tv_priv->type == DRM_MODE_CONNECTOR_Component) == +@@ -1475,9 +1340,9 @@ intel_tv_detect(struct drm_connector *connector) + { + struct drm_crtc *crtc; + struct drm_display_mode mode; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_tv_priv *tv_priv = intel_encoder->dev_priv; + int dpms_mode; + int type = tv_priv->type; + +@@ -1485,12 +1350,14 @@ intel_tv_detect(struct drm_connector *connector) + drm_mode_set_crtcinfo(&mode, CRTC_INTERLACE_HALVE_V); + + if (encoder->crtc && encoder->crtc->enabled) { +- type = intel_tv_detect_type(encoder->crtc, intel_output); ++ type = intel_tv_detect_type(encoder->crtc, intel_encoder); + } else { +- crtc = intel_get_load_detect_pipe(intel_output, &mode, &dpms_mode); ++ crtc = intel_get_load_detect_pipe(intel_encoder, connector, ++ &mode, &dpms_mode); + if (crtc) { +- type = intel_tv_detect_type(crtc, intel_output); +- intel_release_load_detect_pipe(intel_output, dpms_mode); ++ type = intel_tv_detect_type(crtc, intel_encoder); ++ intel_release_load_detect_pipe(intel_encoder, connector, ++ dpms_mode); + } else + type = -1; + } +@@ -1525,8 +1392,9 @@ static void + intel_tv_chose_preferred_modes(struct drm_connector *connector, + struct drm_display_mode *mode_ptr) + { +- struct intel_output *intel_output = to_intel_output(connector); +- const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ const struct tv_mode *tv_mode = intel_tv_mode_find(intel_encoder); + + if (tv_mode->nbr_end < 480 && mode_ptr->vdisplay == 480) + mode_ptr->type |= DRM_MODE_TYPE_PREFERRED; +@@ -1550,8 +1418,9 @@ static int + intel_tv_get_modes(struct drm_connector *connector) + { + struct drm_display_mode *mode_ptr; +- struct intel_output *intel_output = to_intel_output(connector); +- const struct tv_mode *tv_mode = intel_tv_mode_find(intel_output); ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ const struct tv_mode *tv_mode = intel_tv_mode_find(intel_encoder); + int j, count = 0; + u64 tmp; + +@@ -1604,11 +1473,9 @@ intel_tv_get_modes(struct drm_connector *connector) + static void + intel_tv_destroy (struct drm_connector *connector) + { +- struct intel_output *intel_output = to_intel_output(connector); +- + drm_sysfs_connector_remove(connector); + drm_connector_cleanup(connector); +- kfree(intel_output); ++ kfree(connector); + } + + +@@ -1617,9 +1484,9 @@ intel_tv_set_property(struct drm_connector *connector, struct drm_property *prop + uint64_t val) + { + struct drm_device *dev = connector->dev; +- struct intel_output *intel_output = to_intel_output(connector); +- struct intel_tv_priv *tv_priv = intel_output->dev_priv; +- struct drm_encoder *encoder = &intel_output->enc; ++ struct drm_encoder *encoder = intel_attached_encoder(connector); ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ struct intel_tv_priv *tv_priv = intel_encoder->dev_priv; + struct drm_crtc *crtc = encoder->crtc; + int ret = 0; + bool changed = false; +@@ -1676,8 +1543,6 @@ static const struct drm_encoder_helper_funcs intel_tv_helper_funcs = { + + static const struct drm_connector_funcs intel_tv_connector_funcs = { + .dpms = drm_helper_connector_dpms, +- .save = intel_tv_save, +- .restore = intel_tv_restore, + .detect = intel_tv_detect, + .destroy = intel_tv_destroy, + .set_property = intel_tv_set_property, +@@ -1687,12 +1552,15 @@ static const struct drm_connector_funcs intel_tv_connector_funcs = { + static const struct drm_connector_helper_funcs intel_tv_connector_helper_funcs = { + .mode_valid = intel_tv_mode_valid, + .get_modes = intel_tv_get_modes, +- .best_encoder = intel_best_encoder, ++ .best_encoder = intel_attached_encoder, + }; + + static void intel_tv_enc_destroy(struct drm_encoder *encoder) + { ++ struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); ++ + drm_encoder_cleanup(encoder); ++ kfree(intel_encoder); + } + + static const struct drm_encoder_funcs intel_tv_enc_funcs = { +@@ -1740,7 +1608,8 @@ intel_tv_init(struct drm_device *dev) + { + struct drm_i915_private *dev_priv = dev->dev_private; + struct drm_connector *connector; +- struct intel_output *intel_output; ++ struct intel_encoder *intel_encoder; ++ struct intel_connector *intel_connector; + struct intel_tv_priv *tv_priv; + u32 tv_dac_on, tv_dac_off, save_tv_dac; + char **tv_format_names; +@@ -1780,28 +1649,34 @@ intel_tv_init(struct drm_device *dev) + (tv_dac_off & TVDAC_STATE_CHG_EN) != 0) + return; + +- intel_output = kzalloc(sizeof(struct intel_output) + ++ intel_encoder = kzalloc(sizeof(struct intel_encoder) + + sizeof(struct intel_tv_priv), GFP_KERNEL); +- if (!intel_output) { ++ if (!intel_encoder) { ++ return; ++ } ++ ++ intel_connector = kzalloc(sizeof(struct intel_connector), GFP_KERNEL); ++ if (!intel_connector) { ++ kfree(intel_encoder); + return; + } + +- connector = &intel_output->base; ++ connector = &intel_connector->base; + + drm_connector_init(dev, connector, &intel_tv_connector_funcs, + DRM_MODE_CONNECTOR_SVIDEO); + +- drm_encoder_init(dev, &intel_output->enc, &intel_tv_enc_funcs, ++ drm_encoder_init(dev, &intel_encoder->enc, &intel_tv_enc_funcs, + DRM_MODE_ENCODER_TVDAC); + +- drm_mode_connector_attach_encoder(&intel_output->base, &intel_output->enc); +- tv_priv = (struct intel_tv_priv *)(intel_output + 1); +- intel_output->type = INTEL_OUTPUT_TVOUT; +- intel_output->crtc_mask = (1 << 0) | (1 << 1); +- intel_output->clone_mask = (1 << INTEL_TV_CLONE_BIT); +- intel_output->enc.possible_crtcs = ((1 << 0) | (1 << 1)); +- intel_output->enc.possible_clones = (1 << INTEL_OUTPUT_TVOUT); +- intel_output->dev_priv = tv_priv; ++ drm_mode_connector_attach_encoder(&intel_connector->base, &intel_encoder->enc); ++ tv_priv = (struct intel_tv_priv *)(intel_encoder + 1); ++ intel_encoder->type = INTEL_OUTPUT_TVOUT; ++ intel_encoder->crtc_mask = (1 << 0) | (1 << 1); ++ intel_encoder->clone_mask = (1 << INTEL_TV_CLONE_BIT); ++ intel_encoder->enc.possible_crtcs = ((1 << 0) | (1 << 1)); ++ intel_encoder->enc.possible_clones = (1 << INTEL_OUTPUT_TVOUT); ++ intel_encoder->dev_priv = tv_priv; + tv_priv->type = DRM_MODE_CONNECTOR_Unknown; + + /* BIOS margin values */ +@@ -1812,7 +1687,7 @@ intel_tv_init(struct drm_device *dev) + + tv_priv->tv_format = kstrdup(tv_modes[initial_mode].name, GFP_KERNEL); + +- drm_encoder_helper_add(&intel_output->enc, &intel_tv_helper_funcs); ++ drm_encoder_helper_add(&intel_encoder->enc, &intel_tv_helper_funcs); + drm_connector_helper_add(connector, &intel_tv_connector_helper_funcs); + connector->interlace_allowed = false; + connector->doublescan_allowed = false; +diff --git a/include/drm/drm_pciids.h b/include/drm/drm_pciids.h +--- a/include/drm/drm_pciids.h ++++ b/include/drm/drm_pciids.h +@@ -558,4 +558,5 @@ + {0x8086, 0x35e8, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ + {0x8086, 0x0042, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ + {0x8086, 0x0046, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ ++ {0x8086, 0x0102, PCI_ANY_ID, PCI_ANY_ID, PCI_CLASS_DISPLAY_VGA << 8, 0xffff00, 0}, \ + {0, 0, 0} diff --git a/drm-intel-sdvo-fix-2.patch b/drm-intel-sdvo-fix-2.patch new file mode 100644 index 000000000..8a27fa1a2 --- /dev/null +++ b/drm-intel-sdvo-fix-2.patch @@ -0,0 +1,107 @@ +From 4fd1c5ed73fc02d8bcabcb3a457c4c4efaef2099 Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Thu, 29 Apr 2010 14:05:18 -0400 +Subject: [PATCH] drm/i915: Be extra careful about A/D matching for multifunction SDVO + +If we're both RGB and TMDS capable, we'll have set up one connector for +each. When determining connectivity, require analog/digital state in +the EDID block to match analog/digital support in the connector. +Otherwise, both DVI and VGA will appear to be connected. + +Signed-off-by: Adam Jackson +--- + drivers/gpu/drm/i915/intel_sdvo.c | 45 +++++++++++++++++------------------- + 1 files changed, 21 insertions(+), 24 deletions(-) + +diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c +index f55c0d7..31ce975 100644 +--- a/drivers/gpu/drm/i915/intel_sdvo.c ++++ b/drivers/gpu/drm/i915/intel_sdvo.c +@@ -1503,16 +1503,17 @@ intel_analog_is_connected(struct drm_device *dev) + } + + enum drm_connector_status +-intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) ++intel_sdvo_hdmi_sink_detect(struct drm_connector *connector) + { + struct drm_encoder *encoder = intel_attached_encoder(connector); + struct intel_encoder *intel_encoder = enc_to_intel_encoder(encoder); + struct intel_sdvo_priv *sdvo_priv = intel_encoder->dev_priv; ++ struct intel_connector *intel_connector = to_intel_connector(connector); ++ struct intel_sdvo_connector *sdvo_connector = intel_connector->dev_priv; + enum drm_connector_status status = connector_status_connected; + struct edid *edid = NULL; + +- edid = drm_get_edid(connector, +- intel_encoder->ddc_bus); ++ edid = drm_get_edid(connector, intel_encoder->ddc_bus); + + /* This is only applied to SDVO cards with multiple outputs */ + if (edid == NULL && intel_sdvo_multifunc_encoder(intel_encoder)) { +@@ -1525,8 +1526,7 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) + */ + while(temp_ddc > 1) { + sdvo_priv->ddc_bus = temp_ddc; +- edid = drm_get_edid(connector, +- intel_encoder->ddc_bus); ++ edid = drm_get_edid(connector, intel_encoder->ddc_bus); + if (edid) { + /* + * When we can get the EDID, maybe it is the +@@ -1543,28 +1543,25 @@ intel_sdvo_hdmi_sink_detect(struct drm_connector *connector, u16 response) + /* when there is no edid and no monitor is connected with VGA + * port, try to use the CRT ddc to read the EDID for DVI-connector + */ +- if (edid == NULL && +- sdvo_priv->analog_ddc_bus && ++ if (edid == NULL && sdvo_priv->analog_ddc_bus && + !intel_analog_is_connected(connector->dev)) +- edid = drm_get_edid(connector, +- sdvo_priv->analog_ddc_bus); ++ edid = drm_get_edid(connector, sdvo_priv->analog_ddc_bus); ++ + if (edid != NULL) { +- /* Don't report the output as connected if it's a DVI-I +- * connector with a non-digital EDID coming out. +- */ +- if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) { +- if (edid->input & DRM_EDID_INPUT_DIGITAL) +- sdvo_priv->is_hdmi = +- drm_detect_hdmi_monitor(edid); +- else +- status = connector_status_disconnected; +- } ++ bool is_digital = !!(edid->input & DRM_EDID_INPUT_DIGITAL); ++ bool need_digital = !!(sdvo_connector->output_flag & SDVO_TMDS_MASK); + +- kfree(edid); +- connector->display_info.raw_edid = NULL; ++ /* DDC bus is shared, match EDID to connector type */ ++ if (is_digital && need_digital) ++ sdvo_priv->is_hdmi = drm_detect_hdmi_monitor(edid); ++ else if (is_digital != need_digital) ++ status = connector_status_disconnected; + +- } else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) ++ connector->display_info.raw_edid = NULL; ++ } else + status = connector_status_disconnected; ++ ++ kfree(edid); + + return status; + } +@@ -1600,8 +1597,8 @@ static enum drm_connector_status intel_sdvo_detect(struct drm_connector *connect + + if ((sdvo_connector->output_flag & response) == 0) + ret = connector_status_disconnected; +- else if (response & (SDVO_OUTPUT_TMDS0 | SDVO_OUTPUT_TMDS1)) +- ret = intel_sdvo_hdmi_sink_detect(connector, response); ++ else if (response & SDVO_TMDS_MASK) ++ ret = intel_sdvo_hdmi_sink_detect(connector); + else + ret = connector_status_connected; + +-- +1.7.0.1 + diff --git a/drm-intel-sdvo-fix.patch b/drm-intel-sdvo-fix.patch new file mode 100644 index 000000000..98b6a0002 --- /dev/null +++ b/drm-intel-sdvo-fix.patch @@ -0,0 +1,114 @@ +From ef59fcdd9d7fe818d36a0072c80770c0d1a3cc9c Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Fri, 23 Apr 2010 16:07:40 -0400 +Subject: [PATCH] drm/i915: Fix DDC bus selection for multifunction SDVO + +Multifunction SDVO cards stopped working after 14571b4, and would report +something that looked remarkably like an ADD2 SPD ROM instead of EDID. +This appears to be because DDC bus selection was utterly horked by that +commit; controlled_output was no longer always a single bit, so +intel_sdvo_select_ddc_bus would pick bus 0, which is (unsurprisingly) +the SPD ROM bus, not a DDC bus. + +So, instead of that, let's just use the DDC bus the child device table +tells us to use. I'm guessing at the bitmask and shifting from VBIOS +dumps, but it can't possibly be worse. + +cf. https://bugzilla.redhat.com/584229 + +Signed-off-by: Adam Jackson +--- + drivers/gpu/drm/i915/i915_drv.h | 1 + + drivers/gpu/drm/i915/intel_bios.c | 1 + + drivers/gpu/drm/i915/intel_sdvo.c | 41 ++++++++---------------------------- + 3 files changed, 11 insertions(+), 32 deletions(-) + +diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h +index a43a4f5..5d609a8 100644 +--- a/drivers/gpu/drm/i915/i915_drv.h ++++ b/drivers/gpu/drm/i915/i915_drv.h +@@ -135,6 +135,7 @@ struct sdvo_device_mapping { + u8 slave_addr; + u8 dvo_wiring; + u8 initialized; ++ u8 ddc_pin; + }; + + struct drm_i915_error_state { +diff --git a/drivers/gpu/drm/i915/intel_bios.c b/drivers/gpu/drm/i915/intel_bios.c +index f9ba452..4c748d8 100644 +--- a/drivers/gpu/drm/i915/intel_bios.c ++++ b/drivers/gpu/drm/i915/intel_bios.c +@@ -366,6 +366,7 @@ parse_sdvo_device_mapping(struct drm_i915_private *dev_priv, + p_mapping->dvo_port = p_child->dvo_port; + p_mapping->slave_addr = p_child->slave_addr; + p_mapping->dvo_wiring = p_child->dvo_wiring; ++ p_mapping->ddc_pin = p_child->ddc_pin; + p_mapping->initialized = 1; + } else { + DRM_DEBUG_KMS("Maybe one SDVO port is shared by " +diff --git a/drivers/gpu/drm/i915/intel_sdvo.c b/drivers/gpu/drm/i915/intel_sdvo.c +index df9f997..f55c0d7 100644 +--- a/drivers/gpu/drm/i915/intel_sdvo.c ++++ b/drivers/gpu/drm/i915/intel_sdvo.c +@@ -2053,40 +2053,17 @@ static const struct drm_encoder_funcs intel_sdvo_enc_funcs = { + * outputs, then LVDS outputs. + */ + static void +-intel_sdvo_select_ddc_bus(struct intel_sdvo_priv *dev_priv) ++intel_sdvo_select_ddc_bus(struct drm_i915_private *dev_priv, ++ struct intel_sdvo_priv *sdvo, u32 reg) + { +- uint16_t mask = 0; +- unsigned int num_bits; ++ struct sdvo_device_mapping *mapping; + +- /* Make a mask of outputs less than or equal to our own priority in the +- * list. +- */ +- switch (dev_priv->controlled_output) { +- case SDVO_OUTPUT_LVDS1: +- mask |= SDVO_OUTPUT_LVDS1; +- case SDVO_OUTPUT_LVDS0: +- mask |= SDVO_OUTPUT_LVDS0; +- case SDVO_OUTPUT_TMDS1: +- mask |= SDVO_OUTPUT_TMDS1; +- case SDVO_OUTPUT_TMDS0: +- mask |= SDVO_OUTPUT_TMDS0; +- case SDVO_OUTPUT_RGB1: +- mask |= SDVO_OUTPUT_RGB1; +- case SDVO_OUTPUT_RGB0: +- mask |= SDVO_OUTPUT_RGB0; +- break; +- } +- +- /* Count bits to find what number we are in the priority list. */ +- mask &= dev_priv->caps.output_flags; +- num_bits = hweight16(mask); +- if (num_bits > 3) { +- /* if more than 3 outputs, default to DDC bus 3 for now */ +- num_bits = 3; +- } ++ if (IS_SDVOB(reg)) ++ mapping = &(dev_priv->sdvo_mappings[0]); ++ else ++ mapping = &(dev_priv->sdvo_mappings[1]); + +- /* Corresponds to SDVO_CONTROL_BUS_DDCx */ +- dev_priv->ddc_bus = 1 << num_bits; ++ sdvo->ddc_bus = 1 << ((mapping->ddc_pin & 0xf0) >> 4); + } + + static bool +@@ -2863,7 +2840,7 @@ bool intel_sdvo_init(struct drm_device *dev, int sdvo_reg) + goto err_i2c; + } + +- intel_sdvo_select_ddc_bus(sdvo_priv); ++ intel_sdvo_select_ddc_bus(dev_priv, sdvo_priv, sdvo_reg); + + /* Set the input timing to the screen. Assume always input 0. */ + intel_sdvo_set_target_input(intel_encoder, true, false); +-- +1.7.0.1 + diff --git a/drm-nouveau-abi16.patch b/drm-nouveau-abi16.patch new file mode 100644 index 000000000..7e05f5556 --- /dev/null +++ b/drm-nouveau-abi16.patch @@ -0,0 +1,1342 @@ +From d550220dd73ffbd2ad4871dbd5b5f328c4e2227f Mon Sep 17 00:00:00 2001 +From: Ben Skeggs +Date: Thu, 11 Feb 2010 16:37:26 +1000 +Subject: [PATCH 3/4] drm-nouveau-abi16 + +drm/nv50: switch to indirect push buffer controls + +PFIFO on G80 and up has a new mode where the main ring buffer is simply a +ring of pointers to indirect buffers containing the actual command/data +packets. In order to be able to implement index buffers in the 3D driver +we need to be able to submit data-only push buffers right after the cmd +packet header, which is only possible using the new command submission +method. + +This commit doesn't make it possible to implement index buffers yet, some +userspace interface changes will be required, but it does allow for +testing/debugging of the hardware-side support in the meantime. + +Signed-off-by: Ben Skeggs + +drm/nouveau: remove PUSHBUF_CAL macro + +Signed-off-by: Ben Skeggs + +drm/nv50: make pushbuf dma object cover entire vm + +This allows us to submit push buffers from any memtype to the hardware. +We'll need this ability for VRAM index buffers at some point. + +Signed-off-by: Ben Skeggs + +drm/nouveau: new gem pushbuf interface, bump to 0.0.16 + +This commit breaks the userspace interface, and requires a new libdrm for +nouveau to operate again. + +The multiple GEM_PUSHBUF ioctls that were present in 0.0.15 for +compatibility purposes are now gone, and replaced with the new ioctl which +allows for multiple push buffers to be submitted (necessary for hw index +buffers in the nv50 3d driver) and relocations to be applied on any buffer. + +A number of other ioctls (CARD_INIT, GEM_PIN, GEM_UNPIN) that were needed +for userspace modesetting have also been removed. + +Signed-off-by: Ben Skeggs + +drm/nouveau: bump MAX_PUSH to 512 + +Signed-off-by: Ben Skeggs + +drm/nouveau: Unmap pushbuf BOs when we're done with them. + +If you're especially unlucky BOs would move around and their kmaps +would end up pointing to something else in GART, then ioctl_pushbuf() +would use the kmaps again corrupting textures or other pushbufs (the +most noticeable symptom was a PFIFO_DMA_PUSHER from time to time). + +Signed-off-by: Francisco Jerez +Signed-off-by: Ben Skeggs + +drm/nouveau: Don't reuse the same variable in a nested loop. + +Signed-off-by: Francisco Jerez +Signed-off-by: Ben Skeggs + +drm/nouveau: fix missing spin_unlock in failure path + +Found by sparse. + +Signed-off-by: Luca Barbieri +Signed-off-by: Francisco Jerez + +drm/nouveau: only kunmap buffers we mapped during validation + +Fixes suspend/resume regression introduced by 1723b75407...66b4b71229c2c. + +Signed-off-by: Ben Skeggs +--- + drivers/gpu/drm/nouveau/nouveau_channel.c | 26 +- + drivers/gpu/drm/nouveau/nouveau_debugfs.c | 11 + + drivers/gpu/drm/nouveau/nouveau_dma.c | 108 +++++++- + drivers/gpu/drm/nouveau/nouveau_dma.h | 21 +- + drivers/gpu/drm/nouveau/nouveau_drv.h | 26 +- + drivers/gpu/drm/nouveau/nouveau_gem.c | 490 ++++++++++------------------- + drivers/gpu/drm/nouveau/nouveau_state.c | 7 - + drivers/gpu/drm/nouveau/nv50_fifo.c | 8 +- + include/drm/nouveau_drm.h | 86 ++---- + 9 files changed, 365 insertions(+), 418 deletions(-) + +diff --git a/drivers/gpu/drm/nouveau/nouveau_channel.c b/drivers/gpu/drm/nouveau/nouveau_channel.c +index 2281f99..adac0f8 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_channel.c ++++ b/drivers/gpu/drm/nouveau/nouveau_channel.c +@@ -35,22 +35,27 @@ nouveau_channel_pushbuf_ctxdma_init(struct nouveau_channel *chan) + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_bo *pb = chan->pushbuf_bo; + struct nouveau_gpuobj *pushbuf = NULL; +- uint32_t start = pb->bo.mem.mm_node->start << PAGE_SHIFT; + int ret; + ++ if (dev_priv->card_type >= NV_50) { ++ ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY, 0, ++ dev_priv->vm_end, NV_DMA_ACCESS_RO, ++ NV_DMA_TARGET_AGP, &pushbuf); ++ chan->pushbuf_base = pb->bo.offset; ++ } else + if (pb->bo.mem.mem_type == TTM_PL_TT) { + ret = nouveau_gpuobj_gart_dma_new(chan, 0, + dev_priv->gart_info.aper_size, + NV_DMA_ACCESS_RO, &pushbuf, + NULL); +- chan->pushbuf_base = start; ++ chan->pushbuf_base = pb->bo.mem.mm_node->start << PAGE_SHIFT; + } else + if (dev_priv->card_type != NV_04) { + ret = nouveau_gpuobj_dma_new(chan, NV_CLASS_DMA_IN_MEMORY, 0, + dev_priv->fb_available_size, + NV_DMA_ACCESS_RO, + NV_DMA_TARGET_VIDMEM, &pushbuf); +- chan->pushbuf_base = start; ++ chan->pushbuf_base = pb->bo.mem.mm_node->start << PAGE_SHIFT; + } else { + /* NV04 cmdbuf hack, from original ddx.. not sure of it's + * exact reason for existing :) PCI access to cmdbuf in +@@ -61,7 +66,7 @@ nouveau_channel_pushbuf_ctxdma_init(struct nouveau_channel *chan) + dev_priv->fb_available_size, + NV_DMA_ACCESS_RO, + NV_DMA_TARGET_PCI, &pushbuf); +- chan->pushbuf_base = start; ++ chan->pushbuf_base = pb->bo.mem.mm_node->start << PAGE_SHIFT; + } + + ret = nouveau_gpuobj_ref_add(dev, chan, 0, pushbuf, &chan->pushbuf); +@@ -369,6 +374,14 @@ nouveau_ioctl_fifo_alloc(struct drm_device *dev, void *data, + return ret; + init->channel = chan->id; + ++ if (chan->dma.ib_max) ++ init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM | ++ NOUVEAU_GEM_DOMAIN_GART; ++ else if (chan->pushbuf_bo->bo.mem.mem_type == TTM_PL_VRAM) ++ init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_VRAM; ++ else ++ init->pushbuf_domains = NOUVEAU_GEM_DOMAIN_GART; ++ + init->subchan[0].handle = NvM2MF; + if (dev_priv->card_type < NV_50) + init->subchan[0].grclass = 0x0039; +@@ -408,7 +421,6 @@ nouveau_ioctl_fifo_free(struct drm_device *dev, void *data, + ***********************************/ + + struct drm_ioctl_desc nouveau_ioctls[] = { +- DRM_IOCTL_DEF(DRM_NOUVEAU_CARD_INIT, nouveau_ioctl_card_init, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_GETPARAM, nouveau_ioctl_getparam, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_SETPARAM, nouveau_ioctl_setparam, DRM_AUTH|DRM_MASTER|DRM_ROOT_ONLY), + DRM_IOCTL_DEF(DRM_NOUVEAU_CHANNEL_ALLOC, nouveau_ioctl_fifo_alloc, DRM_AUTH), +@@ -418,13 +430,9 @@ struct drm_ioctl_desc nouveau_ioctls[] = { + DRM_IOCTL_DEF(DRM_NOUVEAU_GPUOBJ_FREE, nouveau_ioctl_gpuobj_free, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_NEW, nouveau_gem_ioctl_new, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_PUSHBUF, nouveau_gem_ioctl_pushbuf, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_PUSHBUF_CALL, nouveau_gem_ioctl_pushbuf_call, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_PIN, nouveau_gem_ioctl_pin, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_UNPIN, nouveau_gem_ioctl_unpin, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_CPU_PREP, nouveau_gem_ioctl_cpu_prep, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_CPU_FINI, nouveau_gem_ioctl_cpu_fini, DRM_AUTH), + DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_INFO, nouveau_gem_ioctl_info, DRM_AUTH), +- DRM_IOCTL_DEF(DRM_NOUVEAU_GEM_PUSHBUF_CALL2, nouveau_gem_ioctl_pushbuf_call2, DRM_AUTH), + }; + + int nouveau_max_ioctl = DRM_ARRAY_SIZE(nouveau_ioctls); +diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c +--- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c ++++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c +@@ -47,12 +47,23 @@ nouveau_debugfs_channel_info(struct seq_file *m, void *data) + seq_printf(m, " cur: 0x%08x\n", chan->dma.cur << 2); + seq_printf(m, " put: 0x%08x\n", chan->dma.put << 2); + seq_printf(m, " free: 0x%08x\n", chan->dma.free << 2); ++ if (chan->dma.ib_max) { ++ seq_printf(m, " ib max: 0x%08x\n", chan->dma.ib_max); ++ seq_printf(m, " ib put: 0x%08x\n", chan->dma.ib_put); ++ seq_printf(m, " ib free: 0x%08x\n", chan->dma.ib_free); ++ } + + seq_printf(m, "gpu fifo state:\n"); + seq_printf(m, " get: 0x%08x\n", + nvchan_rd32(chan, chan->user_get)); + seq_printf(m, " put: 0x%08x\n", + nvchan_rd32(chan, chan->user_put)); ++ if (chan->dma.ib_max) { ++ seq_printf(m, " ib get: 0x%08x\n", ++ nvchan_rd32(chan, 0x88)); ++ seq_printf(m, " ib put: 0x%08x\n", ++ nvchan_rd32(chan, 0x8c)); ++ } + + seq_printf(m, "last fence : %d\n", chan->fence.sequence); + seq_printf(m, "last signalled: %d\n", chan->fence.sequence_ack); +diff --git a/drivers/gpu/drm/nouveau/nouveau_dma.c b/drivers/gpu/drm/nouveau/nouveau_dma.c +--- a/drivers/gpu/drm/nouveau/nouveau_dma.c ++++ b/drivers/gpu/drm/nouveau/nouveau_dma.c +@@ -32,7 +32,22 @@ + void + nouveau_dma_pre_init(struct nouveau_channel *chan) + { +- chan->dma.max = (chan->pushbuf_bo->bo.mem.size >> 2) - 2; ++ struct drm_nouveau_private *dev_priv = chan->dev->dev_private; ++ struct nouveau_bo *pushbuf = chan->pushbuf_bo; ++ ++ if (dev_priv->card_type == NV_50) { ++ const int ib_size = pushbuf->bo.mem.size / 2; ++ ++ chan->dma.ib_base = (pushbuf->bo.mem.size - ib_size) >> 2; ++ chan->dma.ib_max = (ib_size / 8) - 1; ++ chan->dma.ib_put = 0; ++ chan->dma.ib_free = chan->dma.ib_max - chan->dma.ib_put; ++ ++ chan->dma.max = (pushbuf->bo.mem.size - ib_size) >> 2; ++ } else { ++ chan->dma.max = (pushbuf->bo.mem.size >> 2) - 2; ++ } ++ + chan->dma.put = 0; + chan->dma.cur = chan->dma.put; + chan->dma.free = chan->dma.max - chan->dma.cur; +@@ -162,12 +177,101 @@ READ_GET(struct nouveau_channel *chan, uint32_t *prev_get, uint32_t *timeout) + return (val - chan->pushbuf_base) >> 2; + } + ++void ++nv50_dma_push(struct nouveau_channel *chan, struct nouveau_bo *bo, ++ int delta, int length) ++{ ++ struct nouveau_bo *pb = chan->pushbuf_bo; ++ uint64_t offset = bo->bo.offset + delta; ++ int ip = (chan->dma.ib_put * 2) + chan->dma.ib_base; ++ ++ BUG_ON(chan->dma.ib_free < 1); ++ nouveau_bo_wr32(pb, ip++, lower_32_bits(offset)); ++ nouveau_bo_wr32(pb, ip++, upper_32_bits(offset) | length << 8); ++ ++ chan->dma.ib_put = (chan->dma.ib_put + 1) & chan->dma.ib_max; ++ nvchan_wr32(chan, 0x8c, chan->dma.ib_put); ++ chan->dma.ib_free--; ++} ++ ++static int ++nv50_dma_push_wait(struct nouveau_channel *chan, int count) ++{ ++ uint32_t cnt = 0, prev_get = 0; ++ ++ while (chan->dma.ib_free < count) { ++ uint32_t get = nvchan_rd32(chan, 0x88); ++ if (get != prev_get) { ++ prev_get = get; ++ cnt = 0; ++ } ++ ++ if ((++cnt & 0xff) == 0) { ++ DRM_UDELAY(1); ++ if (cnt > 100000) ++ return -EBUSY; ++ } ++ ++ chan->dma.ib_free = get - chan->dma.ib_put; ++ if (chan->dma.ib_free <= 0) ++ chan->dma.ib_free += chan->dma.ib_max + 1; ++ } ++ ++ return 0; ++} ++ ++static int ++nv50_dma_wait(struct nouveau_channel *chan, int slots, int count) ++{ ++ uint32_t cnt = 0, prev_get = 0; ++ int ret; ++ ++ ret = nv50_dma_push_wait(chan, slots + 1); ++ if (unlikely(ret)) ++ return ret; ++ ++ while (chan->dma.free < count) { ++ int get = READ_GET(chan, &prev_get, &cnt); ++ if (unlikely(get < 0)) { ++ if (get == -EINVAL) ++ continue; ++ ++ return get; ++ } ++ ++ if (get <= chan->dma.cur) { ++ chan->dma.free = chan->dma.max - chan->dma.cur; ++ if (chan->dma.free >= count) ++ break; ++ ++ FIRE_RING(chan); ++ do { ++ get = READ_GET(chan, &prev_get, &cnt); ++ if (unlikely(get < 0)) { ++ if (get == -EINVAL) ++ continue; ++ return get; ++ } ++ } while (get == 0); ++ chan->dma.cur = 0; ++ chan->dma.put = 0; ++ } ++ ++ chan->dma.free = get - chan->dma.cur - 1; ++ } ++ ++ return 0; ++} ++ + int +-nouveau_dma_wait(struct nouveau_channel *chan, int size) ++nouveau_dma_wait(struct nouveau_channel *chan, int slots, int size) + { + uint32_t prev_get = 0, cnt = 0; + int get; + ++ if (chan->dma.ib_max) ++ return nv50_dma_wait(chan, slots, size); ++ + while (chan->dma.free < size) { + get = READ_GET(chan, &prev_get, &cnt); + if (unlikely(get == -EBUSY)) +diff --git a/drivers/gpu/drm/nouveau/nouveau_dma.h b/drivers/gpu/drm/nouveau/nouveau_dma.h +--- a/drivers/gpu/drm/nouveau/nouveau_dma.h ++++ b/drivers/gpu/drm/nouveau/nouveau_dma.h +@@ -31,6 +31,9 @@ + #define NOUVEAU_DMA_DEBUG 0 + #endif + ++void nv50_dma_push(struct nouveau_channel *, struct nouveau_bo *, ++ int delta, int length); ++ + /* + * There's a hw race condition where you can't jump to your PUT offset, + * to avoid this we jump to offset + SKIPS and fill the difference with +@@ -96,13 +99,11 @@ enum { + static __must_check inline int + RING_SPACE(struct nouveau_channel *chan, int size) + { +- if (chan->dma.free < size) { +- int ret; ++ int ret; + +- ret = nouveau_dma_wait(chan, size); +- if (ret) +- return ret; +- } ++ ret = nouveau_dma_wait(chan, 1, size); ++ if (ret) ++ return ret; + + chan->dma.free -= size; + return 0; +@@ -146,7 +147,13 @@ FIRE_RING(struct nouveau_channel *chan) + return; + chan->accel_done = true; + +- WRITE_PUT(chan->dma.cur); ++ if (chan->dma.ib_max) { ++ nv50_dma_push(chan, chan->pushbuf_bo, chan->dma.put << 2, ++ (chan->dma.cur - chan->dma.put) << 2); ++ } else { ++ WRITE_PUT(chan->dma.cur); ++ } ++ + chan->dma.put = chan->dma.cur; + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h +--- a/drivers/gpu/drm/nouveau/nouveau_drv.h ++++ b/drivers/gpu/drm/nouveau/nouveau_drv.h +@@ -34,7 +34,7 @@ + + #define DRIVER_MAJOR 0 + #define DRIVER_MINOR 0 +-#define DRIVER_PATCHLEVEL 15 ++#define DRIVER_PATCHLEVEL 16 + + #define NOUVEAU_FAMILY 0x0000FFFF + #define NOUVEAU_FLAGS 0xFFFF0000 +@@ -83,6 +83,7 @@ struct nouveau_bo { + struct drm_file *reserved_by; + struct list_head entry; + int pbbo_index; ++ bool validate_mapped; + + struct nouveau_channel *channel; + +@@ -239,6 +240,11 @@ struct nouveau_channel { + int cur; + int put; + /* access via pushbuf_bo */ ++ ++ int ib_base; ++ int ib_max; ++ int ib_free; ++ int ib_put; + } dma; + + uint32_t sw_subchannel[8]; +@@ -696,12 +702,6 @@ extern bool nouveau_wait_until(struct drm_device *, uint64_t timeout, + uint32_t reg, uint32_t mask, uint32_t val); + extern bool nouveau_wait_for_idle(struct drm_device *); + extern int nouveau_card_init(struct drm_device *); +-extern int nouveau_ioctl_card_init(struct drm_device *, void *data, +- struct drm_file *); +-extern int nouveau_ioctl_suspend(struct drm_device *, void *data, +- struct drm_file *); +-extern int nouveau_ioctl_resume(struct drm_device *, void *data, +- struct drm_file *); + + /* nouveau_mem.c */ + extern int nouveau_mem_init_heap(struct mem_block **, uint64_t start, +@@ -845,7 +845,7 @@ nouveau_debugfs_channel_fini(struct nouveau_channel *chan) + /* nouveau_dma.c */ + extern void nouveau_dma_pre_init(struct nouveau_channel *); + extern int nouveau_dma_init(struct nouveau_channel *); +-extern int nouveau_dma_wait(struct nouveau_channel *, int size); ++extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size); + + /* nouveau_acpi.c */ + #ifdef CONFIG_ACPI +@@ -1152,16 +1152,6 @@ extern int nouveau_gem_ioctl_new(struct drm_device *, void *, + struct drm_file *); + extern int nouveau_gem_ioctl_pushbuf(struct drm_device *, void *, + struct drm_file *); +-extern int nouveau_gem_ioctl_pushbuf_call(struct drm_device *, void *, +- struct drm_file *); +-extern int nouveau_gem_ioctl_pushbuf_call2(struct drm_device *, void *, +- struct drm_file *); +-extern int nouveau_gem_ioctl_pin(struct drm_device *, void *, +- struct drm_file *); +-extern int nouveau_gem_ioctl_unpin(struct drm_device *, void *, +- struct drm_file *); +-extern int nouveau_gem_ioctl_tile(struct drm_device *, void *, +- struct drm_file *); + extern int nouveau_gem_ioctl_cpu_prep(struct drm_device *, void *, + struct drm_file *); + extern int nouveau_gem_ioctl_cpu_fini(struct drm_device *, void *, +diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c +--- a/drivers/gpu/drm/nouveau/nouveau_gem.c ++++ b/drivers/gpu/drm/nouveau/nouveau_gem.c +@@ -243,6 +243,11 @@ validate_fini_list(struct list_head *list, struct nouveau_fence *fence) + nouveau_fence_unref((void *)&prev_fence); + } + ++ if (unlikely(nvbo->validate_mapped)) { ++ ttm_bo_kunmap(&nvbo->kmap); ++ nvbo->validate_mapped = false; ++ } ++ + list_del(&nvbo->entry); + nvbo->reserved_by = NULL; + ttm_bo_unreserve(&nvbo->bo); +@@ -302,11 +307,14 @@ retry: + if (ret == -EAGAIN) + ret = ttm_bo_wait_unreserved(&nvbo->bo, false); + drm_gem_object_unreference(gem); +- if (ret) ++ if (ret) { ++ NV_ERROR(dev, "fail reserve\n"); + return ret; ++ } + goto retry; + } + ++ b->user_priv = (uint64_t)(unsigned long)nvbo; + nvbo->reserved_by = file_priv; + nvbo->pbbo_index = i; + if ((b->valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) && +@@ -336,8 +344,10 @@ retry: + } + + ret = ttm_bo_wait_cpu(&nvbo->bo, false); +- if (ret) ++ if (ret) { ++ NV_ERROR(dev, "fail wait_cpu\n"); + return ret; ++ } + goto retry; + } + } +@@ -351,6 +361,7 @@ validate_list(struct nouveau_channel *chan, struct list_head *list, + { + struct drm_nouveau_gem_pushbuf_bo __user *upbbo = + (void __force __user *)(uintptr_t)user_pbbo_ptr; ++ struct drm_device *dev = chan->dev; + struct nouveau_bo *nvbo; + int ret, relocs = 0; + +@@ -362,39 +373,46 @@ validate_list(struct nouveau_channel *chan, struct list_head *list, + spin_lock(&nvbo->bo.lock); + ret = ttm_bo_wait(&nvbo->bo, false, false, false); + spin_unlock(&nvbo->bo.lock); +- if (unlikely(ret)) ++ if (unlikely(ret)) { ++ NV_ERROR(dev, "fail wait other chan\n"); + return ret; ++ } + } + + ret = nouveau_gem_set_domain(nvbo->gem, b->read_domains, + b->write_domains, + b->valid_domains); +- if (unlikely(ret)) ++ if (unlikely(ret)) { ++ NV_ERROR(dev, "fail set_domain\n"); + return ret; ++ } + + nvbo->channel = chan; + ret = ttm_bo_validate(&nvbo->bo, &nvbo->placement, + false, false); + nvbo->channel = NULL; +- if (unlikely(ret)) ++ if (unlikely(ret)) { ++ NV_ERROR(dev, "fail ttm_validate\n"); + return ret; ++ } + +- if (nvbo->bo.offset == b->presumed_offset && ++ if (nvbo->bo.offset == b->presumed.offset && + ((nvbo->bo.mem.mem_type == TTM_PL_VRAM && +- b->presumed_domain & NOUVEAU_GEM_DOMAIN_VRAM) || ++ b->presumed.domain & NOUVEAU_GEM_DOMAIN_VRAM) || + (nvbo->bo.mem.mem_type == TTM_PL_TT && +- b->presumed_domain & NOUVEAU_GEM_DOMAIN_GART))) ++ b->presumed.domain & NOUVEAU_GEM_DOMAIN_GART))) + continue; + + if (nvbo->bo.mem.mem_type == TTM_PL_TT) +- b->presumed_domain = NOUVEAU_GEM_DOMAIN_GART; ++ b->presumed.domain = NOUVEAU_GEM_DOMAIN_GART; + else +- b->presumed_domain = NOUVEAU_GEM_DOMAIN_VRAM; +- b->presumed_offset = nvbo->bo.offset; +- b->presumed_ok = 0; ++ b->presumed.domain = NOUVEAU_GEM_DOMAIN_VRAM; ++ b->presumed.offset = nvbo->bo.offset; ++ b->presumed.valid = 0; + relocs++; + +- if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index], b, sizeof(*b))) ++ if (DRM_COPY_TO_USER(&upbbo[nvbo->pbbo_index].presumed, ++ &b->presumed, sizeof(b->presumed))) + return -EFAULT; + } + +@@ -408,6 +426,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan, + uint64_t user_buffers, int nr_buffers, + struct validate_op *op, int *apply_relocs) + { ++ struct drm_device *dev = chan->dev; + int ret, relocs = 0; + + INIT_LIST_HEAD(&op->vram_list); +@@ -418,11 +437,14 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan, + return 0; + + ret = validate_init(chan, file_priv, pbbo, nr_buffers, op); +- if (unlikely(ret)) ++ if (unlikely(ret)) { ++ NV_ERROR(dev, "validate_init\n"); + return ret; ++ } + + ret = validate_list(chan, &op->vram_list, pbbo, user_buffers); + if (unlikely(ret < 0)) { ++ NV_ERROR(dev, "validate vram_list\n"); + validate_fini(op, NULL); + return ret; + } +@@ -430,6 +452,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan, + + ret = validate_list(chan, &op->gart_list, pbbo, user_buffers); + if (unlikely(ret < 0)) { ++ NV_ERROR(dev, "validate gart_list\n"); + validate_fini(op, NULL); + return ret; + } +@@ -437,6 +460,7 @@ nouveau_gem_pushbuf_validate(struct nouveau_channel *chan, + + ret = validate_list(chan, &op->both_list, pbbo, user_buffers); + if (unlikely(ret < 0)) { ++ NV_ERROR(dev, "validate both_list\n"); + validate_fini(op, NULL); + return ret; + } +@@ -465,59 +489,82 @@ u_memcpya(uint64_t user, unsigned nmemb, unsigned size) + } + + static int +-nouveau_gem_pushbuf_reloc_apply(struct nouveau_channel *chan, int nr_bo, +- struct drm_nouveau_gem_pushbuf_bo *bo, +- unsigned nr_relocs, uint64_t ptr_relocs, +- unsigned nr_dwords, unsigned first_dword, +- uint32_t *pushbuf, bool is_iomem) ++nouveau_gem_pushbuf_reloc_apply(struct drm_device *dev, ++ struct drm_nouveau_gem_pushbuf *req, ++ struct drm_nouveau_gem_pushbuf_bo *bo) + { + struct drm_nouveau_gem_pushbuf_reloc *reloc = NULL; +- struct drm_device *dev = chan->dev; + int ret = 0; + unsigned i; + +- reloc = u_memcpya(ptr_relocs, nr_relocs, sizeof(*reloc)); ++ reloc = u_memcpya(req->relocs, req->nr_relocs, sizeof(*reloc)); + if (IS_ERR(reloc)) + return PTR_ERR(reloc); + +- for (i = 0; i < nr_relocs; i++) { ++ for (i = 0; i < req->nr_relocs; i++) { + struct drm_nouveau_gem_pushbuf_reloc *r = &reloc[i]; + struct drm_nouveau_gem_pushbuf_bo *b; ++ struct nouveau_bo *nvbo; + uint32_t data; + +- if (r->bo_index >= nr_bo || r->reloc_index < first_dword || +- r->reloc_index >= first_dword + nr_dwords) { +- NV_ERROR(dev, "Bad relocation %d\n", i); +- NV_ERROR(dev, " bo: %d max %d\n", r->bo_index, nr_bo); +- NV_ERROR(dev, " id: %d max %d\n", r->reloc_index, nr_dwords); ++ if (unlikely(r->bo_index > req->nr_buffers)) { ++ NV_ERROR(dev, "reloc bo index invalid\n"); + ret = -EINVAL; + break; + } + + b = &bo[r->bo_index]; +- if (b->presumed_ok) ++ if (b->presumed.valid) + continue; + ++ if (unlikely(r->reloc_bo_index > req->nr_buffers)) { ++ NV_ERROR(dev, "reloc container bo index invalid\n"); ++ ret = -EINVAL; ++ break; ++ } ++ nvbo = (void *)(unsigned long)bo[r->reloc_bo_index].user_priv; ++ ++ if (unlikely(r->reloc_bo_offset + 4 > ++ nvbo->bo.mem.num_pages << PAGE_SHIFT)) { ++ NV_ERROR(dev, "reloc outside of bo\n"); ++ ret = -EINVAL; ++ break; ++ } ++ ++ if (!nvbo->kmap.virtual) { ++ ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, ++ &nvbo->kmap); ++ if (ret) { ++ NV_ERROR(dev, "failed kmap for reloc\n"); ++ break; ++ } ++ nvbo->validate_mapped = true; ++ } ++ + if (r->flags & NOUVEAU_GEM_RELOC_LOW) +- data = b->presumed_offset + r->data; ++ data = b->presumed.offset + r->data; + else + if (r->flags & NOUVEAU_GEM_RELOC_HIGH) +- data = (b->presumed_offset + r->data) >> 32; ++ data = (b->presumed.offset + r->data) >> 32; + else + data = r->data; + + if (r->flags & NOUVEAU_GEM_RELOC_OR) { +- if (b->presumed_domain == NOUVEAU_GEM_DOMAIN_GART) ++ if (b->presumed.domain == NOUVEAU_GEM_DOMAIN_GART) + data |= r->tor; + else + data |= r->vor; + } + +- if (is_iomem) +- iowrite32_native(data, (void __force __iomem *) +- &pushbuf[r->reloc_index]); +- else +- pushbuf[r->reloc_index] = data; ++ spin_lock(&nvbo->bo.lock); ++ ret = ttm_bo_wait(&nvbo->bo, false, false, false); ++ spin_unlock(&nvbo->bo.lock); ++ if (ret) { ++ NV_ERROR(dev, "reloc wait_idle failed: %d\n", ret); ++ break; ++ } ++ ++ nouveau_bo_wr32(nvbo, r->reloc_bo_offset >> 2, data); + } + + kfree(reloc); +@@ -528,127 +575,50 @@ int + nouveau_gem_ioctl_pushbuf(struct drm_device *dev, void *data, + struct drm_file *file_priv) + { ++ struct drm_nouveau_private *dev_priv = dev->dev_private; + struct drm_nouveau_gem_pushbuf *req = data; +- struct drm_nouveau_gem_pushbuf_bo *bo = NULL; ++ struct drm_nouveau_gem_pushbuf_push *push; ++ struct drm_nouveau_gem_pushbuf_bo *bo; + struct nouveau_channel *chan; + struct validate_op op; +- struct nouveau_fence* fence = 0; +- uint32_t *pushbuf = NULL; +- int ret = 0, do_reloc = 0, i; ++ struct nouveau_fence *fence = 0; ++ int i, j, ret = 0, do_reloc = 0; + + NOUVEAU_CHECK_INITIALISED_WITH_RETURN; + NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(req->channel, file_priv, chan); + +- if (req->nr_dwords >= chan->dma.max || +- req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS || +- req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS) { +- NV_ERROR(dev, "Pushbuf config exceeds limits:\n"); +- NV_ERROR(dev, " dwords : %d max %d\n", req->nr_dwords, +- chan->dma.max - 1); +- NV_ERROR(dev, " buffers: %d max %d\n", req->nr_buffers, +- NOUVEAU_GEM_MAX_BUFFERS); +- NV_ERROR(dev, " relocs : %d max %d\n", req->nr_relocs, +- NOUVEAU_GEM_MAX_RELOCS); +- return -EINVAL; +- } +- +- pushbuf = u_memcpya(req->dwords, req->nr_dwords, sizeof(uint32_t)); +- if (IS_ERR(pushbuf)) +- return PTR_ERR(pushbuf); +- +- bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo)); +- if (IS_ERR(bo)) { +- kfree(pushbuf); +- return PTR_ERR(bo); +- } +- +- mutex_lock(&dev->struct_mutex); +- +- /* Validate buffer list */ +- ret = nouveau_gem_pushbuf_validate(chan, file_priv, bo, req->buffers, +- req->nr_buffers, &op, &do_reloc); +- if (ret) +- goto out; +- +- /* Apply any relocations that are required */ +- if (do_reloc) { +- ret = nouveau_gem_pushbuf_reloc_apply(chan, req->nr_buffers, +- bo, req->nr_relocs, +- req->relocs, +- req->nr_dwords, 0, +- pushbuf, false); +- if (ret) +- goto out; +- } +- +- /* Emit push buffer to the hw +- */ +- ret = RING_SPACE(chan, req->nr_dwords); +- if (ret) +- goto out; +- +- OUT_RINGp(chan, pushbuf, req->nr_dwords); ++ req->vram_available = dev_priv->fb_aper_free; ++ req->gart_available = dev_priv->gart_info.aper_free; ++ if (unlikely(req->nr_push == 0)) ++ goto out_next; + +- ret = nouveau_fence_new(chan, &fence, true); +- if (ret) { +- NV_ERROR(dev, "error fencing pushbuf: %d\n", ret); +- WIND_RING(chan); +- goto out; ++ if (unlikely(req->nr_push > NOUVEAU_GEM_MAX_PUSH)) { ++ NV_ERROR(dev, "pushbuf push count exceeds limit: %d max %d\n", ++ req->nr_push, NOUVEAU_GEM_MAX_PUSH); ++ return -EINVAL; + } + +- if (nouveau_gem_pushbuf_sync(chan)) { +- ret = nouveau_fence_wait(fence, NULL, false, false); +- if (ret) { +- for (i = 0; i < req->nr_dwords; i++) +- NV_ERROR(dev, "0x%08x\n", pushbuf[i]); +- NV_ERROR(dev, "^^ above push buffer is fail :(\n"); +- } ++ if (unlikely(req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS)) { ++ NV_ERROR(dev, "pushbuf bo count exceeds limit: %d max %d\n", ++ req->nr_buffers, NOUVEAU_GEM_MAX_BUFFERS); ++ return -EINVAL; + } + +-out: +- validate_fini(&op, fence); +- nouveau_fence_unref((void**)&fence); +- mutex_unlock(&dev->struct_mutex); +- kfree(pushbuf); +- kfree(bo); +- return ret; +-} +- +-#define PUSHBUF_CAL (dev_priv->card_type >= NV_20) +- +-int +-nouveau_gem_ioctl_pushbuf_call(struct drm_device *dev, void *data, +- struct drm_file *file_priv) +-{ +- struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct drm_nouveau_gem_pushbuf_call *req = data; +- struct drm_nouveau_gem_pushbuf_bo *bo = NULL; +- struct nouveau_channel *chan; +- struct drm_gem_object *gem; +- struct nouveau_bo *pbbo; +- struct validate_op op; +- struct nouveau_fence* fence = 0; +- int i, ret = 0, do_reloc = 0; +- +- NOUVEAU_CHECK_INITIALISED_WITH_RETURN; +- NOUVEAU_GET_USER_CHANNEL_WITH_RETURN(req->channel, file_priv, chan); +- +- if (unlikely(req->handle == 0)) +- goto out_next; +- +- if (req->nr_buffers > NOUVEAU_GEM_MAX_BUFFERS || +- req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS) { +- NV_ERROR(dev, "Pushbuf config exceeds limits:\n"); +- NV_ERROR(dev, " buffers: %d max %d\n", req->nr_buffers, +- NOUVEAU_GEM_MAX_BUFFERS); +- NV_ERROR(dev, " relocs : %d max %d\n", req->nr_relocs, +- NOUVEAU_GEM_MAX_RELOCS); ++ if (unlikely(req->nr_relocs > NOUVEAU_GEM_MAX_RELOCS)) { ++ NV_ERROR(dev, "pushbuf reloc count exceeds limit: %d max %d\n", ++ req->nr_relocs, NOUVEAU_GEM_MAX_RELOCS); + return -EINVAL; + } + ++ push = u_memcpya(req->push, req->nr_push, sizeof(*push)); ++ if (IS_ERR(push)) ++ return PTR_ERR(push); ++ + bo = u_memcpya(req->buffers, req->nr_buffers, sizeof(*bo)); +- if (IS_ERR(bo)) ++ if (IS_ERR(bo)) { ++ kfree(push); + return PTR_ERR(bo); ++ } + + mutex_lock(&dev->struct_mutex); + +@@ -660,122 +630,84 @@ nouveau_gem_ioctl_pushbuf_call(struct drm_device *dev, void *data, + goto out; + } + +- /* Validate DMA push buffer */ +- gem = drm_gem_object_lookup(dev, file_priv, req->handle); +- if (!gem) { +- NV_ERROR(dev, "Unknown pb handle 0x%08x\n", req->handle); +- ret = -EINVAL; +- goto out; +- } +- pbbo = nouveau_gem_object(gem); +- +- if ((req->offset & 3) || req->nr_dwords < 2 || +- (unsigned long)req->offset > (unsigned long)pbbo->bo.mem.size || +- (unsigned long)req->nr_dwords > +- ((unsigned long)(pbbo->bo.mem.size - req->offset ) >> 2)) { +- NV_ERROR(dev, "pb call misaligned or out of bounds: " +- "%d + %d * 4 > %ld\n", +- req->offset, req->nr_dwords, pbbo->bo.mem.size); +- ret = -EINVAL; +- drm_gem_object_unreference(gem); +- goto out; +- } +- +- ret = ttm_bo_reserve(&pbbo->bo, false, false, true, +- chan->fence.sequence); +- if (ret) { +- NV_ERROR(dev, "resv pb: %d\n", ret); +- drm_gem_object_unreference(gem); +- goto out; +- } +- +- nouveau_bo_placement_set(pbbo, 1 << chan->pushbuf_bo->bo.mem.mem_type); +- ret = ttm_bo_validate(&pbbo->bo, &pbbo->placement, false, false); +- if (ret) { +- NV_ERROR(dev, "validate pb: %d\n", ret); +- ttm_bo_unreserve(&pbbo->bo); +- drm_gem_object_unreference(gem); +- goto out; +- } +- +- list_add_tail(&pbbo->entry, &op.both_list); +- +- /* If presumed return address doesn't match, we need to map the +- * push buffer and fix it.. +- */ +- if (!PUSHBUF_CAL) { +- uint32_t retaddy; +- +- if (chan->dma.free < 4 + NOUVEAU_DMA_SKIPS) { +- ret = nouveau_dma_wait(chan, 4 + NOUVEAU_DMA_SKIPS); +- if (ret) { +- NV_ERROR(dev, "jmp_space: %d\n", ret); +- goto out; +- } +- } +- +- retaddy = chan->pushbuf_base + ((chan->dma.cur + 2) << 2); +- retaddy |= 0x20000000; +- if (retaddy != req->suffix0) { +- req->suffix0 = retaddy; +- do_reloc = 1; +- } +- } +- + /* Apply any relocations that are required */ + if (do_reloc) { +- void *pbvirt; +- bool is_iomem; +- ret = ttm_bo_kmap(&pbbo->bo, 0, pbbo->bo.mem.num_pages, +- &pbbo->kmap); ++ ret = nouveau_gem_pushbuf_reloc_apply(dev, req, bo); + if (ret) { +- NV_ERROR(dev, "kmap pb: %d\n", ret); ++ NV_ERROR(dev, "reloc apply: %d\n", ret); + goto out; + } ++ } + +- pbvirt = ttm_kmap_obj_virtual(&pbbo->kmap, &is_iomem); +- ret = nouveau_gem_pushbuf_reloc_apply(chan, req->nr_buffers, bo, +- req->nr_relocs, +- req->relocs, +- req->nr_dwords, +- req->offset / 4, +- pbvirt, is_iomem); +- +- if (!PUSHBUF_CAL) { +- nouveau_bo_wr32(pbbo, +- req->offset / 4 + req->nr_dwords - 2, +- req->suffix0); +- } +- +- ttm_bo_kunmap(&pbbo->kmap); ++ if (chan->dma.ib_max) { ++ ret = nouveau_dma_wait(chan, req->nr_push + 1, 6); + if (ret) { +- NV_ERROR(dev, "reloc apply: %d\n", ret); ++ NV_INFO(dev, "nv50cal_space: %d\n", ret); + goto out; + } +- } + +- if (PUSHBUF_CAL) { +- ret = RING_SPACE(chan, 2); ++ for (i = 0; i < req->nr_push; i++) { ++ struct nouveau_bo *nvbo = (void *)(unsigned long) ++ bo[push[i].bo_index].user_priv; ++ ++ nv50_dma_push(chan, nvbo, push[i].offset, ++ push[i].length); ++ } ++ } else ++ if (dev_priv->card_type >= NV_20) { ++ ret = RING_SPACE(chan, req->nr_push * 2); + if (ret) { + NV_ERROR(dev, "cal_space: %d\n", ret); + goto out; + } +- OUT_RING(chan, ((pbbo->bo.mem.mm_node->start << PAGE_SHIFT) + +- req->offset) | 2); +- OUT_RING(chan, 0); ++ ++ for (i = 0; i < req->nr_push; i++) { ++ struct nouveau_bo *nvbo = (void *)(unsigned long) ++ bo[push[i].bo_index].user_priv; ++ struct drm_mm_node *mem = nvbo->bo.mem.mm_node; ++ ++ OUT_RING(chan, ((mem->start << PAGE_SHIFT) + ++ push[i].offset) | 2); ++ OUT_RING(chan, 0); ++ } + } else { +- ret = RING_SPACE(chan, 2 + NOUVEAU_DMA_SKIPS); ++ ret = RING_SPACE(chan, req->nr_push * (2 + NOUVEAU_DMA_SKIPS)); + if (ret) { + NV_ERROR(dev, "jmp_space: %d\n", ret); + goto out; + } +- OUT_RING(chan, ((pbbo->bo.mem.mm_node->start << PAGE_SHIFT) + +- req->offset) | 0x20000000); +- OUT_RING(chan, 0); + +- /* Space the jumps apart with NOPs. */ +- for (i = 0; i < NOUVEAU_DMA_SKIPS; i++) ++ for (i = 0; i < req->nr_push; i++) { ++ struct nouveau_bo *nvbo = (void *)(unsigned long) ++ bo[push[i].bo_index].user_priv; ++ struct drm_mm_node *mem = nvbo->bo.mem.mm_node; ++ uint32_t cmd; ++ ++ cmd = chan->pushbuf_base + ((chan->dma.cur + 2) << 2); ++ cmd |= 0x20000000; ++ if (unlikely(cmd != req->suffix0)) { ++ if (!nvbo->kmap.virtual) { ++ ret = ttm_bo_kmap(&nvbo->bo, 0, ++ nvbo->bo.mem. ++ num_pages, ++ &nvbo->kmap); ++ if (ret) { ++ WIND_RING(chan); ++ goto out; ++ } ++ nvbo->validate_mapped = true; ++ } ++ ++ nouveau_bo_wr32(nvbo, (push[i].offset + ++ push[i].length - 8) / 4, cmd); ++ } ++ ++ OUT_RING(chan, ((mem->start << PAGE_SHIFT) + ++ push[i].offset) | 0x20000000); + OUT_RING(chan, 0); ++ for (j = 0; j < NOUVEAU_DMA_SKIPS; j++) ++ OUT_RING(chan, 0); ++ } + } + + ret = nouveau_fence_new(chan, &fence, true); +@@ -790,9 +722,14 @@ out: + nouveau_fence_unref((void**)&fence); + mutex_unlock(&dev->struct_mutex); + kfree(bo); ++ kfree(push); + + out_next: +- if (PUSHBUF_CAL) { ++ if (chan->dma.ib_max) { ++ req->suffix0 = 0x00000000; ++ req->suffix1 = 0x00000000; ++ } else ++ if (dev_priv->card_type >= NV_20) { + req->suffix0 = 0x00020000; + req->suffix1 = 0x00000000; + } else { +@@ -804,19 +741,6 @@ out_next: + return ret; + } + +-int +-nouveau_gem_ioctl_pushbuf_call2(struct drm_device *dev, void *data, +- struct drm_file *file_priv) +-{ +- struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct drm_nouveau_gem_pushbuf_call *req = data; +- +- req->vram_available = dev_priv->fb_aper_free; +- req->gart_available = dev_priv->gart_info.aper_free; +- +- return nouveau_gem_ioctl_pushbuf_call(dev, data, file_priv); +-} +- + static inline uint32_t + domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain) + { +@@ -831,70 +755,6 @@ domain_to_ttm(struct nouveau_bo *nvbo, uint32_t domain) + } + + int +-nouveau_gem_ioctl_pin(struct drm_device *dev, void *data, +- struct drm_file *file_priv) +-{ +- struct drm_nouveau_gem_pin *req = data; +- struct drm_gem_object *gem; +- struct nouveau_bo *nvbo; +- int ret = 0; +- +- NOUVEAU_CHECK_INITIALISED_WITH_RETURN; +- +- if (drm_core_check_feature(dev, DRIVER_MODESET)) { +- NV_ERROR(dev, "pin only allowed without kernel modesetting\n"); +- return -EINVAL; +- } +- +- if (!DRM_SUSER(DRM_CURPROC)) +- return -EPERM; +- +- gem = drm_gem_object_lookup(dev, file_priv, req->handle); +- if (!gem) +- return -EINVAL; +- nvbo = nouveau_gem_object(gem); +- +- ret = nouveau_bo_pin(nvbo, domain_to_ttm(nvbo, req->domain)); +- if (ret) +- goto out; +- +- req->offset = nvbo->bo.offset; +- if (nvbo->bo.mem.mem_type == TTM_PL_TT) +- req->domain = NOUVEAU_GEM_DOMAIN_GART; +- else +- req->domain = NOUVEAU_GEM_DOMAIN_VRAM; +- +-out: +- drm_gem_object_unreference_unlocked(gem); +- +- return ret; +-} +- +-int +-nouveau_gem_ioctl_unpin(struct drm_device *dev, void *data, +- struct drm_file *file_priv) +-{ +- struct drm_nouveau_gem_pin *req = data; +- struct drm_gem_object *gem; +- int ret; +- +- NOUVEAU_CHECK_INITIALISED_WITH_RETURN; +- +- if (drm_core_check_feature(dev, DRIVER_MODESET)) +- return -EINVAL; +- +- gem = drm_gem_object_lookup(dev, file_priv, req->handle); +- if (!gem) +- return -EINVAL; +- +- ret = nouveau_bo_unpin(nouveau_gem_object(gem)); +- +- drm_gem_object_unreference_unlocked(gem); +- +- return ret; +-} +- +-int + nouveau_gem_ioctl_cpu_prep(struct drm_device *dev, void *data, + struct drm_file *file_priv) + { +diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c +index a4851af..a8d77c8 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_state.c ++++ b/drivers/gpu/drm/nouveau/nouveau_state.c +@@ -776,13 +776,6 @@ int nouveau_unload(struct drm_device *dev) + return 0; + } + +-int +-nouveau_ioctl_card_init(struct drm_device *dev, void *data, +- struct drm_file *file_priv) +-{ +- return nouveau_card_init(dev); +-} +- + int nouveau_ioctl_getparam(struct drm_device *dev, void *data, + struct drm_file *file_priv) + { +diff --git a/drivers/gpu/drm/nouveau/nv50_fifo.c b/drivers/gpu/drm/nouveau/nv50_fifo.c +--- a/drivers/gpu/drm/nouveau/nv50_fifo.c ++++ b/drivers/gpu/drm/nouveau/nv50_fifo.c +@@ -280,17 +280,17 @@ nv50_fifo_create_context(struct nouveau_channel *chan) + + dev_priv->engine.instmem.prepare_access(dev, true); + +- nv_wo32(dev, ramfc, 0x08/4, chan->pushbuf_base); +- nv_wo32(dev, ramfc, 0x10/4, chan->pushbuf_base); + nv_wo32(dev, ramfc, 0x48/4, chan->pushbuf->instance >> 4); + nv_wo32(dev, ramfc, 0x80/4, (0xc << 24) | (chan->ramht->instance >> 4)); +- nv_wo32(dev, ramfc, 0x3c/4, 0x00086078); + nv_wo32(dev, ramfc, 0x44/4, 0x2101ffff); + nv_wo32(dev, ramfc, 0x60/4, 0x7fffffff); + nv_wo32(dev, ramfc, 0x40/4, 0x00000000); + nv_wo32(dev, ramfc, 0x7c/4, 0x30000001); + nv_wo32(dev, ramfc, 0x78/4, 0x00000000); +- nv_wo32(dev, ramfc, 0x4c/4, 0xffffffff); ++ nv_wo32(dev, ramfc, 0x3c/4, 0x403f6078); ++ nv_wo32(dev, ramfc, 0x50/4, chan->pushbuf_base + ++ chan->dma.ib_base * 4); ++ nv_wo32(dev, ramfc, 0x54/4, drm_order(chan->dma.ib_max + 1) << 16); + + if (!IS_G80) { + nv_wo32(dev, chan->ramin->gpuobj, 0, chan->id); +diff --git a/include/drm/nouveau_drm.h b/include/drm/nouveau_drm.h +--- a/include/drm/nouveau_drm.h ++++ b/include/drm/nouveau_drm.h +@@ -25,13 +25,14 @@ + #ifndef __NOUVEAU_DRM_H__ + #define __NOUVEAU_DRM_H__ + +-#define NOUVEAU_DRM_HEADER_PATCHLEVEL 15 ++#define NOUVEAU_DRM_HEADER_PATCHLEVEL 16 + + struct drm_nouveau_channel_alloc { + uint32_t fb_ctxdma_handle; + uint32_t tt_ctxdma_handle; + + int channel; ++ uint32_t pushbuf_domains; + + /* Notifier memory */ + uint32_t notifier_handle; +@@ -109,68 +110,58 @@ struct drm_nouveau_gem_new { + uint32_t align; + }; + ++#define NOUVEAU_GEM_MAX_BUFFERS 1024 ++struct drm_nouveau_gem_pushbuf_bo_presumed { ++ uint32_t valid; ++ uint32_t domain; ++ uint64_t offset; ++}; ++ + struct drm_nouveau_gem_pushbuf_bo { + uint64_t user_priv; + uint32_t handle; + uint32_t read_domains; + uint32_t write_domains; + uint32_t valid_domains; +- uint32_t presumed_ok; +- uint32_t presumed_domain; +- uint64_t presumed_offset; ++ struct drm_nouveau_gem_pushbuf_bo_presumed presumed; + }; + + #define NOUVEAU_GEM_RELOC_LOW (1 << 0) + #define NOUVEAU_GEM_RELOC_HIGH (1 << 1) + #define NOUVEAU_GEM_RELOC_OR (1 << 2) ++#define NOUVEAU_GEM_MAX_RELOCS 1024 + struct drm_nouveau_gem_pushbuf_reloc { ++ uint32_t reloc_bo_index; ++ uint32_t reloc_bo_offset; + uint32_t bo_index; +- uint32_t reloc_index; + uint32_t flags; + uint32_t data; + uint32_t vor; + uint32_t tor; + }; + +-#define NOUVEAU_GEM_MAX_BUFFERS 1024 +-#define NOUVEAU_GEM_MAX_RELOCS 1024 ++#define NOUVEAU_GEM_MAX_PUSH 512 ++struct drm_nouveau_gem_pushbuf_push { ++ uint32_t bo_index; ++ uint32_t pad; ++ uint64_t offset; ++ uint64_t length; ++}; + + struct drm_nouveau_gem_pushbuf { + uint32_t channel; +- uint32_t nr_dwords; + uint32_t nr_buffers; +- uint32_t nr_relocs; +- uint64_t dwords; + uint64_t buffers; +- uint64_t relocs; +-}; +- +-struct drm_nouveau_gem_pushbuf_call { +- uint32_t channel; +- uint32_t handle; +- uint32_t offset; +- uint32_t nr_buffers; + uint32_t nr_relocs; +- uint32_t nr_dwords; +- uint64_t buffers; ++ uint32_t nr_push; + uint64_t relocs; ++ uint64_t push; + uint32_t suffix0; + uint32_t suffix1; +- /* below only accessed for CALL2 */ + uint64_t vram_available; + uint64_t gart_available; + }; + +-struct drm_nouveau_gem_pin { +- uint32_t handle; +- uint32_t domain; +- uint64_t offset; +-}; +- +-struct drm_nouveau_gem_unpin { +- uint32_t handle; +-}; +- + #define NOUVEAU_GEM_CPU_PREP_NOWAIT 0x00000001 + #define NOUVEAU_GEM_CPU_PREP_NOBLOCK 0x00000002 + #define NOUVEAU_GEM_CPU_PREP_WRITE 0x00000004 +@@ -183,14 +174,6 @@ struct drm_nouveau_gem_cpu_fini { + uint32_t handle; + }; + +-struct drm_nouveau_gem_tile { +- uint32_t handle; +- uint32_t offset; +- uint32_t size; +- uint32_t tile_mode; +- uint32_t tile_flags; +-}; +- + enum nouveau_bus_type { + NV_AGP = 0, + NV_PCI = 1, +@@ -200,22 +183,17 @@ enum nouveau_bus_type { + struct drm_nouveau_sarea { + }; + +-#define DRM_NOUVEAU_CARD_INIT 0x00 +-#define DRM_NOUVEAU_GETPARAM 0x01 +-#define DRM_NOUVEAU_SETPARAM 0x02 +-#define DRM_NOUVEAU_CHANNEL_ALLOC 0x03 +-#define DRM_NOUVEAU_CHANNEL_FREE 0x04 +-#define DRM_NOUVEAU_GROBJ_ALLOC 0x05 +-#define DRM_NOUVEAU_NOTIFIEROBJ_ALLOC 0x06 +-#define DRM_NOUVEAU_GPUOBJ_FREE 0x07 ++#define DRM_NOUVEAU_GETPARAM 0x00 ++#define DRM_NOUVEAU_SETPARAM 0x01 ++#define DRM_NOUVEAU_CHANNEL_ALLOC 0x02 ++#define DRM_NOUVEAU_CHANNEL_FREE 0x03 ++#define DRM_NOUVEAU_GROBJ_ALLOC 0x04 ++#define DRM_NOUVEAU_NOTIFIEROBJ_ALLOC 0x05 ++#define DRM_NOUVEAU_GPUOBJ_FREE 0x06 + #define DRM_NOUVEAU_GEM_NEW 0x40 + #define DRM_NOUVEAU_GEM_PUSHBUF 0x41 +-#define DRM_NOUVEAU_GEM_PUSHBUF_CALL 0x42 +-#define DRM_NOUVEAU_GEM_PIN 0x43 /* !KMS only */ +-#define DRM_NOUVEAU_GEM_UNPIN 0x44 /* !KMS only */ +-#define DRM_NOUVEAU_GEM_CPU_PREP 0x45 +-#define DRM_NOUVEAU_GEM_CPU_FINI 0x46 +-#define DRM_NOUVEAU_GEM_INFO 0x47 +-#define DRM_NOUVEAU_GEM_PUSHBUF_CALL2 0x48 ++#define DRM_NOUVEAU_GEM_CPU_PREP 0x42 ++#define DRM_NOUVEAU_GEM_CPU_FINI 0x43 ++#define DRM_NOUVEAU_GEM_INFO 0x44 + + #endif /* __NOUVEAU_DRM_H__ */ +-- +1.7.0 + diff --git a/drm-nouveau-acpi-edid-fallback.patch b/drm-nouveau-acpi-edid-fallback.patch new file mode 100644 index 000000000..3b57cb8e7 --- /dev/null +++ b/drm-nouveau-acpi-edid-fallback.patch @@ -0,0 +1,239 @@ +From 782468d6a9fb865677c166ceffc2271e1f709cc5 Mon Sep 17 00:00:00 2001 +From: Ben Skeggs +Date: Fri, 16 Apr 2010 08:12:34 +1000 +Subject: [PATCH 2/3] drm-nouveau-acpi-edid-fallback + +--- + drivers/gpu/drm/nouveau/nouveau_acpi.c | 81 ++++++++++++++++++++++++-- + drivers/gpu/drm/nouveau/nouveau_connector.c | 8 +++ + drivers/gpu/drm/nouveau/nouveau_drv.h | 20 +++++-- + drivers/gpu/drm/nouveau/nouveau_state.c | 5 +- + 4 files changed, 98 insertions(+), 16 deletions(-) + +diff --git a/drivers/gpu/drm/nouveau/nouveau_acpi.c b/drivers/gpu/drm/nouveau/nouveau_acpi.c +index 48227e7..ac7fd04 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_acpi.c ++++ b/drivers/gpu/drm/nouveau/nouveau_acpi.c +@@ -2,11 +2,13 @@ + #include + #include + #include ++#include + + #include "drmP.h" + #include "drm.h" + #include "drm_sarea.h" + #include "drm_crtc_helper.h" ++#include "nouveau_connector.h" + #include "nouveau_drv.h" + #include "nouveau_drm.h" + #include "nv50_display.h" +@@ -35,7 +37,7 @@ static int nouveau_dsm(struct drm_device *dev, int func, int arg, int *result) + 0xB3, 0x4D, 0x7E, 0x5F, 0xEA, 0x12, 0x9F, 0xD4, + }; + +- struct pci_dev *pdev = dev->pdev; ++ struct drm_nouveau_private *dev_priv = dev->dev_private; + struct acpi_handle *handle; + struct acpi_buffer output = { ACPI_ALLOCATE_BUFFER, NULL }; + struct acpi_object_list input; +@@ -43,11 +45,11 @@ static int nouveau_dsm(struct drm_device *dev, int func, int arg, int *result) + union acpi_object *obj; + int err; + +- handle = DEVICE_ACPI_HANDLE(&pdev->dev); +- +- if (!handle) ++ if (!dev_priv->acpi_device) + return -ENODEV; + ++ handle = dev_priv->acpi_device->handle; ++ + input.count = 4; + input.pointer = params; + params[0].type = ACPI_TYPE_BUFFER; +@@ -62,7 +64,8 @@ static int nouveau_dsm(struct drm_device *dev, int func, int arg, int *result) + + err = acpi_evaluate_object(handle, "_DSM", &input, &output); + if (err) { +- NV_INFO(dev, "failed to evaluate _DSM: %d\n", err); ++ if (err != AE_NOT_FOUND) ++ NV_INFO(dev, "failed to evaluate _DSM: %d\n", err); + return err; + } + +@@ -86,7 +89,7 @@ static int nouveau_dsm(struct drm_device *dev, int func, int arg, int *result) + return 0; + } + +-int nouveau_hybrid_setup(struct drm_device *dev) ++static int nouveau_hybrid_setup(struct drm_device *dev) + { + int result; + +@@ -110,7 +113,7 @@ int nouveau_hybrid_setup(struct drm_device *dev) + return 0; + } + +-bool nouveau_dsm_probe(struct drm_device *dev) ++static bool nouveau_dsm_probe(struct drm_device *dev) + { + int support = 0; + +@@ -123,3 +126,67 @@ bool nouveau_dsm_probe(struct drm_device *dev) + + return true; + } ++ ++int nouveau_acpi_get_edid(struct drm_device *dev, ++ struct drm_connector *connector, ++ struct edid **pedid) ++{ ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ void *edid; ++ int connector_type = 0; ++ int ret; ++ ++ switch (connector->connector_type) { ++ case DRM_MODE_CONNECTOR_VGA: ++ connector_type = ACPI_VIDEO_DISPLAY_CRT; ++ break; ++ case DRM_MODE_CONNECTOR_Composite: ++ case DRM_MODE_CONNECTOR_SVIDEO: ++ case DRM_MODE_CONNECTOR_Component: ++ case DRM_MODE_CONNECTOR_9PinDIN: ++ connector_type = ACPI_VIDEO_DISPLAY_TV; ++ break; ++ case DRM_MODE_CONNECTOR_DVII: ++ case DRM_MODE_CONNECTOR_DVID: ++ case DRM_MODE_CONNECTOR_HDMIA: ++ case DRM_MODE_CONNECTOR_HDMIB: ++ case DRM_MODE_CONNECTOR_DisplayPort: ++ connector_type = ACPI_VIDEO_DISPLAY_DVI; ++ break; ++ case DRM_MODE_CONNECTOR_LVDS: ++ connector_type = ACPI_VIDEO_DISPLAY_LCD; ++ break; ++ } ++ ++ ret = acpi_video_get_edid(dev_priv->acpi_device, connector_type, -1, &edid); ++ ++ if (ret < 0) ++ return ret; ++ ++ *pedid = edid; ++ return 0; ++} ++ ++int nouveau_acpi_setup(struct drm_device *dev) ++{ ++ struct pci_dev *pdev = dev->pdev; ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ acpi_handle handle; ++ struct acpi_device *acpi_dev; ++ ++ handle = DEVICE_ACPI_HANDLE(&pdev->dev); ++ ++ if (!handle) ++ return -ENODEV; ++ ++ if (acpi_bus_get_device(handle, &acpi_dev)) ++ return -ENODEV; ++ ++ dev_priv->acpi_device = acpi_dev; ++ dev_priv->acpi_dsm = nouveau_dsm_probe(dev); ++ ++ if (dev_priv->acpi_dsm) ++ nouveau_hybrid_setup(dev); ++ ++ return 0; ++} +diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c +index fb51958..5832b60 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_connector.c ++++ b/drivers/gpu/drm/nouveau/nouveau_connector.c +@@ -356,6 +356,14 @@ nouveau_connector_detect_lvds(struct drm_connector *connector) + } + } + ++ /* Let's try ACPI */ ++ if (status != connector_status_connected && ++ !dev_priv->vbios.fp_no_ddc) { ++ nouveau_acpi_get_edid(dev, connector, &nv_connector->edid); ++ if (nv_connector->edid) ++ status = connector_status_connected; ++ } ++ + out: + #ifdef CONFIG_ACPI + if (status == connector_status_connected && +diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h +index c31159a..675d7ac 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_drv.h ++++ b/drivers/gpu/drm/nouveau/nouveau_drv.h +@@ -39,6 +39,8 @@ + #define NOUVEAU_FAMILY 0x0000FFFF + #define NOUVEAU_FLAGS 0xFFFF0000 + ++#include ++ + #include "ttm/ttm_bo_api.h" + #include "ttm/ttm_bo_driver.h" + #include "ttm/ttm_placement.h" +@@ -615,7 +617,11 @@ struct drm_nouveau_private { + } susres; + + struct backlight_device *backlight; ++ ++#ifdef CONFIG_ACPI + bool acpi_dsm; ++ struct acpi_device *acpi_device; ++#endif + + struct nouveau_channel *evo; + +@@ -846,16 +852,20 @@ extern int nouveau_dma_wait(struct nouveau_channel *, int slots, int size); + + /* nouveau_acpi.c */ + #ifdef CONFIG_ACPI +-extern int nouveau_hybrid_setup(struct drm_device *dev); +-extern bool nouveau_dsm_probe(struct drm_device *dev); ++extern int nouveau_acpi_setup(struct drm_device *dev); ++extern int nouveau_acpi_get_edid(struct drm_device *dev, ++ struct drm_connector *connector, ++ struct edid **edid); + #else +-static inline int nouveau_hybrid_setup(struct drm_device *dev) ++static inline int nouveau_acpi_setup(struct drm_device *dev) + { + return 0; + } +-static inline bool nouveau_dsm_probe(struct drm_device *dev) ++static inline int nouveau_acpi_get_edid(struct drm_device *dev, ++ struct drm_connector *connector, ++ struct edid **edid) + { +- return false; ++ return -ENODEV; + } + #endif + +diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c +index 7c1d252..7ca9465 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_state.c ++++ b/drivers/gpu/drm/nouveau/nouveau_state.c +@@ -627,10 +627,7 @@ int nouveau_load(struct drm_device *dev, unsigned long flags) + NV_DEBUG(dev, "vendor: 0x%X device: 0x%X class: 0x%X\n", + dev->pci_vendor, dev->pci_device, dev->pdev->class); + +- dev_priv->acpi_dsm = nouveau_dsm_probe(dev); +- +- if (dev_priv->acpi_dsm) +- nouveau_hybrid_setup(dev); ++ nouveau_acpi_setup(dev); + + dev_priv->wq = create_workqueue("nouveau"); + if (!dev_priv->wq) +-- +1.7.1 + diff --git a/drm-nouveau-drm-fixed-header.patch b/drm-nouveau-drm-fixed-header.patch new file mode 100644 index 000000000..83df54f9f --- /dev/null +++ b/drm-nouveau-drm-fixed-header.patch @@ -0,0 +1,86 @@ +From 841045c942be3fd2bf928a7de3e730a00665347e Mon Sep 17 00:00:00 2001 +From: Ben Skeggs +Date: Wed, 28 Apr 2010 15:19:10 +1000 +Subject: [PATCH 3/3] drm-nouveau-drm-fixed-header + +--- + drivers/gpu/drm/nouveau/drm_fixed.h | 67 +++++++++++++++++++++++++++++++++++ + 1 files changed, 67 insertions(+), 0 deletions(-) + create mode 100644 drivers/gpu/drm/nouveau/drm_fixed.h + +diff --git a/drivers/gpu/drm/nouveau/drm_fixed.h b/drivers/gpu/drm/nouveau/drm_fixed.h +new file mode 100644 +index 0000000..4a08a66 +--- /dev/null ++++ b/drivers/gpu/drm/nouveau/drm_fixed.h +@@ -0,0 +1,67 @@ ++/* ++ * Copyright 2009 Red Hat Inc. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR ++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ++ * OTHER DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Dave Airlie ++ */ ++#ifndef DRM_FIXED_H ++#define DRM_FIXED_H ++ ++typedef union dfixed { ++ u32 full; ++} fixed20_12; ++ ++ ++#define dfixed_const(A) (u32)(((A) << 12))/* + ((B + 0.000122)*4096)) */ ++#define dfixed_const_half(A) (u32)(((A) << 12) + 2048) ++#define dfixed_const_666(A) (u32)(((A) << 12) + 2731) ++#define dfixed_const_8(A) (u32)(((A) << 12) + 3277) ++#define dfixed_mul(A, B) ((u64)((u64)(A).full * (B).full + 2048) >> 12) ++#define dfixed_init(A) { .full = dfixed_const((A)) } ++#define dfixed_init_half(A) { .full = dfixed_const_half((A)) } ++#define dfixed_trunc(A) ((A).full >> 12) ++ ++static inline u32 dfixed_floor(fixed20_12 A) ++{ ++ u32 non_frac = dfixed_trunc(A); ++ ++ return dfixed_const(non_frac); ++} ++ ++static inline u32 dfixed_ceil(fixed20_12 A) ++{ ++ u32 non_frac = dfixed_trunc(A); ++ ++ if (A.full > dfixed_const(non_frac)) ++ return dfixed_const(non_frac + 1); ++ else ++ return dfixed_const(non_frac); ++} ++ ++static inline u32 dfixed_div(fixed20_12 A, fixed20_12 B) ++{ ++ u64 tmp = ((u64)A.full << 13); ++ ++ do_div(tmp, B.full); ++ tmp += 1; ++ tmp /= 2; ++ return lower_32_bits(tmp); ++} ++#endif +-- +1.7.1 + diff --git a/drm-nouveau-updates.patch b/drm-nouveau-updates.patch new file mode 100644 index 000000000..c6b39f9b9 --- /dev/null +++ b/drm-nouveau-updates.patch @@ -0,0 +1,9174 @@ +From 1fe467ac55c8503078f679b1f503e4895d6c5895 Mon Sep 17 00:00:00 2001 +From: Marcin Slusarz +Date: Wed, 17 Feb 2010 19:04:00 +0100 +Subject: [PATCH 1/3] drm-nouveau-updates +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +drm/nouveau: fix pramdac_table range checking + +get_tmds_index_reg reads some value from stack when mlv happens +to be equal to size of pramdac_table array. Fix it. + +Reported-by: Dan Carpenter +Signed-off-by: Marcin Slusarz +Signed-off-by: Francisco Jerez + +drm/nouveau: fix nouveau_i2c_find bounds checking + +Reported-by: Dan Carpenter +Signed-off-by: Marcin Slusarz +Signed-off-by: Francisco Jerez + +drm/nouveau: fix i2ctable bounds checking + +i2c_entries seems to be the number of i2c entries, +so with index equal to this number, we could read +invalid data from i2ctable. Fix it. + +Signed-off-by: Marcin Slusarz +Signed-off-by: Francisco Jerez + +drm/nouveau: allow retrieval of vbios image from debugfs + +It's very useful to be able to access this without additional tools for +debugging purposes. + +Signed-off-by: Ben Skeggs + +drm/nouveau: rename parsed_dcb_gpio to dcb_gpio_table + +Signed-off-by: Ben Skeggs + +drm/nouveau: merge parsed_dcb and bios_parsed_dcb into dcb_table + +Signed-off-by: Ben Skeggs + +drm/nouveau: merge nvbios and nouveau_bios_info + +Signed-off-by: Ben Skeggs + +drm/nouveau: reorganise bios header, add dcb connector type enums + +Signed-off-by: Ben Skeggs + +drm/nouveau: parse dcb gpio/connector tables after encoders + +Signed-off-by: Ben Skeggs + +drm/nouveau: check for known dcb connector types + +Signed-off-by: Ben Skeggs + +drm/nouveau: construct a connector table for cards that lack a real one + +Signed-off-by: Ben Skeggs + +drm/nouveau: use dcb connector table for creating drm connectors + +This makes this code common to both the nv04 and nv50 paths. + +For the moment, we keep the previous behaviour with HDMI/eDP connectors +and report them as DVI-D/DP instead. This will be fixed once the rest +of the code has been fixed to deal with those types. + +Signed-off-by: Ben Skeggs + +drm/nv50: enable hpd on any connector we know the gpio line for + +Signed-off-by: Ben Skeggs + +drm/nouveau: use dcb connector types throughout the driver + +Signed-off-by: Ben Skeggs + +drm/nv50: Implement ctxprog/state generation. + +This removes dependence on external firmware for NV50 generation cards. +If the generated ctxprogs don't work for you for some reason, please +report it. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nouveau: Fix noaccel/nofbaccel option descriptions. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nouveau: support version 0x20 displayport tables + +Not entirely identical to 0x21, the per-encoder table header lacks the +third init table pointer. However, our current parsing of the table +should work just fine. + +Signed-off-by: Ben Skeggs + +drm/nouveau: report unknown connector state if lid closed + +This is in preference to disconnected. If there's no other outputs +connected this will cause LVDS to be programmed even with the lid +closed rather than having X fail to start because of no available +outputs. + +Signed-off-by: Ben Skeggs + +drm/nouveau: use ALIGN instead of open coding it + +CC: Ben Skeggs +Signed-off-by: Matt Turner +Signed-off-by: Ben Skeggs + +drm/nouveau: protect channel create/destroy and irq handler with a spinlock + +The nv50 pgraph handler (for example) could reenable pgraph fifo access +and that would be bad when pgraph context is being unloaded (we need the +guarantee a ctxprog isn't running). + +Signed-off-by: Maarten Maathuis +Signed-off-by: Ben Skeggs + +drm/nv50: Remove redundant/incorrect ctxvals initialisation. + +11c/004 offset corresponds to PGRAPH reg 0x400828, and is initialised +earlier anyway by both our ctxprog generator and blob ctxvals. It's +actually incorrect with the generator, since we use different layout +on pre-NVA0. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nouveau: Fix fbcon corruption with font width not divisible by 8 + +NV50 is nice and has a switch that autoaligns stuff for us. Pre-NV50, +we need to align input bitmap width manually. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Francisco Jerez + +drm/nv50: Make ctxprog wait until interrupt handler is done. + +This will fix races between generated ctxprogs and interrupt handler. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nv50: Improve PGRAPH interrupt handling. + +This makes nouveau recognise and report more kinds of PGRAPH errors, as +well as prevent GPU lockups resulting from some of them. + +Lots of guesswork was involved and some part of this is probably +incorrect. Some potential-lockuop situations are handled by just +resetting a whole PGRAPH subunit, which doesn't sound like a "proper" +solution, but seems to work just fine... for now. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nouveau: add option to allow override of dcb connector table types + +Signed-off-by: Ben Skeggs + +drm/nouveau: Gigabyte NX85T connector table lies, it has DVI-I not HDMI + +Signed-off-by: Ben Skeggs + +drm/nv04-nv40: Fix up the programmed horizontal sync pulse delay. + +The calculated values were a little bit off (~16 clocks), the only +effect it could have had is a slightly offset image with respect to +the blob on analog outputs (bug 26790). + +Signed-off-by: Francisco Jerez + +drm/nouveau: print a message very early during suspend + +- In case of suspend lockups it's nice to know it happened in nouveau. + +Signed-off-by: Maarten Maathuis + +drm/nv50: add a memory barrier to pushbuf submission + +- This is useful for vram pushbuffers that are write combined. +- pre-nv50 has one too (in WRITE_PUT). + +Signed-off-by: Maarten Maathuis + +drm/nv50: fix connector table parsing for some cards + +The connector table index in the DCB entry for each output type is an +index into the connector table, and does *not* necessarily match up +with what was previously called "index" in the connector table entries +themselves. + +Not real sure what that index is exactly, renamed to "index2" as we +still use it to prevent creating multiple TV connectors. + +Signed-off-by: Ben Skeggs + +drm/nouveau: Never evict VRAM buffers to system. + +VRAM->system is a synchronous operation: it involves scheduling a +VRAM->TT DMA transfer and stalling the CPU until it's finished so that +we can unbind the new memory from the translation tables. VRAM->TT can +always be performed asynchronously, even if TT is already full and we +have to move something out of it. + +Additionally, allowing VRAM->system behaves badly under heavy memory +pressure because once we run out of TT, stuff starts to be moved back +and forth between VRAM and system, and the TT contents are hardly +renewed. + +Signed-off-by: Francisco Jerez + +drm/nouveau: add module option to disable TV detection + +Intended to be used as a workaround in cases where we falsely detect +that a TV is connected when it's not. + +Signed-off-by: Ben Skeggs + +drm/nv50: add more 0x100c80 flushy magic + +Fixes the !vbo_fifo path in the 3D driver on certain chipsets. Still not +really any good idea of what exactly the magic achieves, but it makes +things work. + +While we're at it, in the PCIEGART path, flush on unbinding also. + +Signed-off-by: Ben Skeggs + +drm/nouveau: bail out of auxch transaction if we repeatedly recieve defers + +There's one known case where we never stop recieving DEFER, and loop here +forever. Lets not do that.. + +Signed-off-by: Ben Skeggs + +drm/nv50: fix fbcon when framebuffer above 4GiB mark + +This can't actually happen right now, but lets fix it anyway. + +Signed-off-by: Ben Skeggs + +drm/nv50: Fix NEWCTX_DONE flag number + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nouveau: remove some unused members from drm_nouveau_private + +Signed-off-by: Ben Skeggs + +drm/nouveau: detect vram amount once, and save the value + +As opposed to repeatedly reading the amount back from the GPU every +time we need to know the VRAM size. + +We should now fail to load gracefully on detecting no VRAM, rather than +something potentially messy happening. + +Signed-off-by: Ben Skeggs + +drm/nv40: rework lvds table parsing + +All indications seem to be that the version 0x30 table should be handled +the same way as 0x40 (as used on G80), at least for the parts that we +currently try use. + +This commit cleans up the parsing to make it clearer about what we're +actually trying to achieve, and unifies the 0x30/0x40 parsing. + +Signed-off-by: Ben Skeggs + +drm/nv40: add LVDS table quirk for Dell Latitude D620 + +Should fix: + https://bugzilla.redhat.com/show_bug.cgi?id=505132 + https://bugzilla.redhat.com/show_bug.cgi?id=543091 + https://bugzilla.redhat.com/show_bug.cgi?id=530425 + https://bugs.edge.launchpad.net/ubuntu/+source/xserver-xorg-video-nouveau/ + +bug/539730 + +Signed-off-by: Ben Skeggs + +drm/nv50: fix instmem init on IGPs if stolen mem crosses 4GiB mark + +Signed-off-by: Ben Skeggs + +drm/nouveau: fixup the init failure paths some more + +Signed-off-by: Ben Skeggs + +drm/nv50: move pdisp init earlier, and cleanup if it fails + +Moving it earlier is to avoid some extra cleanup if it fails. + +Signed-off-by: Ben Skeggs + +drm/nv50: Allow using the NVA3 new compute class. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nouveau: Make use of TTM busy_placements. + +Previously we were filling it the same as "placements", but in some +cases there're valid alternatives that we were ignoring completely. +Keeping a back-up memory type helps on several low-mem situations. + +Signed-off-by: Francisco Jerez + +drm/nv50: preserve an unknown SOR_MODECTRL value for DP encoders + +This value interacts with some registers we don't currently know how to +program properly ourselves. The default of 5 that we were using matches +what the VBIOS on early DP cards do, but later ones use 6, which would +cause nouveau to program an incorrect mode on these chips. + +Signed-off-by: Ben Skeggs + +drm/nv50: punt hotplug irq handling out to workqueue + +On DP outputs we'll likely end up running vbios init tables here, which +may sleep. + +Signed-off-by: Ben Skeggs + +drm/nv50: partially revert ec99dbe438787d62ecde3a22f8ce3f880a4f4e14 + +The commit mentioned above breaks the DP SOR_MODE_CTRL detection as once +nv50_display_init() has been called all the MODE_CTRL registers are reset. + +This wasn't noticed when initially writing the DP SOR_MODE_CTRL patch +as it was done on another machine, without ec99dbe..4e14 applied. + +This commit moves the nv50_display_init() call to back where it was, +after the KMS setup, and adds the additional cleanup needed. + +Signed-off-by: Ben Skeggs + +drm/nv50: another dodgy DP hack + +Allows *some* DP cards to keep working in some corner cases that most +people shouldn't hit. I hit it all the time with development, so this +can stay for now. + +Signed-off-by: Ben Skeggs + +drm/nv50: Add NVA3 support in ctxprog/ctxvals generator. + +Signed-off-by: Marcin Kościelnicki +Signed-off-by: Ben Skeggs + +drm/nv40: Init some tiling-related PGRAPH state. + +Fixes garbled 3D on an nv46 card. + +Reported-by: Francesco Marella +Signed-off-by: Francisco Jerez + +drm/nouveau: store raw gpio table entry in bios gpio structs + +And use our own version of the GPIO table for the INIT_GPIO opcode. + +Signed-off-by: Ben Skeggs + +drm/nv50: parse/use some more de-magiced parts of gpio table entries + +Signed-off-by: Ben Skeggs + +drm/nv50: implement gpio set/get routines + +Signed-off-by: Ben Skeggs + +Revert "drm/nouveau: report unknown connector state if lid closed" + +Included in upstream stable point-release. + +This reverts commit b30083bdb990bcc2829fce83d871a86059ff4fc1. + +drm/nouveau: fix a nouveau_bo dereference after it's been destroyed + +Signed-off-by: Ben Skeggs + +drm/nouveau: bios parser fixes for eDP boards + +Signed-off-by: Ben Skeggs + +drm/nouveau: dump pll limits entries when debugging is on + +Signed-off-by: Ben Skeggs + +drm/nv50: output calculated crtc pll when debugging on + +Signed-off-by: Ben Skeggs + +drm/nv50: fix suspend/resume with DP outputs + +Signed-off-by: Ben Skeggs + +drm/nv50: store full dcb i2c entry from vbios + +Signed-off-by: Ben Skeggs + +drm/nv50: fix monitor detection on certain chipsets + +There appears to be some kind of switch on certain chips to control whether +the DP auxch or traditional i2c bus will be operational on a connector, +this commit hopefully fixes nouveau to do the right thing. + +Likely only relevent on chips with DP outputs. + +Signed-off-by: Ben Skeggs + +drm/nv50: send hotplug event to userspace + +Signed-off-by: Ben Skeggs + +drm/nv50: support fractional feedback divider on newer chips + +Signed-off-by: Ben Skeggs + +drm/nouveau: don't execute INIT_GPIO unless we're really running the table + +This resulted in accidently switching off the eDP panel on certain laptops +since the default state in the GPIO table was off. + +Fixes rh#582621 + +Signed-off-by: Ben Skeggs + +drm/nv50: fix iommu errors caused by device reading from address 0 + +Signed-off-by: Ben Skeggs + +drm/nouveau: fix POST detection for certain chipsets + +We totally fail at detecting un-POSTed chipsets prior to G80. This commit +changes the pre-G80 POST detection to read the programmed horizontal total +from CRTC 0, and assume the card isn't POSTed if it's 0. + +NVIDIA use some other heuristics more similar to what we do on G80, but I +wasted quite a long time trying to figure out the exact specifics of what +they do so we can try this for a bit instead. + +Signed-off-by: Ben Skeggs + +drm/nv40: allow cold-booting of nv4x chipsets + +Signed-off-by: Ben Skeggs + +drm/nouveau: fix init table handlers to return proper error codes + +We really want to be able to distinguish between INIT_DONE and an actual +error sometimes. This commit fixes up several lazy "return 0;" to be +actual error codes, and explicitly reserves "0" as "success, but stop +parsing this table". + +Signed-off-by: Ben Skeggs + +drm/nouveau: display error message for any failed init table opcode + +Some handlers don't report specific errors, but we still *really* want to +know if we failed to parse a complete init table. + +Signed-off-by: Ben Skeggs + +drm/nouveau: ensure we've parsed i2c table entry for INIT_*I2C* handlers + +We may not have parsed the entry yet if the i2c_index is for an i2c bus +that's not referenced by a DCB encoder. + +This could be done oh so much more nicely, except we have to care about +prehistoric DCB tables too, and they make life painful. + +Signed-off-by: Ben Skeggs + +drm/nouveau: support init table i2c device identifier 0x81 + +It appears to be meant to reference the second "default index". + +Signed-off-by: Ben Skeggs + +drm/nouveau: fix i2c-related init table handlers + +Mutliple issues. INIT_ZM_I2C_BYTE/INIT_I2C_BYTE didn't even try and +use the register value, and all the handlers were using the wrong +slave address. + +Signed-off-by: Ben Skeggs + +drm/nv50: cast IGP memory location to u64 before shifting + +Signed-off-by: Ben Skeggs + +drm/nouveau: match U/DP script against SOR link + +It appears version 0x21 'U' and 'd' tables require us to take the SOR link +into account when selecting the appropriate table for a particular output. + +Signed-off-by: Ben Skeggs + +drm/nv50: fix memory detection for cards with >=4GiB VRAM + +Signed-off-by: Ben Skeggs + +drm/nouveau: completely fail init if we fail to map the PRAMIN BAR + +On cards where there's a specific BAR for PRAMIN, we used to try and fall +back to the "legacy" aperture within the mmio BAR. + +This is doomed to cause problems, so lets just fail completely as there's +obviously something else very wrong anyway. + +Signed-off-by: Ben Skeggs + +drm/nouveau: Don't clear AGPCMD completely on INIT_RESET. + +We just need to clear the SBA and ENABLE bits to reset the AGP +controller: If the AGP bridge was configured to use "fast writes", +clearing the FW bit would break the subsequent MMIO writes and +eventually end with a lockup. + +Note that all the BIOSes I've seen do the same as we did (it works for +them because they don't use MMIO), OTOH the blob leaves FW untouched. + +Signed-off-by: Francisco Jerez + +drm/nouveau: Ignore broken legacy I2C entries. + +The nv05 card in the bug report [1] doesn't have usable I2C port +register offsets (they're all filled with zeros). Ignore them and use +the defaults. + +[1] http://bugs.launchpad.net/bugs/569505 + +Signed-off-by: Francisco Jerez + +drm/nv50: use alternate source of SOR_MODE_CTRL for DP hack + +Fixes module unload+reload on Dell M4500, where the "normal" registers +get reset to 0. + +Signed-off-by: Ben Skeggs + +drm/nv50: fix duallink_possible calculation for DCB 4.0 cards + +Signed-off-by: Ben Skeggs + +drm/nv50: obey dcb->duallink_possible + +It was once assumed that all G8x had dual-link TMDS everywhere, this isn't +actually the case - especially considering passive DP->DVI converters and +some HDMI connectors only support single-link. + +Signed-off-by: Ben Skeggs + +drm/nouveau: fix dual-link displays when plugged into single-link outputs + +When selecting the native mode for a display we weren't taking into account +whether or not it was actually supported on that particular output. + +This patch modifies our native mode selection to run all modes through +mode_valid() first. + +Signed-off-by: Ben Skeggs + +drm/nouveau: reduce usage of fence spinlock to when absolutely necessary + +Signed-off-by: Ben Skeggs + +drm/nouveau: move LVDS detection back to connector detect() time + +Signed-off-by: Ben Skeggs + +drm/nouveau: Put the dithering check back in nouveau_connector_create. + +a7b9f9e5adef dropped it by accident. + +Signed-off-by: Francisco Jerez +Tested-by: Thibaut Girka + +drm/nouveau: set encoder for lvds + +fixes oops in nouveau_connector_get_modes with nv_encoder is NULL + +Signed-off-by: Albert Damen +Signed-off-by: Francisco Jerez + +drm/nouveau: tidy connector/encoder creation a little + +Create connectors before encoders to avoid having to do another loop across +encoder list whenever we create a new connector. This allows us to pass +the connector to the encoder creation functions, and avoid using a +create_resources() callback since we can now call it directly. + +This can also potentially modify the connector ordering on nv50. On cards +where the DCB connector and encoder tables are in the same order, things +will be unchanged. However, there's some cards where the ordering between +the tables differ, and in one case, leads us to naming the connectors +"wrongly". + +Signed-off-by: Ben Skeggs + +drm/nv50: fix regression caused by ed15e77b6ee7c4fa6f50c18b3325e7f96ed3aade + +It became possible for us to have connectors present without any encoders +attached (TV out, we don't support TVDAC yet), which caused the DDX to +segfault. + +Signed-off-by: Ben Skeggs + +drm/nv04: fix regression caused by ed15e77b6ee7c4fa6f50c18b3325e7f96ed3aade + +Signed-off-by: Ben Skeggs +--- + drivers/gpu/drm/nouveau/Makefile | 7 +- + drivers/gpu/drm/nouveau/nouveau_bios.c | 1057 ++++++++----- + drivers/gpu/drm/nouveau/nouveau_bios.h | 133 +- + drivers/gpu/drm/nouveau/nouveau_bo.c | 68 +- + drivers/gpu/drm/nouveau/nouveau_calc.c | 4 +- + drivers/gpu/drm/nouveau/nouveau_channel.c | 17 +- + drivers/gpu/drm/nouveau/nouveau_connector.c | 383 +++--- + drivers/gpu/drm/nouveau/nouveau_connector.h | 3 +- + drivers/gpu/drm/nouveau/nouveau_debugfs.c | 18 +- + drivers/gpu/drm/nouveau/nouveau_dma.c | 5 + + drivers/gpu/drm/nouveau/nouveau_dp.c | 8 +- + drivers/gpu/drm/nouveau/nouveau_drv.c | 14 +- + drivers/gpu/drm/nouveau/nouveau_drv.h | 70 +- + drivers/gpu/drm/nouveau/nouveau_encoder.h | 7 +- + drivers/gpu/drm/nouveau/nouveau_fence.c | 31 +- + drivers/gpu/drm/nouveau/nouveau_gem.c | 55 +- + drivers/gpu/drm/nouveau/nouveau_hw.c | 6 +- + drivers/gpu/drm/nouveau/nouveau_i2c.c | 23 +- + drivers/gpu/drm/nouveau/nouveau_irq.c | 615 +++++++- + drivers/gpu/drm/nouveau/nouveau_mem.c | 129 +- + drivers/gpu/drm/nouveau/nouveau_reg.h | 1 + + drivers/gpu/drm/nouveau/nouveau_sgdma.c | 18 + + drivers/gpu/drm/nouveau/nouveau_state.c | 39 +- + drivers/gpu/drm/nouveau/nv04_crtc.c | 6 +- + drivers/gpu/drm/nouveau/nv04_dac.c | 15 +- + drivers/gpu/drm/nouveau/nv04_dfp.c | 12 +- + drivers/gpu/drm/nouveau/nv04_display.c | 64 +- + drivers/gpu/drm/nouveau/nv04_fbcon.c | 6 +- + drivers/gpu/drm/nouveau/nv04_fifo.c | 5 + + drivers/gpu/drm/nouveau/nv04_graph.c | 3 +- + drivers/gpu/drm/nouveau/nv04_tv.c | 10 +- + drivers/gpu/drm/nouveau/nv17_tv.c | 12 +- + drivers/gpu/drm/nouveau/nv40_fifo.c | 7 +- + drivers/gpu/drm/nouveau/nv40_graph.c | 21 + + drivers/gpu/drm/nouveau/nv50_calc.c | 87 + + drivers/gpu/drm/nouveau/nv50_crtc.c | 46 +- + drivers/gpu/drm/nouveau/nv50_dac.c | 13 +- + drivers/gpu/drm/nouveau/nv50_display.c | 122 +- + drivers/gpu/drm/nouveau/nv50_display.h | 1 + + drivers/gpu/drm/nouveau/nv50_fb.c | 38 + + drivers/gpu/drm/nouveau/nv50_fbcon.c | 17 +- + drivers/gpu/drm/nouveau/nv50_fifo.c | 5 + + drivers/gpu/drm/nouveau/nv50_gpio.c | 76 + + drivers/gpu/drm/nouveau/nv50_graph.c | 103 +- + drivers/gpu/drm/nouveau/nv50_grctx.c | 2383 +++++++++++++++++++++++++++ + drivers/gpu/drm/nouveau/nv50_instmem.c | 18 +- + drivers/gpu/drm/nouveau/nv50_sor.c | 42 +- + 47 files changed, 4702 insertions(+), 1121 deletions(-) + create mode 100644 drivers/gpu/drm/nouveau/nv50_calc.c + create mode 100644 drivers/gpu/drm/nouveau/nv50_fb.c + create mode 100644 drivers/gpu/drm/nouveau/nv50_gpio.c + create mode 100644 drivers/gpu/drm/nouveau/nv50_grctx.c + +diff --git a/drivers/gpu/drm/nouveau/Makefile b/drivers/gpu/drm/nouveau/Makefile +index 48c290b..acd31ed 100644 +--- a/drivers/gpu/drm/nouveau/Makefile ++++ b/drivers/gpu/drm/nouveau/Makefile +@@ -12,17 +12,18 @@ nouveau-y := nouveau_drv.o nouveau_state.o nouveau_channel.o nouveau_mem.o \ + nouveau_dp.o nouveau_grctx.o \ + nv04_timer.o \ + nv04_mc.o nv40_mc.o nv50_mc.o \ +- nv04_fb.o nv10_fb.o nv40_fb.o \ ++ nv04_fb.o nv10_fb.o nv40_fb.o nv50_fb.o \ + nv04_fifo.o nv10_fifo.o nv40_fifo.o nv50_fifo.o \ + nv04_graph.o nv10_graph.o nv20_graph.o \ + nv40_graph.o nv50_graph.o \ +- nv40_grctx.o \ ++ nv40_grctx.o nv50_grctx.o \ + nv04_instmem.o nv50_instmem.o \ + nv50_crtc.o nv50_dac.o nv50_sor.o \ + nv50_cursor.o nv50_display.o nv50_fbcon.o \ + nv04_dac.o nv04_dfp.o nv04_tv.o nv17_tv.o nv17_tv_modes.o \ + nv04_crtc.o nv04_display.o nv04_cursor.o nv04_fbcon.o \ +- nv17_gpio.o ++ nv17_gpio.o nv50_gpio.o \ ++ nv50_calc.o + + nouveau-$(CONFIG_DRM_NOUVEAU_DEBUG) += nouveau_debugfs.o + nouveau-$(CONFIG_COMPAT) += nouveau_ioc32.o +diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c +index 0e9cd1d..1803cc4 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_bios.c ++++ b/drivers/gpu/drm/nouveau/nouveau_bios.c +@@ -26,6 +26,7 @@ + #define NV_DEBUG_NOTRACE + #include "nouveau_drv.h" + #include "nouveau_hw.h" ++#include "nouveau_encoder.h" + + /* these defines are made up */ + #define NV_CIO_CRE_44_HEADA 0x0 +@@ -256,6 +257,11 @@ static bool NVShadowVBIOS(struct drm_device *dev, uint8_t *data) + struct init_tbl_entry { + char *name; + uint8_t id; ++ /* Return: ++ * > 0: success, length of opcode ++ * 0: success, but abort further parsing of table (INIT_DONE etc) ++ * < 0: failure, table parsing will be aborted ++ */ + int (*handler)(struct nvbios *, uint16_t, struct init_exec *); + }; + +@@ -311,11 +317,11 @@ valid_reg(struct nvbios *bios, uint32_t reg) + + /* C51 has misaligned regs on purpose. Marvellous */ + if (reg & 0x2 || +- (reg & 0x1 && dev_priv->VBIOS.pub.chip_version != 0x51)) ++ (reg & 0x1 && dev_priv->vbios.chip_version != 0x51)) + NV_ERROR(dev, "======= misaligned reg 0x%08X =======\n", reg); + + /* warn on C51 regs that haven't been verified accessible in tracing */ +- if (reg & 0x1 && dev_priv->VBIOS.pub.chip_version == 0x51 && ++ if (reg & 0x1 && dev_priv->vbios.chip_version == 0x51 && + reg != 0x130d && reg != 0x1311 && reg != 0x60081d) + NV_WARN(dev, "=== C51 misaligned reg 0x%08X not verified ===\n", + reg); +@@ -420,7 +426,7 @@ bios_wr32(struct nvbios *bios, uint32_t reg, uint32_t data) + LOG_OLD_VALUE(bios_rd32(bios, reg)); + BIOSLOG(bios, " Write: Reg: 0x%08X, Data: 0x%08X\n", reg, data); + +- if (dev_priv->VBIOS.execute) { ++ if (dev_priv->vbios.execute) { + still_alive(); + nv_wr32(bios->dev, reg, data); + } +@@ -647,7 +653,7 @@ nv50_pll_set(struct drm_device *dev, uint32_t reg, uint32_t clk) + reg0 = (reg0 & 0xfff8ffff) | (pll.log2P << 16); + reg1 = (reg1 & 0xffff0000) | (pll.N1 << 8) | pll.M1; + +- if (dev_priv->VBIOS.execute) { ++ if (dev_priv->vbios.execute) { + still_alive(); + nv_wr32(dev, reg + 4, reg1); + nv_wr32(dev, reg + 0, reg0); +@@ -689,7 +695,7 @@ setPLL(struct nvbios *bios, uint32_t reg, uint32_t clk) + static int dcb_entry_idx_from_crtchead(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + + /* + * For the results of this function to be correct, CR44 must have been +@@ -700,7 +706,7 @@ static int dcb_entry_idx_from_crtchead(struct drm_device *dev) + + uint8_t dcb_entry = NVReadVgaCrtc5758(dev, bios->state.crtchead, 0); + +- if (dcb_entry > bios->bdcb.dcb.entries) { ++ if (dcb_entry > bios->dcb.entries) { + NV_ERROR(dev, "CR58 doesn't have a valid DCB entry currently " + "(%02X)\n", dcb_entry); + dcb_entry = 0x7f; /* unused / invalid marker */ +@@ -709,29 +715,121 @@ static int dcb_entry_idx_from_crtchead(struct drm_device *dev) + return dcb_entry; + } + ++static int ++read_dcb_i2c_entry(struct drm_device *dev, int dcb_version, uint8_t *i2ctable, int index, struct dcb_i2c_entry *i2c) ++{ ++ uint8_t dcb_i2c_ver = dcb_version, headerlen = 0, entry_len = 4; ++ int i2c_entries = DCB_MAX_NUM_I2C_ENTRIES; ++ int recordoffset = 0, rdofs = 1, wrofs = 0; ++ uint8_t port_type = 0; ++ ++ if (!i2ctable) ++ return -EINVAL; ++ ++ if (dcb_version >= 0x30) { ++ if (i2ctable[0] != dcb_version) /* necessary? */ ++ NV_WARN(dev, ++ "DCB I2C table version mismatch (%02X vs %02X)\n", ++ i2ctable[0], dcb_version); ++ dcb_i2c_ver = i2ctable[0]; ++ headerlen = i2ctable[1]; ++ if (i2ctable[2] <= DCB_MAX_NUM_I2C_ENTRIES) ++ i2c_entries = i2ctable[2]; ++ else ++ NV_WARN(dev, ++ "DCB I2C table has more entries than indexable " ++ "(%d entries, max %d)\n", i2ctable[2], ++ DCB_MAX_NUM_I2C_ENTRIES); ++ entry_len = i2ctable[3]; ++ /* [4] is i2c_default_indices, read in parse_dcb_table() */ ++ } ++ /* ++ * It's your own fault if you call this function on a DCB 1.1 BIOS -- ++ * the test below is for DCB 1.2 ++ */ ++ if (dcb_version < 0x14) { ++ recordoffset = 2; ++ rdofs = 0; ++ wrofs = 1; ++ } ++ ++ if (index == 0xf) ++ return 0; ++ if (index >= i2c_entries) { ++ NV_ERROR(dev, "DCB I2C index too big (%d >= %d)\n", ++ index, i2ctable[2]); ++ return -ENOENT; ++ } ++ if (i2ctable[headerlen + entry_len * index + 3] == 0xff) { ++ NV_ERROR(dev, "DCB I2C entry invalid\n"); ++ return -EINVAL; ++ } ++ ++ if (dcb_i2c_ver >= 0x30) { ++ port_type = i2ctable[headerlen + recordoffset + 3 + entry_len * index]; ++ ++ /* ++ * Fixup for chips using same address offset for read and ++ * write. ++ */ ++ if (port_type == 4) /* seen on C51 */ ++ rdofs = wrofs = 1; ++ if (port_type >= 5) /* G80+ */ ++ rdofs = wrofs = 0; ++ } ++ ++ if (dcb_i2c_ver >= 0x40) { ++ if (port_type != 5 && port_type != 6) ++ NV_WARN(dev, "DCB I2C table has port type %d\n", port_type); ++ ++ i2c->entry = ROM32(i2ctable[headerlen + recordoffset + entry_len * index]); ++ } ++ ++ i2c->port_type = port_type; ++ i2c->read = i2ctable[headerlen + recordoffset + rdofs + entry_len * index]; ++ i2c->write = i2ctable[headerlen + recordoffset + wrofs + entry_len * index]; ++ ++ return 0; ++} ++ + static struct nouveau_i2c_chan * + init_i2c_device_find(struct drm_device *dev, int i2c_index) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct bios_parsed_dcb *bdcb = &dev_priv->VBIOS.bdcb; ++ struct dcb_table *dcb = &dev_priv->vbios.dcb; + + if (i2c_index == 0xff) { + /* note: dcb_entry_idx_from_crtchead needs pre-script set-up */ + int idx = dcb_entry_idx_from_crtchead(dev), shift = 0; +- int default_indices = bdcb->i2c_default_indices; ++ int default_indices = dcb->i2c_default_indices; + +- if (idx != 0x7f && bdcb->dcb.entry[idx].i2c_upper_default) ++ if (idx != 0x7f && dcb->entry[idx].i2c_upper_default) + shift = 4; + + i2c_index = (default_indices >> shift) & 0xf; + } + if (i2c_index == 0x80) /* g80+ */ +- i2c_index = bdcb->i2c_default_indices & 0xf; ++ i2c_index = dcb->i2c_default_indices & 0xf; ++ else ++ if (i2c_index == 0x81) ++ i2c_index = (dcb->i2c_default_indices & 0xf0) >> 4; ++ ++ if (i2c_index > DCB_MAX_NUM_I2C_ENTRIES) { ++ NV_ERROR(dev, "invalid i2c_index 0x%x\n", i2c_index); ++ return NULL; ++ } ++ ++ /* Make sure i2c table entry has been parsed, it may not ++ * have been if this is a bus not referenced by a DCB encoder ++ */ ++ read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table, ++ i2c_index, &dcb->i2c[i2c_index]); + + return nouveau_i2c_find(dev, i2c_index); + } + +-static uint32_t get_tmds_index_reg(struct drm_device *dev, uint8_t mlv) ++static uint32_t ++get_tmds_index_reg(struct drm_device *dev, uint8_t mlv) + { + /* + * For mlv < 0x80, it is an index into a table of TMDS base addresses. +@@ -744,6 +842,7 @@ static uint32_t get_tmds_index_reg(struct drm_device *dev, uint8_t mlv) + */ + + struct drm_nouveau_private *dev_priv = dev->dev_private; ++ struct nvbios *bios = &dev_priv->vbios; + const int pramdac_offset[13] = { + 0, 0, 0x8, 0, 0x2000, 0, 0, 0, 0x2008, 0, 0, 0, 0x2000 }; + const uint32_t pramdac_table[4] = { +@@ -756,13 +855,12 @@ static uint32_t get_tmds_index_reg(struct drm_device *dev, uint8_t mlv) + dcb_entry = dcb_entry_idx_from_crtchead(dev); + if (dcb_entry == 0x7f) + return 0; +- dacoffset = pramdac_offset[ +- dev_priv->VBIOS.bdcb.dcb.entry[dcb_entry].or]; ++ dacoffset = pramdac_offset[bios->dcb.entry[dcb_entry].or]; + if (mlv == 0x81) + dacoffset ^= 8; + return 0x6808b0 + dacoffset; + } else { +- if (mlv > ARRAY_SIZE(pramdac_table)) { ++ if (mlv >= ARRAY_SIZE(pramdac_table)) { + NV_ERROR(dev, "Magic Lookup Value too big (%02X)\n", + mlv); + return 0; +@@ -817,7 +915,7 @@ init_io_restrict_prog(struct nvbios *bios, uint16_t offset, + NV_ERROR(bios->dev, + "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", + offset, config, count); +- return 0; ++ return -EINVAL; + } + + configval = ROM32(bios->data[offset + 11 + config * 4]); +@@ -919,7 +1017,7 @@ init_io_restrict_pll(struct nvbios *bios, uint16_t offset, + NV_ERROR(bios->dev, + "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", + offset, config, count); +- return 0; ++ return -EINVAL; + } + + freq = ROM16(bios->data[offset + 12 + config * 2]); +@@ -1066,6 +1164,126 @@ init_io_flag_condition(struct nvbios *bios, uint16_t offset, + } + + static int ++init_dp_condition(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) ++{ ++ /* ++ * INIT_DP_CONDITION opcode: 0x3A ('') ++ * ++ * offset (8 bit): opcode ++ * offset + 1 (8 bit): "sub" opcode ++ * offset + 2 (8 bit): unknown ++ * ++ */ ++ ++ struct bit_displayport_encoder_table *dpe = NULL; ++ struct dcb_entry *dcb = bios->display.output; ++ struct drm_device *dev = bios->dev; ++ uint8_t cond = bios->data[offset + 1]; ++ int dummy; ++ ++ BIOSLOG(bios, "0x%04X: subop 0x%02X\n", offset, cond); ++ ++ if (!iexec->execute) ++ return 3; ++ ++ dpe = nouveau_bios_dp_table(dev, dcb, &dummy); ++ if (!dpe) { ++ NV_ERROR(dev, "0x%04X: INIT_3A: no encoder table!!\n", offset); ++ return -EINVAL; ++ } ++ ++ switch (cond) { ++ case 0: ++ { ++ struct dcb_connector_table_entry *ent = ++ &bios->dcb.connector.entry[dcb->connector]; ++ ++ if (ent->type != DCB_CONNECTOR_eDP) ++ iexec->execute = false; ++ } ++ break; ++ case 1: ++ case 2: ++ if (!(dpe->unknown & cond)) ++ iexec->execute = false; ++ break; ++ case 5: ++ { ++ struct nouveau_i2c_chan *auxch; ++ int ret; ++ ++ auxch = nouveau_i2c_find(dev, bios->display.output->i2c_index); ++ if (!auxch) ++ return -ENODEV; ++ ++ ret = nouveau_dp_auxch(auxch, 9, 0xd, &cond, 1); ++ if (ret) ++ return ret; ++ ++ if (cond & 1) ++ iexec->execute = false; ++ } ++ break; ++ default: ++ NV_WARN(dev, "0x%04X: unknown INIT_3A op: %d\n", offset, cond); ++ break; ++ } ++ ++ if (iexec->execute) ++ BIOSLOG(bios, "0x%04X: continuing to execute\n", offset); ++ else ++ BIOSLOG(bios, "0x%04X: skipping following commands\n", offset); ++ ++ return 3; ++} ++ ++static int ++init_op_3b(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) ++{ ++ /* ++ * INIT_3B opcode: 0x3B ('') ++ * ++ * offset (8 bit): opcode ++ * offset + 1 (8 bit): crtc index ++ * ++ */ ++ ++ uint8_t or = ffs(bios->display.output->or) - 1; ++ uint8_t index = bios->data[offset + 1]; ++ uint8_t data; ++ ++ if (!iexec->execute) ++ return 2; ++ ++ data = bios_idxprt_rd(bios, 0x3d4, index); ++ bios_idxprt_wr(bios, 0x3d4, index, data & ~(1 << or)); ++ return 2; ++} ++ ++static int ++init_op_3c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) ++{ ++ /* ++ * INIT_3C opcode: 0x3C ('') ++ * ++ * offset (8 bit): opcode ++ * offset + 1 (8 bit): crtc index ++ * ++ */ ++ ++ uint8_t or = ffs(bios->display.output->or) - 1; ++ uint8_t index = bios->data[offset + 1]; ++ uint8_t data; ++ ++ if (!iexec->execute) ++ return 2; ++ ++ data = bios_idxprt_rd(bios, 0x3d4, index); ++ bios_idxprt_wr(bios, 0x3d4, index, data | (1 << or)); ++ return 2; ++} ++ ++static int + init_idx_addr_latched(struct nvbios *bios, uint16_t offset, + struct init_exec *iexec) + { +@@ -1169,7 +1387,7 @@ init_io_restrict_pll2(struct nvbios *bios, uint16_t offset, + NV_ERROR(bios->dev, + "0x%04X: Config 0x%02X exceeds maximal bound 0x%02X\n", + offset, config, count); +- return 0; ++ return -EINVAL; + } + + freq = ROM32(bios->data[offset + 11 + config * 4]); +@@ -1230,12 +1448,11 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + */ + + uint8_t i2c_index = bios->data[offset + 1]; +- uint8_t i2c_address = bios->data[offset + 2]; ++ uint8_t i2c_address = bios->data[offset + 2] >> 1; + uint8_t count = bios->data[offset + 3]; +- int len = 4 + count * 3; + struct nouveau_i2c_chan *chan; +- struct i2c_msg msg; +- int i; ++ int len = 4 + count * 3; ++ int ret, i; + + if (!iexec->execute) + return len; +@@ -1246,35 +1463,34 @@ init_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + + chan = init_i2c_device_find(bios->dev, i2c_index); + if (!chan) +- return 0; ++ return -ENODEV; + + for (i = 0; i < count; i++) { +- uint8_t i2c_reg = bios->data[offset + 4 + i * 3]; ++ uint8_t reg = bios->data[offset + 4 + i * 3]; + uint8_t mask = bios->data[offset + 5 + i * 3]; + uint8_t data = bios->data[offset + 6 + i * 3]; +- uint8_t value; ++ union i2c_smbus_data val; + +- msg.addr = i2c_address; +- msg.flags = I2C_M_RD; +- msg.len = 1; +- msg.buf = &value; +- if (i2c_transfer(&chan->adapter, &msg, 1) != 1) +- return 0; ++ ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0, ++ I2C_SMBUS_READ, reg, ++ I2C_SMBUS_BYTE_DATA, &val); ++ if (ret < 0) ++ return ret; + + BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Value: 0x%02X, " + "Mask: 0x%02X, Data: 0x%02X\n", +- offset, i2c_reg, value, mask, data); ++ offset, reg, val.byte, mask, data); + +- value = (value & mask) | data; ++ if (!bios->execute) ++ continue; + +- if (bios->execute) { +- msg.addr = i2c_address; +- msg.flags = 0; +- msg.len = 1; +- msg.buf = &value; +- if (i2c_transfer(&chan->adapter, &msg, 1) != 1) +- return 0; +- } ++ val.byte &= mask; ++ val.byte |= data; ++ ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0, ++ I2C_SMBUS_WRITE, reg, ++ I2C_SMBUS_BYTE_DATA, &val); ++ if (ret < 0) ++ return ret; + } + + return len; +@@ -1300,12 +1516,11 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + */ + + uint8_t i2c_index = bios->data[offset + 1]; +- uint8_t i2c_address = bios->data[offset + 2]; ++ uint8_t i2c_address = bios->data[offset + 2] >> 1; + uint8_t count = bios->data[offset + 3]; +- int len = 4 + count * 2; + struct nouveau_i2c_chan *chan; +- struct i2c_msg msg; +- int i; ++ int len = 4 + count * 2; ++ int ret, i; + + if (!iexec->execute) + return len; +@@ -1316,23 +1531,25 @@ init_zm_i2c_byte(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + + chan = init_i2c_device_find(bios->dev, i2c_index); + if (!chan) +- return 0; ++ return -ENODEV; + + for (i = 0; i < count; i++) { +- uint8_t i2c_reg = bios->data[offset + 4 + i * 2]; +- uint8_t data = bios->data[offset + 5 + i * 2]; ++ uint8_t reg = bios->data[offset + 4 + i * 2]; ++ union i2c_smbus_data val; ++ ++ val.byte = bios->data[offset + 5 + i * 2]; + + BIOSLOG(bios, "0x%04X: I2CReg: 0x%02X, Data: 0x%02X\n", +- offset, i2c_reg, data); +- +- if (bios->execute) { +- msg.addr = i2c_address; +- msg.flags = 0; +- msg.len = 1; +- msg.buf = &data; +- if (i2c_transfer(&chan->adapter, &msg, 1) != 1) +- return 0; +- } ++ offset, reg, val.byte); ++ ++ if (!bios->execute) ++ continue; ++ ++ ret = i2c_smbus_xfer(&chan->adapter, i2c_address, 0, ++ I2C_SMBUS_WRITE, reg, ++ I2C_SMBUS_BYTE_DATA, &val); ++ if (ret < 0) ++ return ret; + } + + return len; +@@ -1356,7 +1573,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + */ + + uint8_t i2c_index = bios->data[offset + 1]; +- uint8_t i2c_address = bios->data[offset + 2]; ++ uint8_t i2c_address = bios->data[offset + 2] >> 1; + uint8_t count = bios->data[offset + 3]; + int len = 4 + count; + struct nouveau_i2c_chan *chan; +@@ -1373,7 +1590,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + + chan = init_i2c_device_find(bios->dev, i2c_index); + if (!chan) +- return 0; ++ return -ENODEV; + + for (i = 0; i < count; i++) { + data[i] = bios->data[offset + 4 + i]; +@@ -1387,7 +1604,7 @@ init_zm_i2c(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + msg.len = count; + msg.buf = data; + if (i2c_transfer(&chan->adapter, &msg, 1) != 1) +- return 0; ++ return -EIO; + } + + return len; +@@ -1426,7 +1643,7 @@ init_tmds(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + + reg = get_tmds_index_reg(bios->dev, mlv); + if (!reg) +- return 0; ++ return -EINVAL; + + bios_wr32(bios, reg, + tmdsaddr | NV_PRAMDAC_FP_TMDS_CONTROL_WRITE_DISABLE); +@@ -1470,7 +1687,7 @@ init_zm_tmds_group(struct nvbios *bios, uint16_t offset, + + reg = get_tmds_index_reg(bios->dev, mlv); + if (!reg) +- return 0; ++ return -EINVAL; + + for (i = 0; i < count; i++) { + uint8_t tmdsaddr = bios->data[offset + 3 + i * 2]; +@@ -1909,7 +2126,8 @@ init_reset(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + /* no iexec->execute check by design */ + + pci_nv_19 = bios_rd32(bios, NV_PBUS_PCI_NV_19); +- bios_wr32(bios, NV_PBUS_PCI_NV_19, 0); ++ bios_wr32(bios, NV_PBUS_PCI_NV_19, pci_nv_19 & ~0xf00); ++ + bios_wr32(bios, reg, value1); + + udelay(10); +@@ -1945,7 +2163,7 @@ init_configure_mem(struct nvbios *bios, uint16_t offset, + uint32_t reg, data; + + if (bios->major_version > 2) +- return 0; ++ return -ENODEV; + + bios_idxprt_wr(bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX, bios_idxprt_rd( + bios, NV_VIO_SRX, NV_VIO_SR_CLOCK_INDEX) | 0x20); +@@ -2000,7 +2218,7 @@ init_configure_clk(struct nvbios *bios, uint16_t offset, + int clock; + + if (bios->major_version > 2) +- return 0; ++ return -ENODEV; + + clock = ROM16(bios->data[meminitoffs + 4]) * 10; + setPLL(bios, NV_PRAMDAC_NVPLL_COEFF, clock); +@@ -2033,7 +2251,7 @@ init_configure_preinit(struct nvbios *bios, uint16_t offset, + uint8_t cr3c = ((straps << 2) & 0xf0) | (straps & (1 << 6)); + + if (bios->major_version > 2) +- return 0; ++ return -ENODEV; + + bios_idxprt_wr(bios, NV_CIO_CRX__COLOR, + NV_CIO_CRE_SCRATCH4__INDEX, cr3c); +@@ -2572,48 +2790,37 @@ init_gpio(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + * each GPIO according to various values listed in each entry + */ + +- const uint32_t nv50_gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 }; ++ struct drm_nouveau_private *dev_priv = bios->dev->dev_private; + const uint32_t nv50_gpio_ctl[2] = { 0xe100, 0xe28c }; +- const uint8_t *gpio_table = &bios->data[bios->bdcb.gpio_table_ptr]; +- const uint8_t *gpio_entry; + int i; + +- if (!iexec->execute) +- return 1; +- +- if (bios->bdcb.version != 0x40) { +- NV_ERROR(bios->dev, "DCB table not version 4.0\n"); +- return 0; +- } +- +- if (!bios->bdcb.gpio_table_ptr) { +- NV_WARN(bios->dev, "Invalid pointer to INIT_8E table\n"); +- return 0; ++ if (dev_priv->card_type != NV_50) { ++ NV_ERROR(bios->dev, "INIT_GPIO on unsupported chipset\n"); ++ return -ENODEV; + } + +- gpio_entry = gpio_table + gpio_table[1]; +- for (i = 0; i < gpio_table[2]; i++, gpio_entry += gpio_table[3]) { +- uint32_t entry = ROM32(gpio_entry[0]), r, s, v; +- int line = (entry & 0x0000001f); ++ if (!iexec->execute) ++ return 1; + +- BIOSLOG(bios, "0x%04X: Entry: 0x%08X\n", offset, entry); ++ for (i = 0; i < bios->dcb.gpio.entries; i++) { ++ struct dcb_gpio_entry *gpio = &bios->dcb.gpio.entry[i]; ++ uint32_t r, s, v; + +- if ((entry & 0x0000ff00) == 0x0000ff00) +- continue; ++ BIOSLOG(bios, "0x%04X: Entry: 0x%08X\n", offset, gpio->entry); + +- r = nv50_gpio_reg[line >> 3]; +- s = (line & 0x07) << 2; +- v = bios_rd32(bios, r) & ~(0x00000003 << s); +- if (entry & 0x01000000) +- v |= (((entry & 0x60000000) >> 29) ^ 2) << s; +- else +- v |= (((entry & 0x18000000) >> 27) ^ 2) << s; +- bios_wr32(bios, r, v); ++ BIOSLOG(bios, "0x%04X: set gpio 0x%02x, state %d\n", ++ offset, gpio->tag, gpio->state_default); ++ if (bios->execute) ++ nv50_gpio_set(bios->dev, gpio->tag, gpio->state_default); + +- r = nv50_gpio_ctl[line >> 4]; +- s = (line & 0x0f); ++ /* The NVIDIA binary driver doesn't appear to actually do ++ * any of this, my VBIOS does however. ++ */ ++ /* Not a clue, needs de-magicing */ ++ r = nv50_gpio_ctl[gpio->line >> 4]; ++ s = (gpio->line & 0x0f); + v = bios_rd32(bios, r) & ~(0x00010001 << s); +- switch ((entry & 0x06000000) >> 25) { ++ switch ((gpio->entry & 0x06000000) >> 25) { + case 1: + v |= (0x00000001 << s); + break; +@@ -2669,7 +2876,7 @@ init_ram_restrict_zm_reg_group(struct nvbios *bios, uint16_t offset, + NV_ERROR(bios->dev, + "0x%04X: Zero block length - has the M table " + "been parsed?\n", offset); +- return 0; ++ return -EINVAL; + } + + strap_ramcfg = (bios_rd32(bios, NV_PEXTDEV_BOOT_0) >> 2) & 0xf; +@@ -2853,14 +3060,14 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + + if (!bios->display.output) { + NV_ERROR(dev, "INIT_AUXCH: no active output\n"); +- return 0; ++ return -EINVAL; + } + + auxch = init_i2c_device_find(dev, bios->display.output->i2c_index); + if (!auxch) { + NV_ERROR(dev, "INIT_AUXCH: couldn't get auxch %d\n", + bios->display.output->i2c_index); +- return 0; ++ return -ENODEV; + } + + if (!iexec->execute) +@@ -2873,7 +3080,7 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + ret = nouveau_dp_auxch(auxch, 9, addr, &data, 1); + if (ret) { + NV_ERROR(dev, "INIT_AUXCH: rd auxch fail %d\n", ret); +- return 0; ++ return ret; + } + + data &= bios->data[offset + 0]; +@@ -2882,7 +3089,7 @@ init_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + ret = nouveau_dp_auxch(auxch, 8, addr, &data, 1); + if (ret) { + NV_ERROR(dev, "INIT_AUXCH: wr auxch fail %d\n", ret); +- return 0; ++ return ret; + } + } + +@@ -2912,14 +3119,14 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + + if (!bios->display.output) { + NV_ERROR(dev, "INIT_ZM_AUXCH: no active output\n"); +- return 0; ++ return -EINVAL; + } + + auxch = init_i2c_device_find(dev, bios->display.output->i2c_index); + if (!auxch) { + NV_ERROR(dev, "INIT_ZM_AUXCH: couldn't get auxch %d\n", + bios->display.output->i2c_index); +- return 0; ++ return -ENODEV; + } + + if (!iexec->execute) +@@ -2930,7 +3137,7 @@ init_zm_auxch(struct nvbios *bios, uint16_t offset, struct init_exec *iexec) + ret = nouveau_dp_auxch(auxch, 8, addr, &bios->data[offset], 1); + if (ret) { + NV_ERROR(dev, "INIT_ZM_AUXCH: wr auxch fail %d\n", ret); +- return 0; ++ return ret; + } + } + +@@ -2947,6 +3154,9 @@ static struct init_tbl_entry itbl_entry[] = { + { "INIT_COPY" , 0x37, init_copy }, + { "INIT_NOT" , 0x38, init_not }, + { "INIT_IO_FLAG_CONDITION" , 0x39, init_io_flag_condition }, ++ { "INIT_DP_CONDITION" , 0x3A, init_dp_condition }, ++ { "INIT_OP_3B" , 0x3B, init_op_3b }, ++ { "INIT_OP_3C" , 0x3C, init_op_3c }, + { "INIT_INDEX_ADDRESS_LATCHED" , 0x49, init_idx_addr_latched }, + { "INIT_IO_RESTRICT_PLL2" , 0x4A, init_io_restrict_pll2 }, + { "INIT_PLL2" , 0x4B, init_pll2 }, +@@ -3014,7 +3224,7 @@ parse_init_table(struct nvbios *bios, unsigned int offset, + * is changed back to EXECUTE. + */ + +- int count = 0, i, res; ++ int count = 0, i, ret; + uint8_t id; + + /* +@@ -3029,26 +3239,33 @@ parse_init_table(struct nvbios *bios, unsigned int offset, + for (i = 0; itbl_entry[i].name && (itbl_entry[i].id != id); i++) + ; + +- if (itbl_entry[i].name) { +- BIOSLOG(bios, "0x%04X: [ (0x%02X) - %s ]\n", +- offset, itbl_entry[i].id, itbl_entry[i].name); +- +- /* execute eventual command handler */ +- res = (*itbl_entry[i].handler)(bios, offset, iexec); +- if (!res) +- break; +- /* +- * Add the offset of the current command including all data +- * of that command. The offset will then be pointing on the +- * next op code. +- */ +- offset += res; +- } else { ++ if (!itbl_entry[i].name) { + NV_ERROR(bios->dev, + "0x%04X: Init table command not found: " + "0x%02X\n", offset, id); + return -ENOENT; + } ++ ++ BIOSLOG(bios, "0x%04X: [ (0x%02X) - %s ]\n", offset, ++ itbl_entry[i].id, itbl_entry[i].name); ++ ++ /* execute eventual command handler */ ++ ret = (*itbl_entry[i].handler)(bios, offset, iexec); ++ if (ret < 0) { ++ NV_ERROR(bios->dev, "0x%04X: Failed parsing init " ++ "table opcode: %s %d\n", offset, ++ itbl_entry[i].name, ret); ++ } ++ ++ if (ret <= 0) ++ break; ++ ++ /* ++ * Add the offset of the current command including all data ++ * of that command. The offset will then be pointing on the ++ * next op code. ++ */ ++ offset += ret; + } + + if (offset >= bios->length) +@@ -3123,7 +3340,7 @@ run_digital_op_script(struct drm_device *dev, uint16_t scriptptr, + struct dcb_entry *dcbent, int head, bool dl) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + struct init_exec iexec = {true, false}; + + NV_TRACE(dev, "0x%04X: Parsing digital output script table\n", +@@ -3140,7 +3357,7 @@ run_digital_op_script(struct drm_device *dev, uint16_t scriptptr, + static int call_lvds_manufacturer_script(struct drm_device *dev, struct dcb_entry *dcbent, int head, enum LVDS_script script) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint8_t sub = bios->data[bios->fp.xlated_entry + script] + (bios->fp.link_c_increment && dcbent->or & OUTPUT_C ? 1 : 0); + uint16_t scriptofs = ROM16(bios->data[bios->init_script_tbls_ptr + sub * 2]); + +@@ -3194,10 +3411,9 @@ static int run_lvds_table(struct drm_device *dev, struct dcb_entry *dcbent, int + * of a list of pxclks and script pointers. + */ + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + unsigned int outputset = (dcbent->or == 4) ? 1 : 0; + uint16_t scriptptr = 0, clktable; +- uint8_t clktableptr = 0; + + /* + * For now we assume version 3.0 table - g80 support will need some +@@ -3216,26 +3432,29 @@ static int run_lvds_table(struct drm_device *dev, struct dcb_entry *dcbent, int + scriptptr = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 11 + outputset * 2]); + break; + case LVDS_RESET: ++ clktable = bios->fp.lvdsmanufacturerpointer + 15; ++ if (dcbent->or == 4) ++ clktable += 8; ++ + if (dcbent->lvdsconf.use_straps_for_mode) { + if (bios->fp.dual_link) +- clktableptr += 2; +- if (bios->fp.BITbit1) +- clktableptr++; ++ clktable += 4; ++ if (bios->fp.if_is_24bit) ++ clktable += 2; + } else { + /* using EDID */ +- uint8_t fallback = bios->data[bios->fp.lvdsmanufacturerpointer + 4]; +- int fallbackcmpval = (dcbent->or == 4) ? 4 : 1; ++ int cmpval_24bit = (dcbent->or == 4) ? 4 : 1; + + if (bios->fp.dual_link) { +- clktableptr += 2; +- fallbackcmpval *= 2; ++ clktable += 4; ++ cmpval_24bit <<= 1; + } +- if (fallbackcmpval & fallback) +- clktableptr++; ++ ++ if (bios->fp.strapless_is_24bit & cmpval_24bit) ++ clktable += 2; + } + +- /* adding outputset * 8 may not be correct */ +- clktable = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 15 + clktableptr * 2 + outputset * 8]); ++ clktable = ROM16(bios->data[clktable]); + if (!clktable) { + NV_ERROR(dev, "Pixel clock comparison table not found\n"); + return -ENOENT; +@@ -3261,7 +3480,7 @@ int call_lvds_script(struct drm_device *dev, struct dcb_entry *dcbent, int head, + */ + + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint8_t lvds_ver = bios->data[bios->fp.lvdsmanufacturerpointer]; + uint32_t sel_clk_binding, sel_clk; + int ret; +@@ -3395,7 +3614,7 @@ static int parse_fp_mode_table(struct drm_device *dev, struct nvbios *bios) + #ifndef __powerpc__ + NV_ERROR(dev, "Pointer to flat panel table invalid\n"); + #endif +- bios->pub.digital_min_front_porch = 0x4b; ++ bios->digital_min_front_porch = 0x4b; + return 0; + } + +@@ -3428,7 +3647,7 @@ static int parse_fp_mode_table(struct drm_device *dev, struct nvbios *bios) + * fptable[4] is the minimum + * RAMDAC_FP_HCRTC -> RAMDAC_FP_HSYNC_START gap + */ +- bios->pub.digital_min_front_porch = fptable[4]; ++ bios->digital_min_front_porch = fptable[4]; + ofs = -7; + break; + default: +@@ -3467,7 +3686,7 @@ static int parse_fp_mode_table(struct drm_device *dev, struct nvbios *bios) + + /* nv4x cards need both a strap value and fpindex of 0xf to use DDC */ + if (lth.lvds_ver > 0x10) +- bios->pub.fp_no_ddc = fpstrapping != 0xf || fpindex != 0xf; ++ bios->fp_no_ddc = fpstrapping != 0xf || fpindex != 0xf; + + /* + * If either the strap or xlated fpindex value are 0xf there is no +@@ -3491,7 +3710,7 @@ static int parse_fp_mode_table(struct drm_device *dev, struct nvbios *bios) + bool nouveau_bios_fp_mode(struct drm_device *dev, struct drm_display_mode *mode) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint8_t *mode_entry = &bios->data[bios->fp.mode_ptr]; + + if (!mode) /* just checking whether we can produce a mode */ +@@ -3562,11 +3781,11 @@ int nouveau_bios_parse_lvds_table(struct drm_device *dev, int pxclk, bool *dl, b + * until later, when this function should be called with non-zero pxclk + */ + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + int fpstrapping = get_fp_strap(dev, bios), lvdsmanufacturerindex = 0; + struct lvdstableheader lth; + uint16_t lvdsofs; +- int ret, chip_version = bios->pub.chip_version; ++ int ret, chip_version = bios->chip_version; + + ret = parse_lvds_manufacturer_table_header(dev, bios, <h); + if (ret) +@@ -3637,37 +3856,40 @@ int nouveau_bios_parse_lvds_table(struct drm_device *dev, int pxclk, bool *dl, b + *if_is_24bit = bios->data[lvdsofs] & 16; + break; + case 0x30: +- /* +- * My money would be on there being a 24 bit interface bit in +- * this table, but I have no example of a laptop bios with a +- * 24 bit panel to confirm that. Hence we shout loudly if any +- * bit other than bit 0 is set (I've not even seen bit 1) +- */ +- if (bios->data[lvdsofs] > 1) +- NV_ERROR(dev, +- "You have a very unusual laptop display; please report it\n"); ++ case 0x40: + /* + * No sign of the "power off for reset" or "reset for panel + * on" bits, but it's safer to assume we should + */ + bios->fp.power_off_for_reset = true; + bios->fp.reset_after_pclk_change = true; ++ + /* + * It's ok lvdsofs is wrong for nv4x edid case; dual_link is +- * over-written, and BITbit1 isn't used ++ * over-written, and if_is_24bit isn't used + */ + bios->fp.dual_link = bios->data[lvdsofs] & 1; +- bios->fp.BITbit1 = bios->data[lvdsofs] & 2; +- bios->fp.duallink_transition_clk = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 5]) * 10; +- break; +- case 0x40: +- bios->fp.dual_link = bios->data[lvdsofs] & 1; + bios->fp.if_is_24bit = bios->data[lvdsofs] & 2; + bios->fp.strapless_is_24bit = bios->data[bios->fp.lvdsmanufacturerpointer + 4]; + bios->fp.duallink_transition_clk = ROM16(bios->data[bios->fp.lvdsmanufacturerpointer + 5]) * 10; + break; + } + ++ /* Dell Latitude D620 reports a too-high value for the dual-link ++ * transition freq, causing us to program the panel incorrectly. ++ * ++ * It doesn't appear the VBIOS actually uses its transition freq ++ * (90000kHz), instead it uses the "Number of LVDS channels" field ++ * out of the panel ID structure (http://www.spwg.org/). ++ * ++ * For the moment, a quirk will do :) ++ */ ++ if ((dev->pdev->device == 0x01d7) && ++ (dev->pdev->subsystem_vendor == 0x1028) && ++ (dev->pdev->subsystem_device == 0x01c2)) { ++ bios->fp.duallink_transition_clk = 80000; ++ } ++ + /* set dual_link flag for EDID case */ + if (pxclk && (chip_version < 0x25 || chip_version > 0x28)) + bios->fp.dual_link = (pxclk >= bios->fp.duallink_transition_clk); +@@ -3679,20 +3901,37 @@ int nouveau_bios_parse_lvds_table(struct drm_device *dev, int pxclk, bool *dl, b + + static uint8_t * + bios_output_config_match(struct drm_device *dev, struct dcb_entry *dcbent, +- uint16_t record, int record_len, int record_nr) ++ uint16_t record, int record_len, int record_nr, ++ bool match_link) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint32_t entry; + uint16_t table; + int i, v; + ++ switch (dcbent->type) { ++ case OUTPUT_TMDS: ++ case OUTPUT_LVDS: ++ case OUTPUT_DP: ++ break; ++ default: ++ match_link = false; ++ break; ++ } ++ + for (i = 0; i < record_nr; i++, record += record_len) { + table = ROM16(bios->data[record]); + if (!table) + continue; + entry = ROM32(bios->data[table]); + ++ if (match_link) { ++ v = (entry & 0x00c00000) >> 22; ++ if (!(v & dcbent->sorconf.link)) ++ continue; ++ } ++ + v = (entry & 0x000f0000) >> 16; + if (!(v & dcbent->or)) + continue; +@@ -3716,7 +3955,7 @@ nouveau_bios_dp_table(struct drm_device *dev, struct dcb_entry *dcbent, + int *length) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint8_t *table; + + if (!bios->display.dp_table_ptr) { +@@ -3725,7 +3964,7 @@ nouveau_bios_dp_table(struct drm_device *dev, struct dcb_entry *dcbent, + } + table = &bios->data[bios->display.dp_table_ptr]; + +- if (table[0] != 0x21) { ++ if (table[0] != 0x20 && table[0] != 0x21) { + NV_ERROR(dev, "DisplayPort table version 0x%02x unknown\n", + table[0]); + return NULL; +@@ -3734,7 +3973,7 @@ nouveau_bios_dp_table(struct drm_device *dev, struct dcb_entry *dcbent, + *length = table[4]; + return bios_output_config_match(dev, dcbent, + bios->display.dp_table_ptr + table[1], +- table[2], table[3]); ++ table[2], table[3], table[0] >= 0x21); + } + + int +@@ -3765,7 +4004,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent, + */ + + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint8_t *table = &bios->data[bios->display.script_table_ptr]; + uint8_t *otable = NULL; + uint16_t script; +@@ -3823,7 +4062,7 @@ nouveau_bios_run_display_table(struct drm_device *dev, struct dcb_entry *dcbent, + dcbent->type, dcbent->location, dcbent->or); + otable = bios_output_config_match(dev, dcbent, table[1] + + bios->display.script_table_ptr, +- table[2], table[3]); ++ table[2], table[3], table[0] >= 0x21); + if (!otable) { + NV_ERROR(dev, "Couldn't find matching output script table\n"); + return 1; +@@ -3918,8 +4157,8 @@ int run_tmds_table(struct drm_device *dev, struct dcb_entry *dcbent, int head, i + */ + + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; +- int cv = bios->pub.chip_version; ++ struct nvbios *bios = &dev_priv->vbios; ++ int cv = bios->chip_version; + uint16_t clktable = 0, scriptptr; + uint32_t sel_clk_binding, sel_clk; + +@@ -3978,8 +4217,8 @@ int get_pll_limits(struct drm_device *dev, uint32_t limit_match, struct pll_lims + */ + + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; +- int cv = bios->pub.chip_version, pllindex = 0; ++ struct nvbios *bios = &dev_priv->vbios; ++ int cv = bios->chip_version, pllindex = 0; + uint8_t pll_lim_ver = 0, headerlen = 0, recordlen = 0, entries = 0; + uint32_t crystal_strap_mask, crystal_straps; + +@@ -4293,31 +4532,32 @@ int get_pll_limits(struct drm_device *dev, uint32_t limit_match, struct pll_lims + break; + } + +-#if 0 /* for easy debugging */ +- ErrorF("pll.vco1.minfreq: %d\n", pll_lim->vco1.minfreq); +- ErrorF("pll.vco1.maxfreq: %d\n", pll_lim->vco1.maxfreq); +- ErrorF("pll.vco2.minfreq: %d\n", pll_lim->vco2.minfreq); +- ErrorF("pll.vco2.maxfreq: %d\n", pll_lim->vco2.maxfreq); +- +- ErrorF("pll.vco1.min_inputfreq: %d\n", pll_lim->vco1.min_inputfreq); +- ErrorF("pll.vco1.max_inputfreq: %d\n", pll_lim->vco1.max_inputfreq); +- ErrorF("pll.vco2.min_inputfreq: %d\n", pll_lim->vco2.min_inputfreq); +- ErrorF("pll.vco2.max_inputfreq: %d\n", pll_lim->vco2.max_inputfreq); +- +- ErrorF("pll.vco1.min_n: %d\n", pll_lim->vco1.min_n); +- ErrorF("pll.vco1.max_n: %d\n", pll_lim->vco1.max_n); +- ErrorF("pll.vco1.min_m: %d\n", pll_lim->vco1.min_m); +- ErrorF("pll.vco1.max_m: %d\n", pll_lim->vco1.max_m); +- ErrorF("pll.vco2.min_n: %d\n", pll_lim->vco2.min_n); +- ErrorF("pll.vco2.max_n: %d\n", pll_lim->vco2.max_n); +- ErrorF("pll.vco2.min_m: %d\n", pll_lim->vco2.min_m); +- ErrorF("pll.vco2.max_m: %d\n", pll_lim->vco2.max_m); +- +- ErrorF("pll.max_log2p: %d\n", pll_lim->max_log2p); +- ErrorF("pll.log2p_bias: %d\n", pll_lim->log2p_bias); +- +- ErrorF("pll.refclk: %d\n", pll_lim->refclk); +-#endif ++ NV_DEBUG(dev, "pll.vco1.minfreq: %d\n", pll_lim->vco1.minfreq); ++ NV_DEBUG(dev, "pll.vco1.maxfreq: %d\n", pll_lim->vco1.maxfreq); ++ NV_DEBUG(dev, "pll.vco1.min_inputfreq: %d\n", pll_lim->vco1.min_inputfreq); ++ NV_DEBUG(dev, "pll.vco1.max_inputfreq: %d\n", pll_lim->vco1.max_inputfreq); ++ NV_DEBUG(dev, "pll.vco1.min_n: %d\n", pll_lim->vco1.min_n); ++ NV_DEBUG(dev, "pll.vco1.max_n: %d\n", pll_lim->vco1.max_n); ++ NV_DEBUG(dev, "pll.vco1.min_m: %d\n", pll_lim->vco1.min_m); ++ NV_DEBUG(dev, "pll.vco1.max_m: %d\n", pll_lim->vco1.max_m); ++ if (pll_lim->vco2.maxfreq) { ++ NV_DEBUG(dev, "pll.vco2.minfreq: %d\n", pll_lim->vco2.minfreq); ++ NV_DEBUG(dev, "pll.vco2.maxfreq: %d\n", pll_lim->vco2.maxfreq); ++ NV_DEBUG(dev, "pll.vco2.min_inputfreq: %d\n", pll_lim->vco2.min_inputfreq); ++ NV_DEBUG(dev, "pll.vco2.max_inputfreq: %d\n", pll_lim->vco2.max_inputfreq); ++ NV_DEBUG(dev, "pll.vco2.min_n: %d\n", pll_lim->vco2.min_n); ++ NV_DEBUG(dev, "pll.vco2.max_n: %d\n", pll_lim->vco2.max_n); ++ NV_DEBUG(dev, "pll.vco2.min_m: %d\n", pll_lim->vco2.min_m); ++ NV_DEBUG(dev, "pll.vco2.max_m: %d\n", pll_lim->vco2.max_m); ++ } ++ if (!pll_lim->max_p) { ++ NV_DEBUG(dev, "pll.max_log2p: %d\n", pll_lim->max_log2p); ++ NV_DEBUG(dev, "pll.log2p_bias: %d\n", pll_lim->log2p_bias); ++ } else { ++ NV_DEBUG(dev, "pll.min_p: %d\n", pll_lim->min_p); ++ NV_DEBUG(dev, "pll.max_p: %d\n", pll_lim->max_p); ++ } ++ NV_DEBUG(dev, "pll.refclk: %d\n", pll_lim->refclk); + + return 0; + } +@@ -4332,7 +4572,7 @@ static void parse_bios_version(struct drm_device *dev, struct nvbios *bios, uint + */ + + bios->major_version = bios->data[offset + 3]; +- bios->pub.chip_version = bios->data[offset + 2]; ++ bios->chip_version = bios->data[offset + 2]; + NV_TRACE(dev, "Bios version %02x.%02x.%02x.%02x\n", + bios->data[offset + 3], bios->data[offset + 2], + bios->data[offset + 1], bios->data[offset]); +@@ -4402,7 +4642,7 @@ static int parse_bit_A_tbl_entry(struct drm_device *dev, struct nvbios *bios, st + } + + /* First entry is normal dac, 2nd tv-out perhaps? */ +- bios->pub.dactestval = ROM32(bios->data[load_table_ptr + headerlen]) & 0x3ff; ++ bios->dactestval = ROM32(bios->data[load_table_ptr + headerlen]) & 0x3ff; + + return 0; + } +@@ -4526,8 +4766,8 @@ static int parse_bit_i_tbl_entry(struct drm_device *dev, struct nvbios *bios, st + return -ENOSYS; + } + +- bios->pub.dactestval = ROM32(bios->data[daccmpoffset + dacheaderlen]); +- bios->pub.tvdactestval = ROM32(bios->data[daccmpoffset + dacheaderlen + 4]); ++ bios->dactestval = ROM32(bios->data[daccmpoffset + dacheaderlen]); ++ bios->tvdactestval = ROM32(bios->data[daccmpoffset + dacheaderlen + 4]); + + return 0; + } +@@ -4796,11 +5036,11 @@ static int parse_bmp_structure(struct drm_device *dev, struct nvbios *bios, unsi + uint16_t legacy_scripts_offset, legacy_i2c_offset; + + /* load needed defaults in case we can't parse this info */ +- bios->bdcb.dcb.i2c[0].write = NV_CIO_CRE_DDC_WR__INDEX; +- bios->bdcb.dcb.i2c[0].read = NV_CIO_CRE_DDC_STATUS__INDEX; +- bios->bdcb.dcb.i2c[1].write = NV_CIO_CRE_DDC0_WR__INDEX; +- bios->bdcb.dcb.i2c[1].read = NV_CIO_CRE_DDC0_STATUS__INDEX; +- bios->pub.digital_min_front_porch = 0x4b; ++ bios->dcb.i2c[0].write = NV_CIO_CRE_DDC_WR__INDEX; ++ bios->dcb.i2c[0].read = NV_CIO_CRE_DDC_STATUS__INDEX; ++ bios->dcb.i2c[1].write = NV_CIO_CRE_DDC0_WR__INDEX; ++ bios->dcb.i2c[1].read = NV_CIO_CRE_DDC0_STATUS__INDEX; ++ bios->digital_min_front_porch = 0x4b; + bios->fmaxvco = 256000; + bios->fminvco = 128000; + bios->fp.duallink_transition_clk = 90000; +@@ -4907,10 +5147,14 @@ static int parse_bmp_structure(struct drm_device *dev, struct nvbios *bios, unsi + bios->legacy.i2c_indices.crt = bios->data[legacy_i2c_offset]; + bios->legacy.i2c_indices.tv = bios->data[legacy_i2c_offset + 1]; + bios->legacy.i2c_indices.panel = bios->data[legacy_i2c_offset + 2]; +- bios->bdcb.dcb.i2c[0].write = bios->data[legacy_i2c_offset + 4]; +- bios->bdcb.dcb.i2c[0].read = bios->data[legacy_i2c_offset + 5]; +- bios->bdcb.dcb.i2c[1].write = bios->data[legacy_i2c_offset + 6]; +- bios->bdcb.dcb.i2c[1].read = bios->data[legacy_i2c_offset + 7]; ++ if (bios->data[legacy_i2c_offset + 4]) ++ bios->dcb.i2c[0].write = bios->data[legacy_i2c_offset + 4]; ++ if (bios->data[legacy_i2c_offset + 5]) ++ bios->dcb.i2c[0].read = bios->data[legacy_i2c_offset + 5]; ++ if (bios->data[legacy_i2c_offset + 6]) ++ bios->dcb.i2c[1].write = bios->data[legacy_i2c_offset + 6]; ++ if (bios->data[legacy_i2c_offset + 7]) ++ bios->dcb.i2c[1].read = bios->data[legacy_i2c_offset + 7]; + + if (bmplength > 74) { + bios->fmaxvco = ROM32(bmp[67]); +@@ -4961,82 +5205,10 @@ static uint16_t findstr(uint8_t *data, int n, const uint8_t *str, int len) + return 0; + } + +-static int +-read_dcb_i2c_entry(struct drm_device *dev, int dcb_version, uint8_t *i2ctable, int index, struct dcb_i2c_entry *i2c) +-{ +- uint8_t dcb_i2c_ver = dcb_version, headerlen = 0, entry_len = 4; +- int i2c_entries = DCB_MAX_NUM_I2C_ENTRIES; +- int recordoffset = 0, rdofs = 1, wrofs = 0; +- uint8_t port_type = 0; +- +- if (!i2ctable) +- return -EINVAL; +- +- if (dcb_version >= 0x30) { +- if (i2ctable[0] != dcb_version) /* necessary? */ +- NV_WARN(dev, +- "DCB I2C table version mismatch (%02X vs %02X)\n", +- i2ctable[0], dcb_version); +- dcb_i2c_ver = i2ctable[0]; +- headerlen = i2ctable[1]; +- if (i2ctable[2] <= DCB_MAX_NUM_I2C_ENTRIES) +- i2c_entries = i2ctable[2]; +- else +- NV_WARN(dev, +- "DCB I2C table has more entries than indexable " +- "(%d entries, max index 15)\n", i2ctable[2]); +- entry_len = i2ctable[3]; +- /* [4] is i2c_default_indices, read in parse_dcb_table() */ +- } +- /* +- * It's your own fault if you call this function on a DCB 1.1 BIOS -- +- * the test below is for DCB 1.2 +- */ +- if (dcb_version < 0x14) { +- recordoffset = 2; +- rdofs = 0; +- wrofs = 1; +- } +- +- if (index == 0xf) +- return 0; +- if (index > i2c_entries) { +- NV_ERROR(dev, "DCB I2C index too big (%d > %d)\n", +- index, i2ctable[2]); +- return -ENOENT; +- } +- if (i2ctable[headerlen + entry_len * index + 3] == 0xff) { +- NV_ERROR(dev, "DCB I2C entry invalid\n"); +- return -EINVAL; +- } +- +- if (dcb_i2c_ver >= 0x30) { +- port_type = i2ctable[headerlen + recordoffset + 3 + entry_len * index]; +- +- /* +- * Fixup for chips using same address offset for read and +- * write. +- */ +- if (port_type == 4) /* seen on C51 */ +- rdofs = wrofs = 1; +- if (port_type >= 5) /* G80+ */ +- rdofs = wrofs = 0; +- } +- +- if (dcb_i2c_ver >= 0x40 && port_type != 5 && port_type != 6) +- NV_WARN(dev, "DCB I2C table has port type %d\n", port_type); +- +- i2c->port_type = port_type; +- i2c->read = i2ctable[headerlen + recordoffset + rdofs + entry_len * index]; +- i2c->write = i2ctable[headerlen + recordoffset + wrofs + entry_len * index]; +- +- return 0; +-} +- + static struct dcb_gpio_entry * + new_gpio_entry(struct nvbios *bios) + { +- struct parsed_dcb_gpio *gpio = &bios->bdcb.gpio; ++ struct dcb_gpio_table *gpio = &bios->dcb.gpio; + + return &gpio->entry[gpio->entries++]; + } +@@ -5045,14 +5217,14 @@ struct dcb_gpio_entry * + nouveau_bios_gpio_entry(struct drm_device *dev, enum dcb_gpio_tag tag) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + int i; + +- for (i = 0; i < bios->bdcb.gpio.entries; i++) { +- if (bios->bdcb.gpio.entry[i].tag != tag) ++ for (i = 0; i < bios->dcb.gpio.entries; i++) { ++ if (bios->dcb.gpio.entry[i].tag != tag) + continue; + +- return &bios->bdcb.gpio.entry[i]; ++ return &bios->dcb.gpio.entry[i]; + } + + return NULL; +@@ -5075,32 +5247,32 @@ parse_dcb30_gpio_entry(struct nvbios *bios, uint16_t offset) + gpio->tag = tag; + gpio->line = line; + gpio->invert = flags != 4; ++ gpio->entry = ent; + } + + static void + parse_dcb40_gpio_entry(struct nvbios *bios, uint16_t offset) + { ++ uint32_t entry = ROM32(bios->data[offset]); + struct dcb_gpio_entry *gpio; +- uint32_t ent = ROM32(bios->data[offset]); +- uint8_t line = ent & 0x1f, +- tag = ent >> 8 & 0xff; + +- if (tag == 0xff) ++ if ((entry & 0x0000ff00) == 0x0000ff00) + return; + + gpio = new_gpio_entry(bios); +- +- /* Currently unused, we may need more fields parsed at some +- * point. */ +- gpio->tag = tag; +- gpio->line = line; ++ gpio->tag = (entry & 0x0000ff00) >> 8; ++ gpio->line = (entry & 0x0000001f) >> 0; ++ gpio->state_default = (entry & 0x01000000) >> 24; ++ gpio->state[0] = (entry & 0x18000000) >> 27; ++ gpio->state[1] = (entry & 0x60000000) >> 29; ++ gpio->entry = entry; + } + + static void + parse_dcb_gpio_table(struct nvbios *bios) + { + struct drm_device *dev = bios->dev; +- uint16_t gpio_table_ptr = bios->bdcb.gpio_table_ptr; ++ uint16_t gpio_table_ptr = bios->dcb.gpio_table_ptr; + uint8_t *gpio_table = &bios->data[gpio_table_ptr]; + int header_len = gpio_table[1], + entries = gpio_table[2], +@@ -5108,7 +5280,7 @@ parse_dcb_gpio_table(struct nvbios *bios) + void (*parse_entry)(struct nvbios *, uint16_t) = NULL; + int i; + +- if (bios->bdcb.version >= 0x40) { ++ if (bios->dcb.version >= 0x40) { + if (gpio_table_ptr && entry_len != 4) { + NV_WARN(dev, "Invalid DCB GPIO table entry length.\n"); + return; +@@ -5116,7 +5288,7 @@ parse_dcb_gpio_table(struct nvbios *bios) + + parse_entry = parse_dcb40_gpio_entry; + +- } else if (bios->bdcb.version >= 0x30) { ++ } else if (bios->dcb.version >= 0x30) { + if (gpio_table_ptr && entry_len != 2) { + NV_WARN(dev, "Invalid DCB GPIO table entry length.\n"); + return; +@@ -5124,7 +5296,7 @@ parse_dcb_gpio_table(struct nvbios *bios) + + parse_entry = parse_dcb30_gpio_entry; + +- } else if (bios->bdcb.version >= 0x22) { ++ } else if (bios->dcb.version >= 0x22) { + /* + * DCBs older than v3.0 don't really have a GPIO + * table, instead they keep some GPIO info at fixed +@@ -5158,30 +5330,82 @@ struct dcb_connector_table_entry * + nouveau_bios_connector_entry(struct drm_device *dev, int index) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + struct dcb_connector_table_entry *cte; + +- if (index >= bios->bdcb.connector.entries) ++ if (index >= bios->dcb.connector.entries) + return NULL; + +- cte = &bios->bdcb.connector.entry[index]; ++ cte = &bios->dcb.connector.entry[index]; + if (cte->type == 0xff) + return NULL; + + return cte; + } + ++static enum dcb_connector_type ++divine_connector_type(struct nvbios *bios, int index) ++{ ++ struct dcb_table *dcb = &bios->dcb; ++ unsigned encoders = 0, type = DCB_CONNECTOR_NONE; ++ int i; ++ ++ for (i = 0; i < dcb->entries; i++) { ++ if (dcb->entry[i].connector == index) ++ encoders |= (1 << dcb->entry[i].type); ++ } ++ ++ if (encoders & (1 << OUTPUT_DP)) { ++ if (encoders & (1 << OUTPUT_TMDS)) ++ type = DCB_CONNECTOR_DP; ++ else ++ type = DCB_CONNECTOR_eDP; ++ } else ++ if (encoders & (1 << OUTPUT_TMDS)) { ++ if (encoders & (1 << OUTPUT_ANALOG)) ++ type = DCB_CONNECTOR_DVI_I; ++ else ++ type = DCB_CONNECTOR_DVI_D; ++ } else ++ if (encoders & (1 << OUTPUT_ANALOG)) { ++ type = DCB_CONNECTOR_VGA; ++ } else ++ if (encoders & (1 << OUTPUT_LVDS)) { ++ type = DCB_CONNECTOR_LVDS; ++ } else ++ if (encoders & (1 << OUTPUT_TV)) { ++ type = DCB_CONNECTOR_TV_0; ++ } ++ ++ return type; ++} ++ ++static void ++apply_dcb_connector_quirks(struct nvbios *bios, int idx) ++{ ++ struct dcb_connector_table_entry *cte = &bios->dcb.connector.entry[idx]; ++ struct drm_device *dev = bios->dev; ++ ++ /* Gigabyte NX85T */ ++ if ((dev->pdev->device == 0x0421) && ++ (dev->pdev->subsystem_vendor == 0x1458) && ++ (dev->pdev->subsystem_device == 0x344c)) { ++ if (cte->type == DCB_CONNECTOR_HDMI_1) ++ cte->type = DCB_CONNECTOR_DVI_I; ++ } ++} ++ + static void + parse_dcb_connector_table(struct nvbios *bios) + { + struct drm_device *dev = bios->dev; +- struct dcb_connector_table *ct = &bios->bdcb.connector; ++ struct dcb_connector_table *ct = &bios->dcb.connector; + struct dcb_connector_table_entry *cte; +- uint8_t *conntab = &bios->data[bios->bdcb.connector_table_ptr]; ++ uint8_t *conntab = &bios->data[bios->dcb.connector_table_ptr]; + uint8_t *entry; + int i; + +- if (!bios->bdcb.connector_table_ptr) { ++ if (!bios->dcb.connector_table_ptr) { + NV_DEBUG_KMS(dev, "No DCB connector table present\n"); + return; + } +@@ -5199,12 +5423,14 @@ parse_dcb_connector_table(struct nvbios *bios) + entry = conntab + conntab[1]; + cte = &ct->entry[0]; + for (i = 0; i < conntab[2]; i++, entry += conntab[3], cte++) { ++ cte->index = i; + if (conntab[3] == 2) + cte->entry = ROM16(entry[0]); + else + cte->entry = ROM32(entry[0]); ++ + cte->type = (cte->entry & 0x000000ff) >> 0; +- cte->index = (cte->entry & 0x00000f00) >> 8; ++ cte->index2 = (cte->entry & 0x00000f00) >> 8; + switch (cte->entry & 0x00033000) { + case 0x00001000: + cte->gpio_tag = 0x07; +@@ -5226,12 +5452,43 @@ parse_dcb_connector_table(struct nvbios *bios) + if (cte->type == 0xff) + continue; + ++ apply_dcb_connector_quirks(bios, i); ++ + NV_INFO(dev, " %d: 0x%08x: type 0x%02x idx %d tag 0x%02x\n", + i, cte->entry, cte->type, cte->index, cte->gpio_tag); ++ ++ /* check for known types, fallback to guessing the type ++ * from attached encoders if we hit an unknown. ++ */ ++ switch (cte->type) { ++ case DCB_CONNECTOR_VGA: ++ case DCB_CONNECTOR_TV_0: ++ case DCB_CONNECTOR_TV_1: ++ case DCB_CONNECTOR_TV_3: ++ case DCB_CONNECTOR_DVI_I: ++ case DCB_CONNECTOR_DVI_D: ++ case DCB_CONNECTOR_LVDS: ++ case DCB_CONNECTOR_DP: ++ case DCB_CONNECTOR_eDP: ++ case DCB_CONNECTOR_HDMI_0: ++ case DCB_CONNECTOR_HDMI_1: ++ break; ++ default: ++ cte->type = divine_connector_type(bios, cte->index); ++ NV_WARN(dev, "unknown type, using 0x%02x\n", cte->type); ++ break; ++ } ++ ++ if (nouveau_override_conntype) { ++ int type = divine_connector_type(bios, cte->index); ++ if (type != cte->type) ++ NV_WARN(dev, " -> type 0x%02x\n", cte->type); ++ } ++ + } + } + +-static struct dcb_entry *new_dcb_entry(struct parsed_dcb *dcb) ++static struct dcb_entry *new_dcb_entry(struct dcb_table *dcb) + { + struct dcb_entry *entry = &dcb->entry[dcb->entries]; + +@@ -5241,7 +5498,7 @@ static struct dcb_entry *new_dcb_entry(struct parsed_dcb *dcb) + return entry; + } + +-static void fabricate_vga_output(struct parsed_dcb *dcb, int i2c, int heads) ++static void fabricate_vga_output(struct dcb_table *dcb, int i2c, int heads) + { + struct dcb_entry *entry = new_dcb_entry(dcb); + +@@ -5252,7 +5509,7 @@ static void fabricate_vga_output(struct parsed_dcb *dcb, int i2c, int heads) + /* "or" mostly unused in early gen crt modesetting, 0 is fine */ + } + +-static void fabricate_dvi_i_output(struct parsed_dcb *dcb, bool twoHeads) ++static void fabricate_dvi_i_output(struct dcb_table *dcb, bool twoHeads) + { + struct dcb_entry *entry = new_dcb_entry(dcb); + +@@ -5279,7 +5536,7 @@ static void fabricate_dvi_i_output(struct parsed_dcb *dcb, bool twoHeads) + #endif + } + +-static void fabricate_tv_output(struct parsed_dcb *dcb, bool twoHeads) ++static void fabricate_tv_output(struct dcb_table *dcb, bool twoHeads) + { + struct dcb_entry *entry = new_dcb_entry(dcb); + +@@ -5290,23 +5547,17 @@ static void fabricate_tv_output(struct parsed_dcb *dcb, bool twoHeads) + } + + static bool +-parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, ++parse_dcb20_entry(struct drm_device *dev, struct dcb_table *dcb, + uint32_t conn, uint32_t conf, struct dcb_entry *entry) + { + entry->type = conn & 0xf; + entry->i2c_index = (conn >> 4) & 0xf; + entry->heads = (conn >> 8) & 0xf; +- if (bdcb->version >= 0x40) ++ if (dcb->version >= 0x40) + entry->connector = (conn >> 12) & 0xf; + entry->bus = (conn >> 16) & 0xf; + entry->location = (conn >> 20) & 0x3; + entry->or = (conn >> 24) & 0xf; +- /* +- * Normal entries consist of a single bit, but dual link has the +- * next most significant bit set too +- */ +- entry->duallink_possible = +- ((1 << (ffs(entry->or) - 1)) * 3 == entry->or); + + switch (entry->type) { + case OUTPUT_ANALOG: +@@ -5314,7 +5565,7 @@ parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, + * Although the rest of a CRT conf dword is usually + * zeros, mac biosen have stuff there so we must mask + */ +- entry->crtconf.maxfreq = (bdcb->version < 0x30) ? ++ entry->crtconf.maxfreq = (dcb->version < 0x30) ? + (conf & 0xffff) * 10 : + (conf & 0xff) * 10000; + break; +@@ -5323,7 +5574,7 @@ parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, + uint32_t mask; + if (conf & 0x1) + entry->lvdsconf.use_straps_for_mode = true; +- if (bdcb->version < 0x22) { ++ if (dcb->version < 0x22) { + mask = ~0xd; + /* + * The laptop in bug 14567 lies and claims to not use +@@ -5347,7 +5598,7 @@ parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, + * Until we even try to use these on G8x, it's + * useless reporting unknown bits. They all are. + */ +- if (bdcb->version >= 0x40) ++ if (dcb->version >= 0x40) + break; + + NV_ERROR(dev, "Unknown LVDS configuration bits, " +@@ -5357,7 +5608,7 @@ parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, + } + case OUTPUT_TV: + { +- if (bdcb->version >= 0x30) ++ if (dcb->version >= 0x30) + entry->tvconf.has_component_output = conf & (0x8 << 4); + else + entry->tvconf.has_component_output = false; +@@ -5384,8 +5635,20 @@ parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, + break; + case 0xe: + /* weird g80 mobile type that "nv" treats as a terminator */ +- bdcb->dcb.entries--; ++ dcb->entries--; + return false; ++ default: ++ break; ++ } ++ ++ if (dcb->version < 0x40) { ++ /* Normal entries consist of a single bit, but dual link has ++ * the next most significant bit set too ++ */ ++ entry->duallink_possible = ++ ((1 << (ffs(entry->or) - 1)) * 3 == entry->or); ++ } else { ++ entry->duallink_possible = (entry->sorconf.link == 3); + } + + /* unsure what DCB version introduces this, 3.0? */ +@@ -5396,7 +5659,7 @@ parse_dcb20_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, + } + + static bool +-parse_dcb15_entry(struct drm_device *dev, struct parsed_dcb *dcb, ++parse_dcb15_entry(struct drm_device *dev, struct dcb_table *dcb, + uint32_t conn, uint32_t conf, struct dcb_entry *entry) + { + switch (conn & 0x0000000f) { +@@ -5462,27 +5725,27 @@ parse_dcb15_entry(struct drm_device *dev, struct parsed_dcb *dcb, + return true; + } + +-static bool parse_dcb_entry(struct drm_device *dev, struct bios_parsed_dcb *bdcb, ++static bool parse_dcb_entry(struct drm_device *dev, struct dcb_table *dcb, + uint32_t conn, uint32_t conf) + { +- struct dcb_entry *entry = new_dcb_entry(&bdcb->dcb); ++ struct dcb_entry *entry = new_dcb_entry(dcb); + bool ret; + +- if (bdcb->version >= 0x20) +- ret = parse_dcb20_entry(dev, bdcb, conn, conf, entry); ++ if (dcb->version >= 0x20) ++ ret = parse_dcb20_entry(dev, dcb, conn, conf, entry); + else +- ret = parse_dcb15_entry(dev, &bdcb->dcb, conn, conf, entry); ++ ret = parse_dcb15_entry(dev, dcb, conn, conf, entry); + if (!ret) + return ret; + +- read_dcb_i2c_entry(dev, bdcb->version, bdcb->i2c_table, +- entry->i2c_index, &bdcb->dcb.i2c[entry->i2c_index]); ++ read_dcb_i2c_entry(dev, dcb->version, dcb->i2c_table, ++ entry->i2c_index, &dcb->i2c[entry->i2c_index]); + + return true; + } + + static +-void merge_like_dcb_entries(struct drm_device *dev, struct parsed_dcb *dcb) ++void merge_like_dcb_entries(struct drm_device *dev, struct dcb_table *dcb) + { + /* + * DCB v2.0 lists each output combination separately. +@@ -5534,8 +5797,7 @@ static int + parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct bios_parsed_dcb *bdcb = &bios->bdcb; +- struct parsed_dcb *dcb; ++ struct dcb_table *dcb = &bios->dcb; + uint16_t dcbptr = 0, i2ctabptr = 0; + uint8_t *dcbtable; + uint8_t headerlen = 0x4, entries = DCB_MAX_NUM_ENTRIES; +@@ -5543,9 +5805,6 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + int recordlength = 8, confofs = 4; + int i; + +- dcb = bios->pub.dcb = &bdcb->dcb; +- dcb->entries = 0; +- + /* get the offset from 0x36 */ + if (dev_priv->card_type > NV_04) { + dcbptr = ROM16(bios->data[0x36]); +@@ -5567,21 +5826,21 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + dcbtable = &bios->data[dcbptr]; + + /* get DCB version */ +- bdcb->version = dcbtable[0]; ++ dcb->version = dcbtable[0]; + NV_TRACE(dev, "Found Display Configuration Block version %d.%d\n", +- bdcb->version >> 4, bdcb->version & 0xf); ++ dcb->version >> 4, dcb->version & 0xf); + +- if (bdcb->version >= 0x20) { /* NV17+ */ ++ if (dcb->version >= 0x20) { /* NV17+ */ + uint32_t sig; + +- if (bdcb->version >= 0x30) { /* NV40+ */ ++ if (dcb->version >= 0x30) { /* NV40+ */ + headerlen = dcbtable[1]; + entries = dcbtable[2]; + recordlength = dcbtable[3]; + i2ctabptr = ROM16(dcbtable[4]); + sig = ROM32(dcbtable[6]); +- bdcb->gpio_table_ptr = ROM16(dcbtable[10]); +- bdcb->connector_table_ptr = ROM16(dcbtable[20]); ++ dcb->gpio_table_ptr = ROM16(dcbtable[10]); ++ dcb->connector_table_ptr = ROM16(dcbtable[20]); + } else { + i2ctabptr = ROM16(dcbtable[2]); + sig = ROM32(dcbtable[4]); +@@ -5593,7 +5852,7 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + "signature (%08X)\n", sig); + return -EINVAL; + } +- } else if (bdcb->version >= 0x15) { /* some NV11 and NV20 */ ++ } else if (dcb->version >= 0x15) { /* some NV11 and NV20 */ + char sig[8] = { 0 }; + + strncpy(sig, (char *)&dcbtable[-7], 7); +@@ -5641,14 +5900,11 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + if (!i2ctabptr) + NV_WARN(dev, "No pointer to DCB I2C port table\n"); + else { +- bdcb->i2c_table = &bios->data[i2ctabptr]; +- if (bdcb->version >= 0x30) +- bdcb->i2c_default_indices = bdcb->i2c_table[4]; ++ dcb->i2c_table = &bios->data[i2ctabptr]; ++ if (dcb->version >= 0x30) ++ dcb->i2c_default_indices = dcb->i2c_table[4]; + } + +- parse_dcb_gpio_table(bios); +- parse_dcb_connector_table(bios); +- + if (entries > DCB_MAX_NUM_ENTRIES) + entries = DCB_MAX_NUM_ENTRIES; + +@@ -5673,7 +5929,7 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + NV_TRACEWARN(dev, "Raw DCB entry %d: %08x %08x\n", + dcb->entries, connection, config); + +- if (!parse_dcb_entry(dev, bdcb, connection, config)) ++ if (!parse_dcb_entry(dev, dcb, connection, config)) + break; + } + +@@ -5681,18 +5937,22 @@ parse_dcb_table(struct drm_device *dev, struct nvbios *bios, bool twoHeads) + * apart for v2.1+ not being known for requiring merging, this + * guarantees dcbent->index is the index of the entry in the rom image + */ +- if (bdcb->version < 0x21) ++ if (dcb->version < 0x21) + merge_like_dcb_entries(dev, dcb); + +- return dcb->entries ? 0 : -ENXIO; ++ if (!dcb->entries) ++ return -ENXIO; ++ ++ parse_dcb_gpio_table(bios); ++ parse_dcb_connector_table(bios); ++ return 0; + } + + static void + fixup_legacy_connector(struct nvbios *bios) + { +- struct bios_parsed_dcb *bdcb = &bios->bdcb; +- struct parsed_dcb *dcb = &bdcb->dcb; +- int high = 0, i; ++ struct dcb_table *dcb = &bios->dcb; ++ int i, i2c, i2c_conn[DCB_MAX_NUM_I2C_ENTRIES] = { }; + + /* + * DCB 3.0 also has the table in most cases, but there are some cards +@@ -5700,9 +5960,11 @@ fixup_legacy_connector(struct nvbios *bios) + * indices are all 0. We don't need the connector indices on pre-G80 + * chips (yet?) so limit the use to DCB 4.0 and above. + */ +- if (bdcb->version >= 0x40) ++ if (dcb->version >= 0x40) + return; + ++ dcb->connector.entries = 0; ++ + /* + * No known connector info before v3.0, so make it up. the rule here + * is: anything on the same i2c bus is considered to be on the same +@@ -5710,37 +5972,38 @@ fixup_legacy_connector(struct nvbios *bios) + * its own unique connector index. + */ + for (i = 0; i < dcb->entries; i++) { +- if (dcb->entry[i].i2c_index == 0xf) +- continue; +- + /* + * Ignore the I2C index for on-chip TV-out, as there + * are cards with bogus values (nv31m in bug 23212), + * and it's otherwise useless. + */ + if (dcb->entry[i].type == OUTPUT_TV && +- dcb->entry[i].location == DCB_LOC_ON_CHIP) { ++ dcb->entry[i].location == DCB_LOC_ON_CHIP) + dcb->entry[i].i2c_index = 0xf; ++ i2c = dcb->entry[i].i2c_index; ++ ++ if (i2c_conn[i2c]) { ++ dcb->entry[i].connector = i2c_conn[i2c] - 1; + continue; + } + +- dcb->entry[i].connector = dcb->entry[i].i2c_index; +- if (dcb->entry[i].connector > high) +- high = dcb->entry[i].connector; ++ dcb->entry[i].connector = dcb->connector.entries++; ++ if (i2c != 0xf) ++ i2c_conn[i2c] = dcb->connector.entries; + } + +- for (i = 0; i < dcb->entries; i++) { +- if (dcb->entry[i].i2c_index != 0xf) +- continue; +- +- dcb->entry[i].connector = ++high; ++ /* Fake the connector table as well as just connector indices */ ++ for (i = 0; i < dcb->connector.entries; i++) { ++ dcb->connector.entry[i].index = i; ++ dcb->connector.entry[i].type = divine_connector_type(bios, i); ++ dcb->connector.entry[i].gpio_tag = 0xff; + } + } + + static void + fixup_legacy_i2c(struct nvbios *bios) + { +- struct parsed_dcb *dcb = &bios->bdcb.dcb; ++ struct dcb_table *dcb = &bios->dcb; + int i; + + for (i = 0; i < dcb->entries; i++) { +@@ -5826,7 +6089,7 @@ static int load_nv17_hw_sequencer_ucode(struct drm_device *dev, + uint8_t *nouveau_bios_embedded_edid(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + const uint8_t edid_sig[] = { + 0x00, 0xff, 0xff, 0xff, 0xff, 0xff, 0xff, 0x00 }; + uint16_t offset = 0; +@@ -5859,7 +6122,7 @@ nouveau_bios_run_init_table(struct drm_device *dev, uint16_t table, + struct dcb_entry *dcbent) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + struct init_exec iexec = { true, false }; + + mutex_lock(&bios->lock); +@@ -5872,7 +6135,7 @@ nouveau_bios_run_init_table(struct drm_device *dev, uint16_t table, + static bool NVInitVBIOS(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + + memset(bios, 0, sizeof(struct nvbios)); + mutex_init(&bios->lock); +@@ -5888,7 +6151,7 @@ static bool NVInitVBIOS(struct drm_device *dev) + static int nouveau_parse_vbios_struct(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + const uint8_t bit_signature[] = { 0xff, 0xb8, 'B', 'I', 'T' }; + const uint8_t bmp_signature[] = { 0xff, 0x7f, 'N', 'V', 0x0 }; + int offset; +@@ -5915,7 +6178,7 @@ int + nouveau_run_vbios_init(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + int i, ret = 0; + + NVLockVgaCrtcs(dev, false); +@@ -5946,9 +6209,9 @@ nouveau_run_vbios_init(struct drm_device *dev) + } + + if (dev_priv->card_type >= NV_50) { +- for (i = 0; i < bios->bdcb.dcb.entries; i++) { ++ for (i = 0; i < bios->dcb.entries; i++) { + nouveau_bios_run_display_table(dev, +- &bios->bdcb.dcb.entry[i], ++ &bios->dcb.entry[i], + 0, 0); + } + } +@@ -5962,26 +6225,48 @@ static void + nouveau_bios_i2c_devices_takedown(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + struct dcb_i2c_entry *entry; + int i; + +- entry = &bios->bdcb.dcb.i2c[0]; ++ entry = &bios->dcb.i2c[0]; + for (i = 0; i < DCB_MAX_NUM_I2C_ENTRIES; i++, entry++) + nouveau_i2c_fini(dev, entry); + } + ++static bool ++nouveau_bios_posted(struct drm_device *dev) ++{ ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ bool was_locked; ++ unsigned htotal; ++ ++ if (dev_priv->chipset >= NV_50) { ++ if (NVReadVgaCrtc(dev, 0, 0x00) == 0 && ++ NVReadVgaCrtc(dev, 0, 0x1a) == 0) ++ return false; ++ return true; ++ } ++ ++ was_locked = NVLockVgaCrtcs(dev, false); ++ htotal = NVReadVgaCrtc(dev, 0, 0x06); ++ htotal |= (NVReadVgaCrtc(dev, 0, 0x07) & 0x01) << 8; ++ htotal |= (NVReadVgaCrtc(dev, 0, 0x07) & 0x20) << 4; ++ htotal |= (NVReadVgaCrtc(dev, 0, 0x25) & 0x01) << 10; ++ htotal |= (NVReadVgaCrtc(dev, 0, 0x41) & 0x01) << 11; ++ NVLockVgaCrtcs(dev, was_locked); ++ return (htotal != 0); ++} ++ + int + nouveau_bios_init(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint32_t saved_nv_pextdev_boot_0; + bool was_locked; + int ret; + +- dev_priv->vbios = &bios->pub; +- + if (!NVInitVBIOS(dev)) + return -ENODEV; + +@@ -6007,11 +6292,9 @@ nouveau_bios_init(struct drm_device *dev) + bios->execute = false; + + /* ... unless card isn't POSTed already */ +- if (dev_priv->card_type >= NV_10 && +- NVReadVgaCrtc(dev, 0, 0x00) == 0 && +- NVReadVgaCrtc(dev, 0, 0x1a) == 0) { ++ if (!nouveau_bios_posted(dev)) { + NV_INFO(dev, "Adaptor not initialised\n"); +- if (dev_priv->card_type < NV_50) { ++ if (dev_priv->card_type < NV_40) { + NV_ERROR(dev, "Unable to POST this chipset\n"); + return -ENODEV; + } +@@ -6023,10 +6306,8 @@ nouveau_bios_init(struct drm_device *dev) + bios_wr32(bios, NV_PEXTDEV_BOOT_0, saved_nv_pextdev_boot_0); + + ret = nouveau_run_vbios_init(dev); +- if (ret) { +- dev_priv->vbios = NULL; ++ if (ret) + return ret; +- } + + /* feature_byte on BMP is poor, but init always sets CR4B */ + was_locked = NVLockVgaCrtcs(dev, false); +diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.h b/drivers/gpu/drm/nouveau/nouveau_bios.h +index fd94bd6..bd33a54 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_bios.h ++++ b/drivers/gpu/drm/nouveau/nouveau_bios.h +@@ -34,9 +34,73 @@ + + #define DCB_LOC_ON_CHIP 0 + ++struct dcb_i2c_entry { ++ uint32_t entry; ++ uint8_t port_type; ++ uint8_t read, write; ++ struct nouveau_i2c_chan *chan; ++}; ++ ++enum dcb_gpio_tag { ++ DCB_GPIO_TVDAC0 = 0xc, ++ DCB_GPIO_TVDAC1 = 0x2d, ++}; ++ ++struct dcb_gpio_entry { ++ enum dcb_gpio_tag tag; ++ int line; ++ bool invert; ++ uint32_t entry; ++ uint8_t state_default; ++ uint8_t state[2]; ++}; ++ ++struct dcb_gpio_table { ++ int entries; ++ struct dcb_gpio_entry entry[DCB_MAX_NUM_GPIO_ENTRIES]; ++}; ++ ++enum dcb_connector_type { ++ DCB_CONNECTOR_VGA = 0x00, ++ DCB_CONNECTOR_TV_0 = 0x10, ++ DCB_CONNECTOR_TV_1 = 0x11, ++ DCB_CONNECTOR_TV_3 = 0x13, ++ DCB_CONNECTOR_DVI_I = 0x30, ++ DCB_CONNECTOR_DVI_D = 0x31, ++ DCB_CONNECTOR_LVDS = 0x40, ++ DCB_CONNECTOR_DP = 0x46, ++ DCB_CONNECTOR_eDP = 0x47, ++ DCB_CONNECTOR_HDMI_0 = 0x60, ++ DCB_CONNECTOR_HDMI_1 = 0x61, ++ DCB_CONNECTOR_NONE = 0xff ++}; ++ ++struct dcb_connector_table_entry { ++ uint8_t index; ++ uint32_t entry; ++ enum dcb_connector_type type; ++ uint8_t index2; ++ uint8_t gpio_tag; ++ void *drm; ++}; ++ ++struct dcb_connector_table { ++ int entries; ++ struct dcb_connector_table_entry entry[DCB_MAX_NUM_CONNECTOR_ENTRIES]; ++}; ++ ++enum dcb_type { ++ OUTPUT_ANALOG = 0, ++ OUTPUT_TV = 1, ++ OUTPUT_TMDS = 2, ++ OUTPUT_LVDS = 3, ++ OUTPUT_DP = 6, ++ OUTPUT_ANY = -1 ++}; ++ + struct dcb_entry { + int index; /* may not be raw dcb index if merging has happened */ +- uint8_t type; ++ enum dcb_type type; + uint8_t i2c_index; + uint8_t heads; + uint8_t connector; +@@ -71,69 +135,22 @@ struct dcb_entry { + bool i2c_upper_default; + }; + +-struct dcb_i2c_entry { +- uint8_t port_type; +- uint8_t read, write; +- struct nouveau_i2c_chan *chan; +-}; ++struct dcb_table { ++ uint8_t version; + +-struct parsed_dcb { + int entries; + struct dcb_entry entry[DCB_MAX_NUM_ENTRIES]; +- struct dcb_i2c_entry i2c[DCB_MAX_NUM_I2C_ENTRIES]; +-}; +- +-enum dcb_gpio_tag { +- DCB_GPIO_TVDAC0 = 0xc, +- DCB_GPIO_TVDAC1 = 0x2d, +-}; +- +-struct dcb_gpio_entry { +- enum dcb_gpio_tag tag; +- int line; +- bool invert; +-}; +- +-struct parsed_dcb_gpio { +- int entries; +- struct dcb_gpio_entry entry[DCB_MAX_NUM_GPIO_ENTRIES]; +-}; +- +-struct dcb_connector_table_entry { +- uint32_t entry; +- uint8_t type; +- uint8_t index; +- uint8_t gpio_tag; +-}; +- +-struct dcb_connector_table { +- int entries; +- struct dcb_connector_table_entry entry[DCB_MAX_NUM_CONNECTOR_ENTRIES]; +-}; +- +-struct bios_parsed_dcb { +- uint8_t version; +- +- struct parsed_dcb dcb; + + uint8_t *i2c_table; + uint8_t i2c_default_indices; ++ struct dcb_i2c_entry i2c[DCB_MAX_NUM_I2C_ENTRIES]; + + uint16_t gpio_table_ptr; +- struct parsed_dcb_gpio gpio; ++ struct dcb_gpio_table gpio; + uint16_t connector_table_ptr; + struct dcb_connector_table connector; + }; + +-enum nouveau_encoder_type { +- OUTPUT_ANALOG = 0, +- OUTPUT_TV = 1, +- OUTPUT_TMDS = 2, +- OUTPUT_LVDS = 3, +- OUTPUT_DP = 6, +- OUTPUT_ANY = -1 +-}; +- + enum nouveau_or { + OUTPUT_A = (1 << 0), + OUTPUT_B = (1 << 1), +@@ -190,8 +207,8 @@ struct pll_lims { + int refclk; + }; + +-struct nouveau_bios_info { +- struct parsed_dcb *dcb; ++struct nvbios { ++ struct drm_device *dev; + + uint8_t chip_version; + +@@ -199,11 +216,6 @@ struct nouveau_bios_info { + uint32_t tvdactestval; + uint8_t digital_min_front_porch; + bool fp_no_ddc; +-}; +- +-struct nvbios { +- struct drm_device *dev; +- struct nouveau_bios_info pub; + + struct mutex lock; + +@@ -234,7 +246,7 @@ struct nvbios { + uint16_t some_script_ptr; /* BIT I + 14 */ + uint16_t init96_tbl_ptr; /* BIT I + 16 */ + +- struct bios_parsed_dcb bdcb; ++ struct dcb_table dcb; + + struct { + int crtchead; +@@ -260,7 +272,6 @@ struct nvbios { + bool reset_after_pclk_change; + bool dual_link; + bool link_c_increment; +- bool BITbit1; + bool if_is_24bit; + int duallink_transition_clk; + uint8_t strapless_is_24bit; +diff --git a/drivers/gpu/drm/nouveau/nouveau_bo.c b/drivers/gpu/drm/nouveau/nouveau_bo.c +index 028719f..8fac10d 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_bo.c ++++ b/drivers/gpu/drm/nouveau/nouveau_bo.c +@@ -71,7 +71,7 @@ nouveau_bo_fixup_align(struct drm_device *dev, + * many small buffers. + */ + if (dev_priv->card_type == NV_50) { +- uint32_t block_size = nouveau_mem_fb_amount(dev) >> 15; ++ uint32_t block_size = dev_priv->vram_size >> 15; + int i; + + switch (tile_flags) { +@@ -153,17 +153,17 @@ nouveau_bo_new(struct drm_device *dev, struct nouveau_channel *chan, + + nvbo->placement.fpfn = 0; + nvbo->placement.lpfn = mappable ? dev_priv->fb_mappable_pages : 0; +- nouveau_bo_placement_set(nvbo, flags); ++ nouveau_bo_placement_set(nvbo, flags, 0); + + nvbo->channel = chan; + ret = ttm_bo_init(&dev_priv->ttm.bdev, &nvbo->bo, size, + ttm_bo_type_device, &nvbo->placement, align, 0, + false, NULL, size, nouveau_bo_del_ttm); +- nvbo->channel = NULL; + if (ret) { + /* ttm will call nouveau_bo_del_ttm if it fails.. */ + return ret; + } ++ nvbo->channel = NULL; + + spin_lock(&dev_priv->ttm.bo_list_lock); + list_add_tail(&nvbo->head, &dev_priv->ttm.bo_list); +@@ -172,26 +172,33 @@ nouveau_bo_new(struct drm_device *dev, struct nouveau_channel *chan, + return 0; + } + ++static void ++set_placement_list(uint32_t *pl, unsigned *n, uint32_t type, uint32_t flags) ++{ ++ *n = 0; ++ ++ if (type & TTM_PL_FLAG_VRAM) ++ pl[(*n)++] = TTM_PL_FLAG_VRAM | flags; ++ if (type & TTM_PL_FLAG_TT) ++ pl[(*n)++] = TTM_PL_FLAG_TT | flags; ++ if (type & TTM_PL_FLAG_SYSTEM) ++ pl[(*n)++] = TTM_PL_FLAG_SYSTEM | flags; ++} ++ + void +-nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t memtype) ++nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy) + { +- int n = 0; +- +- if (memtype & TTM_PL_FLAG_VRAM) +- nvbo->placements[n++] = TTM_PL_FLAG_VRAM | TTM_PL_MASK_CACHING; +- if (memtype & TTM_PL_FLAG_TT) +- nvbo->placements[n++] = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING; +- if (memtype & TTM_PL_FLAG_SYSTEM) +- nvbo->placements[n++] = TTM_PL_FLAG_SYSTEM | TTM_PL_MASK_CACHING; +- nvbo->placement.placement = nvbo->placements; +- nvbo->placement.busy_placement = nvbo->placements; +- nvbo->placement.num_placement = n; +- nvbo->placement.num_busy_placement = n; +- +- if (nvbo->pin_refcnt) { +- while (n--) +- nvbo->placements[n] |= TTM_PL_FLAG_NO_EVICT; +- } ++ struct ttm_placement *pl = &nvbo->placement; ++ uint32_t flags = TTM_PL_MASK_CACHING | ++ (nvbo->pin_refcnt ? TTM_PL_FLAG_NO_EVICT : 0); ++ ++ pl->placement = nvbo->placements; ++ set_placement_list(nvbo->placements, &pl->num_placement, ++ type, flags); ++ ++ pl->busy_placement = nvbo->busy_placements; ++ set_placement_list(nvbo->busy_placements, &pl->num_busy_placement, ++ type | busy, flags); + } + + int +@@ -199,7 +206,7 @@ nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t memtype) + { + struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); + struct ttm_buffer_object *bo = &nvbo->bo; +- int ret, i; ++ int ret; + + if (nvbo->pin_refcnt && !(memtype & (1 << bo->mem.mem_type))) { + NV_ERROR(nouveau_bdev(bo->bdev)->dev, +@@ -215,9 +222,7 @@ nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t memtype) + if (ret) + goto out; + +- nouveau_bo_placement_set(nvbo, memtype); +- for (i = 0; i < nvbo->placement.num_placement; i++) +- nvbo->placements[i] |= TTM_PL_FLAG_NO_EVICT; ++ nouveau_bo_placement_set(nvbo, memtype, 0); + + ret = ttm_bo_validate(bo, &nvbo->placement, false, false); + if (ret == 0) { +@@ -244,7 +249,7 @@ nouveau_bo_unpin(struct nouveau_bo *nvbo) + { + struct drm_nouveau_private *dev_priv = nouveau_bdev(nvbo->bo.bdev); + struct ttm_buffer_object *bo = &nvbo->bo; +- int ret, i; ++ int ret; + + if (--nvbo->pin_refcnt) + return 0; +@@ -253,8 +258,7 @@ nouveau_bo_unpin(struct nouveau_bo *nvbo) + if (ret) + return ret; + +- for (i = 0; i < nvbo->placement.num_placement; i++) +- nvbo->placements[i] &= ~TTM_PL_FLAG_NO_EVICT; ++ nouveau_bo_placement_set(nvbo, bo->mem.placement, 0); + + ret = ttm_bo_validate(bo, &nvbo->placement, false, false); + if (ret == 0) { +@@ -395,8 +399,8 @@ nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, + man->io_addr = NULL; + man->io_offset = drm_get_resource_start(dev, 1); + man->io_size = drm_get_resource_len(dev, 1); +- if (man->io_size > nouveau_mem_fb_amount(dev)) +- man->io_size = nouveau_mem_fb_amount(dev); ++ if (man->io_size > dev_priv->vram_size) ++ man->io_size = dev_priv->vram_size; + + man->gpu_offset = dev_priv->vm_vram_base; + break; +@@ -439,11 +443,11 @@ nouveau_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) + + switch (bo->mem.mem_type) { + case TTM_PL_VRAM: +- nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_TT | ++ nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_TT, + TTM_PL_FLAG_SYSTEM); + break; + default: +- nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_SYSTEM); ++ nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_SYSTEM, 0); + break; + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_calc.c b/drivers/gpu/drm/nouveau/nouveau_calc.c +index ee2b845..88f9bc0 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_calc.c ++++ b/drivers/gpu/drm/nouveau/nouveau_calc.c +@@ -274,7 +274,7 @@ getMNP_single(struct drm_device *dev, struct pll_lims *pll_lim, int clk, + * returns calculated clock + */ + struct drm_nouveau_private *dev_priv = dev->dev_private; +- int cv = dev_priv->vbios->chip_version; ++ int cv = dev_priv->vbios.chip_version; + int minvco = pll_lim->vco1.minfreq, maxvco = pll_lim->vco1.maxfreq; + int minM = pll_lim->vco1.min_m, maxM = pll_lim->vco1.max_m; + int minN = pll_lim->vco1.min_n, maxN = pll_lim->vco1.max_n; +@@ -373,7 +373,7 @@ getMNP_double(struct drm_device *dev, struct pll_lims *pll_lim, int clk, + * returns calculated clock + */ + struct drm_nouveau_private *dev_priv = dev->dev_private; +- int chip_version = dev_priv->vbios->chip_version; ++ int chip_version = dev_priv->vbios.chip_version; + int minvco1 = pll_lim->vco1.minfreq, maxvco1 = pll_lim->vco1.maxfreq; + int minvco2 = pll_lim->vco2.minfreq, maxvco2 = pll_lim->vco2.maxfreq; + int minU1 = pll_lim->vco1.min_inputfreq, minU2 = pll_lim->vco2.min_inputfreq; +diff --git a/drivers/gpu/drm/nouveau/nouveau_channel.c b/drivers/gpu/drm/nouveau/nouveau_channel.c +index adac0f8..f9b2acf 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_channel.c ++++ b/drivers/gpu/drm/nouveau/nouveau_channel.c +@@ -142,7 +142,6 @@ nouveau_channel_alloc(struct drm_device *dev, struct nouveau_channel **chan_ret, + GFP_KERNEL); + if (!dev_priv->fifos[channel]) + return -ENOMEM; +- dev_priv->fifo_alloc_count++; + chan = dev_priv->fifos[channel]; + INIT_LIST_HEAD(&chan->nvsw.vbl_wait); + INIT_LIST_HEAD(&chan->fence.pending); +@@ -258,9 +257,7 @@ nouveau_channel_free(struct nouveau_channel *chan) + nouveau_debugfs_channel_fini(chan); + + /* Give outstanding push buffers a chance to complete */ +- spin_lock_irqsave(&chan->fence.lock, flags); + nouveau_fence_update(chan); +- spin_unlock_irqrestore(&chan->fence.lock, flags); + if (chan->fence.sequence != chan->fence.sequence_ack) { + struct nouveau_fence *fence = NULL; + +@@ -280,9 +277,18 @@ nouveau_channel_free(struct nouveau_channel *chan) + */ + nouveau_fence_fini(chan); + +- /* Ensure the channel is no longer active on the GPU */ ++ /* This will prevent pfifo from switching channels. */ + pfifo->reassign(dev, false); + ++ /* We want to give pgraph a chance to idle and get rid of all potential ++ * errors. We need to do this before the lock, otherwise the irq handler ++ * is unable to process them. ++ */ ++ if (pgraph->channel(dev) == chan) ++ nouveau_wait_for_idle(dev); ++ ++ spin_lock_irqsave(&dev_priv->context_switch_lock, flags); ++ + pgraph->fifo_access(dev, false); + if (pgraph->channel(dev) == chan) + pgraph->unload_context(dev); +@@ -298,6 +304,8 @@ nouveau_channel_free(struct nouveau_channel *chan) + + pfifo->reassign(dev, true); + ++ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); ++ + /* Release the channel's resources */ + nouveau_gpuobj_ref_del(dev, &chan->pushbuf); + if (chan->pushbuf_bo) { +@@ -310,7 +318,6 @@ nouveau_channel_free(struct nouveau_channel *chan) + iounmap(chan->user); + + dev_priv->fifos[chan->id] = NULL; +- dev_priv->fifo_alloc_count--; + kfree(chan); + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.c b/drivers/gpu/drm/nouveau/nouveau_connector.c +index a378bc3..fb51958 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_connector.c ++++ b/drivers/gpu/drm/nouveau/nouveau_connector.c +@@ -218,7 +218,7 @@ nouveau_connector_set_encoder(struct drm_connector *connector, + connector->interlace_allowed = true; + } + +- if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) { ++ if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) { + drm_connector_property_set_value(connector, + dev->mode_config.dvi_i_subconnector_property, + nv_encoder->dcb->type == OUTPUT_TMDS ? +@@ -236,19 +236,6 @@ nouveau_connector_detect(struct drm_connector *connector) + struct nouveau_i2c_chan *i2c; + int type, flags; + +- if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) +- nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS); +- if (nv_encoder && nv_connector->native_mode) { +- unsigned status = connector_status_connected; +- +-#ifdef CONFIG_ACPI +- if (!nouveau_ignorelid && !acpi_lid_open()) +- status = connector_status_unknown; +-#endif +- nouveau_connector_set_encoder(connector, nv_encoder); +- return status; +- } +- + /* Cleanup the previous EDID block. */ + if (nv_connector->edid) { + drm_mode_connector_update_edid_property(connector, NULL); +@@ -281,7 +268,7 @@ nouveau_connector_detect(struct drm_connector *connector) + * same i2c channel so the value returned from ddc_detect + * isn't necessarily correct. + */ +- if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) { ++ if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) { + if (nv_connector->edid->input & DRM_EDID_INPUT_DIGITAL) + type = OUTPUT_TMDS; + else +@@ -302,7 +289,7 @@ nouveau_connector_detect(struct drm_connector *connector) + + detect_analog: + nv_encoder = find_encoder_by_type(connector, OUTPUT_ANALOG); +- if (!nv_encoder) ++ if (!nv_encoder && !nouveau_tv_disable) + nv_encoder = find_encoder_by_type(connector, OUTPUT_TV); + if (nv_encoder) { + struct drm_encoder *encoder = to_drm_encoder(nv_encoder); +@@ -320,14 +307,75 @@ detect_analog: + return connector_status_disconnected; + } + ++static enum drm_connector_status ++nouveau_connector_detect_lvds(struct drm_connector *connector) ++{ ++ struct drm_device *dev = connector->dev; ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ struct nouveau_connector *nv_connector = nouveau_connector(connector); ++ struct nouveau_encoder *nv_encoder = NULL; ++ enum drm_connector_status status = connector_status_disconnected; ++ ++ /* Cleanup the previous EDID block. */ ++ if (nv_connector->edid) { ++ drm_mode_connector_update_edid_property(connector, NULL); ++ kfree(nv_connector->edid); ++ nv_connector->edid = NULL; ++ } ++ ++ nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS); ++ if (!nv_encoder) ++ return connector_status_disconnected; ++ ++ if (!dev_priv->vbios.fp_no_ddc) { ++ status = nouveau_connector_detect(connector); ++ if (status == connector_status_connected) ++ goto out; ++ } ++ ++ /* If no EDID found above, and the VBIOS indicates a hardcoded ++ * modeline is avalilable for the panel, set it as the panel's ++ * native mode and exit. ++ */ ++ if (nouveau_bios_fp_mode(dev, NULL) && (dev_priv->vbios.fp_no_ddc || ++ nv_encoder->dcb->lvdsconf.use_straps_for_mode)) { ++ status = connector_status_connected; ++ goto out; ++ } ++ ++ /* Still nothing, some VBIOS images have a hardcoded EDID block ++ * stored for the panel stored in them. ++ */ ++ if (!dev_priv->vbios.fp_no_ddc) { ++ struct edid *edid = ++ (struct edid *)nouveau_bios_embedded_edid(dev); ++ if (edid) { ++ nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL); ++ *(nv_connector->edid) = *edid; ++ status = connector_status_connected; ++ } ++ } ++ ++out: ++#ifdef CONFIG_ACPI ++ if (status == connector_status_connected && ++ !nouveau_ignorelid && !acpi_lid_open()) ++ status = connector_status_unknown; ++#endif ++ ++ drm_mode_connector_update_edid_property(connector, nv_connector->edid); ++ nouveau_connector_set_encoder(connector, nv_encoder); ++ return status; ++} ++ + static void + nouveau_connector_force(struct drm_connector *connector) + { +- struct drm_device *dev = connector->dev; ++ struct nouveau_connector *nv_connector = nouveau_connector(connector); + struct nouveau_encoder *nv_encoder; + int type; + +- if (connector->connector_type == DRM_MODE_CONNECTOR_DVII) { ++ if (nv_connector->dcb->type == DCB_CONNECTOR_DVI_I) { + if (connector->force == DRM_FORCE_ON_DIGITAL) + type = OUTPUT_TMDS; + else +@@ -337,7 +385,7 @@ nouveau_connector_force(struct drm_connector *connector) + + nv_encoder = find_encoder_by_type(connector, type); + if (!nv_encoder) { +- NV_ERROR(dev, "can't find encoder to force %s on!\n", ++ NV_ERROR(connector->dev, "can't find encoder to force %s on!\n", + drm_get_connector_name(connector)); + connector->status = connector_status_disconnected; + return; +@@ -371,7 +419,7 @@ nouveau_connector_set_property(struct drm_connector *connector, + } + + /* LVDS always needs gpu scaling */ +- if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS && ++ if (nv_connector->dcb->type == DCB_CONNECTOR_LVDS && + value == DRM_MODE_SCALE_NONE) + return -EINVAL; + +@@ -431,24 +479,27 @@ nouveau_connector_set_property(struct drm_connector *connector, + } + + static struct drm_display_mode * +-nouveau_connector_native_mode(struct nouveau_connector *connector) ++nouveau_connector_native_mode(struct drm_connector *connector) + { +- struct drm_device *dev = connector->base.dev; ++ struct drm_connector_helper_funcs *helper = connector->helper_private; ++ struct nouveau_connector *nv_connector = nouveau_connector(connector); ++ struct drm_device *dev = connector->dev; + struct drm_display_mode *mode, *largest = NULL; + int high_w = 0, high_h = 0, high_v = 0; + +- /* Use preferred mode if there is one.. */ +- list_for_each_entry(mode, &connector->base.probed_modes, head) { ++ list_for_each_entry(mode, &nv_connector->base.probed_modes, head) { ++ if (helper->mode_valid(connector, mode) != MODE_OK) ++ continue; ++ ++ /* Use preferred mode if there is one.. */ + if (mode->type & DRM_MODE_TYPE_PREFERRED) { + NV_DEBUG_KMS(dev, "native mode from preferred\n"); + return drm_mode_duplicate(dev, mode); + } +- } + +- /* Otherwise, take the resolution with the largest width, then height, +- * then vertical refresh +- */ +- list_for_each_entry(mode, &connector->base.probed_modes, head) { ++ /* Otherwise, take the resolution with the largest width, then ++ * height, then vertical refresh ++ */ + if (mode->hdisplay < high_w) + continue; + +@@ -530,21 +581,28 @@ static int + nouveau_connector_get_modes(struct drm_connector *connector) + { + struct drm_device *dev = connector->dev; ++ struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_connector *nv_connector = nouveau_connector(connector); + struct nouveau_encoder *nv_encoder = nv_connector->detected_encoder; ++ struct drm_display_mode mode; + int ret = 0; + +- /* If we're not LVDS, destroy the previous native mode, the attached +- * monitor could have changed. ++ /* destroy the native mode, the attached monitor could have changed. + */ +- if (connector->connector_type != DRM_MODE_CONNECTOR_LVDS && +- nv_connector->native_mode) { ++ if (nv_connector->native_mode) { + drm_mode_destroy(dev, nv_connector->native_mode); + nv_connector->native_mode = NULL; + } + + if (nv_connector->edid) + ret = drm_add_edid_modes(connector, nv_connector->edid); ++ else ++ if (nv_encoder->dcb->type == OUTPUT_LVDS && ++ (nv_encoder->dcb->lvdsconf.use_straps_for_mode || ++ dev_priv->vbios.fp_no_ddc) && ++ nouveau_bios_fp_mode(dev, &mode)) { ++ nv_connector->native_mode = drm_mode_duplicate(dev, &mode); ++ } + + /* Find the native mode if this is a digital panel, if we didn't + * find any modes through DDC previously add the native mode to +@@ -552,7 +610,7 @@ nouveau_connector_get_modes(struct drm_connector *connector) + */ + if (!nv_connector->native_mode) + nv_connector->native_mode = +- nouveau_connector_native_mode(nv_connector); ++ nouveau_connector_native_mode(connector); + if (ret == 0 && nv_connector->native_mode) { + struct drm_display_mode *mode; + +@@ -565,7 +623,7 @@ nouveau_connector_get_modes(struct drm_connector *connector) + ret = get_slave_funcs(nv_encoder)-> + get_modes(to_drm_encoder(nv_encoder), connector); + +- if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) ++ if (nv_encoder->dcb->type == OUTPUT_LVDS) + ret += nouveau_connector_scaler_modes_add(connector); + + return ret; +@@ -583,9 +641,9 @@ nouveau_connector_mode_valid(struct drm_connector *connector, + + switch (nv_encoder->dcb->type) { + case OUTPUT_LVDS: +- BUG_ON(!nv_connector->native_mode); +- if (mode->hdisplay > nv_connector->native_mode->hdisplay || +- mode->vdisplay > nv_connector->native_mode->vdisplay) ++ if (nv_connector->native_mode && ++ (mode->hdisplay > nv_connector->native_mode->hdisplay || ++ mode->vdisplay > nv_connector->native_mode->vdisplay)) + return MODE_PANEL; + + min_clock = 0; +@@ -593,8 +651,7 @@ nouveau_connector_mode_valid(struct drm_connector *connector, + break; + case OUTPUT_TMDS: + if ((dev_priv->card_type >= NV_50 && !nouveau_duallink) || +- (dev_priv->card_type < NV_50 && +- !nv_encoder->dcb->duallink_possible)) ++ !nv_encoder->dcb->duallink_possible) + max_clock = 165000; + else + max_clock = 330000; +@@ -615,6 +672,9 @@ nouveau_connector_mode_valid(struct drm_connector *connector, + + clock *= 3; + break; ++ default: ++ BUG_ON(1); ++ return MODE_BAD; + } + + if (clock < min_clock) +@@ -656,193 +716,138 @@ nouveau_connector_funcs = { + .force = nouveau_connector_force + }; + +-static int +-nouveau_connector_create_lvds(struct drm_device *dev, +- struct drm_connector *connector) +-{ +- struct nouveau_connector *nv_connector = nouveau_connector(connector); +- struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nouveau_i2c_chan *i2c = NULL; +- struct nouveau_encoder *nv_encoder; +- struct drm_display_mode native, *mode, *temp; +- bool dummy, if_is_24bit = false; +- int ret, flags; +- +- nv_encoder = find_encoder_by_type(connector, OUTPUT_LVDS); +- if (!nv_encoder) +- return -ENODEV; +- +- ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &if_is_24bit); +- if (ret) { +- NV_ERROR(dev, "Error parsing LVDS table, disabling LVDS\n"); +- return ret; +- } +- nv_connector->use_dithering = !if_is_24bit; +- +- /* Firstly try getting EDID over DDC, if allowed and I2C channel +- * is available. +- */ +- if (!dev_priv->VBIOS.pub.fp_no_ddc && nv_encoder->dcb->i2c_index < 0xf) +- i2c = nouveau_i2c_find(dev, nv_encoder->dcb->i2c_index); +- +- if (i2c) { +- nouveau_connector_ddc_prepare(connector, &flags); +- nv_connector->edid = drm_get_edid(connector, &i2c->adapter); +- nouveau_connector_ddc_finish(connector, flags); +- } +- +- /* If no EDID found above, and the VBIOS indicates a hardcoded +- * modeline is avalilable for the panel, set it as the panel's +- * native mode and exit. +- */ +- if (!nv_connector->edid && nouveau_bios_fp_mode(dev, &native) && +- (nv_encoder->dcb->lvdsconf.use_straps_for_mode || +- dev_priv->VBIOS.pub.fp_no_ddc)) { +- nv_connector->native_mode = drm_mode_duplicate(dev, &native); +- goto out; +- } +- +- /* Still nothing, some VBIOS images have a hardcoded EDID block +- * stored for the panel stored in them. +- */ +- if (!nv_connector->edid && !nv_connector->native_mode && +- !dev_priv->VBIOS.pub.fp_no_ddc) { +- struct edid *edid = +- (struct edid *)nouveau_bios_embedded_edid(dev); +- if (edid) { +- nv_connector->edid = kmalloc(EDID_LENGTH, GFP_KERNEL); +- *(nv_connector->edid) = *edid; +- } +- } +- +- if (!nv_connector->edid) +- goto out; +- +- /* We didn't find/use a panel mode from the VBIOS, so parse the EDID +- * block and look for the preferred mode there. +- */ +- ret = drm_add_edid_modes(connector, nv_connector->edid); +- if (ret == 0) +- goto out; +- nv_connector->detected_encoder = nv_encoder; +- nv_connector->native_mode = nouveau_connector_native_mode(nv_connector); +- list_for_each_entry_safe(mode, temp, &connector->probed_modes, head) +- drm_mode_remove(connector, mode); +- +-out: +- if (!nv_connector->native_mode) { +- NV_ERROR(dev, "LVDS present in DCB table, but couldn't " +- "determine its native mode. Disabling.\n"); +- return -ENODEV; +- } +- +- drm_mode_connector_update_edid_property(connector, nv_connector->edid); +- return 0; +-} ++static const struct drm_connector_funcs ++nouveau_connector_funcs_lvds = { ++ .dpms = drm_helper_connector_dpms, ++ .save = NULL, ++ .restore = NULL, ++ .detect = nouveau_connector_detect_lvds, ++ .destroy = nouveau_connector_destroy, ++ .fill_modes = drm_helper_probe_single_connector_modes, ++ .set_property = nouveau_connector_set_property, ++ .force = nouveau_connector_force ++}; + +-int +-nouveau_connector_create(struct drm_device *dev, int index, int type) ++struct drm_connector * ++nouveau_connector_create(struct drm_device *dev, int index) + { ++ const struct drm_connector_funcs *funcs = &nouveau_connector_funcs; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_connector *nv_connector = NULL; ++ struct dcb_connector_table_entry *dcb = NULL; + struct drm_connector *connector; +- struct drm_encoder *encoder; +- int ret; ++ int type, ret = 0; + + NV_DEBUG_KMS(dev, "\n"); + +- nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL); +- if (!nv_connector) +- return -ENOMEM; +- nv_connector->dcb = nouveau_bios_connector_entry(dev, index); +- connector = &nv_connector->base; ++ if (index >= dev_priv->vbios.dcb.connector.entries) ++ return ERR_PTR(-EINVAL); + +- switch (type) { +- case DRM_MODE_CONNECTOR_VGA: +- NV_INFO(dev, "Detected a VGA connector\n"); ++ dcb = &dev_priv->vbios.dcb.connector.entry[index]; ++ if (dcb->drm) ++ return dcb->drm; ++ ++ switch (dcb->type) { ++ case DCB_CONNECTOR_VGA: ++ type = DRM_MODE_CONNECTOR_VGA; + break; +- case DRM_MODE_CONNECTOR_DVID: +- NV_INFO(dev, "Detected a DVI-D connector\n"); ++ case DCB_CONNECTOR_TV_0: ++ case DCB_CONNECTOR_TV_1: ++ case DCB_CONNECTOR_TV_3: ++ type = DRM_MODE_CONNECTOR_TV; + break; +- case DRM_MODE_CONNECTOR_DVII: +- NV_INFO(dev, "Detected a DVI-I connector\n"); ++ case DCB_CONNECTOR_DVI_I: ++ type = DRM_MODE_CONNECTOR_DVII; + break; +- case DRM_MODE_CONNECTOR_LVDS: +- NV_INFO(dev, "Detected a LVDS connector\n"); ++ case DCB_CONNECTOR_DVI_D: ++ type = DRM_MODE_CONNECTOR_DVID; + break; +- case DRM_MODE_CONNECTOR_TV: +- NV_INFO(dev, "Detected a TV connector\n"); ++ case DCB_CONNECTOR_HDMI_0: ++ case DCB_CONNECTOR_HDMI_1: ++ type = DRM_MODE_CONNECTOR_HDMIA; + break; +- case DRM_MODE_CONNECTOR_DisplayPort: +- NV_INFO(dev, "Detected a DisplayPort connector\n"); ++ case DCB_CONNECTOR_LVDS: ++ type = DRM_MODE_CONNECTOR_LVDS; ++ funcs = &nouveau_connector_funcs_lvds; + break; +- default: +- NV_ERROR(dev, "Unknown connector, this is not good.\n"); ++ case DCB_CONNECTOR_DP: ++ type = DRM_MODE_CONNECTOR_DisplayPort; ++ break; ++ case DCB_CONNECTOR_eDP: ++ type = DRM_MODE_CONNECTOR_eDP; + break; ++ default: ++ NV_ERROR(dev, "unknown connector type: 0x%02x!!\n", dcb->type); ++ return ERR_PTR(-EINVAL); + } + ++ nv_connector = kzalloc(sizeof(*nv_connector), GFP_KERNEL); ++ if (!nv_connector) ++ return ERR_PTR(-ENOMEM); ++ nv_connector->dcb = dcb; ++ connector = &nv_connector->base; ++ + /* defaults, will get overridden in detect() */ + connector->interlace_allowed = false; + connector->doublescan_allowed = false; + +- drm_connector_init(dev, connector, &nouveau_connector_funcs, type); ++ drm_connector_init(dev, connector, funcs, type); + drm_connector_helper_add(connector, &nouveau_connector_helper_funcs); + ++ /* Check if we need dithering enabled */ ++ if (dcb->type == DCB_CONNECTOR_LVDS) { ++ bool dummy, is_24bit = false; ++ ++ ret = nouveau_bios_parse_lvds_table(dev, 0, &dummy, &is_24bit); ++ if (ret) { ++ NV_ERROR(dev, "Error parsing LVDS table, disabling " ++ "LVDS\n"); ++ goto fail; ++ } ++ ++ nv_connector->use_dithering = !is_24bit; ++ } ++ + /* Init DVI-I specific properties */ +- if (type == DRM_MODE_CONNECTOR_DVII) { ++ if (dcb->type == DCB_CONNECTOR_DVI_I) { + drm_mode_create_dvi_i_properties(dev); + drm_connector_attach_property(connector, dev->mode_config.dvi_i_subconnector_property, 0); + drm_connector_attach_property(connector, dev->mode_config.dvi_i_select_subconnector_property, 0); + } + +- if (type != DRM_MODE_CONNECTOR_LVDS) +- nv_connector->use_dithering = false; +- +- if (type == DRM_MODE_CONNECTOR_DVID || +- type == DRM_MODE_CONNECTOR_DVII || +- type == DRM_MODE_CONNECTOR_LVDS || +- type == DRM_MODE_CONNECTOR_DisplayPort) { +- nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN; +- +- drm_connector_attach_property(connector, dev->mode_config.scaling_mode_property, +- nv_connector->scaling_mode); +- drm_connector_attach_property(connector, dev->mode_config.dithering_mode_property, +- nv_connector->use_dithering ? DRM_MODE_DITHERING_ON +- : DRM_MODE_DITHERING_OFF); +- +- } else { +- nv_connector->scaling_mode = DRM_MODE_SCALE_NONE; +- +- if (type == DRM_MODE_CONNECTOR_VGA && +- dev_priv->card_type >= NV_50) { ++ switch (dcb->type) { ++ case DCB_CONNECTOR_VGA: ++ if (dev_priv->card_type >= NV_50) { + drm_connector_attach_property(connector, + dev->mode_config.scaling_mode_property, + nv_connector->scaling_mode); + } +- } +- +- /* attach encoders */ +- list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { +- struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); +- +- if (nv_encoder->dcb->connector != index) +- continue; +- +- if (get_slave_funcs(nv_encoder)) +- get_slave_funcs(nv_encoder)->create_resources(encoder, connector); ++ /* fall-through */ ++ case DCB_CONNECTOR_TV_0: ++ case DCB_CONNECTOR_TV_1: ++ case DCB_CONNECTOR_TV_3: ++ nv_connector->scaling_mode = DRM_MODE_SCALE_NONE; ++ break; ++ default: ++ nv_connector->scaling_mode = DRM_MODE_SCALE_FULLSCREEN; + +- drm_mode_connector_attach_encoder(connector, encoder); ++ drm_connector_attach_property(connector, ++ dev->mode_config.scaling_mode_property, ++ nv_connector->scaling_mode); ++ drm_connector_attach_property(connector, ++ dev->mode_config.dithering_mode_property, ++ nv_connector->use_dithering ? ++ DRM_MODE_DITHERING_ON : DRM_MODE_DITHERING_OFF); ++ break; + } + + drm_sysfs_connector_add(connector); ++ dcb->drm = connector; ++ return dcb->drm; + +- if (connector->connector_type == DRM_MODE_CONNECTOR_LVDS) { +- ret = nouveau_connector_create_lvds(dev, connector); +- if (ret) { +- connector->funcs->destroy(connector); +- return ret; +- } +- } ++fail: ++ drm_connector_cleanup(connector); ++ kfree(connector); ++ return ERR_PTR(ret); + +- return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nouveau_connector.h b/drivers/gpu/drm/nouveau/nouveau_connector.h +index 728b809..1ce3d91 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_connector.h ++++ b/drivers/gpu/drm/nouveau/nouveau_connector.h +@@ -49,6 +49,7 @@ static inline struct nouveau_connector *nouveau_connector( + return container_of(con, struct nouveau_connector, base); + } + +-int nouveau_connector_create(struct drm_device *dev, int i2c_index, int type); ++struct drm_connector * ++nouveau_connector_create(struct drm_device *, int index); + + #endif /* __NOUVEAU_CONNECTOR_H__ */ +diff --git a/drivers/gpu/drm/nouveau/nouveau_debugfs.c b/drivers/gpu/drm/nouveau/nouveau_debugfs.c +index 89e36ee..a251886 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_debugfs.c ++++ b/drivers/gpu/drm/nouveau/nouveau_debugfs.c +@@ -137,16 +137,28 @@ nouveau_debugfs_memory_info(struct seq_file *m, void *data) + { + struct drm_info_node *node = (struct drm_info_node *) m->private; + struct drm_minor *minor = node->minor; +- struct drm_device *dev = minor->dev; ++ struct drm_nouveau_private *dev_priv = minor->dev->dev_private; ++ ++ seq_printf(m, "VRAM total: %dKiB\n", (int)(dev_priv->vram_size >> 10)); ++ return 0; ++} ++ ++static int ++nouveau_debugfs_vbios_image(struct seq_file *m, void *data) ++{ ++ struct drm_info_node *node = (struct drm_info_node *) m->private; ++ struct drm_nouveau_private *dev_priv = node->minor->dev->dev_private; ++ int i; + +- seq_printf(m, "VRAM total: %dKiB\n", +- (int)(nouveau_mem_fb_amount(dev) >> 10)); ++ for (i = 0; i < dev_priv->vbios.length; i++) ++ seq_printf(m, "%c", dev_priv->vbios.data[i]); + return 0; + } + + static struct drm_info_list nouveau_debugfs_list[] = { + { "chipset", nouveau_debugfs_chipset_info, 0, NULL }, + { "memory", nouveau_debugfs_memory_info, 0, NULL }, ++ { "vbios.rom", nouveau_debugfs_vbios_image, 0, NULL }, + }; + #define NOUVEAU_DEBUGFS_ENTRIES ARRAY_SIZE(nouveau_debugfs_list) + +diff --git a/drivers/gpu/drm/nouveau/nouveau_dma.c b/drivers/gpu/drm/nouveau/nouveau_dma.c +index c8482a1..65c441a 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_dma.c ++++ b/drivers/gpu/drm/nouveau/nouveau_dma.c +@@ -190,6 +190,11 @@ nv50_dma_push(struct nouveau_channel *chan, struct nouveau_bo *bo, + nouveau_bo_wr32(pb, ip++, upper_32_bits(offset) | length << 8); + + chan->dma.ib_put = (chan->dma.ib_put + 1) & chan->dma.ib_max; ++ ++ DRM_MEMORYBARRIER(); ++ /* Flush writes. */ ++ nouveau_bo_rd32(pb, 0); ++ + nvchan_wr32(chan, 0x8c, chan->dma.ib_put); + chan->dma.ib_free--; + } +diff --git a/drivers/gpu/drm/nouveau/nouveau_dp.c b/drivers/gpu/drm/nouveau/nouveau_dp.c +index f954ad9..deeb21c 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_dp.c ++++ b/drivers/gpu/drm/nouveau/nouveau_dp.c +@@ -483,7 +483,7 @@ nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr, + ctrl |= (cmd << NV50_AUXCH_CTRL_CMD_SHIFT); + ctrl |= ((data_nr - 1) << NV50_AUXCH_CTRL_LEN_SHIFT); + +- for (;;) { ++ for (i = 0; i < 16; i++) { + nv_wr32(dev, NV50_AUXCH_CTRL(index), ctrl | 0x80000000); + nv_wr32(dev, NV50_AUXCH_CTRL(index), ctrl); + nv_wr32(dev, NV50_AUXCH_CTRL(index), ctrl | 0x00010000); +@@ -502,6 +502,12 @@ nouveau_dp_auxch(struct nouveau_i2c_chan *auxch, int cmd, int addr, + break; + } + ++ if (i == 16) { ++ NV_ERROR(dev, "auxch DEFER too many times, bailing\n"); ++ ret = -EREMOTEIO; ++ goto out; ++ } ++ + if (cmd & 1) { + if ((stat & NV50_AUXCH_STAT_COUNT) != data_nr) { + ret = -EREMOTEIO; +diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.c b/drivers/gpu/drm/nouveau/nouveau_drv.c +index da3b93b..60a709c 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_drv.c ++++ b/drivers/gpu/drm/nouveau/nouveau_drv.c +@@ -75,14 +75,22 @@ MODULE_PARM_DESC(ignorelid, "Ignore ACPI lid status"); + int nouveau_ignorelid = 0; + module_param_named(ignorelid, nouveau_ignorelid, int, 0400); + +-MODULE_PARM_DESC(noagp, "Disable all acceleration"); ++MODULE_PARM_DESC(noaccel, "Disable all acceleration"); + int nouveau_noaccel = 0; + module_param_named(noaccel, nouveau_noaccel, int, 0400); + +-MODULE_PARM_DESC(noagp, "Disable fbcon acceleration"); ++MODULE_PARM_DESC(nofbaccel, "Disable fbcon acceleration"); + int nouveau_nofbaccel = 0; + module_param_named(nofbaccel, nouveau_nofbaccel, int, 0400); + ++MODULE_PARM_DESC(override_conntype, "Ignore DCB connector type"); ++int nouveau_override_conntype = 0; ++module_param_named(override_conntype, nouveau_override_conntype, int, 0400); ++ ++MODULE_PARM_DESC(tv_disable, "Disable TV-out detection\n"); ++int nouveau_tv_disable = 0; ++module_param_named(tv_disable, nouveau_tv_disable, int, 0400); ++ + MODULE_PARM_DESC(tv_norm, "Default TV norm.\n" + "\t\tSupported: PAL, PAL-M, PAL-N, PAL-Nc, NTSC-M, NTSC-J,\n" + "\t\t\thd480i, hd480p, hd576i, hd576p, hd720p, hd1080i.\n" +@@ -154,9 +162,11 @@ nouveau_pci_suspend(struct pci_dev *pdev, pm_message_t pm_state) + if (pm_state.event == PM_EVENT_PRETHAW) + return 0; + ++ NV_INFO(dev, "Disabling fbcon acceleration...\n"); + fbdev_flags = dev_priv->fbdev_info->flags; + dev_priv->fbdev_info->flags |= FBINFO_HWACCEL_DISABLED; + ++ NV_INFO(dev, "Unpinning framebuffer(s)...\n"); + list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { + struct nouveau_framebuffer *nouveau_fb; + +diff --git a/drivers/gpu/drm/nouveau/nouveau_drv.h b/drivers/gpu/drm/nouveau/nouveau_drv.h +index 5be0cca..c31159a 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_drv.h ++++ b/drivers/gpu/drm/nouveau/nouveau_drv.h +@@ -76,6 +76,7 @@ struct nouveau_bo { + struct ttm_buffer_object bo; + struct ttm_placement placement; + u32 placements[3]; ++ u32 busy_placements[3]; + struct ttm_bo_kmap_obj kmap; + struct list_head head; + +@@ -195,7 +196,7 @@ struct nouveau_channel { + struct list_head pending; + uint32_t sequence; + uint32_t sequence_ack; +- uint32_t last_sequence_irq; ++ atomic_t last_sequence_irq; + } fence; + + /* DMA push buffer */ +@@ -519,6 +520,7 @@ struct drm_nouveau_private { + + struct workqueue_struct *wq; + struct work_struct irq_work; ++ struct work_struct hpd_work; + + struct list_head vbl_waiting; + +@@ -533,12 +535,14 @@ struct drm_nouveau_private { + + struct fb_info *fbdev_info; + +- int fifo_alloc_count; + struct nouveau_channel *fifos[NOUVEAU_MAX_CHANNEL_NR]; + + struct nouveau_engine engine; + struct nouveau_channel *channel; + ++ /* For PFIFO and PGRAPH. */ ++ spinlock_t context_switch_lock; ++ + /* RAMIN configuration, RAMFC, RAMHT and RAMRO offsets */ + struct nouveau_gpuobj *ramht; + uint32_t ramin_rsvd_vram; +@@ -550,12 +554,6 @@ struct drm_nouveau_private { + uint32_t ramro_offset; + uint32_t ramro_size; + +- /* base physical adresses */ +- uint64_t fb_phys; +- uint64_t fb_available_size; +- uint64_t fb_mappable_pages; +- uint64_t fb_aper_free; +- + struct { + enum { + NOUVEAU_GART_NONE = 0, +@@ -569,10 +567,6 @@ struct drm_nouveau_private { + struct nouveau_gpuobj *sg_ctxdma; + struct page *sg_dummy_page; + dma_addr_t sg_dummy_bus; +- +- /* nottm hack */ +- struct drm_ttm_backend *sg_be; +- unsigned long sg_handle; + } gart_info; + + /* nv10-nv40 tiling regions */ +@@ -581,6 +575,16 @@ struct drm_nouveau_private { + spinlock_t lock; + } tile; + ++ /* VRAM/fb configuration */ ++ uint64_t vram_size; ++ uint64_t vram_sys_base; ++ ++ uint64_t fb_phys; ++ uint64_t fb_available_size; ++ uint64_t fb_mappable_pages; ++ uint64_t fb_aper_free; ++ int fb_mtrr; ++ + /* G8x/G9x virtual address space */ + uint64_t vm_gart_base; + uint64_t vm_gart_size; +@@ -589,10 +593,6 @@ struct drm_nouveau_private { + uint64_t vm_end; + struct nouveau_gpuobj *vm_vram_pt[NV50_VM_VRAM_NR]; + int vm_vram_pt_nr; +- uint64_t vram_sys_base; +- +- /* the mtrr covering the FB */ +- int fb_mtrr; + + struct mem_block *ramin_heap; + +@@ -602,8 +602,7 @@ struct drm_nouveau_private { + + struct list_head gpuobj_list; + +- struct nvbios VBIOS; +- struct nouveau_bios_info *vbios; ++ struct nvbios vbios; + + struct nv04_mode_state mode_reg; + struct nv04_mode_state saved_reg; +@@ -612,11 +611,7 @@ struct drm_nouveau_private { + uint32_t dac_users[4]; + + struct nouveau_suspend_resume { +- uint32_t fifo_mode; +- uint32_t graph_ctx_control; +- uint32_t graph_state; + uint32_t *ramin_copy; +- uint64_t ramin_size; + } susres; + + struct backlight_device *backlight; +@@ -680,6 +675,7 @@ extern int nouveau_uscript_tmds; + extern int nouveau_vram_pushbuf; + extern int nouveau_vram_notify; + extern int nouveau_fbpercrtc; ++extern int nouveau_tv_disable; + extern char *nouveau_tv_norm; + extern int nouveau_reg_debug; + extern char *nouveau_vbios; +@@ -687,6 +683,7 @@ extern int nouveau_ctxfw; + extern int nouveau_ignorelid; + extern int nouveau_nofbaccel; + extern int nouveau_noaccel; ++extern int nouveau_override_conntype; + + /* nouveau_state.c */ + extern void nouveau_preclose(struct drm_device *dev, struct drm_file *); +@@ -711,7 +708,7 @@ extern struct mem_block *nouveau_mem_alloc_block(struct mem_block *, + struct drm_file *, int tail); + extern void nouveau_mem_takedown(struct mem_block **heap); + extern void nouveau_mem_free_block(struct mem_block *); +-extern uint64_t nouveau_mem_fb_amount(struct drm_device *); ++extern int nouveau_mem_detect(struct drm_device *dev); + extern void nouveau_mem_release(struct drm_file *, struct mem_block *heap); + extern int nouveau_mem_init(struct drm_device *); + extern int nouveau_mem_init_agp(struct drm_device *); +@@ -928,6 +925,10 @@ extern void nv40_fb_takedown(struct drm_device *); + extern void nv40_fb_set_region_tiling(struct drm_device *, int, uint32_t, + uint32_t, uint32_t); + ++/* nv50_fb.c */ ++extern int nv50_fb_init(struct drm_device *); ++extern void nv50_fb_takedown(struct drm_device *); ++ + /* nv04_fifo.c */ + extern int nv04_fifo_init(struct drm_device *); + extern void nv04_fifo_disable(struct drm_device *); +@@ -1027,6 +1028,7 @@ extern void nv50_graph_destroy_context(struct nouveau_channel *); + extern int nv50_graph_load_context(struct nouveau_channel *); + extern int nv50_graph_unload_context(struct drm_device *); + extern void nv50_graph_context_switch(struct drm_device *); ++extern int nv50_grctx_init(struct nouveau_grctx *); + + /* nouveau_grctx.c */ + extern int nouveau_grctx_prog_load(struct drm_device *); +@@ -1081,13 +1083,13 @@ extern long nouveau_compat_ioctl(struct file *file, unsigned int cmd, + unsigned long arg); + + /* nv04_dac.c */ +-extern int nv04_dac_create(struct drm_device *dev, struct dcb_entry *entry); ++extern int nv04_dac_create(struct drm_connector *, struct dcb_entry *); + extern uint32_t nv17_dac_sample_load(struct drm_encoder *encoder); + extern int nv04_dac_output_offset(struct drm_encoder *encoder); + extern void nv04_dac_update_dacclk(struct drm_encoder *encoder, bool enable); + + /* nv04_dfp.c */ +-extern int nv04_dfp_create(struct drm_device *dev, struct dcb_entry *entry); ++extern int nv04_dfp_create(struct drm_connector *, struct dcb_entry *); + extern int nv04_dfp_get_bound_head(struct drm_device *dev, struct dcb_entry *dcbent); + extern void nv04_dfp_bind_head(struct drm_device *dev, struct dcb_entry *dcbent, + int head, bool dl); +@@ -1096,10 +1098,10 @@ extern void nv04_dfp_update_fp_control(struct drm_encoder *encoder, int mode); + + /* nv04_tv.c */ + extern int nv04_tv_identify(struct drm_device *dev, int i2c_index); +-extern int nv04_tv_create(struct drm_device *dev, struct dcb_entry *entry); ++extern int nv04_tv_create(struct drm_connector *, struct dcb_entry *); + + /* nv17_tv.c */ +-extern int nv17_tv_create(struct drm_device *dev, struct dcb_entry *entry); ++extern int nv17_tv_create(struct drm_connector *, struct dcb_entry *); + + /* nv04_display.c */ + extern int nv04_display_create(struct drm_device *); +@@ -1119,7 +1121,8 @@ extern int nouveau_bo_pin(struct nouveau_bo *, uint32_t flags); + extern int nouveau_bo_unpin(struct nouveau_bo *); + extern int nouveau_bo_map(struct nouveau_bo *); + extern void nouveau_bo_unmap(struct nouveau_bo *); +-extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t memtype); ++extern void nouveau_bo_placement_set(struct nouveau_bo *, uint32_t type, ++ uint32_t busy); + extern u16 nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index); + extern void nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val); + extern u32 nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index); +@@ -1139,7 +1142,6 @@ extern int nouveau_fence_wait(void *obj, void *arg, bool lazy, bool intr); + extern int nouveau_fence_flush(void *obj, void *arg); + extern void nouveau_fence_unref(void **obj); + extern void *nouveau_fence_ref(void *obj); +-extern void nouveau_fence_handler(struct drm_device *dev, int channel); + + /* nouveau_gem.c */ + extern int nouveau_gem_new(struct drm_device *, struct nouveau_channel *, +@@ -1163,6 +1165,16 @@ extern int nouveau_gem_ioctl_info(struct drm_device *, void *, + int nv17_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag); + int nv17_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state); + ++/* nv50_gpio.c */ ++int nv50_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag); ++int nv50_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state); ++ ++/* nv50_calc. */ ++int nv50_calc_pll(struct drm_device *, struct pll_lims *, int clk, ++ int *N1, int *M1, int *N2, int *M2, int *P); ++int nv50_calc_pll2(struct drm_device *, struct pll_lims *, ++ int clk, int *N, int *fN, int *M, int *P); ++ + #ifndef ioread32_native + #ifdef __BIG_ENDIAN + #define ioread16_native ioread16be +diff --git a/drivers/gpu/drm/nouveau/nouveau_encoder.h b/drivers/gpu/drm/nouveau/nouveau_encoder.h +index bc4a240..e4442e2 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_encoder.h ++++ b/drivers/gpu/drm/nouveau/nouveau_encoder.h +@@ -47,6 +47,9 @@ struct nouveau_encoder { + + union { + struct { ++ int mc_unknown; ++ uint32_t unk0; ++ uint32_t unk1; + int dpcd_version; + int link_nr; + int link_bw; +@@ -68,8 +71,8 @@ static inline struct drm_encoder *to_drm_encoder(struct nouveau_encoder *enc) + + struct nouveau_connector * + nouveau_encoder_connector_get(struct nouveau_encoder *encoder); +-int nv50_sor_create(struct drm_device *dev, struct dcb_entry *entry); +-int nv50_dac_create(struct drm_device *dev, struct dcb_entry *entry); ++int nv50_sor_create(struct drm_connector *, struct dcb_entry *); ++int nv50_dac_create(struct drm_connector *, struct dcb_entry *); + + struct bit_displayport_encoder_table { + uint32_t match; +diff --git a/drivers/gpu/drm/nouveau/nouveau_fence.c b/drivers/gpu/drm/nouveau/nouveau_fence.c +index faddf53..813d853 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_fence.c ++++ b/drivers/gpu/drm/nouveau/nouveau_fence.c +@@ -67,12 +67,13 @@ nouveau_fence_update(struct nouveau_channel *chan) + if (USE_REFCNT) + sequence = nvchan_rd32(chan, 0x48); + else +- sequence = chan->fence.last_sequence_irq; ++ sequence = atomic_read(&chan->fence.last_sequence_irq); + + if (chan->fence.sequence_ack == sequence) + return; + chan->fence.sequence_ack = sequence; + ++ spin_lock(&chan->fence.lock); + list_for_each_safe(entry, tmp, &chan->fence.pending) { + fence = list_entry(entry, struct nouveau_fence, entry); + +@@ -84,6 +85,7 @@ nouveau_fence_update(struct nouveau_channel *chan) + if (sequence == chan->fence.sequence_ack) + break; + } ++ spin_unlock(&chan->fence.lock); + } + + int +@@ -119,7 +121,6 @@ nouveau_fence_emit(struct nouveau_fence *fence) + { + struct drm_nouveau_private *dev_priv = fence->channel->dev->dev_private; + struct nouveau_channel *chan = fence->channel; +- unsigned long flags; + int ret; + + ret = RING_SPACE(chan, 2); +@@ -127,9 +128,7 @@ nouveau_fence_emit(struct nouveau_fence *fence) + return ret; + + if (unlikely(chan->fence.sequence == chan->fence.sequence_ack - 1)) { +- spin_lock_irqsave(&chan->fence.lock, flags); + nouveau_fence_update(chan); +- spin_unlock_irqrestore(&chan->fence.lock, flags); + + BUG_ON(chan->fence.sequence == + chan->fence.sequence_ack - 1); +@@ -138,9 +137,9 @@ nouveau_fence_emit(struct nouveau_fence *fence) + fence->sequence = ++chan->fence.sequence; + + kref_get(&fence->refcount); +- spin_lock_irqsave(&chan->fence.lock, flags); ++ spin_lock(&chan->fence.lock); + list_add_tail(&fence->entry, &chan->fence.pending); +- spin_unlock_irqrestore(&chan->fence.lock, flags); ++ spin_unlock(&chan->fence.lock); + + BEGIN_RING(chan, NvSubSw, USE_REFCNT ? 0x0050 : 0x0150, 1); + OUT_RING(chan, fence->sequence); +@@ -173,14 +172,11 @@ nouveau_fence_signalled(void *sync_obj, void *sync_arg) + { + struct nouveau_fence *fence = nouveau_fence(sync_obj); + struct nouveau_channel *chan = fence->channel; +- unsigned long flags; + + if (fence->signalled) + return true; + +- spin_lock_irqsave(&chan->fence.lock, flags); + nouveau_fence_update(chan); +- spin_unlock_irqrestore(&chan->fence.lock, flags); + return fence->signalled; + } + +@@ -221,27 +217,12 @@ nouveau_fence_flush(void *sync_obj, void *sync_arg) + return 0; + } + +-void +-nouveau_fence_handler(struct drm_device *dev, int channel) +-{ +- struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nouveau_channel *chan = NULL; +- +- if (channel >= 0 && channel < dev_priv->engine.fifo.channels) +- chan = dev_priv->fifos[channel]; +- +- if (chan) { +- spin_lock_irq(&chan->fence.lock); +- nouveau_fence_update(chan); +- spin_unlock_irq(&chan->fence.lock); +- } +-} +- + int + nouveau_fence_init(struct nouveau_channel *chan) + { + INIT_LIST_HEAD(&chan->fence.pending); + spin_lock_init(&chan->fence.lock); ++ atomic_set(&chan->fence.last_sequence_irq, 0); + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_gem.c b/drivers/gpu/drm/nouveau/nouveau_gem.c +index 8265fed..0846a1e 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_gem.c ++++ b/drivers/gpu/drm/nouveau/nouveau_gem.c +@@ -182,40 +182,35 @@ nouveau_gem_set_domain(struct drm_gem_object *gem, uint32_t read_domains, + { + struct nouveau_bo *nvbo = gem->driver_private; + struct ttm_buffer_object *bo = &nvbo->bo; +- uint64_t flags; ++ uint32_t domains = valid_domains & ++ (write_domains ? write_domains : read_domains); ++ uint32_t pref_flags = 0, valid_flags = 0; + +- if (!valid_domains || (!read_domains && !write_domains)) ++ if (!domains) + return -EINVAL; + +- if (write_domains) { +- if ((valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) && +- (write_domains & NOUVEAU_GEM_DOMAIN_VRAM)) +- flags = TTM_PL_FLAG_VRAM; +- else +- if ((valid_domains & NOUVEAU_GEM_DOMAIN_GART) && +- (write_domains & NOUVEAU_GEM_DOMAIN_GART)) +- flags = TTM_PL_FLAG_TT; +- else +- return -EINVAL; +- } else { +- if ((valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) && +- (read_domains & NOUVEAU_GEM_DOMAIN_VRAM) && +- bo->mem.mem_type == TTM_PL_VRAM) +- flags = TTM_PL_FLAG_VRAM; +- else +- if ((valid_domains & NOUVEAU_GEM_DOMAIN_GART) && +- (read_domains & NOUVEAU_GEM_DOMAIN_GART) && +- bo->mem.mem_type == TTM_PL_TT) +- flags = TTM_PL_FLAG_TT; +- else +- if ((valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) && +- (read_domains & NOUVEAU_GEM_DOMAIN_VRAM)) +- flags = TTM_PL_FLAG_VRAM; +- else +- flags = TTM_PL_FLAG_TT; +- } ++ if (valid_domains & NOUVEAU_GEM_DOMAIN_VRAM) ++ valid_flags |= TTM_PL_FLAG_VRAM; ++ ++ if (valid_domains & NOUVEAU_GEM_DOMAIN_GART) ++ valid_flags |= TTM_PL_FLAG_TT; ++ ++ if ((domains & NOUVEAU_GEM_DOMAIN_VRAM) && ++ bo->mem.mem_type == TTM_PL_VRAM) ++ pref_flags |= TTM_PL_FLAG_VRAM; ++ ++ else if ((domains & NOUVEAU_GEM_DOMAIN_GART) && ++ bo->mem.mem_type == TTM_PL_TT) ++ pref_flags |= TTM_PL_FLAG_TT; ++ ++ else if (domains & NOUVEAU_GEM_DOMAIN_VRAM) ++ pref_flags |= TTM_PL_FLAG_VRAM; ++ ++ else ++ pref_flags |= TTM_PL_FLAG_TT; ++ ++ nouveau_bo_placement_set(nvbo, pref_flags, valid_flags); + +- nouveau_bo_placement_set(nvbo, flags); + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_hw.c b/drivers/gpu/drm/nouveau/nouveau_hw.c +index dc46792..7855b35 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_hw.c ++++ b/drivers/gpu/drm/nouveau/nouveau_hw.c +@@ -160,7 +160,7 @@ static void + setPLL_single(struct drm_device *dev, uint32_t reg, struct nouveau_pll_vals *pv) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- int chip_version = dev_priv->vbios->chip_version; ++ int chip_version = dev_priv->vbios.chip_version; + uint32_t oldpll = NVReadRAMDAC(dev, 0, reg); + int oldN = (oldpll >> 8) & 0xff, oldM = oldpll & 0xff; + uint32_t pll = (oldpll & 0xfff80000) | pv->log2P << 16 | pv->NM1; +@@ -216,7 +216,7 @@ setPLL_double_highregs(struct drm_device *dev, uint32_t reg1, + struct nouveau_pll_vals *pv) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- int chip_version = dev_priv->vbios->chip_version; ++ int chip_version = dev_priv->vbios.chip_version; + bool nv3035 = chip_version == 0x30 || chip_version == 0x35; + uint32_t reg2 = reg1 + ((reg1 == NV_RAMDAC_VPLL2) ? 0x5c : 0x70); + uint32_t oldpll1 = NVReadRAMDAC(dev, 0, reg1); +@@ -374,7 +374,7 @@ nouveau_hw_setpll(struct drm_device *dev, uint32_t reg1, + struct nouveau_pll_vals *pv) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- int cv = dev_priv->vbios->chip_version; ++ int cv = dev_priv->vbios.chip_version; + + if (cv == 0x30 || cv == 0x31 || cv == 0x35 || cv == 0x36 || + cv >= 0x40) { +diff --git a/drivers/gpu/drm/nouveau/nouveau_i2c.c b/drivers/gpu/drm/nouveau/nouveau_i2c.c +index 70e994d..316a3c7 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_i2c.c ++++ b/drivers/gpu/drm/nouveau/nouveau_i2c.c +@@ -254,16 +254,27 @@ struct nouveau_i2c_chan * + nouveau_i2c_find(struct drm_device *dev, int index) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct dcb_i2c_entry *i2c = &dev_priv->vbios.dcb.i2c[index]; + +- if (index > DCB_MAX_NUM_I2C_ENTRIES) ++ if (index >= DCB_MAX_NUM_I2C_ENTRIES) + return NULL; + +- if (!bios->bdcb.dcb.i2c[index].chan) { +- if (nouveau_i2c_init(dev, &bios->bdcb.dcb.i2c[index], index)) +- return NULL; ++ if (dev_priv->chipset >= NV_50 && (i2c->entry & 0x00000100)) { ++ uint32_t reg = 0xe500, val; ++ ++ if (i2c->port_type == 6) { ++ reg += i2c->read * 0x50; ++ val = 0x2002; ++ } else { ++ reg += ((i2c->entry & 0x1e00) >> 9) * 0x50; ++ val = 0xe001; ++ } ++ ++ nv_wr32(dev, reg, (nv_rd32(dev, reg) & ~0xf003) | val); + } + +- return bios->bdcb.dcb.i2c[index].chan; ++ if (!i2c->chan && nouveau_i2c_init(dev, i2c, index)) ++ return NULL; ++ return i2c->chan; + } + +diff --git a/drivers/gpu/drm/nouveau/nouveau_irq.c b/drivers/gpu/drm/nouveau/nouveau_irq.c +index 447f9f6..13e73ce 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_irq.c ++++ b/drivers/gpu/drm/nouveau/nouveau_irq.c +@@ -51,6 +51,7 @@ nouveau_irq_preinstall(struct drm_device *dev) + + if (dev_priv->card_type == NV_50) { + INIT_WORK(&dev_priv->irq_work, nv50_display_irq_handler_bh); ++ INIT_WORK(&dev_priv->hpd_work, nv50_display_irq_hotplug_bh); + INIT_LIST_HEAD(&dev_priv->vbl_waiting); + } + } +@@ -311,6 +312,31 @@ nouveau_print_bitfield_names_(uint32_t value, + #define nouveau_print_bitfield_names(val, namelist) \ + nouveau_print_bitfield_names_((val), (namelist), ARRAY_SIZE(namelist)) + ++struct nouveau_enum_names { ++ uint32_t value; ++ const char *name; ++}; ++ ++static void ++nouveau_print_enum_names_(uint32_t value, ++ const struct nouveau_enum_names *namelist, ++ const int namelist_len) ++{ ++ /* ++ * Caller must have already printed the KERN_* log level for us. ++ * Also the caller is responsible for adding the newline. ++ */ ++ int i; ++ for (i = 0; i < namelist_len; ++i) { ++ if (value == namelist[i].value) { ++ printk("%s", namelist[i].name); ++ return; ++ } ++ } ++ printk("unknown value 0x%08x", value); ++} ++#define nouveau_print_enum_names(val, namelist) \ ++ nouveau_print_enum_names_((val), (namelist), ARRAY_SIZE(namelist)) + + static int + nouveau_graph_chid_from_grctx(struct drm_device *dev) +@@ -427,14 +453,16 @@ nouveau_graph_dump_trap_info(struct drm_device *dev, const char *id, + struct drm_nouveau_private *dev_priv = dev->dev_private; + uint32_t nsource = trap->nsource, nstatus = trap->nstatus; + +- NV_INFO(dev, "%s - nSource:", id); +- nouveau_print_bitfield_names(nsource, nsource_names); +- printk(", nStatus:"); +- if (dev_priv->card_type < NV_10) +- nouveau_print_bitfield_names(nstatus, nstatus_names); +- else +- nouveau_print_bitfield_names(nstatus, nstatus_names_nv10); +- printk("\n"); ++ if (dev_priv->card_type < NV_50) { ++ NV_INFO(dev, "%s - nSource:", id); ++ nouveau_print_bitfield_names(nsource, nsource_names); ++ printk(", nStatus:"); ++ if (dev_priv->card_type < NV_10) ++ nouveau_print_bitfield_names(nstatus, nstatus_names); ++ else ++ nouveau_print_bitfield_names(nstatus, nstatus_names_nv10); ++ printk("\n"); ++ } + + NV_INFO(dev, "%s - Ch %d/%d Class 0x%04x Mthd 0x%04x " + "Data 0x%08x:0x%08x\n", +@@ -578,27 +606,502 @@ nouveau_pgraph_irq_handler(struct drm_device *dev) + } + + static void ++nv50_pfb_vm_trap(struct drm_device *dev, int display, const char *name) ++{ ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ uint32_t trap[6]; ++ int i, ch; ++ uint32_t idx = nv_rd32(dev, 0x100c90); ++ if (idx & 0x80000000) { ++ idx &= 0xffffff; ++ if (display) { ++ for (i = 0; i < 6; i++) { ++ nv_wr32(dev, 0x100c90, idx | i << 24); ++ trap[i] = nv_rd32(dev, 0x100c94); ++ } ++ for (ch = 0; ch < dev_priv->engine.fifo.channels; ch++) { ++ struct nouveau_channel *chan = dev_priv->fifos[ch]; ++ ++ if (!chan || !chan->ramin) ++ continue; ++ ++ if (trap[1] == chan->ramin->instance >> 12) ++ break; ++ } ++ NV_INFO(dev, "%s - VM: Trapped %s at %02x%04x%04x status %08x %08x channel %d\n", ++ name, (trap[5]&0x100?"read":"write"), ++ trap[5]&0xff, trap[4]&0xffff, ++ trap[3]&0xffff, trap[0], trap[2], ch); ++ } ++ nv_wr32(dev, 0x100c90, idx | 0x80000000); ++ } else if (display) { ++ NV_INFO(dev, "%s - no VM fault?\n", name); ++ } ++} ++ ++static struct nouveau_enum_names nv50_mp_exec_error_names[] = ++{ ++ { 3, "STACK_UNDERFLOW" }, ++ { 4, "QUADON_ACTIVE" }, ++ { 8, "TIMEOUT" }, ++ { 0x10, "INVALID_OPCODE" }, ++ { 0x40, "BREAKPOINT" }, ++}; ++ ++static void ++nv50_pgraph_mp_trap(struct drm_device *dev, int tpid, int display) ++{ ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ uint32_t units = nv_rd32(dev, 0x1540); ++ uint32_t addr, mp10, status, pc, oplow, ophigh; ++ int i; ++ int mps = 0; ++ for (i = 0; i < 4; i++) { ++ if (!(units & 1 << (i+24))) ++ continue; ++ if (dev_priv->chipset < 0xa0) ++ addr = 0x408200 + (tpid << 12) + (i << 7); ++ else ++ addr = 0x408100 + (tpid << 11) + (i << 7); ++ mp10 = nv_rd32(dev, addr + 0x10); ++ status = nv_rd32(dev, addr + 0x14); ++ if (!status) ++ continue; ++ if (display) { ++ nv_rd32(dev, addr + 0x20); ++ pc = nv_rd32(dev, addr + 0x24); ++ oplow = nv_rd32(dev, addr + 0x70); ++ ophigh= nv_rd32(dev, addr + 0x74); ++ NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - " ++ "TP %d MP %d: ", tpid, i); ++ nouveau_print_enum_names(status, ++ nv50_mp_exec_error_names); ++ printk(" at %06x warp %d, opcode %08x %08x\n", ++ pc&0xffffff, pc >> 24, ++ oplow, ophigh); ++ } ++ nv_wr32(dev, addr + 0x10, mp10); ++ nv_wr32(dev, addr + 0x14, 0); ++ mps++; ++ } ++ if (!mps && display) ++ NV_INFO(dev, "PGRAPH_TRAP_MP_EXEC - TP %d: " ++ "No MPs claiming errors?\n", tpid); ++} ++ ++static void ++nv50_pgraph_tp_trap(struct drm_device *dev, int type, uint32_t ustatus_old, ++ uint32_t ustatus_new, int display, const char *name) ++{ ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ int tps = 0; ++ uint32_t units = nv_rd32(dev, 0x1540); ++ int i, r; ++ uint32_t ustatus_addr, ustatus; ++ for (i = 0; i < 16; i++) { ++ if (!(units & (1 << i))) ++ continue; ++ if (dev_priv->chipset < 0xa0) ++ ustatus_addr = ustatus_old + (i << 12); ++ else ++ ustatus_addr = ustatus_new + (i << 11); ++ ustatus = nv_rd32(dev, ustatus_addr) & 0x7fffffff; ++ if (!ustatus) ++ continue; ++ tps++; ++ switch (type) { ++ case 6: /* texture error... unknown for now */ ++ nv50_pfb_vm_trap(dev, display, name); ++ if (display) { ++ NV_ERROR(dev, "magic set %d:\n", i); ++ for (r = ustatus_addr + 4; r <= ustatus_addr + 0x10; r += 4) ++ NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, ++ nv_rd32(dev, r)); ++ } ++ break; ++ case 7: /* MP error */ ++ if (ustatus & 0x00010000) { ++ nv50_pgraph_mp_trap(dev, i, display); ++ ustatus &= ~0x00010000; ++ } ++ break; ++ case 8: /* TPDMA error */ ++ { ++ uint32_t e0c = nv_rd32(dev, ustatus_addr + 4); ++ uint32_t e10 = nv_rd32(dev, ustatus_addr + 8); ++ uint32_t e14 = nv_rd32(dev, ustatus_addr + 0xc); ++ uint32_t e18 = nv_rd32(dev, ustatus_addr + 0x10); ++ uint32_t e1c = nv_rd32(dev, ustatus_addr + 0x14); ++ uint32_t e20 = nv_rd32(dev, ustatus_addr + 0x18); ++ uint32_t e24 = nv_rd32(dev, ustatus_addr + 0x1c); ++ nv50_pfb_vm_trap(dev, display, name); ++ /* 2d engine destination */ ++ if (ustatus & 0x00000010) { ++ if (display) { ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - Unknown fault at address %02x%08x\n", ++ i, e14, e10); ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA_2D - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n", ++ i, e0c, e18, e1c, e20, e24); ++ } ++ ustatus &= ~0x00000010; ++ } ++ /* Render target */ ++ if (ustatus & 0x00000040) { ++ if (display) { ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - Unknown fault at address %02x%08x\n", ++ i, e14, e10); ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA_RT - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n", ++ i, e0c, e18, e1c, e20, e24); ++ } ++ ustatus &= ~0x00000040; ++ } ++ /* CUDA memory: l[], g[] or stack. */ ++ if (ustatus & 0x00000080) { ++ if (display) { ++ if (e18 & 0x80000000) { ++ /* g[] read fault? */ ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global read fault at address %02x%08x\n", ++ i, e14, e10 | ((e18 >> 24) & 0x1f)); ++ e18 &= ~0x1f000000; ++ } else if (e18 & 0xc) { ++ /* g[] write fault? */ ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Global write fault at address %02x%08x\n", ++ i, e14, e10 | ((e18 >> 7) & 0x1f)); ++ e18 &= ~0x00000f80; ++ } else { ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - Unknown CUDA fault at address %02x%08x\n", ++ i, e14, e10); ++ } ++ NV_INFO(dev, "PGRAPH_TRAP_TPDMA - TP %d - e0c: %08x, e18: %08x, e1c: %08x, e20: %08x, e24: %08x\n", ++ i, e0c, e18, e1c, e20, e24); ++ } ++ ustatus &= ~0x00000080; ++ } ++ } ++ break; ++ } ++ if (ustatus) { ++ if (display) ++ NV_INFO(dev, "%s - TP%d: Unhandled ustatus 0x%08x\n", name, i, ustatus); ++ } ++ nv_wr32(dev, ustatus_addr, 0xc0000000); ++ } ++ ++ if (!tps && display) ++ NV_INFO(dev, "%s - No TPs claiming errors?\n", name); ++} ++ ++static void ++nv50_pgraph_trap_handler(struct drm_device *dev) ++{ ++ struct nouveau_pgraph_trap trap; ++ uint32_t status = nv_rd32(dev, 0x400108); ++ uint32_t ustatus; ++ int display = nouveau_ratelimit(); ++ ++ ++ if (!status && display) { ++ nouveau_graph_trap_info(dev, &trap); ++ nouveau_graph_dump_trap_info(dev, "PGRAPH_TRAP", &trap); ++ NV_INFO(dev, "PGRAPH_TRAP - no units reporting traps?\n"); ++ } ++ ++ /* DISPATCH: Relays commands to other units and handles NOTIFY, ++ * COND, QUERY. If you get a trap from it, the command is still stuck ++ * in DISPATCH and you need to do something about it. */ ++ if (status & 0x001) { ++ ustatus = nv_rd32(dev, 0x400804) & 0x7fffffff; ++ if (!ustatus && display) { ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - no ustatus?\n"); ++ } ++ ++ /* Known to be triggered by screwed up NOTIFY and COND... */ ++ if (ustatus & 0x00000001) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_FAULT"); ++ nv_wr32(dev, 0x400500, 0); ++ if (nv_rd32(dev, 0x400808) & 0x80000000) { ++ if (display) { ++ if (nouveau_graph_trapped_channel(dev, &trap.channel)) ++ trap.channel = -1; ++ trap.class = nv_rd32(dev, 0x400814); ++ trap.mthd = nv_rd32(dev, 0x400808) & 0x1ffc; ++ trap.subc = (nv_rd32(dev, 0x400808) >> 16) & 0x7; ++ trap.data = nv_rd32(dev, 0x40080c); ++ trap.data2 = nv_rd32(dev, 0x400810); ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_TRAP_DISPATCH_FAULT", &trap); ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400808: %08x\n", nv_rd32(dev, 0x400808)); ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - 400848: %08x\n", nv_rd32(dev, 0x400848)); ++ } ++ nv_wr32(dev, 0x400808, 0); ++ } else if (display) { ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_FAULT - No stuck command?\n"); ++ } ++ nv_wr32(dev, 0x4008e8, nv_rd32(dev, 0x4008e8) & 3); ++ nv_wr32(dev, 0x400848, 0); ++ ustatus &= ~0x00000001; ++ } ++ if (ustatus & 0x00000002) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_DISPATCH_QUERY"); ++ nv_wr32(dev, 0x400500, 0); ++ if (nv_rd32(dev, 0x40084c) & 0x80000000) { ++ if (display) { ++ if (nouveau_graph_trapped_channel(dev, &trap.channel)) ++ trap.channel = -1; ++ trap.class = nv_rd32(dev, 0x400814); ++ trap.mthd = nv_rd32(dev, 0x40084c) & 0x1ffc; ++ trap.subc = (nv_rd32(dev, 0x40084c) >> 16) & 0x7; ++ trap.data = nv_rd32(dev, 0x40085c); ++ trap.data2 = 0; ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_TRAP_DISPATCH_QUERY", &trap); ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - 40084c: %08x\n", nv_rd32(dev, 0x40084c)); ++ } ++ nv_wr32(dev, 0x40084c, 0); ++ } else if (display) { ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH_QUERY - No stuck command?\n"); ++ } ++ ustatus &= ~0x00000002; ++ } ++ if (ustatus && display) ++ NV_INFO(dev, "PGRAPH_TRAP_DISPATCH - Unhandled ustatus 0x%08x\n", ustatus); ++ nv_wr32(dev, 0x400804, 0xc0000000); ++ nv_wr32(dev, 0x400108, 0x001); ++ status &= ~0x001; ++ } ++ ++ /* TRAPs other than dispatch use the "normal" trap regs. */ ++ if (status && display) { ++ nouveau_graph_trap_info(dev, &trap); ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_TRAP", &trap); ++ } ++ ++ /* M2MF: Memory to memory copy engine. */ ++ if (status & 0x002) { ++ ustatus = nv_rd32(dev, 0x406800) & 0x7fffffff; ++ if (!ustatus && display) { ++ NV_INFO(dev, "PGRAPH_TRAP_M2MF - no ustatus?\n"); ++ } ++ if (ustatus & 0x00000001) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_NOTIFY"); ++ ustatus &= ~0x00000001; ++ } ++ if (ustatus & 0x00000002) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_IN"); ++ ustatus &= ~0x00000002; ++ } ++ if (ustatus & 0x00000004) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_M2MF_OUT"); ++ ustatus &= ~0x00000004; ++ } ++ NV_INFO (dev, "PGRAPH_TRAP_M2MF - %08x %08x %08x %08x\n", ++ nv_rd32(dev, 0x406804), ++ nv_rd32(dev, 0x406808), ++ nv_rd32(dev, 0x40680c), ++ nv_rd32(dev, 0x406810)); ++ if (ustatus && display) ++ NV_INFO(dev, "PGRAPH_TRAP_M2MF - Unhandled ustatus 0x%08x\n", ustatus); ++ /* No sane way found yet -- just reset the bugger. */ ++ nv_wr32(dev, 0x400040, 2); ++ nv_wr32(dev, 0x400040, 0); ++ nv_wr32(dev, 0x406800, 0xc0000000); ++ nv_wr32(dev, 0x400108, 0x002); ++ status &= ~0x002; ++ } ++ ++ /* VFETCH: Fetches data from vertex buffers. */ ++ if (status & 0x004) { ++ ustatus = nv_rd32(dev, 0x400c04) & 0x7fffffff; ++ if (!ustatus && display) { ++ NV_INFO(dev, "PGRAPH_TRAP_VFETCH - no ustatus?\n"); ++ } ++ if (ustatus & 0x00000001) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_VFETCH_FAULT"); ++ NV_INFO (dev, "PGRAPH_TRAP_VFETCH_FAULT - %08x %08x %08x %08x\n", ++ nv_rd32(dev, 0x400c00), ++ nv_rd32(dev, 0x400c08), ++ nv_rd32(dev, 0x400c0c), ++ nv_rd32(dev, 0x400c10)); ++ ustatus &= ~0x00000001; ++ } ++ if (ustatus && display) ++ NV_INFO(dev, "PGRAPH_TRAP_VFETCH - Unhandled ustatus 0x%08x\n", ustatus); ++ nv_wr32(dev, 0x400c04, 0xc0000000); ++ nv_wr32(dev, 0x400108, 0x004); ++ status &= ~0x004; ++ } ++ ++ /* STRMOUT: DirectX streamout / OpenGL transform feedback. */ ++ if (status & 0x008) { ++ ustatus = nv_rd32(dev, 0x401800) & 0x7fffffff; ++ if (!ustatus && display) { ++ NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - no ustatus?\n"); ++ } ++ if (ustatus & 0x00000001) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_STRMOUT_FAULT"); ++ NV_INFO (dev, "PGRAPH_TRAP_STRMOUT_FAULT - %08x %08x %08x %08x\n", ++ nv_rd32(dev, 0x401804), ++ nv_rd32(dev, 0x401808), ++ nv_rd32(dev, 0x40180c), ++ nv_rd32(dev, 0x401810)); ++ ustatus &= ~0x00000001; ++ } ++ if (ustatus && display) ++ NV_INFO(dev, "PGRAPH_TRAP_STRMOUT - Unhandled ustatus 0x%08x\n", ustatus); ++ /* No sane way found yet -- just reset the bugger. */ ++ nv_wr32(dev, 0x400040, 0x80); ++ nv_wr32(dev, 0x400040, 0); ++ nv_wr32(dev, 0x401800, 0xc0000000); ++ nv_wr32(dev, 0x400108, 0x008); ++ status &= ~0x008; ++ } ++ ++ /* CCACHE: Handles code and c[] caches and fills them. */ ++ if (status & 0x010) { ++ ustatus = nv_rd32(dev, 0x405018) & 0x7fffffff; ++ if (!ustatus && display) { ++ NV_INFO(dev, "PGRAPH_TRAP_CCACHE - no ustatus?\n"); ++ } ++ if (ustatus & 0x00000001) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_CCACHE_FAULT"); ++ NV_INFO (dev, "PGRAPH_TRAP_CCACHE_FAULT - %08x %08x %08x %08x %08x %08x %08x\n", ++ nv_rd32(dev, 0x405800), ++ nv_rd32(dev, 0x405804), ++ nv_rd32(dev, 0x405808), ++ nv_rd32(dev, 0x40580c), ++ nv_rd32(dev, 0x405810), ++ nv_rd32(dev, 0x405814), ++ nv_rd32(dev, 0x40581c)); ++ ustatus &= ~0x00000001; ++ } ++ if (ustatus && display) ++ NV_INFO(dev, "PGRAPH_TRAP_CCACHE - Unhandled ustatus 0x%08x\n", ustatus); ++ nv_wr32(dev, 0x405018, 0xc0000000); ++ nv_wr32(dev, 0x400108, 0x010); ++ status &= ~0x010; ++ } ++ ++ /* Unknown, not seen yet... 0x402000 is the only trap status reg ++ * remaining, so try to handle it anyway. Perhaps related to that ++ * unknown DMA slot on tesla? */ ++ if (status & 0x20) { ++ nv50_pfb_vm_trap(dev, display, "PGRAPH_TRAP_UNKC04"); ++ ustatus = nv_rd32(dev, 0x402000) & 0x7fffffff; ++ if (display) ++ NV_INFO(dev, "PGRAPH_TRAP_UNKC04 - Unhandled ustatus 0x%08x\n", ustatus); ++ nv_wr32(dev, 0x402000, 0xc0000000); ++ /* no status modifiction on purpose */ ++ } ++ ++ /* TEXTURE: CUDA texturing units */ ++ if (status & 0x040) { ++ nv50_pgraph_tp_trap (dev, 6, 0x408900, 0x408600, display, ++ "PGRAPH_TRAP_TEXTURE"); ++ nv_wr32(dev, 0x400108, 0x040); ++ status &= ~0x040; ++ } ++ ++ /* MP: CUDA execution engines. */ ++ if (status & 0x080) { ++ nv50_pgraph_tp_trap (dev, 7, 0x408314, 0x40831c, display, ++ "PGRAPH_TRAP_MP"); ++ nv_wr32(dev, 0x400108, 0x080); ++ status &= ~0x080; ++ } ++ ++ /* TPDMA: Handles TP-initiated uncached memory accesses: ++ * l[], g[], stack, 2d surfaces, render targets. */ ++ if (status & 0x100) { ++ nv50_pgraph_tp_trap (dev, 8, 0x408e08, 0x408708, display, ++ "PGRAPH_TRAP_TPDMA"); ++ nv_wr32(dev, 0x400108, 0x100); ++ status &= ~0x100; ++ } ++ ++ if (status) { ++ if (display) ++ NV_INFO(dev, "PGRAPH_TRAP - Unknown trap 0x%08x\n", ++ status); ++ nv_wr32(dev, 0x400108, status); ++ } ++} ++ ++/* There must be a *lot* of these. Will take some time to gather them up. */ ++static struct nouveau_enum_names nv50_data_error_names[] = ++{ ++ { 4, "INVALID_VALUE" }, ++ { 5, "INVALID_ENUM" }, ++ { 8, "INVALID_OBJECT" }, ++ { 0xc, "INVALID_BITFIELD" }, ++ { 0x28, "MP_NO_REG_SPACE" }, ++ { 0x2b, "MP_BLOCK_SIZE_MISMATCH" }, ++}; ++ ++static void + nv50_pgraph_irq_handler(struct drm_device *dev) + { ++ struct nouveau_pgraph_trap trap; ++ int unhandled = 0; + uint32_t status; + + while ((status = nv_rd32(dev, NV03_PGRAPH_INTR))) { +- uint32_t nsource = nv_rd32(dev, NV03_PGRAPH_NSOURCE); +- ++ /* NOTIFY: You've set a NOTIFY an a command and it's done. */ + if (status & 0x00000001) { +- nouveau_pgraph_intr_notify(dev, nsource); ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_NOTIFY", &trap); + status &= ~0x00000001; + nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000001); + } + +- if (status & 0x00000010) { +- nouveau_pgraph_intr_error(dev, nsource | +- NV03_PGRAPH_NSOURCE_ILLEGAL_MTHD); ++ /* COMPUTE_QUERY: Purpose and exact cause unknown, happens ++ * when you write 0x200 to 0x50c0 method 0x31c. */ ++ if (status & 0x00000002) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_COMPUTE_QUERY", &trap); ++ status &= ~0x00000002; ++ nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000002); ++ } ++ ++ /* Unknown, never seen: 0x4 */ + ++ /* ILLEGAL_MTHD: You used a wrong method for this class. */ ++ if (status & 0x00000010) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_pgraph_intr_swmthd(dev, &trap)) ++ unhandled = 1; ++ if (unhandled && nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_ILLEGAL_MTHD", &trap); + status &= ~0x00000010; + nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000010); + } + ++ /* ILLEGAL_CLASS: You used a wrong class. */ ++ if (status & 0x00000020) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_ILLEGAL_CLASS", &trap); ++ status &= ~0x00000020; ++ nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000020); ++ } ++ ++ /* DOUBLE_NOTIFY: You tried to set a NOTIFY on another NOTIFY. */ ++ if (status & 0x00000040) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_DOUBLE_NOTIFY", &trap); ++ status &= ~0x00000040; ++ nv_wr32(dev, NV03_PGRAPH_INTR, 0x00000040); ++ } ++ ++ /* CONTEXT_SWITCH: PGRAPH needs us to load a new context */ + if (status & 0x00001000) { + nv_wr32(dev, 0x400500, 0x00000000); + nv_wr32(dev, NV03_PGRAPH_INTR, +@@ -613,49 +1116,59 @@ nv50_pgraph_irq_handler(struct drm_device *dev) + status &= ~NV_PGRAPH_INTR_CONTEXT_SWITCH; + } + +- if (status & 0x00100000) { +- nouveau_pgraph_intr_error(dev, nsource | +- NV03_PGRAPH_NSOURCE_DATA_ERROR); ++ /* BUFFER_NOTIFY: Your m2mf transfer finished */ ++ if (status & 0x00010000) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_BUFFER_NOTIFY", &trap); ++ status &= ~0x00010000; ++ nv_wr32(dev, NV03_PGRAPH_INTR, 0x00010000); ++ } + ++ /* DATA_ERROR: Invalid value for this method, or invalid ++ * state in current PGRAPH context for this operation */ ++ if (status & 0x00100000) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) { ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_DATA_ERROR", &trap); ++ NV_INFO (dev, "PGRAPH_DATA_ERROR - "); ++ nouveau_print_enum_names(nv_rd32(dev, 0x400110), ++ nv50_data_error_names); ++ printk("\n"); ++ } + status &= ~0x00100000; + nv_wr32(dev, NV03_PGRAPH_INTR, 0x00100000); + } + ++ /* TRAP: Something bad happened in the middle of command ++ * execution. Has a billion types, subtypes, and even ++ * subsubtypes. */ + if (status & 0x00200000) { +- int r; +- +- nouveau_pgraph_intr_error(dev, nsource | +- NV03_PGRAPH_NSOURCE_PROTECTION_ERROR); +- +- NV_ERROR(dev, "magic set 1:\n"); +- for (r = 0x408900; r <= 0x408910; r += 4) +- NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, +- nv_rd32(dev, r)); +- nv_wr32(dev, 0x408900, +- nv_rd32(dev, 0x408904) | 0xc0000000); +- for (r = 0x408e08; r <= 0x408e24; r += 4) +- NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, +- nv_rd32(dev, r)); +- nv_wr32(dev, 0x408e08, +- nv_rd32(dev, 0x408e08) | 0xc0000000); +- +- NV_ERROR(dev, "magic set 2:\n"); +- for (r = 0x409900; r <= 0x409910; r += 4) +- NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, +- nv_rd32(dev, r)); +- nv_wr32(dev, 0x409900, +- nv_rd32(dev, 0x409904) | 0xc0000000); +- for (r = 0x409e08; r <= 0x409e24; r += 4) +- NV_ERROR(dev, "\t0x%08x: 0x%08x\n", r, +- nv_rd32(dev, r)); +- nv_wr32(dev, 0x409e08, +- nv_rd32(dev, 0x409e08) | 0xc0000000); +- ++ nv50_pgraph_trap_handler(dev); + status &= ~0x00200000; +- nv_wr32(dev, NV03_PGRAPH_NSOURCE, nsource); + nv_wr32(dev, NV03_PGRAPH_INTR, 0x00200000); + } + ++ /* Unknown, never seen: 0x00400000 */ ++ ++ /* SINGLE_STEP: Happens on every method if you turned on ++ * single stepping in 40008c */ ++ if (status & 0x01000000) { ++ nouveau_graph_trap_info(dev, &trap); ++ if (nouveau_ratelimit()) ++ nouveau_graph_dump_trap_info(dev, ++ "PGRAPH_SINGLE_STEP", &trap); ++ status &= ~0x01000000; ++ nv_wr32(dev, NV03_PGRAPH_INTR, 0x01000000); ++ } ++ ++ /* 0x02000000 happens when you pause a ctxprog... ++ * but the only way this can happen that I know is by ++ * poking the relevant MMIO register, and we don't ++ * do that. */ ++ + if (status) { + NV_INFO(dev, "Unhandled PGRAPH_INTR - 0x%08x\n", + status); +@@ -672,7 +1185,8 @@ nv50_pgraph_irq_handler(struct drm_device *dev) + } + + nv_wr32(dev, NV03_PMC_INTR_0, NV_PMC_INTR_0_PGRAPH_PENDING); +- nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31)); ++ if (nv_rd32(dev, 0x400824) & (1 << 31)) ++ nv_wr32(dev, 0x400824, nv_rd32(dev, 0x400824) & ~(1 << 31)); + } + + static void +@@ -691,11 +1205,14 @@ nouveau_irq_handler(DRM_IRQ_ARGS) + struct drm_device *dev = (struct drm_device *)arg; + struct drm_nouveau_private *dev_priv = dev->dev_private; + uint32_t status, fbdev_flags = 0; ++ unsigned long flags; + + status = nv_rd32(dev, NV03_PMC_INTR_0); + if (!status) + return IRQ_NONE; + ++ spin_lock_irqsave(&dev_priv->context_switch_lock, flags); ++ + if (dev_priv->fbdev_info) { + fbdev_flags = dev_priv->fbdev_info->flags; + dev_priv->fbdev_info->flags |= FBINFO_HWACCEL_DISABLED; +@@ -733,5 +1250,7 @@ nouveau_irq_handler(DRM_IRQ_ARGS) + if (dev_priv->fbdev_info) + dev_priv->fbdev_info->flags = fbdev_flags; + ++ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); ++ + return IRQ_HANDLED; + } +diff --git a/drivers/gpu/drm/nouveau/nouveau_mem.c b/drivers/gpu/drm/nouveau/nouveau_mem.c +index 2dc09db..816948b 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_mem.c ++++ b/drivers/gpu/drm/nouveau/nouveau_mem.c +@@ -347,6 +347,20 @@ nv50_mem_vm_bind_linear(struct drm_device *dev, uint64_t virt, uint32_t size, + return -EBUSY; + } + ++ nv_wr32(dev, 0x100c80, 0x00040001); ++ if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { ++ NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); ++ NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80)); ++ return -EBUSY; ++ } ++ ++ nv_wr32(dev, 0x100c80, 0x00060001); ++ if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { ++ NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); ++ NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80)); ++ return -EBUSY; ++ } ++ + return 0; + } + +@@ -387,6 +401,20 @@ nv50_mem_vm_unbind(struct drm_device *dev, uint64_t virt, uint32_t size) + if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { + NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); + NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80)); ++ return; ++ } ++ ++ nv_wr32(dev, 0x100c80, 0x00040001); ++ if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { ++ NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); ++ NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80)); ++ return; ++ } ++ ++ nv_wr32(dev, 0x100c80, 0x00060001); ++ if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { ++ NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); ++ NV_ERROR(dev, "0x100c80 = 0x%08x\n", nv_rd32(dev, 0x100c80)); + } + } + +@@ -449,9 +477,30 @@ void nouveau_mem_close(struct drm_device *dev) + } + } + +-/*XXX won't work on BSD because of pci_read_config_dword */ + static uint32_t +-nouveau_mem_fb_amount_igp(struct drm_device *dev) ++nouveau_mem_detect_nv04(struct drm_device *dev) ++{ ++ uint32_t boot0 = nv_rd32(dev, NV03_BOOT_0); ++ ++ if (boot0 & 0x00000100) ++ return (((boot0 >> 12) & 0xf) * 2 + 2) * 1024 * 1024; ++ ++ switch (boot0 & NV03_BOOT_0_RAM_AMOUNT) { ++ case NV04_BOOT_0_RAM_AMOUNT_32MB: ++ return 32 * 1024 * 1024; ++ case NV04_BOOT_0_RAM_AMOUNT_16MB: ++ return 16 * 1024 * 1024; ++ case NV04_BOOT_0_RAM_AMOUNT_8MB: ++ return 8 * 1024 * 1024; ++ case NV04_BOOT_0_RAM_AMOUNT_4MB: ++ return 4 * 1024 * 1024; ++ } ++ ++ return 0; ++} ++ ++static uint32_t ++nouveau_mem_detect_nforce(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct pci_dev *bridge; +@@ -463,11 +512,11 @@ nouveau_mem_fb_amount_igp(struct drm_device *dev) + return 0; + } + +- if (dev_priv->flags&NV_NFORCE) { ++ if (dev_priv->flags & NV_NFORCE) { + pci_read_config_dword(bridge, 0x7C, &mem); + return (uint64_t)(((mem >> 6) & 31) + 1)*1024*1024; + } else +- if (dev_priv->flags&NV_NFORCE2) { ++ if (dev_priv->flags & NV_NFORCE2) { + pci_read_config_dword(bridge, 0x84, &mem); + return (uint64_t)(((mem >> 4) & 127) + 1)*1024*1024; + } +@@ -477,50 +526,39 @@ nouveau_mem_fb_amount_igp(struct drm_device *dev) + } + + /* returns the amount of FB ram in bytes */ +-uint64_t nouveau_mem_fb_amount(struct drm_device *dev) ++int ++nouveau_mem_detect(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- uint32_t boot0; +- +- switch (dev_priv->card_type) { +- case NV_04: +- boot0 = nv_rd32(dev, NV03_BOOT_0); +- if (boot0 & 0x00000100) +- return (((boot0 >> 12) & 0xf) * 2 + 2) * 1024 * 1024; +- +- switch (boot0 & NV03_BOOT_0_RAM_AMOUNT) { +- case NV04_BOOT_0_RAM_AMOUNT_32MB: +- return 32 * 1024 * 1024; +- case NV04_BOOT_0_RAM_AMOUNT_16MB: +- return 16 * 1024 * 1024; +- case NV04_BOOT_0_RAM_AMOUNT_8MB: +- return 8 * 1024 * 1024; +- case NV04_BOOT_0_RAM_AMOUNT_4MB: +- return 4 * 1024 * 1024; +- } +- break; +- case NV_10: +- case NV_20: +- case NV_30: +- case NV_40: +- case NV_50: +- default: +- if (dev_priv->flags & (NV_NFORCE | NV_NFORCE2)) { +- return nouveau_mem_fb_amount_igp(dev); +- } else { +- uint64_t mem; +- mem = (nv_rd32(dev, NV04_FIFO_DATA) & +- NV10_FIFO_DATA_RAM_AMOUNT_MB_MASK) >> +- NV10_FIFO_DATA_RAM_AMOUNT_MB_SHIFT; +- return mem * 1024 * 1024; ++ ++ if (dev_priv->card_type == NV_04) { ++ dev_priv->vram_size = nouveau_mem_detect_nv04(dev); ++ } else ++ if (dev_priv->flags & (NV_NFORCE | NV_NFORCE2)) { ++ dev_priv->vram_size = nouveau_mem_detect_nforce(dev); ++ } else ++ if (dev_priv->card_type < NV_50) { ++ dev_priv->vram_size = nv_rd32(dev, NV04_FIFO_DATA); ++ dev_priv->vram_size &= NV10_FIFO_DATA_RAM_AMOUNT_MB_MASK; ++ } else { ++ dev_priv->vram_size = nv_rd32(dev, NV04_FIFO_DATA); ++ dev_priv->vram_size |= (dev_priv->vram_size & 0xff) << 32; ++ dev_priv->vram_size &= 0xffffffff00; ++ if (dev_priv->chipset == 0xaa || dev_priv->chipset == 0xac) { ++ dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10); ++ dev_priv->vram_sys_base <<= 12; + } +- break; + } + +- NV_ERROR(dev, +- "Unable to detect video ram size. Please report your setup to " +- DRIVER_EMAIL "\n"); +- return 0; ++ NV_INFO(dev, "Detected %dMiB VRAM\n", (int)(dev_priv->vram_size >> 20)); ++ if (dev_priv->vram_sys_base) { ++ NV_INFO(dev, "Stolen system memory at: 0x%010llx\n", ++ dev_priv->vram_sys_base); ++ } ++ ++ if (dev_priv->vram_size) ++ return 0; ++ return -ENOMEM; + } + + #if __OS_HAS_AGP +@@ -631,15 +669,12 @@ nouveau_mem_init(struct drm_device *dev) + spin_lock_init(&dev_priv->ttm.bo_list_lock); + spin_lock_init(&dev_priv->tile.lock); + +- dev_priv->fb_available_size = nouveau_mem_fb_amount(dev); +- ++ dev_priv->fb_available_size = dev_priv->vram_size; + dev_priv->fb_mappable_pages = dev_priv->fb_available_size; + if (dev_priv->fb_mappable_pages > drm_get_resource_len(dev, 1)) + dev_priv->fb_mappable_pages = drm_get_resource_len(dev, 1); + dev_priv->fb_mappable_pages >>= PAGE_SHIFT; + +- NV_INFO(dev, "%d MiB VRAM\n", (int)(dev_priv->fb_available_size >> 20)); +- + /* remove reserved space at end of vram from available amount */ + dev_priv->fb_available_size -= dev_priv->ramin_rsvd_vram; + dev_priv->fb_aper_free = dev_priv->fb_available_size; +diff --git a/drivers/gpu/drm/nouveau/nouveau_reg.h b/drivers/gpu/drm/nouveau/nouveau_reg.h +index aa9b310..6ca80a3 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_reg.h ++++ b/drivers/gpu/drm/nouveau/nouveau_reg.h +@@ -826,6 +826,7 @@ + #define NV50_SOR_DP_CTRL_TRAINING_PATTERN_2 0x02000000 + #define NV50_SOR_DP_UNK118(i,l) (0x0061c118 + (i) * 0x800 + (l) * 0x80) + #define NV50_SOR_DP_UNK120(i,l) (0x0061c120 + (i) * 0x800 + (l) * 0x80) ++#define NV50_SOR_DP_UNK128(i,l) (0x0061c128 + (i) * 0x800 + (l) * 0x80) + #define NV50_SOR_DP_UNK130(i,l) (0x0061c130 + (i) * 0x800 + (l) * 0x80) + + #define NV50_PDISPLAY_USER(i) ((i) * 0x1000 + 0x00640000) +diff --git a/drivers/gpu/drm/nouveau/nouveau_sgdma.c b/drivers/gpu/drm/nouveau/nouveau_sgdma.c +index ed15905..554fb45 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_sgdma.c ++++ b/drivers/gpu/drm/nouveau/nouveau_sgdma.c +@@ -171,6 +171,24 @@ nouveau_sgdma_unbind(struct ttm_backend *be) + } + dev_priv->engine.instmem.finish_access(nvbe->dev); + ++ if (dev_priv->card_type == NV_50) { ++ nv_wr32(dev, 0x100c80, 0x00050001); ++ if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { ++ NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); ++ NV_ERROR(dev, "0x100c80 = 0x%08x\n", ++ nv_rd32(dev, 0x100c80)); ++ return -EBUSY; ++ } ++ ++ nv_wr32(dev, 0x100c80, 0x00000001); ++ if (!nv_wait(0x100c80, 0x00000001, 0x00000000)) { ++ NV_ERROR(dev, "timeout: (0x100c80 & 1) == 0 (2)\n"); ++ NV_ERROR(dev, "0x100c80 = 0x%08x\n", ++ nv_rd32(dev, 0x100c80)); ++ return -EBUSY; ++ } ++ } ++ + nvbe->bound = false; + return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nouveau_state.c b/drivers/gpu/drm/nouveau/nouveau_state.c +index a8d77c8..7c1d252 100644 +--- a/drivers/gpu/drm/nouveau/nouveau_state.c ++++ b/drivers/gpu/drm/nouveau/nouveau_state.c +@@ -34,7 +34,6 @@ + #include "nouveau_drm.h" + #include "nv50_display.h" + +-static int nouveau_stub_init(struct drm_device *dev) { return 0; } + static void nouveau_stub_takedown(struct drm_device *dev) {} + + static int nouveau_init_engine_ptrs(struct drm_device *dev) +@@ -276,8 +275,8 @@ static int nouveau_init_engine_ptrs(struct drm_device *dev) + engine->timer.init = nv04_timer_init; + engine->timer.read = nv04_timer_read; + engine->timer.takedown = nv04_timer_takedown; +- engine->fb.init = nouveau_stub_init; +- engine->fb.takedown = nouveau_stub_takedown; ++ engine->fb.init = nv50_fb_init; ++ engine->fb.takedown = nv50_fb_takedown; + engine->graph.grclass = nv50_graph_grclass; + engine->graph.init = nv50_graph_init; + engine->graph.takedown = nv50_graph_takedown; +@@ -340,7 +339,7 @@ nouveau_card_init_channel(struct drm_device *dev) + + gpuobj = NULL; + ret = nouveau_gpuobj_dma_new(dev_priv->channel, NV_CLASS_DMA_IN_MEMORY, +- 0, nouveau_mem_fb_amount(dev), ++ 0, dev_priv->vram_size, + NV_DMA_ACCESS_RW, NV_DMA_TARGET_VIDMEM, + &gpuobj); + if (ret) +@@ -391,6 +390,7 @@ nouveau_card_init(struct drm_device *dev) + goto out; + engine = &dev_priv->engine; + dev_priv->init_state = NOUVEAU_CARD_INIT_FAILED; ++ spin_lock_init(&dev_priv->context_switch_lock); + + /* Parse BIOS tables / Run init tables if card not POSTed */ + if (drm_core_check_feature(dev, DRIVER_MODESET)) { +@@ -399,6 +399,10 @@ nouveau_card_init(struct drm_device *dev) + goto out; + } + ++ ret = nouveau_mem_detect(dev); ++ if (ret) ++ goto out_bios; ++ + ret = nouveau_gpuobj_early_init(dev); + if (ret) + goto out_bios; +@@ -474,7 +478,7 @@ nouveau_card_init(struct drm_device *dev) + else + ret = nv04_display_create(dev); + if (ret) +- goto out_irq; ++ goto out_channel; + } + + ret = nouveau_backlight_init(dev); +@@ -488,6 +492,11 @@ nouveau_card_init(struct drm_device *dev) + + return 0; + ++out_channel: ++ if (dev_priv->channel) { ++ nouveau_channel_free(dev_priv->channel); ++ dev_priv->channel = NULL; ++ } + out_irq: + drm_irq_uninstall(dev); + out_fifo: +@@ -505,6 +514,7 @@ out_mc: + out_gpuobj: + nouveau_gpuobj_takedown(dev); + out_mem: ++ nouveau_sgdma_takedown(dev); + nouveau_mem_close(dev); + out_instmem: + engine->instmem.takedown(dev); +@@ -691,29 +701,24 @@ int nouveau_load(struct drm_device *dev, unsigned long flags) + NV_INFO(dev, "Detected an NV%2x generation card (0x%08x)\n", + dev_priv->card_type, reg0); + +- /* map larger RAMIN aperture on NV40 cards */ +- dev_priv->ramin = NULL; ++ /* Map PRAMIN BAR, or on older cards, the aperture withing BAR0 */ + if (dev_priv->card_type >= NV_40) { + int ramin_bar = 2; + if (pci_resource_len(dev->pdev, ramin_bar) == 0) + ramin_bar = 3; + + dev_priv->ramin_size = pci_resource_len(dev->pdev, ramin_bar); +- dev_priv->ramin = ioremap( +- pci_resource_start(dev->pdev, ramin_bar), ++ dev_priv->ramin = ++ ioremap(pci_resource_start(dev->pdev, ramin_bar), + dev_priv->ramin_size); + if (!dev_priv->ramin) { +- NV_ERROR(dev, "Failed to init RAMIN mapping, " +- "limited instance memory available\n"); ++ NV_ERROR(dev, "Failed to PRAMIN BAR"); ++ return -ENOMEM; + } +- } +- +- /* On older cards (or if the above failed), create a map covering +- * the BAR0 PRAMIN aperture */ +- if (!dev_priv->ramin) { ++ } else { + dev_priv->ramin_size = 1 * 1024 * 1024; + dev_priv->ramin = ioremap(mmio_start_offs + NV_RAMIN, +- dev_priv->ramin_size); ++ dev_priv->ramin_size); + if (!dev_priv->ramin) { + NV_ERROR(dev, "Failed to map BAR0 PRAMIN.\n"); + return -ENOMEM; +diff --git a/drivers/gpu/drm/nouveau/nv04_crtc.c b/drivers/gpu/drm/nouveau/nv04_crtc.c +index d2f143e..9986aba 100644 +--- a/drivers/gpu/drm/nouveau/nv04_crtc.c ++++ b/drivers/gpu/drm/nouveau/nv04_crtc.c +@@ -230,9 +230,9 @@ nv_crtc_mode_set_vga(struct drm_crtc *crtc, struct drm_display_mode *mode) + struct drm_framebuffer *fb = crtc->fb; + + /* Calculate our timings */ +- int horizDisplay = (mode->crtc_hdisplay >> 3) - 1; +- int horizStart = (mode->crtc_hsync_start >> 3) - 1; +- int horizEnd = (mode->crtc_hsync_end >> 3) - 1; ++ int horizDisplay = (mode->crtc_hdisplay >> 3) - 1; ++ int horizStart = (mode->crtc_hsync_start >> 3) + 1; ++ int horizEnd = (mode->crtc_hsync_end >> 3) + 1; + int horizTotal = (mode->crtc_htotal >> 3) - 5; + int horizBlankStart = (mode->crtc_hdisplay >> 3) - 1; + int horizBlankEnd = (mode->crtc_htotal >> 3) - 1; +diff --git a/drivers/gpu/drm/nouveau/nv04_dac.c b/drivers/gpu/drm/nouveau/nv04_dac.c +index 1d73b15..8066c56 100644 +--- a/drivers/gpu/drm/nouveau/nv04_dac.c ++++ b/drivers/gpu/drm/nouveau/nv04_dac.c +@@ -230,13 +230,13 @@ uint32_t nv17_dac_sample_load(struct drm_encoder *encoder) + if (dcb->type == OUTPUT_TV) { + testval = RGB_TEST_DATA(0xa0, 0xa0, 0xa0); + +- if (dev_priv->vbios->tvdactestval) +- testval = dev_priv->vbios->tvdactestval; ++ if (dev_priv->vbios.tvdactestval) ++ testval = dev_priv->vbios.tvdactestval; + } else { + testval = RGB_TEST_DATA(0x140, 0x140, 0x140); /* 0x94050140 */ + +- if (dev_priv->vbios->dactestval) +- testval = dev_priv->vbios->dactestval; ++ if (dev_priv->vbios.dactestval) ++ testval = dev_priv->vbios.dactestval; + } + + saved_rtest_ctrl = NVReadRAMDAC(dev, 0, NV_PRAMDAC_TEST_CONTROL + regoffset); +@@ -501,11 +501,13 @@ static const struct drm_encoder_funcs nv04_dac_funcs = { + .destroy = nv04_dac_destroy, + }; + +-int nv04_dac_create(struct drm_device *dev, struct dcb_entry *entry) ++int ++nv04_dac_create(struct drm_connector *connector, struct dcb_entry *entry) + { + const struct drm_encoder_helper_funcs *helper; +- struct drm_encoder *encoder; + struct nouveau_encoder *nv_encoder = NULL; ++ struct drm_device *dev = connector->dev; ++ struct drm_encoder *encoder; + + nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); + if (!nv_encoder) +@@ -527,5 +529,6 @@ int nv04_dac_create(struct drm_device *dev, struct dcb_entry *entry) + encoder->possible_crtcs = entry->heads; + encoder->possible_clones = 0; + ++ drm_mode_connector_attach_encoder(connector, encoder); + return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nv04_dfp.c b/drivers/gpu/drm/nouveau/nv04_dfp.c +index 483f875..3559d89 100644 +--- a/drivers/gpu/drm/nouveau/nv04_dfp.c ++++ b/drivers/gpu/drm/nouveau/nv04_dfp.c +@@ -269,10 +269,10 @@ static void nv04_dfp_mode_set(struct drm_encoder *encoder, + regp->fp_horiz_regs[FP_TOTAL] = output_mode->htotal - 1; + if (!nv_gf4_disp_arch(dev) || + (output_mode->hsync_start - output_mode->hdisplay) >= +- dev_priv->vbios->digital_min_front_porch) ++ dev_priv->vbios.digital_min_front_porch) + regp->fp_horiz_regs[FP_CRTC] = output_mode->hdisplay; + else +- regp->fp_horiz_regs[FP_CRTC] = output_mode->hsync_start - dev_priv->vbios->digital_min_front_porch - 1; ++ regp->fp_horiz_regs[FP_CRTC] = output_mode->hsync_start - dev_priv->vbios.digital_min_front_porch - 1; + regp->fp_horiz_regs[FP_SYNC_START] = output_mode->hsync_start - 1; + regp->fp_horiz_regs[FP_SYNC_END] = output_mode->hsync_end - 1; + regp->fp_horiz_regs[FP_VALID_START] = output_mode->hskew; +@@ -584,11 +584,12 @@ static const struct drm_encoder_funcs nv04_dfp_funcs = { + .destroy = nv04_dfp_destroy, + }; + +-int nv04_dfp_create(struct drm_device *dev, struct dcb_entry *entry) ++int ++nv04_dfp_create(struct drm_connector *connector, struct dcb_entry *entry) + { + const struct drm_encoder_helper_funcs *helper; +- struct drm_encoder *encoder; + struct nouveau_encoder *nv_encoder = NULL; ++ struct drm_encoder *encoder; + int type; + + switch (entry->type) { +@@ -613,11 +614,12 @@ int nv04_dfp_create(struct drm_device *dev, struct dcb_entry *entry) + nv_encoder->dcb = entry; + nv_encoder->or = ffs(entry->or) - 1; + +- drm_encoder_init(dev, encoder, &nv04_dfp_funcs, type); ++ drm_encoder_init(connector->dev, encoder, &nv04_dfp_funcs, type); + drm_encoder_helper_add(encoder, helper); + + encoder->possible_crtcs = entry->heads; + encoder->possible_clones = 0; + ++ drm_mode_connector_attach_encoder(connector, encoder); + return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nv04_display.c b/drivers/gpu/drm/nouveau/nv04_display.c +index ef77215..b35b7ed 100644 +--- a/drivers/gpu/drm/nouveau/nv04_display.c ++++ b/drivers/gpu/drm/nouveau/nv04_display.c +@@ -93,10 +93,10 @@ int + nv04_display_create(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct parsed_dcb *dcb = dev_priv->vbios->dcb; ++ struct dcb_table *dcb = &dev_priv->vbios.dcb; ++ struct drm_connector *connector, *ct; + struct drm_encoder *encoder; + struct drm_crtc *crtc; +- uint16_t connector[16] = { 0 }; + int i, ret; + + NV_DEBUG_KMS(dev, "\n"); +@@ -133,19 +133,23 @@ nv04_display_create(struct drm_device *dev) + for (i = 0; i < dcb->entries; i++) { + struct dcb_entry *dcbent = &dcb->entry[i]; + ++ connector = nouveau_connector_create(dev, dcbent->connector); ++ if (IS_ERR(connector)) ++ continue; ++ + switch (dcbent->type) { + case OUTPUT_ANALOG: +- ret = nv04_dac_create(dev, dcbent); ++ ret = nv04_dac_create(connector, dcbent); + break; + case OUTPUT_LVDS: + case OUTPUT_TMDS: +- ret = nv04_dfp_create(dev, dcbent); ++ ret = nv04_dfp_create(connector, dcbent); + break; + case OUTPUT_TV: + if (dcbent->location == DCB_LOC_ON_CHIP) +- ret = nv17_tv_create(dev, dcbent); ++ ret = nv17_tv_create(connector, dcbent); + else +- ret = nv04_tv_create(dev, dcbent); ++ ret = nv04_tv_create(connector, dcbent); + break; + default: + NV_WARN(dev, "DCB type %d not known\n", dcbent->type); +@@ -154,51 +158,15 @@ nv04_display_create(struct drm_device *dev) + + if (ret) + continue; +- +- connector[dcbent->connector] |= (1 << dcbent->type); + } + +- for (i = 0; i < dcb->entries; i++) { +- struct dcb_entry *dcbent = &dcb->entry[i]; +- uint16_t encoders; +- int type; +- +- encoders = connector[dcbent->connector]; +- if (!(encoders & (1 << dcbent->type))) +- continue; +- connector[dcbent->connector] = 0; +- +- switch (dcbent->type) { +- case OUTPUT_ANALOG: +- if (!MULTIPLE_ENCODERS(encoders)) +- type = DRM_MODE_CONNECTOR_VGA; +- else +- type = DRM_MODE_CONNECTOR_DVII; +- break; +- case OUTPUT_TMDS: +- if (!MULTIPLE_ENCODERS(encoders)) +- type = DRM_MODE_CONNECTOR_DVID; +- else +- type = DRM_MODE_CONNECTOR_DVII; +- break; +- case OUTPUT_LVDS: +- type = DRM_MODE_CONNECTOR_LVDS; +-#if 0 +- /* don't create i2c adapter when lvds ddc not allowed */ +- if (dcbent->lvdsconf.use_straps_for_mode || +- dev_priv->vbios->fp_no_ddc) +- i2c_index = 0xf; +-#endif +- break; +- case OUTPUT_TV: +- type = DRM_MODE_CONNECTOR_TV; +- break; +- default: +- type = DRM_MODE_CONNECTOR_Unknown; +- continue; ++ list_for_each_entry_safe(connector, ct, ++ &dev->mode_config.connector_list, head) { ++ if (!connector->encoder_ids[0]) { ++ NV_WARN(dev, "%s has no encoders, removing\n", ++ drm_get_connector_name(connector)); ++ connector->funcs->destroy(connector); + } +- +- nouveau_connector_create(dev, dcbent->connector, type); + } + + /* Save previous state */ +diff --git a/drivers/gpu/drm/nouveau/nv04_fbcon.c b/drivers/gpu/drm/nouveau/nv04_fbcon.c +index fd01caa..813b25c 100644 +--- a/drivers/gpu/drm/nouveau/nv04_fbcon.c ++++ b/drivers/gpu/drm/nouveau/nv04_fbcon.c +@@ -118,8 +118,8 @@ nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image) + return; + } + +- width = (image->width + 31) & ~31; +- dsize = (width * image->height) >> 5; ++ width = ALIGN(image->width, 8); ++ dsize = ALIGN(width * image->height, 32) >> 5; + + if (info->fix.visual == FB_VISUAL_TRUECOLOR || + info->fix.visual == FB_VISUAL_DIRECTCOLOR) { +@@ -136,8 +136,8 @@ nv04_fbcon_imageblit(struct fb_info *info, const struct fb_image *image) + ((image->dx + image->width) & 0xffff)); + OUT_RING(chan, bg); + OUT_RING(chan, fg); +- OUT_RING(chan, (image->height << 16) | image->width); + OUT_RING(chan, (image->height << 16) | width); ++ OUT_RING(chan, (image->height << 16) | image->width); + OUT_RING(chan, (image->dy << 16) | (image->dx & 0xffff)); + + while (dsize) { +diff --git a/drivers/gpu/drm/nouveau/nv04_fifo.c b/drivers/gpu/drm/nouveau/nv04_fifo.c +index f31347b..66fe559 100644 +--- a/drivers/gpu/drm/nouveau/nv04_fifo.c ++++ b/drivers/gpu/drm/nouveau/nv04_fifo.c +@@ -117,6 +117,7 @@ nv04_fifo_create_context(struct nouveau_channel *chan) + { + struct drm_device *dev = chan->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; ++ unsigned long flags; + int ret; + + ret = nouveau_gpuobj_new_fake(dev, NV04_RAMFC(chan->id), ~0, +@@ -127,6 +128,8 @@ nv04_fifo_create_context(struct nouveau_channel *chan) + if (ret) + return ret; + ++ spin_lock_irqsave(&dev_priv->context_switch_lock, flags); ++ + /* Setup initial state */ + dev_priv->engine.instmem.prepare_access(dev, true); + RAMFC_WR(DMA_PUT, chan->pushbuf_base); +@@ -144,6 +147,8 @@ nv04_fifo_create_context(struct nouveau_channel *chan) + /* enable the fifo dma operation */ + nv_wr32(dev, NV04_PFIFO_MODE, + nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id)); ++ ++ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nv04_graph.c b/drivers/gpu/drm/nouveau/nv04_graph.c +index e260986..f0cbbc0 100644 +--- a/drivers/gpu/drm/nouveau/nv04_graph.c ++++ b/drivers/gpu/drm/nouveau/nv04_graph.c +@@ -527,8 +527,7 @@ static int + nv04_graph_mthd_set_ref(struct nouveau_channel *chan, int grclass, + int mthd, uint32_t data) + { +- chan->fence.last_sequence_irq = data; +- nouveau_fence_handler(chan->dev, chan->id); ++ atomic_set(&chan->fence.last_sequence_irq, data); + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nv04_tv.c b/drivers/gpu/drm/nouveau/nv04_tv.c +index 9c63099..84b5954 100644 +--- a/drivers/gpu/drm/nouveau/nv04_tv.c ++++ b/drivers/gpu/drm/nouveau/nv04_tv.c +@@ -223,10 +223,12 @@ static void nv04_tv_destroy(struct drm_encoder *encoder) + kfree(nv_encoder); + } + +-int nv04_tv_create(struct drm_device *dev, struct dcb_entry *entry) ++int ++nv04_tv_create(struct drm_connector *connector, struct dcb_entry *entry) + { + struct nouveau_encoder *nv_encoder; + struct drm_encoder *encoder; ++ struct drm_device *dev = connector->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct i2c_adapter *adap; + struct drm_encoder_funcs *funcs = NULL; +@@ -262,11 +264,11 @@ int nv04_tv_create(struct drm_device *dev, struct dcb_entry *entry) + nv_encoder->or = ffs(entry->or) - 1; + + /* Run the slave-specific initialization */ +- adap = &dev_priv->vbios->dcb->i2c[i2c_index].chan->adapter; ++ adap = &dev_priv->vbios.dcb.i2c[i2c_index].chan->adapter; + + was_locked = NVLockVgaCrtcs(dev, false); + +- ret = drm_i2c_encoder_init(encoder->dev, to_encoder_slave(encoder), adap, ++ ret = drm_i2c_encoder_init(dev, to_encoder_slave(encoder), adap, + &nv04_tv_encoder_info[type].board_info); + + NVLockVgaCrtcs(dev, was_locked); +@@ -294,7 +296,9 @@ int nv04_tv_create(struct drm_device *dev, struct dcb_entry *entry) + + /* Set the slave encoder configuration */ + sfuncs->set_config(encoder, nv04_tv_encoder_info[type].params); ++ sfuncs->create_resources(encoder, connector); + ++ drm_mode_connector_attach_encoder(connector, encoder); + return 0; + + fail: +diff --git a/drivers/gpu/drm/nouveau/nv17_tv.c b/drivers/gpu/drm/nouveau/nv17_tv.c +index 21ac6e4..44437ff 100644 +--- a/drivers/gpu/drm/nouveau/nv17_tv.c ++++ b/drivers/gpu/drm/nouveau/nv17_tv.c +@@ -45,8 +45,8 @@ static uint32_t nv42_tv_sample_load(struct drm_encoder *encoder) + + #define RGB_TEST_DATA(r, g, b) (r << 0 | g << 10 | b << 20) + testval = RGB_TEST_DATA(0x82, 0xeb, 0x82); +- if (dev_priv->vbios->tvdactestval) +- testval = dev_priv->vbios->tvdactestval; ++ if (dev_priv->vbios.tvdactestval) ++ testval = dev_priv->vbios.tvdactestval; + + dacclk = NVReadRAMDAC(dev, 0, NV_PRAMDAC_DACCLK + regoffset); + head = (dacclk & 0x100) >> 8; +@@ -367,7 +367,7 @@ static void nv17_tv_prepare(struct drm_encoder *encoder) + !enc->crtc && + nv04_dfp_get_bound_head(dev, dcb) == head) { + nv04_dfp_bind_head(dev, dcb, head ^ 1, +- dev_priv->VBIOS.fp.dual_link); ++ dev_priv->vbios.fp.dual_link); + } + } + +@@ -744,8 +744,10 @@ static struct drm_encoder_funcs nv17_tv_funcs = { + .destroy = nv17_tv_destroy, + }; + +-int nv17_tv_create(struct drm_device *dev, struct dcb_entry *entry) ++int ++nv17_tv_create(struct drm_connector *connector, struct dcb_entry *entry) + { ++ struct drm_device *dev = connector->dev; + struct drm_encoder *encoder; + struct nv17_tv_encoder *tv_enc = NULL; + +@@ -774,5 +776,7 @@ int nv17_tv_create(struct drm_device *dev, struct dcb_entry *entry) + encoder->possible_crtcs = entry->heads; + encoder->possible_clones = 0; + ++ nv17_tv_create_resources(encoder, connector); ++ drm_mode_connector_attach_encoder(connector, encoder); + return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nv40_fifo.c b/drivers/gpu/drm/nouveau/nv40_fifo.c +index b4f19cc..500ccfd 100644 +--- a/drivers/gpu/drm/nouveau/nv40_fifo.c ++++ b/drivers/gpu/drm/nouveau/nv40_fifo.c +@@ -37,6 +37,7 @@ nv40_fifo_create_context(struct nouveau_channel *chan) + struct drm_device *dev = chan->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + uint32_t fc = NV40_RAMFC(chan->id); ++ unsigned long flags; + int ret; + + ret = nouveau_gpuobj_new_fake(dev, NV40_RAMFC(chan->id), ~0, +@@ -45,6 +46,8 @@ nv40_fifo_create_context(struct nouveau_channel *chan) + if (ret) + return ret; + ++ spin_lock_irqsave(&dev_priv->context_switch_lock, flags); ++ + dev_priv->engine.instmem.prepare_access(dev, true); + nv_wi32(dev, fc + 0, chan->pushbuf_base); + nv_wi32(dev, fc + 4, chan->pushbuf_base); +@@ -63,6 +66,8 @@ nv40_fifo_create_context(struct nouveau_channel *chan) + /* enable the fifo dma operation */ + nv_wr32(dev, NV04_PFIFO_MODE, + nv_rd32(dev, NV04_PFIFO_MODE) | (1 << chan->id)); ++ ++ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); + return 0; + } + +@@ -273,7 +278,7 @@ nv40_fifo_init_ramxx(struct drm_device *dev) + default: + nv_wr32(dev, 0x2230, 0); + nv_wr32(dev, NV40_PFIFO_RAMFC, +- ((nouveau_mem_fb_amount(dev) - 512 * 1024 + ++ ((dev_priv->vram_size - 512 * 1024 + + dev_priv->ramfc_offset) >> 16) | (3 << 16)); + break; + } +diff --git a/drivers/gpu/drm/nouveau/nv40_graph.c b/drivers/gpu/drm/nouveau/nv40_graph.c +index 53e8afe..0616c96 100644 +--- a/drivers/gpu/drm/nouveau/nv40_graph.c ++++ b/drivers/gpu/drm/nouveau/nv40_graph.c +@@ -335,6 +335,27 @@ nv40_graph_init(struct drm_device *dev) + nv_wr32(dev, 0x400b38, 0x2ffff800); + nv_wr32(dev, 0x400b3c, 0x00006000); + ++ /* Tiling related stuff. */ ++ switch (dev_priv->chipset) { ++ case 0x44: ++ case 0x4a: ++ nv_wr32(dev, 0x400bc4, 0x1003d888); ++ nv_wr32(dev, 0x400bbc, 0xb7a7b500); ++ break; ++ case 0x46: ++ nv_wr32(dev, 0x400bc4, 0x0000e024); ++ nv_wr32(dev, 0x400bbc, 0xb7a7b520); ++ break; ++ case 0x4c: ++ case 0x4e: ++ case 0x67: ++ nv_wr32(dev, 0x400bc4, 0x1003d888); ++ nv_wr32(dev, 0x400bbc, 0xb7a7b540); ++ break; ++ default: ++ break; ++ } ++ + /* Turn all the tiling regions off. */ + for (i = 0; i < pfb->num_tiles; i++) + nv40_graph_set_region_tiling(dev, i, 0, 0, 0); +diff --git a/drivers/gpu/drm/nouveau/nv50_calc.c b/drivers/gpu/drm/nouveau/nv50_calc.c +new file mode 100644 +index 0000000..2cdc2bf +--- /dev/null ++++ b/drivers/gpu/drm/nouveau/nv50_calc.c +@@ -0,0 +1,87 @@ ++/* ++ * Copyright 2010 Red Hat Inc. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR ++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ++ * OTHER DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Ben Skeggs ++ */ ++ ++#include "drmP.h" ++#include "drm_fixed.h" ++#include "nouveau_drv.h" ++#include "nouveau_hw.h" ++ ++int ++nv50_calc_pll(struct drm_device *dev, struct pll_lims *pll, int clk, ++ int *N1, int *M1, int *N2, int *M2, int *P) ++{ ++ struct nouveau_pll_vals pll_vals; ++ int ret; ++ ++ ret = nouveau_calc_pll_mnp(dev, pll, clk, &pll_vals); ++ if (ret <= 0) ++ return ret; ++ ++ *N1 = pll_vals.N1; ++ *M1 = pll_vals.M1; ++ *N2 = pll_vals.N2; ++ *M2 = pll_vals.M2; ++ *P = pll_vals.log2P; ++ return ret; ++} ++ ++int ++nv50_calc_pll2(struct drm_device *dev, struct pll_lims *pll, int clk, ++ int *N, int *fN, int *M, int *P) ++{ ++ fixed20_12 fb_div, a, b; ++ ++ *P = pll->vco1.maxfreq / clk; ++ if (*P > pll->max_p) ++ *P = pll->max_p; ++ if (*P < pll->min_p) ++ *P = pll->min_p; ++ ++ /* *M = ceil(refclk / pll->vco.max_inputfreq); */ ++ a.full = dfixed_const(pll->refclk); ++ b.full = dfixed_const(pll->vco1.max_inputfreq); ++ a.full = dfixed_div(a, b); ++ a.full = dfixed_ceil(a); ++ *M = dfixed_trunc(a); ++ ++ /* fb_div = (vco * *M) / refclk; */ ++ fb_div.full = dfixed_const(clk * *P); ++ fb_div.full = dfixed_mul(fb_div, a); ++ a.full = dfixed_const(pll->refclk); ++ fb_div.full = dfixed_div(fb_div, a); ++ ++ /* *N = floor(fb_div); */ ++ a.full = dfixed_floor(fb_div); ++ *N = dfixed_trunc(fb_div); ++ ++ /* *fN = (fmod(fb_div, 1.0) * 8192) - 4096; */ ++ b.full = dfixed_const(8192); ++ a.full = dfixed_mul(a, b); ++ fb_div.full = dfixed_mul(fb_div, b); ++ fb_div.full = fb_div.full - a.full; ++ *fN = dfixed_trunc(fb_div) - 4096; ++ *fN &= 0xffff; ++ ++ return clk; ++} +diff --git a/drivers/gpu/drm/nouveau/nv50_crtc.c b/drivers/gpu/drm/nouveau/nv50_crtc.c +index d1a651e..03d0e41 100644 +--- a/drivers/gpu/drm/nouveau/nv50_crtc.c ++++ b/drivers/gpu/drm/nouveau/nv50_crtc.c +@@ -264,32 +264,40 @@ nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, int scaling_mode, bool update) + int + nv50_crtc_set_clock(struct drm_device *dev, int head, int pclk) + { +- uint32_t pll_reg = NV50_PDISPLAY_CRTC_CLK_CTRL1(head); +- struct nouveau_pll_vals pll; +- struct pll_lims limits; ++ uint32_t reg = NV50_PDISPLAY_CRTC_CLK_CTRL1(head); ++ struct pll_lims pll; + uint32_t reg1, reg2; +- int ret; ++ int ret, N1, M1, N2, M2, P; + +- ret = get_pll_limits(dev, pll_reg, &limits); ++ ret = get_pll_limits(dev, reg, &pll); + if (ret) + return ret; + +- ret = nouveau_calc_pll_mnp(dev, &limits, pclk, &pll); +- if (ret <= 0) +- return ret; ++ if (pll.vco2.maxfreq) { ++ ret = nv50_calc_pll(dev, &pll, pclk, &N1, &M1, &N2, &M2, &P); ++ if (ret <= 0) ++ return 0; ++ ++ NV_DEBUG(dev, "pclk %d out %d NM1 %d %d NM2 %d %d P %d\n", ++ pclk, ret, N1, M1, N2, M2, P); + +- if (limits.vco2.maxfreq) { +- reg1 = nv_rd32(dev, pll_reg + 4) & 0xff00ff00; +- reg2 = nv_rd32(dev, pll_reg + 8) & 0x8000ff00; +- nv_wr32(dev, pll_reg, 0x10000611); +- nv_wr32(dev, pll_reg + 4, reg1 | (pll.M1 << 16) | pll.N1); +- nv_wr32(dev, pll_reg + 8, +- reg2 | (pll.log2P << 28) | (pll.M2 << 16) | pll.N2); ++ reg1 = nv_rd32(dev, reg + 4) & 0xff00ff00; ++ reg2 = nv_rd32(dev, reg + 8) & 0x8000ff00; ++ nv_wr32(dev, reg, 0x10000611); ++ nv_wr32(dev, reg + 4, reg1 | (M1 << 16) | N1); ++ nv_wr32(dev, reg + 8, reg2 | (P << 28) | (M2 << 16) | N2); + } else { +- reg1 = nv_rd32(dev, pll_reg + 4) & 0xffc00000; +- nv_wr32(dev, pll_reg, 0x50000610); +- nv_wr32(dev, pll_reg + 4, reg1 | +- (pll.log2P << 16) | (pll.M1 << 8) | pll.N1); ++ ret = nv50_calc_pll2(dev, &pll, pclk, &N1, &N2, &M1, &P); ++ if (ret <= 0) ++ return 0; ++ ++ NV_DEBUG(dev, "pclk %d out %d N %d fN 0x%04x M %d P %d\n", ++ pclk, ret, N1, N2, M1, P); ++ ++ reg1 = nv_rd32(dev, reg + 4) & 0xffc00000; ++ nv_wr32(dev, reg, 0x50000610); ++ nv_wr32(dev, reg + 4, reg1 | (P << 16) | (M1 << 8) | N1); ++ nv_wr32(dev, reg + 8, N2); + } + + return 0; +diff --git a/drivers/gpu/drm/nouveau/nv50_dac.c b/drivers/gpu/drm/nouveau/nv50_dac.c +index f08f042..e114f81 100644 +--- a/drivers/gpu/drm/nouveau/nv50_dac.c ++++ b/drivers/gpu/drm/nouveau/nv50_dac.c +@@ -79,8 +79,8 @@ nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) + } + + /* Use bios provided value if possible. */ +- if (dev_priv->vbios->dactestval) { +- load_pattern = dev_priv->vbios->dactestval; ++ if (dev_priv->vbios.dactestval) { ++ load_pattern = dev_priv->vbios.dactestval; + NV_DEBUG_KMS(dev, "Using bios provided load_pattern of %d\n", + load_pattern); + } else { +@@ -275,14 +275,11 @@ static const struct drm_encoder_funcs nv50_dac_encoder_funcs = { + }; + + int +-nv50_dac_create(struct drm_device *dev, struct dcb_entry *entry) ++nv50_dac_create(struct drm_connector *connector, struct dcb_entry *entry) + { + struct nouveau_encoder *nv_encoder; + struct drm_encoder *encoder; + +- NV_DEBUG_KMS(dev, "\n"); +- NV_INFO(dev, "Detected a DAC output\n"); +- + nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); + if (!nv_encoder) + return -ENOMEM; +@@ -293,12 +290,14 @@ nv50_dac_create(struct drm_device *dev, struct dcb_entry *entry) + + nv_encoder->disconnect = nv50_dac_disconnect; + +- drm_encoder_init(dev, encoder, &nv50_dac_encoder_funcs, ++ drm_encoder_init(connector->dev, encoder, &nv50_dac_encoder_funcs, + DRM_MODE_ENCODER_DAC); + drm_encoder_helper_add(encoder, &nv50_dac_helper_funcs); + + encoder->possible_crtcs = entry->heads; + encoder->possible_clones = 0; ++ ++ drm_mode_connector_attach_encoder(connector, encoder); + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nv50_display.c b/drivers/gpu/drm/nouveau/nv50_display.c +index 90f0bf5..a0d7467 100644 +--- a/drivers/gpu/drm/nouveau/nv50_display.c ++++ b/drivers/gpu/drm/nouveau/nv50_display.c +@@ -143,7 +143,7 @@ nv50_evo_channel_new(struct drm_device *dev, struct nouveau_channel **pchan) + } + + ret = nv50_evo_dmaobj_new(chan, 0x3d, NvEvoVRAM, 0, 0x19, +- 0, nouveau_mem_fb_amount(dev)); ++ 0, dev_priv->vram_size); + if (ret) { + nv50_evo_channel_del(pchan); + return ret; +@@ -231,7 +231,7 @@ nv50_display_init(struct drm_device *dev) + /* This used to be in crtc unblank, but seems out of place there. */ + nv_wr32(dev, NV50_PDISPLAY_UNK_380, 0); + /* RAM is clamped to 256 MiB. */ +- ram_amount = nouveau_mem_fb_amount(dev); ++ ram_amount = dev_priv->vram_size; + NV_DEBUG_KMS(dev, "ram_amount %d\n", ram_amount); + if (ram_amount > 256*1024*1024) + ram_amount = 256*1024*1024; +@@ -370,9 +370,7 @@ nv50_display_init(struct drm_device *dev) + struct nouveau_connector *conn = nouveau_connector(connector); + struct dcb_gpio_entry *gpio; + +- if (connector->connector_type != DRM_MODE_CONNECTOR_DVII && +- connector->connector_type != DRM_MODE_CONNECTOR_DVID && +- connector->connector_type != DRM_MODE_CONNECTOR_DisplayPort) ++ if (conn->dcb->gpio_tag == 0xff) + continue; + + gpio = nouveau_bios_gpio_entry(dev, conn->dcb->gpio_tag); +@@ -465,8 +463,8 @@ static int nv50_display_disable(struct drm_device *dev) + int nv50_display_create(struct drm_device *dev) + { + struct drm_nouveau_private *dev_priv = dev->dev_private; +- struct parsed_dcb *dcb = dev_priv->vbios->dcb; +- uint32_t connector[16] = {}; ++ struct dcb_table *dcb = &dev_priv->vbios.dcb; ++ struct drm_connector *connector, *ct; + int ret, i; + + NV_DEBUG_KMS(dev, "\n"); +@@ -509,62 +507,39 @@ int nv50_display_create(struct drm_device *dev) + continue; + } + ++ connector = nouveau_connector_create(dev, entry->connector); ++ if (IS_ERR(connector)) ++ continue; ++ + switch (entry->type) { + case OUTPUT_TMDS: + case OUTPUT_LVDS: + case OUTPUT_DP: +- nv50_sor_create(dev, entry); ++ nv50_sor_create(connector, entry); + break; + case OUTPUT_ANALOG: +- nv50_dac_create(dev, entry); ++ nv50_dac_create(connector, entry); + break; + default: + NV_WARN(dev, "DCB encoder %d unknown\n", entry->type); + continue; + } +- +- connector[entry->connector] |= (1 << entry->type); + } + +- /* It appears that DCB 3.0+ VBIOS has a connector table, however, +- * I'm not 100% certain how to decode it correctly yet so just +- * look at what encoders are present on each connector index and +- * attempt to derive the connector type from that. +- */ +- for (i = 0 ; i < dcb->entries; i++) { +- struct dcb_entry *entry = &dcb->entry[i]; +- uint16_t encoders; +- int type; +- +- encoders = connector[entry->connector]; +- if (!(encoders & (1 << entry->type))) +- continue; +- connector[entry->connector] = 0; +- +- if (encoders & (1 << OUTPUT_DP)) { +- type = DRM_MODE_CONNECTOR_DisplayPort; +- } else if (encoders & (1 << OUTPUT_TMDS)) { +- if (encoders & (1 << OUTPUT_ANALOG)) +- type = DRM_MODE_CONNECTOR_DVII; +- else +- type = DRM_MODE_CONNECTOR_DVID; +- } else if (encoders & (1 << OUTPUT_ANALOG)) { +- type = DRM_MODE_CONNECTOR_VGA; +- } else if (encoders & (1 << OUTPUT_LVDS)) { +- type = DRM_MODE_CONNECTOR_LVDS; +- } else { +- type = DRM_MODE_CONNECTOR_Unknown; ++ list_for_each_entry_safe(connector, ct, ++ &dev->mode_config.connector_list, head) { ++ if (!connector->encoder_ids[0]) { ++ NV_WARN(dev, "%s has no encoders, removing\n", ++ drm_get_connector_name(connector)); ++ connector->funcs->destroy(connector); + } +- +- if (type == DRM_MODE_CONNECTOR_Unknown) +- continue; +- +- nouveau_connector_create(dev, entry->connector, type); + } + + ret = nv50_display_init(dev); +- if (ret) ++ if (ret) { ++ nv50_display_destroy(dev); + return ret; ++ } + + return 0; + } +@@ -667,8 +642,8 @@ nv50_display_irq_head(struct drm_device *dev, int *phead, + return -1; + } + +- for (i = 0; i < dev_priv->vbios->dcb->entries; i++) { +- struct dcb_entry *dcbent = &dev_priv->vbios->dcb->entry[i]; ++ for (i = 0; i < dev_priv->vbios.dcb.entries; i++) { ++ struct dcb_entry *dcbent = &dev_priv->vbios.dcb.entry[i]; + + if (dcbent->type != type) + continue; +@@ -692,7 +667,7 @@ nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcbent, + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_connector *nv_connector = NULL; + struct drm_encoder *encoder; +- struct nvbios *bios = &dev_priv->VBIOS; ++ struct nvbios *bios = &dev_priv->vbios; + uint32_t mc, script = 0, or; + + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { +@@ -710,7 +685,7 @@ nv50_display_script_select(struct drm_device *dev, struct dcb_entry *dcbent, + switch (dcbent->type) { + case OUTPUT_LVDS: + script = (mc >> 8) & 0xf; +- if (bios->pub.fp_no_ddc) { ++ if (bios->fp_no_ddc) { + if (bios->fp.dual_link) + script |= 0x0100; + if (bios->fp.if_is_24bit) +@@ -815,6 +790,37 @@ ack: + } + + static void ++nv50_display_unk20_dp_hack(struct drm_device *dev, struct dcb_entry *dcb) ++{ ++ int or = ffs(dcb->or) - 1, link = !(dcb->dpconf.sor.link & 1); ++ struct drm_encoder *encoder; ++ uint32_t tmp, unk0 = 0, unk1 = 0; ++ ++ if (dcb->type != OUTPUT_DP) ++ return; ++ ++ list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { ++ struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); ++ ++ if (nv_encoder->dcb == dcb) { ++ unk0 = nv_encoder->dp.unk0; ++ unk1 = nv_encoder->dp.unk1; ++ break; ++ } ++ } ++ ++ if (unk0 || unk1) { ++ tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); ++ tmp &= 0xfffffe03; ++ nv_wr32(dev, NV50_SOR_DP_CTRL(or, link), tmp | unk0); ++ ++ tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link)); ++ tmp &= 0xfef080c0; ++ nv_wr32(dev, NV50_SOR_DP_UNK128(or, link), tmp | unk1); ++ } ++} ++ ++static void + nv50_display_unk20_handler(struct drm_device *dev) + { + struct dcb_entry *dcbent; +@@ -837,6 +843,8 @@ nv50_display_unk20_handler(struct drm_device *dev) + + nouveau_bios_run_display_table(dev, dcbent, script, pclk); + ++ nv50_display_unk20_dp_hack(dev, dcbent); ++ + tmp = nv_rd32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(head)); + tmp &= ~0x000000f; + nv_wr32(dev, NV50_PDISPLAY_CRTC_CLK_CTRL2(head), tmp); +@@ -919,10 +927,12 @@ nv50_display_error_handler(struct drm_device *dev) + nv_wr32(dev, NV50_PDISPLAY_TRAPPED_ADDR, 0x90000000); + } + +-static void +-nv50_display_irq_hotplug(struct drm_device *dev) ++void ++nv50_display_irq_hotplug_bh(struct work_struct *work) + { +- struct drm_nouveau_private *dev_priv = dev->dev_private; ++ struct drm_nouveau_private *dev_priv = ++ container_of(work, struct drm_nouveau_private, hpd_work); ++ struct drm_device *dev = dev_priv->dev; + struct drm_connector *connector; + const uint32_t gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 }; + uint32_t unplug_mask, plug_mask, change_mask; +@@ -975,6 +985,8 @@ nv50_display_irq_hotplug(struct drm_device *dev) + nv_wr32(dev, 0xe054, nv_rd32(dev, 0xe054)); + if (dev_priv->chipset >= 0x90) + nv_wr32(dev, 0xe074, nv_rd32(dev, 0xe074)); ++ ++ drm_sysfs_hotplug_event(dev); + } + + void +@@ -983,8 +995,10 @@ nv50_display_irq_handler(struct drm_device *dev) + struct drm_nouveau_private *dev_priv = dev->dev_private; + uint32_t delayed = 0; + +- while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_HOTPLUG) +- nv50_display_irq_hotplug(dev); ++ if (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_HOTPLUG) { ++ if (!work_pending(&dev_priv->hpd_work)) ++ queue_work(dev_priv->wq, &dev_priv->hpd_work); ++ } + + while (nv_rd32(dev, NV50_PMC_INTR_0) & NV50_PMC_INTR_0_DISPLAY) { + uint32_t intr0 = nv_rd32(dev, NV50_PDISPLAY_INTR_0); +diff --git a/drivers/gpu/drm/nouveau/nv50_display.h b/drivers/gpu/drm/nouveau/nv50_display.h +index 3ae8d07..581d405 100644 +--- a/drivers/gpu/drm/nouveau/nv50_display.h ++++ b/drivers/gpu/drm/nouveau/nv50_display.h +@@ -37,6 +37,7 @@ + + void nv50_display_irq_handler(struct drm_device *dev); + void nv50_display_irq_handler_bh(struct work_struct *work); ++void nv50_display_irq_hotplug_bh(struct work_struct *work); + int nv50_display_init(struct drm_device *dev); + int nv50_display_create(struct drm_device *dev); + int nv50_display_destroy(struct drm_device *dev); +diff --git a/drivers/gpu/drm/nouveau/nv50_fb.c b/drivers/gpu/drm/nouveau/nv50_fb.c +new file mode 100644 +index 0000000..32611bd +--- /dev/null ++++ b/drivers/gpu/drm/nouveau/nv50_fb.c +@@ -0,0 +1,38 @@ ++#include "drmP.h" ++#include "drm.h" ++#include "nouveau_drv.h" ++#include "nouveau_drm.h" ++ ++int ++nv50_fb_init(struct drm_device *dev) ++{ ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ ++ /* Not a clue what this is exactly. Without pointing it at a ++ * scratch page, VRAM->GART blits with M2MF (as in DDX DFS) ++ * cause IOMMU "read from address 0" errors (rh#561267) ++ */ ++ nv_wr32(dev, 0x100c08, dev_priv->gart_info.sg_dummy_bus >> 8); ++ ++ /* This is needed to get meaningful information from 100c90 ++ * on traps. No idea what these values mean exactly. */ ++ switch (dev_priv->chipset) { ++ case 0x50: ++ nv_wr32(dev, 0x100c90, 0x0707ff); ++ break; ++ case 0xa5: ++ case 0xa8: ++ nv_wr32(dev, 0x100c90, 0x0d0fff); ++ break; ++ default: ++ nv_wr32(dev, 0x100c90, 0x1d07ff); ++ break; ++ } ++ ++ return 0; ++} ++ ++void ++nv50_fb_takedown(struct drm_device *dev) ++{ ++} +diff --git a/drivers/gpu/drm/nouveau/nv50_fbcon.c b/drivers/gpu/drm/nouveau/nv50_fbcon.c +index 0f57cdf..a8c70e7 100644 +--- a/drivers/gpu/drm/nouveau/nv50_fbcon.c ++++ b/drivers/gpu/drm/nouveau/nv50_fbcon.c +@@ -109,7 +109,7 @@ nv50_fbcon_imageblit(struct fb_info *info, const struct fb_image *image) + return; + } + +- width = (image->width + 31) & ~31; ++ width = ALIGN(image->width, 32); + dwords = (width * image->height) >> 5; + + BEGIN_RING(chan, NvSub2D, 0x0814, 2); +@@ -157,8 +157,11 @@ nv50_fbcon_accel_init(struct fb_info *info) + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_channel *chan = dev_priv->channel; + struct nouveau_gpuobj *eng2d = NULL; ++ uint64_t fb; + int ret, format; + ++ fb = info->fix.smem_start - dev_priv->fb_phys + dev_priv->vm_vram_base; ++ + switch (info->var.bits_per_pixel) { + case 8: + format = 0xf3; +@@ -233,7 +236,7 @@ nv50_fbcon_accel_init(struct fb_info *info) + BEGIN_RING(chan, NvSub2D, 0x0808, 3); + OUT_RING(chan, 0); + OUT_RING(chan, 0); +- OUT_RING(chan, 0); ++ OUT_RING(chan, 1); + BEGIN_RING(chan, NvSub2D, 0x081c, 1); + OUT_RING(chan, 1); + BEGIN_RING(chan, NvSub2D, 0x0840, 4); +@@ -248,9 +251,8 @@ nv50_fbcon_accel_init(struct fb_info *info) + OUT_RING(chan, info->fix.line_length); + OUT_RING(chan, info->var.xres_virtual); + OUT_RING(chan, info->var.yres_virtual); +- OUT_RING(chan, 0); +- OUT_RING(chan, info->fix.smem_start - dev_priv->fb_phys + +- dev_priv->vm_vram_base); ++ OUT_RING(chan, upper_32_bits(fb)); ++ OUT_RING(chan, lower_32_bits(fb)); + BEGIN_RING(chan, NvSub2D, 0x0230, 2); + OUT_RING(chan, format); + OUT_RING(chan, 1); +@@ -258,9 +260,8 @@ nv50_fbcon_accel_init(struct fb_info *info) + OUT_RING(chan, info->fix.line_length); + OUT_RING(chan, info->var.xres_virtual); + OUT_RING(chan, info->var.yres_virtual); +- OUT_RING(chan, 0); +- OUT_RING(chan, info->fix.smem_start - dev_priv->fb_phys + +- dev_priv->vm_vram_base); ++ OUT_RING(chan, upper_32_bits(fb)); ++ OUT_RING(chan, lower_32_bits(fb)); + + return 0; + } +diff --git a/drivers/gpu/drm/nouveau/nv50_fifo.c b/drivers/gpu/drm/nouveau/nv50_fifo.c +index df5335a..e20c0e2 100644 +--- a/drivers/gpu/drm/nouveau/nv50_fifo.c ++++ b/drivers/gpu/drm/nouveau/nv50_fifo.c +@@ -243,6 +243,7 @@ nv50_fifo_create_context(struct nouveau_channel *chan) + struct drm_device *dev = chan->dev; + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_gpuobj *ramfc = NULL; ++ unsigned long flags; + int ret; + + NV_DEBUG(dev, "ch%d\n", chan->id); +@@ -278,6 +279,8 @@ nv50_fifo_create_context(struct nouveau_channel *chan) + return ret; + } + ++ spin_lock_irqsave(&dev_priv->context_switch_lock, flags); ++ + dev_priv->engine.instmem.prepare_access(dev, true); + + nv_wo32(dev, ramfc, 0x48/4, chan->pushbuf->instance >> 4); +@@ -306,10 +309,12 @@ nv50_fifo_create_context(struct nouveau_channel *chan) + ret = nv50_fifo_channel_enable(dev, chan->id, false); + if (ret) { + NV_ERROR(dev, "error enabling ch%d: %d\n", chan->id, ret); ++ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); + nouveau_gpuobj_ref_del(dev, &chan->ramfc); + return ret; + } + ++ spin_unlock_irqrestore(&dev_priv->context_switch_lock, flags); + return 0; + } + +diff --git a/drivers/gpu/drm/nouveau/nv50_gpio.c b/drivers/gpu/drm/nouveau/nv50_gpio.c +new file mode 100644 +index 0000000..c61782b +--- /dev/null ++++ b/drivers/gpu/drm/nouveau/nv50_gpio.c +@@ -0,0 +1,76 @@ ++/* ++ * Copyright 2010 Red Hat Inc. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR ++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ++ * OTHER DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Ben Skeggs ++ */ ++ ++#include "drmP.h" ++#include "nouveau_drv.h" ++#include "nouveau_hw.h" ++ ++static int ++nv50_gpio_location(struct dcb_gpio_entry *gpio, uint32_t *reg, uint32_t *shift) ++{ ++ const uint32_t nv50_gpio_reg[4] = { 0xe104, 0xe108, 0xe280, 0xe284 }; ++ ++ if (gpio->line > 32) ++ return -EINVAL; ++ ++ *reg = nv50_gpio_reg[gpio->line >> 3]; ++ *shift = (gpio->line & 7) << 2; ++ return 0; ++} ++ ++int ++nv50_gpio_get(struct drm_device *dev, enum dcb_gpio_tag tag) ++{ ++ struct dcb_gpio_entry *gpio; ++ uint32_t r, s, v; ++ ++ gpio = nouveau_bios_gpio_entry(dev, tag); ++ if (!gpio) ++ return -ENOENT; ++ ++ if (nv50_gpio_location(gpio, &r, &s)) ++ return -EINVAL; ++ ++ v = nv_rd32(dev, r) >> (s + 2); ++ return ((v & 1) == (gpio->state[1] & 1)); ++} ++ ++int ++nv50_gpio_set(struct drm_device *dev, enum dcb_gpio_tag tag, int state) ++{ ++ struct dcb_gpio_entry *gpio; ++ uint32_t r, s, v; ++ ++ gpio = nouveau_bios_gpio_entry(dev, tag); ++ if (!gpio) ++ return -ENOENT; ++ ++ if (nv50_gpio_location(gpio, &r, &s)) ++ return -EINVAL; ++ ++ v = nv_rd32(dev, r) & ~(0x3 << s); ++ v |= (gpio->state[state] ^ 2) << s; ++ nv_wr32(dev, r, v); ++ return 0; ++} +diff --git a/drivers/gpu/drm/nouveau/nv50_graph.c b/drivers/gpu/drm/nouveau/nv50_graph.c +index 6d50480..b203d06 100644 +--- a/drivers/gpu/drm/nouveau/nv50_graph.c ++++ b/drivers/gpu/drm/nouveau/nv50_graph.c +@@ -28,30 +28,7 @@ + #include "drm.h" + #include "nouveau_drv.h" + +-MODULE_FIRMWARE("nouveau/nv50.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv50.ctxvals"); +-MODULE_FIRMWARE("nouveau/nv84.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv84.ctxvals"); +-MODULE_FIRMWARE("nouveau/nv86.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv86.ctxvals"); +-MODULE_FIRMWARE("nouveau/nv92.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv92.ctxvals"); +-MODULE_FIRMWARE("nouveau/nv94.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv94.ctxvals"); +-MODULE_FIRMWARE("nouveau/nv96.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv96.ctxvals"); +-MODULE_FIRMWARE("nouveau/nv98.ctxprog"); +-MODULE_FIRMWARE("nouveau/nv98.ctxvals"); +-MODULE_FIRMWARE("nouveau/nva0.ctxprog"); +-MODULE_FIRMWARE("nouveau/nva0.ctxvals"); +-MODULE_FIRMWARE("nouveau/nva5.ctxprog"); +-MODULE_FIRMWARE("nouveau/nva5.ctxvals"); +-MODULE_FIRMWARE("nouveau/nva8.ctxprog"); +-MODULE_FIRMWARE("nouveau/nva8.ctxvals"); +-MODULE_FIRMWARE("nouveau/nvaa.ctxprog"); +-MODULE_FIRMWARE("nouveau/nvaa.ctxvals"); +-MODULE_FIRMWARE("nouveau/nvac.ctxprog"); +-MODULE_FIRMWARE("nouveau/nvac.ctxvals"); ++#include "nouveau_grctx.h" + + #define IS_G80 ((dev_priv->chipset & 0xf0) == 0x50) + +@@ -79,6 +56,10 @@ nv50_graph_init_intr(struct drm_device *dev) + static void + nv50_graph_init_regs__nv(struct drm_device *dev) + { ++ struct drm_nouveau_private *dev_priv = dev->dev_private; ++ uint32_t units = nv_rd32(dev, 0x1540); ++ int i; ++ + NV_DEBUG(dev, "\n"); + + nv_wr32(dev, 0x400804, 0xc0000000); +@@ -88,6 +69,20 @@ nv50_graph_init_regs__nv(struct drm_device *dev) + nv_wr32(dev, 0x405018, 0xc0000000); + nv_wr32(dev, 0x402000, 0xc0000000); + ++ for (i = 0; i < 16; i++) { ++ if (units & 1 << i) { ++ if (dev_priv->chipset < 0xa0) { ++ nv_wr32(dev, 0x408900 + (i << 12), 0xc0000000); ++ nv_wr32(dev, 0x408e08 + (i << 12), 0xc0000000); ++ nv_wr32(dev, 0x408314 + (i << 12), 0xc0000000); ++ } else { ++ nv_wr32(dev, 0x408600 + (i << 11), 0xc0000000); ++ nv_wr32(dev, 0x408708 + (i << 11), 0xc0000000); ++ nv_wr32(dev, 0x40831c + (i << 11), 0xc0000000); ++ } ++ } ++ } ++ + nv_wr32(dev, 0x400108, 0xffffffff); + + nv_wr32(dev, 0x400824, 0x00004000); +@@ -111,9 +106,34 @@ nv50_graph_init_ctxctl(struct drm_device *dev) + + NV_DEBUG(dev, "\n"); + +- nouveau_grctx_prog_load(dev); +- if (!dev_priv->engine.graph.ctxprog) +- dev_priv->engine.graph.accel_blocked = true; ++ if (nouveau_ctxfw) { ++ nouveau_grctx_prog_load(dev); ++ dev_priv->engine.graph.grctx_size = 0x70000; ++ } ++ if (!dev_priv->engine.graph.ctxprog) { ++ struct nouveau_grctx ctx = {}; ++ uint32_t *cp = kmalloc(512 * 4, GFP_KERNEL); ++ int i; ++ if (!cp) { ++ NV_ERROR(dev, "Couldn't alloc ctxprog! Disabling acceleration.\n"); ++ dev_priv->engine.graph.accel_blocked = true; ++ return 0; ++ } ++ ctx.dev = dev; ++ ctx.mode = NOUVEAU_GRCTX_PROG; ++ ctx.data = cp; ++ ctx.ctxprog_max = 512; ++ if (!nv50_grctx_init(&ctx)) { ++ dev_priv->engine.graph.grctx_size = ctx.ctxvals_pos * 4; ++ ++ nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_INDEX, 0); ++ for (i = 0; i < ctx.ctxprog_len; i++) ++ nv_wr32(dev, NV40_PGRAPH_CTXCTL_UCODE_DATA, cp[i]); ++ } else { ++ dev_priv->engine.graph.accel_blocked = true; ++ } ++ kfree(cp); ++ } + + nv_wr32(dev, 0x400320, 4); + nv_wr32(dev, NV40_PGRAPH_CTXCTL_CUR, 0); +@@ -193,13 +213,13 @@ nv50_graph_create_context(struct nouveau_channel *chan) + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_gpuobj *ramin = chan->ramin->gpuobj; + struct nouveau_gpuobj *ctx; +- uint32_t grctx_size = 0x70000; ++ struct nouveau_pgraph_engine *pgraph = &dev_priv->engine.graph; + int hdr, ret; + + NV_DEBUG(dev, "ch%d\n", chan->id); + +- ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, grctx_size, 0x1000, +- NVOBJ_FLAG_ZERO_ALLOC | ++ ret = nouveau_gpuobj_new_ref(dev, chan, NULL, 0, pgraph->grctx_size, ++ 0x1000, NVOBJ_FLAG_ZERO_ALLOC | + NVOBJ_FLAG_ZERO_FREE, &chan->ramin_grctx); + if (ret) + return ret; +@@ -209,7 +229,7 @@ nv50_graph_create_context(struct nouveau_channel *chan) + dev_priv->engine.instmem.prepare_access(dev, true); + nv_wo32(dev, ramin, (hdr + 0x00)/4, 0x00190002); + nv_wo32(dev, ramin, (hdr + 0x04)/4, chan->ramin_grctx->instance + +- grctx_size - 1); ++ pgraph->grctx_size - 1); + nv_wo32(dev, ramin, (hdr + 0x08)/4, chan->ramin_grctx->instance); + nv_wo32(dev, ramin, (hdr + 0x0c)/4, 0); + nv_wo32(dev, ramin, (hdr + 0x10)/4, 0); +@@ -217,12 +237,16 @@ nv50_graph_create_context(struct nouveau_channel *chan) + dev_priv->engine.instmem.finish_access(dev); + + dev_priv->engine.instmem.prepare_access(dev, true); +- nouveau_grctx_vals_load(dev, ctx); ++ if (!pgraph->ctxprog) { ++ struct nouveau_grctx ctx = {}; ++ ctx.dev = chan->dev; ++ ctx.mode = NOUVEAU_GRCTX_VALS; ++ ctx.data = chan->ramin_grctx->gpuobj; ++ nv50_grctx_init(&ctx); ++ } else { ++ nouveau_grctx_vals_load(dev, ctx); ++ } + nv_wo32(dev, ctx, 0x00000/4, chan->ramin->instance >> 12); +- if ((dev_priv->chipset & 0xf0) == 0xa0) +- nv_wo32(dev, ctx, 0x00004/4, 0x00000000); +- else +- nv_wo32(dev, ctx, 0x0011c/4, 0x00000000); + dev_priv->engine.instmem.finish_access(dev); + + return 0; +@@ -386,9 +410,10 @@ struct nouveau_pgraph_object_class nv50_graph_grclass[] = { + { 0x5039, false, NULL }, /* m2mf */ + { 0x502d, false, NULL }, /* 2d */ + { 0x50c0, false, NULL }, /* compute */ ++ { 0x85c0, false, NULL }, /* compute (nva3, nva5, nva8) */ + { 0x5097, false, NULL }, /* tesla (nv50) */ +- { 0x8297, false, NULL }, /* tesla (nv80/nv90) */ +- { 0x8397, false, NULL }, /* tesla (nva0) */ +- { 0x8597, false, NULL }, /* tesla (nva8) */ ++ { 0x8297, false, NULL }, /* tesla (nv8x/nv9x) */ ++ { 0x8397, false, NULL }, /* tesla (nva0, nvaa, nvac) */ ++ { 0x8597, false, NULL }, /* tesla (nva3, nva5, nva8) */ + {} + }; +diff --git a/drivers/gpu/drm/nouveau/nv50_grctx.c b/drivers/gpu/drm/nouveau/nv50_grctx.c +new file mode 100644 +index 0000000..42a8fb2 +--- /dev/null ++++ b/drivers/gpu/drm/nouveau/nv50_grctx.c +@@ -0,0 +1,2383 @@ ++/* ++ * Copyright 2009 Marcin Kościelnicki ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR ++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ++ * OTHER DEALINGS IN THE SOFTWARE. ++ */ ++ ++#define CP_FLAG_CLEAR 0 ++#define CP_FLAG_SET 1 ++#define CP_FLAG_SWAP_DIRECTION ((0 * 32) + 0) ++#define CP_FLAG_SWAP_DIRECTION_LOAD 0 ++#define CP_FLAG_SWAP_DIRECTION_SAVE 1 ++#define CP_FLAG_UNK01 ((0 * 32) + 1) ++#define CP_FLAG_UNK01_CLEAR 0 ++#define CP_FLAG_UNK01_SET 1 ++#define CP_FLAG_UNK03 ((0 * 32) + 3) ++#define CP_FLAG_UNK03_CLEAR 0 ++#define CP_FLAG_UNK03_SET 1 ++#define CP_FLAG_USER_SAVE ((0 * 32) + 5) ++#define CP_FLAG_USER_SAVE_NOT_PENDING 0 ++#define CP_FLAG_USER_SAVE_PENDING 1 ++#define CP_FLAG_USER_LOAD ((0 * 32) + 6) ++#define CP_FLAG_USER_LOAD_NOT_PENDING 0 ++#define CP_FLAG_USER_LOAD_PENDING 1 ++#define CP_FLAG_UNK0B ((0 * 32) + 0xb) ++#define CP_FLAG_UNK0B_CLEAR 0 ++#define CP_FLAG_UNK0B_SET 1 ++#define CP_FLAG_UNK1D ((0 * 32) + 0x1d) ++#define CP_FLAG_UNK1D_CLEAR 0 ++#define CP_FLAG_UNK1D_SET 1 ++#define CP_FLAG_UNK20 ((1 * 32) + 0) ++#define CP_FLAG_UNK20_CLEAR 0 ++#define CP_FLAG_UNK20_SET 1 ++#define CP_FLAG_STATUS ((2 * 32) + 0) ++#define CP_FLAG_STATUS_BUSY 0 ++#define CP_FLAG_STATUS_IDLE 1 ++#define CP_FLAG_AUTO_SAVE ((2 * 32) + 4) ++#define CP_FLAG_AUTO_SAVE_NOT_PENDING 0 ++#define CP_FLAG_AUTO_SAVE_PENDING 1 ++#define CP_FLAG_AUTO_LOAD ((2 * 32) + 5) ++#define CP_FLAG_AUTO_LOAD_NOT_PENDING 0 ++#define CP_FLAG_AUTO_LOAD_PENDING 1 ++#define CP_FLAG_NEWCTX ((2 * 32) + 10) ++#define CP_FLAG_NEWCTX_BUSY 0 ++#define CP_FLAG_NEWCTX_DONE 1 ++#define CP_FLAG_XFER ((2 * 32) + 11) ++#define CP_FLAG_XFER_IDLE 0 ++#define CP_FLAG_XFER_BUSY 1 ++#define CP_FLAG_ALWAYS ((2 * 32) + 13) ++#define CP_FLAG_ALWAYS_FALSE 0 ++#define CP_FLAG_ALWAYS_TRUE 1 ++#define CP_FLAG_INTR ((2 * 32) + 15) ++#define CP_FLAG_INTR_NOT_PENDING 0 ++#define CP_FLAG_INTR_PENDING 1 ++ ++#define CP_CTX 0x00100000 ++#define CP_CTX_COUNT 0x000f0000 ++#define CP_CTX_COUNT_SHIFT 16 ++#define CP_CTX_REG 0x00003fff ++#define CP_LOAD_SR 0x00200000 ++#define CP_LOAD_SR_VALUE 0x000fffff ++#define CP_BRA 0x00400000 ++#define CP_BRA_IP 0x0001ff00 ++#define CP_BRA_IP_SHIFT 8 ++#define CP_BRA_IF_CLEAR 0x00000080 ++#define CP_BRA_FLAG 0x0000007f ++#define CP_WAIT 0x00500000 ++#define CP_WAIT_SET 0x00000080 ++#define CP_WAIT_FLAG 0x0000007f ++#define CP_SET 0x00700000 ++#define CP_SET_1 0x00000080 ++#define CP_SET_FLAG 0x0000007f ++#define CP_NEWCTX 0x00600004 ++#define CP_NEXT_TO_SWAP 0x00600005 ++#define CP_SET_CONTEXT_POINTER 0x00600006 ++#define CP_SET_XFER_POINTER 0x00600007 ++#define CP_ENABLE 0x00600009 ++#define CP_END 0x0060000c ++#define CP_NEXT_TO_CURRENT 0x0060000d ++#define CP_DISABLE1 0x0090ffff ++#define CP_DISABLE2 0x0091ffff ++#define CP_XFER_1 0x008000ff ++#define CP_XFER_2 0x008800ff ++#define CP_SEEK_1 0x00c000ff ++#define CP_SEEK_2 0x00c800ff ++ ++#include "drmP.h" ++#include "nouveau_drv.h" ++#include "nouveau_grctx.h" ++ ++/* ++ * This code deals with PGRAPH contexts on NV50 family cards. Like NV40, it's ++ * the GPU itself that does context-switching, but it needs a special ++ * microcode to do it. And it's the driver's task to supply this microcode, ++ * further known as ctxprog, as well as the initial context values, known ++ * as ctxvals. ++ * ++ * Without ctxprog, you cannot switch contexts. Not even in software, since ++ * the majority of context [xfer strands] isn't accessible directly. You're ++ * stuck with a single channel, and you also suffer all the problems resulting ++ * from missing ctxvals, since you cannot load them. ++ * ++ * Without ctxvals, you're stuck with PGRAPH's default context. It's enough to ++ * run 2d operations, but trying to utilise 3d or CUDA will just lock you up, ++ * since you don't have... some sort of needed setup. ++ * ++ * Nouveau will just disable acceleration if not given ctxprog + ctxvals, since ++ * it's too much hassle to handle no-ctxprog as a special case. ++ */ ++ ++/* ++ * How ctxprogs work. ++ * ++ * The ctxprog is written in its own kind of microcode, with very small and ++ * crappy set of available commands. You upload it to a small [512 insns] ++ * area of memory on PGRAPH, and it'll be run when PFIFO wants PGRAPH to ++ * switch channel. or when the driver explicitely requests it. Stuff visible ++ * to ctxprog consists of: PGRAPH MMIO registers, PGRAPH context strands, ++ * the per-channel context save area in VRAM [known as ctxvals or grctx], ++ * 4 flags registers, a scratch register, two grctx pointers, plus many ++ * random poorly-understood details. ++ * ++ * When ctxprog runs, it's supposed to check what operations are asked of it, ++ * save old context if requested, optionally reset PGRAPH and switch to the ++ * new channel, and load the new context. Context consists of three major ++ * parts: subset of MMIO registers and two "xfer areas". ++ */ ++ ++/* TODO: ++ * - document unimplemented bits compared to nvidia ++ * - NVAx: make a TP subroutine, use it. ++ * - use 0x4008fc instead of 0x1540? ++ */ ++ ++enum cp_label { ++ cp_check_load = 1, ++ cp_setup_auto_load, ++ cp_setup_load, ++ cp_setup_save, ++ cp_swap_state, ++ cp_prepare_exit, ++ cp_exit, ++}; ++ ++static void nv50_graph_construct_mmio(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_xfer1(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_xfer2(struct nouveau_grctx *ctx); ++ ++/* Main function: construct the ctxprog skeleton, call the other functions. */ ++ ++int ++nv50_grctx_init(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ ++ switch (dev_priv->chipset) { ++ case 0x50: ++ case 0x84: ++ case 0x86: ++ case 0x92: ++ case 0x94: ++ case 0x96: ++ case 0x98: ++ case 0xa0: ++ case 0xa3: ++ case 0xa5: ++ case 0xa8: ++ case 0xaa: ++ case 0xac: ++ break; ++ default: ++ NV_ERROR(ctx->dev, "I don't know how to make a ctxprog for " ++ "your NV%x card.\n", dev_priv->chipset); ++ NV_ERROR(ctx->dev, "Disabling acceleration. Please contact " ++ "the devs.\n"); ++ return -ENOSYS; ++ } ++ /* decide whether we're loading/unloading the context */ ++ cp_bra (ctx, AUTO_SAVE, PENDING, cp_setup_save); ++ cp_bra (ctx, USER_SAVE, PENDING, cp_setup_save); ++ ++ cp_name(ctx, cp_check_load); ++ cp_bra (ctx, AUTO_LOAD, PENDING, cp_setup_auto_load); ++ cp_bra (ctx, USER_LOAD, PENDING, cp_setup_load); ++ cp_bra (ctx, ALWAYS, TRUE, cp_exit); ++ ++ /* setup for context load */ ++ cp_name(ctx, cp_setup_auto_load); ++ cp_out (ctx, CP_DISABLE1); ++ cp_out (ctx, CP_DISABLE2); ++ cp_out (ctx, CP_ENABLE); ++ cp_out (ctx, CP_NEXT_TO_SWAP); ++ cp_set (ctx, UNK01, SET); ++ cp_name(ctx, cp_setup_load); ++ cp_out (ctx, CP_NEWCTX); ++ cp_wait(ctx, NEWCTX, BUSY); ++ cp_set (ctx, UNK1D, CLEAR); ++ cp_set (ctx, SWAP_DIRECTION, LOAD); ++ cp_bra (ctx, UNK0B, SET, cp_prepare_exit); ++ cp_bra (ctx, ALWAYS, TRUE, cp_swap_state); ++ ++ /* setup for context save */ ++ cp_name(ctx, cp_setup_save); ++ cp_set (ctx, UNK1D, SET); ++ cp_wait(ctx, STATUS, BUSY); ++ cp_wait(ctx, INTR, PENDING); ++ cp_bra (ctx, STATUS, BUSY, cp_setup_save); ++ cp_set (ctx, UNK01, SET); ++ cp_set (ctx, SWAP_DIRECTION, SAVE); ++ ++ /* general PGRAPH state */ ++ cp_name(ctx, cp_swap_state); ++ cp_set (ctx, UNK03, SET); ++ cp_pos (ctx, 0x00004/4); ++ cp_ctx (ctx, 0x400828, 1); /* needed. otherwise, flickering happens. */ ++ cp_pos (ctx, 0x00100/4); ++ nv50_graph_construct_mmio(ctx); ++ nv50_graph_construct_xfer1(ctx); ++ nv50_graph_construct_xfer2(ctx); ++ ++ cp_bra (ctx, SWAP_DIRECTION, SAVE, cp_check_load); ++ ++ cp_set (ctx, UNK20, SET); ++ cp_set (ctx, SWAP_DIRECTION, SAVE); /* no idea why this is needed, but fixes at least one lockup. */ ++ cp_lsr (ctx, ctx->ctxvals_base); ++ cp_out (ctx, CP_SET_XFER_POINTER); ++ cp_lsr (ctx, 4); ++ cp_out (ctx, CP_SEEK_1); ++ cp_out (ctx, CP_XFER_1); ++ cp_wait(ctx, XFER, BUSY); ++ ++ /* pre-exit state updates */ ++ cp_name(ctx, cp_prepare_exit); ++ cp_set (ctx, UNK01, CLEAR); ++ cp_set (ctx, UNK03, CLEAR); ++ cp_set (ctx, UNK1D, CLEAR); ++ ++ cp_bra (ctx, USER_SAVE, PENDING, cp_exit); ++ cp_out (ctx, CP_NEXT_TO_CURRENT); ++ ++ cp_name(ctx, cp_exit); ++ cp_set (ctx, USER_SAVE, NOT_PENDING); ++ cp_set (ctx, USER_LOAD, NOT_PENDING); ++ cp_out (ctx, CP_END); ++ ctx->ctxvals_pos += 0x400; /* padding... no idea why you need it */ ++ ++ return 0; ++} ++ ++/* ++ * Constructs MMIO part of ctxprog and ctxvals. Just a matter of knowing which ++ * registers to save/restore and the default values for them. ++ */ ++ ++static void ++nv50_graph_construct_mmio(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int i, j; ++ int offset, base; ++ uint32_t units = nv_rd32 (ctx->dev, 0x1540); ++ ++ /* 0800: DISPATCH */ ++ cp_ctx(ctx, 0x400808, 7); ++ gr_def(ctx, 0x400814, 0x00000030); ++ cp_ctx(ctx, 0x400834, 0x32); ++ if (dev_priv->chipset == 0x50) { ++ gr_def(ctx, 0x400834, 0xff400040); ++ gr_def(ctx, 0x400838, 0xfff00080); ++ gr_def(ctx, 0x40083c, 0xfff70090); ++ gr_def(ctx, 0x400840, 0xffe806a8); ++ } ++ gr_def(ctx, 0x400844, 0x00000002); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ gr_def(ctx, 0x400894, 0x00001000); ++ gr_def(ctx, 0x4008e8, 0x00000003); ++ gr_def(ctx, 0x4008ec, 0x00001000); ++ if (dev_priv->chipset == 0x50) ++ cp_ctx(ctx, 0x400908, 0xb); ++ else if (dev_priv->chipset < 0xa0) ++ cp_ctx(ctx, 0x400908, 0xc); ++ else ++ cp_ctx(ctx, 0x400908, 0xe); ++ ++ if (dev_priv->chipset >= 0xa0) ++ cp_ctx(ctx, 0x400b00, 0x1); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ cp_ctx(ctx, 0x400b10, 0x1); ++ gr_def(ctx, 0x400b10, 0x0001629d); ++ cp_ctx(ctx, 0x400b20, 0x1); ++ gr_def(ctx, 0x400b20, 0x0001629d); ++ } ++ ++ /* 0C00: VFETCH */ ++ cp_ctx(ctx, 0x400c08, 0x2); ++ gr_def(ctx, 0x400c08, 0x0000fe0c); ++ ++ /* 1000 */ ++ if (dev_priv->chipset < 0xa0) { ++ cp_ctx(ctx, 0x401008, 0x4); ++ gr_def(ctx, 0x401014, 0x00001000); ++ } else if (dev_priv->chipset == 0xa0 || dev_priv->chipset >= 0xaa) { ++ cp_ctx(ctx, 0x401008, 0x5); ++ gr_def(ctx, 0x401018, 0x00001000); ++ } else { ++ cp_ctx(ctx, 0x401008, 0x5); ++ gr_def(ctx, 0x401018, 0x00004000); ++ } ++ ++ /* 1400 */ ++ cp_ctx(ctx, 0x401400, 0x8); ++ cp_ctx(ctx, 0x401424, 0x3); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, 0x40142c, 0x0001fd87); ++ else ++ gr_def(ctx, 0x40142c, 0x00000187); ++ cp_ctx(ctx, 0x401540, 0x5); ++ gr_def(ctx, 0x401550, 0x00001018); ++ ++ /* 1800: STREAMOUT */ ++ cp_ctx(ctx, 0x401814, 0x1); ++ gr_def(ctx, 0x401814, 0x000000ff); ++ if (dev_priv->chipset == 0x50) { ++ cp_ctx(ctx, 0x40181c, 0xe); ++ gr_def(ctx, 0x401850, 0x00000004); ++ } else if (dev_priv->chipset < 0xa0) { ++ cp_ctx(ctx, 0x40181c, 0xf); ++ gr_def(ctx, 0x401854, 0x00000004); ++ } else { ++ cp_ctx(ctx, 0x40181c, 0x13); ++ gr_def(ctx, 0x401864, 0x00000004); ++ } ++ ++ /* 1C00 */ ++ cp_ctx(ctx, 0x401c00, 0x1); ++ switch (dev_priv->chipset) { ++ case 0x50: ++ gr_def(ctx, 0x401c00, 0x0001005f); ++ break; ++ case 0x84: ++ case 0x86: ++ case 0x94: ++ gr_def(ctx, 0x401c00, 0x044d00df); ++ break; ++ case 0x92: ++ case 0x96: ++ case 0x98: ++ case 0xa0: ++ case 0xaa: ++ case 0xac: ++ gr_def(ctx, 0x401c00, 0x042500df); ++ break; ++ case 0xa3: ++ case 0xa5: ++ case 0xa8: ++ gr_def(ctx, 0x401c00, 0x142500df); ++ break; ++ } ++ ++ /* 2400 */ ++ cp_ctx(ctx, 0x402400, 0x1); ++ if (dev_priv->chipset == 0x50) ++ cp_ctx(ctx, 0x402408, 0x1); ++ else ++ cp_ctx(ctx, 0x402408, 0x2); ++ gr_def(ctx, 0x402408, 0x00000600); ++ ++ /* 2800 */ ++ cp_ctx(ctx, 0x402800, 0x1); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, 0x402800, 0x00000006); ++ ++ /* 2C00 */ ++ cp_ctx(ctx, 0x402c08, 0x6); ++ if (dev_priv->chipset != 0x50) ++ gr_def(ctx, 0x402c14, 0x01000000); ++ gr_def(ctx, 0x402c18, 0x000000ff); ++ if (dev_priv->chipset == 0x50) ++ cp_ctx(ctx, 0x402ca0, 0x1); ++ else ++ cp_ctx(ctx, 0x402ca0, 0x2); ++ if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, 0x402ca0, 0x00000400); ++ else if (dev_priv->chipset == 0xa0 || dev_priv->chipset >= 0xaa) ++ gr_def(ctx, 0x402ca0, 0x00000800); ++ else ++ gr_def(ctx, 0x402ca0, 0x00000400); ++ cp_ctx(ctx, 0x402cac, 0x4); ++ ++ /* 3000 */ ++ cp_ctx(ctx, 0x403004, 0x1); ++ gr_def(ctx, 0x403004, 0x00000001); ++ ++ /* 3404 */ ++ if (dev_priv->chipset >= 0xa0) { ++ cp_ctx(ctx, 0x403404, 0x1); ++ gr_def(ctx, 0x403404, 0x00000001); ++ } ++ ++ /* 5000 */ ++ cp_ctx(ctx, 0x405000, 0x1); ++ switch (dev_priv->chipset) { ++ case 0x50: ++ gr_def(ctx, 0x405000, 0x00300080); ++ break; ++ case 0x84: ++ case 0xa0: ++ case 0xa3: ++ case 0xa5: ++ case 0xa8: ++ case 0xaa: ++ case 0xac: ++ gr_def(ctx, 0x405000, 0x000e0080); ++ break; ++ case 0x86: ++ case 0x92: ++ case 0x94: ++ case 0x96: ++ case 0x98: ++ gr_def(ctx, 0x405000, 0x00000080); ++ break; ++ } ++ cp_ctx(ctx, 0x405014, 0x1); ++ gr_def(ctx, 0x405014, 0x00000004); ++ cp_ctx(ctx, 0x40501c, 0x1); ++ cp_ctx(ctx, 0x405024, 0x1); ++ cp_ctx(ctx, 0x40502c, 0x1); ++ ++ /* 5400 or maybe 4800 */ ++ if (dev_priv->chipset == 0x50) { ++ offset = 0x405400; ++ cp_ctx(ctx, 0x405400, 0xea); ++ } else if (dev_priv->chipset < 0x94) { ++ offset = 0x405400; ++ cp_ctx(ctx, 0x405400, 0xcb); ++ } else if (dev_priv->chipset < 0xa0) { ++ offset = 0x405400; ++ cp_ctx(ctx, 0x405400, 0xcc); ++ } else if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ offset = 0x404800; ++ cp_ctx(ctx, 0x404800, 0xda); ++ } else { ++ offset = 0x405400; ++ cp_ctx(ctx, 0x405400, 0xd4); ++ } ++ gr_def(ctx, offset + 0x0c, 0x00000002); ++ gr_def(ctx, offset + 0x10, 0x00000001); ++ if (dev_priv->chipset >= 0x94) ++ offset += 4; ++ gr_def(ctx, offset + 0x1c, 0x00000001); ++ gr_def(ctx, offset + 0x20, 0x00000100); ++ gr_def(ctx, offset + 0x38, 0x00000002); ++ gr_def(ctx, offset + 0x3c, 0x00000001); ++ gr_def(ctx, offset + 0x40, 0x00000001); ++ gr_def(ctx, offset + 0x50, 0x00000001); ++ gr_def(ctx, offset + 0x54, 0x003fffff); ++ gr_def(ctx, offset + 0x58, 0x00001fff); ++ gr_def(ctx, offset + 0x60, 0x00000001); ++ gr_def(ctx, offset + 0x64, 0x00000001); ++ gr_def(ctx, offset + 0x6c, 0x00000001); ++ gr_def(ctx, offset + 0x70, 0x00000001); ++ gr_def(ctx, offset + 0x74, 0x00000001); ++ gr_def(ctx, offset + 0x78, 0x00000004); ++ gr_def(ctx, offset + 0x7c, 0x00000001); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ offset += 4; ++ gr_def(ctx, offset + 0x80, 0x00000001); ++ gr_def(ctx, offset + 0x84, 0x00000001); ++ gr_def(ctx, offset + 0x88, 0x00000007); ++ gr_def(ctx, offset + 0x8c, 0x00000001); ++ gr_def(ctx, offset + 0x90, 0x00000007); ++ gr_def(ctx, offset + 0x94, 0x00000001); ++ gr_def(ctx, offset + 0x98, 0x00000001); ++ gr_def(ctx, offset + 0x9c, 0x00000001); ++ if (dev_priv->chipset == 0x50) { ++ gr_def(ctx, offset + 0xb0, 0x00000001); ++ gr_def(ctx, offset + 0xb4, 0x00000001); ++ gr_def(ctx, offset + 0xbc, 0x00000001); ++ gr_def(ctx, offset + 0xc0, 0x0000000a); ++ gr_def(ctx, offset + 0xd0, 0x00000040); ++ gr_def(ctx, offset + 0xd8, 0x00000002); ++ gr_def(ctx, offset + 0xdc, 0x00000100); ++ gr_def(ctx, offset + 0xe0, 0x00000001); ++ gr_def(ctx, offset + 0xe4, 0x00000100); ++ gr_def(ctx, offset + 0x100, 0x00000001); ++ gr_def(ctx, offset + 0x124, 0x00000004); ++ gr_def(ctx, offset + 0x13c, 0x00000001); ++ gr_def(ctx, offset + 0x140, 0x00000100); ++ gr_def(ctx, offset + 0x148, 0x00000001); ++ gr_def(ctx, offset + 0x154, 0x00000100); ++ gr_def(ctx, offset + 0x158, 0x00000001); ++ gr_def(ctx, offset + 0x15c, 0x00000100); ++ gr_def(ctx, offset + 0x164, 0x00000001); ++ gr_def(ctx, offset + 0x170, 0x00000100); ++ gr_def(ctx, offset + 0x174, 0x00000001); ++ gr_def(ctx, offset + 0x17c, 0x00000001); ++ gr_def(ctx, offset + 0x188, 0x00000002); ++ gr_def(ctx, offset + 0x190, 0x00000001); ++ gr_def(ctx, offset + 0x198, 0x00000001); ++ gr_def(ctx, offset + 0x1ac, 0x00000003); ++ offset += 0xd0; ++ } else { ++ gr_def(ctx, offset + 0xb0, 0x00000001); ++ gr_def(ctx, offset + 0xb4, 0x00000100); ++ gr_def(ctx, offset + 0xbc, 0x00000001); ++ gr_def(ctx, offset + 0xc8, 0x00000100); ++ gr_def(ctx, offset + 0xcc, 0x00000001); ++ gr_def(ctx, offset + 0xd0, 0x00000100); ++ gr_def(ctx, offset + 0xd8, 0x00000001); ++ gr_def(ctx, offset + 0xe4, 0x00000100); ++ } ++ gr_def(ctx, offset + 0xf8, 0x00000004); ++ gr_def(ctx, offset + 0xfc, 0x00000070); ++ gr_def(ctx, offset + 0x100, 0x00000080); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ offset += 4; ++ gr_def(ctx, offset + 0x114, 0x0000000c); ++ if (dev_priv->chipset == 0x50) ++ offset -= 4; ++ gr_def(ctx, offset + 0x11c, 0x00000008); ++ gr_def(ctx, offset + 0x120, 0x00000014); ++ if (dev_priv->chipset == 0x50) { ++ gr_def(ctx, offset + 0x124, 0x00000026); ++ offset -= 0x18; ++ } else { ++ gr_def(ctx, offset + 0x128, 0x00000029); ++ gr_def(ctx, offset + 0x12c, 0x00000027); ++ gr_def(ctx, offset + 0x130, 0x00000026); ++ gr_def(ctx, offset + 0x134, 0x00000008); ++ gr_def(ctx, offset + 0x138, 0x00000004); ++ gr_def(ctx, offset + 0x13c, 0x00000027); ++ } ++ gr_def(ctx, offset + 0x148, 0x00000001); ++ gr_def(ctx, offset + 0x14c, 0x00000002); ++ gr_def(ctx, offset + 0x150, 0x00000003); ++ gr_def(ctx, offset + 0x154, 0x00000004); ++ gr_def(ctx, offset + 0x158, 0x00000005); ++ gr_def(ctx, offset + 0x15c, 0x00000006); ++ gr_def(ctx, offset + 0x160, 0x00000007); ++ gr_def(ctx, offset + 0x164, 0x00000001); ++ gr_def(ctx, offset + 0x1a8, 0x000000cf); ++ if (dev_priv->chipset == 0x50) ++ offset -= 4; ++ gr_def(ctx, offset + 0x1d8, 0x00000080); ++ gr_def(ctx, offset + 0x1dc, 0x00000004); ++ gr_def(ctx, offset + 0x1e0, 0x00000004); ++ if (dev_priv->chipset == 0x50) ++ offset -= 4; ++ else ++ gr_def(ctx, offset + 0x1e4, 0x00000003); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ gr_def(ctx, offset + 0x1ec, 0x00000003); ++ offset += 8; ++ } ++ gr_def(ctx, offset + 0x1e8, 0x00000001); ++ if (dev_priv->chipset == 0x50) ++ offset -= 4; ++ gr_def(ctx, offset + 0x1f4, 0x00000012); ++ gr_def(ctx, offset + 0x1f8, 0x00000010); ++ gr_def(ctx, offset + 0x1fc, 0x0000000c); ++ gr_def(ctx, offset + 0x200, 0x00000001); ++ gr_def(ctx, offset + 0x210, 0x00000004); ++ gr_def(ctx, offset + 0x214, 0x00000002); ++ gr_def(ctx, offset + 0x218, 0x00000004); ++ if (dev_priv->chipset >= 0xa0) ++ offset += 4; ++ gr_def(ctx, offset + 0x224, 0x003fffff); ++ gr_def(ctx, offset + 0x228, 0x00001fff); ++ if (dev_priv->chipset == 0x50) ++ offset -= 0x20; ++ else if (dev_priv->chipset >= 0xa0) { ++ gr_def(ctx, offset + 0x250, 0x00000001); ++ gr_def(ctx, offset + 0x254, 0x00000001); ++ gr_def(ctx, offset + 0x258, 0x00000002); ++ offset += 0x10; ++ } ++ gr_def(ctx, offset + 0x250, 0x00000004); ++ gr_def(ctx, offset + 0x254, 0x00000014); ++ gr_def(ctx, offset + 0x258, 0x00000001); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ offset += 4; ++ gr_def(ctx, offset + 0x264, 0x00000002); ++ if (dev_priv->chipset >= 0xa0) ++ offset += 8; ++ gr_def(ctx, offset + 0x270, 0x00000001); ++ gr_def(ctx, offset + 0x278, 0x00000002); ++ gr_def(ctx, offset + 0x27c, 0x00001000); ++ if (dev_priv->chipset == 0x50) ++ offset -= 0xc; ++ else { ++ gr_def(ctx, offset + 0x280, 0x00000e00); ++ gr_def(ctx, offset + 0x284, 0x00001000); ++ gr_def(ctx, offset + 0x288, 0x00001e00); ++ } ++ gr_def(ctx, offset + 0x290, 0x00000001); ++ gr_def(ctx, offset + 0x294, 0x00000001); ++ gr_def(ctx, offset + 0x298, 0x00000001); ++ gr_def(ctx, offset + 0x29c, 0x00000001); ++ gr_def(ctx, offset + 0x2a0, 0x00000001); ++ gr_def(ctx, offset + 0x2b0, 0x00000200); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ gr_def(ctx, offset + 0x2b4, 0x00000200); ++ offset += 4; ++ } ++ if (dev_priv->chipset < 0xa0) { ++ gr_def(ctx, offset + 0x2b8, 0x00000001); ++ gr_def(ctx, offset + 0x2bc, 0x00000070); ++ gr_def(ctx, offset + 0x2c0, 0x00000080); ++ gr_def(ctx, offset + 0x2cc, 0x00000001); ++ gr_def(ctx, offset + 0x2d0, 0x00000070); ++ gr_def(ctx, offset + 0x2d4, 0x00000080); ++ } else { ++ gr_def(ctx, offset + 0x2b8, 0x00000001); ++ gr_def(ctx, offset + 0x2bc, 0x000000f0); ++ gr_def(ctx, offset + 0x2c0, 0x000000ff); ++ gr_def(ctx, offset + 0x2cc, 0x00000001); ++ gr_def(ctx, offset + 0x2d0, 0x000000f0); ++ gr_def(ctx, offset + 0x2d4, 0x000000ff); ++ gr_def(ctx, offset + 0x2dc, 0x00000009); ++ offset += 4; ++ } ++ gr_def(ctx, offset + 0x2e4, 0x00000001); ++ gr_def(ctx, offset + 0x2e8, 0x000000cf); ++ gr_def(ctx, offset + 0x2f0, 0x00000001); ++ gr_def(ctx, offset + 0x300, 0x000000cf); ++ gr_def(ctx, offset + 0x308, 0x00000002); ++ gr_def(ctx, offset + 0x310, 0x00000001); ++ gr_def(ctx, offset + 0x318, 0x00000001); ++ gr_def(ctx, offset + 0x320, 0x000000cf); ++ gr_def(ctx, offset + 0x324, 0x000000cf); ++ gr_def(ctx, offset + 0x328, 0x00000001); ++ ++ /* 6000? */ ++ if (dev_priv->chipset == 0x50) ++ cp_ctx(ctx, 0x4063e0, 0x1); ++ ++ /* 6800: M2MF */ ++ if (dev_priv->chipset < 0x90) { ++ cp_ctx(ctx, 0x406814, 0x2b); ++ gr_def(ctx, 0x406818, 0x00000f80); ++ gr_def(ctx, 0x406860, 0x007f0080); ++ gr_def(ctx, 0x40689c, 0x007f0080); ++ } else { ++ cp_ctx(ctx, 0x406814, 0x4); ++ if (dev_priv->chipset == 0x98) ++ gr_def(ctx, 0x406818, 0x00000f80); ++ else ++ gr_def(ctx, 0x406818, 0x00001f80); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ gr_def(ctx, 0x40681c, 0x00000030); ++ cp_ctx(ctx, 0x406830, 0x3); ++ } ++ ++ /* 7000: per-ROP group state */ ++ for (i = 0; i < 8; i++) { ++ if (units & (1<<(i+16))) { ++ cp_ctx(ctx, 0x407000 + (i<<8), 3); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, 0x407000 + (i<<8), 0x1b74f820); ++ else if (dev_priv->chipset != 0xa5) ++ gr_def(ctx, 0x407000 + (i<<8), 0x3b74f821); ++ else ++ gr_def(ctx, 0x407000 + (i<<8), 0x7b74f821); ++ gr_def(ctx, 0x407004 + (i<<8), 0x89058001); ++ ++ if (dev_priv->chipset == 0x50) { ++ cp_ctx(ctx, 0x407010 + (i<<8), 1); ++ } else if (dev_priv->chipset < 0xa0) { ++ cp_ctx(ctx, 0x407010 + (i<<8), 2); ++ gr_def(ctx, 0x407010 + (i<<8), 0x00001000); ++ gr_def(ctx, 0x407014 + (i<<8), 0x0000001f); ++ } else { ++ cp_ctx(ctx, 0x407010 + (i<<8), 3); ++ gr_def(ctx, 0x407010 + (i<<8), 0x00001000); ++ if (dev_priv->chipset != 0xa5) ++ gr_def(ctx, 0x407014 + (i<<8), 0x000000ff); ++ else ++ gr_def(ctx, 0x407014 + (i<<8), 0x000001ff); ++ } ++ ++ cp_ctx(ctx, 0x407080 + (i<<8), 4); ++ if (dev_priv->chipset != 0xa5) ++ gr_def(ctx, 0x407080 + (i<<8), 0x027c10fa); ++ else ++ gr_def(ctx, 0x407080 + (i<<8), 0x827c10fa); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, 0x407084 + (i<<8), 0x000000c0); ++ else ++ gr_def(ctx, 0x407084 + (i<<8), 0x400000c0); ++ gr_def(ctx, 0x407088 + (i<<8), 0xb7892080); ++ ++ if (dev_priv->chipset < 0xa0) ++ cp_ctx(ctx, 0x407094 + (i<<8), 1); ++ else if (dev_priv->chipset <= 0xa0 || dev_priv->chipset >= 0xaa) ++ cp_ctx(ctx, 0x407094 + (i<<8), 3); ++ else { ++ cp_ctx(ctx, 0x407094 + (i<<8), 4); ++ gr_def(ctx, 0x4070a0 + (i<<8), 1); ++ } ++ } ++ } ++ ++ cp_ctx(ctx, 0x407c00, 0x3); ++ if (dev_priv->chipset < 0x90) ++ gr_def(ctx, 0x407c00, 0x00010040); ++ else if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, 0x407c00, 0x00390040); ++ else ++ gr_def(ctx, 0x407c00, 0x003d0040); ++ gr_def(ctx, 0x407c08, 0x00000022); ++ if (dev_priv->chipset >= 0xa0) { ++ cp_ctx(ctx, 0x407c10, 0x3); ++ cp_ctx(ctx, 0x407c20, 0x1); ++ cp_ctx(ctx, 0x407c2c, 0x1); ++ } ++ ++ if (dev_priv->chipset < 0xa0) { ++ cp_ctx(ctx, 0x407d00, 0x9); ++ } else { ++ cp_ctx(ctx, 0x407d00, 0x15); ++ } ++ if (dev_priv->chipset == 0x98) ++ gr_def(ctx, 0x407d08, 0x00380040); ++ else { ++ if (dev_priv->chipset < 0x90) ++ gr_def(ctx, 0x407d08, 0x00010040); ++ else if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, 0x407d08, 0x00390040); ++ else ++ gr_def(ctx, 0x407d08, 0x003d0040); ++ gr_def(ctx, 0x407d0c, 0x00000022); ++ } ++ ++ /* 8000+: per-TP state */ ++ for (i = 0; i < 10; i++) { ++ if (units & (1<chipset < 0xa0) ++ base = 0x408000 + (i<<12); ++ else ++ base = 0x408000 + (i<<11); ++ if (dev_priv->chipset < 0xa0) ++ offset = base + 0xc00; ++ else ++ offset = base + 0x80; ++ cp_ctx(ctx, offset + 0x00, 1); ++ gr_def(ctx, offset + 0x00, 0x0000ff0a); ++ cp_ctx(ctx, offset + 0x08, 1); ++ ++ /* per-MP state */ ++ for (j = 0; j < (dev_priv->chipset < 0xa0 ? 2 : 4); j++) { ++ if (!(units & (1 << (j+24)))) continue; ++ if (dev_priv->chipset < 0xa0) ++ offset = base + 0x200 + (j<<7); ++ else ++ offset = base + 0x100 + (j<<7); ++ cp_ctx(ctx, offset, 0x20); ++ gr_def(ctx, offset + 0x00, 0x01800000); ++ gr_def(ctx, offset + 0x04, 0x00160000); ++ gr_def(ctx, offset + 0x08, 0x01800000); ++ gr_def(ctx, offset + 0x18, 0x0003ffff); ++ switch (dev_priv->chipset) { ++ case 0x50: ++ gr_def(ctx, offset + 0x1c, 0x00080000); ++ break; ++ case 0x84: ++ gr_def(ctx, offset + 0x1c, 0x00880000); ++ break; ++ case 0x86: ++ gr_def(ctx, offset + 0x1c, 0x008c0000); ++ break; ++ case 0x92: ++ case 0x96: ++ case 0x98: ++ gr_def(ctx, offset + 0x1c, 0x118c0000); ++ break; ++ case 0x94: ++ gr_def(ctx, offset + 0x1c, 0x10880000); ++ break; ++ case 0xa0: ++ case 0xa5: ++ gr_def(ctx, offset + 0x1c, 0x310c0000); ++ break; ++ case 0xa3: ++ case 0xa8: ++ case 0xaa: ++ case 0xac: ++ gr_def(ctx, offset + 0x1c, 0x300c0000); ++ break; ++ } ++ gr_def(ctx, offset + 0x40, 0x00010401); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, offset + 0x48, 0x00000040); ++ else ++ gr_def(ctx, offset + 0x48, 0x00000078); ++ gr_def(ctx, offset + 0x50, 0x000000bf); ++ gr_def(ctx, offset + 0x58, 0x00001210); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, offset + 0x5c, 0x00000080); ++ else ++ gr_def(ctx, offset + 0x5c, 0x08000080); ++ if (dev_priv->chipset >= 0xa0) ++ gr_def(ctx, offset + 0x68, 0x0000003e); ++ } ++ ++ if (dev_priv->chipset < 0xa0) ++ cp_ctx(ctx, base + 0x300, 0x4); ++ else ++ cp_ctx(ctx, base + 0x300, 0x5); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, base + 0x304, 0x00007070); ++ else if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, base + 0x304, 0x00027070); ++ else if (dev_priv->chipset <= 0xa0 || dev_priv->chipset >= 0xaa) ++ gr_def(ctx, base + 0x304, 0x01127070); ++ else ++ gr_def(ctx, base + 0x304, 0x05127070); ++ ++ if (dev_priv->chipset < 0xa0) ++ cp_ctx(ctx, base + 0x318, 1); ++ else ++ cp_ctx(ctx, base + 0x320, 1); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, base + 0x318, 0x0003ffff); ++ else if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, base + 0x318, 0x03ffffff); ++ else ++ gr_def(ctx, base + 0x320, 0x07ffffff); ++ ++ if (dev_priv->chipset < 0xa0) ++ cp_ctx(ctx, base + 0x324, 5); ++ else ++ cp_ctx(ctx, base + 0x328, 4); ++ ++ if (dev_priv->chipset < 0xa0) { ++ cp_ctx(ctx, base + 0x340, 9); ++ offset = base + 0x340; ++ } else if (dev_priv->chipset <= 0xa0 || dev_priv->chipset >= 0xaa) { ++ cp_ctx(ctx, base + 0x33c, 0xb); ++ offset = base + 0x344; ++ } else { ++ cp_ctx(ctx, base + 0x33c, 0xd); ++ offset = base + 0x344; ++ } ++ gr_def(ctx, offset + 0x0, 0x00120407); ++ gr_def(ctx, offset + 0x4, 0x05091507); ++ if (dev_priv->chipset == 0x84) ++ gr_def(ctx, offset + 0x8, 0x05100202); ++ else ++ gr_def(ctx, offset + 0x8, 0x05010202); ++ gr_def(ctx, offset + 0xc, 0x00030201); ++ if (dev_priv->chipset == 0xa3) ++ cp_ctx(ctx, base + 0x36c, 1); ++ ++ cp_ctx(ctx, base + 0x400, 2); ++ gr_def(ctx, base + 0x404, 0x00000040); ++ cp_ctx(ctx, base + 0x40c, 2); ++ gr_def(ctx, base + 0x40c, 0x0d0c0b0a); ++ gr_def(ctx, base + 0x410, 0x00141210); ++ ++ if (dev_priv->chipset < 0xa0) ++ offset = base + 0x800; ++ else ++ offset = base + 0x500; ++ cp_ctx(ctx, offset, 6); ++ gr_def(ctx, offset + 0x0, 0x000001f0); ++ gr_def(ctx, offset + 0x4, 0x00000001); ++ gr_def(ctx, offset + 0x8, 0x00000003); ++ if (dev_priv->chipset == 0x50 || dev_priv->chipset >= 0xaa) ++ gr_def(ctx, offset + 0xc, 0x00008000); ++ gr_def(ctx, offset + 0x14, 0x00039e00); ++ cp_ctx(ctx, offset + 0x1c, 2); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, offset + 0x1c, 0x00000040); ++ else ++ gr_def(ctx, offset + 0x1c, 0x00000100); ++ gr_def(ctx, offset + 0x20, 0x00003800); ++ ++ if (dev_priv->chipset >= 0xa0) { ++ cp_ctx(ctx, base + 0x54c, 2); ++ if (dev_priv->chipset <= 0xa0 || dev_priv->chipset >= 0xaa) ++ gr_def(ctx, base + 0x54c, 0x003fe006); ++ else ++ gr_def(ctx, base + 0x54c, 0x003fe007); ++ gr_def(ctx, base + 0x550, 0x003fe000); ++ } ++ ++ if (dev_priv->chipset < 0xa0) ++ offset = base + 0xa00; ++ else ++ offset = base + 0x680; ++ cp_ctx(ctx, offset, 1); ++ gr_def(ctx, offset, 0x00404040); ++ ++ if (dev_priv->chipset < 0xa0) ++ offset = base + 0xe00; ++ else ++ offset = base + 0x700; ++ cp_ctx(ctx, offset, 2); ++ if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, offset, 0x0077f005); ++ else if (dev_priv->chipset == 0xa5) ++ gr_def(ctx, offset, 0x6cf7f007); ++ else if (dev_priv->chipset == 0xa8) ++ gr_def(ctx, offset, 0x6cfff007); ++ else if (dev_priv->chipset == 0xac) ++ gr_def(ctx, offset, 0x0cfff007); ++ else ++ gr_def(ctx, offset, 0x0cf7f007); ++ if (dev_priv->chipset == 0x50) ++ gr_def(ctx, offset + 0x4, 0x00007fff); ++ else if (dev_priv->chipset < 0xa0) ++ gr_def(ctx, offset + 0x4, 0x003f7fff); ++ else ++ gr_def(ctx, offset + 0x4, 0x02bf7fff); ++ cp_ctx(ctx, offset + 0x2c, 1); ++ if (dev_priv->chipset == 0x50) { ++ cp_ctx(ctx, offset + 0x50, 9); ++ gr_def(ctx, offset + 0x54, 0x000003ff); ++ gr_def(ctx, offset + 0x58, 0x00000003); ++ gr_def(ctx, offset + 0x5c, 0x00000003); ++ gr_def(ctx, offset + 0x60, 0x000001ff); ++ gr_def(ctx, offset + 0x64, 0x0000001f); ++ gr_def(ctx, offset + 0x68, 0x0000000f); ++ gr_def(ctx, offset + 0x6c, 0x0000000f); ++ } else if(dev_priv->chipset < 0xa0) { ++ cp_ctx(ctx, offset + 0x50, 1); ++ cp_ctx(ctx, offset + 0x70, 1); ++ } else { ++ cp_ctx(ctx, offset + 0x50, 1); ++ cp_ctx(ctx, offset + 0x60, 5); ++ } ++ } ++ } ++} ++ ++/* ++ * xfer areas. These are a pain. ++ * ++ * There are 2 xfer areas: the first one is big and contains all sorts of ++ * stuff, the second is small and contains some per-TP context. ++ * ++ * Each area is split into 8 "strands". The areas, when saved to grctx, ++ * are made of 8-word blocks. Each block contains a single word from ++ * each strand. The strands are independent of each other, their ++ * addresses are unrelated to each other, and data in them is closely ++ * packed together. The strand layout varies a bit between cards: here ++ * and there, a single word is thrown out in the middle and the whole ++ * strand is offset by a bit from corresponding one on another chipset. ++ * For this reason, addresses of stuff in strands are almost useless. ++ * Knowing sequence of stuff and size of gaps between them is much more ++ * useful, and that's how we build the strands in our generator. ++ * ++ * NVA0 takes this mess to a whole new level by cutting the old strands ++ * into a few dozen pieces [known as genes], rearranging them randomly, ++ * and putting them back together to make new strands. Hopefully these ++ * genes correspond more or less directly to the same PGRAPH subunits ++ * as in 400040 register. ++ * ++ * The most common value in default context is 0, and when the genes ++ * are separated by 0's, gene bounduaries are quite speculative... ++ * some of them can be clearly deduced, others can be guessed, and yet ++ * others won't be resolved without figuring out the real meaning of ++ * given ctxval. For the same reason, ending point of each strand ++ * is unknown. Except for strand 0, which is the longest strand and ++ * its end corresponds to end of the whole xfer. ++ * ++ * An unsolved mystery is the seek instruction: it takes an argument ++ * in bits 8-18, and that argument is clearly the place in strands to ++ * seek to... but the offsets don't seem to correspond to offsets as ++ * seen in grctx. Perhaps there's another, real, not randomly-changing ++ * addressing in strands, and the xfer insn just happens to skip over ++ * the unused bits? NV10-NV30 PIPE comes to mind... ++ * ++ * As far as I know, there's no way to access the xfer areas directly ++ * without the help of ctxprog. ++ */ ++ ++static inline void ++xf_emit(struct nouveau_grctx *ctx, int num, uint32_t val) { ++ int i; ++ if (val && ctx->mode == NOUVEAU_GRCTX_VALS) ++ for (i = 0; i < num; i++) ++ nv_wo32(ctx->dev, ctx->data, ctx->ctxvals_pos + (i << 3), val); ++ ctx->ctxvals_pos += num << 3; ++} ++ ++/* Gene declarations... */ ++ ++static void nv50_graph_construct_gene_m2mf(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk1(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk2(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk3(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk4(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk5(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk6(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk7(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk8(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk9(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_unk10(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_gene_ropc(struct nouveau_grctx *ctx); ++static void nv50_graph_construct_xfer_tp(struct nouveau_grctx *ctx); ++ ++static void ++nv50_graph_construct_xfer1(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int i; ++ int offset; ++ int size = 0; ++ uint32_t units = nv_rd32 (ctx->dev, 0x1540); ++ ++ offset = (ctx->ctxvals_pos+0x3f)&~0x3f; ++ ctx->ctxvals_base = offset; ++ ++ if (dev_priv->chipset < 0xa0) { ++ /* Strand 0 */ ++ ctx->ctxvals_pos = offset; ++ switch (dev_priv->chipset) { ++ case 0x50: ++ xf_emit(ctx, 0x99, 0); ++ break; ++ case 0x84: ++ case 0x86: ++ xf_emit(ctx, 0x384, 0); ++ break; ++ case 0x92: ++ case 0x94: ++ case 0x96: ++ case 0x98: ++ xf_emit(ctx, 0x380, 0); ++ break; ++ } ++ nv50_graph_construct_gene_m2mf (ctx); ++ switch (dev_priv->chipset) { ++ case 0x50: ++ case 0x84: ++ case 0x86: ++ case 0x98: ++ xf_emit(ctx, 0x4c4, 0); ++ break; ++ case 0x92: ++ case 0x94: ++ case 0x96: ++ xf_emit(ctx, 0x984, 0); ++ break; ++ } ++ nv50_graph_construct_gene_unk5(ctx); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 0xa, 0); ++ else ++ xf_emit(ctx, 0xb, 0); ++ nv50_graph_construct_gene_unk4(ctx); ++ nv50_graph_construct_gene_unk3(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 1 */ ++ ctx->ctxvals_pos = offset + 0x1; ++ nv50_graph_construct_gene_unk6(ctx); ++ nv50_graph_construct_gene_unk7(ctx); ++ nv50_graph_construct_gene_unk8(ctx); ++ switch (dev_priv->chipset) { ++ case 0x50: ++ case 0x92: ++ xf_emit(ctx, 0xfb, 0); ++ break; ++ case 0x84: ++ xf_emit(ctx, 0xd3, 0); ++ break; ++ case 0x94: ++ case 0x96: ++ xf_emit(ctx, 0xab, 0); ++ break; ++ case 0x86: ++ case 0x98: ++ xf_emit(ctx, 0x6b, 0); ++ break; ++ } ++ xf_emit(ctx, 2, 0x4e3bfdf); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 0xb, 0); ++ xf_emit(ctx, 2, 0x4e3bfdf); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 2 */ ++ ctx->ctxvals_pos = offset + 0x2; ++ switch (dev_priv->chipset) { ++ case 0x50: ++ case 0x92: ++ xf_emit(ctx, 0xa80, 0); ++ break; ++ case 0x84: ++ xf_emit(ctx, 0xa7e, 0); ++ break; ++ case 0x94: ++ case 0x96: ++ xf_emit(ctx, 0xa7c, 0); ++ break; ++ case 0x86: ++ case 0x98: ++ xf_emit(ctx, 0xa7a, 0); ++ break; ++ } ++ xf_emit(ctx, 1, 0x3fffff); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x1fff); ++ xf_emit(ctx, 0xe, 0); ++ nv50_graph_construct_gene_unk9(ctx); ++ nv50_graph_construct_gene_unk2(ctx); ++ nv50_graph_construct_gene_unk1(ctx); ++ nv50_graph_construct_gene_unk10(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 3: per-ROP group state */ ++ ctx->ctxvals_pos = offset + 3; ++ for (i = 0; i < 6; i++) ++ if (units & (1 << (i + 16))) ++ nv50_graph_construct_gene_ropc(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strands 4-7: per-TP state */ ++ for (i = 0; i < 4; i++) { ++ ctx->ctxvals_pos = offset + 4 + i; ++ if (units & (1 << (2 * i))) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << (2 * i + 1))) ++ nv50_graph_construct_xfer_tp(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ } ++ } else { ++ /* Strand 0 */ ++ ctx->ctxvals_pos = offset; ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0x385, 0); ++ else ++ xf_emit(ctx, 0x384, 0); ++ nv50_graph_construct_gene_m2mf(ctx); ++ xf_emit(ctx, 0x950, 0); ++ nv50_graph_construct_gene_unk10(ctx); ++ xf_emit(ctx, 1, 0x0fac6881); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 3, 0); ++ } ++ nv50_graph_construct_gene_unk8(ctx); ++ if (dev_priv->chipset == 0xa0) ++ xf_emit(ctx, 0x189, 0); ++ else if (dev_priv->chipset == 0xa3) ++ xf_emit(ctx, 0xd5, 0); ++ else if (dev_priv->chipset == 0xa5) ++ xf_emit(ctx, 0x99, 0); ++ else if (dev_priv->chipset == 0xaa) ++ xf_emit(ctx, 0x65, 0); ++ else ++ xf_emit(ctx, 0x6d, 0); ++ nv50_graph_construct_gene_unk9(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 1 */ ++ ctx->ctxvals_pos = offset + 1; ++ nv50_graph_construct_gene_unk1(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 2 */ ++ ctx->ctxvals_pos = offset + 2; ++ if (dev_priv->chipset == 0xa0) { ++ nv50_graph_construct_gene_unk2(ctx); ++ } ++ xf_emit(ctx, 0x36, 0); ++ nv50_graph_construct_gene_unk5(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 3 */ ++ ctx->ctxvals_pos = offset + 3; ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ nv50_graph_construct_gene_unk6(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 4 */ ++ ctx->ctxvals_pos = offset + 4; ++ if (dev_priv->chipset == 0xa0) ++ xf_emit(ctx, 0xa80, 0); ++ else if (dev_priv->chipset == 0xa3) ++ xf_emit(ctx, 0xa7c, 0); ++ else ++ xf_emit(ctx, 0xa7a, 0); ++ xf_emit(ctx, 1, 0x3fffff); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x1fff); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 5 */ ++ ctx->ctxvals_pos = offset + 5; ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 0xb, 0); ++ xf_emit(ctx, 2, 0x4e3bfdf); ++ xf_emit(ctx, 3, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 2, 0x4e3bfdf); ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 0); ++ for (i = 0; i < 8; i++) ++ if (units & (1<<(i+16))) ++ nv50_graph_construct_gene_ropc(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 6 */ ++ ctx->ctxvals_pos = offset + 6; ++ nv50_graph_construct_gene_unk3(ctx); ++ xf_emit(ctx, 0xb, 0); ++ nv50_graph_construct_gene_unk4(ctx); ++ nv50_graph_construct_gene_unk7(ctx); ++ if (units & (1 << 0)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 1)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 2)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 3)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 7 */ ++ ctx->ctxvals_pos = offset + 7; ++ if (dev_priv->chipset == 0xa0) { ++ if (units & (1 << 4)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 5)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 6)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 7)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 8)) ++ nv50_graph_construct_xfer_tp(ctx); ++ if (units & (1 << 9)) ++ nv50_graph_construct_xfer_tp(ctx); ++ } else { ++ nv50_graph_construct_gene_unk2(ctx); ++ } ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ } ++ ++ ctx->ctxvals_pos = offset + size * 8; ++ ctx->ctxvals_pos = (ctx->ctxvals_pos+0x3f)&~0x3f; ++ cp_lsr (ctx, offset); ++ cp_out (ctx, CP_SET_XFER_POINTER); ++ cp_lsr (ctx, size); ++ cp_out (ctx, CP_SEEK_1); ++ cp_out (ctx, CP_XFER_1); ++ cp_wait(ctx, XFER, BUSY); ++} ++ ++/* ++ * non-trivial demagiced parts of ctx init go here ++ */ ++ ++static void ++nv50_graph_construct_gene_m2mf(struct nouveau_grctx *ctx) ++{ ++ /* m2mf state */ ++ xf_emit (ctx, 1, 0); /* DMA_NOTIFY instance >> 4 */ ++ xf_emit (ctx, 1, 0); /* DMA_BUFFER_IN instance >> 4 */ ++ xf_emit (ctx, 1, 0); /* DMA_BUFFER_OUT instance >> 4 */ ++ xf_emit (ctx, 1, 0); /* OFFSET_IN */ ++ xf_emit (ctx, 1, 0); /* OFFSET_OUT */ ++ xf_emit (ctx, 1, 0); /* PITCH_IN */ ++ xf_emit (ctx, 1, 0); /* PITCH_OUT */ ++ xf_emit (ctx, 1, 0); /* LINE_LENGTH */ ++ xf_emit (ctx, 1, 0); /* LINE_COUNT */ ++ xf_emit (ctx, 1, 0x21); /* FORMAT: bits 0-4 INPUT_INC, bits 5-9 OUTPUT_INC */ ++ xf_emit (ctx, 1, 1); /* LINEAR_IN */ ++ xf_emit (ctx, 1, 0x2); /* TILING_MODE_IN: bits 0-2 y tiling, bits 3-5 z tiling */ ++ xf_emit (ctx, 1, 0x100); /* TILING_PITCH_IN */ ++ xf_emit (ctx, 1, 0x100); /* TILING_HEIGHT_IN */ ++ xf_emit (ctx, 1, 1); /* TILING_DEPTH_IN */ ++ xf_emit (ctx, 1, 0); /* TILING_POSITION_IN_Z */ ++ xf_emit (ctx, 1, 0); /* TILING_POSITION_IN */ ++ xf_emit (ctx, 1, 1); /* LINEAR_OUT */ ++ xf_emit (ctx, 1, 0x2); /* TILING_MODE_OUT: bits 0-2 y tiling, bits 3-5 z tiling */ ++ xf_emit (ctx, 1, 0x100); /* TILING_PITCH_OUT */ ++ xf_emit (ctx, 1, 0x100); /* TILING_HEIGHT_OUT */ ++ xf_emit (ctx, 1, 1); /* TILING_DEPTH_OUT */ ++ xf_emit (ctx, 1, 0); /* TILING_POSITION_OUT_Z */ ++ xf_emit (ctx, 1, 0); /* TILING_POSITION_OUT */ ++ xf_emit (ctx, 1, 0); /* OFFSET_IN_HIGH */ ++ xf_emit (ctx, 1, 0); /* OFFSET_OUT_HIGH */ ++} ++ ++static void ++nv50_graph_construct_gene_unk1(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* end of area 2 on pre-NVA0, area 1 on NVAx */ ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x80); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0x80c14); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 1, 0x3ff); ++ else ++ xf_emit(ctx, 1, 0x7ff); ++ switch (dev_priv->chipset) { ++ case 0x50: ++ case 0x86: ++ case 0x98: ++ case 0xaa: ++ case 0xac: ++ xf_emit(ctx, 0x542, 0); ++ break; ++ case 0x84: ++ case 0x92: ++ case 0x94: ++ case 0x96: ++ xf_emit(ctx, 0x942, 0); ++ break; ++ case 0xa0: ++ case 0xa3: ++ xf_emit(ctx, 0x2042, 0); ++ break; ++ case 0xa5: ++ case 0xa8: ++ xf_emit(ctx, 0x842, 0); ++ break; ++ } ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x80); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x27); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x26); ++ xf_emit(ctx, 3, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk10(struct nouveau_grctx *ctx) ++{ ++ /* end of area 2 on pre-NVA0, area 1 on NVAx */ ++ xf_emit(ctx, 0x10, 0x04000000); ++ xf_emit(ctx, 0x24, 0); ++ xf_emit(ctx, 2, 0x04e3bfdf); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x1fe21); ++} ++ ++static void ++nv50_graph_construct_gene_unk2(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* middle of area 2 on pre-NVA0, beginning of area 2 on NVA0, area 7 on >NVA0 */ ++ if (dev_priv->chipset != 0x50) { ++ xf_emit(ctx, 5, 0); ++ xf_emit(ctx, 1, 0x80c14); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x804); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0x8100c12); ++ } ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x10); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 3, 0); ++ else ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x804); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x1a); ++ if (dev_priv->chipset != 0x50) ++ xf_emit(ctx, 1, 0x7f); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x80c14); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 6, 0); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 1, 0x3ff); ++ else ++ xf_emit(ctx, 1, 0x7ff); ++ xf_emit(ctx, 1, 0x80c14); ++ xf_emit(ctx, 0x38, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 0x38, 0); ++ xf_emit(ctx, 2, 0x88); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 0x16, 0); ++ xf_emit(ctx, 1, 0x26); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x3f800000); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 4, 0); ++ else ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x1a); ++ xf_emit(ctx, 1, 0x10); ++ if (dev_priv->chipset != 0x50) ++ xf_emit(ctx, 0x28, 0); ++ else ++ xf_emit(ctx, 0x25, 0); ++ xf_emit(ctx, 1, 0x52); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x26); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x1a); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x00ffff00); ++ xf_emit(ctx, 1, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk3(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* end of area 0 on pre-NVA0, beginning of area 6 on NVAx */ ++ xf_emit(ctx, 1, 0x3f); ++ xf_emit(ctx, 0xa, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 0x04000000); ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 4); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 0x10, 0); ++ else ++ xf_emit(ctx, 0x11, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x1001); ++ xf_emit(ctx, 4, 0xffff); ++ xf_emit(ctx, 0x20, 0); ++ xf_emit(ctx, 0x10, 0x3f800000); ++ xf_emit(ctx, 1, 0x10); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 1, 0); ++ else ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 2, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk4(struct nouveau_grctx *ctx) ++{ ++ /* middle of area 0 on pre-NVA0, middle of area 6 on NVAx */ ++ xf_emit(ctx, 2, 0x04000000); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x80); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x80); ++ xf_emit(ctx, 1, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk5(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* middle of area 0 on pre-NVA0 [after m2mf], end of area 2 on NVAx */ ++ xf_emit(ctx, 2, 4); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0x1c4d, 0); ++ else ++ xf_emit(ctx, 0x1c4b, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0x8100c12); ++ if (dev_priv->chipset != 0x50) ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x80c14); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0x80c14); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 1, 0x27); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x3c1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x16, 0); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 1, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk6(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* beginning of area 1 on pre-NVA0 [after m2mf], area 3 on NVAx */ ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0xf); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 8, 0); ++ else ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x20); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0x11, 0); ++ else if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 0xf, 0); ++ else ++ xf_emit(ctx, 0xe, 0); ++ xf_emit(ctx, 1, 0x1a); ++ xf_emit(ctx, 0xd, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 8); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 1, 0x3ff); ++ else ++ xf_emit(ctx, 1, 0x7ff); ++ if (dev_priv->chipset == 0xa8) ++ xf_emit(ctx, 1, 0x1e00); ++ xf_emit(ctx, 0xc, 0); ++ xf_emit(ctx, 1, 0xf); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 0x125, 0); ++ else if (dev_priv->chipset < 0xa0) ++ xf_emit(ctx, 0x126, 0); ++ else if (dev_priv->chipset == 0xa0 || dev_priv->chipset >= 0xaa) ++ xf_emit(ctx, 0x124, 0); ++ else ++ xf_emit(ctx, 0x1f7, 0); ++ xf_emit(ctx, 1, 0xf); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 3, 0); ++ else ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0xa1, 0); ++ else ++ xf_emit(ctx, 0x5a, 0); ++ xf_emit(ctx, 1, 0xf); ++ if (dev_priv->chipset < 0xa0) ++ xf_emit(ctx, 0x834, 0); ++ else if (dev_priv->chipset == 0xa0) ++ xf_emit(ctx, 0x1873, 0); ++ else if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0x8ba, 0); ++ else ++ xf_emit(ctx, 0x833, 0); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 0xf, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk7(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* middle of area 1 on pre-NVA0 [after m2mf], middle of area 6 on NVAx */ ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 2, 1); ++ else ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0x100); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 8); ++ xf_emit(ctx, 5, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 3, 1); ++ xf_emit(ctx, 1, 0xcf); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 6, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 3, 1); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x15); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x4444480); ++ xf_emit(ctx, 0x37, 0); ++} ++ ++static void ++nv50_graph_construct_gene_unk8(struct nouveau_grctx *ctx) ++{ ++ /* middle of area 1 on pre-NVA0 [after m2mf], middle of area 0 on NVAx */ ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x100); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x10001); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x10001); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x10001); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 2); ++} ++ ++static void ++nv50_graph_construct_gene_unk9(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ /* middle of area 2 on pre-NVA0 [after m2mf], end of area 0 on NVAx */ ++ xf_emit(ctx, 1, 0x3f800000); ++ xf_emit(ctx, 6, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0x1a); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x12, 0); ++ xf_emit(ctx, 1, 0x00ffff00); ++ xf_emit(ctx, 6, 0); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 0xf, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 3); ++ else if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 0x04000000); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 5); ++ xf_emit(ctx, 1, 0x52); ++ if (dev_priv->chipset == 0x50) { ++ xf_emit(ctx, 0x13, 0); ++ } else { ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0x11, 0); ++ else ++ xf_emit(ctx, 0x10, 0); ++ } ++ xf_emit(ctx, 0x10, 0x3f800000); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 0x26, 0); ++ xf_emit(ctx, 1, 0x8100c12); ++ xf_emit(ctx, 1, 5); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 4, 0xffff); ++ if (dev_priv->chipset != 0x50) ++ xf_emit(ctx, 1, 3); ++ if (dev_priv->chipset < 0xa0) ++ xf_emit(ctx, 0x1f, 0); ++ else if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0xc, 0); ++ else ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x00ffff00); ++ xf_emit(ctx, 1, 0x1a); ++ if (dev_priv->chipset != 0x50) { ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 3); ++ } ++ if (dev_priv->chipset < 0xa0) ++ xf_emit(ctx, 0x26, 0); ++ else ++ xf_emit(ctx, 0x3c, 0); ++ xf_emit(ctx, 1, 0x102); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 4, 4); ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 1, 0x3ff); ++ else ++ xf_emit(ctx, 1, 0x7ff); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x102); ++ xf_emit(ctx, 9, 0); ++ xf_emit(ctx, 4, 4); ++ xf_emit(ctx, 0x2c, 0); ++} ++ ++static void ++nv50_graph_construct_gene_ropc(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int magic2; ++ if (dev_priv->chipset == 0x50) { ++ magic2 = 0x00003e60; ++ } else if (dev_priv->chipset <= 0xa0 || dev_priv->chipset >= 0xaa) { ++ magic2 = 0x001ffe67; ++ } else { ++ magic2 = 0x00087e67; ++ } ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, magic2); ++ xf_emit(ctx, 4, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 7, 0); ++ if (dev_priv->chipset >= 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 0x15); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 4, 0); ++ if (dev_priv->chipset == 0x86 || dev_priv->chipset == 0x92 || dev_priv->chipset == 0x98 || dev_priv->chipset >= 0xa0) { ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0x400); ++ xf_emit(ctx, 1, 0x300); ++ xf_emit(ctx, 1, 0x1001); ++ if (dev_priv->chipset != 0xa0) { ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 0); ++ else ++ xf_emit(ctx, 1, 0x15); ++ } ++ xf_emit(ctx, 3, 0); ++ } ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x13, 0); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 0x10, 0); ++ xf_emit(ctx, 0x10, 0x3f800000); ++ xf_emit(ctx, 0x19, 0); ++ xf_emit(ctx, 1, 0x10); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x3f); ++ xf_emit(ctx, 6, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset >= 0xa0) { ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x1001); ++ xf_emit(ctx, 0xb, 0); ++ } else { ++ xf_emit(ctx, 0xc, 0); ++ } ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x11); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 4, 0); ++ else ++ xf_emit(ctx, 6, 0); ++ xf_emit(ctx, 3, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, magic2); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 0x18, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 5, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x16, 0); ++ } else { ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 0x1b, 0); ++ else ++ xf_emit(ctx, 0x15, 0); ++ } ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 1); ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 4, 0); ++ else ++ xf_emit(ctx, 3, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 0x10, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 0x10, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 3, 0); ++ } ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x5b, 0); ++} ++ ++static void ++nv50_graph_construct_xfer_tp_x1(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int magic3; ++ if (dev_priv->chipset == 0x50) ++ magic3 = 0x1000; ++ else if (dev_priv->chipset == 0x86 || dev_priv->chipset == 0x98 || dev_priv->chipset >= 0xa8) ++ magic3 = 0x1e00; ++ else ++ magic3 = 0; ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 4); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0x24, 0); ++ else if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 0x14, 0); ++ else ++ xf_emit(ctx, 0x15, 0); ++ xf_emit(ctx, 2, 4); ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 1, 0x03020100); ++ else ++ xf_emit(ctx, 1, 0x00608080); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 2, 4); ++ xf_emit(ctx, 1, 0x80); ++ if (magic3) ++ xf_emit(ctx, 1, magic3); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 0x24, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0x80); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0x03020100); ++ xf_emit(ctx, 1, 3); ++ if (magic3) ++ xf_emit(ctx, 1, magic3); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 4); ++ if (dev_priv->chipset == 0x94 || dev_priv->chipset == 0x96) ++ xf_emit(ctx, 0x1024, 0); ++ else if (dev_priv->chipset < 0xa0) ++ xf_emit(ctx, 0xa24, 0); ++ else if (dev_priv->chipset == 0xa0 || dev_priv->chipset >= 0xaa) ++ xf_emit(ctx, 0x214, 0); ++ else ++ xf_emit(ctx, 0x414, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 2, 0); ++} ++ ++static void ++nv50_graph_construct_xfer_tp_x2(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int magic1, magic2; ++ if (dev_priv->chipset == 0x50) { ++ magic1 = 0x3ff; ++ magic2 = 0x00003e60; ++ } else if (dev_priv->chipset <= 0xa0 || dev_priv->chipset >= 0xaa) { ++ magic1 = 0x7ff; ++ magic2 = 0x001ffe67; ++ } else { ++ magic1 = 0x7ff; ++ magic2 = 0x00087e67; ++ } ++ xf_emit(ctx, 3, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0xc, 0); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 0xb, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 4, 0xffff); ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 5, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 1, 0); ++ } else if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0xa, 0); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 1, 2); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 0x18, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 1, 0); ++ } ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 3, 0xcf); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0xa, 0); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, magic2); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x11); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 2, 1); ++ else ++ xf_emit(ctx, 1, 1); ++ if(dev_priv->chipset == 0x50) ++ xf_emit(ctx, 1, 0); ++ else ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 5, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, magic1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x28, 0); ++ xf_emit(ctx, 8, 8); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 8, 0x400); ++ xf_emit(ctx, 8, 0x300); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x20); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 0x100); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x40); ++ xf_emit(ctx, 1, 0x100); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 4, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, magic2); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 9, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x400); ++ xf_emit(ctx, 1, 0x300); ++ xf_emit(ctx, 1, 0x1001); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 4, 0); ++ else ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 1, 0xf); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 0x15, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 3, 0); ++ } else ++ xf_emit(ctx, 0x17, 0); ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 1, 0x0fac6881); ++ xf_emit(ctx, 1, magic2); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 3, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 2, 1); ++ else ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 2, 0); ++ else if (dev_priv->chipset != 0x50) ++ xf_emit(ctx, 1, 0); ++} ++ ++static void ++nv50_graph_construct_xfer_tp_x3(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 2, 0); ++ else ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0x2a712488); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x4085c000); ++ xf_emit(ctx, 1, 0x40); ++ xf_emit(ctx, 1, 0x100); ++ xf_emit(ctx, 1, 0x10100); ++ xf_emit(ctx, 1, 0x02800000); ++} ++ ++static void ++nv50_graph_construct_xfer_tp_x4(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ xf_emit(ctx, 2, 0x04e3bfdf); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x00ffff00); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 2, 1); ++ else ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 0x00ffff00); ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0x30201000); ++ xf_emit(ctx, 1, 0x70605040); ++ xf_emit(ctx, 1, 0xb8a89888); ++ xf_emit(ctx, 1, 0xf8e8d8c8); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x1a); ++} ++ ++static void ++nv50_graph_construct_xfer_tp_x5(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 0xfac6881); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 2, 0); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0xb, 0); ++ else ++ xf_emit(ctx, 0xa, 0); ++ xf_emit(ctx, 8, 1); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0xfac6881); ++ xf_emit(ctx, 1, 0xf); ++ xf_emit(ctx, 7, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 1); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 6, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 6, 0); ++ } else { ++ xf_emit(ctx, 0xb, 0); ++ } ++} ++ ++static void ++nv50_graph_construct_xfer_tp(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ if (dev_priv->chipset < 0xa0) { ++ nv50_graph_construct_xfer_tp_x1(ctx); ++ nv50_graph_construct_xfer_tp_x2(ctx); ++ nv50_graph_construct_xfer_tp_x3(ctx); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 0xf, 0); ++ else ++ xf_emit(ctx, 0x12, 0); ++ nv50_graph_construct_xfer_tp_x4(ctx); ++ } else { ++ nv50_graph_construct_xfer_tp_x3(ctx); ++ if (dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 0xc, 0); ++ else ++ xf_emit(ctx, 0xa, 0); ++ nv50_graph_construct_xfer_tp_x2(ctx); ++ nv50_graph_construct_xfer_tp_x5(ctx); ++ nv50_graph_construct_xfer_tp_x4(ctx); ++ nv50_graph_construct_xfer_tp_x1(ctx); ++ } ++} ++ ++static void ++nv50_graph_construct_xfer_tp2(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int i, mpcnt; ++ if (dev_priv->chipset == 0x98 || dev_priv->chipset == 0xaa) ++ mpcnt = 1; ++ else if (dev_priv->chipset < 0xa0 || dev_priv->chipset >= 0xa8) ++ mpcnt = 2; ++ else ++ mpcnt = 3; ++ for (i = 0; i < mpcnt; i++) { ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x80); ++ xf_emit(ctx, 1, 0x80007004); ++ xf_emit(ctx, 1, 0x04000400); ++ if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 1, 0xc0); ++ xf_emit(ctx, 1, 0x1000); ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset == 0x86 || dev_priv->chipset == 0x98 || dev_priv->chipset >= 0xa8) { ++ xf_emit(ctx, 1, 0xe00); ++ xf_emit(ctx, 1, 0x1e00); ++ } ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 2, 0x1000); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 2); ++ if (dev_priv->chipset >= 0xaa) ++ xf_emit(ctx, 0xb, 0); ++ else if (dev_priv->chipset >= 0xa0) ++ xf_emit(ctx, 0xc, 0); ++ else ++ xf_emit(ctx, 0xa, 0); ++ } ++ xf_emit(ctx, 1, 0x08100c12); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset >= 0xa0) { ++ xf_emit(ctx, 1, 0x1fe21); ++ } ++ xf_emit(ctx, 5, 0); ++ xf_emit(ctx, 4, 0xffff); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 2, 0x10001); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 0x1fe21); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 4, 0); ++ xf_emit(ctx, 1, 0x08100c12); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 8, 0); ++ xf_emit(ctx, 1, 0xfac6881); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) ++ xf_emit(ctx, 1, 3); ++ xf_emit(ctx, 3, 0); ++ xf_emit(ctx, 1, 4); ++ xf_emit(ctx, 9, 0); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 2, 1); ++ xf_emit(ctx, 1, 2); ++ xf_emit(ctx, 3, 1); ++ xf_emit(ctx, 1, 0); ++ if (dev_priv->chipset > 0xa0 && dev_priv->chipset < 0xaa) { ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 0x10, 1); ++ xf_emit(ctx, 8, 2); ++ xf_emit(ctx, 0x18, 1); ++ xf_emit(ctx, 3, 0); ++ } ++ xf_emit(ctx, 1, 4); ++ if (dev_priv->chipset == 0x50) ++ xf_emit(ctx, 0x3a0, 0); ++ else if (dev_priv->chipset < 0x94) ++ xf_emit(ctx, 0x3a2, 0); ++ else if (dev_priv->chipset == 0x98 || dev_priv->chipset == 0xaa) ++ xf_emit(ctx, 0x39f, 0); ++ else ++ xf_emit(ctx, 0x3a3, 0); ++ xf_emit(ctx, 1, 0x11); ++ xf_emit(ctx, 1, 0); ++ xf_emit(ctx, 1, 1); ++ xf_emit(ctx, 0x2d, 0); ++} ++ ++static void ++nv50_graph_construct_xfer2(struct nouveau_grctx *ctx) ++{ ++ struct drm_nouveau_private *dev_priv = ctx->dev->dev_private; ++ int i; ++ uint32_t offset; ++ uint32_t units = nv_rd32 (ctx->dev, 0x1540); ++ int size = 0; ++ ++ offset = (ctx->ctxvals_pos+0x3f)&~0x3f; ++ ++ if (dev_priv->chipset < 0xa0) { ++ for (i = 0; i < 8; i++) { ++ ctx->ctxvals_pos = offset + i; ++ if (i == 0) ++ xf_emit(ctx, 1, 0x08100c12); ++ if (units & (1 << i)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ } ++ } else { ++ /* Strand 0: TPs 0, 1 */ ++ ctx->ctxvals_pos = offset; ++ xf_emit(ctx, 1, 0x08100c12); ++ if (units & (1 << 0)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if (units & (1 << 1)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 0: TPs 2, 3 */ ++ ctx->ctxvals_pos = offset + 1; ++ if (units & (1 << 2)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if (units & (1 << 3)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 0: TPs 4, 5, 6 */ ++ ctx->ctxvals_pos = offset + 2; ++ if (units & (1 << 4)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if (units & (1 << 5)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if (units & (1 << 6)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ ++ /* Strand 0: TPs 7, 8, 9 */ ++ ctx->ctxvals_pos = offset + 3; ++ if (units & (1 << 7)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if (units & (1 << 8)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if (units & (1 << 9)) ++ nv50_graph_construct_xfer_tp2(ctx); ++ if ((ctx->ctxvals_pos-offset)/8 > size) ++ size = (ctx->ctxvals_pos-offset)/8; ++ } ++ ctx->ctxvals_pos = offset + size * 8; ++ ctx->ctxvals_pos = (ctx->ctxvals_pos+0x3f)&~0x3f; ++ cp_lsr (ctx, offset); ++ cp_out (ctx, CP_SET_XFER_POINTER); ++ cp_lsr (ctx, size); ++ cp_out (ctx, CP_SEEK_2); ++ cp_out (ctx, CP_XFER_2); ++ cp_wait(ctx, XFER, BUSY); ++} +diff --git a/drivers/gpu/drm/nouveau/nv50_instmem.c b/drivers/gpu/drm/nouveau/nv50_instmem.c +index f0dc4e3..5f21df3 100644 +--- a/drivers/gpu/drm/nouveau/nv50_instmem.c ++++ b/drivers/gpu/drm/nouveau/nv50_instmem.c +@@ -63,9 +63,10 @@ nv50_instmem_init(struct drm_device *dev) + struct drm_nouveau_private *dev_priv = dev->dev_private; + struct nouveau_channel *chan; + uint32_t c_offset, c_size, c_ramfc, c_vmpd, c_base, pt_size; ++ uint32_t save_nv001700; ++ uint64_t v; + struct nv50_instmem_priv *priv; + int ret, i; +- uint32_t v, save_nv001700; + + priv = kzalloc(sizeof(*priv), GFP_KERNEL); + if (!priv) +@@ -76,17 +77,12 @@ nv50_instmem_init(struct drm_device *dev) + for (i = 0x1700; i <= 0x1710; i += 4) + priv->save1700[(i-0x1700)/4] = nv_rd32(dev, i); + +- if (dev_priv->chipset == 0xaa || dev_priv->chipset == 0xac) +- dev_priv->vram_sys_base = nv_rd32(dev, 0x100e10) << 12; +- else +- dev_priv->vram_sys_base = 0; +- + /* Reserve the last MiB of VRAM, we should probably try to avoid + * setting up the below tables over the top of the VBIOS image at + * some point. + */ + dev_priv->ramin_rsvd_vram = 1 << 20; +- c_offset = nouveau_mem_fb_amount(dev) - dev_priv->ramin_rsvd_vram; ++ c_offset = dev_priv->vram_size - dev_priv->ramin_rsvd_vram; + c_size = 128 << 10; + c_vmpd = ((dev_priv->chipset & 0xf0) == 0x50) ? 0x1400 : 0x200; + c_ramfc = ((dev_priv->chipset & 0xf0) == 0x50) ? 0x0 : 0x20; +@@ -106,7 +102,7 @@ nv50_instmem_init(struct drm_device *dev) + dev_priv->vm_gart_size = NV50_VM_BLOCK; + + dev_priv->vm_vram_base = dev_priv->vm_gart_base + dev_priv->vm_gart_size; +- dev_priv->vm_vram_size = nouveau_mem_fb_amount(dev); ++ dev_priv->vm_vram_size = dev_priv->vram_size; + if (dev_priv->vm_vram_size > NV50_VM_MAX_VRAM) + dev_priv->vm_vram_size = NV50_VM_MAX_VRAM; + dev_priv->vm_vram_size = roundup(dev_priv->vm_vram_size, NV50_VM_BLOCK); +@@ -189,8 +185,8 @@ nv50_instmem_init(struct drm_device *dev) + + i = 0; + while (v < dev_priv->vram_sys_base + c_offset + c_size) { +- BAR0_WI32(priv->pramin_pt->gpuobj, i + 0, v); +- BAR0_WI32(priv->pramin_pt->gpuobj, i + 4, 0x00000000); ++ BAR0_WI32(priv->pramin_pt->gpuobj, i + 0, lower_32_bits(v)); ++ BAR0_WI32(priv->pramin_pt->gpuobj, i + 4, upper_32_bits(v)); + v += 0x1000; + i += 8; + } +@@ -390,7 +386,7 @@ nv50_instmem_populate(struct drm_device *dev, struct nouveau_gpuobj *gpuobj, + if (gpuobj->im_backing) + return -EINVAL; + +- *sz = (*sz + (NV50_INSTMEM_PAGE_SIZE-1)) & ~(NV50_INSTMEM_PAGE_SIZE-1); ++ *sz = ALIGN(*sz, NV50_INSTMEM_PAGE_SIZE); + if (*sz == 0) + return -EINVAL; + +diff --git a/drivers/gpu/drm/nouveau/nv50_sor.c b/drivers/gpu/drm/nouveau/nv50_sor.c +index c2fff54..4832bba 100644 +--- a/drivers/gpu/drm/nouveau/nv50_sor.c ++++ b/drivers/gpu/drm/nouveau/nv50_sor.c +@@ -211,7 +211,7 @@ nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, + mode_ctl = 0x0200; + break; + case OUTPUT_DP: +- mode_ctl |= 0x00050000; ++ mode_ctl |= (nv_encoder->dp.mc_unknown << 16); + if (nv_encoder->dcb->sorconf.link & 1) + mode_ctl |= 0x00000800; + else +@@ -272,32 +272,22 @@ static const struct drm_encoder_funcs nv50_sor_encoder_funcs = { + }; + + int +-nv50_sor_create(struct drm_device *dev, struct dcb_entry *entry) ++nv50_sor_create(struct drm_connector *connector, struct dcb_entry *entry) + { + struct nouveau_encoder *nv_encoder = NULL; ++ struct drm_device *dev = connector->dev; + struct drm_encoder *encoder; +- bool dum; + int type; + + NV_DEBUG_KMS(dev, "\n"); + + switch (entry->type) { + case OUTPUT_TMDS: +- NV_INFO(dev, "Detected a TMDS output\n"); ++ case OUTPUT_DP: + type = DRM_MODE_ENCODER_TMDS; + break; + case OUTPUT_LVDS: +- NV_INFO(dev, "Detected a LVDS output\n"); + type = DRM_MODE_ENCODER_LVDS; +- +- if (nouveau_bios_parse_lvds_table(dev, 0, &dum, &dum)) { +- NV_ERROR(dev, "Failed parsing LVDS table\n"); +- return -EINVAL; +- } +- break; +- case OUTPUT_DP: +- NV_INFO(dev, "Detected a DP output\n"); +- type = DRM_MODE_ENCODER_TMDS; + break; + default: + return -EINVAL; +@@ -319,5 +309,29 @@ nv50_sor_create(struct drm_device *dev, struct dcb_entry *entry) + encoder->possible_crtcs = entry->heads; + encoder->possible_clones = 0; + ++ if (nv_encoder->dcb->type == OUTPUT_DP) { ++ int or = nv_encoder->or, link = !(entry->dpconf.sor.link & 1); ++ uint32_t tmp; ++ ++ tmp = nv_rd32(dev, 0x61c700 + (or * 0x800)); ++ ++ switch ((tmp & 0x00000f00) >> 8) { ++ case 8: ++ case 9: ++ nv_encoder->dp.mc_unknown = (tmp & 0x000f0000) >> 16; ++ tmp = nv_rd32(dev, NV50_SOR_DP_CTRL(or, link)); ++ nv_encoder->dp.unk0 = tmp & 0x000001fc; ++ tmp = nv_rd32(dev, NV50_SOR_DP_UNK128(or, link)); ++ nv_encoder->dp.unk1 = tmp & 0x010f7f3f; ++ break; ++ default: ++ break; ++ } ++ ++ if (!nv_encoder->dp.mc_unknown) ++ nv_encoder->dp.mc_unknown = 5; ++ } ++ ++ drm_mode_connector_attach_encoder(connector, encoder); + return 0; + } +-- +1.7.1 + diff --git a/drm-radeon-evergreen.patch b/drm-radeon-evergreen.patch new file mode 100644 index 000000000..530344648 --- /dev/null +++ b/drm-radeon-evergreen.patch @@ -0,0 +1,11726 @@ +diff --git a/drivers/gpu/drm/radeon/Makefile b/drivers/gpu/drm/radeon/Makefile +index 1cc7b93..83c5907 100644 +--- a/drivers/gpu/drm/radeon/Makefile ++++ b/drivers/gpu/drm/radeon/Makefile +@@ -54,7 +54,8 @@ radeon-y += radeon_device.o radeon_kms.o \ + radeon_cs.o radeon_bios.o radeon_benchmark.o r100.o r300.o r420.o \ + rs400.o rs600.o rs690.o rv515.o r520.o r600.o rv770.o radeon_test.o \ + r200.o radeon_legacy_tv.o r600_cs.o r600_blit.o r600_blit_shaders.o \ +- r600_blit_kms.o radeon_pm.o atombios_dp.o r600_audio.o r600_hdmi.o ++ r600_blit_kms.o radeon_pm.o atombios_dp.o r600_audio.o r600_hdmi.o \ ++ evergreen.o + + radeon-$(CONFIG_COMPAT) += radeon_ioc32.o + +diff --git a/drivers/gpu/drm/radeon/atom.c b/drivers/gpu/drm/radeon/atom.c +index d75788f..b7fe660 100644 +--- a/drivers/gpu/drm/radeon/atom.c ++++ b/drivers/gpu/drm/radeon/atom.c +@@ -52,15 +52,17 @@ + + typedef struct { + struct atom_context *ctx; +- + uint32_t *ps, *ws; + int ps_shift; + uint16_t start; ++ unsigned last_jump; ++ unsigned long last_jump_jiffies; ++ bool abort; + } atom_exec_context; + + int atom_debug = 0; +-static void atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params); +-void atom_execute_table(struct atom_context *ctx, int index, uint32_t * params); ++static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params); ++int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params); + + static uint32_t atom_arg_mask[8] = + { 0xFFFFFFFF, 0xFFFF, 0xFFFF00, 0xFFFF0000, 0xFF, 0xFF00, 0xFF0000, +@@ -604,12 +606,17 @@ static void atom_op_beep(atom_exec_context *ctx, int *ptr, int arg) + static void atom_op_calltable(atom_exec_context *ctx, int *ptr, int arg) + { + int idx = U8((*ptr)++); ++ int r = 0; ++ + if (idx < ATOM_TABLE_NAMES_CNT) + SDEBUG(" table: %d (%s)\n", idx, atom_table_names[idx]); + else + SDEBUG(" table: %d\n", idx); + if (U16(ctx->ctx->cmd_table + 4 + 2 * idx)) +- atom_execute_table_locked(ctx->ctx, idx, ctx->ps + ctx->ps_shift); ++ r = atom_execute_table_locked(ctx->ctx, idx, ctx->ps + ctx->ps_shift); ++ if (r) { ++ ctx->abort = true; ++ } + } + + static void atom_op_clear(atom_exec_context *ctx, int *ptr, int arg) +@@ -673,6 +680,8 @@ static void atom_op_eot(atom_exec_context *ctx, int *ptr, int arg) + static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg) + { + int execute = 0, target = U16(*ptr); ++ unsigned long cjiffies; ++ + (*ptr) += 2; + switch (arg) { + case ATOM_COND_ABOVE: +@@ -700,8 +709,25 @@ static void atom_op_jump(atom_exec_context *ctx, int *ptr, int arg) + if (arg != ATOM_COND_ALWAYS) + SDEBUG(" taken: %s\n", execute ? "yes" : "no"); + SDEBUG(" target: 0x%04X\n", target); +- if (execute) ++ if (execute) { ++ if (ctx->last_jump == (ctx->start + target)) { ++ cjiffies = jiffies; ++ if (time_after(cjiffies, ctx->last_jump_jiffies)) { ++ cjiffies -= ctx->last_jump_jiffies; ++ if ((jiffies_to_msecs(cjiffies) > 1000)) { ++ DRM_ERROR("atombios stuck in loop for more than 1sec aborting\n"); ++ ctx->abort = true; ++ } ++ } else { ++ /* jiffies wrap around we will just wait a little longer */ ++ ctx->last_jump_jiffies = jiffies; ++ } ++ } else { ++ ctx->last_jump = ctx->start + target; ++ ctx->last_jump_jiffies = jiffies; ++ } + *ptr = ctx->start + target; ++ } + } + + static void atom_op_mask(atom_exec_context *ctx, int *ptr, int arg) +@@ -1104,7 +1130,7 @@ static struct { + atom_op_shr, ATOM_ARG_MC}, { + atom_op_debug, 0},}; + +-static void atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params) ++static int atom_execute_table_locked(struct atom_context *ctx, int index, uint32_t * params) + { + int base = CU16(ctx->cmd_table + 4 + 2 * index); + int len, ws, ps, ptr; +@@ -1112,7 +1138,7 @@ static void atom_execute_table_locked(struct atom_context *ctx, int index, uint3 + atom_exec_context ectx; + + if (!base) +- return; ++ return -EINVAL; + + len = CU16(base + ATOM_CT_SIZE_PTR); + ws = CU8(base + ATOM_CT_WS_PTR); +@@ -1125,6 +1151,8 @@ static void atom_execute_table_locked(struct atom_context *ctx, int index, uint3 + ectx.ps_shift = ps / 4; + ectx.start = base; + ectx.ps = params; ++ ectx.abort = false; ++ ectx.last_jump = 0; + if (ws) + ectx.ws = kzalloc(4 * ws, GFP_KERNEL); + else +@@ -1137,6 +1165,11 @@ static void atom_execute_table_locked(struct atom_context *ctx, int index, uint3 + SDEBUG("%s @ 0x%04X\n", atom_op_names[op], ptr - 1); + else + SDEBUG("[%d] @ 0x%04X\n", op, ptr - 1); ++ if (ectx.abort) { ++ DRM_ERROR("atombios stuck executing %04X (len %d, WS %d, PS %d) @ 0x%04X\n", ++ base, len, ws, ps, ptr - 1); ++ return -EINVAL; ++ } + + if (op < ATOM_OP_CNT && op > 0) + opcode_table[op].func(&ectx, &ptr, +@@ -1152,10 +1185,13 @@ static void atom_execute_table_locked(struct atom_context *ctx, int index, uint3 + + if (ws) + kfree(ectx.ws); ++ return 0; + } + +-void atom_execute_table(struct atom_context *ctx, int index, uint32_t * params) ++int atom_execute_table(struct atom_context *ctx, int index, uint32_t * params) + { ++ int r; ++ + mutex_lock(&ctx->mutex); + /* reset reg block */ + ctx->reg_block = 0; +@@ -1163,8 +1199,9 @@ void atom_execute_table(struct atom_context *ctx, int index, uint32_t * params) + ctx->fb_base = 0; + /* reset io mode */ + ctx->io_mode = ATOM_IO_MM; +- atom_execute_table_locked(ctx, index, params); ++ r = atom_execute_table_locked(ctx, index, params); + mutex_unlock(&ctx->mutex); ++ return r; + } + + static int atom_iio_len[] = { 1, 2, 3, 3, 3, 3, 4, 4, 4, 3 }; +@@ -1248,9 +1285,7 @@ int atom_asic_init(struct atom_context *ctx) + + if (!CU16(ctx->cmd_table + 4 + 2 * ATOM_CMD_INIT)) + return 1; +- atom_execute_table(ctx, ATOM_CMD_INIT, ps); +- +- return 0; ++ return atom_execute_table(ctx, ATOM_CMD_INIT, ps); + } + + void atom_destroy(struct atom_context *ctx) +diff --git a/drivers/gpu/drm/radeon/atom.h b/drivers/gpu/drm/radeon/atom.h +index bc73781..1b26263 100644 +--- a/drivers/gpu/drm/radeon/atom.h ++++ b/drivers/gpu/drm/radeon/atom.h +@@ -140,7 +140,7 @@ struct atom_context { + extern int atom_debug; + + struct atom_context *atom_parse(struct card_info *, void *); +-void atom_execute_table(struct atom_context *, int, uint32_t *); ++int atom_execute_table(struct atom_context *, int, uint32_t *); + int atom_asic_init(struct atom_context *); + void atom_destroy(struct atom_context *); + void atom_parse_data_header(struct atom_context *ctx, int index, uint16_t *size, uint8_t *frev, uint8_t *crev, uint16_t *data_start); +diff --git a/drivers/gpu/drm/radeon/atombios.h b/drivers/gpu/drm/radeon/atombios.h +index 91ad0d1..6732b5d 100644 +--- a/drivers/gpu/drm/radeon/atombios.h ++++ b/drivers/gpu/drm/radeon/atombios.h +@@ -1,5 +1,5 @@ + /* +- * Copyright 2006-2007 Advanced Micro Devices, Inc. ++ * Copyright 2006-2007 Advanced Micro Devices, Inc. + * + * Permission is hereby granted, free of charge, to any person obtaining a + * copy of this software and associated documentation files (the "Software"), +@@ -20,10 +20,12 @@ + * OTHER DEALINGS IN THE SOFTWARE. + */ + +-/****************************************************************************/ ++ ++/****************************************************************************/ + /*Portion I: Definitions shared between VBIOS and Driver */ + /****************************************************************************/ + ++ + #ifndef _ATOMBIOS_H + #define _ATOMBIOS_H + +@@ -40,39 +42,46 @@ + #endif + + #ifdef _H2INC +-#ifndef ULONG +-typedef unsigned long ULONG; +-#endif ++ #ifndef ULONG ++ typedef unsigned long ULONG; ++ #endif + +-#ifndef UCHAR +-typedef unsigned char UCHAR; +-#endif ++ #ifndef UCHAR ++ typedef unsigned char UCHAR; ++ #endif + +-#ifndef USHORT +-typedef unsigned short USHORT; +-#endif ++ #ifndef USHORT ++ typedef unsigned short USHORT; ++ #endif + #endif +- +-#define ATOM_DAC_A 0 ++ ++#define ATOM_DAC_A 0 + #define ATOM_DAC_B 1 + #define ATOM_EXT_DAC 2 + + #define ATOM_CRTC1 0 + #define ATOM_CRTC2 1 ++#define ATOM_CRTC3 2 ++#define ATOM_CRTC4 3 ++#define ATOM_CRTC5 4 ++#define ATOM_CRTC6 5 ++#define ATOM_CRTC_INVALID 0xFF + + #define ATOM_DIGA 0 + #define ATOM_DIGB 1 + + #define ATOM_PPLL1 0 + #define ATOM_PPLL2 1 ++#define ATOM_DCPLL 2 ++#define ATOM_PPLL_INVALID 0xFF + + #define ATOM_SCALER1 0 + #define ATOM_SCALER2 1 + +-#define ATOM_SCALER_DISABLE 0 +-#define ATOM_SCALER_CENTER 1 +-#define ATOM_SCALER_EXPANSION 2 +-#define ATOM_SCALER_MULTI_EX 3 ++#define ATOM_SCALER_DISABLE 0 ++#define ATOM_SCALER_CENTER 1 ++#define ATOM_SCALER_EXPANSION 2 ++#define ATOM_SCALER_MULTI_EX 3 + + #define ATOM_DISABLE 0 + #define ATOM_ENABLE 1 +@@ -82,6 +91,7 @@ typedef unsigned short USHORT; + #define ATOM_LCD_SELFTEST_START (ATOM_DISABLE+5) + #define ATOM_LCD_SELFTEST_STOP (ATOM_ENABLE+5) + #define ATOM_ENCODER_INIT (ATOM_DISABLE+7) ++#define ATOM_GET_STATUS (ATOM_DISABLE+8) + + #define ATOM_BLANKING 1 + #define ATOM_BLANKING_OFF 0 +@@ -114,7 +124,7 @@ typedef unsigned short USHORT; + #define ATOM_DAC2_CV ATOM_DAC1_CV + #define ATOM_DAC2_NTSC ATOM_DAC1_NTSC + #define ATOM_DAC2_PAL ATOM_DAC1_PAL +- ++ + #define ATOM_PM_ON 0 + #define ATOM_PM_STANDBY 1 + #define ATOM_PM_SUSPEND 2 +@@ -134,6 +144,7 @@ typedef unsigned short USHORT; + #define ATOM_PANEL_MISC_TEMPORAL 0x00000040 + #define ATOM_PANEL_MISC_API_ENABLED 0x00000080 + ++ + #define MEMTYPE_DDR1 "DDR1" + #define MEMTYPE_DDR2 "DDR2" + #define MEMTYPE_DDR3 "DDR3" +@@ -145,19 +156,19 @@ typedef unsigned short USHORT; + + /* Maximum size of that FireGL flag string */ + +-#define ATOM_FIREGL_FLAG_STRING "FGL" /* Flag used to enable FireGL Support */ +-#define ATOM_MAX_SIZE_OF_FIREGL_FLAG_STRING 3 /* sizeof( ATOM_FIREGL_FLAG_STRING ) */ ++#define ATOM_FIREGL_FLAG_STRING "FGL" //Flag used to enable FireGL Support ++#define ATOM_MAX_SIZE_OF_FIREGL_FLAG_STRING 3 //sizeof( ATOM_FIREGL_FLAG_STRING ) + +-#define ATOM_FAKE_DESKTOP_STRING "DSK" /* Flag used to enable mobile ASIC on Desktop */ +-#define ATOM_MAX_SIZE_OF_FAKE_DESKTOP_STRING ATOM_MAX_SIZE_OF_FIREGL_FLAG_STRING ++#define ATOM_FAKE_DESKTOP_STRING "DSK" //Flag used to enable mobile ASIC on Desktop ++#define ATOM_MAX_SIZE_OF_FAKE_DESKTOP_STRING ATOM_MAX_SIZE_OF_FIREGL_FLAG_STRING + +-#define ATOM_M54T_FLAG_STRING "M54T" /* Flag used to enable M54T Support */ +-#define ATOM_MAX_SIZE_OF_M54T_FLAG_STRING 4 /* sizeof( ATOM_M54T_FLAG_STRING ) */ ++#define ATOM_M54T_FLAG_STRING "M54T" //Flag used to enable M54T Support ++#define ATOM_MAX_SIZE_OF_M54T_FLAG_STRING 4 //sizeof( ATOM_M54T_FLAG_STRING ) + + #define HW_ASSISTED_I2C_STATUS_FAILURE 2 + #define HW_ASSISTED_I2C_STATUS_SUCCESS 1 + +-#pragma pack(1) /* BIOS data must use byte aligment */ ++#pragma pack(1) /* BIOS data must use byte aligment */ + + /* Define offset to location of ROM header. */ + +@@ -165,367 +176,410 @@ typedef unsigned short USHORT; + #define OFFSET_TO_ATOM_ROM_IMAGE_SIZE 0x00000002L + + #define OFFSET_TO_ATOMBIOS_ASIC_BUS_MEM_TYPE 0x94 +-#define MAXSIZE_OF_ATOMBIOS_ASIC_BUS_MEM_TYPE 20 /* including the terminator 0x0! */ ++#define MAXSIZE_OF_ATOMBIOS_ASIC_BUS_MEM_TYPE 20 /* including the terminator 0x0! */ + #define OFFSET_TO_GET_ATOMBIOS_STRINGS_NUMBER 0x002f + #define OFFSET_TO_GET_ATOMBIOS_STRINGS_START 0x006e + + /* Common header for all ROM Data tables. +- Every table pointed _ATOM_MASTER_DATA_TABLE has this common header. ++ Every table pointed _ATOM_MASTER_DATA_TABLE has this common header. + And the pointer actually points to this header. */ + +-typedef struct _ATOM_COMMON_TABLE_HEADER { +- USHORT usStructureSize; +- UCHAR ucTableFormatRevision; /*Change it when the Parser is not backward compatible */ +- UCHAR ucTableContentRevision; /*Change it only when the table needs to change but the firmware */ +- /*Image can't be updated, while Driver needs to carry the new table! */ +-} ATOM_COMMON_TABLE_HEADER; +- +-typedef struct _ATOM_ROM_HEADER { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR uaFirmWareSignature[4]; /*Signature to distinguish between Atombios and non-atombios, +- atombios should init it as "ATOM", don't change the position */ +- USHORT usBiosRuntimeSegmentAddress; +- USHORT usProtectedModeInfoOffset; +- USHORT usConfigFilenameOffset; +- USHORT usCRC_BlockOffset; +- USHORT usBIOS_BootupMessageOffset; +- USHORT usInt10Offset; +- USHORT usPciBusDevInitCode; +- USHORT usIoBaseAddress; +- USHORT usSubsystemVendorID; +- USHORT usSubsystemID; +- USHORT usPCI_InfoOffset; +- USHORT usMasterCommandTableOffset; /*Offset for SW to get all command table offsets, Don't change the position */ +- USHORT usMasterDataTableOffset; /*Offset for SW to get all data table offsets, Don't change the position */ +- UCHAR ucExtendedFunctionCode; +- UCHAR ucReserved; +-} ATOM_ROM_HEADER; ++typedef struct _ATOM_COMMON_TABLE_HEADER ++{ ++ USHORT usStructureSize; ++ UCHAR ucTableFormatRevision; /*Change it when the Parser is not backward compatible */ ++ UCHAR ucTableContentRevision; /*Change it only when the table needs to change but the firmware */ ++ /*Image can't be updated, while Driver needs to carry the new table! */ ++}ATOM_COMMON_TABLE_HEADER; ++ ++typedef struct _ATOM_ROM_HEADER ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR uaFirmWareSignature[4]; /*Signature to distinguish between Atombios and non-atombios, ++ atombios should init it as "ATOM", don't change the position */ ++ USHORT usBiosRuntimeSegmentAddress; ++ USHORT usProtectedModeInfoOffset; ++ USHORT usConfigFilenameOffset; ++ USHORT usCRC_BlockOffset; ++ USHORT usBIOS_BootupMessageOffset; ++ USHORT usInt10Offset; ++ USHORT usPciBusDevInitCode; ++ USHORT usIoBaseAddress; ++ USHORT usSubsystemVendorID; ++ USHORT usSubsystemID; ++ USHORT usPCI_InfoOffset; ++ USHORT usMasterCommandTableOffset; /*Offset for SW to get all command table offsets, Don't change the position */ ++ USHORT usMasterDataTableOffset; /*Offset for SW to get all data table offsets, Don't change the position */ ++ UCHAR ucExtendedFunctionCode; ++ UCHAR ucReserved; ++}ATOM_ROM_HEADER; + + /*==============================Command Table Portion==================================== */ + + #ifdef UEFI_BUILD +-#define UTEMP USHORT +-#define USHORT void* ++ #define UTEMP USHORT ++ #define USHORT void* + #endif + +-typedef struct _ATOM_MASTER_LIST_OF_COMMAND_TABLES { +- USHORT ASIC_Init; /* Function Table, used by various SW components,latest version 1.1 */ +- USHORT GetDisplaySurfaceSize; /* Atomic Table, Used by Bios when enabling HW ICON */ +- USHORT ASIC_RegistersInit; /* Atomic Table, indirectly used by various SW components,called from ASIC_Init */ +- USHORT VRAM_BlockVenderDetection; /* Atomic Table, used only by Bios */ +- USHORT DIGxEncoderControl; /* Only used by Bios */ +- USHORT MemoryControllerInit; /* Atomic Table, indirectly used by various SW components,called from ASIC_Init */ +- USHORT EnableCRTCMemReq; /* Function Table,directly used by various SW components,latest version 2.1 */ +- USHORT MemoryParamAdjust; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock if needed */ +- USHORT DVOEncoderControl; /* Function Table,directly used by various SW components,latest version 1.2 */ +- USHORT GPIOPinControl; /* Atomic Table, only used by Bios */ +- USHORT SetEngineClock; /*Function Table,directly used by various SW components,latest version 1.1 */ +- USHORT SetMemoryClock; /* Function Table,directly used by various SW components,latest version 1.1 */ +- USHORT SetPixelClock; /*Function Table,directly used by various SW components,latest version 1.2 */ +- USHORT DynamicClockGating; /* Atomic Table, indirectly used by various SW components,called from ASIC_Init */ +- USHORT ResetMemoryDLL; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock */ +- USHORT ResetMemoryDevice; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock */ +- USHORT MemoryPLLInit; +- USHORT AdjustDisplayPll; /* only used by Bios */ +- USHORT AdjustMemoryController; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock */ +- USHORT EnableASIC_StaticPwrMgt; /* Atomic Table, only used by Bios */ +- USHORT ASIC_StaticPwrMgtStatusChange; /* Obsolete, only used by Bios */ +- USHORT DAC_LoadDetection; /* Atomic Table, directly used by various SW components,latest version 1.2 */ +- USHORT LVTMAEncoderControl; /* Atomic Table,directly used by various SW components,latest version 1.3 */ +- USHORT LCD1OutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT DAC1EncoderControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT DAC2EncoderControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT DVOOutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT CV1OutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT GetConditionalGoldenSetting; /* only used by Bios */ +- USHORT TVEncoderControl; /* Function Table,directly used by various SW components,latest version 1.1 */ +- USHORT TMDSAEncoderControl; /* Atomic Table, directly used by various SW components,latest version 1.3 */ +- USHORT LVDSEncoderControl; /* Atomic Table, directly used by various SW components,latest version 1.3 */ +- USHORT TV1OutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT EnableScaler; /* Atomic Table, used only by Bios */ +- USHORT BlankCRTC; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT EnableCRTC; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT GetPixelClock; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT EnableVGA_Render; /* Function Table,directly used by various SW components,latest version 1.1 */ +- USHORT EnableVGA_Access; /* Obsolete , only used by Bios */ +- USHORT SetCRTC_Timing; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT SetCRTC_OverScan; /* Atomic Table, used by various SW components,latest version 1.1 */ +- USHORT SetCRTC_Replication; /* Atomic Table, used only by Bios */ +- USHORT SelectCRTC_Source; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT EnableGraphSurfaces; /* Atomic Table, used only by Bios */ +- USHORT UpdateCRTC_DoubleBufferRegisters; +- USHORT LUT_AutoFill; /* Atomic Table, only used by Bios */ +- USHORT EnableHW_IconCursor; /* Atomic Table, only used by Bios */ +- USHORT GetMemoryClock; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT GetEngineClock; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT SetCRTC_UsingDTDTiming; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT ExternalEncoderControl; /* Atomic Table, directly used by various SW components,latest version 2.1 */ +- USHORT LVTMAOutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT VRAM_BlockDetectionByStrap; /* Atomic Table, used only by Bios */ +- USHORT MemoryCleanUp; /* Atomic Table, only used by Bios */ +- USHORT ProcessI2cChannelTransaction; /* Function Table,only used by Bios */ +- USHORT WriteOneByteToHWAssistedI2C; /* Function Table,indirectly used by various SW components */ +- USHORT ReadHWAssistedI2CStatus; /* Atomic Table, indirectly used by various SW components */ +- USHORT SpeedFanControl; /* Function Table,indirectly used by various SW components,called from ASIC_Init */ +- USHORT PowerConnectorDetection; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT MC_Synchronization; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock */ +- USHORT ComputeMemoryEnginePLL; /* Atomic Table, indirectly used by various SW components,called from SetMemory/EngineClock */ +- USHORT MemoryRefreshConversion; /* Atomic Table, indirectly used by various SW components,called from SetMemory or SetEngineClock */ +- USHORT VRAM_GetCurrentInfoBlock; /* Atomic Table, used only by Bios */ +- USHORT DynamicMemorySettings; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock */ +- USHORT MemoryTraining; /* Atomic Table, used only by Bios */ +- USHORT EnableSpreadSpectrumOnPPLL; /* Atomic Table, directly used by various SW components,latest version 1.2 */ +- USHORT TMDSAOutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT SetVoltage; /* Function Table,directly and/or indirectly used by various SW components,latest version 1.1 */ +- USHORT DAC1OutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT DAC2OutputControl; /* Atomic Table, directly used by various SW components,latest version 1.1 */ +- USHORT SetupHWAssistedI2CStatus; /* Function Table,only used by Bios, obsolete soon.Switch to use "ReadEDIDFromHWAssistedI2C" */ +- USHORT ClockSource; /* Atomic Table, indirectly used by various SW components,called from ASIC_Init */ +- USHORT MemoryDeviceInit; /* Atomic Table, indirectly used by various SW components,called from SetMemoryClock */ +- USHORT EnableYUV; /* Atomic Table, indirectly used by various SW components,called from EnableVGARender */ +- USHORT DIG1EncoderControl; /* Atomic Table,directly used by various SW components,latest version 1.1 */ +- USHORT DIG2EncoderControl; /* Atomic Table,directly used by various SW components,latest version 1.1 */ +- USHORT DIG1TransmitterControl; /* Atomic Table,directly used by various SW components,latest version 1.1 */ +- USHORT DIG2TransmitterControl; /* Atomic Table,directly used by various SW components,latest version 1.1 */ +- USHORT ProcessAuxChannelTransaction; /* Function Table,only used by Bios */ +- USHORT DPEncoderService; /* Function Table,only used by Bios */ +-} ATOM_MASTER_LIST_OF_COMMAND_TABLES; +- +-/* For backward compatible */ ++typedef struct _ATOM_MASTER_LIST_OF_COMMAND_TABLES{ ++ USHORT ASIC_Init; //Function Table, used by various SW components,latest version 1.1 ++ USHORT GetDisplaySurfaceSize; //Atomic Table, Used by Bios when enabling HW ICON ++ USHORT ASIC_RegistersInit; //Atomic Table, indirectly used by various SW components,called from ASIC_Init ++ USHORT VRAM_BlockVenderDetection; //Atomic Table, used only by Bios ++ USHORT DIGxEncoderControl; //Only used by Bios ++ USHORT MemoryControllerInit; //Atomic Table, indirectly used by various SW components,called from ASIC_Init ++ USHORT EnableCRTCMemReq; //Function Table,directly used by various SW components,latest version 2.1 ++ USHORT MemoryParamAdjust; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock if needed ++ USHORT DVOEncoderControl; //Function Table,directly used by various SW components,latest version 1.2 ++ USHORT GPIOPinControl; //Atomic Table, only used by Bios ++ USHORT SetEngineClock; //Function Table,directly used by various SW components,latest version 1.1 ++ USHORT SetMemoryClock; //Function Table,directly used by various SW components,latest version 1.1 ++ USHORT SetPixelClock; //Function Table,directly used by various SW components,latest version 1.2 ++ USHORT DynamicClockGating; //Atomic Table, indirectly used by various SW components,called from ASIC_Init ++ USHORT ResetMemoryDLL; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock ++ USHORT ResetMemoryDevice; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock ++ USHORT MemoryPLLInit; ++ USHORT AdjustDisplayPll; //only used by Bios ++ USHORT AdjustMemoryController; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock ++ USHORT EnableASIC_StaticPwrMgt; //Atomic Table, only used by Bios ++ USHORT ASIC_StaticPwrMgtStatusChange; //Obsolete , only used by Bios ++ USHORT DAC_LoadDetection; //Atomic Table, directly used by various SW components,latest version 1.2 ++ USHORT LVTMAEncoderControl; //Atomic Table,directly used by various SW components,latest version 1.3 ++ USHORT LCD1OutputControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT DAC1EncoderControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT DAC2EncoderControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT DVOOutputControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT CV1OutputControl; //Atomic Table, Atomic Table, Obsolete from Ry6xx, use DAC2 Output instead ++ USHORT GetConditionalGoldenSetting; //only used by Bios ++ USHORT TVEncoderControl; //Function Table,directly used by various SW components,latest version 1.1 ++ USHORT TMDSAEncoderControl; //Atomic Table, directly used by various SW components,latest version 1.3 ++ USHORT LVDSEncoderControl; //Atomic Table, directly used by various SW components,latest version 1.3 ++ USHORT TV1OutputControl; //Atomic Table, Obsolete from Ry6xx, use DAC2 Output instead ++ USHORT EnableScaler; //Atomic Table, used only by Bios ++ USHORT BlankCRTC; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT EnableCRTC; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT GetPixelClock; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT EnableVGA_Render; //Function Table,directly used by various SW components,latest version 1.1 ++ USHORT GetSCLKOverMCLKRatio; //Atomic Table, only used by Bios ++ USHORT SetCRTC_Timing; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT SetCRTC_OverScan; //Atomic Table, used by various SW components,latest version 1.1 ++ USHORT SetCRTC_Replication; //Atomic Table, used only by Bios ++ USHORT SelectCRTC_Source; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT EnableGraphSurfaces; //Atomic Table, used only by Bios ++ USHORT UpdateCRTC_DoubleBufferRegisters; ++ USHORT LUT_AutoFill; //Atomic Table, only used by Bios ++ USHORT EnableHW_IconCursor; //Atomic Table, only used by Bios ++ USHORT GetMemoryClock; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT GetEngineClock; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT SetCRTC_UsingDTDTiming; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT ExternalEncoderControl; //Atomic Table, directly used by various SW components,latest version 2.1 ++ USHORT LVTMAOutputControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT VRAM_BlockDetectionByStrap; //Atomic Table, used only by Bios ++ USHORT MemoryCleanUp; //Atomic Table, only used by Bios ++ USHORT ProcessI2cChannelTransaction; //Function Table,only used by Bios ++ USHORT WriteOneByteToHWAssistedI2C; //Function Table,indirectly used by various SW components ++ USHORT ReadHWAssistedI2CStatus; //Atomic Table, indirectly used by various SW components ++ USHORT SpeedFanControl; //Function Table,indirectly used by various SW components,called from ASIC_Init ++ USHORT PowerConnectorDetection; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT MC_Synchronization; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock ++ USHORT ComputeMemoryEnginePLL; //Atomic Table, indirectly used by various SW components,called from SetMemory/EngineClock ++ USHORT MemoryRefreshConversion; //Atomic Table, indirectly used by various SW components,called from SetMemory or SetEngineClock ++ USHORT VRAM_GetCurrentInfoBlock; //Atomic Table, used only by Bios ++ USHORT DynamicMemorySettings; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock ++ USHORT MemoryTraining; //Atomic Table, used only by Bios ++ USHORT EnableSpreadSpectrumOnPPLL; //Atomic Table, directly used by various SW components,latest version 1.2 ++ USHORT TMDSAOutputControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT SetVoltage; //Function Table,directly and/or indirectly used by various SW components,latest version 1.1 ++ USHORT DAC1OutputControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT DAC2OutputControl; //Atomic Table, directly used by various SW components,latest version 1.1 ++ USHORT SetupHWAssistedI2CStatus; //Function Table,only used by Bios, obsolete soon.Switch to use "ReadEDIDFromHWAssistedI2C" ++ USHORT ClockSource; //Atomic Table, indirectly used by various SW components,called from ASIC_Init ++ USHORT MemoryDeviceInit; //Atomic Table, indirectly used by various SW components,called from SetMemoryClock ++ USHORT EnableYUV; //Atomic Table, indirectly used by various SW components,called from EnableVGARender ++ USHORT DIG1EncoderControl; //Atomic Table,directly used by various SW components,latest version 1.1 ++ USHORT DIG2EncoderControl; //Atomic Table,directly used by various SW components,latest version 1.1 ++ USHORT DIG1TransmitterControl; //Atomic Table,directly used by various SW components,latest version 1.1 ++ USHORT DIG2TransmitterControl; //Atomic Table,directly used by various SW components,latest version 1.1 ++ USHORT ProcessAuxChannelTransaction; //Function Table,only used by Bios ++ USHORT DPEncoderService; //Function Table,only used by Bios ++}ATOM_MASTER_LIST_OF_COMMAND_TABLES; ++ ++// For backward compatible + #define ReadEDIDFromHWAssistedI2C ProcessI2cChannelTransaction + #define UNIPHYTransmitterControl DIG1TransmitterControl + #define LVTMATransmitterControl DIG2TransmitterControl + #define SetCRTC_DPM_State GetConditionalGoldenSetting + #define SetUniphyInstance ASIC_StaticPwrMgtStatusChange ++#define HPDInterruptService ReadHWAssistedI2CStatus ++#define EnableVGA_Access GetSCLKOverMCLKRatio + +-typedef struct _ATOM_MASTER_COMMAND_TABLE { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_MASTER_LIST_OF_COMMAND_TABLES ListOfCommandTables; +-} ATOM_MASTER_COMMAND_TABLE; +- +-/****************************************************************************/ +-/* Structures used in every command table */ +-/****************************************************************************/ +-typedef struct _ATOM_TABLE_ATTRIBUTE { ++typedef struct _ATOM_MASTER_COMMAND_TABLE ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_MASTER_LIST_OF_COMMAND_TABLES ListOfCommandTables; ++}ATOM_MASTER_COMMAND_TABLE; ++ ++/****************************************************************************/ ++// Structures used in every command table ++/****************************************************************************/ ++typedef struct _ATOM_TABLE_ATTRIBUTE ++{ + #if ATOM_BIG_ENDIAN +- USHORT UpdatedByUtility:1; /* [15]=Table updated by utility flag */ +- USHORT PS_SizeInBytes:7; /* [14:8]=Size of parameter space in Bytes (multiple of a dword), */ +- USHORT WS_SizeInBytes:8; /* [7:0]=Size of workspace in Bytes (in multiple of a dword), */ ++ USHORT UpdatedByUtility:1; //[15]=Table updated by utility flag ++ USHORT PS_SizeInBytes:7; //[14:8]=Size of parameter space in Bytes (multiple of a dword), ++ USHORT WS_SizeInBytes:8; //[7:0]=Size of workspace in Bytes (in multiple of a dword), + #else +- USHORT WS_SizeInBytes:8; /* [7:0]=Size of workspace in Bytes (in multiple of a dword), */ +- USHORT PS_SizeInBytes:7; /* [14:8]=Size of parameter space in Bytes (multiple of a dword), */ +- USHORT UpdatedByUtility:1; /* [15]=Table updated by utility flag */ ++ USHORT WS_SizeInBytes:8; //[7:0]=Size of workspace in Bytes (in multiple of a dword), ++ USHORT PS_SizeInBytes:7; //[14:8]=Size of parameter space in Bytes (multiple of a dword), ++ USHORT UpdatedByUtility:1; //[15]=Table updated by utility flag + #endif +-} ATOM_TABLE_ATTRIBUTE; +- +-typedef union _ATOM_TABLE_ATTRIBUTE_ACCESS { +- ATOM_TABLE_ATTRIBUTE sbfAccess; +- USHORT susAccess; +-} ATOM_TABLE_ATTRIBUTE_ACCESS; ++}ATOM_TABLE_ATTRIBUTE; + +-/****************************************************************************/ +-/* Common header for all command tables. */ +-/* Every table pointed by _ATOM_MASTER_COMMAND_TABLE has this common header. */ +-/* And the pointer actually points to this header. */ +-/****************************************************************************/ +-typedef struct _ATOM_COMMON_ROM_COMMAND_TABLE_HEADER { +- ATOM_COMMON_TABLE_HEADER CommonHeader; +- ATOM_TABLE_ATTRIBUTE TableAttribute; +-} ATOM_COMMON_ROM_COMMAND_TABLE_HEADER; ++typedef union _ATOM_TABLE_ATTRIBUTE_ACCESS ++{ ++ ATOM_TABLE_ATTRIBUTE sbfAccess; ++ USHORT susAccess; ++}ATOM_TABLE_ATTRIBUTE_ACCESS; ++ ++/****************************************************************************/ ++// Common header for all command tables. ++// Every table pointed by _ATOM_MASTER_COMMAND_TABLE has this common header. ++// And the pointer actually points to this header. ++/****************************************************************************/ ++typedef struct _ATOM_COMMON_ROM_COMMAND_TABLE_HEADER ++{ ++ ATOM_COMMON_TABLE_HEADER CommonHeader; ++ ATOM_TABLE_ATTRIBUTE TableAttribute; ++}ATOM_COMMON_ROM_COMMAND_TABLE_HEADER; + +-/****************************************************************************/ +-/* Structures used by ComputeMemoryEnginePLLTable */ +-/****************************************************************************/ ++/****************************************************************************/ ++// Structures used by ComputeMemoryEnginePLLTable ++/****************************************************************************/ + #define COMPUTE_MEMORY_PLL_PARAM 1 + #define COMPUTE_ENGINE_PLL_PARAM 2 + +-typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS { +- ULONG ulClock; /* When returen, it's the re-calculated clock based on given Fb_div Post_Div and ref_div */ +- UCHAR ucAction; /* 0:reserved //1:Memory //2:Engine */ +- UCHAR ucReserved; /* may expand to return larger Fbdiv later */ +- UCHAR ucFbDiv; /* return value */ +- UCHAR ucPostDiv; /* return value */ +-} COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS; +- +-typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 { +- ULONG ulClock; /* When return, [23:0] return real clock */ +- UCHAR ucAction; /* 0:reserved;COMPUTE_MEMORY_PLL_PARAM:Memory;COMPUTE_ENGINE_PLL_PARAM:Engine. it return ref_div to be written to register */ +- USHORT usFbDiv; /* return Feedback value to be written to register */ +- UCHAR ucPostDiv; /* return post div to be written to register */ +-} COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2; ++typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS ++{ ++ ULONG ulClock; //When returen, it's the re-calculated clock based on given Fb_div Post_Div and ref_div ++ UCHAR ucAction; //0:reserved //1:Memory //2:Engine ++ UCHAR ucReserved; //may expand to return larger Fbdiv later ++ UCHAR ucFbDiv; //return value ++ UCHAR ucPostDiv; //return value ++}COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS; ++ ++typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2 ++{ ++ ULONG ulClock; //When return, [23:0] return real clock ++ UCHAR ucAction; //0:reserved;COMPUTE_MEMORY_PLL_PARAM:Memory;COMPUTE_ENGINE_PLL_PARAM:Engine. it return ref_div to be written to register ++ USHORT usFbDiv; //return Feedback value to be written to register ++ UCHAR ucPostDiv; //return post div to be written to register ++}COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V2; + #define COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_PS_ALLOCATION COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS + +-#define SET_CLOCK_FREQ_MASK 0x00FFFFFF /* Clock change tables only take bit [23:0] as the requested clock value */ +-#define USE_NON_BUS_CLOCK_MASK 0x01000000 /* Applicable to both memory and engine clock change, when set, it uses another clock as the temporary clock (engine uses memory and vice versa) */ +-#define USE_MEMORY_SELF_REFRESH_MASK 0x02000000 /* Only applicable to memory clock change, when set, using memory self refresh during clock transition */ +-#define SKIP_INTERNAL_MEMORY_PARAMETER_CHANGE 0x04000000 /* Only applicable to memory clock change, when set, the table will skip predefined internal memory parameter change */ +-#define FIRST_TIME_CHANGE_CLOCK 0x08000000 /* Applicable to both memory and engine clock change,when set, it means this is 1st time to change clock after ASIC bootup */ +-#define SKIP_SW_PROGRAM_PLL 0x10000000 /* Applicable to both memory and engine clock change, when set, it means the table will not program SPLL/MPLL */ ++ ++#define SET_CLOCK_FREQ_MASK 0x00FFFFFF //Clock change tables only take bit [23:0] as the requested clock value ++#define USE_NON_BUS_CLOCK_MASK 0x01000000 //Applicable to both memory and engine clock change, when set, it uses another clock as the temporary clock (engine uses memory and vice versa) ++#define USE_MEMORY_SELF_REFRESH_MASK 0x02000000 //Only applicable to memory clock change, when set, using memory self refresh during clock transition ++#define SKIP_INTERNAL_MEMORY_PARAMETER_CHANGE 0x04000000 //Only applicable to memory clock change, when set, the table will skip predefined internal memory parameter change ++#define FIRST_TIME_CHANGE_CLOCK 0x08000000 //Applicable to both memory and engine clock change,when set, it means this is 1st time to change clock after ASIC bootup ++#define SKIP_SW_PROGRAM_PLL 0x10000000 //Applicable to both memory and engine clock change, when set, it means the table will not program SPLL/MPLL + #define USE_SS_ENABLED_PIXEL_CLOCK USE_NON_BUS_CLOCK_MASK + +-#define b3USE_NON_BUS_CLOCK_MASK 0x01 /* Applicable to both memory and engine clock change, when set, it uses another clock as the temporary clock (engine uses memory and vice versa) */ +-#define b3USE_MEMORY_SELF_REFRESH 0x02 /* Only applicable to memory clock change, when set, using memory self refresh during clock transition */ +-#define b3SKIP_INTERNAL_MEMORY_PARAMETER_CHANGE 0x04 /* Only applicable to memory clock change, when set, the table will skip predefined internal memory parameter change */ +-#define b3FIRST_TIME_CHANGE_CLOCK 0x08 /* Applicable to both memory and engine clock change,when set, it means this is 1st time to change clock after ASIC bootup */ +-#define b3SKIP_SW_PROGRAM_PLL 0x10 /* Applicable to both memory and engine clock change, when set, it means the table will not program SPLL/MPLL */ ++#define b3USE_NON_BUS_CLOCK_MASK 0x01 //Applicable to both memory and engine clock change, when set, it uses another clock as the temporary clock (engine uses memory and vice versa) ++#define b3USE_MEMORY_SELF_REFRESH 0x02 //Only applicable to memory clock change, when set, using memory self refresh during clock transition ++#define b3SKIP_INTERNAL_MEMORY_PARAMETER_CHANGE 0x04 //Only applicable to memory clock change, when set, the table will skip predefined internal memory parameter change ++#define b3FIRST_TIME_CHANGE_CLOCK 0x08 //Applicable to both memory and engine clock change,when set, it means this is 1st time to change clock after ASIC bootup ++#define b3SKIP_SW_PROGRAM_PLL 0x10 //Applicable to both memory and engine clock change, when set, it means the table will not program SPLL/MPLL + +-typedef struct _ATOM_COMPUTE_CLOCK_FREQ { ++typedef struct _ATOM_COMPUTE_CLOCK_FREQ ++{ + #if ATOM_BIG_ENDIAN +- ULONG ulComputeClockFlag:8; /* =1: COMPUTE_MEMORY_PLL_PARAM, =2: COMPUTE_ENGINE_PLL_PARAM */ +- ULONG ulClockFreq:24; /* in unit of 10kHz */ ++ ULONG ulComputeClockFlag:8; // =1: COMPUTE_MEMORY_PLL_PARAM, =2: COMPUTE_ENGINE_PLL_PARAM ++ ULONG ulClockFreq:24; // in unit of 10kHz + #else +- ULONG ulClockFreq:24; /* in unit of 10kHz */ +- ULONG ulComputeClockFlag:8; /* =1: COMPUTE_MEMORY_PLL_PARAM, =2: COMPUTE_ENGINE_PLL_PARAM */ ++ ULONG ulClockFreq:24; // in unit of 10kHz ++ ULONG ulComputeClockFlag:8; // =1: COMPUTE_MEMORY_PLL_PARAM, =2: COMPUTE_ENGINE_PLL_PARAM + #endif +-} ATOM_COMPUTE_CLOCK_FREQ; +- +-typedef struct _ATOM_S_MPLL_FB_DIVIDER { +- USHORT usFbDivFrac; +- USHORT usFbDiv; +-} ATOM_S_MPLL_FB_DIVIDER; ++}ATOM_COMPUTE_CLOCK_FREQ; + +-typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 { +- union { +- ATOM_COMPUTE_CLOCK_FREQ ulClock; /* Input Parameter */ +- ATOM_S_MPLL_FB_DIVIDER ulFbDiv; /* Output Parameter */ +- }; +- UCHAR ucRefDiv; /* Output Parameter */ +- UCHAR ucPostDiv; /* Output Parameter */ +- UCHAR ucCntlFlag; /* Output Parameter */ +- UCHAR ucReserved; +-} COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3; ++typedef struct _ATOM_S_MPLL_FB_DIVIDER ++{ ++ USHORT usFbDivFrac; ++ USHORT usFbDiv; ++}ATOM_S_MPLL_FB_DIVIDER; + +-/* ucCntlFlag */ ++typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3 ++{ ++ union ++ { ++ ATOM_COMPUTE_CLOCK_FREQ ulClock; //Input Parameter ++ ATOM_S_MPLL_FB_DIVIDER ulFbDiv; //Output Parameter ++ }; ++ UCHAR ucRefDiv; //Output Parameter ++ UCHAR ucPostDiv; //Output Parameter ++ UCHAR ucCntlFlag; //Output Parameter ++ UCHAR ucReserved; ++}COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V3; ++ ++// ucCntlFlag + #define ATOM_PLL_CNTL_FLAG_PLL_POST_DIV_EN 1 + #define ATOM_PLL_CNTL_FLAG_MPLL_VCO_MODE 2 + #define ATOM_PLL_CNTL_FLAG_FRACTION_DISABLE 4 ++#define ATOM_PLL_CNTL_FLAG_SPLL_ISPARE_9 8 + +-typedef struct _DYNAMICE_MEMORY_SETTINGS_PARAMETER { +- ATOM_COMPUTE_CLOCK_FREQ ulClock; +- ULONG ulReserved[2]; +-} DYNAMICE_MEMORY_SETTINGS_PARAMETER; +- +-typedef struct _DYNAMICE_ENGINE_SETTINGS_PARAMETER { +- ATOM_COMPUTE_CLOCK_FREQ ulClock; +- ULONG ulMemoryClock; +- ULONG ulReserved; +-} DYNAMICE_ENGINE_SETTINGS_PARAMETER; +- +-/****************************************************************************/ +-/* Structures used by SetEngineClockTable */ +-/****************************************************************************/ +-typedef struct _SET_ENGINE_CLOCK_PARAMETERS { +- ULONG ulTargetEngineClock; /* In 10Khz unit */ +-} SET_ENGINE_CLOCK_PARAMETERS; + +-typedef struct _SET_ENGINE_CLOCK_PS_ALLOCATION { +- ULONG ulTargetEngineClock; /* In 10Khz unit */ +- COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_PS_ALLOCATION sReserved; +-} SET_ENGINE_CLOCK_PS_ALLOCATION; ++// V4 are only used for APU which PLL outside GPU ++typedef struct _COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4 ++{ ++#if ATOM_BIG_ENDIAN ++ ULONG ucPostDiv; //return parameter: post divider which is used to program to register directly ++ ULONG ulClock:24; //Input= target clock, output = actual clock ++#else ++ ULONG ulClock:24; //Input= target clock, output = actual clock ++ ULONG ucPostDiv; //return parameter: post divider which is used to program to register directly ++#endif ++}COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_V4; + +-/****************************************************************************/ +-/* Structures used by SetMemoryClockTable */ +-/****************************************************************************/ +-typedef struct _SET_MEMORY_CLOCK_PARAMETERS { +- ULONG ulTargetMemoryClock; /* In 10Khz unit */ +-} SET_MEMORY_CLOCK_PARAMETERS; ++typedef struct _DYNAMICE_MEMORY_SETTINGS_PARAMETER ++{ ++ ATOM_COMPUTE_CLOCK_FREQ ulClock; ++ ULONG ulReserved[2]; ++}DYNAMICE_MEMORY_SETTINGS_PARAMETER; + +-typedef struct _SET_MEMORY_CLOCK_PS_ALLOCATION { +- ULONG ulTargetMemoryClock; /* In 10Khz unit */ +- COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_PS_ALLOCATION sReserved; +-} SET_MEMORY_CLOCK_PS_ALLOCATION; ++typedef struct _DYNAMICE_ENGINE_SETTINGS_PARAMETER ++{ ++ ATOM_COMPUTE_CLOCK_FREQ ulClock; ++ ULONG ulMemoryClock; ++ ULONG ulReserved; ++}DYNAMICE_ENGINE_SETTINGS_PARAMETER; ++ ++/****************************************************************************/ ++// Structures used by SetEngineClockTable ++/****************************************************************************/ ++typedef struct _SET_ENGINE_CLOCK_PARAMETERS ++{ ++ ULONG ulTargetEngineClock; //In 10Khz unit ++}SET_ENGINE_CLOCK_PARAMETERS; + +-/****************************************************************************/ +-/* Structures used by ASIC_Init.ctb */ +-/****************************************************************************/ +-typedef struct _ASIC_INIT_PARAMETERS { +- ULONG ulDefaultEngineClock; /* In 10Khz unit */ +- ULONG ulDefaultMemoryClock; /* In 10Khz unit */ +-} ASIC_INIT_PARAMETERS; ++typedef struct _SET_ENGINE_CLOCK_PS_ALLOCATION ++{ ++ ULONG ulTargetEngineClock; //In 10Khz unit ++ COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_PS_ALLOCATION sReserved; ++}SET_ENGINE_CLOCK_PS_ALLOCATION; ++ ++/****************************************************************************/ ++// Structures used by SetMemoryClockTable ++/****************************************************************************/ ++typedef struct _SET_MEMORY_CLOCK_PARAMETERS ++{ ++ ULONG ulTargetMemoryClock; //In 10Khz unit ++}SET_MEMORY_CLOCK_PARAMETERS; + +-typedef struct _ASIC_INIT_PS_ALLOCATION { +- ASIC_INIT_PARAMETERS sASICInitClocks; +- SET_ENGINE_CLOCK_PS_ALLOCATION sReserved; /* Caller doesn't need to init this structure */ +-} ASIC_INIT_PS_ALLOCATION; ++typedef struct _SET_MEMORY_CLOCK_PS_ALLOCATION ++{ ++ ULONG ulTargetMemoryClock; //In 10Khz unit ++ COMPUTE_MEMORY_ENGINE_PLL_PARAMETERS_PS_ALLOCATION sReserved; ++}SET_MEMORY_CLOCK_PS_ALLOCATION; ++ ++/****************************************************************************/ ++// Structures used by ASIC_Init.ctb ++/****************************************************************************/ ++typedef struct _ASIC_INIT_PARAMETERS ++{ ++ ULONG ulDefaultEngineClock; //In 10Khz unit ++ ULONG ulDefaultMemoryClock; //In 10Khz unit ++}ASIC_INIT_PARAMETERS; + +-/****************************************************************************/ +-/* Structure used by DynamicClockGatingTable.ctb */ +-/****************************************************************************/ +-typedef struct _DYNAMIC_CLOCK_GATING_PARAMETERS { +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucPadding[3]; +-} DYNAMIC_CLOCK_GATING_PARAMETERS; ++typedef struct _ASIC_INIT_PS_ALLOCATION ++{ ++ ASIC_INIT_PARAMETERS sASICInitClocks; ++ SET_ENGINE_CLOCK_PS_ALLOCATION sReserved; //Caller doesn't need to init this structure ++}ASIC_INIT_PS_ALLOCATION; ++ ++/****************************************************************************/ ++// Structure used by DynamicClockGatingTable.ctb ++/****************************************************************************/ ++typedef struct _DYNAMIC_CLOCK_GATING_PARAMETERS ++{ ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucPadding[3]; ++}DYNAMIC_CLOCK_GATING_PARAMETERS; + #define DYNAMIC_CLOCK_GATING_PS_ALLOCATION DYNAMIC_CLOCK_GATING_PARAMETERS + +-/****************************************************************************/ +-/* Structure used by EnableASIC_StaticPwrMgtTable.ctb */ +-/****************************************************************************/ +-typedef struct _ENABLE_ASIC_STATIC_PWR_MGT_PARAMETERS { +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucPadding[3]; +-} ENABLE_ASIC_STATIC_PWR_MGT_PARAMETERS; ++/****************************************************************************/ ++// Structure used by EnableASIC_StaticPwrMgtTable.ctb ++/****************************************************************************/ ++typedef struct _ENABLE_ASIC_STATIC_PWR_MGT_PARAMETERS ++{ ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucPadding[3]; ++}ENABLE_ASIC_STATIC_PWR_MGT_PARAMETERS; + #define ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION ENABLE_ASIC_STATIC_PWR_MGT_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by DAC_LoadDetectionTable.ctb */ +-/****************************************************************************/ +-typedef struct _DAC_LOAD_DETECTION_PARAMETERS { +- USHORT usDeviceID; /* {ATOM_DEVICE_CRTx_SUPPORT,ATOM_DEVICE_TVx_SUPPORT,ATOM_DEVICE_CVx_SUPPORT} */ +- UCHAR ucDacType; /* {ATOM_DAC_A,ATOM_DAC_B, ATOM_EXT_DAC} */ +- UCHAR ucMisc; /* Valid only when table revision =1.3 and above */ +-} DAC_LOAD_DETECTION_PARAMETERS; ++/****************************************************************************/ ++// Structures used by DAC_LoadDetectionTable.ctb ++/****************************************************************************/ ++typedef struct _DAC_LOAD_DETECTION_PARAMETERS ++{ ++ USHORT usDeviceID; //{ATOM_DEVICE_CRTx_SUPPORT,ATOM_DEVICE_TVx_SUPPORT,ATOM_DEVICE_CVx_SUPPORT} ++ UCHAR ucDacType; //{ATOM_DAC_A,ATOM_DAC_B, ATOM_EXT_DAC} ++ UCHAR ucMisc; //Valid only when table revision =1.3 and above ++}DAC_LOAD_DETECTION_PARAMETERS; + +-/* DAC_LOAD_DETECTION_PARAMETERS.ucMisc */ ++// DAC_LOAD_DETECTION_PARAMETERS.ucMisc + #define DAC_LOAD_MISC_YPrPb 0x01 + +-typedef struct _DAC_LOAD_DETECTION_PS_ALLOCATION { +- DAC_LOAD_DETECTION_PARAMETERS sDacload; +- ULONG Reserved[2]; /* Don't set this one, allocation for EXT DAC */ +-} DAC_LOAD_DETECTION_PS_ALLOCATION; +- +-/****************************************************************************/ +-/* Structures used by DAC1EncoderControlTable.ctb and DAC2EncoderControlTable.ctb */ +-/****************************************************************************/ +-typedef struct _DAC_ENCODER_CONTROL_PARAMETERS { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- UCHAR ucDacStandard; /* See definition of ATOM_DACx_xxx, For DEC3.0, bit 7 used as internal flag to indicate DAC2 (==1) or DAC1 (==0) */ +- UCHAR ucAction; /* 0: turn off encoder */ +- /* 1: setup and turn on encoder */ +- /* 7: ATOM_ENCODER_INIT Initialize DAC */ +-} DAC_ENCODER_CONTROL_PARAMETERS; ++typedef struct _DAC_LOAD_DETECTION_PS_ALLOCATION ++{ ++ DAC_LOAD_DETECTION_PARAMETERS sDacload; ++ ULONG Reserved[2];// Don't set this one, allocation for EXT DAC ++}DAC_LOAD_DETECTION_PS_ALLOCATION; ++ ++/****************************************************************************/ ++// Structures used by DAC1EncoderControlTable.ctb and DAC2EncoderControlTable.ctb ++/****************************************************************************/ ++typedef struct _DAC_ENCODER_CONTROL_PARAMETERS ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ UCHAR ucDacStandard; // See definition of ATOM_DACx_xxx, For DEC3.0, bit 7 used as internal flag to indicate DAC2 (==1) or DAC1 (==0) ++ UCHAR ucAction; // 0: turn off encoder ++ // 1: setup and turn on encoder ++ // 7: ATOM_ENCODER_INIT Initialize DAC ++}DAC_ENCODER_CONTROL_PARAMETERS; + + #define DAC_ENCODER_CONTROL_PS_ALLOCATION DAC_ENCODER_CONTROL_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by DIG1EncoderControlTable */ +-/* DIG2EncoderControlTable */ +-/* ExternalEncoderControlTable */ +-/****************************************************************************/ +-typedef struct _DIG_ENCODER_CONTROL_PARAMETERS { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- UCHAR ucConfig; +- /* [2] Link Select: */ +- /* =0: PHY linkA if bfLane<3 */ +- /* =1: PHY linkB if bfLanes<3 */ +- /* =0: PHY linkA+B if bfLanes=3 */ +- /* [3] Transmitter Sel */ +- /* =0: UNIPHY or PCIEPHY */ +- /* =1: LVTMA */ +- UCHAR ucAction; /* =0: turn off encoder */ +- /* =1: turn on encoder */ +- UCHAR ucEncoderMode; +- /* =0: DP encoder */ +- /* =1: LVDS encoder */ +- /* =2: DVI encoder */ +- /* =3: HDMI encoder */ +- /* =4: SDVO encoder */ +- UCHAR ucLaneNum; /* how many lanes to enable */ +- UCHAR ucReserved[2]; +-} DIG_ENCODER_CONTROL_PARAMETERS; ++/****************************************************************************/ ++// Structures used by DIG1EncoderControlTable ++// DIG2EncoderControlTable ++// ExternalEncoderControlTable ++/****************************************************************************/ ++typedef struct _DIG_ENCODER_CONTROL_PARAMETERS ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ UCHAR ucConfig; ++ // [2] Link Select: ++ // =0: PHY linkA if bfLane<3 ++ // =1: PHY linkB if bfLanes<3 ++ // =0: PHY linkA+B if bfLanes=3 ++ // [3] Transmitter Sel ++ // =0: UNIPHY or PCIEPHY ++ // =1: LVTMA ++ UCHAR ucAction; // =0: turn off encoder ++ // =1: turn on encoder ++ UCHAR ucEncoderMode; ++ // =0: DP encoder ++ // =1: LVDS encoder ++ // =2: DVI encoder ++ // =3: HDMI encoder ++ // =4: SDVO encoder ++ UCHAR ucLaneNum; // how many lanes to enable ++ UCHAR ucReserved[2]; ++}DIG_ENCODER_CONTROL_PARAMETERS; + #define DIG_ENCODER_CONTROL_PS_ALLOCATION DIG_ENCODER_CONTROL_PARAMETERS + #define EXTERNAL_ENCODER_CONTROL_PARAMETER DIG_ENCODER_CONTROL_PARAMETERS + +-/* ucConfig */ ++//ucConfig + #define ATOM_ENCODER_CONFIG_DPLINKRATE_MASK 0x01 + #define ATOM_ENCODER_CONFIG_DPLINKRATE_1_62GHZ 0x00 + #define ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ 0x01 +@@ -539,52 +593,57 @@ typedef struct _DIG_ENCODER_CONTROL_PARAMETERS { + #define ATOM_ENCODER_CONFIG_LVTMA 0x08 + #define ATOM_ENCODER_CONFIG_TRANSMITTER1 0x00 + #define ATOM_ENCODER_CONFIG_TRANSMITTER2 0x08 +-#define ATOM_ENCODER_CONFIG_DIGB 0x80 /* VBIOS Internal use, outside SW should set this bit=0 */ +-/* ucAction */ +-/* ATOM_ENABLE: Enable Encoder */ +-/* ATOM_DISABLE: Disable Encoder */ ++#define ATOM_ENCODER_CONFIG_DIGB 0x80 // VBIOS Internal use, outside SW should set this bit=0 ++// ucAction ++// ATOM_ENABLE: Enable Encoder ++// ATOM_DISABLE: Disable Encoder + +-/* ucEncoderMode */ ++//ucEncoderMode + #define ATOM_ENCODER_MODE_DP 0 + #define ATOM_ENCODER_MODE_LVDS 1 + #define ATOM_ENCODER_MODE_DVI 2 + #define ATOM_ENCODER_MODE_HDMI 3 + #define ATOM_ENCODER_MODE_SDVO 4 ++#define ATOM_ENCODER_MODE_DP_AUDIO 5 + #define ATOM_ENCODER_MODE_TV 13 + #define ATOM_ENCODER_MODE_CV 14 + #define ATOM_ENCODER_MODE_CRT 15 + +-typedef struct _ATOM_DIG_ENCODER_CONFIG_V2 { ++typedef struct _ATOM_DIG_ENCODER_CONFIG_V2 ++{ + #if ATOM_BIG_ENDIAN +- UCHAR ucReserved1:2; +- UCHAR ucTransmitterSel:2; /* =0: UniphyAB, =1: UniphyCD =2: UniphyEF */ +- UCHAR ucLinkSel:1; /* =0: linkA/C/E =1: linkB/D/F */ +- UCHAR ucReserved:1; +- UCHAR ucDPLinkRate:1; /* =0: 1.62Ghz, =1: 2.7Ghz */ ++ UCHAR ucReserved1:2; ++ UCHAR ucTransmitterSel:2; // =0: UniphyAB, =1: UniphyCD =2: UniphyEF ++ UCHAR ucLinkSel:1; // =0: linkA/C/E =1: linkB/D/F ++ UCHAR ucReserved:1; ++ UCHAR ucDPLinkRate:1; // =0: 1.62Ghz, =1: 2.7Ghz + #else +- UCHAR ucDPLinkRate:1; /* =0: 1.62Ghz, =1: 2.7Ghz */ +- UCHAR ucReserved:1; +- UCHAR ucLinkSel:1; /* =0: linkA/C/E =1: linkB/D/F */ +- UCHAR ucTransmitterSel:2; /* =0: UniphyAB, =1: UniphyCD =2: UniphyEF */ +- UCHAR ucReserved1:2; ++ UCHAR ucDPLinkRate:1; // =0: 1.62Ghz, =1: 2.7Ghz ++ UCHAR ucReserved:1; ++ UCHAR ucLinkSel:1; // =0: linkA/C/E =1: linkB/D/F ++ UCHAR ucTransmitterSel:2; // =0: UniphyAB, =1: UniphyCD =2: UniphyEF ++ UCHAR ucReserved1:2; + #endif +-} ATOM_DIG_ENCODER_CONFIG_V2; ++}ATOM_DIG_ENCODER_CONFIG_V2; + +-typedef struct _DIG_ENCODER_CONTROL_PARAMETERS_V2 { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- ATOM_DIG_ENCODER_CONFIG_V2 acConfig; +- UCHAR ucAction; +- UCHAR ucEncoderMode; +- /* =0: DP encoder */ +- /* =1: LVDS encoder */ +- /* =2: DVI encoder */ +- /* =3: HDMI encoder */ +- /* =4: SDVO encoder */ +- UCHAR ucLaneNum; /* how many lanes to enable */ +- UCHAR ucReserved[2]; +-} DIG_ENCODER_CONTROL_PARAMETERS_V2; + +-/* ucConfig */ ++typedef struct _DIG_ENCODER_CONTROL_PARAMETERS_V2 ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ ATOM_DIG_ENCODER_CONFIG_V2 acConfig; ++ UCHAR ucAction; ++ UCHAR ucEncoderMode; ++ // =0: DP encoder ++ // =1: LVDS encoder ++ // =2: DVI encoder ++ // =3: HDMI encoder ++ // =4: SDVO encoder ++ UCHAR ucLaneNum; // how many lanes to enable ++ UCHAR ucStatus; // = DP_LINK_TRAINING_COMPLETE or DP_LINK_TRAINING_INCOMPLETE, only used by VBIOS with command ATOM_ENCODER_CMD_QUERY_DP_LINK_TRAINING_STATUS ++ UCHAR ucReserved; ++}DIG_ENCODER_CONTROL_PARAMETERS_V2; ++ ++//ucConfig + #define ATOM_ENCODER_CONFIG_V2_DPLINKRATE_MASK 0x01 + #define ATOM_ENCODER_CONFIG_V2_DPLINKRATE_1_62GHZ 0x00 + #define ATOM_ENCODER_CONFIG_V2_DPLINKRATE_2_70GHZ 0x01 +@@ -596,58 +655,122 @@ typedef struct _DIG_ENCODER_CONTROL_PARAMETERS_V2 { + #define ATOM_ENCODER_CONFIG_V2_TRANSMITTER2 0x08 + #define ATOM_ENCODER_CONFIG_V2_TRANSMITTER3 0x10 + +-/****************************************************************************/ +-/* Structures used by UNIPHYTransmitterControlTable */ +-/* LVTMATransmitterControlTable */ +-/* DVOOutputControlTable */ +-/****************************************************************************/ +-typedef struct _ATOM_DP_VS_MODE { +- UCHAR ucLaneSel; +- UCHAR ucLaneSet; +-} ATOM_DP_VS_MODE; +- +-typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS { +- union { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- USHORT usInitInfo; /* when init uniphy,lower 8bit is used for connector type defined in objectid.h */ +- ATOM_DP_VS_MODE asMode; /* DP Voltage swing mode */ ++// ucAction: ++// ATOM_DISABLE ++// ATOM_ENABLE ++#define ATOM_ENCODER_CMD_DP_LINK_TRAINING_START 0x08 ++#define ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN1 0x09 ++#define ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN2 0x0a ++#define ATOM_ENCODER_CMD_DP_LINK_TRAINING_COMPLETE 0x0b ++#define ATOM_ENCODER_CMD_DP_VIDEO_OFF 0x0c ++#define ATOM_ENCODER_CMD_DP_VIDEO_ON 0x0d ++#define ATOM_ENCODER_CMD_QUERY_DP_LINK_TRAINING_STATUS 0x0e ++#define ATOM_ENCODER_CMD_SETUP 0x0f ++ ++// ucStatus ++#define ATOM_ENCODER_STATUS_LINK_TRAINING_COMPLETE 0x10 ++#define ATOM_ENCODER_STATUS_LINK_TRAINING_INCOMPLETE 0x00 ++ ++// Following function ENABLE sub-function will be used by driver when TMDS/HDMI/LVDS is used, disable function will be used by driver ++typedef struct _ATOM_DIG_ENCODER_CONFIG_V3 ++{ ++#if ATOM_BIG_ENDIAN ++ UCHAR ucReserved1:1; ++ UCHAR ucDigSel:3; // =0: DIGA/B/C/D/E/F ++ UCHAR ucReserved:3; ++ UCHAR ucDPLinkRate:1; // =0: 1.62Ghz, =1: 2.7Ghz ++#else ++ UCHAR ucDPLinkRate:1; // =0: 1.62Ghz, =1: 2.7Ghz ++ UCHAR ucReserved:3; ++ UCHAR ucDigSel:3; // =0: DIGA/B/C/D/E/F ++ UCHAR ucReserved1:1; ++#endif ++}ATOM_DIG_ENCODER_CONFIG_V3; ++ ++#define ATOM_ENCODER_CONFIG_V3_ENCODER_SEL 0x70 ++ ++ ++typedef struct _DIG_ENCODER_CONTROL_PARAMETERS_V3 ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ ATOM_DIG_ENCODER_CONFIG_V3 acConfig; ++ UCHAR ucAction; ++ UCHAR ucEncoderMode; ++ // =0: DP encoder ++ // =1: LVDS encoder ++ // =2: DVI encoder ++ // =3: HDMI encoder ++ // =4: SDVO encoder ++ // =5: DP audio ++ UCHAR ucLaneNum; // how many lanes to enable ++ UCHAR ucBitPerColor; // only valid for DP mode when ucAction = ATOM_ENCODER_CMD_SETUP ++ UCHAR ucReserved; ++}DIG_ENCODER_CONTROL_PARAMETERS_V3; ++ ++ ++// define ucBitPerColor: ++#define PANEL_BPC_UNDEFINE 0x00 ++#define PANEL_6BIT_PER_COLOR 0x01 ++#define PANEL_8BIT_PER_COLOR 0x02 ++#define PANEL_10BIT_PER_COLOR 0x03 ++#define PANEL_12BIT_PER_COLOR 0x04 ++#define PANEL_16BIT_PER_COLOR 0x05 ++ ++/****************************************************************************/ ++// Structures used by UNIPHYTransmitterControlTable ++// LVTMATransmitterControlTable ++// DVOOutputControlTable ++/****************************************************************************/ ++typedef struct _ATOM_DP_VS_MODE ++{ ++ UCHAR ucLaneSel; ++ UCHAR ucLaneSet; ++}ATOM_DP_VS_MODE; ++ ++typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS ++{ ++ union ++ { ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ USHORT usInitInfo; // when init uniphy,lower 8bit is used for connector type defined in objectid.h ++ ATOM_DP_VS_MODE asMode; // DP Voltage swing mode + }; +- UCHAR ucConfig; +- /* [0]=0: 4 lane Link, */ +- /* =1: 8 lane Link ( Dual Links TMDS ) */ +- /* [1]=0: InCoherent mode */ +- /* =1: Coherent Mode */ +- /* [2] Link Select: */ +- /* =0: PHY linkA if bfLane<3 */ +- /* =1: PHY linkB if bfLanes<3 */ +- /* =0: PHY linkA+B if bfLanes=3 */ +- /* [5:4]PCIE lane Sel */ +- /* =0: lane 0~3 or 0~7 */ +- /* =1: lane 4~7 */ +- /* =2: lane 8~11 or 8~15 */ +- /* =3: lane 12~15 */ +- UCHAR ucAction; /* =0: turn off encoder */ +- /* =1: turn on encoder */ +- UCHAR ucReserved[4]; +-} DIG_TRANSMITTER_CONTROL_PARAMETERS; +- +-#define DIG_TRANSMITTER_CONTROL_PS_ALLOCATION DIG_TRANSMITTER_CONTROL_PARAMETERS +- +-/* ucInitInfo */ +-#define ATOM_TRAMITTER_INITINFO_CONNECTOR_MASK 0x00ff +- +-/* ucConfig */ ++ UCHAR ucConfig; ++ // [0]=0: 4 lane Link, ++ // =1: 8 lane Link ( Dual Links TMDS ) ++ // [1]=0: InCoherent mode ++ // =1: Coherent Mode ++ // [2] Link Select: ++ // =0: PHY linkA if bfLane<3 ++ // =1: PHY linkB if bfLanes<3 ++ // =0: PHY linkA+B if bfLanes=3 ++ // [5:4]PCIE lane Sel ++ // =0: lane 0~3 or 0~7 ++ // =1: lane 4~7 ++ // =2: lane 8~11 or 8~15 ++ // =3: lane 12~15 ++ UCHAR ucAction; // =0: turn off encoder ++ // =1: turn on encoder ++ UCHAR ucReserved[4]; ++}DIG_TRANSMITTER_CONTROL_PARAMETERS; ++ ++#define DIG_TRANSMITTER_CONTROL_PS_ALLOCATION DIG_TRANSMITTER_CONTROL_PARAMETERS ++ ++//ucInitInfo ++#define ATOM_TRAMITTER_INITINFO_CONNECTOR_MASK 0x00ff ++ ++//ucConfig + #define ATOM_TRANSMITTER_CONFIG_8LANE_LINK 0x01 + #define ATOM_TRANSMITTER_CONFIG_COHERENT 0x02 + #define ATOM_TRANSMITTER_CONFIG_LINK_SEL_MASK 0x04 + #define ATOM_TRANSMITTER_CONFIG_LINKA 0x00 + #define ATOM_TRANSMITTER_CONFIG_LINKB 0x04 +-#define ATOM_TRANSMITTER_CONFIG_LINKA_B 0x00 ++#define ATOM_TRANSMITTER_CONFIG_LINKA_B 0x00 + #define ATOM_TRANSMITTER_CONFIG_LINKB_A 0x04 + +-#define ATOM_TRANSMITTER_CONFIG_ENCODER_SEL_MASK 0x08 /* only used when ATOM_TRANSMITTER_ACTION_ENABLE */ +-#define ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER 0x00 /* only used when ATOM_TRANSMITTER_ACTION_ENABLE */ +-#define ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER 0x08 /* only used when ATOM_TRANSMITTER_ACTION_ENABLE */ ++#define ATOM_TRANSMITTER_CONFIG_ENCODER_SEL_MASK 0x08 // only used when ATOM_TRANSMITTER_ACTION_ENABLE ++#define ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER 0x00 // only used when ATOM_TRANSMITTER_ACTION_ENABLE ++#define ATOM_TRANSMITTER_CONFIG_DIG2_ENCODER 0x08 // only used when ATOM_TRANSMITTER_ACTION_ENABLE + + #define ATOM_TRANSMITTER_CONFIG_CLKSRC_MASK 0x30 + #define ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL 0x00 +@@ -661,7 +784,7 @@ typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS { + #define ATOM_TRANSMITTER_CONFIG_LANE_8_15 0x80 + #define ATOM_TRANSMITTER_CONFIG_LANE_12_15 0xc0 + +-/* ucAction */ ++//ucAction + #define ATOM_TRANSMITTER_ACTION_DISABLE 0 + #define ATOM_TRANSMITTER_ACTION_ENABLE 1 + #define ATOM_TRANSMITTER_ACTION_LCD_BLOFF 2 +@@ -674,93 +797,168 @@ typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS { + #define ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT 9 + #define ATOM_TRANSMITTER_ACTION_SETUP 10 + #define ATOM_TRANSMITTER_ACTION_SETUP_VSEMPH 11 ++#define ATOM_TRANSMITTER_ACTION_POWER_ON 12 ++#define ATOM_TRANSMITTER_ACTION_POWER_OFF 13 + +-/* Following are used for DigTransmitterControlTable ver1.2 */ +-typedef struct _ATOM_DIG_TRANSMITTER_CONFIG_V2 { ++// Following are used for DigTransmitterControlTable ver1.2 ++typedef struct _ATOM_DIG_TRANSMITTER_CONFIG_V2 ++{ + #if ATOM_BIG_ENDIAN +- UCHAR ucTransmitterSel:2; /* bit7:6: =0 Dig Transmitter 1 ( Uniphy AB ) */ +- /* =1 Dig Transmitter 2 ( Uniphy CD ) */ +- /* =2 Dig Transmitter 3 ( Uniphy EF ) */ +- UCHAR ucReserved:1; +- UCHAR fDPConnector:1; /* bit4=0: DP connector =1: None DP connector */ +- UCHAR ucEncoderSel:1; /* bit3=0: Data/Clk path source from DIGA( DIG inst0 ). =1: Data/clk path source from DIGB ( DIG inst1 ) */ +- UCHAR ucLinkSel:1; /* bit2=0: Uniphy LINKA or C or E when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is A or C or E */ +- /* =1: Uniphy LINKB or D or F when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is B or D or F */ +- +- UCHAR fCoherentMode:1; /* bit1=1: Coherent Mode ( for DVI/HDMI mode ) */ +- UCHAR fDualLinkConnector:1; /* bit0=1: Dual Link DVI connector */ ++ UCHAR ucTransmitterSel:2; //bit7:6: =0 Dig Transmitter 1 ( Uniphy AB ) ++ // =1 Dig Transmitter 2 ( Uniphy CD ) ++ // =2 Dig Transmitter 3 ( Uniphy EF ) ++ UCHAR ucReserved:1; ++ UCHAR fDPConnector:1; //bit4=0: DP connector =1: None DP connector ++ UCHAR ucEncoderSel:1; //bit3=0: Data/Clk path source from DIGA( DIG inst0 ). =1: Data/clk path source from DIGB ( DIG inst1 ) ++ UCHAR ucLinkSel:1; //bit2=0: Uniphy LINKA or C or E when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is A or C or E ++ // =1: Uniphy LINKB or D or F when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is B or D or F ++ ++ UCHAR fCoherentMode:1; //bit1=1: Coherent Mode ( for DVI/HDMI mode ) ++ UCHAR fDualLinkConnector:1; //bit0=1: Dual Link DVI connector + #else +- UCHAR fDualLinkConnector:1; /* bit0=1: Dual Link DVI connector */ +- UCHAR fCoherentMode:1; /* bit1=1: Coherent Mode ( for DVI/HDMI mode ) */ +- UCHAR ucLinkSel:1; /* bit2=0: Uniphy LINKA or C or E when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is A or C or E */ +- /* =1: Uniphy LINKB or D or F when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is B or D or F */ +- UCHAR ucEncoderSel:1; /* bit3=0: Data/Clk path source from DIGA( DIG inst0 ). =1: Data/clk path source from DIGB ( DIG inst1 ) */ +- UCHAR fDPConnector:1; /* bit4=0: DP connector =1: None DP connector */ +- UCHAR ucReserved:1; +- UCHAR ucTransmitterSel:2; /* bit7:6: =0 Dig Transmitter 1 ( Uniphy AB ) */ +- /* =1 Dig Transmitter 2 ( Uniphy CD ) */ +- /* =2 Dig Transmitter 3 ( Uniphy EF ) */ ++ UCHAR fDualLinkConnector:1; //bit0=1: Dual Link DVI connector ++ UCHAR fCoherentMode:1; //bit1=1: Coherent Mode ( for DVI/HDMI mode ) ++ UCHAR ucLinkSel:1; //bit2=0: Uniphy LINKA or C or E when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is A or C or E ++ // =1: Uniphy LINKB or D or F when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is B or D or F ++ UCHAR ucEncoderSel:1; //bit3=0: Data/Clk path source from DIGA( DIG inst0 ). =1: Data/clk path source from DIGB ( DIG inst1 ) ++ UCHAR fDPConnector:1; //bit4=0: DP connector =1: None DP connector ++ UCHAR ucReserved:1; ++ UCHAR ucTransmitterSel:2; //bit7:6: =0 Dig Transmitter 1 ( Uniphy AB ) ++ // =1 Dig Transmitter 2 ( Uniphy CD ) ++ // =2 Dig Transmitter 3 ( Uniphy EF ) + #endif +-} ATOM_DIG_TRANSMITTER_CONFIG_V2; ++}ATOM_DIG_TRANSMITTER_CONFIG_V2; + +-/* ucConfig */ +-/* Bit0 */ ++//ucConfig ++//Bit0 + #define ATOM_TRANSMITTER_CONFIG_V2_DUAL_LINK_CONNECTOR 0x01 + +-/* Bit1 */ ++//Bit1 + #define ATOM_TRANSMITTER_CONFIG_V2_COHERENT 0x02 + +-/* Bit2 */ ++//Bit2 + #define ATOM_TRANSMITTER_CONFIG_V2_LINK_SEL_MASK 0x04 +-#define ATOM_TRANSMITTER_CONFIG_V2_LINKA 0x00 ++#define ATOM_TRANSMITTER_CONFIG_V2_LINKA 0x00 + #define ATOM_TRANSMITTER_CONFIG_V2_LINKB 0x04 + +-/* Bit3 */ ++// Bit3 + #define ATOM_TRANSMITTER_CONFIG_V2_ENCODER_SEL_MASK 0x08 +-#define ATOM_TRANSMITTER_CONFIG_V2_DIG1_ENCODER 0x00 /* only used when ucAction == ATOM_TRANSMITTER_ACTION_ENABLE or ATOM_TRANSMITTER_ACTION_SETUP */ +-#define ATOM_TRANSMITTER_CONFIG_V2_DIG2_ENCODER 0x08 /* only used when ucAction == ATOM_TRANSMITTER_ACTION_ENABLE or ATOM_TRANSMITTER_ACTION_SETUP */ ++#define ATOM_TRANSMITTER_CONFIG_V2_DIG1_ENCODER 0x00 // only used when ucAction == ATOM_TRANSMITTER_ACTION_ENABLE or ATOM_TRANSMITTER_ACTION_SETUP ++#define ATOM_TRANSMITTER_CONFIG_V2_DIG2_ENCODER 0x08 // only used when ucAction == ATOM_TRANSMITTER_ACTION_ENABLE or ATOM_TRANSMITTER_ACTION_SETUP + +-/* Bit4 */ ++// Bit4 + #define ATOM_TRASMITTER_CONFIG_V2_DP_CONNECTOR 0x10 + +-/* Bit7:6 */ ++// Bit7:6 + #define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER_SEL_MASK 0xC0 +-#define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER1 0x00 /* AB */ +-#define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER2 0x40 /* CD */ +-#define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER3 0x80 /* EF */ +- +-typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 { +- union { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- USHORT usInitInfo; /* when init uniphy,lower 8bit is used for connector type defined in objectid.h */ +- ATOM_DP_VS_MODE asMode; /* DP Voltage swing mode */ ++#define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER1 0x00 //AB ++#define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER2 0x40 //CD ++#define ATOM_TRANSMITTER_CONFIG_V2_TRANSMITTER3 0x80 //EF ++ ++typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 ++{ ++ union ++ { ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ USHORT usInitInfo; // when init uniphy,lower 8bit is used for connector type defined in objectid.h ++ ATOM_DP_VS_MODE asMode; // DP Voltage swing mode + }; +- ATOM_DIG_TRANSMITTER_CONFIG_V2 acConfig; +- UCHAR ucAction; /* define as ATOM_TRANSMITER_ACTION_XXX */ +- UCHAR ucReserved[4]; +-} DIG_TRANSMITTER_CONTROL_PARAMETERS_V2; ++ ATOM_DIG_TRANSMITTER_CONFIG_V2 acConfig; ++ UCHAR ucAction; // define as ATOM_TRANSMITER_ACTION_XXX ++ UCHAR ucReserved[4]; ++}DIG_TRANSMITTER_CONTROL_PARAMETERS_V2; + +-/****************************************************************************/ +-/* Structures used by DAC1OuputControlTable */ +-/* DAC2OuputControlTable */ +-/* LVTMAOutputControlTable (Before DEC30) */ +-/* TMDSAOutputControlTable (Before DEC30) */ +-/****************************************************************************/ +-typedef struct _DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS { +- UCHAR ucAction; /* Possible input:ATOM_ENABLE||ATOMDISABLE */ +- /* When the display is LCD, in addition to above: */ +- /* ATOM_LCD_BLOFF|| ATOM_LCD_BLON ||ATOM_LCD_BL_BRIGHTNESS_CONTROL||ATOM_LCD_SELFTEST_START|| */ +- /* ATOM_LCD_SELFTEST_STOP */ ++typedef struct _ATOM_DIG_TRANSMITTER_CONFIG_V3 ++{ ++#if ATOM_BIG_ENDIAN ++ UCHAR ucTransmitterSel:2; //bit7:6: =0 Dig Transmitter 1 ( Uniphy AB ) ++ // =1 Dig Transmitter 2 ( Uniphy CD ) ++ // =2 Dig Transmitter 3 ( Uniphy EF ) ++ UCHAR ucRefClkSource:2; //bit5:4: PPLL1 =0, PPLL2=1, EXT_CLK=2 ++ UCHAR ucEncoderSel:1; //bit3=0: Data/Clk path source from DIGA/C/E. =1: Data/clk path source from DIGB/D/F ++ UCHAR ucLinkSel:1; //bit2=0: Uniphy LINKA or C or E when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is A or C or E ++ // =1: Uniphy LINKB or D or F when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is B or D or F ++ UCHAR fCoherentMode:1; //bit1=1: Coherent Mode ( for DVI/HDMI mode ) ++ UCHAR fDualLinkConnector:1; //bit0=1: Dual Link DVI connector ++#else ++ UCHAR fDualLinkConnector:1; //bit0=1: Dual Link DVI connector ++ UCHAR fCoherentMode:1; //bit1=1: Coherent Mode ( for DVI/HDMI mode ) ++ UCHAR ucLinkSel:1; //bit2=0: Uniphy LINKA or C or E when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is A or C or E ++ // =1: Uniphy LINKB or D or F when fDualLinkConnector=0. when fDualLinkConnector=1, it means master link of dual link is B or D or F ++ UCHAR ucEncoderSel:1; //bit3=0: Data/Clk path source from DIGA/C/E. =1: Data/clk path source from DIGB/D/F ++ UCHAR ucRefClkSource:2; //bit5:4: PPLL1 =0, PPLL2=1, EXT_CLK=2 ++ UCHAR ucTransmitterSel:2; //bit7:6: =0 Dig Transmitter 1 ( Uniphy AB ) ++ // =1 Dig Transmitter 2 ( Uniphy CD ) ++ // =2 Dig Transmitter 3 ( Uniphy EF ) ++#endif ++}ATOM_DIG_TRANSMITTER_CONFIG_V3; + +- UCHAR aucPadding[3]; /* padding to DWORD aligned */ +-} DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS; ++typedef struct _DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 ++{ ++ union ++ { ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ USHORT usInitInfo; // when init uniphy,lower 8bit is used for connector type defined in objectid.h ++ ATOM_DP_VS_MODE asMode; // DP Voltage swing mode ++ }; ++ ATOM_DIG_TRANSMITTER_CONFIG_V3 acConfig; ++ UCHAR ucAction; // define as ATOM_TRANSMITER_ACTION_XXX ++ UCHAR ucLaneNum; ++ UCHAR ucReserved[3]; ++}DIG_TRANSMITTER_CONTROL_PARAMETERS_V3; ++ ++//ucConfig ++//Bit0 ++#define ATOM_TRANSMITTER_CONFIG_V3_DUAL_LINK_CONNECTOR 0x01 ++ ++//Bit1 ++#define ATOM_TRANSMITTER_CONFIG_V3_COHERENT 0x02 ++ ++//Bit2 ++#define ATOM_TRANSMITTER_CONFIG_V3_LINK_SEL_MASK 0x04 ++#define ATOM_TRANSMITTER_CONFIG_V3_LINKA 0x00 ++#define ATOM_TRANSMITTER_CONFIG_V3_LINKB 0x04 ++ ++// Bit3 ++#define ATOM_TRANSMITTER_CONFIG_V3_ENCODER_SEL_MASK 0x08 ++#define ATOM_TRANSMITTER_CONFIG_V3_DIG1_ENCODER 0x00 ++#define ATOM_TRANSMITTER_CONFIG_V3_DIG2_ENCODER 0x08 ++ ++// Bit5:4 ++#define ATOM_TRASMITTER_CONFIG_V3_REFCLK_SEL_MASK 0x30 ++#define ATOM_TRASMITTER_CONFIG_V3_P1PLL 0x00 ++#define ATOM_TRASMITTER_CONFIG_V3_P2PLL 0x10 ++#define ATOM_TRASMITTER_CONFIG_V3_REFCLK_SRC_EXT 0x20 ++ ++// Bit7:6 ++#define ATOM_TRANSMITTER_CONFIG_V3_TRANSMITTER_SEL_MASK 0xC0 ++#define ATOM_TRANSMITTER_CONFIG_V3_TRANSMITTER1 0x00 //AB ++#define ATOM_TRANSMITTER_CONFIG_V3_TRANSMITTER2 0x40 //CD ++#define ATOM_TRANSMITTER_CONFIG_V3_TRANSMITTER3 0x80 //EF ++ ++/****************************************************************************/ ++// Structures used by DAC1OuputControlTable ++// DAC2OuputControlTable ++// LVTMAOutputControlTable (Before DEC30) ++// TMDSAOutputControlTable (Before DEC30) ++/****************************************************************************/ ++typedef struct _DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS ++{ ++ UCHAR ucAction; // Possible input:ATOM_ENABLE||ATOMDISABLE ++ // When the display is LCD, in addition to above: ++ // ATOM_LCD_BLOFF|| ATOM_LCD_BLON ||ATOM_LCD_BL_BRIGHTNESS_CONTROL||ATOM_LCD_SELFTEST_START|| ++ // ATOM_LCD_SELFTEST_STOP ++ ++ UCHAR aucPadding[3]; // padding to DWORD aligned ++}DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS; + + #define DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS + +-#define CRT1_OUTPUT_CONTROL_PARAMETERS DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS ++ ++#define CRT1_OUTPUT_CONTROL_PARAMETERS DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS + #define CRT1_OUTPUT_CONTROL_PS_ALLOCATION DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION + +-#define CRT2_OUTPUT_CONTROL_PARAMETERS DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS ++#define CRT2_OUTPUT_CONTROL_PARAMETERS DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS + #define CRT2_OUTPUT_CONTROL_PS_ALLOCATION DISPLAY_DEVICE_OUTPUT_CONTROL_PS_ALLOCATION + + #define CV1_OUTPUT_CONTROL_PARAMETERS DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS +@@ -782,397 +980,550 @@ typedef struct _DISPLAY_DEVICE_OUTPUT_CONTROL_PARAMETERS { + #define DVO_OUTPUT_CONTROL_PS_ALLOCATION DIG_TRANSMITTER_CONTROL_PS_ALLOCATION + #define DVO_OUTPUT_CONTROL_PARAMETERS_V3 DIG_TRANSMITTER_CONTROL_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by BlankCRTCTable */ +-/****************************************************************************/ +-typedef struct _BLANK_CRTC_PARAMETERS { +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucBlanking; /* ATOM_BLANKING or ATOM_BLANKINGOFF */ +- USHORT usBlackColorRCr; +- USHORT usBlackColorGY; +- USHORT usBlackColorBCb; +-} BLANK_CRTC_PARAMETERS; ++/****************************************************************************/ ++// Structures used by BlankCRTCTable ++/****************************************************************************/ ++typedef struct _BLANK_CRTC_PARAMETERS ++{ ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucBlanking; // ATOM_BLANKING or ATOM_BLANKINGOFF ++ USHORT usBlackColorRCr; ++ USHORT usBlackColorGY; ++ USHORT usBlackColorBCb; ++}BLANK_CRTC_PARAMETERS; + #define BLANK_CRTC_PS_ALLOCATION BLANK_CRTC_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by EnableCRTCTable */ +-/* EnableCRTCMemReqTable */ +-/* UpdateCRTC_DoubleBufferRegistersTable */ +-/****************************************************************************/ +-typedef struct _ENABLE_CRTC_PARAMETERS { +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucPadding[2]; +-} ENABLE_CRTC_PARAMETERS; ++/****************************************************************************/ ++// Structures used by EnableCRTCTable ++// EnableCRTCMemReqTable ++// UpdateCRTC_DoubleBufferRegistersTable ++/****************************************************************************/ ++typedef struct _ENABLE_CRTC_PARAMETERS ++{ ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucPadding[2]; ++}ENABLE_CRTC_PARAMETERS; + #define ENABLE_CRTC_PS_ALLOCATION ENABLE_CRTC_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by SetCRTC_OverScanTable */ +-/****************************************************************************/ +-typedef struct _SET_CRTC_OVERSCAN_PARAMETERS { +- USHORT usOverscanRight; /* right */ +- USHORT usOverscanLeft; /* left */ +- USHORT usOverscanBottom; /* bottom */ +- USHORT usOverscanTop; /* top */ +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucPadding[3]; +-} SET_CRTC_OVERSCAN_PARAMETERS; ++/****************************************************************************/ ++// Structures used by SetCRTC_OverScanTable ++/****************************************************************************/ ++typedef struct _SET_CRTC_OVERSCAN_PARAMETERS ++{ ++ USHORT usOverscanRight; // right ++ USHORT usOverscanLeft; // left ++ USHORT usOverscanBottom; // bottom ++ USHORT usOverscanTop; // top ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucPadding[3]; ++}SET_CRTC_OVERSCAN_PARAMETERS; + #define SET_CRTC_OVERSCAN_PS_ALLOCATION SET_CRTC_OVERSCAN_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by SetCRTC_ReplicationTable */ +-/****************************************************************************/ +-typedef struct _SET_CRTC_REPLICATION_PARAMETERS { +- UCHAR ucH_Replication; /* horizontal replication */ +- UCHAR ucV_Replication; /* vertical replication */ +- UCHAR usCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucPadding; +-} SET_CRTC_REPLICATION_PARAMETERS; ++/****************************************************************************/ ++// Structures used by SetCRTC_ReplicationTable ++/****************************************************************************/ ++typedef struct _SET_CRTC_REPLICATION_PARAMETERS ++{ ++ UCHAR ucH_Replication; // horizontal replication ++ UCHAR ucV_Replication; // vertical replication ++ UCHAR usCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucPadding; ++}SET_CRTC_REPLICATION_PARAMETERS; + #define SET_CRTC_REPLICATION_PS_ALLOCATION SET_CRTC_REPLICATION_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by SelectCRTC_SourceTable */ +-/****************************************************************************/ +-typedef struct _SELECT_CRTC_SOURCE_PARAMETERS { +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucDevice; /* ATOM_DEVICE_CRT1|ATOM_DEVICE_CRT2|.... */ +- UCHAR ucPadding[2]; +-} SELECT_CRTC_SOURCE_PARAMETERS; ++/****************************************************************************/ ++// Structures used by SelectCRTC_SourceTable ++/****************************************************************************/ ++typedef struct _SELECT_CRTC_SOURCE_PARAMETERS ++{ ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucDevice; // ATOM_DEVICE_CRT1|ATOM_DEVICE_CRT2|.... ++ UCHAR ucPadding[2]; ++}SELECT_CRTC_SOURCE_PARAMETERS; + #define SELECT_CRTC_SOURCE_PS_ALLOCATION SELECT_CRTC_SOURCE_PARAMETERS + +-typedef struct _SELECT_CRTC_SOURCE_PARAMETERS_V2 { +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucEncoderID; /* DAC1/DAC2/TVOUT/DIG1/DIG2/DVO */ +- UCHAR ucEncodeMode; /* Encoding mode, only valid when using DIG1/DIG2/DVO */ +- UCHAR ucPadding; +-} SELECT_CRTC_SOURCE_PARAMETERS_V2; +- +-/* ucEncoderID */ +-/* #define ASIC_INT_DAC1_ENCODER_ID 0x00 */ +-/* #define ASIC_INT_TV_ENCODER_ID 0x02 */ +-/* #define ASIC_INT_DIG1_ENCODER_ID 0x03 */ +-/* #define ASIC_INT_DAC2_ENCODER_ID 0x04 */ +-/* #define ASIC_EXT_TV_ENCODER_ID 0x06 */ +-/* #define ASIC_INT_DVO_ENCODER_ID 0x07 */ +-/* #define ASIC_INT_DIG2_ENCODER_ID 0x09 */ +-/* #define ASIC_EXT_DIG_ENCODER_ID 0x05 */ +- +-/* ucEncodeMode */ +-/* #define ATOM_ENCODER_MODE_DP 0 */ +-/* #define ATOM_ENCODER_MODE_LVDS 1 */ +-/* #define ATOM_ENCODER_MODE_DVI 2 */ +-/* #define ATOM_ENCODER_MODE_HDMI 3 */ +-/* #define ATOM_ENCODER_MODE_SDVO 4 */ +-/* #define ATOM_ENCODER_MODE_TV 13 */ +-/* #define ATOM_ENCODER_MODE_CV 14 */ +-/* #define ATOM_ENCODER_MODE_CRT 15 */ +- +-/****************************************************************************/ +-/* Structures used by SetPixelClockTable */ +-/* GetPixelClockTable */ +-/****************************************************************************/ +-/* Major revision=1., Minor revision=1 */ +-typedef struct _PIXEL_CLOCK_PARAMETERS { +- USHORT usPixelClock; /* in 10kHz unit; for bios convenient = (RefClk*FB_Div)/(Ref_Div*Post_Div) */ +- /* 0 means disable PPLL */ +- USHORT usRefDiv; /* Reference divider */ +- USHORT usFbDiv; /* feedback divider */ +- UCHAR ucPostDiv; /* post divider */ +- UCHAR ucFracFbDiv; /* fractional feedback divider */ +- UCHAR ucPpll; /* ATOM_PPLL1 or ATOM_PPL2 */ +- UCHAR ucRefDivSrc; /* ATOM_PJITTER or ATO_NONPJITTER */ +- UCHAR ucCRTC; /* Which CRTC uses this Ppll */ +- UCHAR ucPadding; +-} PIXEL_CLOCK_PARAMETERS; +- +-/* Major revision=1., Minor revision=2, add ucMiscIfno */ +-/* ucMiscInfo: */ ++typedef struct _SELECT_CRTC_SOURCE_PARAMETERS_V2 ++{ ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucEncoderID; // DAC1/DAC2/TVOUT/DIG1/DIG2/DVO ++ UCHAR ucEncodeMode; // Encoding mode, only valid when using DIG1/DIG2/DVO ++ UCHAR ucPadding; ++}SELECT_CRTC_SOURCE_PARAMETERS_V2; ++ ++//ucEncoderID ++//#define ASIC_INT_DAC1_ENCODER_ID 0x00 ++//#define ASIC_INT_TV_ENCODER_ID 0x02 ++//#define ASIC_INT_DIG1_ENCODER_ID 0x03 ++//#define ASIC_INT_DAC2_ENCODER_ID 0x04 ++//#define ASIC_EXT_TV_ENCODER_ID 0x06 ++//#define ASIC_INT_DVO_ENCODER_ID 0x07 ++//#define ASIC_INT_DIG2_ENCODER_ID 0x09 ++//#define ASIC_EXT_DIG_ENCODER_ID 0x05 ++ ++//ucEncodeMode ++//#define ATOM_ENCODER_MODE_DP 0 ++//#define ATOM_ENCODER_MODE_LVDS 1 ++//#define ATOM_ENCODER_MODE_DVI 2 ++//#define ATOM_ENCODER_MODE_HDMI 3 ++//#define ATOM_ENCODER_MODE_SDVO 4 ++//#define ATOM_ENCODER_MODE_TV 13 ++//#define ATOM_ENCODER_MODE_CV 14 ++//#define ATOM_ENCODER_MODE_CRT 15 ++ ++/****************************************************************************/ ++// Structures used by SetPixelClockTable ++// GetPixelClockTable ++/****************************************************************************/ ++//Major revision=1., Minor revision=1 ++typedef struct _PIXEL_CLOCK_PARAMETERS ++{ ++ USHORT usPixelClock; // in 10kHz unit; for bios convenient = (RefClk*FB_Div)/(Ref_Div*Post_Div) ++ // 0 means disable PPLL ++ USHORT usRefDiv; // Reference divider ++ USHORT usFbDiv; // feedback divider ++ UCHAR ucPostDiv; // post divider ++ UCHAR ucFracFbDiv; // fractional feedback divider ++ UCHAR ucPpll; // ATOM_PPLL1 or ATOM_PPL2 ++ UCHAR ucRefDivSrc; // ATOM_PJITTER or ATO_NONPJITTER ++ UCHAR ucCRTC; // Which CRTC uses this Ppll ++ UCHAR ucPadding; ++}PIXEL_CLOCK_PARAMETERS; ++ ++//Major revision=1., Minor revision=2, add ucMiscIfno ++//ucMiscInfo: + #define MISC_FORCE_REPROG_PIXEL_CLOCK 0x1 + #define MISC_DEVICE_INDEX_MASK 0xF0 + #define MISC_DEVICE_INDEX_SHIFT 4 + +-typedef struct _PIXEL_CLOCK_PARAMETERS_V2 { +- USHORT usPixelClock; /* in 10kHz unit; for bios convenient = (RefClk*FB_Div)/(Ref_Div*Post_Div) */ +- /* 0 means disable PPLL */ +- USHORT usRefDiv; /* Reference divider */ +- USHORT usFbDiv; /* feedback divider */ +- UCHAR ucPostDiv; /* post divider */ +- UCHAR ucFracFbDiv; /* fractional feedback divider */ +- UCHAR ucPpll; /* ATOM_PPLL1 or ATOM_PPL2 */ +- UCHAR ucRefDivSrc; /* ATOM_PJITTER or ATO_NONPJITTER */ +- UCHAR ucCRTC; /* Which CRTC uses this Ppll */ +- UCHAR ucMiscInfo; /* Different bits for different purpose, bit [7:4] as device index, bit[0]=Force prog */ +-} PIXEL_CLOCK_PARAMETERS_V2; +- +-/* Major revision=1., Minor revision=3, structure/definition change */ +-/* ucEncoderMode: */ +-/* ATOM_ENCODER_MODE_DP */ +-/* ATOM_ENOCDER_MODE_LVDS */ +-/* ATOM_ENOCDER_MODE_DVI */ +-/* ATOM_ENOCDER_MODE_HDMI */ +-/* ATOM_ENOCDER_MODE_SDVO */ +-/* ATOM_ENCODER_MODE_TV 13 */ +-/* ATOM_ENCODER_MODE_CV 14 */ +-/* ATOM_ENCODER_MODE_CRT 15 */ +- +-/* ucDVOConfig */ +-/* #define DVO_ENCODER_CONFIG_RATE_SEL 0x01 */ +-/* #define DVO_ENCODER_CONFIG_DDR_SPEED 0x00 */ +-/* #define DVO_ENCODER_CONFIG_SDR_SPEED 0x01 */ +-/* #define DVO_ENCODER_CONFIG_OUTPUT_SEL 0x0c */ +-/* #define DVO_ENCODER_CONFIG_LOW12BIT 0x00 */ +-/* #define DVO_ENCODER_CONFIG_UPPER12BIT 0x04 */ +-/* #define DVO_ENCODER_CONFIG_24BIT 0x08 */ +- +-/* ucMiscInfo: also changed, see below */ ++typedef struct _PIXEL_CLOCK_PARAMETERS_V2 ++{ ++ USHORT usPixelClock; // in 10kHz unit; for bios convenient = (RefClk*FB_Div)/(Ref_Div*Post_Div) ++ // 0 means disable PPLL ++ USHORT usRefDiv; // Reference divider ++ USHORT usFbDiv; // feedback divider ++ UCHAR ucPostDiv; // post divider ++ UCHAR ucFracFbDiv; // fractional feedback divider ++ UCHAR ucPpll; // ATOM_PPLL1 or ATOM_PPL2 ++ UCHAR ucRefDivSrc; // ATOM_PJITTER or ATO_NONPJITTER ++ UCHAR ucCRTC; // Which CRTC uses this Ppll ++ UCHAR ucMiscInfo; // Different bits for different purpose, bit [7:4] as device index, bit[0]=Force prog ++}PIXEL_CLOCK_PARAMETERS_V2; ++ ++//Major revision=1., Minor revision=3, structure/definition change ++//ucEncoderMode: ++//ATOM_ENCODER_MODE_DP ++//ATOM_ENOCDER_MODE_LVDS ++//ATOM_ENOCDER_MODE_DVI ++//ATOM_ENOCDER_MODE_HDMI ++//ATOM_ENOCDER_MODE_SDVO ++//ATOM_ENCODER_MODE_TV 13 ++//ATOM_ENCODER_MODE_CV 14 ++//ATOM_ENCODER_MODE_CRT 15 ++ ++//ucDVOConfig ++//#define DVO_ENCODER_CONFIG_RATE_SEL 0x01 ++//#define DVO_ENCODER_CONFIG_DDR_SPEED 0x00 ++//#define DVO_ENCODER_CONFIG_SDR_SPEED 0x01 ++//#define DVO_ENCODER_CONFIG_OUTPUT_SEL 0x0c ++//#define DVO_ENCODER_CONFIG_LOW12BIT 0x00 ++//#define DVO_ENCODER_CONFIG_UPPER12BIT 0x04 ++//#define DVO_ENCODER_CONFIG_24BIT 0x08 ++ ++//ucMiscInfo: also changed, see below + #define PIXEL_CLOCK_MISC_FORCE_PROG_PPLL 0x01 + #define PIXEL_CLOCK_MISC_VGA_MODE 0x02 + #define PIXEL_CLOCK_MISC_CRTC_SEL_MASK 0x04 + #define PIXEL_CLOCK_MISC_CRTC_SEL_CRTC1 0x00 + #define PIXEL_CLOCK_MISC_CRTC_SEL_CRTC2 0x04 + #define PIXEL_CLOCK_MISC_USE_ENGINE_FOR_DISPCLK 0x08 ++#define PIXEL_CLOCK_MISC_REF_DIV_SRC 0x10 ++// V1.4 for RoadRunner ++#define PIXEL_CLOCK_V4_MISC_SS_ENABLE 0x10 ++#define PIXEL_CLOCK_V4_MISC_COHERENT_MODE 0x20 + +-typedef struct _PIXEL_CLOCK_PARAMETERS_V3 { +- USHORT usPixelClock; /* in 10kHz unit; for bios convenient = (RefClk*FB_Div)/(Ref_Div*Post_Div) */ +- /* 0 means disable PPLL. For VGA PPLL,make sure this value is not 0. */ +- USHORT usRefDiv; /* Reference divider */ +- USHORT usFbDiv; /* feedback divider */ +- UCHAR ucPostDiv; /* post divider */ +- UCHAR ucFracFbDiv; /* fractional feedback divider */ +- UCHAR ucPpll; /* ATOM_PPLL1 or ATOM_PPL2 */ +- UCHAR ucTransmitterId; /* graphic encoder id defined in objectId.h */ +- union { +- UCHAR ucEncoderMode; /* encoder type defined as ATOM_ENCODER_MODE_DP/DVI/HDMI/ */ +- UCHAR ucDVOConfig; /* when use DVO, need to know SDR/DDR, 12bit or 24bit */ ++typedef struct _PIXEL_CLOCK_PARAMETERS_V3 ++{ ++ USHORT usPixelClock; // in 10kHz unit; for bios convenient = (RefClk*FB_Div)/(Ref_Div*Post_Div) ++ // 0 means disable PPLL. For VGA PPLL,make sure this value is not 0. ++ USHORT usRefDiv; // Reference divider ++ USHORT usFbDiv; // feedback divider ++ UCHAR ucPostDiv; // post divider ++ UCHAR ucFracFbDiv; // fractional feedback divider ++ UCHAR ucPpll; // ATOM_PPLL1 or ATOM_PPL2 ++ UCHAR ucTransmitterId; // graphic encoder id defined in objectId.h ++ union ++ { ++ UCHAR ucEncoderMode; // encoder type defined as ATOM_ENCODER_MODE_DP/DVI/HDMI/ ++ UCHAR ucDVOConfig; // when use DVO, need to know SDR/DDR, 12bit or 24bit + }; +- UCHAR ucMiscInfo; /* bit[0]=Force program, bit[1]= set pclk for VGA, b[2]= CRTC sel */ +- /* bit[3]=0:use PPLL for dispclk source, =1: use engine clock for dispclock source */ +-} PIXEL_CLOCK_PARAMETERS_V3; ++ UCHAR ucMiscInfo; // bit[0]=Force program, bit[1]= set pclk for VGA, b[2]= CRTC sel ++ // bit[3]=0:use PPLL for dispclk source, =1: use engine clock for dispclock source ++ // bit[4]=0:use XTALIN as the source of reference divider,=1 use the pre-defined clock as the source of reference divider ++}PIXEL_CLOCK_PARAMETERS_V3; + + #define PIXEL_CLOCK_PARAMETERS_LAST PIXEL_CLOCK_PARAMETERS_V2 + #define GET_PIXEL_CLOCK_PS_ALLOCATION PIXEL_CLOCK_PARAMETERS_LAST + +-/****************************************************************************/ +-/* Structures used by AdjustDisplayPllTable */ +-/****************************************************************************/ +-typedef struct _ADJUST_DISPLAY_PLL_PARAMETERS { ++typedef struct _PIXEL_CLOCK_PARAMETERS_V5 ++{ ++ UCHAR ucCRTC; // ATOM_CRTC1~6, indicate the CRTC controller to ++ // drive the pixel clock. not used for DCPLL case. ++ union{ ++ UCHAR ucReserved; ++ UCHAR ucFracFbDiv; // [gphan] temporary to prevent build problem. remove it after driver code is changed. ++ }; ++ USHORT usPixelClock; // target the pixel clock to drive the CRTC timing ++ // 0 means disable PPLL/DCPLL. ++ USHORT usFbDiv; // feedback divider integer part. ++ UCHAR ucPostDiv; // post divider. ++ UCHAR ucRefDiv; // Reference divider ++ UCHAR ucPpll; // ATOM_PPLL1/ATOM_PPLL2/ATOM_DCPLL ++ UCHAR ucTransmitterID; // ASIC encoder id defined in objectId.h, ++ // indicate which graphic encoder will be used. ++ UCHAR ucEncoderMode; // Encoder mode: ++ UCHAR ucMiscInfo; // bit[0]= Force program PPLL ++ // bit[1]= when VGA timing is used. ++ // bit[3:2]= HDMI panel bit depth: =0: 24bpp =1:30bpp, =2:32bpp ++ // bit[4]= RefClock source for PPLL. ++ // =0: XTLAIN( default mode ) ++ // =1: other external clock source, which is pre-defined ++ // by VBIOS depend on the feature required. ++ // bit[7:5]: reserved. ++ ULONG ulFbDivDecFrac; // 20 bit feedback divider decimal fraction part, range from 1~999999 ( 0.000001 to 0.999999 ) ++ ++}PIXEL_CLOCK_PARAMETERS_V5; ++ ++#define PIXEL_CLOCK_V5_MISC_FORCE_PROG_PPLL 0x01 ++#define PIXEL_CLOCK_V5_MISC_VGA_MODE 0x02 ++#define PIXEL_CLOCK_V5_MISC_HDMI_BPP_MASK 0x0c ++#define PIXEL_CLOCK_V5_MISC_HDMI_24BPP 0x00 ++#define PIXEL_CLOCK_V5_MISC_HDMI_30BPP 0x04 ++#define PIXEL_CLOCK_V5_MISC_HDMI_32BPP 0x08 ++#define PIXEL_CLOCK_V5_MISC_REF_DIV_SRC 0x10 ++ ++typedef struct _GET_DISP_PLL_STATUS_INPUT_PARAMETERS_V2 ++{ ++ PIXEL_CLOCK_PARAMETERS_V3 sDispClkInput; ++}GET_DISP_PLL_STATUS_INPUT_PARAMETERS_V2; ++ ++typedef struct _GET_DISP_PLL_STATUS_OUTPUT_PARAMETERS_V2 ++{ ++ UCHAR ucStatus; ++ UCHAR ucRefDivSrc; // =1: reference clock source from XTALIN, =0: source from PCIE ref clock ++ UCHAR ucReserved[2]; ++}GET_DISP_PLL_STATUS_OUTPUT_PARAMETERS_V2; ++ ++typedef struct _GET_DISP_PLL_STATUS_INPUT_PARAMETERS_V3 ++{ ++ PIXEL_CLOCK_PARAMETERS_V5 sDispClkInput; ++}GET_DISP_PLL_STATUS_INPUT_PARAMETERS_V3; ++ ++/****************************************************************************/ ++// Structures used by AdjustDisplayPllTable ++/****************************************************************************/ ++typedef struct _ADJUST_DISPLAY_PLL_PARAMETERS ++{ + USHORT usPixelClock; + UCHAR ucTransmitterID; + UCHAR ucEncodeMode; +- union { +- UCHAR ucDVOConfig; /* if DVO, need passing link rate and output 12bitlow or 24bit */ +- UCHAR ucConfig; /* if none DVO, not defined yet */ ++ union ++ { ++ UCHAR ucDVOConfig; //if DVO, need passing link rate and output 12bitlow or 24bit ++ UCHAR ucConfig; //if none DVO, not defined yet + }; + UCHAR ucReserved[3]; +-} ADJUST_DISPLAY_PLL_PARAMETERS; ++}ADJUST_DISPLAY_PLL_PARAMETERS; + + #define ADJUST_DISPLAY_CONFIG_SS_ENABLE 0x10 +- + #define ADJUST_DISPLAY_PLL_PS_ALLOCATION ADJUST_DISPLAY_PLL_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by EnableYUVTable */ +-/****************************************************************************/ +-typedef struct _ENABLE_YUV_PARAMETERS { +- UCHAR ucEnable; /* ATOM_ENABLE:Enable YUV or ATOM_DISABLE:Disable YUV (RGB) */ +- UCHAR ucCRTC; /* Which CRTC needs this YUV or RGB format */ +- UCHAR ucPadding[2]; +-} ENABLE_YUV_PARAMETERS; ++typedef struct _ADJUST_DISPLAY_PLL_INPUT_PARAMETERS_V3 ++{ ++ USHORT usPixelClock; // target pixel clock ++ UCHAR ucTransmitterID; // transmitter id defined in objectid.h ++ UCHAR ucEncodeMode; // encoder mode: CRT, LVDS, DP, TMDS or HDMI ++ UCHAR ucDispPllConfig; // display pll configure parameter defined as following DISPPLL_CONFIG_XXXX ++ UCHAR ucReserved[3]; ++}ADJUST_DISPLAY_PLL_INPUT_PARAMETERS_V3; ++ ++// usDispPllConfig v1.2 for RoadRunner ++#define DISPPLL_CONFIG_DVO_RATE_SEL 0x0001 // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_DVO_DDR_SPEED 0x0000 // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_DVO_SDR_SPEED 0x0001 // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_DVO_OUTPUT_SEL 0x000c // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_DVO_LOW12BIT 0x0000 // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_DVO_UPPER12BIT 0x0004 // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_DVO_24BIT 0x0008 // need only when ucTransmitterID = DVO ++#define DISPPLL_CONFIG_SS_ENABLE 0x0010 // Only used when ucEncoderMode = DP or LVDS ++#define DISPPLL_CONFIG_COHERENT_MODE 0x0020 // Only used when ucEncoderMode = TMDS or HDMI ++#define DISPPLL_CONFIG_DUAL_LINK 0x0040 // Only used when ucEncoderMode = TMDS or LVDS ++ ++ ++typedef struct _ADJUST_DISPLAY_PLL_OUTPUT_PARAMETERS_V3 ++{ ++ ULONG ulDispPllFreq; // return display PPLL freq which is used to generate the pixclock, and related idclk, symclk etc ++ UCHAR ucRefDiv; // if it is none-zero, it is used to be calculated the other ppll parameter fb_divider and post_div ( if it is not given ) ++ UCHAR ucPostDiv; // if it is none-zero, it is used to be calculated the other ppll parameter fb_divider ++ UCHAR ucReserved[2]; ++}ADJUST_DISPLAY_PLL_OUTPUT_PARAMETERS_V3; ++ ++typedef struct _ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 ++{ ++ union ++ { ++ ADJUST_DISPLAY_PLL_INPUT_PARAMETERS_V3 sInput; ++ ADJUST_DISPLAY_PLL_OUTPUT_PARAMETERS_V3 sOutput; ++ }; ++} ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3; ++ ++/****************************************************************************/ ++// Structures used by EnableYUVTable ++/****************************************************************************/ ++typedef struct _ENABLE_YUV_PARAMETERS ++{ ++ UCHAR ucEnable; // ATOM_ENABLE:Enable YUV or ATOM_DISABLE:Disable YUV (RGB) ++ UCHAR ucCRTC; // Which CRTC needs this YUV or RGB format ++ UCHAR ucPadding[2]; ++}ENABLE_YUV_PARAMETERS; + #define ENABLE_YUV_PS_ALLOCATION ENABLE_YUV_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by GetMemoryClockTable */ +-/****************************************************************************/ +-typedef struct _GET_MEMORY_CLOCK_PARAMETERS { +- ULONG ulReturnMemoryClock; /* current memory speed in 10KHz unit */ ++/****************************************************************************/ ++// Structures used by GetMemoryClockTable ++/****************************************************************************/ ++typedef struct _GET_MEMORY_CLOCK_PARAMETERS ++{ ++ ULONG ulReturnMemoryClock; // current memory speed in 10KHz unit + } GET_MEMORY_CLOCK_PARAMETERS; + #define GET_MEMORY_CLOCK_PS_ALLOCATION GET_MEMORY_CLOCK_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by GetEngineClockTable */ +-/****************************************************************************/ +-typedef struct _GET_ENGINE_CLOCK_PARAMETERS { +- ULONG ulReturnEngineClock; /* current engine speed in 10KHz unit */ ++/****************************************************************************/ ++// Structures used by GetEngineClockTable ++/****************************************************************************/ ++typedef struct _GET_ENGINE_CLOCK_PARAMETERS ++{ ++ ULONG ulReturnEngineClock; // current engine speed in 10KHz unit + } GET_ENGINE_CLOCK_PARAMETERS; + #define GET_ENGINE_CLOCK_PS_ALLOCATION GET_ENGINE_CLOCK_PARAMETERS + +-/****************************************************************************/ +-/* Following Structures and constant may be obsolete */ +-/****************************************************************************/ +-/* Maxium 8 bytes,the data read in will be placed in the parameter space. */ +-/* Read operaion successeful when the paramter space is non-zero, otherwise read operation failed */ +-typedef struct _READ_EDID_FROM_HW_I2C_DATA_PARAMETERS { +- USHORT usPrescale; /* Ratio between Engine clock and I2C clock */ +- USHORT usVRAMAddress; /* Adress in Frame Buffer where to pace raw EDID */ +- USHORT usStatus; /* When use output: lower byte EDID checksum, high byte hardware status */ +- /* WHen use input: lower byte as 'byte to read':currently limited to 128byte or 1byte */ +- UCHAR ucSlaveAddr; /* Read from which slave */ +- UCHAR ucLineNumber; /* Read from which HW assisted line */ +-} READ_EDID_FROM_HW_I2C_DATA_PARAMETERS; ++/****************************************************************************/ ++// Following Structures and constant may be obsolete ++/****************************************************************************/ ++//Maxium 8 bytes,the data read in will be placed in the parameter space. ++//Read operaion successeful when the paramter space is non-zero, otherwise read operation failed ++typedef struct _READ_EDID_FROM_HW_I2C_DATA_PARAMETERS ++{ ++ USHORT usPrescale; //Ratio between Engine clock and I2C clock ++ USHORT usVRAMAddress; //Adress in Frame Buffer where to pace raw EDID ++ USHORT usStatus; //When use output: lower byte EDID checksum, high byte hardware status ++ //WHen use input: lower byte as 'byte to read':currently limited to 128byte or 1byte ++ UCHAR ucSlaveAddr; //Read from which slave ++ UCHAR ucLineNumber; //Read from which HW assisted line ++}READ_EDID_FROM_HW_I2C_DATA_PARAMETERS; + #define READ_EDID_FROM_HW_I2C_DATA_PS_ALLOCATION READ_EDID_FROM_HW_I2C_DATA_PARAMETERS + ++ + #define ATOM_WRITE_I2C_FORMAT_PSOFFSET_PSDATABYTE 0 + #define ATOM_WRITE_I2C_FORMAT_PSOFFSET_PSTWODATABYTES 1 + #define ATOM_WRITE_I2C_FORMAT_PSCOUNTER_PSOFFSET_IDDATABLOCK 2 + #define ATOM_WRITE_I2C_FORMAT_PSCOUNTER_IDOFFSET_PLUS_IDDATABLOCK 3 + #define ATOM_WRITE_I2C_FORMAT_IDCOUNTER_IDOFFSET_IDDATABLOCK 4 + +-typedef struct _WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS { +- USHORT usPrescale; /* Ratio between Engine clock and I2C clock */ +- USHORT usByteOffset; /* Write to which byte */ +- /* Upper portion of usByteOffset is Format of data */ +- /* 1bytePS+offsetPS */ +- /* 2bytesPS+offsetPS */ +- /* blockID+offsetPS */ +- /* blockID+offsetID */ +- /* blockID+counterID+offsetID */ +- UCHAR ucData; /* PS data1 */ +- UCHAR ucStatus; /* Status byte 1=success, 2=failure, Also is used as PS data2 */ +- UCHAR ucSlaveAddr; /* Write to which slave */ +- UCHAR ucLineNumber; /* Write from which HW assisted line */ +-} WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS; ++typedef struct _WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS ++{ ++ USHORT usPrescale; //Ratio between Engine clock and I2C clock ++ USHORT usByteOffset; //Write to which byte ++ //Upper portion of usByteOffset is Format of data ++ //1bytePS+offsetPS ++ //2bytesPS+offsetPS ++ //blockID+offsetPS ++ //blockID+offsetID ++ //blockID+counterID+offsetID ++ UCHAR ucData; //PS data1 ++ UCHAR ucStatus; //Status byte 1=success, 2=failure, Also is used as PS data2 ++ UCHAR ucSlaveAddr; //Write to which slave ++ UCHAR ucLineNumber; //Write from which HW assisted line ++}WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS; + + #define WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS + +-typedef struct _SET_UP_HW_I2C_DATA_PARAMETERS { +- USHORT usPrescale; /* Ratio between Engine clock and I2C clock */ +- UCHAR ucSlaveAddr; /* Write to which slave */ +- UCHAR ucLineNumber; /* Write from which HW assisted line */ +-} SET_UP_HW_I2C_DATA_PARAMETERS; ++typedef struct _SET_UP_HW_I2C_DATA_PARAMETERS ++{ ++ USHORT usPrescale; //Ratio between Engine clock and I2C clock ++ UCHAR ucSlaveAddr; //Write to which slave ++ UCHAR ucLineNumber; //Write from which HW assisted line ++}SET_UP_HW_I2C_DATA_PARAMETERS; ++ + + /**************************************************************************/ + #define SPEED_FAN_CONTROL_PS_ALLOCATION WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS + +-/****************************************************************************/ +-/* Structures used by PowerConnectorDetectionTable */ +-/****************************************************************************/ +-typedef struct _POWER_CONNECTOR_DETECTION_PARAMETERS { +- UCHAR ucPowerConnectorStatus; /* Used for return value 0: detected, 1:not detected */ +- UCHAR ucPwrBehaviorId; +- USHORT usPwrBudget; /* how much power currently boot to in unit of watt */ +-} POWER_CONNECTOR_DETECTION_PARAMETERS; +- +-typedef struct POWER_CONNECTOR_DETECTION_PS_ALLOCATION { +- UCHAR ucPowerConnectorStatus; /* Used for return value 0: detected, 1:not detected */ +- UCHAR ucReserved; +- USHORT usPwrBudget; /* how much power currently boot to in unit of watt */ +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; +-} POWER_CONNECTOR_DETECTION_PS_ALLOCATION; ++/****************************************************************************/ ++// Structures used by PowerConnectorDetectionTable ++/****************************************************************************/ ++typedef struct _POWER_CONNECTOR_DETECTION_PARAMETERS ++{ ++ UCHAR ucPowerConnectorStatus; //Used for return value 0: detected, 1:not detected ++ UCHAR ucPwrBehaviorId; ++ USHORT usPwrBudget; //how much power currently boot to in unit of watt ++}POWER_CONNECTOR_DETECTION_PARAMETERS; ++ ++typedef struct POWER_CONNECTOR_DETECTION_PS_ALLOCATION ++{ ++ UCHAR ucPowerConnectorStatus; //Used for return value 0: detected, 1:not detected ++ UCHAR ucReserved; ++ USHORT usPwrBudget; //how much power currently boot to in unit of watt ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; ++}POWER_CONNECTOR_DETECTION_PS_ALLOCATION; + + /****************************LVDS SS Command Table Definitions**********************/ + +-/****************************************************************************/ +-/* Structures used by EnableSpreadSpectrumOnPPLLTable */ +-/****************************************************************************/ +-typedef struct _ENABLE_LVDS_SS_PARAMETERS { +- USHORT usSpreadSpectrumPercentage; +- UCHAR ucSpreadSpectrumType; /* Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD */ +- UCHAR ucSpreadSpectrumStepSize_Delay; /* bits3:2 SS_STEP_SIZE; bit 6:4 SS_DELAY */ +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucPadding[3]; +-} ENABLE_LVDS_SS_PARAMETERS; +- +-/* ucTableFormatRevision=1,ucTableContentRevision=2 */ +-typedef struct _ENABLE_LVDS_SS_PARAMETERS_V2 { +- USHORT usSpreadSpectrumPercentage; +- UCHAR ucSpreadSpectrumType; /* Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD */ +- UCHAR ucSpreadSpectrumStep; /* */ +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucSpreadSpectrumDelay; +- UCHAR ucSpreadSpectrumRange; +- UCHAR ucPadding; +-} ENABLE_LVDS_SS_PARAMETERS_V2; +- +-/* This new structure is based on ENABLE_LVDS_SS_PARAMETERS but expands to SS on PPLL, so other devices can use SS. */ +-typedef struct _ENABLE_SPREAD_SPECTRUM_ON_PPLL { +- USHORT usSpreadSpectrumPercentage; +- UCHAR ucSpreadSpectrumType; /* Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD */ +- UCHAR ucSpreadSpectrumStep; /* */ +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucSpreadSpectrumDelay; +- UCHAR ucSpreadSpectrumRange; +- UCHAR ucPpll; /* ATOM_PPLL1/ATOM_PPLL2 */ +-} ENABLE_SPREAD_SPECTRUM_ON_PPLL; ++/****************************************************************************/ ++// Structures used by EnableSpreadSpectrumOnPPLLTable ++/****************************************************************************/ ++typedef struct _ENABLE_LVDS_SS_PARAMETERS ++{ ++ USHORT usSpreadSpectrumPercentage; ++ UCHAR ucSpreadSpectrumType; //Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD ++ UCHAR ucSpreadSpectrumStepSize_Delay; //bits3:2 SS_STEP_SIZE; bit 6:4 SS_DELAY ++ UCHAR ucEnable; //ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucPadding[3]; ++}ENABLE_LVDS_SS_PARAMETERS; ++ ++//ucTableFormatRevision=1,ucTableContentRevision=2 ++typedef struct _ENABLE_LVDS_SS_PARAMETERS_V2 ++{ ++ USHORT usSpreadSpectrumPercentage; ++ UCHAR ucSpreadSpectrumType; //Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD ++ UCHAR ucSpreadSpectrumStep; // ++ UCHAR ucEnable; //ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucSpreadSpectrumDelay; ++ UCHAR ucSpreadSpectrumRange; ++ UCHAR ucPadding; ++}ENABLE_LVDS_SS_PARAMETERS_V2; ++ ++//This new structure is based on ENABLE_LVDS_SS_PARAMETERS but expands to SS on PPLL, so other devices can use SS. ++typedef struct _ENABLE_SPREAD_SPECTRUM_ON_PPLL ++{ ++ USHORT usSpreadSpectrumPercentage; ++ UCHAR ucSpreadSpectrumType; // Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD ++ UCHAR ucSpreadSpectrumStep; // ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucSpreadSpectrumDelay; ++ UCHAR ucSpreadSpectrumRange; ++ UCHAR ucPpll; // ATOM_PPLL1/ATOM_PPLL2 ++}ENABLE_SPREAD_SPECTRUM_ON_PPLL; ++ ++typedef struct _ENABLE_SPREAD_SPECTRUM_ON_PPLL_V2 ++{ ++ USHORT usSpreadSpectrumPercentage; ++ UCHAR ucSpreadSpectrumType; // Bit[0]: 0-Down Spread,1-Center Spread. ++ // Bit[1]: 1-Ext. 0-Int. ++ // Bit[3:2]: =0 P1PLL =1 P2PLL =2 DCPLL ++ // Bits[7:4] reserved ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ USHORT usSpreadSpectrumAmount; // Includes SS_AMOUNT_FBDIV[7:0] and SS_AMOUNT_NFRAC_SLIP[11:8] ++ USHORT usSpreadSpectrumStep; // SS_STEP_SIZE_DSFRAC ++}ENABLE_SPREAD_SPECTRUM_ON_PPLL_V2; ++ ++#define ATOM_PPLL_SS_TYPE_V2_DOWN_SPREAD 0x00 ++#define ATOM_PPLL_SS_TYPE_V2_CENTRE_SPREAD 0x01 ++#define ATOM_PPLL_SS_TYPE_V2_EXT_SPREAD 0x02 ++#define ATOM_PPLL_SS_TYPE_V2_PPLL_SEL_MASK 0x0c ++#define ATOM_PPLL_SS_TYPE_V2_P1PLL 0x00 ++#define ATOM_PPLL_SS_TYPE_V2_P2PLL 0x04 ++#define ATOM_PPLL_SS_TYPE_V2_DCPLL 0x08 ++#define ATOM_PPLL_SS_AMOUNT_V2_FBDIV_MASK 0x00FF ++#define ATOM_PPLL_SS_AMOUNT_V2_FBDIV_SHIFT 0 ++#define ATOM_PPLL_SS_AMOUNT_V2_NFRAC_MASK 0x0F00 ++#define ATOM_PPLL_SS_AMOUNT_V2_NFRAC_SHIFT 8 + + #define ENABLE_SPREAD_SPECTRUM_ON_PPLL_PS_ALLOCATION ENABLE_SPREAD_SPECTRUM_ON_PPLL + + /**************************************************************************/ + +-typedef struct _SET_PIXEL_CLOCK_PS_ALLOCATION { +- PIXEL_CLOCK_PARAMETERS sPCLKInput; +- ENABLE_SPREAD_SPECTRUM_ON_PPLL sReserved; /* Caller doesn't need to init this portion */ +-} SET_PIXEL_CLOCK_PS_ALLOCATION; ++typedef struct _SET_PIXEL_CLOCK_PS_ALLOCATION ++{ ++ PIXEL_CLOCK_PARAMETERS sPCLKInput; ++ ENABLE_SPREAD_SPECTRUM_ON_PPLL sReserved;//Caller doesn't need to init this portion ++}SET_PIXEL_CLOCK_PS_ALLOCATION; + + #define ENABLE_VGA_RENDER_PS_ALLOCATION SET_PIXEL_CLOCK_PS_ALLOCATION + +-/****************************************************************************/ +-/* Structures used by ### */ +-/****************************************************************************/ +-typedef struct _MEMORY_TRAINING_PARAMETERS { +- ULONG ulTargetMemoryClock; /* In 10Khz unit */ +-} MEMORY_TRAINING_PARAMETERS; ++/****************************************************************************/ ++// Structures used by ### ++/****************************************************************************/ ++typedef struct _MEMORY_TRAINING_PARAMETERS ++{ ++ ULONG ulTargetMemoryClock; //In 10Khz unit ++}MEMORY_TRAINING_PARAMETERS; + #define MEMORY_TRAINING_PS_ALLOCATION MEMORY_TRAINING_PARAMETERS + ++ + /****************************LVDS and other encoder command table definitions **********************/ + +-/****************************************************************************/ +-/* Structures used by LVDSEncoderControlTable (Before DCE30) */ +-/* LVTMAEncoderControlTable (Before DCE30) */ +-/* TMDSAEncoderControlTable (Before DCE30) */ +-/****************************************************************************/ +-typedef struct _LVDS_ENCODER_CONTROL_PARAMETERS { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- UCHAR ucMisc; /* bit0=0: Enable single link */ +- /* =1: Enable dual link */ +- /* Bit1=0: 666RGB */ +- /* =1: 888RGB */ +- UCHAR ucAction; /* 0: turn off encoder */ +- /* 1: setup and turn on encoder */ +-} LVDS_ENCODER_CONTROL_PARAMETERS; + +-#define LVDS_ENCODER_CONTROL_PS_ALLOCATION LVDS_ENCODER_CONTROL_PARAMETERS ++/****************************************************************************/ ++// Structures used by LVDSEncoderControlTable (Before DCE30) ++// LVTMAEncoderControlTable (Before DCE30) ++// TMDSAEncoderControlTable (Before DCE30) ++/****************************************************************************/ ++typedef struct _LVDS_ENCODER_CONTROL_PARAMETERS ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ UCHAR ucMisc; // bit0=0: Enable single link ++ // =1: Enable dual link ++ // Bit1=0: 666RGB ++ // =1: 888RGB ++ UCHAR ucAction; // 0: turn off encoder ++ // 1: setup and turn on encoder ++}LVDS_ENCODER_CONTROL_PARAMETERS; + ++#define LVDS_ENCODER_CONTROL_PS_ALLOCATION LVDS_ENCODER_CONTROL_PARAMETERS ++ + #define TMDS1_ENCODER_CONTROL_PARAMETERS LVDS_ENCODER_CONTROL_PARAMETERS + #define TMDS1_ENCODER_CONTROL_PS_ALLOCATION TMDS1_ENCODER_CONTROL_PARAMETERS + + #define TMDS2_ENCODER_CONTROL_PARAMETERS TMDS1_ENCODER_CONTROL_PARAMETERS + #define TMDS2_ENCODER_CONTROL_PS_ALLOCATION TMDS2_ENCODER_CONTROL_PARAMETERS + +-/* ucTableFormatRevision=1,ucTableContentRevision=2 */ +-typedef struct _LVDS_ENCODER_CONTROL_PARAMETERS_V2 { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- UCHAR ucMisc; /* see PANEL_ENCODER_MISC_xx definitions below */ +- UCHAR ucAction; /* 0: turn off encoder */ +- /* 1: setup and turn on encoder */ +- UCHAR ucTruncate; /* bit0=0: Disable truncate */ +- /* =1: Enable truncate */ +- /* bit4=0: 666RGB */ +- /* =1: 888RGB */ +- UCHAR ucSpatial; /* bit0=0: Disable spatial dithering */ +- /* =1: Enable spatial dithering */ +- /* bit4=0: 666RGB */ +- /* =1: 888RGB */ +- UCHAR ucTemporal; /* bit0=0: Disable temporal dithering */ +- /* =1: Enable temporal dithering */ +- /* bit4=0: 666RGB */ +- /* =1: 888RGB */ +- /* bit5=0: Gray level 2 */ +- /* =1: Gray level 4 */ +- UCHAR ucFRC; /* bit4=0: 25FRC_SEL pattern E */ +- /* =1: 25FRC_SEL pattern F */ +- /* bit6:5=0: 50FRC_SEL pattern A */ +- /* =1: 50FRC_SEL pattern B */ +- /* =2: 50FRC_SEL pattern C */ +- /* =3: 50FRC_SEL pattern D */ +- /* bit7=0: 75FRC_SEL pattern E */ +- /* =1: 75FRC_SEL pattern F */ +-} LVDS_ENCODER_CONTROL_PARAMETERS_V2; + +-#define LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 LVDS_ENCODER_CONTROL_PARAMETERS_V2 ++//ucTableFormatRevision=1,ucTableContentRevision=2 ++typedef struct _LVDS_ENCODER_CONTROL_PARAMETERS_V2 ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ UCHAR ucMisc; // see PANEL_ENCODER_MISC_xx defintions below ++ UCHAR ucAction; // 0: turn off encoder ++ // 1: setup and turn on encoder ++ UCHAR ucTruncate; // bit0=0: Disable truncate ++ // =1: Enable truncate ++ // bit4=0: 666RGB ++ // =1: 888RGB ++ UCHAR ucSpatial; // bit0=0: Disable spatial dithering ++ // =1: Enable spatial dithering ++ // bit4=0: 666RGB ++ // =1: 888RGB ++ UCHAR ucTemporal; // bit0=0: Disable temporal dithering ++ // =1: Enable temporal dithering ++ // bit4=0: 666RGB ++ // =1: 888RGB ++ // bit5=0: Gray level 2 ++ // =1: Gray level 4 ++ UCHAR ucFRC; // bit4=0: 25FRC_SEL pattern E ++ // =1: 25FRC_SEL pattern F ++ // bit6:5=0: 50FRC_SEL pattern A ++ // =1: 50FRC_SEL pattern B ++ // =2: 50FRC_SEL pattern C ++ // =3: 50FRC_SEL pattern D ++ // bit7=0: 75FRC_SEL pattern E ++ // =1: 75FRC_SEL pattern F ++}LVDS_ENCODER_CONTROL_PARAMETERS_V2; + ++#define LVDS_ENCODER_CONTROL_PS_ALLOCATION_V2 LVDS_ENCODER_CONTROL_PARAMETERS_V2 ++ + #define TMDS1_ENCODER_CONTROL_PARAMETERS_V2 LVDS_ENCODER_CONTROL_PARAMETERS_V2 + #define TMDS1_ENCODER_CONTROL_PS_ALLOCATION_V2 TMDS1_ENCODER_CONTROL_PARAMETERS_V2 +- ++ + #define TMDS2_ENCODER_CONTROL_PARAMETERS_V2 TMDS1_ENCODER_CONTROL_PARAMETERS_V2 + #define TMDS2_ENCODER_CONTROL_PS_ALLOCATION_V2 TMDS2_ENCODER_CONTROL_PARAMETERS_V2 + +@@ -1185,38 +1536,42 @@ typedef struct _LVDS_ENCODER_CONTROL_PARAMETERS_V2 { + #define TMDS2_ENCODER_CONTROL_PARAMETERS_V3 LVDS_ENCODER_CONTROL_PARAMETERS_V3 + #define TMDS2_ENCODER_CONTROL_PS_ALLOCATION_V3 TMDS2_ENCODER_CONTROL_PARAMETERS_V3 + +-/****************************************************************************/ +-/* Structures used by ### */ +-/****************************************************************************/ +-typedef struct _ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS { +- UCHAR ucEnable; /* Enable or Disable External TMDS encoder */ +- UCHAR ucMisc; /* Bit0=0:Enable Single link;=1:Enable Dual link;Bit1 {=0:666RGB, =1:888RGB} */ +- UCHAR ucPadding[2]; +-} ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS; +- +-typedef struct _ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION { +- ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS sXTmdsEncoder; +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; /* Caller doesn't need to init this portion */ +-} ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION; ++/****************************************************************************/ ++// Structures used by ### ++/****************************************************************************/ ++typedef struct _ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS ++{ ++ UCHAR ucEnable; // Enable or Disable External TMDS encoder ++ UCHAR ucMisc; // Bit0=0:Enable Single link;=1:Enable Dual link;Bit1 {=0:666RGB, =1:888RGB} ++ UCHAR ucPadding[2]; ++}ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS; ++ ++typedef struct _ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION ++{ ++ ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS sXTmdsEncoder; ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; //Caller doesn't need to init this portion ++}ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION; + + #define ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS_V2 LVDS_ENCODER_CONTROL_PARAMETERS_V2 + +-typedef struct _ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION_V2 { +- ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS_V2 sXTmdsEncoder; +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; /* Caller doesn't need to init this portion */ +-} ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION_V2; ++typedef struct _ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION_V2 ++{ ++ ENABLE_EXTERNAL_TMDS_ENCODER_PARAMETERS_V2 sXTmdsEncoder; ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; //Caller doesn't need to init this portion ++}ENABLE_EXTERNAL_TMDS_ENCODER_PS_ALLOCATION_V2; + +-typedef struct _EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION { +- DIG_ENCODER_CONTROL_PARAMETERS sDigEncoder; +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; +-} EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION; ++typedef struct _EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION ++{ ++ DIG_ENCODER_CONTROL_PARAMETERS sDigEncoder; ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; ++}EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION; + +-/****************************************************************************/ +-/* Structures used by DVOEncoderControlTable */ +-/****************************************************************************/ +-/* ucTableFormatRevision=1,ucTableContentRevision=3 */ ++/****************************************************************************/ ++// Structures used by DVOEncoderControlTable ++/****************************************************************************/ ++//ucTableFormatRevision=1,ucTableContentRevision=3 + +-/* ucDVOConfig: */ ++//ucDVOConfig: + #define DVO_ENCODER_CONFIG_RATE_SEL 0x01 + #define DVO_ENCODER_CONFIG_DDR_SPEED 0x00 + #define DVO_ENCODER_CONFIG_SDR_SPEED 0x01 +@@ -1225,21 +1580,22 @@ typedef struct _EXTERNAL_ENCODER_CONTROL_PS_ALLOCATION { + #define DVO_ENCODER_CONFIG_UPPER12BIT 0x04 + #define DVO_ENCODER_CONFIG_24BIT 0x08 + +-typedef struct _DVO_ENCODER_CONTROL_PARAMETERS_V3 { +- USHORT usPixelClock; +- UCHAR ucDVOConfig; +- UCHAR ucAction; /* ATOM_ENABLE/ATOM_DISABLE/ATOM_HPD_INIT */ +- UCHAR ucReseved[4]; +-} DVO_ENCODER_CONTROL_PARAMETERS_V3; ++typedef struct _DVO_ENCODER_CONTROL_PARAMETERS_V3 ++{ ++ USHORT usPixelClock; ++ UCHAR ucDVOConfig; ++ UCHAR ucAction; //ATOM_ENABLE/ATOM_DISABLE/ATOM_HPD_INIT ++ UCHAR ucReseved[4]; ++}DVO_ENCODER_CONTROL_PARAMETERS_V3; + #define DVO_ENCODER_CONTROL_PS_ALLOCATION_V3 DVO_ENCODER_CONTROL_PARAMETERS_V3 + +-/* ucTableFormatRevision=1 */ +-/* ucTableContentRevision=3 structure is not changed but usMisc add bit 1 as another input for */ +-/* bit1=0: non-coherent mode */ +-/* =1: coherent mode */ ++//ucTableFormatRevision=1 ++//ucTableContentRevision=3 structure is not changed but usMisc add bit 1 as another input for ++// bit1=0: non-coherent mode ++// =1: coherent mode + +-/* ========================================================================================== */ +-/* Only change is here next time when changing encoder parameter definitions again! */ ++//========================================================================================== ++//Only change is here next time when changing encoder parameter definitions again! + #define LVDS_ENCODER_CONTROL_PARAMETERS_LAST LVDS_ENCODER_CONTROL_PARAMETERS_V3 + #define LVDS_ENCODER_CONTROL_PS_ALLOCATION_LAST LVDS_ENCODER_CONTROL_PARAMETERS_LAST + +@@ -1252,7 +1608,7 @@ typedef struct _DVO_ENCODER_CONTROL_PARAMETERS_V3 { + #define DVO_ENCODER_CONTROL_PARAMETERS_LAST DVO_ENCODER_CONTROL_PARAMETERS + #define DVO_ENCODER_CONTROL_PS_ALLOCATION_LAST DVO_ENCODER_CONTROL_PS_ALLOCATION + +-/* ========================================================================================== */ ++//========================================================================================== + #define PANEL_ENCODER_MISC_DUAL 0x01 + #define PANEL_ENCODER_MISC_COHERENT 0x02 + #define PANEL_ENCODER_MISC_TMDS_LINKB 0x04 +@@ -1281,159 +1637,159 @@ typedef struct _DVO_ENCODER_CONTROL_PARAMETERS_V3 { + #define PANEL_ENCODER_75FRC_E 0x00 + #define PANEL_ENCODER_75FRC_F 0x80 + +-/****************************************************************************/ +-/* Structures used by SetVoltageTable */ +-/****************************************************************************/ ++/****************************************************************************/ ++// Structures used by SetVoltageTable ++/****************************************************************************/ + #define SET_VOLTAGE_TYPE_ASIC_VDDC 1 + #define SET_VOLTAGE_TYPE_ASIC_MVDDC 2 + #define SET_VOLTAGE_TYPE_ASIC_MVDDQ 3 + #define SET_VOLTAGE_TYPE_ASIC_VDDCI 4 + #define SET_VOLTAGE_INIT_MODE 5 +-#define SET_VOLTAGE_GET_MAX_VOLTAGE 6 /* Gets the Max. voltage for the soldered Asic */ ++#define SET_VOLTAGE_GET_MAX_VOLTAGE 6 //Gets the Max. voltage for the soldered Asic + + #define SET_ASIC_VOLTAGE_MODE_ALL_SOURCE 0x1 + #define SET_ASIC_VOLTAGE_MODE_SOURCE_A 0x2 + #define SET_ASIC_VOLTAGE_MODE_SOURCE_B 0x4 + + #define SET_ASIC_VOLTAGE_MODE_SET_VOLTAGE 0x0 +-#define SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL 0x1 ++#define SET_ASIC_VOLTAGE_MODE_GET_GPIOVAL 0x1 + #define SET_ASIC_VOLTAGE_MODE_GET_GPIOMASK 0x2 + +-typedef struct _SET_VOLTAGE_PARAMETERS { +- UCHAR ucVoltageType; /* To tell which voltage to set up, VDDC/MVDDC/MVDDQ */ +- UCHAR ucVoltageMode; /* To set all, to set source A or source B or ... */ +- UCHAR ucVoltageIndex; /* An index to tell which voltage level */ +- UCHAR ucReserved; +-} SET_VOLTAGE_PARAMETERS; +- +-typedef struct _SET_VOLTAGE_PARAMETERS_V2 { +- UCHAR ucVoltageType; /* To tell which voltage to set up, VDDC/MVDDC/MVDDQ */ +- UCHAR ucVoltageMode; /* Not used, maybe use for state machine for differen power mode */ +- USHORT usVoltageLevel; /* real voltage level */ +-} SET_VOLTAGE_PARAMETERS_V2; +- +-typedef struct _SET_VOLTAGE_PS_ALLOCATION { +- SET_VOLTAGE_PARAMETERS sASICSetVoltage; +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; +-} SET_VOLTAGE_PS_ALLOCATION; +- +-/****************************************************************************/ +-/* Structures used by TVEncoderControlTable */ +-/****************************************************************************/ +-typedef struct _TV_ENCODER_CONTROL_PARAMETERS { +- USHORT usPixelClock; /* in 10KHz; for bios convenient */ +- UCHAR ucTvStandard; /* See definition "ATOM_TV_NTSC ..." */ +- UCHAR ucAction; /* 0: turn off encoder */ +- /* 1: setup and turn on encoder */ +-} TV_ENCODER_CONTROL_PARAMETERS; +- +-typedef struct _TV_ENCODER_CONTROL_PS_ALLOCATION { +- TV_ENCODER_CONTROL_PARAMETERS sTVEncoder; +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; /* Don't set this one */ +-} TV_ENCODER_CONTROL_PS_ALLOCATION; +- +-/* ==============================Data Table Portion==================================== */ +- +-#ifdef UEFI_BUILD +-#define UTEMP USHORT +-#define USHORT void* +-#endif +- +-/****************************************************************************/ +-/* Structure used in Data.mtb */ +-/****************************************************************************/ +-typedef struct _ATOM_MASTER_LIST_OF_DATA_TABLES { +- USHORT UtilityPipeLine; /* Offest for the utility to get parser info,Don't change this position! */ +- USHORT MultimediaCapabilityInfo; /* Only used by MM Lib,latest version 1.1, not configuable from Bios, need to include the table to build Bios */ +- USHORT MultimediaConfigInfo; /* Only used by MM Lib,latest version 2.1, not configuable from Bios, need to include the table to build Bios */ +- USHORT StandardVESA_Timing; /* Only used by Bios */ +- USHORT FirmwareInfo; /* Shared by various SW components,latest version 1.4 */ +- USHORT DAC_Info; /* Will be obsolete from R600 */ +- USHORT LVDS_Info; /* Shared by various SW components,latest version 1.1 */ +- USHORT TMDS_Info; /* Will be obsolete from R600 */ +- USHORT AnalogTV_Info; /* Shared by various SW components,latest version 1.1 */ +- USHORT SupportedDevicesInfo; /* Will be obsolete from R600 */ +- USHORT GPIO_I2C_Info; /* Shared by various SW components,latest version 1.2 will be used from R600 */ +- USHORT VRAM_UsageByFirmware; /* Shared by various SW components,latest version 1.3 will be used from R600 */ +- USHORT GPIO_Pin_LUT; /* Shared by various SW components,latest version 1.1 */ +- USHORT VESA_ToInternalModeLUT; /* Only used by Bios */ +- USHORT ComponentVideoInfo; /* Shared by various SW components,latest version 2.1 will be used from R600 */ +- USHORT PowerPlayInfo; /* Shared by various SW components,latest version 2.1,new design from R600 */ +- USHORT CompassionateData; /* Will be obsolete from R600 */ +- USHORT SaveRestoreInfo; /* Only used by Bios */ +- USHORT PPLL_SS_Info; /* Shared by various SW components,latest version 1.2, used to call SS_Info, change to new name because of int ASIC SS info */ +- USHORT OemInfo; /* Defined and used by external SW, should be obsolete soon */ +- USHORT XTMDS_Info; /* Will be obsolete from R600 */ +- USHORT MclkSS_Info; /* Shared by various SW components,latest version 1.1, only enabled when ext SS chip is used */ +- USHORT Object_Header; /* Shared by various SW components,latest version 1.1 */ +- USHORT IndirectIOAccess; /* Only used by Bios,this table position can't change at all!! */ +- USHORT MC_InitParameter; /* Only used by command table */ +- USHORT ASIC_VDDC_Info; /* Will be obsolete from R600 */ +- USHORT ASIC_InternalSS_Info; /* New tabel name from R600, used to be called "ASIC_MVDDC_Info" */ +- USHORT TV_VideoMode; /* Only used by command table */ +- USHORT VRAM_Info; /* Only used by command table, latest version 1.3 */ +- USHORT MemoryTrainingInfo; /* Used for VBIOS and Diag utility for memory training purpose since R600. the new table rev start from 2.1 */ +- USHORT IntegratedSystemInfo; /* Shared by various SW components */ +- USHORT ASIC_ProfilingInfo; /* New table name from R600, used to be called "ASIC_VDDCI_Info" for pre-R600 */ +- USHORT VoltageObjectInfo; /* Shared by various SW components, latest version 1.1 */ +- USHORT PowerSourceInfo; /* Shared by various SW components, latest versoin 1.1 */ +-} ATOM_MASTER_LIST_OF_DATA_TABLES; +- +-#ifdef UEFI_BUILD +-#define USHORT UTEMP +-#endif ++typedef struct _SET_VOLTAGE_PARAMETERS ++{ ++ UCHAR ucVoltageType; // To tell which voltage to set up, VDDC/MVDDC/MVDDQ ++ UCHAR ucVoltageMode; // To set all, to set source A or source B or ... ++ UCHAR ucVoltageIndex; // An index to tell which voltage level ++ UCHAR ucReserved; ++}SET_VOLTAGE_PARAMETERS; + +-typedef struct _ATOM_MASTER_DATA_TABLE { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_MASTER_LIST_OF_DATA_TABLES ListOfDataTables; +-} ATOM_MASTER_DATA_TABLE; ++typedef struct _SET_VOLTAGE_PARAMETERS_V2 ++{ ++ UCHAR ucVoltageType; // To tell which voltage to set up, VDDC/MVDDC/MVDDQ ++ UCHAR ucVoltageMode; // Not used, maybe use for state machine for differen power mode ++ USHORT usVoltageLevel; // real voltage level ++}SET_VOLTAGE_PARAMETERS_V2; + +-/****************************************************************************/ +-/* Structure used in MultimediaCapabilityInfoTable */ +-/****************************************************************************/ +-typedef struct _ATOM_MULTIMEDIA_CAPABILITY_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulSignature; /* HW info table signature string "$ATI" */ +- UCHAR ucI2C_Type; /* I2C type (normal GP_IO, ImpactTV GP_IO, Dedicated I2C pin, etc) */ +- UCHAR ucTV_OutInfo; /* Type of TV out supported (3:0) and video out crystal frequency (6:4) and TV data port (7) */ +- UCHAR ucVideoPortInfo; /* Provides the video port capabilities */ +- UCHAR ucHostPortInfo; /* Provides host port configuration information */ +-} ATOM_MULTIMEDIA_CAPABILITY_INFO; ++typedef struct _SET_VOLTAGE_PS_ALLOCATION ++{ ++ SET_VOLTAGE_PARAMETERS sASICSetVoltage; ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; ++}SET_VOLTAGE_PS_ALLOCATION; ++ ++/****************************************************************************/ ++// Structures used by TVEncoderControlTable ++/****************************************************************************/ ++typedef struct _TV_ENCODER_CONTROL_PARAMETERS ++{ ++ USHORT usPixelClock; // in 10KHz; for bios convenient ++ UCHAR ucTvStandard; // See definition "ATOM_TV_NTSC ..." ++ UCHAR ucAction; // 0: turn off encoder ++ // 1: setup and turn on encoder ++}TV_ENCODER_CONTROL_PARAMETERS; + +-/****************************************************************************/ +-/* Structure used in MultimediaConfigInfoTable */ +-/****************************************************************************/ +-typedef struct _ATOM_MULTIMEDIA_CONFIG_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulSignature; /* MM info table signature sting "$MMT" */ +- UCHAR ucTunerInfo; /* Type of tuner installed on the adapter (4:0) and video input for tuner (7:5) */ +- UCHAR ucAudioChipInfo; /* List the audio chip type (3:0) product type (4) and OEM revision (7:5) */ +- UCHAR ucProductID; /* Defines as OEM ID or ATI board ID dependent on product type setting */ +- UCHAR ucMiscInfo1; /* Tuner voltage (1:0) HW teletext support (3:2) FM audio decoder (5:4) reserved (6) audio scrambling (7) */ +- UCHAR ucMiscInfo2; /* I2S input config (0) I2S output config (1) I2S Audio Chip (4:2) SPDIF Output Config (5) reserved (7:6) */ +- UCHAR ucMiscInfo3; /* Video Decoder Type (3:0) Video In Standard/Crystal (7:4) */ +- UCHAR ucMiscInfo4; /* Video Decoder Host Config (2:0) reserved (7:3) */ +- UCHAR ucVideoInput0Info; /* Video Input 0 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) */ +- UCHAR ucVideoInput1Info; /* Video Input 1 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) */ +- UCHAR ucVideoInput2Info; /* Video Input 2 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) */ +- UCHAR ucVideoInput3Info; /* Video Input 3 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) */ +- UCHAR ucVideoInput4Info; /* Video Input 4 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) */ +-} ATOM_MULTIMEDIA_CONFIG_INFO; ++typedef struct _TV_ENCODER_CONTROL_PS_ALLOCATION ++{ ++ TV_ENCODER_CONTROL_PARAMETERS sTVEncoder; ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; // Don't set this one ++}TV_ENCODER_CONTROL_PS_ALLOCATION; + +-/****************************************************************************/ +-/* Structures used in FirmwareInfoTable */ +-/****************************************************************************/ ++//==============================Data Table Portion==================================== + +-/* usBIOSCapability Definition: */ +-/* Bit 0 = 0: Bios image is not Posted, =1:Bios image is Posted; */ +-/* Bit 1 = 0: Dual CRTC is not supported, =1: Dual CRTC is supported; */ +-/* Bit 2 = 0: Extended Desktop is not supported, =1: Extended Desktop is supported; */ +-/* Others: Reserved */ ++/****************************************************************************/ ++// Structure used in Data.mtb ++/****************************************************************************/ ++typedef struct _ATOM_MASTER_LIST_OF_DATA_TABLES ++{ ++ USHORT UtilityPipeLine; // Offest for the utility to get parser info,Don't change this position! ++ USHORT MultimediaCapabilityInfo; // Only used by MM Lib,latest version 1.1, not configuable from Bios, need to include the table to build Bios ++ USHORT MultimediaConfigInfo; // Only used by MM Lib,latest version 2.1, not configuable from Bios, need to include the table to build Bios ++ USHORT StandardVESA_Timing; // Only used by Bios ++ USHORT FirmwareInfo; // Shared by various SW components,latest version 1.4 ++ USHORT DAC_Info; // Will be obsolete from R600 ++ USHORT LVDS_Info; // Shared by various SW components,latest version 1.1 ++ USHORT TMDS_Info; // Will be obsolete from R600 ++ USHORT AnalogTV_Info; // Shared by various SW components,latest version 1.1 ++ USHORT SupportedDevicesInfo; // Will be obsolete from R600 ++ USHORT GPIO_I2C_Info; // Shared by various SW components,latest version 1.2 will be used from R600 ++ USHORT VRAM_UsageByFirmware; // Shared by various SW components,latest version 1.3 will be used from R600 ++ USHORT GPIO_Pin_LUT; // Shared by various SW components,latest version 1.1 ++ USHORT VESA_ToInternalModeLUT; // Only used by Bios ++ USHORT ComponentVideoInfo; // Shared by various SW components,latest version 2.1 will be used from R600 ++ USHORT PowerPlayInfo; // Shared by various SW components,latest version 2.1,new design from R600 ++ USHORT CompassionateData; // Will be obsolete from R600 ++ USHORT SaveRestoreInfo; // Only used by Bios ++ USHORT PPLL_SS_Info; // Shared by various SW components,latest version 1.2, used to call SS_Info, change to new name because of int ASIC SS info ++ USHORT OemInfo; // Defined and used by external SW, should be obsolete soon ++ USHORT XTMDS_Info; // Will be obsolete from R600 ++ USHORT MclkSS_Info; // Shared by various SW components,latest version 1.1, only enabled when ext SS chip is used ++ USHORT Object_Header; // Shared by various SW components,latest version 1.1 ++ USHORT IndirectIOAccess; // Only used by Bios,this table position can't change at all!! ++ USHORT MC_InitParameter; // Only used by command table ++ USHORT ASIC_VDDC_Info; // Will be obsolete from R600 ++ USHORT ASIC_InternalSS_Info; // New tabel name from R600, used to be called "ASIC_MVDDC_Info" ++ USHORT TV_VideoMode; // Only used by command table ++ USHORT VRAM_Info; // Only used by command table, latest version 1.3 ++ USHORT MemoryTrainingInfo; // Used for VBIOS and Diag utility for memory training purpose since R600. the new table rev start from 2.1 ++ USHORT IntegratedSystemInfo; // Shared by various SW components ++ USHORT ASIC_ProfilingInfo; // New table name from R600, used to be called "ASIC_VDDCI_Info" for pre-R600 ++ USHORT VoltageObjectInfo; // Shared by various SW components, latest version 1.1 ++ USHORT PowerSourceInfo; // Shared by various SW components, latest versoin 1.1 ++}ATOM_MASTER_LIST_OF_DATA_TABLES; ++ ++typedef struct _ATOM_MASTER_DATA_TABLE ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_MASTER_LIST_OF_DATA_TABLES ListOfDataTables; ++}ATOM_MASTER_DATA_TABLE; ++ ++/****************************************************************************/ ++// Structure used in MultimediaCapabilityInfoTable ++/****************************************************************************/ ++typedef struct _ATOM_MULTIMEDIA_CAPABILITY_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulSignature; // HW info table signature string "$ATI" ++ UCHAR ucI2C_Type; // I2C type (normal GP_IO, ImpactTV GP_IO, Dedicated I2C pin, etc) ++ UCHAR ucTV_OutInfo; // Type of TV out supported (3:0) and video out crystal frequency (6:4) and TV data port (7) ++ UCHAR ucVideoPortInfo; // Provides the video port capabilities ++ UCHAR ucHostPortInfo; // Provides host port configuration information ++}ATOM_MULTIMEDIA_CAPABILITY_INFO; ++ ++/****************************************************************************/ ++// Structure used in MultimediaConfigInfoTable ++/****************************************************************************/ ++typedef struct _ATOM_MULTIMEDIA_CONFIG_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulSignature; // MM info table signature sting "$MMT" ++ UCHAR ucTunerInfo; // Type of tuner installed on the adapter (4:0) and video input for tuner (7:5) ++ UCHAR ucAudioChipInfo; // List the audio chip type (3:0) product type (4) and OEM revision (7:5) ++ UCHAR ucProductID; // Defines as OEM ID or ATI board ID dependent on product type setting ++ UCHAR ucMiscInfo1; // Tuner voltage (1:0) HW teletext support (3:2) FM audio decoder (5:4) reserved (6) audio scrambling (7) ++ UCHAR ucMiscInfo2; // I2S input config (0) I2S output config (1) I2S Audio Chip (4:2) SPDIF Output Config (5) reserved (7:6) ++ UCHAR ucMiscInfo3; // Video Decoder Type (3:0) Video In Standard/Crystal (7:4) ++ UCHAR ucMiscInfo4; // Video Decoder Host Config (2:0) reserved (7:3) ++ UCHAR ucVideoInput0Info;// Video Input 0 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) ++ UCHAR ucVideoInput1Info;// Video Input 1 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) ++ UCHAR ucVideoInput2Info;// Video Input 2 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) ++ UCHAR ucVideoInput3Info;// Video Input 3 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) ++ UCHAR ucVideoInput4Info;// Video Input 4 Type (1:0) F/B setting (2) physical connector ID (5:3) reserved (7:6) ++}ATOM_MULTIMEDIA_CONFIG_INFO; ++ ++/****************************************************************************/ ++// Structures used in FirmwareInfoTable ++/****************************************************************************/ ++ ++// usBIOSCapability Defintion: ++// Bit 0 = 0: Bios image is not Posted, =1:Bios image is Posted; ++// Bit 1 = 0: Dual CRTC is not supported, =1: Dual CRTC is supported; ++// Bit 2 = 0: Extended Desktop is not supported, =1: Extended Desktop is supported; ++// Others: Reserved + #define ATOM_BIOS_INFO_ATOM_FIRMWARE_POSTED 0x0001 + #define ATOM_BIOS_INFO_DUAL_CRTC_SUPPORT 0x0002 + #define ATOM_BIOS_INFO_EXTENDED_DESKTOP_SUPPORT 0x0004 +-#define ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT 0x0008 +-#define ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT 0x0010 ++#define ATOM_BIOS_INFO_MEMORY_CLOCK_SS_SUPPORT 0x0008 // (valid from v1.1 ~v1.4):=1: memclk SS enable, =0 memclk SS disable. ++#define ATOM_BIOS_INFO_ENGINE_CLOCK_SS_SUPPORT 0x0010 // (valid from v1.1 ~v1.4):=1: engclk SS enable, =0 engclk SS disable. + #define ATOM_BIOS_INFO_BL_CONTROLLED_BY_GPU 0x0020 + #define ATOM_BIOS_INFO_WMI_SUPPORT 0x0040 + #define ATOM_BIOS_INFO_PPMODE_ASSIGNGED_BY_SYSTEM 0x0080 +@@ -1441,242 +1797,292 @@ typedef struct _ATOM_MULTIMEDIA_CONFIG_INFO { + #define ATOM_BIOS_INFO_HYPERMEMORY_SIZE_MASK 0x1E00 + #define ATOM_BIOS_INFO_VPOST_WITHOUT_FIRST_MODE_SET 0x2000 + #define ATOM_BIOS_INFO_BIOS_SCRATCH6_SCL2_REDEFINE 0x4000 ++#define ATOM_BIOS_INFO_MEMORY_CLOCK_EXT_SS_SUPPORT 0x0008 // (valid from v2.1 ): =1: memclk ss enable with external ss chip ++#define ATOM_BIOS_INFO_ENGINE_CLOCK_EXT_SS_SUPPORT 0x0010 // (valid from v2.1 ): =1: engclk ss enable with external ss chip + + #ifndef _H2INC + +-/* Please don't add or expand this bitfield structure below, this one will retire soon.! */ +-typedef struct _ATOM_FIRMWARE_CAPABILITY { ++//Please don't add or expand this bitfield structure below, this one will retire soon.! ++typedef struct _ATOM_FIRMWARE_CAPABILITY ++{ + #if ATOM_BIG_ENDIAN +- USHORT Reserved:3; +- USHORT HyperMemory_Size:4; +- USHORT HyperMemory_Support:1; +- USHORT PPMode_Assigned:1; +- USHORT WMI_SUPPORT:1; +- USHORT GPUControlsBL:1; +- USHORT EngineClockSS_Support:1; +- USHORT MemoryClockSS_Support:1; +- USHORT ExtendedDesktopSupport:1; +- USHORT DualCRTC_Support:1; +- USHORT FirmwarePosted:1; ++ USHORT Reserved:3; ++ USHORT HyperMemory_Size:4; ++ USHORT HyperMemory_Support:1; ++ USHORT PPMode_Assigned:1; ++ USHORT WMI_SUPPORT:1; ++ USHORT GPUControlsBL:1; ++ USHORT EngineClockSS_Support:1; ++ USHORT MemoryClockSS_Support:1; ++ USHORT ExtendedDesktopSupport:1; ++ USHORT DualCRTC_Support:1; ++ USHORT FirmwarePosted:1; + #else +- USHORT FirmwarePosted:1; +- USHORT DualCRTC_Support:1; +- USHORT ExtendedDesktopSupport:1; +- USHORT MemoryClockSS_Support:1; +- USHORT EngineClockSS_Support:1; +- USHORT GPUControlsBL:1; +- USHORT WMI_SUPPORT:1; +- USHORT PPMode_Assigned:1; +- USHORT HyperMemory_Support:1; +- USHORT HyperMemory_Size:4; +- USHORT Reserved:3; ++ USHORT FirmwarePosted:1; ++ USHORT DualCRTC_Support:1; ++ USHORT ExtendedDesktopSupport:1; ++ USHORT MemoryClockSS_Support:1; ++ USHORT EngineClockSS_Support:1; ++ USHORT GPUControlsBL:1; ++ USHORT WMI_SUPPORT:1; ++ USHORT PPMode_Assigned:1; ++ USHORT HyperMemory_Support:1; ++ USHORT HyperMemory_Size:4; ++ USHORT Reserved:3; + #endif +-} ATOM_FIRMWARE_CAPABILITY; ++}ATOM_FIRMWARE_CAPABILITY; + +-typedef union _ATOM_FIRMWARE_CAPABILITY_ACCESS { +- ATOM_FIRMWARE_CAPABILITY sbfAccess; +- USHORT susAccess; +-} ATOM_FIRMWARE_CAPABILITY_ACCESS; ++typedef union _ATOM_FIRMWARE_CAPABILITY_ACCESS ++{ ++ ATOM_FIRMWARE_CAPABILITY sbfAccess; ++ USHORT susAccess; ++}ATOM_FIRMWARE_CAPABILITY_ACCESS; + + #else + +-typedef union _ATOM_FIRMWARE_CAPABILITY_ACCESS { +- USHORT susAccess; +-} ATOM_FIRMWARE_CAPABILITY_ACCESS; ++typedef union _ATOM_FIRMWARE_CAPABILITY_ACCESS ++{ ++ USHORT susAccess; ++}ATOM_FIRMWARE_CAPABILITY_ACCESS; + + #endif + +-typedef struct _ATOM_FIRMWARE_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulFirmwareRevision; +- ULONG ulDefaultEngineClock; /* In 10Khz unit */ +- ULONG ulDefaultMemoryClock; /* In 10Khz unit */ +- ULONG ulDriverTargetEngineClock; /* In 10Khz unit */ +- ULONG ulDriverTargetMemoryClock; /* In 10Khz unit */ +- ULONG ulMaxEngineClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxMemoryClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxPixelClockPLL_Output; /* In 10Khz unit */ +- ULONG ulASICMaxEngineClock; /* In 10Khz unit */ +- ULONG ulASICMaxMemoryClock; /* In 10Khz unit */ +- UCHAR ucASICMaxTemperature; +- UCHAR ucPadding[3]; /* Don't use them */ +- ULONG aulReservedForBIOS[3]; /* Don't use them */ +- USHORT usMinEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Output; /* In 10Khz unit */ +- USHORT usMaxPixelClock; /* In 10Khz unit, Max. Pclk */ +- USHORT usMinPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinPixelClockPLL_Output; /* In 10Khz unit, the definitions above can't change!!! */ +- ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; +- USHORT usReferenceClock; /* In 10Khz unit */ +- USHORT usPM_RTS_Location; /* RTS PM4 starting location in ROM in 1Kb unit */ +- UCHAR ucPM_RTS_StreamSize; /* RTS PM4 packets in Kb unit */ +- UCHAR ucDesign_ID; /* Indicate what is the board design */ +- UCHAR ucMemoryModule_ID; /* Indicate what is the board design */ +-} ATOM_FIRMWARE_INFO; +- +-typedef struct _ATOM_FIRMWARE_INFO_V1_2 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulFirmwareRevision; +- ULONG ulDefaultEngineClock; /* In 10Khz unit */ +- ULONG ulDefaultMemoryClock; /* In 10Khz unit */ +- ULONG ulDriverTargetEngineClock; /* In 10Khz unit */ +- ULONG ulDriverTargetMemoryClock; /* In 10Khz unit */ +- ULONG ulMaxEngineClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxMemoryClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxPixelClockPLL_Output; /* In 10Khz unit */ +- ULONG ulASICMaxEngineClock; /* In 10Khz unit */ +- ULONG ulASICMaxMemoryClock; /* In 10Khz unit */ +- UCHAR ucASICMaxTemperature; +- UCHAR ucMinAllowedBL_Level; +- UCHAR ucPadding[2]; /* Don't use them */ +- ULONG aulReservedForBIOS[2]; /* Don't use them */ +- ULONG ulMinPixelClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Output; /* In 10Khz unit */ +- USHORT usMaxPixelClock; /* In 10Khz unit, Max. Pclk */ +- USHORT usMinPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinPixelClockPLL_Output; /* In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output */ +- ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; +- USHORT usReferenceClock; /* In 10Khz unit */ +- USHORT usPM_RTS_Location; /* RTS PM4 starting location in ROM in 1Kb unit */ +- UCHAR ucPM_RTS_StreamSize; /* RTS PM4 packets in Kb unit */ +- UCHAR ucDesign_ID; /* Indicate what is the board design */ +- UCHAR ucMemoryModule_ID; /* Indicate what is the board design */ +-} ATOM_FIRMWARE_INFO_V1_2; +- +-typedef struct _ATOM_FIRMWARE_INFO_V1_3 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulFirmwareRevision; +- ULONG ulDefaultEngineClock; /* In 10Khz unit */ +- ULONG ulDefaultMemoryClock; /* In 10Khz unit */ +- ULONG ulDriverTargetEngineClock; /* In 10Khz unit */ +- ULONG ulDriverTargetMemoryClock; /* In 10Khz unit */ +- ULONG ulMaxEngineClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxMemoryClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxPixelClockPLL_Output; /* In 10Khz unit */ +- ULONG ulASICMaxEngineClock; /* In 10Khz unit */ +- ULONG ulASICMaxMemoryClock; /* In 10Khz unit */ +- UCHAR ucASICMaxTemperature; +- UCHAR ucMinAllowedBL_Level; +- UCHAR ucPadding[2]; /* Don't use them */ +- ULONG aulReservedForBIOS; /* Don't use them */ +- ULONG ul3DAccelerationEngineClock; /* In 10Khz unit */ +- ULONG ulMinPixelClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Output; /* In 10Khz unit */ +- USHORT usMaxPixelClock; /* In 10Khz unit, Max. Pclk */ +- USHORT usMinPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinPixelClockPLL_Output; /* In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output */ +- ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; +- USHORT usReferenceClock; /* In 10Khz unit */ +- USHORT usPM_RTS_Location; /* RTS PM4 starting location in ROM in 1Kb unit */ +- UCHAR ucPM_RTS_StreamSize; /* RTS PM4 packets in Kb unit */ +- UCHAR ucDesign_ID; /* Indicate what is the board design */ +- UCHAR ucMemoryModule_ID; /* Indicate what is the board design */ +-} ATOM_FIRMWARE_INFO_V1_3; +- +-typedef struct _ATOM_FIRMWARE_INFO_V1_4 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulFirmwareRevision; +- ULONG ulDefaultEngineClock; /* In 10Khz unit */ +- ULONG ulDefaultMemoryClock; /* In 10Khz unit */ +- ULONG ulDriverTargetEngineClock; /* In 10Khz unit */ +- ULONG ulDriverTargetMemoryClock; /* In 10Khz unit */ +- ULONG ulMaxEngineClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxMemoryClockPLL_Output; /* In 10Khz unit */ +- ULONG ulMaxPixelClockPLL_Output; /* In 10Khz unit */ +- ULONG ulASICMaxEngineClock; /* In 10Khz unit */ +- ULONG ulASICMaxMemoryClock; /* In 10Khz unit */ +- UCHAR ucASICMaxTemperature; +- UCHAR ucMinAllowedBL_Level; +- USHORT usBootUpVDDCVoltage; /* In MV unit */ +- USHORT usLcdMinPixelClockPLL_Output; /* In MHz unit */ +- USHORT usLcdMaxPixelClockPLL_Output; /* In MHz unit */ +- ULONG ul3DAccelerationEngineClock; /* In 10Khz unit */ +- ULONG ulMinPixelClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxEngineClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinEngineClockPLL_Output; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxMemoryClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinMemoryClockPLL_Output; /* In 10Khz unit */ +- USHORT usMaxPixelClock; /* In 10Khz unit, Max. Pclk */ +- USHORT usMinPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMaxPixelClockPLL_Input; /* In 10Khz unit */ +- USHORT usMinPixelClockPLL_Output; /* In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output */ +- ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; +- USHORT usReferenceClock; /* In 10Khz unit */ +- USHORT usPM_RTS_Location; /* RTS PM4 starting location in ROM in 1Kb unit */ +- UCHAR ucPM_RTS_StreamSize; /* RTS PM4 packets in Kb unit */ +- UCHAR ucDesign_ID; /* Indicate what is the board design */ +- UCHAR ucMemoryModule_ID; /* Indicate what is the board design */ +-} ATOM_FIRMWARE_INFO_V1_4; +- +-#define ATOM_FIRMWARE_INFO_LAST ATOM_FIRMWARE_INFO_V1_4 +- +-/****************************************************************************/ +-/* Structures used in IntegratedSystemInfoTable */ +-/****************************************************************************/ ++typedef struct _ATOM_FIRMWARE_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulFirmwareRevision; ++ ULONG ulDefaultEngineClock; //In 10Khz unit ++ ULONG ulDefaultMemoryClock; //In 10Khz unit ++ ULONG ulDriverTargetEngineClock; //In 10Khz unit ++ ULONG ulDriverTargetMemoryClock; //In 10Khz unit ++ ULONG ulMaxEngineClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxMemoryClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxPixelClockPLL_Output; //In 10Khz unit ++ ULONG ulASICMaxEngineClock; //In 10Khz unit ++ ULONG ulASICMaxMemoryClock; //In 10Khz unit ++ UCHAR ucASICMaxTemperature; ++ UCHAR ucPadding[3]; //Don't use them ++ ULONG aulReservedForBIOS[3]; //Don't use them ++ USHORT usMinEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMaxEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Output; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMaxMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Output; //In 10Khz unit ++ USHORT usMaxPixelClock; //In 10Khz unit, Max. Pclk ++ USHORT usMinPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMaxPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMinPixelClockPLL_Output; //In 10Khz unit, the definitions above can't change!!! ++ ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; ++ USHORT usReferenceClock; //In 10Khz unit ++ USHORT usPM_RTS_Location; //RTS PM4 starting location in ROM in 1Kb unit ++ UCHAR ucPM_RTS_StreamSize; //RTS PM4 packets in Kb unit ++ UCHAR ucDesign_ID; //Indicate what is the board design ++ UCHAR ucMemoryModule_ID; //Indicate what is the board design ++}ATOM_FIRMWARE_INFO; ++ ++typedef struct _ATOM_FIRMWARE_INFO_V1_2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulFirmwareRevision; ++ ULONG ulDefaultEngineClock; //In 10Khz unit ++ ULONG ulDefaultMemoryClock; //In 10Khz unit ++ ULONG ulDriverTargetEngineClock; //In 10Khz unit ++ ULONG ulDriverTargetMemoryClock; //In 10Khz unit ++ ULONG ulMaxEngineClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxMemoryClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxPixelClockPLL_Output; //In 10Khz unit ++ ULONG ulASICMaxEngineClock; //In 10Khz unit ++ ULONG ulASICMaxMemoryClock; //In 10Khz unit ++ UCHAR ucASICMaxTemperature; ++ UCHAR ucMinAllowedBL_Level; ++ UCHAR ucPadding[2]; //Don't use them ++ ULONG aulReservedForBIOS[2]; //Don't use them ++ ULONG ulMinPixelClockPLL_Output; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMaxEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Output; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMaxMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Output; //In 10Khz unit ++ USHORT usMaxPixelClock; //In 10Khz unit, Max. Pclk ++ USHORT usMinPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMaxPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMinPixelClockPLL_Output; //In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output ++ ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; ++ USHORT usReferenceClock; //In 10Khz unit ++ USHORT usPM_RTS_Location; //RTS PM4 starting location in ROM in 1Kb unit ++ UCHAR ucPM_RTS_StreamSize; //RTS PM4 packets in Kb unit ++ UCHAR ucDesign_ID; //Indicate what is the board design ++ UCHAR ucMemoryModule_ID; //Indicate what is the board design ++}ATOM_FIRMWARE_INFO_V1_2; ++ ++typedef struct _ATOM_FIRMWARE_INFO_V1_3 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulFirmwareRevision; ++ ULONG ulDefaultEngineClock; //In 10Khz unit ++ ULONG ulDefaultMemoryClock; //In 10Khz unit ++ ULONG ulDriverTargetEngineClock; //In 10Khz unit ++ ULONG ulDriverTargetMemoryClock; //In 10Khz unit ++ ULONG ulMaxEngineClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxMemoryClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxPixelClockPLL_Output; //In 10Khz unit ++ ULONG ulASICMaxEngineClock; //In 10Khz unit ++ ULONG ulASICMaxMemoryClock; //In 10Khz unit ++ UCHAR ucASICMaxTemperature; ++ UCHAR ucMinAllowedBL_Level; ++ UCHAR ucPadding[2]; //Don't use them ++ ULONG aulReservedForBIOS; //Don't use them ++ ULONG ul3DAccelerationEngineClock;//In 10Khz unit ++ ULONG ulMinPixelClockPLL_Output; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMaxEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Output; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMaxMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Output; //In 10Khz unit ++ USHORT usMaxPixelClock; //In 10Khz unit, Max. Pclk ++ USHORT usMinPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMaxPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMinPixelClockPLL_Output; //In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output ++ ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; ++ USHORT usReferenceClock; //In 10Khz unit ++ USHORT usPM_RTS_Location; //RTS PM4 starting location in ROM in 1Kb unit ++ UCHAR ucPM_RTS_StreamSize; //RTS PM4 packets in Kb unit ++ UCHAR ucDesign_ID; //Indicate what is the board design ++ UCHAR ucMemoryModule_ID; //Indicate what is the board design ++}ATOM_FIRMWARE_INFO_V1_3; ++ ++typedef struct _ATOM_FIRMWARE_INFO_V1_4 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulFirmwareRevision; ++ ULONG ulDefaultEngineClock; //In 10Khz unit ++ ULONG ulDefaultMemoryClock; //In 10Khz unit ++ ULONG ulDriverTargetEngineClock; //In 10Khz unit ++ ULONG ulDriverTargetMemoryClock; //In 10Khz unit ++ ULONG ulMaxEngineClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxMemoryClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxPixelClockPLL_Output; //In 10Khz unit ++ ULONG ulASICMaxEngineClock; //In 10Khz unit ++ ULONG ulASICMaxMemoryClock; //In 10Khz unit ++ UCHAR ucASICMaxTemperature; ++ UCHAR ucMinAllowedBL_Level; ++ USHORT usBootUpVDDCVoltage; //In MV unit ++ USHORT usLcdMinPixelClockPLL_Output; // In MHz unit ++ USHORT usLcdMaxPixelClockPLL_Output; // In MHz unit ++ ULONG ul3DAccelerationEngineClock;//In 10Khz unit ++ ULONG ulMinPixelClockPLL_Output; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMaxEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Output; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMaxMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Output; //In 10Khz unit ++ USHORT usMaxPixelClock; //In 10Khz unit, Max. Pclk ++ USHORT usMinPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMaxPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMinPixelClockPLL_Output; //In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output ++ ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; ++ USHORT usReferenceClock; //In 10Khz unit ++ USHORT usPM_RTS_Location; //RTS PM4 starting location in ROM in 1Kb unit ++ UCHAR ucPM_RTS_StreamSize; //RTS PM4 packets in Kb unit ++ UCHAR ucDesign_ID; //Indicate what is the board design ++ UCHAR ucMemoryModule_ID; //Indicate what is the board design ++}ATOM_FIRMWARE_INFO_V1_4; ++ ++//the structure below to be used from Cypress ++typedef struct _ATOM_FIRMWARE_INFO_V2_1 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulFirmwareRevision; ++ ULONG ulDefaultEngineClock; //In 10Khz unit ++ ULONG ulDefaultMemoryClock; //In 10Khz unit ++ ULONG ulReserved1; ++ ULONG ulReserved2; ++ ULONG ulMaxEngineClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxMemoryClockPLL_Output; //In 10Khz unit ++ ULONG ulMaxPixelClockPLL_Output; //In 10Khz unit ++ ULONG ulBinaryAlteredInfo; //Was ulASICMaxEngineClock ++ ULONG ulDefaultDispEngineClkFreq; //In 10Khz unit ++ UCHAR ucReserved1; //Was ucASICMaxTemperature; ++ UCHAR ucMinAllowedBL_Level; ++ USHORT usBootUpVDDCVoltage; //In MV unit ++ USHORT usLcdMinPixelClockPLL_Output; // In MHz unit ++ USHORT usLcdMaxPixelClockPLL_Output; // In MHz unit ++ ULONG ulReserved4; //Was ulAsicMaximumVoltage ++ ULONG ulMinPixelClockPLL_Output; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMaxEngineClockPLL_Input; //In 10Khz unit ++ USHORT usMinEngineClockPLL_Output; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMaxMemoryClockPLL_Input; //In 10Khz unit ++ USHORT usMinMemoryClockPLL_Output; //In 10Khz unit ++ USHORT usMaxPixelClock; //In 10Khz unit, Max. Pclk ++ USHORT usMinPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMaxPixelClockPLL_Input; //In 10Khz unit ++ USHORT usMinPixelClockPLL_Output; //In 10Khz unit - lower 16bit of ulMinPixelClockPLL_Output ++ ATOM_FIRMWARE_CAPABILITY_ACCESS usFirmwareCapability; ++ USHORT usCoreReferenceClock; //In 10Khz unit ++ USHORT usMemoryReferenceClock; //In 10Khz unit ++ USHORT usUniphyDPModeExtClkFreq; //In 10Khz unit, if it is 0, In DP Mode Uniphy Input clock from internal PPLL, otherwise Input clock from external Spread clock ++ UCHAR ucMemoryModule_ID; //Indicate what is the board design ++ UCHAR ucReserved4[3]; ++}ATOM_FIRMWARE_INFO_V2_1; ++ ++ ++#define ATOM_FIRMWARE_INFO_LAST ATOM_FIRMWARE_INFO_V2_1 ++ ++/****************************************************************************/ ++// Structures used in IntegratedSystemInfoTable ++/****************************************************************************/ + #define IGP_CAP_FLAG_DYNAMIC_CLOCK_EN 0x2 + #define IGP_CAP_FLAG_AC_CARD 0x4 + #define IGP_CAP_FLAG_SDVO_CARD 0x8 + #define IGP_CAP_FLAG_POSTDIV_BY_2_MODE 0x10 + +-typedef struct _ATOM_INTEGRATED_SYSTEM_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulBootUpEngineClock; /* in 10kHz unit */ +- ULONG ulBootUpMemoryClock; /* in 10kHz unit */ +- ULONG ulMaxSystemMemoryClock; /* in 10kHz unit */ +- ULONG ulMinSystemMemoryClock; /* in 10kHz unit */ +- UCHAR ucNumberOfCyclesInPeriodHi; +- UCHAR ucLCDTimingSel; /* =0:not valid.!=0 sel this timing descriptor from LCD EDID. */ +- USHORT usReserved1; +- USHORT usInterNBVoltageLow; /* An intermidiate PMW value to set the voltage */ +- USHORT usInterNBVoltageHigh; /* Another intermidiate PMW value to set the voltage */ +- ULONG ulReserved[2]; +- +- USHORT usFSBClock; /* In MHz unit */ +- USHORT usCapabilityFlag; /* Bit0=1 indicates the fake HDMI support,Bit1=0/1 for Dynamic clocking dis/enable */ +- /* Bit[3:2]== 0:No PCIE card, 1:AC card, 2:SDVO card */ +- /* Bit[4]==1: P/2 mode, ==0: P/1 mode */ +- USHORT usPCIENBCfgReg7; /* bit[7:0]=MUX_Sel, bit[9:8]=MUX_SEL_LEVEL2, bit[10]=Lane_Reversal */ +- USHORT usK8MemoryClock; /* in MHz unit */ +- USHORT usK8SyncStartDelay; /* in 0.01 us unit */ +- USHORT usK8DataReturnTime; /* in 0.01 us unit */ +- UCHAR ucMaxNBVoltage; +- UCHAR ucMinNBVoltage; +- UCHAR ucMemoryType; /* [7:4]=1:DDR1;=2:DDR2;=3:DDR3.[3:0] is reserved */ +- UCHAR ucNumberOfCyclesInPeriod; /* CG.FVTHROT_PWM_CTRL_REG0.NumberOfCyclesInPeriod */ +- UCHAR ucStartingPWM_HighTime; /* CG.FVTHROT_PWM_CTRL_REG0.StartingPWM_HighTime */ +- UCHAR ucHTLinkWidth; /* 16 bit vs. 8 bit */ +- UCHAR ucMaxNBVoltageHigh; +- UCHAR ucMinNBVoltageHigh; +-} ATOM_INTEGRATED_SYSTEM_INFO; ++typedef struct _ATOM_INTEGRATED_SYSTEM_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulBootUpEngineClock; //in 10kHz unit ++ ULONG ulBootUpMemoryClock; //in 10kHz unit ++ ULONG ulMaxSystemMemoryClock; //in 10kHz unit ++ ULONG ulMinSystemMemoryClock; //in 10kHz unit ++ UCHAR ucNumberOfCyclesInPeriodHi; ++ UCHAR ucLCDTimingSel; //=0:not valid.!=0 sel this timing descriptor from LCD EDID. ++ USHORT usReserved1; ++ USHORT usInterNBVoltageLow; //An intermidiate PMW value to set the voltage ++ USHORT usInterNBVoltageHigh; //Another intermidiate PMW value to set the voltage ++ ULONG ulReserved[2]; ++ ++ USHORT usFSBClock; //In MHz unit ++ USHORT usCapabilityFlag; //Bit0=1 indicates the fake HDMI support,Bit1=0/1 for Dynamic clocking dis/enable ++ //Bit[3:2]== 0:No PCIE card, 1:AC card, 2:SDVO card ++ //Bit[4]==1: P/2 mode, ==0: P/1 mode ++ USHORT usPCIENBCfgReg7; //bit[7:0]=MUX_Sel, bit[9:8]=MUX_SEL_LEVEL2, bit[10]=Lane_Reversal ++ USHORT usK8MemoryClock; //in MHz unit ++ USHORT usK8SyncStartDelay; //in 0.01 us unit ++ USHORT usK8DataReturnTime; //in 0.01 us unit ++ UCHAR ucMaxNBVoltage; ++ UCHAR ucMinNBVoltage; ++ UCHAR ucMemoryType; //[7:4]=1:DDR1;=2:DDR2;=3:DDR3.[3:0] is reserved ++ UCHAR ucNumberOfCyclesInPeriod; //CG.FVTHROT_PWM_CTRL_REG0.NumberOfCyclesInPeriod ++ UCHAR ucStartingPWM_HighTime; //CG.FVTHROT_PWM_CTRL_REG0.StartingPWM_HighTime ++ UCHAR ucHTLinkWidth; //16 bit vs. 8 bit ++ UCHAR ucMaxNBVoltageHigh; ++ UCHAR ucMinNBVoltageHigh; ++}ATOM_INTEGRATED_SYSTEM_INFO; + + /* Explanation on entries in ATOM_INTEGRATED_SYSTEM_INFO +-ulBootUpMemoryClock: For Intel IGP,it's the UMA system memory clock ++ulBootUpMemoryClock: For Intel IGP,it's the UMA system memory clock + For AMD IGP,it's 0 if no SidePort memory installed or it's the boot-up SidePort memory clock + ulMaxSystemMemoryClock: For Intel IGP,it's the Max freq from memory SPD if memory runs in ASYNC mode or otherwise (SYNC mode) it's 0 + For AMD IGP,for now this can be 0 +-ulMinSystemMemoryClock: For Intel IGP,it's 133MHz if memory runs in ASYNC mode or otherwise (SYNC mode) it's 0 ++ulMinSystemMemoryClock: For Intel IGP,it's 133MHz if memory runs in ASYNC mode or otherwise (SYNC mode) it's 0 + For AMD IGP,for now this can be 0 + +-usFSBClock: For Intel IGP,it's FSB Freq ++usFSBClock: For Intel IGP,it's FSB Freq + For AMD IGP,it's HT Link Speed + + usK8MemoryClock: For AMD IGP only. For RevF CPU, set it to 200 +@@ -1687,98 +2093,113 @@ VC:Voltage Control + ucMaxNBVoltage: Voltage regulator dependent PWM value. Low 8 bits of the value for the max voltage.Set this one to 0xFF if VC without PWM. Set this to 0x0 if no VC at all. + ucMinNBVoltage: Voltage regulator dependent PWM value. Low 8 bits of the value for the min voltage.Set this one to 0x00 if VC without PWM or no VC at all. + +-ucNumberOfCyclesInPeriod: Indicate how many cycles when PWM duty is 100%. low 8 bits of the value. +-ucNumberOfCyclesInPeriodHi: Indicate how many cycles when PWM duty is 100%. high 8 bits of the value.If the PWM has an inverter,set bit [7]==1,otherwise set it 0 ++ucNumberOfCyclesInPeriod: Indicate how many cycles when PWM duty is 100%. low 8 bits of the value. ++ucNumberOfCyclesInPeriodHi: Indicate how many cycles when PWM duty is 100%. high 8 bits of the value.If the PWM has an inverter,set bit [7]==1,otherwise set it 0 + + ucMaxNBVoltageHigh: Voltage regulator dependent PWM value. High 8 bits of the value for the max voltage.Set this one to 0xFF if VC without PWM. Set this to 0x0 if no VC at all. + ucMinNBVoltageHigh: Voltage regulator dependent PWM value. High 8 bits of the value for the min voltage.Set this one to 0x00 if VC without PWM or no VC at all. + ++ + usInterNBVoltageLow: Voltage regulator dependent PWM value. The value makes the the voltage >=Min NB voltage but <=InterNBVoltageHigh. Set this to 0x0000 if VC without PWM or no VC at all. + usInterNBVoltageHigh: Voltage regulator dependent PWM value. The value makes the the voltage >=InterNBVoltageLow but <=Max NB voltage.Set this to 0x0000 if VC without PWM or no VC at all. + */ + ++ + /* + The following IGP table is introduced from RS780, which is supposed to be put by SBIOS in FB before IGP VBIOS starts VPOST; +-Then VBIOS will copy the whole structure to its image so all GPU SW components can access this data structure to get whatever they need. ++Then VBIOS will copy the whole structure to its image so all GPU SW components can access this data structure to get whatever they need. + The enough reservation should allow us to never change table revisions. Whenever needed, a GPU SW component can use reserved portion for new data entries. + + SW components can access the IGP system infor structure in the same way as before + */ + +-typedef struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ULONG ulBootUpEngineClock; /* in 10kHz unit */ +- ULONG ulReserved1[2]; /* must be 0x0 for the reserved */ +- ULONG ulBootUpUMAClock; /* in 10kHz unit */ +- ULONG ulBootUpSidePortClock; /* in 10kHz unit */ +- ULONG ulMinSidePortClock; /* in 10kHz unit */ +- ULONG ulReserved2[6]; /* must be 0x0 for the reserved */ +- ULONG ulSystemConfig; /* see explanation below */ +- ULONG ulBootUpReqDisplayVector; +- ULONG ulOtherDisplayMisc; +- ULONG ulDDISlot1Config; +- ULONG ulDDISlot2Config; +- UCHAR ucMemoryType; /* [3:0]=1:DDR1;=2:DDR2;=3:DDR3.[7:4] is reserved */ +- UCHAR ucUMAChannelNumber; +- UCHAR ucDockingPinBit; +- UCHAR ucDockingPinPolarity; +- ULONG ulDockingPinCFGInfo; +- ULONG ulCPUCapInfo; +- USHORT usNumberOfCyclesInPeriod; +- USHORT usMaxNBVoltage; +- USHORT usMinNBVoltage; +- USHORT usBootUpNBVoltage; +- ULONG ulHTLinkFreq; /* in 10Khz */ +- USHORT usMinHTLinkWidth; +- USHORT usMaxHTLinkWidth; +- USHORT usUMASyncStartDelay; +- USHORT usUMADataReturnTime; +- USHORT usLinkStatusZeroTime; +- USHORT usReserved; +- ULONG ulHighVoltageHTLinkFreq; /* in 10Khz */ +- ULONG ulLowVoltageHTLinkFreq; /* in 10Khz */ +- USHORT usMaxUpStreamHTLinkWidth; +- USHORT usMaxDownStreamHTLinkWidth; +- USHORT usMinUpStreamHTLinkWidth; +- USHORT usMinDownStreamHTLinkWidth; +- ULONG ulReserved3[97]; /* must be 0x0 */ +-} ATOM_INTEGRATED_SYSTEM_INFO_V2; ++ ++typedef struct _ATOM_INTEGRATED_SYSTEM_INFO_V2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulBootUpEngineClock; //in 10kHz unit ++ ULONG ulReserved1[2]; //must be 0x0 for the reserved ++ ULONG ulBootUpUMAClock; //in 10kHz unit ++ ULONG ulBootUpSidePortClock; //in 10kHz unit ++ ULONG ulMinSidePortClock; //in 10kHz unit ++ ULONG ulReserved2[6]; //must be 0x0 for the reserved ++ ULONG ulSystemConfig; //see explanation below ++ ULONG ulBootUpReqDisplayVector; ++ ULONG ulOtherDisplayMisc; ++ ULONG ulDDISlot1Config; ++ ULONG ulDDISlot2Config; ++ UCHAR ucMemoryType; //[3:0]=1:DDR1;=2:DDR2;=3:DDR3.[7:4] is reserved ++ UCHAR ucUMAChannelNumber; ++ UCHAR ucDockingPinBit; ++ UCHAR ucDockingPinPolarity; ++ ULONG ulDockingPinCFGInfo; ++ ULONG ulCPUCapInfo; ++ USHORT usNumberOfCyclesInPeriod; ++ USHORT usMaxNBVoltage; ++ USHORT usMinNBVoltage; ++ USHORT usBootUpNBVoltage; ++ ULONG ulHTLinkFreq; //in 10Khz ++ USHORT usMinHTLinkWidth; ++ USHORT usMaxHTLinkWidth; ++ USHORT usUMASyncStartDelay; ++ USHORT usUMADataReturnTime; ++ USHORT usLinkStatusZeroTime; ++ USHORT usDACEfuse; //for storing badgap value (for RS880 only) ++ ULONG ulHighVoltageHTLinkFreq; // in 10Khz ++ ULONG ulLowVoltageHTLinkFreq; // in 10Khz ++ USHORT usMaxUpStreamHTLinkWidth; ++ USHORT usMaxDownStreamHTLinkWidth; ++ USHORT usMinUpStreamHTLinkWidth; ++ USHORT usMinDownStreamHTLinkWidth; ++ USHORT usFirmwareVersion; //0 means FW is not supported. Otherwise it's the FW version loaded by SBIOS and driver should enable FW. ++ USHORT usFullT0Time; // Input to calculate minimum HT link change time required by NB P-State. Unit is 0.01us. ++ ULONG ulReserved3[96]; //must be 0x0 ++}ATOM_INTEGRATED_SYSTEM_INFO_V2; + + /* + ulBootUpEngineClock: Boot-up Engine Clock in 10Khz; + ulBootUpUMAClock: Boot-up UMA Clock in 10Khz; it must be 0x0 when UMA is not present + ulBootUpSidePortClock: Boot-up SidePort Clock in 10Khz; it must be 0x0 when SidePort Memory is not present,this could be equal to or less than maximum supported Sideport memory clock + +-ulSystemConfig: +-Bit[0]=1: PowerExpress mode =0 Non-PowerExpress mode; ++ulSystemConfig: ++Bit[0]=1: PowerExpress mode =0 Non-PowerExpress mode; + Bit[1]=1: system boots up at AMD overdrived state or user customized mode. In this case, driver will just stick to this boot-up mode. No other PowerPlay state + =0: system boots up at driver control state. Power state depends on PowerPlay table. + Bit[2]=1: PWM method is used on NB voltage control. =0: GPIO method is used. + Bit[3]=1: Only one power state(Performance) will be supported. + =0: Multiple power states supported from PowerPlay table. +-Bit[4]=1: CLMC is supported and enabled on current system. +- =0: CLMC is not supported or enabled on current system. SBIOS need to support HT link/freq change through ATIF interface. +-Bit[5]=1: Enable CDLW for all driver control power states. Max HT width is from SBIOS, while Min HT width is determined by display requirement. ++Bit[4]=1: CLMC is supported and enabled on current system. ++ =0: CLMC is not supported or enabled on current system. SBIOS need to support HT link/freq change through ATIF interface. ++Bit[5]=1: Enable CDLW for all driver control power states. Max HT width is from SBIOS, while Min HT width is determined by display requirement. + =0: CDLW is disabled. If CLMC is enabled case, Min HT width will be set equal to Max HT width. If CLMC disabled case, Max HT width will be applied. + Bit[6]=1: High Voltage requested for all power states. In this case, voltage will be forced at 1.1v and powerplay table voltage drop/throttling request will be ignored. + =0: Voltage settings is determined by powerplay table. + Bit[7]=1: Enable CLMC as hybrid Mode. CDLD and CILR will be disabled in this case and we're using legacy C1E. This is workaround for CPU(Griffin) performance issue. + =0: Enable CLMC as regular mode, CDLD and CILR will be enabled. ++Bit[8]=1: CDLF is supported and enabled on current system. ++ =0: CDLF is not supported or enabled on current system. ++Bit[9]=1: DLL Shut Down feature is enabled on current system. ++ =0: DLL Shut Down feature is not enabled or supported on current system. + + ulBootUpReqDisplayVector: This dword is a bit vector indicates what display devices are requested during boot-up. Refer to ATOM_DEVICE_xxx_SUPPORT for the bit vector definitions. + + ulOtherDisplayMisc: [15:8]- Bootup LCD Expansion selection; 0-center, 1-full panel size expansion; +- [7:0] - BootupTV standard selection; This is a bit vector to indicate what TV standards are supported by the system. Refer to ucTVSuppportedStd definition; ++ [7:0] - BootupTV standard selection; This is a bit vector to indicate what TV standards are supported by the system. Refer to ucTVSupportedStd definition; + + ulDDISlot1Config: Describes the PCIE lane configuration on this DDI PCIE slot (ADD2 card) or connector (Mobile design). + [3:0] - Bit vector to indicate PCIE lane config of the DDI slot/connector on chassis (bit 0=1 lane 3:0; bit 1=1 lane 7:4; bit 2=1 lane 11:8; bit 3=1 lane 15:12) +- [7:4] - Bit vector to indicate PCIE lane config of the same DDI slot/connector on docking station (bit 0=1 lane 3:0; bit 1=1 lane 7:4; bit 2=1 lane 11:8; bit 3=1 lane 15:12) +- [15:8] - Lane configuration attribute; ++ [7:4] - Bit vector to indicate PCIE lane config of the same DDI slot/connector on docking station (bit 4=1 lane 3:0; bit 5=1 lane 7:4; bit 6=1 lane 11:8; bit 7=1 lane 15:12) ++ When a DDI connector is not "paired" (meaming two connections mutualexclusive on chassis or docking, only one of them can be connected at one time. ++ in both chassis and docking, SBIOS has to duplicate the same PCIE lane info from chassis to docking or vice versa. For example: ++ one DDI connector is only populated in docking with PCIE lane 8-11, but there is no paired connection on chassis, SBIOS has to copy bit 6 to bit 2. ++ ++ [15:8] - Lane configuration attribute; + [23:16]- Connector type, possible value: + CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D + CONNECTOR_OBJECT_ID_DUAL_LINK_DVI_D + CONNECTOR_OBJECT_ID_HDMI_TYPE_A + CONNECTOR_OBJECT_ID_DISPLAYPORT ++ CONNECTOR_OBJECT_ID_eDP + [31:24]- Reserved + + ulDDISlot2Config: Same as Slot1. +@@ -1787,29 +2208,31 @@ For IGP, Hypermemory is the only memory type showed in CCC. + + ucUMAChannelNumber: how many channels for the UMA; + +-ulDockingPinCFGInfo: [15:0]-Bus/Device/Function # to CFG to read this Docking Pin; [31:16]-reg offset in CFG to read this pin ++ulDockingPinCFGInfo: [15:0]-Bus/Device/Function # to CFG to read this Docking Pin; [31:16]-reg offset in CFG to read this pin + ucDockingPinBit: which bit in this register to read the pin status; + ucDockingPinPolarity:Polarity of the pin when docked; + + ulCPUCapInfo: [7:0]=1:Griffin;[7:0]=2:Greyhound;[7:0]=3:K8, other bits reserved for now and must be 0x0 + + usNumberOfCyclesInPeriod:Indicate how many cycles when PWM duty is 100%. +-usMaxNBVoltage:Max. voltage control value in either PWM or GPIO mode. ++ ++usMaxNBVoltage:Max. voltage control value in either PWM or GPIO mode. + usMinNBVoltage:Min. voltage control value in either PWM or GPIO mode. + GPIO mode: both usMaxNBVoltage & usMinNBVoltage have a valid value ulSystemConfig.SYSTEM_CONFIG_USE_PWM_ON_VOLTAGE=0 + PWM mode: both usMaxNBVoltage & usMinNBVoltage have a valid value ulSystemConfig.SYSTEM_CONFIG_USE_PWM_ON_VOLTAGE=1 + GPU SW don't control mode: usMaxNBVoltage & usMinNBVoltage=0 and no care about ulSystemConfig.SYSTEM_CONFIG_USE_PWM_ON_VOLTAGE ++ + usBootUpNBVoltage:Boot-up voltage regulator dependent PWM value. + + ulHTLinkFreq: Bootup HT link Frequency in 10Khz. +-usMinHTLinkWidth: Bootup minimum HT link width. If CDLW disabled, this is equal to usMaxHTLinkWidth. +- If CDLW enabled, both upstream and downstream width should be the same during bootup. +-usMaxHTLinkWidth: Bootup maximum HT link width. If CDLW disabled, this is equal to usMinHTLinkWidth. ++usMinHTLinkWidth: Bootup minimum HT link width. If CDLW disabled, this is equal to usMaxHTLinkWidth. + If CDLW enabled, both upstream and downstream width should be the same during bootup. ++usMaxHTLinkWidth: Bootup maximum HT link width. If CDLW disabled, this is equal to usMinHTLinkWidth. ++ If CDLW enabled, both upstream and downstream width should be the same during bootup. + +-usUMASyncStartDelay: Memory access latency, required for watermark calculation ++usUMASyncStartDelay: Memory access latency, required for watermark calculation + usUMADataReturnTime: Memory access latency, required for watermark calculation +-usLinkStatusZeroTime:Memory access latency required for watermark calculation, set this to 0x0 for K8 CPU, set a proper value in 0.01 the unit of us ++usLinkStatusZeroTime:Memory access latency required for watermark calculation, set this to 0x0 for K8 CPU, set a proper value in 0.01 the unit of us + for Griffin or Greyhound. SBIOS needs to convert to actual time by: + if T0Ttime [5:4]=00b, then usLinkStatusZeroTime=T0Ttime [3:0]*0.1us (0.0 to 1.5us) + if T0Ttime [5:4]=01b, then usLinkStatusZeroTime=T0Ttime [3:0]*0.5us (0.0 to 7.5us) +@@ -1817,7 +2240,7 @@ for Griffin or Greyhound. SBIOS needs to convert to actual time by: + if T0Ttime [5:4]=11b, and T0Ttime [3:0]=0x0 to 0xa, then usLinkStatusZeroTime=T0Ttime [3:0]*20us (0.0 to 200us) + + ulHighVoltageHTLinkFreq: HT link frequency for power state with low voltage. If boot up runs in HT1, this must be 0. +- This must be less than or equal to ulHTLinkFreq(bootup frequency). ++ This must be less than or equal to ulHTLinkFreq(bootup frequency). + ulLowVoltageHTLinkFreq: HT link frequency for power state with low voltage or voltage scaling 1.0v~1.1v. If boot up runs in HT1, this must be 0. + This must be less than or equal to ulHighVoltageHTLinkFreq. + +@@ -1827,14 +2250,17 @@ usMinUpStreamHTLinkWidth: Asymmetric link width support in the future, to rep + usMinDownStreamHTLinkWidth: same as above. + */ + ++ + #define SYSTEM_CONFIG_POWEREXPRESS_ENABLE 0x00000001 + #define SYSTEM_CONFIG_RUN_AT_OVERDRIVE_ENGINE 0x00000002 +-#define SYSTEM_CONFIG_USE_PWM_ON_VOLTAGE 0x00000004 ++#define SYSTEM_CONFIG_USE_PWM_ON_VOLTAGE 0x00000004 + #define SYSTEM_CONFIG_PERFORMANCE_POWERSTATE_ONLY 0x00000008 + #define SYSTEM_CONFIG_CLMC_ENABLED 0x00000010 + #define SYSTEM_CONFIG_CDLW_ENABLED 0x00000020 + #define SYSTEM_CONFIG_HIGH_VOLTAGE_REQUESTED 0x00000040 + #define SYSTEM_CONFIG_CLMC_HYBRID_MODE_ENABLED 0x00000080 ++#define SYSTEM_CONFIG_CDLF_ENABLED 0x00000100 ++#define SYSTEM_CONFIG_DLL_SHUTDOWN_ENABLED 0x00000200 + + #define IGP_DDI_SLOT_LANE_CONFIG_MASK 0x000000FF + +@@ -1851,6 +2277,41 @@ usMinDownStreamHTLinkWidth: same as above. + + #define IGP_DDI_SLOT_CONNECTOR_TYPE_MASK 0x00FF0000 + ++// IntegratedSystemInfoTable new Rev is V5 after V2, because of the real rev of V2 is v1.4. This rev is used for RR ++typedef struct _ATOM_INTEGRATED_SYSTEM_INFO_V5 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulBootUpEngineClock; //in 10kHz unit ++ ULONG ulDentistVCOFreq; //Dentist VCO clock in 10kHz unit, the source of GPU SCLK, LCLK, UCLK and VCLK. ++ ULONG ulLClockFreq; //GPU Lclk freq in 10kHz unit, have relationship with NCLK in NorthBridge ++ ULONG ulBootUpUMAClock; //in 10kHz unit ++ ULONG ulReserved1[8]; //must be 0x0 for the reserved ++ ULONG ulBootUpReqDisplayVector; ++ ULONG ulOtherDisplayMisc; ++ ULONG ulReserved2[4]; //must be 0x0 for the reserved ++ ULONG ulSystemConfig; //TBD ++ ULONG ulCPUCapInfo; //TBD ++ USHORT usMaxNBVoltage; //high NB voltage, calculated using current VDDNB (D24F2xDC) and VDDNB offset fuse; ++ USHORT usMinNBVoltage; //low NB voltage, calculated using current VDDNB (D24F2xDC) and VDDNB offset fuse; ++ USHORT usBootUpNBVoltage; //boot up NB voltage ++ UCHAR ucHtcTmpLmt; //bit [22:16] of D24F3x64 Hardware Thermal Control (HTC) Register, may not be needed, TBD ++ UCHAR ucTjOffset; //bit [28:22] of D24F3xE4 Thermtrip Status Register,may not be needed, TBD ++ ULONG ulReserved3[4]; //must be 0x0 for the reserved ++ ULONG ulDDISlot1Config; //see above ulDDISlot1Config definition ++ ULONG ulDDISlot2Config; ++ ULONG ulDDISlot3Config; ++ ULONG ulDDISlot4Config; ++ ULONG ulReserved4[4]; //must be 0x0 for the reserved ++ UCHAR ucMemoryType; //[3:0]=1:DDR1;=2:DDR2;=3:DDR3.[7:4] is reserved ++ UCHAR ucUMAChannelNumber; ++ USHORT usReserved; ++ ULONG ulReserved5[4]; //must be 0x0 for the reserved ++ ULONG ulCSR_M3_ARB_CNTL_DEFAULT[10];//arrays with values for CSR M3 arbiter for default ++ ULONG ulCSR_M3_ARB_CNTL_UVD[10]; //arrays with values for CSR M3 arbiter for UVD playback ++ ULONG ulCSR_M3_ARB_CNTL_FS3D[10];//arrays with values for CSR M3 arbiter for Full Screen 3D applications ++ ULONG ulReserved6[61]; //must be 0x0 ++}ATOM_INTEGRATED_SYSTEM_INFO_V5; ++ + #define ATOM_CRT_INT_ENCODER1_INDEX 0x00000000 + #define ATOM_LCD_INT_ENCODER1_INDEX 0x00000001 + #define ATOM_TV_INT_ENCODER1_INDEX 0x00000002 +@@ -1866,8 +2327,8 @@ usMinDownStreamHTLinkWidth: same as above. + #define ATOM_DFP_INT_ENCODER3_INDEX 0x0000000C + #define ATOM_DFP_INT_ENCODER4_INDEX 0x0000000D + +-/* define ASIC internal encoder id ( bit vector ) */ +-#define ASIC_INT_DAC1_ENCODER_ID 0x00 ++// define ASIC internal encoder id ( bit vector ), used for CRTC_SourceSelTable ++#define ASIC_INT_DAC1_ENCODER_ID 0x00 + #define ASIC_INT_TV_ENCODER_ID 0x02 + #define ASIC_INT_DIG1_ENCODER_ID 0x03 + #define ASIC_INT_DAC2_ENCODER_ID 0x04 +@@ -1875,10 +2336,24 @@ usMinDownStreamHTLinkWidth: same as above. + #define ASIC_INT_DVO_ENCODER_ID 0x07 + #define ASIC_INT_DIG2_ENCODER_ID 0x09 + #define ASIC_EXT_DIG_ENCODER_ID 0x05 ++#define ASIC_EXT_DIG2_ENCODER_ID 0x08 ++#define ASIC_INT_DIG3_ENCODER_ID 0x0a ++#define ASIC_INT_DIG4_ENCODER_ID 0x0b ++#define ASIC_INT_DIG5_ENCODER_ID 0x0c ++#define ASIC_INT_DIG6_ENCODER_ID 0x0d + +-/* define Encoder attribute */ ++//define Encoder attribute + #define ATOM_ANALOG_ENCODER 0 +-#define ATOM_DIGITAL_ENCODER 1 ++#define ATOM_DIGITAL_ENCODER 1 ++#define ATOM_DP_ENCODER 2 ++ ++#define ATOM_ENCODER_ENUM_MASK 0x70 ++#define ATOM_ENCODER_ENUM_ID1 0x00 ++#define ATOM_ENCODER_ENUM_ID2 0x10 ++#define ATOM_ENCODER_ENUM_ID3 0x20 ++#define ATOM_ENCODER_ENUM_ID4 0x30 ++#define ATOM_ENCODER_ENUM_ID5 0x40 ++#define ATOM_ENCODER_ENUM_ID6 0x50 + + #define ATOM_DEVICE_CRT1_INDEX 0x00000000 + #define ATOM_DEVICE_LCD1_INDEX 0x00000001 +@@ -1886,45 +2361,40 @@ usMinDownStreamHTLinkWidth: same as above. + #define ATOM_DEVICE_DFP1_INDEX 0x00000003 + #define ATOM_DEVICE_CRT2_INDEX 0x00000004 + #define ATOM_DEVICE_LCD2_INDEX 0x00000005 +-#define ATOM_DEVICE_TV2_INDEX 0x00000006 ++#define ATOM_DEVICE_DFP6_INDEX 0x00000006 + #define ATOM_DEVICE_DFP2_INDEX 0x00000007 + #define ATOM_DEVICE_CV_INDEX 0x00000008 +-#define ATOM_DEVICE_DFP3_INDEX 0x00000009 +-#define ATOM_DEVICE_DFP4_INDEX 0x0000000A +-#define ATOM_DEVICE_DFP5_INDEX 0x0000000B ++#define ATOM_DEVICE_DFP3_INDEX 0x00000009 ++#define ATOM_DEVICE_DFP4_INDEX 0x0000000A ++#define ATOM_DEVICE_DFP5_INDEX 0x0000000B ++ + #define ATOM_DEVICE_RESERVEDC_INDEX 0x0000000C + #define ATOM_DEVICE_RESERVEDD_INDEX 0x0000000D + #define ATOM_DEVICE_RESERVEDE_INDEX 0x0000000E + #define ATOM_DEVICE_RESERVEDF_INDEX 0x0000000F + #define ATOM_MAX_SUPPORTED_DEVICE_INFO (ATOM_DEVICE_DFP3_INDEX+1) + #define ATOM_MAX_SUPPORTED_DEVICE_INFO_2 ATOM_MAX_SUPPORTED_DEVICE_INFO +-#define ATOM_MAX_SUPPORTED_DEVICE_INFO_3 (ATOM_DEVICE_DFP5_INDEX + 1) ++#define ATOM_MAX_SUPPORTED_DEVICE_INFO_3 (ATOM_DEVICE_DFP5_INDEX + 1 ) + + #define ATOM_MAX_SUPPORTED_DEVICE (ATOM_DEVICE_RESERVEDF_INDEX+1) + +-#define ATOM_DEVICE_CRT1_SUPPORT (0x1L << ATOM_DEVICE_CRT1_INDEX) +-#define ATOM_DEVICE_LCD1_SUPPORT (0x1L << ATOM_DEVICE_LCD1_INDEX) +-#define ATOM_DEVICE_TV1_SUPPORT (0x1L << ATOM_DEVICE_TV1_INDEX) +-#define ATOM_DEVICE_DFP1_SUPPORT (0x1L << ATOM_DEVICE_DFP1_INDEX) +-#define ATOM_DEVICE_CRT2_SUPPORT (0x1L << ATOM_DEVICE_CRT2_INDEX) +-#define ATOM_DEVICE_LCD2_SUPPORT (0x1L << ATOM_DEVICE_LCD2_INDEX) +-#define ATOM_DEVICE_TV2_SUPPORT (0x1L << ATOM_DEVICE_TV2_INDEX) +-#define ATOM_DEVICE_DFP2_SUPPORT (0x1L << ATOM_DEVICE_DFP2_INDEX) +-#define ATOM_DEVICE_CV_SUPPORT (0x1L << ATOM_DEVICE_CV_INDEX) +-#define ATOM_DEVICE_DFP3_SUPPORT (0x1L << ATOM_DEVICE_DFP3_INDEX) +-#define ATOM_DEVICE_DFP4_SUPPORT (0x1L << ATOM_DEVICE_DFP4_INDEX ) +-#define ATOM_DEVICE_DFP5_SUPPORT (0x1L << ATOM_DEVICE_DFP5_INDEX) +- +-#define ATOM_DEVICE_CRT_SUPPORT \ +- (ATOM_DEVICE_CRT1_SUPPORT | ATOM_DEVICE_CRT2_SUPPORT) +-#define ATOM_DEVICE_DFP_SUPPORT \ +- (ATOM_DEVICE_DFP1_SUPPORT | ATOM_DEVICE_DFP2_SUPPORT | \ +- ATOM_DEVICE_DFP3_SUPPORT | ATOM_DEVICE_DFP4_SUPPORT | \ +- ATOM_DEVICE_DFP5_SUPPORT) +-#define ATOM_DEVICE_TV_SUPPORT \ +- (ATOM_DEVICE_TV1_SUPPORT | ATOM_DEVICE_TV2_SUPPORT) +-#define ATOM_DEVICE_LCD_SUPPORT \ +- (ATOM_DEVICE_LCD1_SUPPORT | ATOM_DEVICE_LCD2_SUPPORT) ++#define ATOM_DEVICE_CRT1_SUPPORT (0x1L << ATOM_DEVICE_CRT1_INDEX ) ++#define ATOM_DEVICE_LCD1_SUPPORT (0x1L << ATOM_DEVICE_LCD1_INDEX ) ++#define ATOM_DEVICE_TV1_SUPPORT (0x1L << ATOM_DEVICE_TV1_INDEX ) ++#define ATOM_DEVICE_DFP1_SUPPORT (0x1L << ATOM_DEVICE_DFP1_INDEX ) ++#define ATOM_DEVICE_CRT2_SUPPORT (0x1L << ATOM_DEVICE_CRT2_INDEX ) ++#define ATOM_DEVICE_LCD2_SUPPORT (0x1L << ATOM_DEVICE_LCD2_INDEX ) ++#define ATOM_DEVICE_DFP6_SUPPORT (0x1L << ATOM_DEVICE_DFP6_INDEX ) ++#define ATOM_DEVICE_DFP2_SUPPORT (0x1L << ATOM_DEVICE_DFP2_INDEX ) ++#define ATOM_DEVICE_CV_SUPPORT (0x1L << ATOM_DEVICE_CV_INDEX ) ++#define ATOM_DEVICE_DFP3_SUPPORT (0x1L << ATOM_DEVICE_DFP3_INDEX ) ++#define ATOM_DEVICE_DFP4_SUPPORT (0x1L << ATOM_DEVICE_DFP4_INDEX ) ++#define ATOM_DEVICE_DFP5_SUPPORT (0x1L << ATOM_DEVICE_DFP5_INDEX ) ++ ++#define ATOM_DEVICE_CRT_SUPPORT (ATOM_DEVICE_CRT1_SUPPORT | ATOM_DEVICE_CRT2_SUPPORT) ++#define ATOM_DEVICE_DFP_SUPPORT (ATOM_DEVICE_DFP1_SUPPORT | ATOM_DEVICE_DFP2_SUPPORT | ATOM_DEVICE_DFP3_SUPPORT | ATOM_DEVICE_DFP4_SUPPORT | ATOM_DEVICE_DFP5_SUPPORT | ATOM_DEVICE_DFP6_SUPPORT) ++#define ATOM_DEVICE_TV_SUPPORT (ATOM_DEVICE_TV1_SUPPORT) ++#define ATOM_DEVICE_LCD_SUPPORT (ATOM_DEVICE_LCD1_SUPPORT | ATOM_DEVICE_LCD2_SUPPORT) + + #define ATOM_DEVICE_CONNECTOR_TYPE_MASK 0x000000F0 + #define ATOM_DEVICE_CONNECTOR_TYPE_SHIFT 0x00000004 +@@ -1942,6 +2412,7 @@ usMinDownStreamHTLinkWidth: same as above. + #define ATOM_DEVICE_CONNECTOR_CASE_1 0x0000000E + #define ATOM_DEVICE_CONNECTOR_DISPLAYPORT 0x0000000F + ++ + #define ATOM_DEVICE_DAC_INFO_MASK 0x0000000F + #define ATOM_DEVICE_DAC_INFO_SHIFT 0x00000000 + #define ATOM_DEVICE_DAC_INFO_NODAC 0x00000000 +@@ -1958,139 +2429,150 @@ usMinDownStreamHTLinkWidth: same as above. + #define ATOM_DEVICE_I2C_ID_SHIFT 0x00000004 + #define ATOM_DEVICE_I2C_ID_IS_FOR_NON_MM_USE 0x00000001 + #define ATOM_DEVICE_I2C_ID_IS_FOR_MM_USE 0x00000002 +-#define ATOM_DEVICE_I2C_ID_IS_FOR_SDVO_USE 0x00000003 /* For IGP RS600 */ +-#define ATOM_DEVICE_I2C_ID_IS_FOR_DAC_SCL 0x00000004 /* For IGP RS690 */ ++#define ATOM_DEVICE_I2C_ID_IS_FOR_SDVO_USE 0x00000003 //For IGP RS600 ++#define ATOM_DEVICE_I2C_ID_IS_FOR_DAC_SCL 0x00000004 //For IGP RS690 + + #define ATOM_DEVICE_I2C_HARDWARE_CAP_MASK 0x00000080 + #define ATOM_DEVICE_I2C_HARDWARE_CAP_SHIFT 0x00000007 + #define ATOM_DEVICE_USES_SOFTWARE_ASSISTED_I2C 0x00000000 + #define ATOM_DEVICE_USES_HARDWARE_ASSISTED_I2C 0x00000001 + +-/* usDeviceSupport: */ +-/* Bits0 = 0 - no CRT1 support= 1- CRT1 is supported */ +-/* Bit 1 = 0 - no LCD1 support= 1- LCD1 is supported */ +-/* Bit 2 = 0 - no TV1 support= 1- TV1 is supported */ +-/* Bit 3 = 0 - no DFP1 support= 1- DFP1 is supported */ +-/* Bit 4 = 0 - no CRT2 support= 1- CRT2 is supported */ +-/* Bit 5 = 0 - no LCD2 support= 1- LCD2 is supported */ +-/* Bit 6 = 0 - no TV2 support= 1- TV2 is supported */ +-/* Bit 7 = 0 - no DFP2 support= 1- DFP2 is supported */ +-/* Bit 8 = 0 - no CV support= 1- CV is supported */ +-/* Bit 9 = 0 - no DFP3 support= 1- DFP3 is supported */ +-/* Byte1 (Supported Device Info) */ +-/* Bit 0 = = 0 - no CV support= 1- CV is supported */ +-/* */ +-/* */ +- +-/* ucI2C_ConfigID */ +-/* [7:0] - I2C LINE Associate ID */ +-/* = 0 - no I2C */ +-/* [7] - HW_Cap = 1, [6:0]=HW assisted I2C ID(HW line selection) */ +-/* = 0, [6:0]=SW assisted I2C ID */ +-/* [6-4] - HW_ENGINE_ID = 1, HW engine for NON multimedia use */ +-/* = 2, HW engine for Multimedia use */ +-/* = 3-7 Reserved for future I2C engines */ +-/* [3-0] - I2C_LINE_MUX = A Mux number when it's HW assisted I2C or GPIO ID when it's SW I2C */ +- +-typedef struct _ATOM_I2C_ID_CONFIG { +-#if ATOM_BIG_ENDIAN +- UCHAR bfHW_Capable:1; +- UCHAR bfHW_EngineID:3; +- UCHAR bfI2C_LineMux:4; +-#else +- UCHAR bfI2C_LineMux:4; +- UCHAR bfHW_EngineID:3; +- UCHAR bfHW_Capable:1; +-#endif +-} ATOM_I2C_ID_CONFIG; +- +-typedef union _ATOM_I2C_ID_CONFIG_ACCESS { +- ATOM_I2C_ID_CONFIG sbfAccess; +- UCHAR ucAccess; +-} ATOM_I2C_ID_CONFIG_ACCESS; ++// usDeviceSupport: ++// Bits0 = 0 - no CRT1 support= 1- CRT1 is supported ++// Bit 1 = 0 - no LCD1 support= 1- LCD1 is supported ++// Bit 2 = 0 - no TV1 support= 1- TV1 is supported ++// Bit 3 = 0 - no DFP1 support= 1- DFP1 is supported ++// Bit 4 = 0 - no CRT2 support= 1- CRT2 is supported ++// Bit 5 = 0 - no LCD2 support= 1- LCD2 is supported ++// Bit 6 = 0 - no DFP6 support= 1- DFP6 is supported ++// Bit 7 = 0 - no DFP2 support= 1- DFP2 is supported ++// Bit 8 = 0 - no CV support= 1- CV is supported ++// Bit 9 = 0 - no DFP3 support= 1- DFP3 is supported ++// Bit 10 = 0 - no DFP4 support= 1- DFP4 is supported ++// Bit 11 = 0 - no DFP5 support= 1- DFP5 is supported ++// ++// + + /****************************************************************************/ +-/* Structure used in GPIO_I2C_InfoTable */ ++/* Structure used in MclkSS_InfoTable */ + /****************************************************************************/ +-typedef struct _ATOM_GPIO_I2C_ASSIGMENT { +- USHORT usClkMaskRegisterIndex; +- USHORT usClkEnRegisterIndex; +- USHORT usClkY_RegisterIndex; +- USHORT usClkA_RegisterIndex; +- USHORT usDataMaskRegisterIndex; +- USHORT usDataEnRegisterIndex; +- USHORT usDataY_RegisterIndex; +- USHORT usDataA_RegisterIndex; +- ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; +- UCHAR ucClkMaskShift; +- UCHAR ucClkEnShift; +- UCHAR ucClkY_Shift; +- UCHAR ucClkA_Shift; +- UCHAR ucDataMaskShift; +- UCHAR ucDataEnShift; +- UCHAR ucDataY_Shift; +- UCHAR ucDataA_Shift; +- UCHAR ucReserved1; +- UCHAR ucReserved2; +-} ATOM_GPIO_I2C_ASSIGMENT; +- +-typedef struct _ATOM_GPIO_I2C_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_GPIO_I2C_ASSIGMENT asGPIO_Info[ATOM_MAX_SUPPORTED_DEVICE]; +-} ATOM_GPIO_I2C_INFO; ++// ucI2C_ConfigID ++// [7:0] - I2C LINE Associate ID ++// = 0 - no I2C ++// [7] - HW_Cap = 1, [6:0]=HW assisted I2C ID(HW line selection) ++// = 0, [6:0]=SW assisted I2C ID ++// [6-4] - HW_ENGINE_ID = 1, HW engine for NON multimedia use ++// = 2, HW engine for Multimedia use ++// = 3-7 Reserved for future I2C engines ++// [3-0] - I2C_LINE_MUX = A Mux number when it's HW assisted I2C or GPIO ID when it's SW I2C ++ ++typedef struct _ATOM_I2C_ID_CONFIG ++{ ++#if ATOM_BIG_ENDIAN ++ UCHAR bfHW_Capable:1; ++ UCHAR bfHW_EngineID:3; ++ UCHAR bfI2C_LineMux:4; ++#else ++ UCHAR bfI2C_LineMux:4; ++ UCHAR bfHW_EngineID:3; ++ UCHAR bfHW_Capable:1; ++#endif ++}ATOM_I2C_ID_CONFIG; + +-/****************************************************************************/ +-/* Common Structure used in other structures */ +-/****************************************************************************/ ++typedef union _ATOM_I2C_ID_CONFIG_ACCESS ++{ ++ ATOM_I2C_ID_CONFIG sbfAccess; ++ UCHAR ucAccess; ++}ATOM_I2C_ID_CONFIG_ACCESS; ++ ++ ++/****************************************************************************/ ++// Structure used in GPIO_I2C_InfoTable ++/****************************************************************************/ ++typedef struct _ATOM_GPIO_I2C_ASSIGMENT ++{ ++ USHORT usClkMaskRegisterIndex; ++ USHORT usClkEnRegisterIndex; ++ USHORT usClkY_RegisterIndex; ++ USHORT usClkA_RegisterIndex; ++ USHORT usDataMaskRegisterIndex; ++ USHORT usDataEnRegisterIndex; ++ USHORT usDataY_RegisterIndex; ++ USHORT usDataA_RegisterIndex; ++ ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; ++ UCHAR ucClkMaskShift; ++ UCHAR ucClkEnShift; ++ UCHAR ucClkY_Shift; ++ UCHAR ucClkA_Shift; ++ UCHAR ucDataMaskShift; ++ UCHAR ucDataEnShift; ++ UCHAR ucDataY_Shift; ++ UCHAR ucDataA_Shift; ++ UCHAR ucReserved1; ++ UCHAR ucReserved2; ++}ATOM_GPIO_I2C_ASSIGMENT; ++ ++typedef struct _ATOM_GPIO_I2C_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_GPIO_I2C_ASSIGMENT asGPIO_Info[ATOM_MAX_SUPPORTED_DEVICE]; ++}ATOM_GPIO_I2C_INFO; ++ ++/****************************************************************************/ ++// Common Structure used in other structures ++/****************************************************************************/ + + #ifndef _H2INC +- +-/* Please don't add or expand this bitfield structure below, this one will retire soon.! */ +-typedef struct _ATOM_MODE_MISC_INFO { ++ ++//Please don't add or expand this bitfield structure below, this one will retire soon.! ++typedef struct _ATOM_MODE_MISC_INFO ++{ + #if ATOM_BIG_ENDIAN +- USHORT Reserved:6; +- USHORT RGB888:1; +- USHORT DoubleClock:1; +- USHORT Interlace:1; +- USHORT CompositeSync:1; +- USHORT V_ReplicationBy2:1; +- USHORT H_ReplicationBy2:1; +- USHORT VerticalCutOff:1; +- USHORT VSyncPolarity:1; /* 0=Active High, 1=Active Low */ +- USHORT HSyncPolarity:1; /* 0=Active High, 1=Active Low */ +- USHORT HorizontalCutOff:1; ++ USHORT Reserved:6; ++ USHORT RGB888:1; ++ USHORT DoubleClock:1; ++ USHORT Interlace:1; ++ USHORT CompositeSync:1; ++ USHORT V_ReplicationBy2:1; ++ USHORT H_ReplicationBy2:1; ++ USHORT VerticalCutOff:1; ++ USHORT VSyncPolarity:1; //0=Active High, 1=Active Low ++ USHORT HSyncPolarity:1; //0=Active High, 1=Active Low ++ USHORT HorizontalCutOff:1; + #else +- USHORT HorizontalCutOff:1; +- USHORT HSyncPolarity:1; /* 0=Active High, 1=Active Low */ +- USHORT VSyncPolarity:1; /* 0=Active High, 1=Active Low */ +- USHORT VerticalCutOff:1; +- USHORT H_ReplicationBy2:1; +- USHORT V_ReplicationBy2:1; +- USHORT CompositeSync:1; +- USHORT Interlace:1; +- USHORT DoubleClock:1; +- USHORT RGB888:1; +- USHORT Reserved:6; ++ USHORT HorizontalCutOff:1; ++ USHORT HSyncPolarity:1; //0=Active High, 1=Active Low ++ USHORT VSyncPolarity:1; //0=Active High, 1=Active Low ++ USHORT VerticalCutOff:1; ++ USHORT H_ReplicationBy2:1; ++ USHORT V_ReplicationBy2:1; ++ USHORT CompositeSync:1; ++ USHORT Interlace:1; ++ USHORT DoubleClock:1; ++ USHORT RGB888:1; ++ USHORT Reserved:6; + #endif +-} ATOM_MODE_MISC_INFO; +- +-typedef union _ATOM_MODE_MISC_INFO_ACCESS { +- ATOM_MODE_MISC_INFO sbfAccess; +- USHORT usAccess; +-} ATOM_MODE_MISC_INFO_ACCESS; +- ++}ATOM_MODE_MISC_INFO; ++ ++typedef union _ATOM_MODE_MISC_INFO_ACCESS ++{ ++ ATOM_MODE_MISC_INFO sbfAccess; ++ USHORT usAccess; ++}ATOM_MODE_MISC_INFO_ACCESS; ++ + #else +- +-typedef union _ATOM_MODE_MISC_INFO_ACCESS { +- USHORT usAccess; +-} ATOM_MODE_MISC_INFO_ACCESS; +- ++ ++typedef union _ATOM_MODE_MISC_INFO_ACCESS ++{ ++ USHORT usAccess; ++}ATOM_MODE_MISC_INFO_ACCESS; ++ + #endif + +-/* usModeMiscInfo- */ ++// usModeMiscInfo- + #define ATOM_H_CUTOFF 0x01 +-#define ATOM_HSYNC_POLARITY 0x02 /* 0=Active High, 1=Active Low */ +-#define ATOM_VSYNC_POLARITY 0x04 /* 0=Active High, 1=Active Low */ ++#define ATOM_HSYNC_POLARITY 0x02 //0=Active High, 1=Active Low ++#define ATOM_VSYNC_POLARITY 0x04 //0=Active High, 1=Active Low + #define ATOM_V_CUTOFF 0x08 + #define ATOM_H_REPLICATIONBY2 0x10 + #define ATOM_V_REPLICATIONBY2 0x20 +@@ -2099,10 +2581,10 @@ typedef union _ATOM_MODE_MISC_INFO_ACCESS { + #define ATOM_DOUBLE_CLOCK_MODE 0x100 + #define ATOM_RGB888_MODE 0x200 + +-/* usRefreshRate- */ ++//usRefreshRate- + #define ATOM_REFRESH_43 43 + #define ATOM_REFRESH_47 47 +-#define ATOM_REFRESH_56 56 ++#define ATOM_REFRESH_56 56 + #define ATOM_REFRESH_60 60 + #define ATOM_REFRESH_65 65 + #define ATOM_REFRESH_70 70 +@@ -2110,192 +2592,233 @@ typedef union _ATOM_MODE_MISC_INFO_ACCESS { + #define ATOM_REFRESH_75 75 + #define ATOM_REFRESH_85 85 + +-/* ATOM_MODE_TIMING data are exactly the same as VESA timing data. */ +-/* Translation from EDID to ATOM_MODE_TIMING, use the following formula. */ +-/* */ +-/* VESA_HTOTAL = VESA_ACTIVE + 2* VESA_BORDER + VESA_BLANK */ +-/* = EDID_HA + EDID_HBL */ +-/* VESA_HDISP = VESA_ACTIVE = EDID_HA */ +-/* VESA_HSYNC_START = VESA_ACTIVE + VESA_BORDER + VESA_FRONT_PORCH */ +-/* = EDID_HA + EDID_HSO */ +-/* VESA_HSYNC_WIDTH = VESA_HSYNC_TIME = EDID_HSPW */ +-/* VESA_BORDER = EDID_BORDER */ +- +-/****************************************************************************/ +-/* Structure used in SetCRTC_UsingDTDTimingTable */ +-/****************************************************************************/ +-typedef struct _SET_CRTC_USING_DTD_TIMING_PARAMETERS { +- USHORT usH_Size; +- USHORT usH_Blanking_Time; +- USHORT usV_Size; +- USHORT usV_Blanking_Time; +- USHORT usH_SyncOffset; +- USHORT usH_SyncWidth; +- USHORT usV_SyncOffset; +- USHORT usV_SyncWidth; +- ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; +- UCHAR ucH_Border; /* From DFP EDID */ +- UCHAR ucV_Border; +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucPadding[3]; +-} SET_CRTC_USING_DTD_TIMING_PARAMETERS; +- +-/****************************************************************************/ +-/* Structure used in SetCRTC_TimingTable */ +-/****************************************************************************/ +-typedef struct _SET_CRTC_TIMING_PARAMETERS { +- USHORT usH_Total; /* horizontal total */ +- USHORT usH_Disp; /* horizontal display */ +- USHORT usH_SyncStart; /* horozontal Sync start */ +- USHORT usH_SyncWidth; /* horizontal Sync width */ +- USHORT usV_Total; /* vertical total */ +- USHORT usV_Disp; /* vertical display */ +- USHORT usV_SyncStart; /* vertical Sync start */ +- USHORT usV_SyncWidth; /* vertical Sync width */ +- ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; +- UCHAR ucCRTC; /* ATOM_CRTC1 or ATOM_CRTC2 */ +- UCHAR ucOverscanRight; /* right */ +- UCHAR ucOverscanLeft; /* left */ +- UCHAR ucOverscanBottom; /* bottom */ +- UCHAR ucOverscanTop; /* top */ +- UCHAR ucReserved; +-} SET_CRTC_TIMING_PARAMETERS; ++// ATOM_MODE_TIMING data are exactly the same as VESA timing data. ++// Translation from EDID to ATOM_MODE_TIMING, use the following formula. ++// ++// VESA_HTOTAL = VESA_ACTIVE + 2* VESA_BORDER + VESA_BLANK ++// = EDID_HA + EDID_HBL ++// VESA_HDISP = VESA_ACTIVE = EDID_HA ++// VESA_HSYNC_START = VESA_ACTIVE + VESA_BORDER + VESA_FRONT_PORCH ++// = EDID_HA + EDID_HSO ++// VESA_HSYNC_WIDTH = VESA_HSYNC_TIME = EDID_HSPW ++// VESA_BORDER = EDID_BORDER ++ ++/****************************************************************************/ ++// Structure used in SetCRTC_UsingDTDTimingTable ++/****************************************************************************/ ++typedef struct _SET_CRTC_USING_DTD_TIMING_PARAMETERS ++{ ++ USHORT usH_Size; ++ USHORT usH_Blanking_Time; ++ USHORT usV_Size; ++ USHORT usV_Blanking_Time; ++ USHORT usH_SyncOffset; ++ USHORT usH_SyncWidth; ++ USHORT usV_SyncOffset; ++ USHORT usV_SyncWidth; ++ ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; ++ UCHAR ucH_Border; // From DFP EDID ++ UCHAR ucV_Border; ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucPadding[3]; ++}SET_CRTC_USING_DTD_TIMING_PARAMETERS; ++ ++/****************************************************************************/ ++// Structure used in SetCRTC_TimingTable ++/****************************************************************************/ ++typedef struct _SET_CRTC_TIMING_PARAMETERS ++{ ++ USHORT usH_Total; // horizontal total ++ USHORT usH_Disp; // horizontal display ++ USHORT usH_SyncStart; // horozontal Sync start ++ USHORT usH_SyncWidth; // horizontal Sync width ++ USHORT usV_Total; // vertical total ++ USHORT usV_Disp; // vertical display ++ USHORT usV_SyncStart; // vertical Sync start ++ USHORT usV_SyncWidth; // vertical Sync width ++ ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; ++ UCHAR ucCRTC; // ATOM_CRTC1 or ATOM_CRTC2 ++ UCHAR ucOverscanRight; // right ++ UCHAR ucOverscanLeft; // left ++ UCHAR ucOverscanBottom; // bottom ++ UCHAR ucOverscanTop; // top ++ UCHAR ucReserved; ++}SET_CRTC_TIMING_PARAMETERS; + #define SET_CRTC_TIMING_PARAMETERS_PS_ALLOCATION SET_CRTC_TIMING_PARAMETERS + +-/****************************************************************************/ +-/* Structure used in StandardVESA_TimingTable */ +-/* AnalogTV_InfoTable */ +-/* ComponentVideoInfoTable */ +-/****************************************************************************/ +-typedef struct _ATOM_MODE_TIMING { +- USHORT usCRTC_H_Total; +- USHORT usCRTC_H_Disp; +- USHORT usCRTC_H_SyncStart; +- USHORT usCRTC_H_SyncWidth; +- USHORT usCRTC_V_Total; +- USHORT usCRTC_V_Disp; +- USHORT usCRTC_V_SyncStart; +- USHORT usCRTC_V_SyncWidth; +- USHORT usPixelClock; /* in 10Khz unit */ +- ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; +- USHORT usCRTC_OverscanRight; +- USHORT usCRTC_OverscanLeft; +- USHORT usCRTC_OverscanBottom; +- USHORT usCRTC_OverscanTop; +- USHORT usReserve; +- UCHAR ucInternalModeNumber; +- UCHAR ucRefreshRate; +-} ATOM_MODE_TIMING; +- +-typedef struct _ATOM_DTD_FORMAT { +- USHORT usPixClk; +- USHORT usHActive; +- USHORT usHBlanking_Time; +- USHORT usVActive; +- USHORT usVBlanking_Time; +- USHORT usHSyncOffset; +- USHORT usHSyncWidth; +- USHORT usVSyncOffset; +- USHORT usVSyncWidth; +- USHORT usImageHSize; +- USHORT usImageVSize; +- UCHAR ucHBorder; +- UCHAR ucVBorder; +- ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; +- UCHAR ucInternalModeNumber; +- UCHAR ucRefreshRate; +-} ATOM_DTD_FORMAT; +- +-/****************************************************************************/ +-/* Structure used in LVDS_InfoTable */ +-/* * Need a document to describe this table */ +-/****************************************************************************/ ++/****************************************************************************/ ++// Structure used in StandardVESA_TimingTable ++// AnalogTV_InfoTable ++// ComponentVideoInfoTable ++/****************************************************************************/ ++typedef struct _ATOM_MODE_TIMING ++{ ++ USHORT usCRTC_H_Total; ++ USHORT usCRTC_H_Disp; ++ USHORT usCRTC_H_SyncStart; ++ USHORT usCRTC_H_SyncWidth; ++ USHORT usCRTC_V_Total; ++ USHORT usCRTC_V_Disp; ++ USHORT usCRTC_V_SyncStart; ++ USHORT usCRTC_V_SyncWidth; ++ USHORT usPixelClock; //in 10Khz unit ++ ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; ++ USHORT usCRTC_OverscanRight; ++ USHORT usCRTC_OverscanLeft; ++ USHORT usCRTC_OverscanBottom; ++ USHORT usCRTC_OverscanTop; ++ USHORT usReserve; ++ UCHAR ucInternalModeNumber; ++ UCHAR ucRefreshRate; ++}ATOM_MODE_TIMING; ++ ++typedef struct _ATOM_DTD_FORMAT ++{ ++ USHORT usPixClk; ++ USHORT usHActive; ++ USHORT usHBlanking_Time; ++ USHORT usVActive; ++ USHORT usVBlanking_Time; ++ USHORT usHSyncOffset; ++ USHORT usHSyncWidth; ++ USHORT usVSyncOffset; ++ USHORT usVSyncWidth; ++ USHORT usImageHSize; ++ USHORT usImageVSize; ++ UCHAR ucHBorder; ++ UCHAR ucVBorder; ++ ATOM_MODE_MISC_INFO_ACCESS susModeMiscInfo; ++ UCHAR ucInternalModeNumber; ++ UCHAR ucRefreshRate; ++}ATOM_DTD_FORMAT; ++ ++/****************************************************************************/ ++// Structure used in LVDS_InfoTable ++// * Need a document to describe this table ++/****************************************************************************/ + #define SUPPORTED_LCD_REFRESHRATE_30Hz 0x0004 + #define SUPPORTED_LCD_REFRESHRATE_40Hz 0x0008 + #define SUPPORTED_LCD_REFRESHRATE_50Hz 0x0010 + #define SUPPORTED_LCD_REFRESHRATE_60Hz 0x0020 + +-/* Once DAL sees this CAP is set, it will read EDID from LCD on its own instead of using sLCDTiming in ATOM_LVDS_INFO_V12. */ +-/* Other entries in ATOM_LVDS_INFO_V12 are still valid/useful to DAL */ +-#define LCDPANEL_CAP_READ_EDID 0x1 +- +-/* ucTableFormatRevision=1 */ +-/* ucTableContentRevision=1 */ +-typedef struct _ATOM_LVDS_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_DTD_FORMAT sLCDTiming; +- USHORT usModePatchTableOffset; +- USHORT usSupportedRefreshRate; /* Refer to panel info table in ATOMBIOS extension Spec. */ +- USHORT usOffDelayInMs; +- UCHAR ucPowerSequenceDigOntoDEin10Ms; +- UCHAR ucPowerSequenceDEtoBLOnin10Ms; +- UCHAR ucLVDS_Misc; /* Bit0:{=0:single, =1:dual},Bit1 {=0:666RGB, =1:888RGB},Bit2:3:{Grey level} */ +- /* Bit4:{=0:LDI format for RGB888, =1 FPDI format for RGB888} */ +- /* Bit5:{=0:Spatial Dithering disabled;1 Spatial Dithering enabled} */ +- /* Bit6:{=0:Temporal Dithering disabled;1 Temporal Dithering enabled} */ +- UCHAR ucPanelDefaultRefreshRate; +- UCHAR ucPanelIdentification; +- UCHAR ucSS_Id; +-} ATOM_LVDS_INFO; +- +-/* ucTableFormatRevision=1 */ +-/* ucTableContentRevision=2 */ +-typedef struct _ATOM_LVDS_INFO_V12 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_DTD_FORMAT sLCDTiming; +- USHORT usExtInfoTableOffset; +- USHORT usSupportedRefreshRate; /* Refer to panel info table in ATOMBIOS extension Spec. */ +- USHORT usOffDelayInMs; +- UCHAR ucPowerSequenceDigOntoDEin10Ms; +- UCHAR ucPowerSequenceDEtoBLOnin10Ms; +- UCHAR ucLVDS_Misc; /* Bit0:{=0:single, =1:dual},Bit1 {=0:666RGB, =1:888RGB},Bit2:3:{Grey level} */ +- /* Bit4:{=0:LDI format for RGB888, =1 FPDI format for RGB888} */ +- /* Bit5:{=0:Spatial Dithering disabled;1 Spatial Dithering enabled} */ +- /* Bit6:{=0:Temporal Dithering disabled;1 Temporal Dithering enabled} */ +- UCHAR ucPanelDefaultRefreshRate; +- UCHAR ucPanelIdentification; +- UCHAR ucSS_Id; +- USHORT usLCDVenderID; +- USHORT usLCDProductID; +- UCHAR ucLCDPanel_SpecialHandlingCap; +- UCHAR ucPanelInfoSize; /* start from ATOM_DTD_FORMAT to end of panel info, include ExtInfoTable */ +- UCHAR ucReserved[2]; +-} ATOM_LVDS_INFO_V12; ++//ucTableFormatRevision=1 ++//ucTableContentRevision=1 ++typedef struct _ATOM_LVDS_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_DTD_FORMAT sLCDTiming; ++ USHORT usModePatchTableOffset; ++ USHORT usSupportedRefreshRate; //Refer to panel info table in ATOMBIOS extension Spec. ++ USHORT usOffDelayInMs; ++ UCHAR ucPowerSequenceDigOntoDEin10Ms; ++ UCHAR ucPowerSequenceDEtoBLOnin10Ms; ++ UCHAR ucLVDS_Misc; // Bit0:{=0:single, =1:dual},Bit1 {=0:666RGB, =1:888RGB},Bit2:3:{Grey level} ++ // Bit4:{=0:LDI format for RGB888, =1 FPDI format for RGB888} ++ // Bit5:{=0:Spatial Dithering disabled;1 Spatial Dithering enabled} ++ // Bit6:{=0:Temporal Dithering disabled;1 Temporal Dithering enabled} ++ UCHAR ucPanelDefaultRefreshRate; ++ UCHAR ucPanelIdentification; ++ UCHAR ucSS_Id; ++}ATOM_LVDS_INFO; ++ ++//ucTableFormatRevision=1 ++//ucTableContentRevision=2 ++typedef struct _ATOM_LVDS_INFO_V12 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_DTD_FORMAT sLCDTiming; ++ USHORT usExtInfoTableOffset; ++ USHORT usSupportedRefreshRate; //Refer to panel info table in ATOMBIOS extension Spec. ++ USHORT usOffDelayInMs; ++ UCHAR ucPowerSequenceDigOntoDEin10Ms; ++ UCHAR ucPowerSequenceDEtoBLOnin10Ms; ++ UCHAR ucLVDS_Misc; // Bit0:{=0:single, =1:dual},Bit1 {=0:666RGB, =1:888RGB},Bit2:3:{Grey level} ++ // Bit4:{=0:LDI format for RGB888, =1 FPDI format for RGB888} ++ // Bit5:{=0:Spatial Dithering disabled;1 Spatial Dithering enabled} ++ // Bit6:{=0:Temporal Dithering disabled;1 Temporal Dithering enabled} ++ UCHAR ucPanelDefaultRefreshRate; ++ UCHAR ucPanelIdentification; ++ UCHAR ucSS_Id; ++ USHORT usLCDVenderID; ++ USHORT usLCDProductID; ++ UCHAR ucLCDPanel_SpecialHandlingCap; ++ UCHAR ucPanelInfoSize; // start from ATOM_DTD_FORMAT to end of panel info, include ExtInfoTable ++ UCHAR ucReserved[2]; ++}ATOM_LVDS_INFO_V12; ++ ++//Definitions for ucLCDPanel_SpecialHandlingCap: ++ ++//Once DAL sees this CAP is set, it will read EDID from LCD on its own instead of using sLCDTiming in ATOM_LVDS_INFO_V12. ++//Other entries in ATOM_LVDS_INFO_V12 are still valid/useful to DAL ++#define LCDPANEL_CAP_READ_EDID 0x1 ++ ++//If a design supports DRR (dynamic refresh rate) on internal panels (LVDS or EDP), this cap is set in ucLCDPanel_SpecialHandlingCap together ++//with multiple supported refresh rates@usSupportedRefreshRate. This cap should not be set when only slow refresh rate is supported (static ++//refresh rate switch by SW. This is only valid from ATOM_LVDS_INFO_V12 ++#define LCDPANEL_CAP_DRR_SUPPORTED 0x2 ++ ++//Use this cap bit for a quick reference whether an embadded panel (LCD1 ) is LVDS or eDP. ++#define LCDPANEL_CAP_eDP 0x4 ++ ++ ++//Color Bit Depth definition in EDID V1.4 @BYTE 14h ++//Bit 6 5 4 ++ // 0 0 0 - Color bit depth is undefined ++ // 0 0 1 - 6 Bits per Primary Color ++ // 0 1 0 - 8 Bits per Primary Color ++ // 0 1 1 - 10 Bits per Primary Color ++ // 1 0 0 - 12 Bits per Primary Color ++ // 1 0 1 - 14 Bits per Primary Color ++ // 1 1 0 - 16 Bits per Primary Color ++ // 1 1 1 - Reserved ++ ++#define PANEL_COLOR_BIT_DEPTH_MASK 0x70 ++ ++// Bit7:{=0:Random Dithering disabled;1 Random Dithering enabled} ++#define PANEL_RANDOM_DITHER 0x80 ++#define PANEL_RANDOM_DITHER_MASK 0x80 ++ + + #define ATOM_LVDS_INFO_LAST ATOM_LVDS_INFO_V12 + +-typedef struct _ATOM_PATCH_RECORD_MODE { +- UCHAR ucRecordType; +- USHORT usHDisp; +- USHORT usVDisp; +-} ATOM_PATCH_RECORD_MODE; ++typedef struct _ATOM_PATCH_RECORD_MODE ++{ ++ UCHAR ucRecordType; ++ USHORT usHDisp; ++ USHORT usVDisp; ++}ATOM_PATCH_RECORD_MODE; + +-typedef struct _ATOM_LCD_RTS_RECORD { +- UCHAR ucRecordType; +- UCHAR ucRTSValue; +-} ATOM_LCD_RTS_RECORD; ++typedef struct _ATOM_LCD_RTS_RECORD ++{ ++ UCHAR ucRecordType; ++ UCHAR ucRTSValue; ++}ATOM_LCD_RTS_RECORD; + +-/* !! If the record below exits, it shoud always be the first record for easy use in command table!!! */ +-typedef struct _ATOM_LCD_MODE_CONTROL_CAP { +- UCHAR ucRecordType; +- USHORT usLCDCap; +-} ATOM_LCD_MODE_CONTROL_CAP; ++//!! If the record below exits, it shoud always be the first record for easy use in command table!!! ++// The record below is only used when LVDS_Info is present. From ATOM_LVDS_INFO_V12, use ucLCDPanel_SpecialHandlingCap instead. ++typedef struct _ATOM_LCD_MODE_CONTROL_CAP ++{ ++ UCHAR ucRecordType; ++ USHORT usLCDCap; ++}ATOM_LCD_MODE_CONTROL_CAP; + + #define LCD_MODE_CAP_BL_OFF 1 + #define LCD_MODE_CAP_CRTC_OFF 2 + #define LCD_MODE_CAP_PANEL_OFF 4 + +-typedef struct _ATOM_FAKE_EDID_PATCH_RECORD { +- UCHAR ucRecordType; +- UCHAR ucFakeEDIDLength; +- UCHAR ucFakeEDIDString[1]; /* This actually has ucFakeEdidLength elements. */ ++typedef struct _ATOM_FAKE_EDID_PATCH_RECORD ++{ ++ UCHAR ucRecordType; ++ UCHAR ucFakeEDIDLength; ++ UCHAR ucFakeEDIDString[1]; // This actually has ucFakeEdidLength elements. + } ATOM_FAKE_EDID_PATCH_RECORD; + +-typedef struct _ATOM_PANEL_RESOLUTION_PATCH_RECORD { +- UCHAR ucRecordType; +- USHORT usHSize; +- USHORT usVSize; +-} ATOM_PANEL_RESOLUTION_PATCH_RECORD; ++typedef struct _ATOM_PANEL_RESOLUTION_PATCH_RECORD ++{ ++ UCHAR ucRecordType; ++ USHORT usHSize; ++ USHORT usVSize; ++}ATOM_PANEL_RESOLUTION_PATCH_RECORD; + + #define LCD_MODE_PATCH_RECORD_MODE_TYPE 1 + #define LCD_RTS_RECORD_TYPE 2 +@@ -2306,21 +2829,25 @@ typedef struct _ATOM_PANEL_RESOLUTION_PATCH_RECORD { + + /****************************Spread Spectrum Info Table Definitions **********************/ + +-/* ucTableFormatRevision=1 */ +-/* ucTableContentRevision=2 */ +-typedef struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT { +- USHORT usSpreadSpectrumPercentage; +- UCHAR ucSpreadSpectrumType; /* Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Others:TBD */ +- UCHAR ucSS_Step; +- UCHAR ucSS_Delay; +- UCHAR ucSS_Id; +- UCHAR ucRecommendedRef_Div; +- UCHAR ucSS_Range; /* it was reserved for V11 */ +-} ATOM_SPREAD_SPECTRUM_ASSIGNMENT; ++//ucTableFormatRevision=1 ++//ucTableContentRevision=2 ++typedef struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT ++{ ++ USHORT usSpreadSpectrumPercentage; ++ UCHAR ucSpreadSpectrumType; //Bit1=0 Down Spread,=1 Center Spread. Bit1=1 Ext. =0 Int. Bit2=1: PCIE REFCLK SS =0 iternal PPLL SS Others:TBD ++ UCHAR ucSS_Step; ++ UCHAR ucSS_Delay; ++ UCHAR ucSS_Id; ++ UCHAR ucRecommendedRef_Div; ++ UCHAR ucSS_Range; //it was reserved for V11 ++}ATOM_SPREAD_SPECTRUM_ASSIGNMENT; + + #define ATOM_MAX_SS_ENTRY 16 +-#define ATOM_DP_SS_ID1 0x0f1 /* SS modulation freq=30k */ +-#define ATOM_DP_SS_ID2 0x0f2 /* SS modulation freq=33k */ ++#define ATOM_DP_SS_ID1 0x0f1 // SS ID for internal DP stream at 2.7Ghz. if ATOM_DP_SS_ID2 does not exist in SS_InfoTable, it is used for internal DP stream at 1.62Ghz as well. ++#define ATOM_DP_SS_ID2 0x0f2 // SS ID for internal DP stream at 1.62Ghz, if it exists in SS_InfoTable. ++#define ATOM_LVLINK_2700MHz_SS_ID 0x0f3 // SS ID for LV link translator chip at 2.7Ghz ++#define ATOM_LVLINK_1620MHz_SS_ID 0x0f4 // SS ID for LV link translator chip at 1.62Ghz ++ + + #define ATOM_SS_DOWN_SPREAD_MODE_MASK 0x00000000 + #define ATOM_SS_DOWN_SPREAD_MODE 0x00000000 +@@ -2329,29 +2856,30 @@ typedef struct _ATOM_SPREAD_SPECTRUM_ASSIGNMENT { + #define ATOM_INTERNAL_SS_MASK 0x00000000 + #define ATOM_EXTERNAL_SS_MASK 0x00000002 + #define EXEC_SS_STEP_SIZE_SHIFT 2 +-#define EXEC_SS_DELAY_SHIFT 4 ++#define EXEC_SS_DELAY_SHIFT 4 + #define ACTIVEDATA_TO_BLON_DELAY_SHIFT 4 + +-typedef struct _ATOM_SPREAD_SPECTRUM_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_SPREAD_SPECTRUM_ASSIGNMENT asSS_Info[ATOM_MAX_SS_ENTRY]; +-} ATOM_SPREAD_SPECTRUM_INFO; +- +-/****************************************************************************/ +-/* Structure used in AnalogTV_InfoTable (Top level) */ +-/****************************************************************************/ +-/* ucTVBootUpDefaultStd definiton: */ +- +-/* ATOM_TV_NTSC 1 */ +-/* ATOM_TV_NTSCJ 2 */ +-/* ATOM_TV_PAL 3 */ +-/* ATOM_TV_PALM 4 */ +-/* ATOM_TV_PALCN 5 */ +-/* ATOM_TV_PALN 6 */ +-/* ATOM_TV_PAL60 7 */ +-/* ATOM_TV_SECAM 8 */ +- +-/* ucTVSuppportedStd definition: */ ++typedef struct _ATOM_SPREAD_SPECTRUM_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_SPREAD_SPECTRUM_ASSIGNMENT asSS_Info[ATOM_MAX_SS_ENTRY]; ++}ATOM_SPREAD_SPECTRUM_INFO; ++ ++/****************************************************************************/ ++// Structure used in AnalogTV_InfoTable (Top level) ++/****************************************************************************/ ++//ucTVBootUpDefaultStd definiton: ++ ++//ATOM_TV_NTSC 1 ++//ATOM_TV_NTSCJ 2 ++//ATOM_TV_PAL 3 ++//ATOM_TV_PALM 4 ++//ATOM_TV_PALCN 5 ++//ATOM_TV_PALN 6 ++//ATOM_TV_PAL60 7 ++//ATOM_TV_SECAM 8 ++ ++//ucTVSupportedStd definition: + #define NTSC_SUPPORT 0x1 + #define NTSCJ_SUPPORT 0x2 + +@@ -2364,46 +2892,58 @@ typedef struct _ATOM_SPREAD_SPECTRUM_INFO { + + #define MAX_SUPPORTED_TV_TIMING 2 + +-typedef struct _ATOM_ANALOG_TV_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucTV_SupportedStandard; +- UCHAR ucTV_BootUpDefaultStandard; +- UCHAR ucExt_TV_ASIC_ID; +- UCHAR ucExt_TV_ASIC_SlaveAddr; +- /*ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_TV_TIMING]; */ +- ATOM_MODE_TIMING aModeTimings[MAX_SUPPORTED_TV_TIMING]; +-} ATOM_ANALOG_TV_INFO; ++typedef struct _ATOM_ANALOG_TV_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucTV_SupportedStandard; ++ UCHAR ucTV_BootUpDefaultStandard; ++ UCHAR ucExt_TV_ASIC_ID; ++ UCHAR ucExt_TV_ASIC_SlaveAddr; ++ /*ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_TV_TIMING];*/ ++ ATOM_MODE_TIMING aModeTimings[MAX_SUPPORTED_TV_TIMING]; ++}ATOM_ANALOG_TV_INFO; + + #define MAX_SUPPORTED_TV_TIMING_V1_2 3 + +-typedef struct _ATOM_ANALOG_TV_INFO_V1_2 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucTV_SupportedStandard; +- UCHAR ucTV_BootUpDefaultStandard; +- UCHAR ucExt_TV_ASIC_ID; +- UCHAR ucExt_TV_ASIC_SlaveAddr; +- ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_TV_TIMING]; +-} ATOM_ANALOG_TV_INFO_V1_2; ++typedef struct _ATOM_ANALOG_TV_INFO_V1_2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucTV_SupportedStandard; ++ UCHAR ucTV_BootUpDefaultStandard; ++ UCHAR ucExt_TV_ASIC_ID; ++ UCHAR ucExt_TV_ASIC_SlaveAddr; ++ ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_TV_TIMING]; ++}ATOM_ANALOG_TV_INFO_V1_2; ++ ++typedef struct _ATOM_DPCD_INFO ++{ ++ UCHAR ucRevisionNumber; //10h : Revision 1.0; 11h : Revision 1.1 ++ UCHAR ucMaxLinkRate; //06h : 1.62Gbps per lane; 0Ah = 2.7Gbps per lane ++ UCHAR ucMaxLane; //Bits 4:0 = MAX_LANE_COUNT (1/2/4). Bit 7 = ENHANCED_FRAME_CAP ++ UCHAR ucMaxDownSpread; //Bit0 = 0: No Down spread; Bit0 = 1: 0.5% (Subject to change according to DP spec) ++}ATOM_DPCD_INFO; ++ ++#define ATOM_DPCD_MAX_LANE_MASK 0x1F + + /**************************************************************************/ +-/* VRAM usage and their definitions */ ++// VRAM usage and their defintions + +-/* One chunk of VRAM used by Bios are for HWICON surfaces,EDID data. */ +-/* Current Mode timing and Dail Timing and/or STD timing data EACH device. They can be broken down as below. */ +-/* All the addresses below are the offsets from the frame buffer start.They all MUST be Dword aligned! */ +-/* To driver: The physical address of this memory portion=mmFB_START(4K aligned)+ATOMBIOS_VRAM_USAGE_START_ADDR+ATOM_x_ADDR */ +-/* To Bios: ATOMBIOS_VRAM_USAGE_START_ADDR+ATOM_x_ADDR->MM_INDEX */ ++// One chunk of VRAM used by Bios are for HWICON surfaces,EDID data. ++// Current Mode timing and Dail Timing and/or STD timing data EACH device. They can be broken down as below. ++// All the addresses below are the offsets from the frame buffer start.They all MUST be Dword aligned! ++// To driver: The physical address of this memory portion=mmFB_START(4K aligned)+ATOMBIOS_VRAM_USAGE_START_ADDR+ATOM_x_ADDR ++// To Bios: ATOMBIOS_VRAM_USAGE_START_ADDR+ATOM_x_ADDR->MM_INDEX + + #ifndef VESA_MEMORY_IN_64K_BLOCK +-#define VESA_MEMORY_IN_64K_BLOCK 0x100 /* 256*64K=16Mb (Max. VESA memory is 16Mb!) */ ++#define VESA_MEMORY_IN_64K_BLOCK 0x100 //256*64K=16Mb (Max. VESA memory is 16Mb!) + #endif + +-#define ATOM_EDID_RAW_DATASIZE 256 /* In Bytes */ +-#define ATOM_HWICON_SURFACE_SIZE 4096 /* In Bytes */ ++#define ATOM_EDID_RAW_DATASIZE 256 //In Bytes ++#define ATOM_HWICON_SURFACE_SIZE 4096 //In Bytes + #define ATOM_HWICON_INFOTABLE_SIZE 32 + #define MAX_DTD_MODE_IN_VRAM 6 +-#define ATOM_DTD_MODE_SUPPORT_TBL_SIZE (MAX_DTD_MODE_IN_VRAM*28) /* 28= (SIZEOF ATOM_DTD_FORMAT) */ +-#define ATOM_STD_MODE_SUPPORT_TBL_SIZE (32*8) /* 32 is a predefined number,8= (SIZEOF ATOM_STD_FORMAT) */ ++#define ATOM_DTD_MODE_SUPPORT_TBL_SIZE (MAX_DTD_MODE_IN_VRAM*28) //28= (SIZEOF ATOM_DTD_FORMAT) ++#define ATOM_STD_MODE_SUPPORT_TBL_SIZE 32*8 //32 is a predefined number,8= (SIZEOF ATOM_STD_FORMAT) + #define DFP_ENCODER_TYPE_OFFSET 0x80 + #define DP_ENCODER_LANE_NUM_OFFSET 0x84 + #define DP_ENCODER_LINK_RATE_OFFSET 0x88 +@@ -2417,7 +2957,7 @@ typedef struct _ATOM_ANALOG_TV_INFO_V1_2 { + + #define ATOM_LCD1_EDID_ADDR (ATOM_CRT1_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) + #define ATOM_LCD1_DTD_MODE_TBL_ADDR (ATOM_LCD1_EDID_ADDR + ATOM_EDID_RAW_DATASIZE) +-#define ATOM_LCD1_STD_MODE_TBL_ADDR (ATOM_LCD1_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) ++#define ATOM_LCD1_STD_MODE_TBL_ADDR (ATOM_LCD1_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) + + #define ATOM_TV1_DTD_MODE_TBL_ADDR (ATOM_LCD1_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) + +@@ -2431,13 +2971,13 @@ typedef struct _ATOM_ANALOG_TV_INFO_V1_2 { + + #define ATOM_LCD2_EDID_ADDR (ATOM_CRT2_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) + #define ATOM_LCD2_DTD_MODE_TBL_ADDR (ATOM_LCD2_EDID_ADDR + ATOM_EDID_RAW_DATASIZE) +-#define ATOM_LCD2_STD_MODE_TBL_ADDR (ATOM_LCD2_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) ++#define ATOM_LCD2_STD_MODE_TBL_ADDR (ATOM_LCD2_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) + +-#define ATOM_TV2_EDID_ADDR (ATOM_LCD2_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) +-#define ATOM_TV2_DTD_MODE_TBL_ADDR (ATOM_TV2_EDID_ADDR + ATOM_EDID_RAW_DATASIZE) +-#define ATOM_TV2_STD_MODE_TBL_ADDR (ATOM_TV2_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) ++#define ATOM_DFP6_EDID_ADDR (ATOM_LCD2_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) ++#define ATOM_DFP6_DTD_MODE_TBL_ADDR (ATOM_DFP6_EDID_ADDR + ATOM_EDID_RAW_DATASIZE) ++#define ATOM_DFP6_STD_MODE_TBL_ADDR (ATOM_DFP6_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) + +-#define ATOM_DFP2_EDID_ADDR (ATOM_TV2_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) ++#define ATOM_DFP2_EDID_ADDR (ATOM_DFP6_STD_MODE_TBL_ADDR + ATOM_STD_MODE_SUPPORT_TBL_SIZE) + #define ATOM_DFP2_DTD_MODE_TBL_ADDR (ATOM_DFP2_EDID_ADDR + ATOM_EDID_RAW_DATASIZE) + #define ATOM_DFP2_STD_MODE_TBL_ADDR (ATOM_DFP2_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) + +@@ -2457,533 +2997,850 @@ typedef struct _ATOM_ANALOG_TV_INFO_V1_2 { + #define ATOM_DFP5_DTD_MODE_TBL_ADDR (ATOM_DFP5_EDID_ADDR + ATOM_EDID_RAW_DATASIZE) + #define ATOM_DFP5_STD_MODE_TBL_ADDR (ATOM_DFP5_DTD_MODE_TBL_ADDR + ATOM_DTD_MODE_SUPPORT_TBL_SIZE) + +-#define ATOM_DP_TRAINING_TBL_ADDR (ATOM_DFP5_STD_MODE_TBL_ADDR+ATOM_STD_MODE_SUPPORT_TBL_SIZE) ++#define ATOM_DP_TRAINING_TBL_ADDR (ATOM_DFP5_STD_MODE_TBL_ADDR+ATOM_STD_MODE_SUPPORT_TBL_SIZE) + +-#define ATOM_STACK_STORAGE_START (ATOM_DP_TRAINING_TBL_ADDR + 256) +-#define ATOM_STACK_STORAGE_END (ATOM_STACK_STORAGE_START + 512) ++#define ATOM_STACK_STORAGE_START (ATOM_DP_TRAINING_TBL_ADDR+256) ++#define ATOM_STACK_STORAGE_END ATOM_STACK_STORAGE_START+512 + +-/* The size below is in Kb! */ ++//The size below is in Kb! + #define ATOM_VRAM_RESERVE_SIZE ((((ATOM_STACK_STORAGE_END - ATOM_HWICON1_SURFACE_ADDR)>>10)+4)&0xFFFC) +- ++ + #define ATOM_VRAM_OPERATION_FLAGS_MASK 0xC0000000L + #define ATOM_VRAM_OPERATION_FLAGS_SHIFT 30 + #define ATOM_VRAM_BLOCK_NEEDS_NO_RESERVATION 0x1 + #define ATOM_VRAM_BLOCK_NEEDS_RESERVATION 0x0 + +-/***********************************************************************************/ +-/* Structure used in VRAM_UsageByFirmwareTable */ +-/* Note1: This table is filled by SetBiosReservationStartInFB in CoreCommSubs.asm */ +-/* at running time. */ +-/* note2: From RV770, the memory is more than 32bit addressable, so we will change */ +-/* ucTableFormatRevision=1,ucTableContentRevision=4, the strcuture remains */ +-/* exactly same as 1.1 and 1.2 (1.3 is never in use), but ulStartAddrUsedByFirmware */ +-/* (in offset to start of memory address) is KB aligned instead of byte aligend. */ +-/***********************************************************************************/ ++/***********************************************************************************/ ++// Structure used in VRAM_UsageByFirmwareTable ++// Note1: This table is filled by SetBiosReservationStartInFB in CoreCommSubs.asm ++// at running time. ++// note2: From RV770, the memory is more than 32bit addressable, so we will change ++// ucTableFormatRevision=1,ucTableContentRevision=4, the strcuture remains ++// exactly same as 1.1 and 1.2 (1.3 is never in use), but ulStartAddrUsedByFirmware ++// (in offset to start of memory address) is KB aligned instead of byte aligend. ++/***********************************************************************************/ ++// Note3: ++/* If we change usReserved to "usFBUsedbyDrvInKB", then to VBIOS this usFBUsedbyDrvInKB is a predefined, unchanged constant across VGA or non VGA adapter, ++for CAIL, The size of FB access area is known, only thing missing is the Offset of FB Access area, so we can have: ++ ++If (ulStartAddrUsedByFirmware!=0) ++FBAccessAreaOffset= ulStartAddrUsedByFirmware - usFBUsedbyDrvInKB; ++Reserved area has been claimed by VBIOS including this FB access area; CAIL doesn't need to reserve any extra area for this purpose ++else //Non VGA case ++ if (FB_Size<=2Gb) ++ FBAccessAreaOffset= FB_Size - usFBUsedbyDrvInKB; ++ else ++ FBAccessAreaOffset= Aper_Size - usFBUsedbyDrvInKB ++ ++CAIL needs to claim an reserved area defined by FBAccessAreaOffset and usFBUsedbyDrvInKB in non VGA case.*/ ++ + #define ATOM_MAX_FIRMWARE_VRAM_USAGE_INFO 1 + +-typedef struct _ATOM_FIRMWARE_VRAM_RESERVE_INFO { +- ULONG ulStartAddrUsedByFirmware; +- USHORT usFirmwareUseInKb; +- USHORT usReserved; +-} ATOM_FIRMWARE_VRAM_RESERVE_INFO; ++typedef struct _ATOM_FIRMWARE_VRAM_RESERVE_INFO ++{ ++ ULONG ulStartAddrUsedByFirmware; ++ USHORT usFirmwareUseInKb; ++ USHORT usReserved; ++}ATOM_FIRMWARE_VRAM_RESERVE_INFO; + +-typedef struct _ATOM_VRAM_USAGE_BY_FIRMWARE { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_FIRMWARE_VRAM_RESERVE_INFO +- asFirmwareVramReserveInfo[ATOM_MAX_FIRMWARE_VRAM_USAGE_INFO]; +-} ATOM_VRAM_USAGE_BY_FIRMWARE; ++typedef struct _ATOM_VRAM_USAGE_BY_FIRMWARE ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_FIRMWARE_VRAM_RESERVE_INFO asFirmwareVramReserveInfo[ATOM_MAX_FIRMWARE_VRAM_USAGE_INFO]; ++}ATOM_VRAM_USAGE_BY_FIRMWARE; + +-/****************************************************************************/ +-/* Structure used in GPIO_Pin_LUTTable */ +-/****************************************************************************/ +-typedef struct _ATOM_GPIO_PIN_ASSIGNMENT { +- USHORT usGpioPin_AIndex; +- UCHAR ucGpioPinBitShift; +- UCHAR ucGPIO_ID; +-} ATOM_GPIO_PIN_ASSIGNMENT; ++// change verion to 1.5, when allow driver to allocate the vram area for command table access. ++typedef struct _ATOM_FIRMWARE_VRAM_RESERVE_INFO_V1_5 ++{ ++ ULONG ulStartAddrUsedByFirmware; ++ USHORT usFirmwareUseInKb; ++ USHORT usFBUsedByDrvInKb; ++}ATOM_FIRMWARE_VRAM_RESERVE_INFO_V1_5; + +-typedef struct _ATOM_GPIO_PIN_LUT { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_GPIO_PIN_ASSIGNMENT asGPIO_Pin[1]; +-} ATOM_GPIO_PIN_LUT; ++typedef struct _ATOM_VRAM_USAGE_BY_FIRMWARE_V1_5 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_FIRMWARE_VRAM_RESERVE_INFO_V1_5 asFirmwareVramReserveInfo[ATOM_MAX_FIRMWARE_VRAM_USAGE_INFO]; ++}ATOM_VRAM_USAGE_BY_FIRMWARE_V1_5; ++ ++/****************************************************************************/ ++// Structure used in GPIO_Pin_LUTTable ++/****************************************************************************/ ++typedef struct _ATOM_GPIO_PIN_ASSIGNMENT ++{ ++ USHORT usGpioPin_AIndex; ++ UCHAR ucGpioPinBitShift; ++ UCHAR ucGPIO_ID; ++}ATOM_GPIO_PIN_ASSIGNMENT; + +-/****************************************************************************/ +-/* Structure used in ComponentVideoInfoTable */ +-/****************************************************************************/ ++typedef struct _ATOM_GPIO_PIN_LUT ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_GPIO_PIN_ASSIGNMENT asGPIO_Pin[1]; ++}ATOM_GPIO_PIN_LUT; ++ ++/****************************************************************************/ ++// Structure used in ComponentVideoInfoTable ++/****************************************************************************/ + #define GPIO_PIN_ACTIVE_HIGH 0x1 + + #define MAX_SUPPORTED_CV_STANDARDS 5 + +-/* definitions for ATOM_D_INFO.ucSettings */ +-#define ATOM_GPIO_SETTINGS_BITSHIFT_MASK 0x1F /* [4:0] */ +-#define ATOM_GPIO_SETTINGS_RESERVED_MASK 0x60 /* [6:5] = must be zeroed out */ +-#define ATOM_GPIO_SETTINGS_ACTIVE_MASK 0x80 /* [7] */ ++// definitions for ATOM_D_INFO.ucSettings ++#define ATOM_GPIO_SETTINGS_BITSHIFT_MASK 0x1F // [4:0] ++#define ATOM_GPIO_SETTINGS_RESERVED_MASK 0x60 // [6:5] = must be zeroed out ++#define ATOM_GPIO_SETTINGS_ACTIVE_MASK 0x80 // [7] + +-typedef struct _ATOM_GPIO_INFO { +- USHORT usAOffset; +- UCHAR ucSettings; +- UCHAR ucReserved; +-} ATOM_GPIO_INFO; ++typedef struct _ATOM_GPIO_INFO ++{ ++ USHORT usAOffset; ++ UCHAR ucSettings; ++ UCHAR ucReserved; ++}ATOM_GPIO_INFO; + +-/* definitions for ATOM_COMPONENT_VIDEO_INFO.ucMiscInfo (bit vector) */ ++// definitions for ATOM_COMPONENT_VIDEO_INFO.ucMiscInfo (bit vector) + #define ATOM_CV_RESTRICT_FORMAT_SELECTION 0x2 + +-/* definitions for ATOM_COMPONENT_VIDEO_INFO.uc480i/uc480p/uc720p/uc1080i */ +-#define ATOM_GPIO_DEFAULT_MODE_EN 0x80 /* [7]; */ +-#define ATOM_GPIO_SETTING_PERMODE_MASK 0x7F /* [6:0] */ +- +-/* definitions for ATOM_COMPONENT_VIDEO_INFO.ucLetterBoxMode */ +-/* Line 3 out put 5V. */ +-#define ATOM_CV_LINE3_ASPECTRATIO_16_9_GPIO_A 0x01 /* represent gpio 3 state for 16:9 */ +-#define ATOM_CV_LINE3_ASPECTRATIO_16_9_GPIO_B 0x02 /* represent gpio 4 state for 16:9 */ +-#define ATOM_CV_LINE3_ASPECTRATIO_16_9_GPIO_SHIFT 0x0 +- +-/* Line 3 out put 2.2V */ +-#define ATOM_CV_LINE3_ASPECTRATIO_4_3_LETBOX_GPIO_A 0x04 /* represent gpio 3 state for 4:3 Letter box */ +-#define ATOM_CV_LINE3_ASPECTRATIO_4_3_LETBOX_GPIO_B 0x08 /* represent gpio 4 state for 4:3 Letter box */ +-#define ATOM_CV_LINE3_ASPECTRATIO_4_3_LETBOX_GPIO_SHIFT 0x2 +- +-/* Line 3 out put 0V */ +-#define ATOM_CV_LINE3_ASPECTRATIO_4_3_GPIO_A 0x10 /* represent gpio 3 state for 4:3 */ +-#define ATOM_CV_LINE3_ASPECTRATIO_4_3_GPIO_B 0x20 /* represent gpio 4 state for 4:3 */ +-#define ATOM_CV_LINE3_ASPECTRATIO_4_3_GPIO_SHIFT 0x4 +- +-#define ATOM_CV_LINE3_ASPECTRATIO_MASK 0x3F /* bit [5:0] */ +- +-#define ATOM_CV_LINE3_ASPECTRATIO_EXIST 0x80 /* bit 7 */ +- +-/* GPIO bit index in gpio setting per mode value, also represend the block no. in gpio blocks. */ +-#define ATOM_GPIO_INDEX_LINE3_ASPECRATIO_GPIO_A 3 /* bit 3 in uc480i/uc480p/uc720p/uc1080i, which represend the default gpio bit setting for the mode. */ +-#define ATOM_GPIO_INDEX_LINE3_ASPECRATIO_GPIO_B 4 /* bit 4 in uc480i/uc480p/uc720p/uc1080i, which represend the default gpio bit setting for the mode. */ +- +-typedef struct _ATOM_COMPONENT_VIDEO_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usMask_PinRegisterIndex; +- USHORT usEN_PinRegisterIndex; +- USHORT usY_PinRegisterIndex; +- USHORT usA_PinRegisterIndex; +- UCHAR ucBitShift; +- UCHAR ucPinActiveState; /* ucPinActiveState: Bit0=1 active high, =0 active low */ +- ATOM_DTD_FORMAT sReserved; /* must be zeroed out */ +- UCHAR ucMiscInfo; +- UCHAR uc480i; +- UCHAR uc480p; +- UCHAR uc720p; +- UCHAR uc1080i; +- UCHAR ucLetterBoxMode; +- UCHAR ucReserved[3]; +- UCHAR ucNumOfWbGpioBlocks; /* For Component video D-Connector support. If zere, NTSC type connector */ +- ATOM_GPIO_INFO aWbGpioStateBlock[MAX_SUPPORTED_CV_STANDARDS]; +- ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_CV_STANDARDS]; +-} ATOM_COMPONENT_VIDEO_INFO; +- +-/* ucTableFormatRevision=2 */ +-/* ucTableContentRevision=1 */ +-typedef struct _ATOM_COMPONENT_VIDEO_INFO_V21 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucMiscInfo; +- UCHAR uc480i; +- UCHAR uc480p; +- UCHAR uc720p; +- UCHAR uc1080i; +- UCHAR ucReserved; +- UCHAR ucLetterBoxMode; +- UCHAR ucNumOfWbGpioBlocks; /* For Component video D-Connector support. If zere, NTSC type connector */ +- ATOM_GPIO_INFO aWbGpioStateBlock[MAX_SUPPORTED_CV_STANDARDS]; +- ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_CV_STANDARDS]; +-} ATOM_COMPONENT_VIDEO_INFO_V21; ++// definitions for ATOM_COMPONENT_VIDEO_INFO.uc480i/uc480p/uc720p/uc1080i ++#define ATOM_GPIO_DEFAULT_MODE_EN 0x80 //[7]; ++#define ATOM_GPIO_SETTING_PERMODE_MASK 0x7F //[6:0] ++ ++// definitions for ATOM_COMPONENT_VIDEO_INFO.ucLetterBoxMode ++//Line 3 out put 5V. ++#define ATOM_CV_LINE3_ASPECTRATIO_16_9_GPIO_A 0x01 //represent gpio 3 state for 16:9 ++#define ATOM_CV_LINE3_ASPECTRATIO_16_9_GPIO_B 0x02 //represent gpio 4 state for 16:9 ++#define ATOM_CV_LINE3_ASPECTRATIO_16_9_GPIO_SHIFT 0x0 ++ ++//Line 3 out put 2.2V ++#define ATOM_CV_LINE3_ASPECTRATIO_4_3_LETBOX_GPIO_A 0x04 //represent gpio 3 state for 4:3 Letter box ++#define ATOM_CV_LINE3_ASPECTRATIO_4_3_LETBOX_GPIO_B 0x08 //represent gpio 4 state for 4:3 Letter box ++#define ATOM_CV_LINE3_ASPECTRATIO_4_3_LETBOX_GPIO_SHIFT 0x2 ++ ++//Line 3 out put 0V ++#define ATOM_CV_LINE3_ASPECTRATIO_4_3_GPIO_A 0x10 //represent gpio 3 state for 4:3 ++#define ATOM_CV_LINE3_ASPECTRATIO_4_3_GPIO_B 0x20 //represent gpio 4 state for 4:3 ++#define ATOM_CV_LINE3_ASPECTRATIO_4_3_GPIO_SHIFT 0x4 ++ ++#define ATOM_CV_LINE3_ASPECTRATIO_MASK 0x3F // bit [5:0] ++ ++#define ATOM_CV_LINE3_ASPECTRATIO_EXIST 0x80 //bit 7 ++ ++//GPIO bit index in gpio setting per mode value, also represend the block no. in gpio blocks. ++#define ATOM_GPIO_INDEX_LINE3_ASPECRATIO_GPIO_A 3 //bit 3 in uc480i/uc480p/uc720p/uc1080i, which represend the default gpio bit setting for the mode. ++#define ATOM_GPIO_INDEX_LINE3_ASPECRATIO_GPIO_B 4 //bit 4 in uc480i/uc480p/uc720p/uc1080i, which represend the default gpio bit setting for the mode. ++ ++ ++typedef struct _ATOM_COMPONENT_VIDEO_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usMask_PinRegisterIndex; ++ USHORT usEN_PinRegisterIndex; ++ USHORT usY_PinRegisterIndex; ++ USHORT usA_PinRegisterIndex; ++ UCHAR ucBitShift; ++ UCHAR ucPinActiveState; //ucPinActiveState: Bit0=1 active high, =0 active low ++ ATOM_DTD_FORMAT sReserved; // must be zeroed out ++ UCHAR ucMiscInfo; ++ UCHAR uc480i; ++ UCHAR uc480p; ++ UCHAR uc720p; ++ UCHAR uc1080i; ++ UCHAR ucLetterBoxMode; ++ UCHAR ucReserved[3]; ++ UCHAR ucNumOfWbGpioBlocks; //For Component video D-Connector support. If zere, NTSC type connector ++ ATOM_GPIO_INFO aWbGpioStateBlock[MAX_SUPPORTED_CV_STANDARDS]; ++ ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_CV_STANDARDS]; ++}ATOM_COMPONENT_VIDEO_INFO; ++ ++//ucTableFormatRevision=2 ++//ucTableContentRevision=1 ++typedef struct _ATOM_COMPONENT_VIDEO_INFO_V21 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucMiscInfo; ++ UCHAR uc480i; ++ UCHAR uc480p; ++ UCHAR uc720p; ++ UCHAR uc1080i; ++ UCHAR ucReserved; ++ UCHAR ucLetterBoxMode; ++ UCHAR ucNumOfWbGpioBlocks; //For Component video D-Connector support. If zere, NTSC type connector ++ ATOM_GPIO_INFO aWbGpioStateBlock[MAX_SUPPORTED_CV_STANDARDS]; ++ ATOM_DTD_FORMAT aModeTimings[MAX_SUPPORTED_CV_STANDARDS]; ++}ATOM_COMPONENT_VIDEO_INFO_V21; + + #define ATOM_COMPONENT_VIDEO_INFO_LAST ATOM_COMPONENT_VIDEO_INFO_V21 + +-/****************************************************************************/ +-/* Structure used in object_InfoTable */ +-/****************************************************************************/ +-typedef struct _ATOM_OBJECT_HEADER { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usDeviceSupport; +- USHORT usConnectorObjectTableOffset; +- USHORT usRouterObjectTableOffset; +- USHORT usEncoderObjectTableOffset; +- USHORT usProtectionObjectTableOffset; /* only available when Protection block is independent. */ +- USHORT usDisplayPathTableOffset; +-} ATOM_OBJECT_HEADER; +- +-typedef struct _ATOM_DISPLAY_OBJECT_PATH { +- USHORT usDeviceTag; /* supported device */ +- USHORT usSize; /* the size of ATOM_DISPLAY_OBJECT_PATH */ +- USHORT usConnObjectId; /* Connector Object ID */ +- USHORT usGPUObjectId; /* GPU ID */ +- USHORT usGraphicObjIds[1]; /* 1st Encoder Obj source from GPU to last Graphic Obj destinate to connector. */ +-} ATOM_DISPLAY_OBJECT_PATH; +- +-typedef struct _ATOM_DISPLAY_OBJECT_PATH_TABLE { +- UCHAR ucNumOfDispPath; +- UCHAR ucVersion; +- UCHAR ucPadding[2]; +- ATOM_DISPLAY_OBJECT_PATH asDispPath[1]; +-} ATOM_DISPLAY_OBJECT_PATH_TABLE; +- +-typedef struct _ATOM_OBJECT /* each object has this structure */ +-{ +- USHORT usObjectID; +- USHORT usSrcDstTableOffset; +- USHORT usRecordOffset; /* this pointing to a bunch of records defined below */ +- USHORT usReserved; +-} ATOM_OBJECT; +- +-typedef struct _ATOM_OBJECT_TABLE /* Above 4 object table offset pointing to a bunch of objects all have this structure */ +-{ +- UCHAR ucNumberOfObjects; +- UCHAR ucPadding[3]; +- ATOM_OBJECT asObjects[1]; +-} ATOM_OBJECT_TABLE; +- +-typedef struct _ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT /* usSrcDstTableOffset pointing to this structure */ +-{ +- UCHAR ucNumberOfSrc; +- USHORT usSrcObjectID[1]; +- UCHAR ucNumberOfDst; +- USHORT usDstObjectID[1]; +-} ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT; +- +-/* Related definitions, all records are differnt but they have a commond header */ +-typedef struct _ATOM_COMMON_RECORD_HEADER { +- UCHAR ucRecordType; /* An emun to indicate the record type */ +- UCHAR ucRecordSize; /* The size of the whole record in byte */ +-} ATOM_COMMON_RECORD_HEADER; +- +-#define ATOM_I2C_RECORD_TYPE 1 ++/****************************************************************************/ ++// Structure used in object_InfoTable ++/****************************************************************************/ ++typedef struct _ATOM_OBJECT_HEADER ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usDeviceSupport; ++ USHORT usConnectorObjectTableOffset; ++ USHORT usRouterObjectTableOffset; ++ USHORT usEncoderObjectTableOffset; ++ USHORT usProtectionObjectTableOffset; //only available when Protection block is independent. ++ USHORT usDisplayPathTableOffset; ++}ATOM_OBJECT_HEADER; ++ ++typedef struct _ATOM_OBJECT_HEADER_V3 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usDeviceSupport; ++ USHORT usConnectorObjectTableOffset; ++ USHORT usRouterObjectTableOffset; ++ USHORT usEncoderObjectTableOffset; ++ USHORT usProtectionObjectTableOffset; //only available when Protection block is independent. ++ USHORT usDisplayPathTableOffset; ++ USHORT usMiscObjectTableOffset; ++}ATOM_OBJECT_HEADER_V3; ++ ++typedef struct _ATOM_DISPLAY_OBJECT_PATH ++{ ++ USHORT usDeviceTag; //supported device ++ USHORT usSize; //the size of ATOM_DISPLAY_OBJECT_PATH ++ USHORT usConnObjectId; //Connector Object ID ++ USHORT usGPUObjectId; //GPU ID ++ USHORT usGraphicObjIds[1]; //1st Encoder Obj source from GPU to last Graphic Obj destinate to connector. ++}ATOM_DISPLAY_OBJECT_PATH; ++ ++typedef struct _ATOM_DISPLAY_OBJECT_PATH_TABLE ++{ ++ UCHAR ucNumOfDispPath; ++ UCHAR ucVersion; ++ UCHAR ucPadding[2]; ++ ATOM_DISPLAY_OBJECT_PATH asDispPath[1]; ++}ATOM_DISPLAY_OBJECT_PATH_TABLE; ++ ++ ++typedef struct _ATOM_OBJECT //each object has this structure ++{ ++ USHORT usObjectID; ++ USHORT usSrcDstTableOffset; ++ USHORT usRecordOffset; //this pointing to a bunch of records defined below ++ USHORT usReserved; ++}ATOM_OBJECT; ++ ++typedef struct _ATOM_OBJECT_TABLE //Above 4 object table offset pointing to a bunch of objects all have this structure ++{ ++ UCHAR ucNumberOfObjects; ++ UCHAR ucPadding[3]; ++ ATOM_OBJECT asObjects[1]; ++}ATOM_OBJECT_TABLE; ++ ++typedef struct _ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT //usSrcDstTableOffset pointing to this structure ++{ ++ UCHAR ucNumberOfSrc; ++ USHORT usSrcObjectID[1]; ++ UCHAR ucNumberOfDst; ++ USHORT usDstObjectID[1]; ++}ATOM_SRC_DST_TABLE_FOR_ONE_OBJECT; ++ ++ ++//Two definitions below are for OPM on MXM module designs ++ ++#define EXT_HPDPIN_LUTINDEX_0 0 ++#define EXT_HPDPIN_LUTINDEX_1 1 ++#define EXT_HPDPIN_LUTINDEX_2 2 ++#define EXT_HPDPIN_LUTINDEX_3 3 ++#define EXT_HPDPIN_LUTINDEX_4 4 ++#define EXT_HPDPIN_LUTINDEX_5 5 ++#define EXT_HPDPIN_LUTINDEX_6 6 ++#define EXT_HPDPIN_LUTINDEX_7 7 ++#define MAX_NUMBER_OF_EXT_HPDPIN_LUT_ENTRIES (EXT_HPDPIN_LUTINDEX_7+1) ++ ++#define EXT_AUXDDC_LUTINDEX_0 0 ++#define EXT_AUXDDC_LUTINDEX_1 1 ++#define EXT_AUXDDC_LUTINDEX_2 2 ++#define EXT_AUXDDC_LUTINDEX_3 3 ++#define EXT_AUXDDC_LUTINDEX_4 4 ++#define EXT_AUXDDC_LUTINDEX_5 5 ++#define EXT_AUXDDC_LUTINDEX_6 6 ++#define EXT_AUXDDC_LUTINDEX_7 7 ++#define MAX_NUMBER_OF_EXT_AUXDDC_LUT_ENTRIES (EXT_AUXDDC_LUTINDEX_7+1) ++ ++typedef struct _EXT_DISPLAY_PATH ++{ ++ USHORT usDeviceTag; //A bit vector to show what devices are supported ++ USHORT usDeviceACPIEnum; //16bit device ACPI id. ++ USHORT usDeviceConnector; //A physical connector for displays to plug in, using object connector definitions ++ UCHAR ucExtAUXDDCLutIndex; //An index into external AUX/DDC channel LUT ++ UCHAR ucExtHPDPINLutIndex; //An index into external HPD pin LUT ++ USHORT usExtEncoderObjId; //external encoder object id ++ USHORT usReserved[3]; ++}EXT_DISPLAY_PATH; ++ ++#define NUMBER_OF_UCHAR_FOR_GUID 16 ++#define MAX_NUMBER_OF_EXT_DISPLAY_PATH 7 ++ ++typedef struct _ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucGuid [NUMBER_OF_UCHAR_FOR_GUID]; // a GUID is a 16 byte long string ++ EXT_DISPLAY_PATH sPath[MAX_NUMBER_OF_EXT_DISPLAY_PATH]; // total of fixed 7 entries. ++ UCHAR ucChecksum; // a simple Checksum of the sum of whole structure equal to 0x0. ++ UCHAR Reserved [7]; // for potential expansion ++}ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO; ++ ++//Related definitions, all records are differnt but they have a commond header ++typedef struct _ATOM_COMMON_RECORD_HEADER ++{ ++ UCHAR ucRecordType; //An emun to indicate the record type ++ UCHAR ucRecordSize; //The size of the whole record in byte ++}ATOM_COMMON_RECORD_HEADER; ++ ++ ++#define ATOM_I2C_RECORD_TYPE 1 + #define ATOM_HPD_INT_RECORD_TYPE 2 + #define ATOM_OUTPUT_PROTECTION_RECORD_TYPE 3 + #define ATOM_CONNECTOR_DEVICE_TAG_RECORD_TYPE 4 +-#define ATOM_CONNECTOR_DVI_EXT_INPUT_RECORD_TYPE 5 /* Obsolete, switch to use GPIO_CNTL_RECORD_TYPE */ +-#define ATOM_ENCODER_FPGA_CONTROL_RECORD_TYPE 6 /* Obsolete, switch to use GPIO_CNTL_RECORD_TYPE */ ++#define ATOM_CONNECTOR_DVI_EXT_INPUT_RECORD_TYPE 5 //Obsolete, switch to use GPIO_CNTL_RECORD_TYPE ++#define ATOM_ENCODER_FPGA_CONTROL_RECORD_TYPE 6 //Obsolete, switch to use GPIO_CNTL_RECORD_TYPE + #define ATOM_CONNECTOR_CVTV_SHARE_DIN_RECORD_TYPE 7 +-#define ATOM_JTAG_RECORD_TYPE 8 /* Obsolete, switch to use GPIO_CNTL_RECORD_TYPE */ ++#define ATOM_JTAG_RECORD_TYPE 8 //Obsolete, switch to use GPIO_CNTL_RECORD_TYPE + #define ATOM_OBJECT_GPIO_CNTL_RECORD_TYPE 9 + #define ATOM_ENCODER_DVO_CF_RECORD_TYPE 10 + #define ATOM_CONNECTOR_CF_RECORD_TYPE 11 + #define ATOM_CONNECTOR_HARDCODE_DTD_RECORD_TYPE 12 + #define ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD_TYPE 13 +-#define ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE 14 +-#define ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE 15 +- +-/* Must be updated when new record type is added,equal to that record definition! */ +-#define ATOM_MAX_OBJECT_RECORD_NUMBER ATOM_CONNECTOR_CF_RECORD_TYPE +- +-typedef struct _ATOM_I2C_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- ATOM_I2C_ID_CONFIG sucI2cId; +- UCHAR ucI2CAddr; /* The slave address, it's 0 when the record is attached to connector for DDC */ +-} ATOM_I2C_RECORD; +- +-typedef struct _ATOM_HPD_INT_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucHPDIntGPIOID; /* Corresponding block in GPIO_PIN_INFO table gives the pin info */ +- UCHAR ucPlugged_PinState; +-} ATOM_HPD_INT_RECORD; +- +-typedef struct _ATOM_OUTPUT_PROTECTION_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucProtectionFlag; +- UCHAR ucReserved; +-} ATOM_OUTPUT_PROTECTION_RECORD; +- +-typedef struct _ATOM_CONNECTOR_DEVICE_TAG { +- ULONG ulACPIDeviceEnum; /* Reserved for now */ +- USHORT usDeviceID; /* This Id is same as "ATOM_DEVICE_XXX_SUPPORT" */ +- USHORT usPadding; +-} ATOM_CONNECTOR_DEVICE_TAG; +- +-typedef struct _ATOM_CONNECTOR_DEVICE_TAG_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucNumberOfDevice; +- UCHAR ucReserved; +- ATOM_CONNECTOR_DEVICE_TAG asDeviceTag[1]; /* This Id is same as "ATOM_DEVICE_XXX_SUPPORT", 1 is only for allocation */ +-} ATOM_CONNECTOR_DEVICE_TAG_RECORD; +- +-typedef struct _ATOM_CONNECTOR_DVI_EXT_INPUT_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucConfigGPIOID; +- UCHAR ucConfigGPIOState; /* Set to 1 when it's active high to enable external flow in */ +- UCHAR ucFlowinGPIPID; +- UCHAR ucExtInGPIPID; +-} ATOM_CONNECTOR_DVI_EXT_INPUT_RECORD; +- +-typedef struct _ATOM_ENCODER_FPGA_CONTROL_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucCTL1GPIO_ID; +- UCHAR ucCTL1GPIOState; /* Set to 1 when it's active high */ +- UCHAR ucCTL2GPIO_ID; +- UCHAR ucCTL2GPIOState; /* Set to 1 when it's active high */ +- UCHAR ucCTL3GPIO_ID; +- UCHAR ucCTL3GPIOState; /* Set to 1 when it's active high */ +- UCHAR ucCTLFPGA_IN_ID; +- UCHAR ucPadding[3]; +-} ATOM_ENCODER_FPGA_CONTROL_RECORD; +- +-typedef struct _ATOM_CONNECTOR_CVTV_SHARE_DIN_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucGPIOID; /* Corresponding block in GPIO_PIN_INFO table gives the pin info */ +- UCHAR ucTVActiveState; /* Indicating when the pin==0 or 1 when TV is connected */ +-} ATOM_CONNECTOR_CVTV_SHARE_DIN_RECORD; +- +-typedef struct _ATOM_JTAG_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucTMSGPIO_ID; +- UCHAR ucTMSGPIOState; /* Set to 1 when it's active high */ +- UCHAR ucTCKGPIO_ID; +- UCHAR ucTCKGPIOState; /* Set to 1 when it's active high */ +- UCHAR ucTDOGPIO_ID; +- UCHAR ucTDOGPIOState; /* Set to 1 when it's active high */ +- UCHAR ucTDIGPIO_ID; +- UCHAR ucTDIGPIOState; /* Set to 1 when it's active high */ +- UCHAR ucPadding[2]; +-} ATOM_JTAG_RECORD; +- +-/* The following generic object gpio pin control record type will replace JTAG_RECORD/FPGA_CONTROL_RECORD/DVI_EXT_INPUT_RECORD above gradually */ +-typedef struct _ATOM_GPIO_PIN_CONTROL_PAIR { +- UCHAR ucGPIOID; /* GPIO_ID, find the corresponding ID in GPIO_LUT table */ +- UCHAR ucGPIO_PinState; /* Pin state showing how to set-up the pin */ +-} ATOM_GPIO_PIN_CONTROL_PAIR; +- +-typedef struct _ATOM_OBJECT_GPIO_CNTL_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucFlags; /* Future expnadibility */ +- UCHAR ucNumberOfPins; /* Number of GPIO pins used to control the object */ +- ATOM_GPIO_PIN_CONTROL_PAIR asGpio[1]; /* the real gpio pin pair determined by number of pins ucNumberOfPins */ +-} ATOM_OBJECT_GPIO_CNTL_RECORD; +- +-/* Definitions for GPIO pin state */ ++#define ATOM_ROUTER_DDC_PATH_SELECT_RECORD_TYPE 14 ++#define ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD_TYPE 15 ++#define ATOM_CONNECTOR_HPDPIN_LUT_RECORD_TYPE 16 //This is for the case when connectors are not known to object table ++#define ATOM_CONNECTOR_AUXDDC_LUT_RECORD_TYPE 17 //This is for the case when connectors are not known to object table ++#define ATOM_OBJECT_LINK_RECORD_TYPE 18 //Once this record is present under one object, it indicats the oobject is linked to another obj described by the record ++#define ATOM_CONNECTOR_REMOTE_CAP_RECORD_TYPE 19 ++ ++ ++//Must be updated when new record type is added,equal to that record definition! ++#define ATOM_MAX_OBJECT_RECORD_NUMBER ATOM_CONNECTOR_REMOTE_CAP_RECORD_TYPE ++ ++typedef struct _ATOM_I2C_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ ATOM_I2C_ID_CONFIG sucI2cId; ++ UCHAR ucI2CAddr; //The slave address, it's 0 when the record is attached to connector for DDC ++}ATOM_I2C_RECORD; ++ ++typedef struct _ATOM_HPD_INT_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucHPDIntGPIOID; //Corresponding block in GPIO_PIN_INFO table gives the pin info ++ UCHAR ucPlugged_PinState; ++}ATOM_HPD_INT_RECORD; ++ ++ ++typedef struct _ATOM_OUTPUT_PROTECTION_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucProtectionFlag; ++ UCHAR ucReserved; ++}ATOM_OUTPUT_PROTECTION_RECORD; ++ ++typedef struct _ATOM_CONNECTOR_DEVICE_TAG ++{ ++ ULONG ulACPIDeviceEnum; //Reserved for now ++ USHORT usDeviceID; //This Id is same as "ATOM_DEVICE_XXX_SUPPORT" ++ USHORT usPadding; ++}ATOM_CONNECTOR_DEVICE_TAG; ++ ++typedef struct _ATOM_CONNECTOR_DEVICE_TAG_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucNumberOfDevice; ++ UCHAR ucReserved; ++ ATOM_CONNECTOR_DEVICE_TAG asDeviceTag[1]; //This Id is same as "ATOM_DEVICE_XXX_SUPPORT", 1 is only for allocation ++}ATOM_CONNECTOR_DEVICE_TAG_RECORD; ++ ++ ++typedef struct _ATOM_CONNECTOR_DVI_EXT_INPUT_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucConfigGPIOID; ++ UCHAR ucConfigGPIOState; //Set to 1 when it's active high to enable external flow in ++ UCHAR ucFlowinGPIPID; ++ UCHAR ucExtInGPIPID; ++}ATOM_CONNECTOR_DVI_EXT_INPUT_RECORD; ++ ++typedef struct _ATOM_ENCODER_FPGA_CONTROL_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucCTL1GPIO_ID; ++ UCHAR ucCTL1GPIOState; //Set to 1 when it's active high ++ UCHAR ucCTL2GPIO_ID; ++ UCHAR ucCTL2GPIOState; //Set to 1 when it's active high ++ UCHAR ucCTL3GPIO_ID; ++ UCHAR ucCTL3GPIOState; //Set to 1 when it's active high ++ UCHAR ucCTLFPGA_IN_ID; ++ UCHAR ucPadding[3]; ++}ATOM_ENCODER_FPGA_CONTROL_RECORD; ++ ++typedef struct _ATOM_CONNECTOR_CVTV_SHARE_DIN_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucGPIOID; //Corresponding block in GPIO_PIN_INFO table gives the pin info ++ UCHAR ucTVActiveState; //Indicating when the pin==0 or 1 when TV is connected ++}ATOM_CONNECTOR_CVTV_SHARE_DIN_RECORD; ++ ++typedef struct _ATOM_JTAG_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucTMSGPIO_ID; ++ UCHAR ucTMSGPIOState; //Set to 1 when it's active high ++ UCHAR ucTCKGPIO_ID; ++ UCHAR ucTCKGPIOState; //Set to 1 when it's active high ++ UCHAR ucTDOGPIO_ID; ++ UCHAR ucTDOGPIOState; //Set to 1 when it's active high ++ UCHAR ucTDIGPIO_ID; ++ UCHAR ucTDIGPIOState; //Set to 1 when it's active high ++ UCHAR ucPadding[2]; ++}ATOM_JTAG_RECORD; ++ ++ ++//The following generic object gpio pin control record type will replace JTAG_RECORD/FPGA_CONTROL_RECORD/DVI_EXT_INPUT_RECORD above gradually ++typedef struct _ATOM_GPIO_PIN_CONTROL_PAIR ++{ ++ UCHAR ucGPIOID; // GPIO_ID, find the corresponding ID in GPIO_LUT table ++ UCHAR ucGPIO_PinState; // Pin state showing how to set-up the pin ++}ATOM_GPIO_PIN_CONTROL_PAIR; ++ ++typedef struct _ATOM_OBJECT_GPIO_CNTL_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucFlags; // Future expnadibility ++ UCHAR ucNumberOfPins; // Number of GPIO pins used to control the object ++ ATOM_GPIO_PIN_CONTROL_PAIR asGpio[1]; // the real gpio pin pair determined by number of pins ucNumberOfPins ++}ATOM_OBJECT_GPIO_CNTL_RECORD; ++ ++//Definitions for GPIO pin state + #define GPIO_PIN_TYPE_INPUT 0x00 + #define GPIO_PIN_TYPE_OUTPUT 0x10 + #define GPIO_PIN_TYPE_HW_CONTROL 0x20 + +-/* For GPIO_PIN_TYPE_OUTPUT the following is defined */ ++//For GPIO_PIN_TYPE_OUTPUT the following is defined + #define GPIO_PIN_OUTPUT_STATE_MASK 0x01 + #define GPIO_PIN_OUTPUT_STATE_SHIFT 0 + #define GPIO_PIN_STATE_ACTIVE_LOW 0x0 + #define GPIO_PIN_STATE_ACTIVE_HIGH 0x1 + +-typedef struct _ATOM_ENCODER_DVO_CF_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- ULONG ulStrengthControl; /* DVOA strength control for CF */ +- UCHAR ucPadding[2]; +-} ATOM_ENCODER_DVO_CF_RECORD; ++// Indexes to GPIO array in GLSync record ++#define ATOM_GPIO_INDEX_GLSYNC_REFCLK 0 ++#define ATOM_GPIO_INDEX_GLSYNC_HSYNC 1 ++#define ATOM_GPIO_INDEX_GLSYNC_VSYNC 2 ++#define ATOM_GPIO_INDEX_GLSYNC_SWAP_REQ 3 ++#define ATOM_GPIO_INDEX_GLSYNC_SWAP_GNT 4 ++#define ATOM_GPIO_INDEX_GLSYNC_INTERRUPT 5 ++#define ATOM_GPIO_INDEX_GLSYNC_V_RESET 6 ++#define ATOM_GPIO_INDEX_GLSYNC_MAX 7 ++ ++typedef struct _ATOM_ENCODER_DVO_CF_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ ULONG ulStrengthControl; // DVOA strength control for CF ++ UCHAR ucPadding[2]; ++}ATOM_ENCODER_DVO_CF_RECORD; + +-/* value for ATOM_CONNECTOR_CF_RECORD.ucConnectedDvoBundle */ ++// value for ATOM_CONNECTOR_CF_RECORD.ucConnectedDvoBundle + #define ATOM_CONNECTOR_CF_RECORD_CONNECTED_UPPER12BITBUNDLEA 1 + #define ATOM_CONNECTOR_CF_RECORD_CONNECTED_LOWER12BITBUNDLEB 2 + +-typedef struct _ATOM_CONNECTOR_CF_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- USHORT usMaxPixClk; +- UCHAR ucFlowCntlGpioId; +- UCHAR ucSwapCntlGpioId; +- UCHAR ucConnectedDvoBundle; +- UCHAR ucPadding; +-} ATOM_CONNECTOR_CF_RECORD; +- +-typedef struct _ATOM_CONNECTOR_HARDCODE_DTD_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- ATOM_DTD_FORMAT asTiming; +-} ATOM_CONNECTOR_HARDCODE_DTD_RECORD; +- +-typedef struct _ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; /* ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD_TYPE */ +- UCHAR ucSubConnectorType; /* CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D|X_ID_DUAL_LINK_DVI_D|HDMI_TYPE_A */ +- UCHAR ucReserved; +-} ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD; +- +-typedef struct _ATOM_ROUTER_DDC_PATH_SELECT_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucMuxType; /* decide the number of ucMuxState, =0, no pin state, =1: single state with complement, >1: multiple state */ +- UCHAR ucMuxControlPin; +- UCHAR ucMuxState[2]; /* for alligment purpose */ +-} ATOM_ROUTER_DDC_PATH_SELECT_RECORD; +- +-typedef struct _ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD { +- ATOM_COMMON_RECORD_HEADER sheader; +- UCHAR ucMuxType; +- UCHAR ucMuxControlPin; +- UCHAR ucMuxState[2]; /* for alligment purpose */ +-} ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD; +- +-/* define ucMuxType */ ++typedef struct _ATOM_CONNECTOR_CF_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ USHORT usMaxPixClk; ++ UCHAR ucFlowCntlGpioId; ++ UCHAR ucSwapCntlGpioId; ++ UCHAR ucConnectedDvoBundle; ++ UCHAR ucPadding; ++}ATOM_CONNECTOR_CF_RECORD; ++ ++typedef struct _ATOM_CONNECTOR_HARDCODE_DTD_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ ATOM_DTD_FORMAT asTiming; ++}ATOM_CONNECTOR_HARDCODE_DTD_RECORD; ++ ++typedef struct _ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; //ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD_TYPE ++ UCHAR ucSubConnectorType; //CONNECTOR_OBJECT_ID_SINGLE_LINK_DVI_D|X_ID_DUAL_LINK_DVI_D|HDMI_TYPE_A ++ UCHAR ucReserved; ++}ATOM_CONNECTOR_PCIE_SUBCONNECTOR_RECORD; ++ ++ ++typedef struct _ATOM_ROUTER_DDC_PATH_SELECT_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucMuxType; //decide the number of ucMuxState, =0, no pin state, =1: single state with complement, >1: multiple state ++ UCHAR ucMuxControlPin; ++ UCHAR ucMuxState[2]; //for alligment purpose ++}ATOM_ROUTER_DDC_PATH_SELECT_RECORD; ++ ++typedef struct _ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucMuxType; ++ UCHAR ucMuxControlPin; ++ UCHAR ucMuxState[2]; //for alligment purpose ++}ATOM_ROUTER_DATA_CLOCK_PATH_SELECT_RECORD; ++ ++// define ucMuxType + #define ATOM_ROUTER_MUX_PIN_STATE_MASK 0x0f + #define ATOM_ROUTER_MUX_PIN_SINGLE_STATE_COMPLEMENT 0x01 + +-/****************************************************************************/ +-/* ASIC voltage data table */ +-/****************************************************************************/ +-typedef struct _ATOM_VOLTAGE_INFO_HEADER { +- USHORT usVDDCBaseLevel; /* In number of 50mv unit */ +- USHORT usReserved; /* For possible extension table offset */ +- UCHAR ucNumOfVoltageEntries; +- UCHAR ucBytesPerVoltageEntry; +- UCHAR ucVoltageStep; /* Indicating in how many mv increament is one step, 0.5mv unit */ +- UCHAR ucDefaultVoltageEntry; +- UCHAR ucVoltageControlI2cLine; +- UCHAR ucVoltageControlAddress; +- UCHAR ucVoltageControlOffset; +-} ATOM_VOLTAGE_INFO_HEADER; +- +-typedef struct _ATOM_VOLTAGE_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_VOLTAGE_INFO_HEADER viHeader; +- UCHAR ucVoltageEntries[64]; /* 64 is for allocation, the actual number of entry is present at ucNumOfVoltageEntries*ucBytesPerVoltageEntry */ +-} ATOM_VOLTAGE_INFO; +- +-typedef struct _ATOM_VOLTAGE_FORMULA { +- USHORT usVoltageBaseLevel; /* In number of 1mv unit */ +- USHORT usVoltageStep; /* Indicating in how many mv increament is one step, 1mv unit */ +- UCHAR ucNumOfVoltageEntries; /* Number of Voltage Entry, which indicate max Voltage */ +- UCHAR ucFlag; /* bit0=0 :step is 1mv =1 0.5mv */ +- UCHAR ucBaseVID; /* if there is no lookup table, VID= BaseVID + ( Vol - BaseLevle ) /VoltageStep */ +- UCHAR ucReserved; +- UCHAR ucVIDAdjustEntries[32]; /* 32 is for allocation, the actual number of entry is present at ucNumOfVoltageEntries */ +-} ATOM_VOLTAGE_FORMULA; +- +-typedef struct _ATOM_VOLTAGE_CONTROL { +- UCHAR ucVoltageControlId; /* Indicate it is controlled by I2C or GPIO or HW state machine */ +- UCHAR ucVoltageControlI2cLine; +- UCHAR ucVoltageControlAddress; +- UCHAR ucVoltageControlOffset; +- USHORT usGpioPin_AIndex; /* GPIO_PAD register index */ +- UCHAR ucGpioPinBitShift[9]; /* at most 8 pin support 255 VIDs, termintate with 0xff */ +- UCHAR ucReserved; +-} ATOM_VOLTAGE_CONTROL; +- +-/* Define ucVoltageControlId */ ++typedef struct _ATOM_CONNECTOR_HPDPIN_LUT_RECORD //record for ATOM_CONNECTOR_HPDPIN_LUT_RECORD_TYPE ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ UCHAR ucHPDPINMap[MAX_NUMBER_OF_EXT_HPDPIN_LUT_ENTRIES]; //An fixed size array which maps external pins to internal GPIO_PIN_INFO table ++}ATOM_CONNECTOR_HPDPIN_LUT_RECORD; ++ ++typedef struct _ATOM_CONNECTOR_AUXDDC_LUT_RECORD //record for ATOM_CONNECTOR_AUXDDC_LUT_RECORD_TYPE ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ ATOM_I2C_ID_CONFIG ucAUXDDCMap[MAX_NUMBER_OF_EXT_AUXDDC_LUT_ENTRIES]; //An fixed size array which maps external pins to internal DDC ID ++}ATOM_CONNECTOR_AUXDDC_LUT_RECORD; ++ ++typedef struct _ATOM_OBJECT_LINK_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ USHORT usObjectID; //could be connector, encorder or other object in object.h ++}ATOM_OBJECT_LINK_RECORD; ++ ++typedef struct _ATOM_CONNECTOR_REMOTE_CAP_RECORD ++{ ++ ATOM_COMMON_RECORD_HEADER sheader; ++ USHORT usReserved; ++}ATOM_CONNECTOR_REMOTE_CAP_RECORD; ++ ++/****************************************************************************/ ++// ASIC voltage data table ++/****************************************************************************/ ++typedef struct _ATOM_VOLTAGE_INFO_HEADER ++{ ++ USHORT usVDDCBaseLevel; //In number of 50mv unit ++ USHORT usReserved; //For possible extension table offset ++ UCHAR ucNumOfVoltageEntries; ++ UCHAR ucBytesPerVoltageEntry; ++ UCHAR ucVoltageStep; //Indicating in how many mv increament is one step, 0.5mv unit ++ UCHAR ucDefaultVoltageEntry; ++ UCHAR ucVoltageControlI2cLine; ++ UCHAR ucVoltageControlAddress; ++ UCHAR ucVoltageControlOffset; ++}ATOM_VOLTAGE_INFO_HEADER; ++ ++typedef struct _ATOM_VOLTAGE_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_VOLTAGE_INFO_HEADER viHeader; ++ UCHAR ucVoltageEntries[64]; //64 is for allocation, the actual number of entry is present at ucNumOfVoltageEntries*ucBytesPerVoltageEntry ++}ATOM_VOLTAGE_INFO; ++ ++ ++typedef struct _ATOM_VOLTAGE_FORMULA ++{ ++ USHORT usVoltageBaseLevel; // In number of 1mv unit ++ USHORT usVoltageStep; // Indicating in how many mv increament is one step, 1mv unit ++ UCHAR ucNumOfVoltageEntries; // Number of Voltage Entry, which indicate max Voltage ++ UCHAR ucFlag; // bit0=0 :step is 1mv =1 0.5mv ++ UCHAR ucBaseVID; // if there is no lookup table, VID= BaseVID + ( Vol - BaseLevle ) /VoltageStep ++ UCHAR ucReserved; ++ UCHAR ucVIDAdjustEntries[32]; // 32 is for allocation, the actual number of entry is present at ucNumOfVoltageEntries ++}ATOM_VOLTAGE_FORMULA; ++ ++typedef struct _VOLTAGE_LUT_ENTRY ++{ ++ USHORT usVoltageCode; // The Voltage ID, either GPIO or I2C code ++ USHORT usVoltageValue; // The corresponding Voltage Value, in mV ++}VOLTAGE_LUT_ENTRY; ++ ++typedef struct _ATOM_VOLTAGE_FORMULA_V2 ++{ ++ UCHAR ucNumOfVoltageEntries; // Number of Voltage Entry, which indicate max Voltage ++ UCHAR ucReserved[3]; ++ VOLTAGE_LUT_ENTRY asVIDAdjustEntries[32];// 32 is for allocation, the actual number of entries is in ucNumOfVoltageEntries ++}ATOM_VOLTAGE_FORMULA_V2; ++ ++typedef struct _ATOM_VOLTAGE_CONTROL ++{ ++ UCHAR ucVoltageControlId; //Indicate it is controlled by I2C or GPIO or HW state machine ++ UCHAR ucVoltageControlI2cLine; ++ UCHAR ucVoltageControlAddress; ++ UCHAR ucVoltageControlOffset; ++ USHORT usGpioPin_AIndex; //GPIO_PAD register index ++ UCHAR ucGpioPinBitShift[9]; //at most 8 pin support 255 VIDs, termintate with 0xff ++ UCHAR ucReserved; ++}ATOM_VOLTAGE_CONTROL; ++ ++// Define ucVoltageControlId + #define VOLTAGE_CONTROLLED_BY_HW 0x00 + #define VOLTAGE_CONTROLLED_BY_I2C_MASK 0x7F + #define VOLTAGE_CONTROLLED_BY_GPIO 0x80 +-#define VOLTAGE_CONTROL_ID_LM64 0x01 /* I2C control, used for R5xx Core Voltage */ +-#define VOLTAGE_CONTROL_ID_DAC 0x02 /* I2C control, used for R5xx/R6xx MVDDC,MVDDQ or VDDCI */ +-#define VOLTAGE_CONTROL_ID_VT116xM 0x03 /* I2C control, used for R6xx Core Voltage */ +-#define VOLTAGE_CONTROL_ID_DS4402 0x04 +- +-typedef struct _ATOM_VOLTAGE_OBJECT { +- UCHAR ucVoltageType; /* Indicate Voltage Source: VDDC, MVDDC, MVDDQ or MVDDCI */ +- UCHAR ucSize; /* Size of Object */ +- ATOM_VOLTAGE_CONTROL asControl; /* describ how to control */ +- ATOM_VOLTAGE_FORMULA asFormula; /* Indicate How to convert real Voltage to VID */ +-} ATOM_VOLTAGE_OBJECT; +- +-typedef struct _ATOM_VOLTAGE_OBJECT_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_VOLTAGE_OBJECT asVoltageObj[3]; /* Info for Voltage control */ +-} ATOM_VOLTAGE_OBJECT_INFO; +- +-typedef struct _ATOM_LEAKID_VOLTAGE { +- UCHAR ucLeakageId; +- UCHAR ucReserved; +- USHORT usVoltage; +-} ATOM_LEAKID_VOLTAGE; +- +-typedef struct _ATOM_ASIC_PROFILE_VOLTAGE { +- UCHAR ucProfileId; +- UCHAR ucReserved; +- USHORT usSize; +- USHORT usEfuseSpareStartAddr; +- USHORT usFuseIndex[8]; /* from LSB to MSB, Max 8bit,end of 0xffff if less than 8 efuse id, */ +- ATOM_LEAKID_VOLTAGE asLeakVol[2]; /* Leakid and relatd voltage */ +-} ATOM_ASIC_PROFILE_VOLTAGE; +- +-/* ucProfileId */ +-#define ATOM_ASIC_PROFILE_ID_EFUSE_VOLTAGE 1 ++#define VOLTAGE_CONTROL_ID_LM64 0x01 //I2C control, used for R5xx Core Voltage ++#define VOLTAGE_CONTROL_ID_DAC 0x02 //I2C control, used for R5xx/R6xx MVDDC,MVDDQ or VDDCI ++#define VOLTAGE_CONTROL_ID_VT116xM 0x03 //I2C control, used for R6xx Core Voltage ++#define VOLTAGE_CONTROL_ID_DS4402 0x04 ++ ++typedef struct _ATOM_VOLTAGE_OBJECT ++{ ++ UCHAR ucVoltageType; //Indicate Voltage Source: VDDC, MVDDC, MVDDQ or MVDDCI ++ UCHAR ucSize; //Size of Object ++ ATOM_VOLTAGE_CONTROL asControl; //describ how to control ++ ATOM_VOLTAGE_FORMULA asFormula; //Indicate How to convert real Voltage to VID ++}ATOM_VOLTAGE_OBJECT; ++ ++typedef struct _ATOM_VOLTAGE_OBJECT_V2 ++{ ++ UCHAR ucVoltageType; //Indicate Voltage Source: VDDC, MVDDC, MVDDQ or MVDDCI ++ UCHAR ucSize; //Size of Object ++ ATOM_VOLTAGE_CONTROL asControl; //describ how to control ++ ATOM_VOLTAGE_FORMULA_V2 asFormula; //Indicate How to convert real Voltage to VID ++}ATOM_VOLTAGE_OBJECT_V2; ++ ++typedef struct _ATOM_VOLTAGE_OBJECT_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_VOLTAGE_OBJECT asVoltageObj[3]; //Info for Voltage control ++}ATOM_VOLTAGE_OBJECT_INFO; ++ ++typedef struct _ATOM_VOLTAGE_OBJECT_INFO_V2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_VOLTAGE_OBJECT_V2 asVoltageObj[3]; //Info for Voltage control ++}ATOM_VOLTAGE_OBJECT_INFO_V2; ++ ++typedef struct _ATOM_LEAKID_VOLTAGE ++{ ++ UCHAR ucLeakageId; ++ UCHAR ucReserved; ++ USHORT usVoltage; ++}ATOM_LEAKID_VOLTAGE; ++ ++typedef struct _ATOM_ASIC_PROFILE_VOLTAGE ++{ ++ UCHAR ucProfileId; ++ UCHAR ucReserved; ++ USHORT usSize; ++ USHORT usEfuseSpareStartAddr; ++ USHORT usFuseIndex[8]; //from LSB to MSB, Max 8bit,end of 0xffff if less than 8 efuse id, ++ ATOM_LEAKID_VOLTAGE asLeakVol[2]; //Leakid and relatd voltage ++}ATOM_ASIC_PROFILE_VOLTAGE; ++ ++//ucProfileId ++#define ATOM_ASIC_PROFILE_ID_EFUSE_VOLTAGE 1 + #define ATOM_ASIC_PROFILE_ID_EFUSE_PERFORMANCE_VOLTAGE 1 + #define ATOM_ASIC_PROFILE_ID_EFUSE_THERMAL_VOLTAGE 2 + +-typedef struct _ATOM_ASIC_PROFILING_INFO { +- ATOM_COMMON_TABLE_HEADER asHeader; +- ATOM_ASIC_PROFILE_VOLTAGE asVoltage; +-} ATOM_ASIC_PROFILING_INFO; +- +-typedef struct _ATOM_POWER_SOURCE_OBJECT { +- UCHAR ucPwrSrcId; /* Power source */ +- UCHAR ucPwrSensorType; /* GPIO, I2C or none */ +- UCHAR ucPwrSensId; /* if GPIO detect, it is GPIO id, if I2C detect, it is I2C id */ +- UCHAR ucPwrSensSlaveAddr; /* Slave address if I2C detect */ +- UCHAR ucPwrSensRegIndex; /* I2C register Index if I2C detect */ +- UCHAR ucPwrSensRegBitMask; /* detect which bit is used if I2C detect */ +- UCHAR ucPwrSensActiveState; /* high active or low active */ +- UCHAR ucReserve[3]; /* reserve */ +- USHORT usSensPwr; /* in unit of watt */ +-} ATOM_POWER_SOURCE_OBJECT; +- +-typedef struct _ATOM_POWER_SOURCE_INFO { +- ATOM_COMMON_TABLE_HEADER asHeader; +- UCHAR asPwrbehave[16]; +- ATOM_POWER_SOURCE_OBJECT asPwrObj[1]; +-} ATOM_POWER_SOURCE_INFO; +- +-/* Define ucPwrSrcId */ ++typedef struct _ATOM_ASIC_PROFILING_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER asHeader; ++ ATOM_ASIC_PROFILE_VOLTAGE asVoltage; ++}ATOM_ASIC_PROFILING_INFO; ++ ++typedef struct _ATOM_POWER_SOURCE_OBJECT ++{ ++ UCHAR ucPwrSrcId; // Power source ++ UCHAR ucPwrSensorType; // GPIO, I2C or none ++ UCHAR ucPwrSensId; // if GPIO detect, it is GPIO id, if I2C detect, it is I2C id ++ UCHAR ucPwrSensSlaveAddr; // Slave address if I2C detect ++ UCHAR ucPwrSensRegIndex; // I2C register Index if I2C detect ++ UCHAR ucPwrSensRegBitMask; // detect which bit is used if I2C detect ++ UCHAR ucPwrSensActiveState; // high active or low active ++ UCHAR ucReserve[3]; // reserve ++ USHORT usSensPwr; // in unit of watt ++}ATOM_POWER_SOURCE_OBJECT; ++ ++typedef struct _ATOM_POWER_SOURCE_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER asHeader; ++ UCHAR asPwrbehave[16]; ++ ATOM_POWER_SOURCE_OBJECT asPwrObj[1]; ++}ATOM_POWER_SOURCE_INFO; ++ ++ ++//Define ucPwrSrcId + #define POWERSOURCE_PCIE_ID1 0x00 + #define POWERSOURCE_6PIN_CONNECTOR_ID1 0x01 + #define POWERSOURCE_8PIN_CONNECTOR_ID1 0x02 + #define POWERSOURCE_6PIN_CONNECTOR_ID2 0x04 + #define POWERSOURCE_8PIN_CONNECTOR_ID2 0x08 + +-/* define ucPwrSensorId */ ++//define ucPwrSensorId + #define POWER_SENSOR_ALWAYS 0x00 + #define POWER_SENSOR_GPIO 0x01 + #define POWER_SENSOR_I2C 0x02 + ++typedef struct _ATOM_INTEGRATED_SYSTEM_INFO_V6 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ULONG ulBootUpEngineClock; ++ ULONG ulDentistVCOFreq; ++ ULONG ulBootUpUMAClock; ++ ULONG ulReserved1[8]; ++ ULONG ulBootUpReqDisplayVector; ++ ULONG ulOtherDisplayMisc; ++ ULONG ulGPUCapInfo; ++ ULONG ulReserved2[3]; ++ ULONG ulSystemConfig; ++ ULONG ulCPUCapInfo; ++ USHORT usMaxNBVoltage; ++ USHORT usMinNBVoltage; ++ USHORT usBootUpNBVoltage; ++ USHORT usExtDispConnInfoOffset; ++ UCHAR ucHtcTmpLmt; ++ UCHAR ucTjOffset; ++ UCHAR ucMemoryType; ++ UCHAR ucUMAChannelNumber; ++ ULONG ulCSR_M3_ARB_CNTL_DEFAULT[10]; ++ ULONG ulCSR_M3_ARB_CNTL_UVD[10]; ++ ULONG ulCSR_M3_ARB_CNTL_FS3D[10]; ++ ULONG ulReserved3[42]; ++ ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO sExtDispConnInfo; ++}ATOM_INTEGRATED_SYSTEM_INFO_V6; ++ ++/********************************************************************************************************************** ++// ATOM_INTEGRATED_SYSTEM_INFO_V6 Description ++//ulBootUpEngineClock: VBIOS bootup Engine clock frequency, in 10kHz unit. ++//ulDentistVCOFreq: Dentist VCO clock in 10kHz unit. ++//ulBootUpUMAClock: System memory boot up clock frequency in 10Khz unit. ++//ulReserved1[8] Reserved by now, must be 0x0. ++//ulBootUpReqDisplayVector VBIOS boot up display IDs ++// ATOM_DEVICE_CRT1_SUPPORT 0x0001 ++// ATOM_DEVICE_CRT2_SUPPORT 0x0010 ++// ATOM_DEVICE_DFP1_SUPPORT 0x0008 ++// ATOM_DEVICE_DFP6_SUPPORT 0x0040 ++// ATOM_DEVICE_DFP2_SUPPORT 0x0080 ++// ATOM_DEVICE_DFP3_SUPPORT 0x0200 ++// ATOM_DEVICE_DFP4_SUPPORT 0x0400 ++// ATOM_DEVICE_DFP5_SUPPORT 0x0800 ++// ATOM_DEVICE_LCD1_SUPPORT 0x0002 ++//ulOtherDisplayMisc Other display related flags, not defined yet. ++//ulGPUCapInfo TBD ++//ulReserved2[3] must be 0x0 for the reserved. ++//ulSystemConfig TBD ++//ulCPUCapInfo TBD ++//usMaxNBVoltage High NB voltage in unit of mv, calculated using current VDDNB (D24F2xDC) and VDDNB offset fuse. ++//usMinNBVoltage Low NB voltage in unit of mv, calculated using current VDDNB (D24F2xDC) and VDDNB offset fuse. ++//usBootUpNBVoltage Boot up NB voltage in unit of mv. ++//ucHtcTmpLmt Bit [22:16] of D24F3x64 Thermal Control (HTC) Register. ++//ucTjOffset Bit [28:22] of D24F3xE4 Thermtrip Status Register,may not be needed. ++//ucMemoryType [3:0]=1:DDR1;=2:DDR2;=3:DDR3.[7:4] is reserved. ++//ucUMAChannelNumber System memory channel numbers. ++//usExtDispConnectionInfoOffset ATOM_EXTERNAL_DISPLAY_CONNECTION_INFO offset relative to beginning of this table. ++//ulCSR_M3_ARB_CNTL_DEFAULT[10] Arrays with values for CSR M3 arbiter for default ++//ulCSR_M3_ARB_CNTL_UVD[10] Arrays with values for CSR M3 arbiter for UVD playback. ++//ulCSR_M3_ARB_CNTL_FS3D[10] Arrays with values for CSR M3 arbiter for Full Screen 3D applications. ++**********************************************************************************************************************/ ++ + /**************************************************************************/ +-/* This portion is only used when ext thermal chip or engine/memory clock SS chip is populated on a design */ +-/* Memory SS Info Table */ +-/* Define Memory Clock SS chip ID */ ++// This portion is only used when ext thermal chip or engine/memory clock SS chip is populated on a design ++//Memory SS Info Table ++//Define Memory Clock SS chip ID + #define ICS91719 1 + #define ICS91720 2 + +-/* Define one structure to inform SW a "block of data" writing to external SS chip via I2C protocol */ +-typedef struct _ATOM_I2C_DATA_RECORD { +- UCHAR ucNunberOfBytes; /* Indicates how many bytes SW needs to write to the external ASIC for one block, besides to "Start" and "Stop" */ +- UCHAR ucI2CData[1]; /* I2C data in bytes, should be less than 16 bytes usually */ +-} ATOM_I2C_DATA_RECORD; +- +-/* Define one structure to inform SW how many blocks of data writing to external SS chip via I2C protocol, in addition to other information */ +-typedef struct _ATOM_I2C_DEVICE_SETUP_INFO { +- ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; /* I2C line and HW/SW assisted cap. */ +- UCHAR ucSSChipID; /* SS chip being used */ +- UCHAR ucSSChipSlaveAddr; /* Slave Address to set up this SS chip */ +- UCHAR ucNumOfI2CDataRecords; /* number of data block */ +- ATOM_I2C_DATA_RECORD asI2CData[1]; +-} ATOM_I2C_DEVICE_SETUP_INFO; +- +-/* ========================================================================================== */ +-typedef struct _ATOM_ASIC_MVDD_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_I2C_DEVICE_SETUP_INFO asI2CSetup[1]; +-} ATOM_ASIC_MVDD_INFO; +- +-/* ========================================================================================== */ ++//Define one structure to inform SW a "block of data" writing to external SS chip via I2C protocol ++typedef struct _ATOM_I2C_DATA_RECORD ++{ ++ UCHAR ucNunberOfBytes; //Indicates how many bytes SW needs to write to the external ASIC for one block, besides to "Start" and "Stop" ++ UCHAR ucI2CData[1]; //I2C data in bytes, should be less than 16 bytes usually ++}ATOM_I2C_DATA_RECORD; ++ ++ ++//Define one structure to inform SW how many blocks of data writing to external SS chip via I2C protocol, in addition to other information ++typedef struct _ATOM_I2C_DEVICE_SETUP_INFO ++{ ++ ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; //I2C line and HW/SW assisted cap. ++ UCHAR ucSSChipID; //SS chip being used ++ UCHAR ucSSChipSlaveAddr; //Slave Address to set up this SS chip ++ UCHAR ucNumOfI2CDataRecords; //number of data block ++ ATOM_I2C_DATA_RECORD asI2CData[1]; ++}ATOM_I2C_DEVICE_SETUP_INFO; ++ ++//========================================================================================== ++typedef struct _ATOM_ASIC_MVDD_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_I2C_DEVICE_SETUP_INFO asI2CSetup[1]; ++}ATOM_ASIC_MVDD_INFO; ++ ++//========================================================================================== + #define ATOM_MCLK_SS_INFO ATOM_ASIC_MVDD_INFO + +-/* ========================================================================================== */ ++//========================================================================================== + /**************************************************************************/ + +-typedef struct _ATOM_ASIC_SS_ASSIGNMENT { +- ULONG ulTargetClockRange; /* Clock Out frequence (VCO ), in unit of 10Khz */ +- USHORT usSpreadSpectrumPercentage; /* in unit of 0.01% */ +- USHORT usSpreadRateInKhz; /* in unit of kHz, modulation freq */ +- UCHAR ucClockIndication; /* Indicate which clock source needs SS */ +- UCHAR ucSpreadSpectrumMode; /* Bit1=0 Down Spread,=1 Center Spread. */ +- UCHAR ucReserved[2]; +-} ATOM_ASIC_SS_ASSIGNMENT; +- +-/* Define ucSpreadSpectrumType */ ++typedef struct _ATOM_ASIC_SS_ASSIGNMENT ++{ ++ ULONG ulTargetClockRange; //Clock Out frequence (VCO ), in unit of 10Khz ++ USHORT usSpreadSpectrumPercentage; //in unit of 0.01% ++ USHORT usSpreadRateInKhz; //in unit of kHz, modulation freq ++ UCHAR ucClockIndication; //Indicate which clock source needs SS ++ UCHAR ucSpreadSpectrumMode; //Bit1=0 Down Spread,=1 Center Spread. ++ UCHAR ucReserved[2]; ++}ATOM_ASIC_SS_ASSIGNMENT; ++ ++//Define ucClockIndication, SW uses the IDs below to search if the SS is requried/enabled on a clock branch/signal type. ++//SS is not required or enabled if a match is not found. + #define ASIC_INTERNAL_MEMORY_SS 1 + #define ASIC_INTERNAL_ENGINE_SS 2 +-#define ASIC_INTERNAL_UVD_SS 3 ++#define ASIC_INTERNAL_UVD_SS 3 ++#define ASIC_INTERNAL_SS_ON_TMDS 4 ++#define ASIC_INTERNAL_SS_ON_HDMI 5 ++#define ASIC_INTERNAL_SS_ON_LVDS 6 ++#define ASIC_INTERNAL_SS_ON_DP 7 ++#define ASIC_INTERNAL_SS_ON_DCPLL 8 ++ ++typedef struct _ATOM_ASIC_SS_ASSIGNMENT_V2 ++{ ++ ULONG ulTargetClockRange; //For mem/engine/uvd, Clock Out frequence (VCO ), in unit of 10Khz ++ //For TMDS/HDMI/LVDS, it is pixel clock , for DP, it is link clock ( 27000 or 16200 ) ++ USHORT usSpreadSpectrumPercentage; //in unit of 0.01% ++ USHORT usSpreadRateIn10Hz; //in unit of 10Hz, modulation freq ++ UCHAR ucClockIndication; //Indicate which clock source needs SS ++ UCHAR ucSpreadSpectrumMode; //Bit0=0 Down Spread,=1 Center Spread, bit1=0: internal SS bit1=1: external SS ++ UCHAR ucReserved[2]; ++}ATOM_ASIC_SS_ASSIGNMENT_V2; ++ ++//ucSpreadSpectrumMode ++//#define ATOM_SS_DOWN_SPREAD_MODE_MASK 0x00000000 ++//#define ATOM_SS_DOWN_SPREAD_MODE 0x00000000 ++//#define ATOM_SS_CENTRE_SPREAD_MODE_MASK 0x00000001 ++//#define ATOM_SS_CENTRE_SPREAD_MODE 0x00000001 ++//#define ATOM_INTERNAL_SS_MASK 0x00000000 ++//#define ATOM_EXTERNAL_SS_MASK 0x00000002 ++ ++typedef struct _ATOM_ASIC_INTERNAL_SS_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_ASIC_SS_ASSIGNMENT asSpreadSpectrum[4]; ++}ATOM_ASIC_INTERNAL_SS_INFO; + +-typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_ASIC_SS_ASSIGNMENT asSpreadSpectrum[4]; +-} ATOM_ASIC_INTERNAL_SS_INFO; ++typedef struct _ATOM_ASIC_INTERNAL_SS_INFO_V2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_ASIC_SS_ASSIGNMENT_V2 asSpreadSpectrum[1]; //this is point only. ++}ATOM_ASIC_INTERNAL_SS_INFO_V2; + +-/* ==============================Scratch Pad Definition Portion=============================== */ ++typedef struct _ATOM_ASIC_SS_ASSIGNMENT_V3 ++{ ++ ULONG ulTargetClockRange; //For mem/engine/uvd, Clock Out frequence (VCO ), in unit of 10Khz ++ //For TMDS/HDMI/LVDS, it is pixel clock , for DP, it is link clock ( 27000 or 16200 ) ++ USHORT usSpreadSpectrumPercentage; //in unit of 0.01% ++ USHORT usSpreadRateIn10Hz; //in unit of 10Hz, modulation freq ++ UCHAR ucClockIndication; //Indicate which clock source needs SS ++ UCHAR ucSpreadSpectrumMode; //Bit0=0 Down Spread,=1 Center Spread, bit1=0: internal SS bit1=1: external SS ++ UCHAR ucReserved[2]; ++}ATOM_ASIC_SS_ASSIGNMENT_V3; ++ ++typedef struct _ATOM_ASIC_INTERNAL_SS_INFO_V3 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_ASIC_SS_ASSIGNMENT_V3 asSpreadSpectrum[1]; //this is pointer only. ++}ATOM_ASIC_INTERNAL_SS_INFO_V3; ++ ++ ++//==============================Scratch Pad Definition Portion=============================== + #define ATOM_DEVICE_CONNECT_INFO_DEF 0 + #define ATOM_ROM_LOCATION_DEF 1 + #define ATOM_TV_STANDARD_DEF 2 +@@ -2995,7 +3852,8 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_I2C_CHANNEL_STATUS_DEF 8 + #define ATOM_I2C_CHANNEL_STATUS1_DEF 9 + +-/* BIOS_0_SCRATCH Definition */ ++ ++// BIOS_0_SCRATCH Definition + #define ATOM_S0_CRT1_MONO 0x00000001L + #define ATOM_S0_CRT1_COLOR 0x00000002L + #define ATOM_S0_CRT1_MASK (ATOM_S0_CRT1_MONO+ATOM_S0_CRT1_COLOR) +@@ -3008,6 +3866,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S0_CV_DIN_A 0x00000020L + #define ATOM_S0_CV_MASK_A (ATOM_S0_CV_A+ATOM_S0_CV_DIN_A) + ++ + #define ATOM_S0_CRT2_MONO 0x00000100L + #define ATOM_S0_CRT2_COLOR 0x00000200L + #define ATOM_S0_CRT2_MASK (ATOM_S0_CRT2_MONO+ATOM_S0_CRT2_COLOR) +@@ -3025,28 +3884,27 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S0_DFP2 0x00020000L + #define ATOM_S0_LCD1 0x00040000L + #define ATOM_S0_LCD2 0x00080000L +-#define ATOM_S0_TV2 0x00100000L +-#define ATOM_S0_DFP3 0x00200000L +-#define ATOM_S0_DFP4 0x00400000L +-#define ATOM_S0_DFP5 0x00800000L ++#define ATOM_S0_DFP6 0x00100000L ++#define ATOM_S0_DFP3 0x00200000L ++#define ATOM_S0_DFP4 0x00400000L ++#define ATOM_S0_DFP5 0x00800000L + +-#define ATOM_S0_DFP_MASK \ +- (ATOM_S0_DFP1 | ATOM_S0_DFP2 | ATOM_S0_DFP3 | ATOM_S0_DFP4 | ATOM_S0_DFP5) ++#define ATOM_S0_DFP_MASK ATOM_S0_DFP1 | ATOM_S0_DFP2 | ATOM_S0_DFP3 | ATOM_S0_DFP4 | ATOM_S0_DFP5 | ATOM_S0_DFP6 + +-#define ATOM_S0_FAD_REGISTER_BUG 0x02000000L /* If set, indicates we are running a PCIE asic with */ +- /* the FAD/HDP reg access bug. Bit is read by DAL */ ++#define ATOM_S0_FAD_REGISTER_BUG 0x02000000L // If set, indicates we are running a PCIE asic with ++ // the FAD/HDP reg access bug. Bit is read by DAL, this is obsolete from RV5xx + + #define ATOM_S0_THERMAL_STATE_MASK 0x1C000000L + #define ATOM_S0_THERMAL_STATE_SHIFT 26 + + #define ATOM_S0_SYSTEM_POWER_STATE_MASK 0xE0000000L +-#define ATOM_S0_SYSTEM_POWER_STATE_SHIFT 29 ++#define ATOM_S0_SYSTEM_POWER_STATE_SHIFT 29 + + #define ATOM_S0_SYSTEM_POWER_STATE_VALUE_AC 1 + #define ATOM_S0_SYSTEM_POWER_STATE_VALUE_DC 2 + #define ATOM_S0_SYSTEM_POWER_STATE_VALUE_LITEAC 3 + +-/* Byte aligned definition for BIOS usage */ ++//Byte aligned defintion for BIOS usage + #define ATOM_S0_CRT1_MONOb0 0x01 + #define ATOM_S0_CRT1_COLORb0 0x02 + #define ATOM_S0_CRT1_MASKb0 (ATOM_S0_CRT1_MONOb0+ATOM_S0_CRT1_COLORb0) +@@ -3076,8 +3934,11 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S0_DFP2b2 0x02 + #define ATOM_S0_LCD1b2 0x04 + #define ATOM_S0_LCD2b2 0x08 +-#define ATOM_S0_TV2b2 0x10 +-#define ATOM_S0_DFP3b2 0x20 ++#define ATOM_S0_DFP6b2 0x10 ++#define ATOM_S0_DFP3b2 0x20 ++#define ATOM_S0_DFP4b2 0x40 ++#define ATOM_S0_DFP5b2 0x80 ++ + + #define ATOM_S0_THERMAL_STATE_MASKb3 0x1C + #define ATOM_S0_THERMAL_STATE_SHIFTb3 2 +@@ -3085,43 +3946,20 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S0_SYSTEM_POWER_STATE_MASKb3 0xE0 + #define ATOM_S0_LCD1_SHIFT 18 + +-/* BIOS_1_SCRATCH Definition */ ++// BIOS_1_SCRATCH Definition + #define ATOM_S1_ROM_LOCATION_MASK 0x0000FFFFL + #define ATOM_S1_PCI_BUS_DEV_MASK 0xFFFF0000L + +-/* BIOS_2_SCRATCH Definition */ ++// BIOS_2_SCRATCH Definition + #define ATOM_S2_TV1_STANDARD_MASK 0x0000000FL + #define ATOM_S2_CURRENT_BL_LEVEL_MASK 0x0000FF00L + #define ATOM_S2_CURRENT_BL_LEVEL_SHIFT 8 + +-#define ATOM_S2_CRT1_DPMS_STATE 0x00010000L +-#define ATOM_S2_LCD1_DPMS_STATE 0x00020000L +-#define ATOM_S2_TV1_DPMS_STATE 0x00040000L +-#define ATOM_S2_DFP1_DPMS_STATE 0x00080000L +-#define ATOM_S2_CRT2_DPMS_STATE 0x00100000L +-#define ATOM_S2_LCD2_DPMS_STATE 0x00200000L +-#define ATOM_S2_TV2_DPMS_STATE 0x00400000L +-#define ATOM_S2_DFP2_DPMS_STATE 0x00800000L +-#define ATOM_S2_CV_DPMS_STATE 0x01000000L +-#define ATOM_S2_DFP3_DPMS_STATE 0x02000000L +-#define ATOM_S2_DFP4_DPMS_STATE 0x04000000L +-#define ATOM_S2_DFP5_DPMS_STATE 0x08000000L +- +-#define ATOM_S2_DFP_DPM_STATE \ +- (ATOM_S2_DFP1_DPMS_STATE | ATOM_S2_DFP2_DPMS_STATE | \ +- ATOM_S2_DFP3_DPMS_STATE | ATOM_S2_DFP4_DPMS_STATE | \ +- ATOM_S2_DFP5_DPMS_STATE) +- +-#define ATOM_S2_DEVICE_DPMS_STATE \ +- (ATOM_S2_CRT1_DPMS_STATE + ATOM_S2_LCD1_DPMS_STATE + \ +- ATOM_S2_TV1_DPMS_STATE + ATOM_S2_DFP_DPMS_STATE + \ +- ATOM_S2_CRT2_DPMS_STATE + ATOM_S2_LCD2_DPMS_STATE + \ +- ATOM_S2_TV2_DPMS_STATE + ATOM_S2_CV_DPMS_STATE) +- + #define ATOM_S2_FORCEDLOWPWRMODE_STATE_MASK 0x0C000000L + #define ATOM_S2_FORCEDLOWPWRMODE_STATE_MASK_SHIFT 26 + #define ATOM_S2_FORCEDLOWPWRMODE_STATE_CHANGE 0x10000000L + ++#define ATOM_S2_DEVICE_DPMS_STATE 0x00010000L + #define ATOM_S2_VRI_BRIGHT_ENABLE 0x20000000L + + #define ATOM_S2_DISPLAY_ROTATION_0_DEGREE 0x0 +@@ -3131,21 +3969,11 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S2_DISPLAY_ROTATION_DEGREE_SHIFT 30 + #define ATOM_S2_DISPLAY_ROTATION_ANGLE_MASK 0xC0000000L + +-/* Byte aligned definition for BIOS usage */ ++ ++//Byte aligned defintion for BIOS usage + #define ATOM_S2_TV1_STANDARD_MASKb0 0x0F + #define ATOM_S2_CURRENT_BL_LEVEL_MASKb1 0xFF +-#define ATOM_S2_CRT1_DPMS_STATEb2 0x01 +-#define ATOM_S2_LCD1_DPMS_STATEb2 0x02 +-#define ATOM_S2_TV1_DPMS_STATEb2 0x04 +-#define ATOM_S2_DFP1_DPMS_STATEb2 0x08 +-#define ATOM_S2_CRT2_DPMS_STATEb2 0x10 +-#define ATOM_S2_LCD2_DPMS_STATEb2 0x20 +-#define ATOM_S2_TV2_DPMS_STATEb2 0x40 +-#define ATOM_S2_DFP2_DPMS_STATEb2 0x80 +-#define ATOM_S2_CV_DPMS_STATEb3 0x01 +-#define ATOM_S2_DFP3_DPMS_STATEb3 0x02 +-#define ATOM_S2_DFP4_DPMS_STATEb3 0x04 +-#define ATOM_S2_DFP5_DPMS_STATEb3 0x08 ++#define ATOM_S2_DEVICE_DPMS_STATEb2 0x01 + + #define ATOM_S2_DEVICE_DPMS_MASKw1 0x3FF + #define ATOM_S2_FORCEDLOWPWRMODE_STATE_MASKb3 0x0C +@@ -3153,21 +3981,22 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S2_VRI_BRIGHT_ENABLEb3 0x20 + #define ATOM_S2_ROTATION_STATE_MASKb3 0xC0 + +-/* BIOS_3_SCRATCH Definition */ ++ ++// BIOS_3_SCRATCH Definition + #define ATOM_S3_CRT1_ACTIVE 0x00000001L + #define ATOM_S3_LCD1_ACTIVE 0x00000002L + #define ATOM_S3_TV1_ACTIVE 0x00000004L + #define ATOM_S3_DFP1_ACTIVE 0x00000008L + #define ATOM_S3_CRT2_ACTIVE 0x00000010L + #define ATOM_S3_LCD2_ACTIVE 0x00000020L +-#define ATOM_S3_TV2_ACTIVE 0x00000040L ++#define ATOM_S3_DFP6_ACTIVE 0x00000040L + #define ATOM_S3_DFP2_ACTIVE 0x00000080L + #define ATOM_S3_CV_ACTIVE 0x00000100L + #define ATOM_S3_DFP3_ACTIVE 0x00000200L + #define ATOM_S3_DFP4_ACTIVE 0x00000400L + #define ATOM_S3_DFP5_ACTIVE 0x00000800L + +-#define ATOM_S3_DEVICE_ACTIVE_MASK 0x000003FFL ++#define ATOM_S3_DEVICE_ACTIVE_MASK 0x00000FFFL + + #define ATOM_S3_LCD_FULLEXPANSION_ACTIVE 0x00001000L + #define ATOM_S3_LCD_EXPANSION_ASPEC_RATIO_ACTIVE 0x00002000L +@@ -3178,7 +4007,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S3_DFP1_CRTC_ACTIVE 0x00080000L + #define ATOM_S3_CRT2_CRTC_ACTIVE 0x00100000L + #define ATOM_S3_LCD2_CRTC_ACTIVE 0x00200000L +-#define ATOM_S3_TV2_CRTC_ACTIVE 0x00400000L ++#define ATOM_S3_DFP6_CRTC_ACTIVE 0x00400000L + #define ATOM_S3_DFP2_CRTC_ACTIVE 0x00800000L + #define ATOM_S3_CV_CRTC_ACTIVE 0x01000000L + #define ATOM_S3_DFP3_CRTC_ACTIVE 0x02000000L +@@ -3187,17 +4016,18 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + + #define ATOM_S3_DEVICE_CRTC_ACTIVE_MASK 0x0FFF0000L + #define ATOM_S3_ASIC_GUI_ENGINE_HUNG 0x20000000L ++//Below two definitions are not supported in pplib, but in the old powerplay in DAL + #define ATOM_S3_ALLOW_FAST_PWR_SWITCH 0x40000000L + #define ATOM_S3_RQST_GPU_USE_MIN_PWR 0x80000000L + +-/* Byte aligned definition for BIOS usage */ ++//Byte aligned defintion for BIOS usage + #define ATOM_S3_CRT1_ACTIVEb0 0x01 + #define ATOM_S3_LCD1_ACTIVEb0 0x02 + #define ATOM_S3_TV1_ACTIVEb0 0x04 + #define ATOM_S3_DFP1_ACTIVEb0 0x08 + #define ATOM_S3_CRT2_ACTIVEb0 0x10 + #define ATOM_S3_LCD2_ACTIVEb0 0x20 +-#define ATOM_S3_TV2_ACTIVEb0 0x40 ++#define ATOM_S3_DFP6_ACTIVEb0 0x40 + #define ATOM_S3_DFP2_ACTIVEb0 0x80 + #define ATOM_S3_CV_ACTIVEb1 0x01 + #define ATOM_S3_DFP3_ACTIVEb1 0x02 +@@ -3212,7 +4042,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S3_DFP1_CRTC_ACTIVEb2 0x08 + #define ATOM_S3_CRT2_CRTC_ACTIVEb2 0x10 + #define ATOM_S3_LCD2_CRTC_ACTIVEb2 0x20 +-#define ATOM_S3_TV2_CRTC_ACTIVEb2 0x40 ++#define ATOM_S3_DFP6_CRTC_ACTIVEb2 0x40 + #define ATOM_S3_DFP2_CRTC_ACTIVEb2 0x80 + #define ATOM_S3_CV_CRTC_ACTIVEb3 0x01 + #define ATOM_S3_DFP3_CRTC_ACTIVEb3 0x02 +@@ -3221,35 +4051,31 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + + #define ATOM_S3_ACTIVE_CRTC2w1 0xFFF + +-#define ATOM_S3_ASIC_GUI_ENGINE_HUNGb3 0x20 +-#define ATOM_S3_ALLOW_FAST_PWR_SWITCHb3 0x40 +-#define ATOM_S3_RQST_GPU_USE_MIN_PWRb3 0x80 +- +-/* BIOS_4_SCRATCH Definition */ ++// BIOS_4_SCRATCH Definition + #define ATOM_S4_LCD1_PANEL_ID_MASK 0x000000FFL + #define ATOM_S4_LCD1_REFRESH_MASK 0x0000FF00L + #define ATOM_S4_LCD1_REFRESH_SHIFT 8 + +-/* Byte aligned definition for BIOS usage */ ++//Byte aligned defintion for BIOS usage + #define ATOM_S4_LCD1_PANEL_ID_MASKb0 0x0FF + #define ATOM_S4_LCD1_REFRESH_MASKb1 ATOM_S4_LCD1_PANEL_ID_MASKb0 + #define ATOM_S4_VRAM_INFO_MASKb2 ATOM_S4_LCD1_PANEL_ID_MASKb0 + +-/* BIOS_5_SCRATCH Definition, BIOS_5_SCRATCH is used by Firmware only !!!! */ ++// BIOS_5_SCRATCH Definition, BIOS_5_SCRATCH is used by Firmware only !!!! + #define ATOM_S5_DOS_REQ_CRT1b0 0x01 + #define ATOM_S5_DOS_REQ_LCD1b0 0x02 + #define ATOM_S5_DOS_REQ_TV1b0 0x04 + #define ATOM_S5_DOS_REQ_DFP1b0 0x08 + #define ATOM_S5_DOS_REQ_CRT2b0 0x10 + #define ATOM_S5_DOS_REQ_LCD2b0 0x20 +-#define ATOM_S5_DOS_REQ_TV2b0 0x40 ++#define ATOM_S5_DOS_REQ_DFP6b0 0x40 + #define ATOM_S5_DOS_REQ_DFP2b0 0x80 + #define ATOM_S5_DOS_REQ_CVb1 0x01 + #define ATOM_S5_DOS_REQ_DFP3b1 0x02 + #define ATOM_S5_DOS_REQ_DFP4b1 0x04 + #define ATOM_S5_DOS_REQ_DFP5b1 0x08 + +-#define ATOM_S5_DOS_REQ_DEVICEw0 0x03FF ++#define ATOM_S5_DOS_REQ_DEVICEw0 0x0FFF + + #define ATOM_S5_DOS_REQ_CRT1 0x0001 + #define ATOM_S5_DOS_REQ_LCD1 0x0002 +@@ -3257,22 +4083,21 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S5_DOS_REQ_DFP1 0x0008 + #define ATOM_S5_DOS_REQ_CRT2 0x0010 + #define ATOM_S5_DOS_REQ_LCD2 0x0020 +-#define ATOM_S5_DOS_REQ_TV2 0x0040 ++#define ATOM_S5_DOS_REQ_DFP6 0x0040 + #define ATOM_S5_DOS_REQ_DFP2 0x0080 + #define ATOM_S5_DOS_REQ_CV 0x0100 +-#define ATOM_S5_DOS_REQ_DFP3 0x0200 +-#define ATOM_S5_DOS_REQ_DFP4 0x0400 +-#define ATOM_S5_DOS_REQ_DFP5 0x0800 ++#define ATOM_S5_DOS_REQ_DFP3 0x0200 ++#define ATOM_S5_DOS_REQ_DFP4 0x0400 ++#define ATOM_S5_DOS_REQ_DFP5 0x0800 + + #define ATOM_S5_DOS_FORCE_CRT1b2 ATOM_S5_DOS_REQ_CRT1b0 + #define ATOM_S5_DOS_FORCE_TV1b2 ATOM_S5_DOS_REQ_TV1b0 + #define ATOM_S5_DOS_FORCE_CRT2b2 ATOM_S5_DOS_REQ_CRT2b0 + #define ATOM_S5_DOS_FORCE_CVb3 ATOM_S5_DOS_REQ_CVb1 +-#define ATOM_S5_DOS_FORCE_DEVICEw1 \ +- (ATOM_S5_DOS_FORCE_CRT1b2 + ATOM_S5_DOS_FORCE_TV1b2 + \ +- ATOM_S5_DOS_FORCE_CRT2b2 + (ATOM_S5_DOS_FORCE_CVb3 << 8)) ++#define ATOM_S5_DOS_FORCE_DEVICEw1 (ATOM_S5_DOS_FORCE_CRT1b2+ATOM_S5_DOS_FORCE_TV1b2+ATOM_S5_DOS_FORCE_CRT2b2+\ ++ (ATOM_S5_DOS_FORCE_CVb3<<8)) + +-/* BIOS_6_SCRATCH Definition */ ++// BIOS_6_SCRATCH Definition + #define ATOM_S6_DEVICE_CHANGE 0x00000001L + #define ATOM_S6_SCALER_CHANGE 0x00000002L + #define ATOM_S6_LID_CHANGE 0x00000004L +@@ -3285,11 +4110,11 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S6_HW_I2C_BUSY_STATE 0x00000200L + #define ATOM_S6_THERMAL_STATE_CHANGE 0x00000400L + #define ATOM_S6_INTERRUPT_SET_BY_BIOS 0x00000800L +-#define ATOM_S6_REQ_LCD_EXPANSION_FULL 0x00001000L /* Normal expansion Request bit for LCD */ +-#define ATOM_S6_REQ_LCD_EXPANSION_ASPEC_RATIO 0x00002000L /* Aspect ratio expansion Request bit for LCD */ ++#define ATOM_S6_REQ_LCD_EXPANSION_FULL 0x00001000L //Normal expansion Request bit for LCD ++#define ATOM_S6_REQ_LCD_EXPANSION_ASPEC_RATIO 0x00002000L //Aspect ratio expansion Request bit for LCD + +-#define ATOM_S6_DISPLAY_STATE_CHANGE 0x00004000L /* This bit is recycled when ATOM_BIOS_INFO_BIOS_SCRATCH6_SCL2_REDEFINE is set,previously it's SCL2_H_expansion */ +-#define ATOM_S6_I2C_STATE_CHANGE 0x00008000L /* This bit is recycled,when ATOM_BIOS_INFO_BIOS_SCRATCH6_SCL2_REDEFINE is set,previously it's SCL2_V_expansion */ ++#define ATOM_S6_DISPLAY_STATE_CHANGE 0x00004000L //This bit is recycled when ATOM_BIOS_INFO_BIOS_SCRATCH6_SCL2_REDEFINE is set,previously it's SCL2_H_expansion ++#define ATOM_S6_I2C_STATE_CHANGE 0x00008000L //This bit is recycled,when ATOM_BIOS_INFO_BIOS_SCRATCH6_SCL2_REDEFINE is set,previously it's SCL2_V_expansion + + #define ATOM_S6_ACC_REQ_CRT1 0x00010000L + #define ATOM_S6_ACC_REQ_LCD1 0x00020000L +@@ -3297,7 +4122,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S6_ACC_REQ_DFP1 0x00080000L + #define ATOM_S6_ACC_REQ_CRT2 0x00100000L + #define ATOM_S6_ACC_REQ_LCD2 0x00200000L +-#define ATOM_S6_ACC_REQ_TV2 0x00400000L ++#define ATOM_S6_ACC_REQ_DFP6 0x00400000L + #define ATOM_S6_ACC_REQ_DFP2 0x00800000L + #define ATOM_S6_ACC_REQ_CV 0x01000000L + #define ATOM_S6_ACC_REQ_DFP3 0x02000000L +@@ -3310,7 +4135,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S6_VRI_BRIGHTNESS_CHANGE 0x40000000L + #define ATOM_S6_CONFIG_DISPLAY_CHANGE_MASK 0x80000000L + +-/* Byte aligned definition for BIOS usage */ ++//Byte aligned defintion for BIOS usage + #define ATOM_S6_DEVICE_CHANGEb0 0x01 + #define ATOM_S6_SCALER_CHANGEb0 0x02 + #define ATOM_S6_LID_CHANGEb0 0x04 +@@ -3320,11 +4145,11 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S6_LID_STATEb0 0x40 + #define ATOM_S6_DOCK_STATEb0 0x80 + #define ATOM_S6_CRITICAL_STATEb1 0x01 +-#define ATOM_S6_HW_I2C_BUSY_STATEb1 0x02 ++#define ATOM_S6_HW_I2C_BUSY_STATEb1 0x02 + #define ATOM_S6_THERMAL_STATE_CHANGEb1 0x04 + #define ATOM_S6_INTERRUPT_SET_BY_BIOSb1 0x08 +-#define ATOM_S6_REQ_LCD_EXPANSION_FULLb1 0x10 +-#define ATOM_S6_REQ_LCD_EXPANSION_ASPEC_RATIOb1 0x20 ++#define ATOM_S6_REQ_LCD_EXPANSION_FULLb1 0x10 ++#define ATOM_S6_REQ_LCD_EXPANSION_ASPEC_RATIOb1 0x20 + + #define ATOM_S6_ACC_REQ_CRT1b2 0x01 + #define ATOM_S6_ACC_REQ_LCD1b2 0x02 +@@ -3332,12 +4157,12 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S6_ACC_REQ_DFP1b2 0x08 + #define ATOM_S6_ACC_REQ_CRT2b2 0x10 + #define ATOM_S6_ACC_REQ_LCD2b2 0x20 +-#define ATOM_S6_ACC_REQ_TV2b2 0x40 ++#define ATOM_S6_ACC_REQ_DFP6b2 0x40 + #define ATOM_S6_ACC_REQ_DFP2b2 0x80 + #define ATOM_S6_ACC_REQ_CVb3 0x01 +-#define ATOM_S6_ACC_REQ_DFP3b3 0x02 +-#define ATOM_S6_ACC_REQ_DFP4b3 0x04 +-#define ATOM_S6_ACC_REQ_DFP5b3 0x08 ++#define ATOM_S6_ACC_REQ_DFP3b3 0x02 ++#define ATOM_S6_ACC_REQ_DFP4b3 0x04 ++#define ATOM_S6_ACC_REQ_DFP5b3 0x08 + + #define ATOM_S6_ACC_REQ_DEVICEw1 ATOM_S5_DOS_REQ_DEVICEw0 + #define ATOM_S6_SYSTEM_POWER_MODE_CHANGEb3 0x10 +@@ -3366,7 +4191,7 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + #define ATOM_S6_VRI_BRIGHTNESS_CHANGE_SHIFT 30 + #define ATOM_S6_CONFIG_DISPLAY_CHANGE_SHIFT 31 + +-/* BIOS_7_SCRATCH Definition, BIOS_7_SCRATCH is used by Firmware only !!!! */ ++// BIOS_7_SCRATCH Definition, BIOS_7_SCRATCH is used by Firmware only !!!! + #define ATOM_S7_DOS_MODE_TYPEb0 0x03 + #define ATOM_S7_DOS_MODE_VGAb0 0x00 + #define ATOM_S7_DOS_MODE_VESAb0 0x01 +@@ -3378,220 +4203,194 @@ typedef struct _ATOM_ASIC_INTERNAL_SS_INFO { + + #define ATOM_S7_DOS_8BIT_DAC_EN_SHIFT 8 + +-/* BIOS_8_SCRATCH Definition */ ++// BIOS_8_SCRATCH Definition + #define ATOM_S8_I2C_CHANNEL_BUSY_MASK 0x00000FFFF +-#define ATOM_S8_I2C_HW_ENGINE_BUSY_MASK 0x0FFFF0000 ++#define ATOM_S8_I2C_HW_ENGINE_BUSY_MASK 0x0FFFF0000 + + #define ATOM_S8_I2C_CHANNEL_BUSY_SHIFT 0 + #define ATOM_S8_I2C_ENGINE_BUSY_SHIFT 16 + +-/* BIOS_9_SCRATCH Definition */ +-#ifndef ATOM_S9_I2C_CHANNEL_COMPLETED_MASK ++// BIOS_9_SCRATCH Definition ++#ifndef ATOM_S9_I2C_CHANNEL_COMPLETED_MASK + #define ATOM_S9_I2C_CHANNEL_COMPLETED_MASK 0x0000FFFF + #endif +-#ifndef ATOM_S9_I2C_CHANNEL_ABORTED_MASK ++#ifndef ATOM_S9_I2C_CHANNEL_ABORTED_MASK + #define ATOM_S9_I2C_CHANNEL_ABORTED_MASK 0xFFFF0000 + #endif +-#ifndef ATOM_S9_I2C_CHANNEL_COMPLETED_SHIFT ++#ifndef ATOM_S9_I2C_CHANNEL_COMPLETED_SHIFT + #define ATOM_S9_I2C_CHANNEL_COMPLETED_SHIFT 0 + #endif +-#ifndef ATOM_S9_I2C_CHANNEL_ABORTED_SHIFT ++#ifndef ATOM_S9_I2C_CHANNEL_ABORTED_SHIFT + #define ATOM_S9_I2C_CHANNEL_ABORTED_SHIFT 16 + #endif + ++ + #define ATOM_FLAG_SET 0x20 + #define ATOM_FLAG_CLEAR 0 +-#define CLEAR_ATOM_S6_ACC_MODE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_ACC_MODE_SHIFT | ATOM_FLAG_CLEAR) +-#define SET_ATOM_S6_DEVICE_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_DEVICE_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define SET_ATOM_S6_VRI_BRIGHTNESS_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_VRI_BRIGHTNESS_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define SET_ATOM_S6_SCALER_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_SCALER_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define SET_ATOM_S6_LID_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_LID_CHANGE_SHIFT | ATOM_FLAG_SET) +- +-#define SET_ATOM_S6_LID_STATE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) |\ +- ATOM_S6_LID_STATE_SHIFT | ATOM_FLAG_SET) +-#define CLEAR_ATOM_S6_LID_STATE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_LID_STATE_SHIFT | ATOM_FLAG_CLEAR) +- +-#define SET_ATOM_S6_DOCK_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8)| \ +- ATOM_S6_DOCKING_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define SET_ATOM_S6_DOCK_STATE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_DOCK_STATE_SHIFT | ATOM_FLAG_SET) +-#define CLEAR_ATOM_S6_DOCK_STATE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_DOCK_STATE_SHIFT | ATOM_FLAG_CLEAR) +- +-#define SET_ATOM_S6_THERMAL_STATE_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_THERMAL_STATE_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define SET_ATOM_S6_SYSTEM_POWER_MODE_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_SYSTEM_POWER_MODE_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define SET_ATOM_S6_INTERRUPT_SET_BY_BIOS \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_INTERRUPT_SET_BY_BIOS_SHIFT | ATOM_FLAG_SET) +- +-#define SET_ATOM_S6_CRITICAL_STATE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_CRITICAL_STATE_SHIFT | ATOM_FLAG_SET) +-#define CLEAR_ATOM_S6_CRITICAL_STATE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_CRITICAL_STATE_SHIFT | ATOM_FLAG_CLEAR) +- +-#define SET_ATOM_S6_REQ_SCALER \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_REQ_SCALER_SHIFT | ATOM_FLAG_SET) +-#define CLEAR_ATOM_S6_REQ_SCALER \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_REQ_SCALER_SHIFT | ATOM_FLAG_CLEAR ) +- +-#define SET_ATOM_S6_REQ_SCALER_ARATIO \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_REQ_SCALER_ARATIO_SHIFT | ATOM_FLAG_SET ) +-#define CLEAR_ATOM_S6_REQ_SCALER_ARATIO \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_REQ_SCALER_ARATIO_SHIFT | ATOM_FLAG_CLEAR ) +- +-#define SET_ATOM_S6_I2C_STATE_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_I2C_STATE_CHANGE_SHIFT | ATOM_FLAG_SET ) +- +-#define SET_ATOM_S6_DISPLAY_STATE_CHANGE \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_DISPLAY_STATE_CHANGE_SHIFT | ATOM_FLAG_SET ) +- +-#define SET_ATOM_S6_DEVICE_RECONFIG \ +- ((ATOM_ACC_CHANGE_INFO_DEF << 8) | \ +- ATOM_S6_CONFIG_DISPLAY_CHANGE_SHIFT | ATOM_FLAG_SET) +-#define CLEAR_ATOM_S0_LCD1 \ +- ((ATOM_DEVICE_CONNECT_INFO_DEF << 8 ) | \ +- ATOM_S0_LCD1_SHIFT | ATOM_FLAG_CLEAR ) +-#define SET_ATOM_S7_DOS_8BIT_DAC_EN \ +- ((ATOM_DOS_MODE_INFO_DEF << 8) | \ +- ATOM_S7_DOS_8BIT_DAC_EN_SHIFT | ATOM_FLAG_SET ) +-#define CLEAR_ATOM_S7_DOS_8BIT_DAC_EN \ +- ((ATOM_DOS_MODE_INFO_DEF << 8) | \ +- ATOM_S7_DOS_8BIT_DAC_EN_SHIFT | ATOM_FLAG_CLEAR ) ++#define CLEAR_ATOM_S6_ACC_MODE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_ACC_MODE_SHIFT | ATOM_FLAG_CLEAR) ++#define SET_ATOM_S6_DEVICE_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_DEVICE_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define SET_ATOM_S6_VRI_BRIGHTNESS_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_VRI_BRIGHTNESS_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define SET_ATOM_S6_SCALER_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_SCALER_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define SET_ATOM_S6_LID_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_LID_CHANGE_SHIFT | ATOM_FLAG_SET) + +-/****************************************************************************/ +-/* Portion II: Definitinos only used in Driver */ ++#define SET_ATOM_S6_LID_STATE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_LID_STATE_SHIFT | ATOM_FLAG_SET) ++#define CLEAR_ATOM_S6_LID_STATE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_LID_STATE_SHIFT | ATOM_FLAG_CLEAR) ++ ++#define SET_ATOM_S6_DOCK_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_DOCKING_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define SET_ATOM_S6_DOCK_STATE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_DOCK_STATE_SHIFT | ATOM_FLAG_SET) ++#define CLEAR_ATOM_S6_DOCK_STATE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_DOCK_STATE_SHIFT | ATOM_FLAG_CLEAR) ++ ++#define SET_ATOM_S6_THERMAL_STATE_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_THERMAL_STATE_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define SET_ATOM_S6_SYSTEM_POWER_MODE_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_SYSTEM_POWER_MODE_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define SET_ATOM_S6_INTERRUPT_SET_BY_BIOS ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_INTERRUPT_SET_BY_BIOS_SHIFT | ATOM_FLAG_SET) ++ ++#define SET_ATOM_S6_CRITICAL_STATE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_CRITICAL_STATE_SHIFT | ATOM_FLAG_SET) ++#define CLEAR_ATOM_S6_CRITICAL_STATE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_CRITICAL_STATE_SHIFT | ATOM_FLAG_CLEAR) ++ ++#define SET_ATOM_S6_REQ_SCALER ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_REQ_SCALER_SHIFT | ATOM_FLAG_SET) ++#define CLEAR_ATOM_S6_REQ_SCALER ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_REQ_SCALER_SHIFT | ATOM_FLAG_CLEAR ) ++ ++#define SET_ATOM_S6_REQ_SCALER_ARATIO ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_REQ_SCALER_ARATIO_SHIFT | ATOM_FLAG_SET ) ++#define CLEAR_ATOM_S6_REQ_SCALER_ARATIO ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_REQ_SCALER_ARATIO_SHIFT | ATOM_FLAG_CLEAR ) ++ ++#define SET_ATOM_S6_I2C_STATE_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_I2C_STATE_CHANGE_SHIFT | ATOM_FLAG_SET ) ++ ++#define SET_ATOM_S6_DISPLAY_STATE_CHANGE ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_DISPLAY_STATE_CHANGE_SHIFT | ATOM_FLAG_SET ) ++ ++#define SET_ATOM_S6_DEVICE_RECONFIG ((ATOM_ACC_CHANGE_INFO_DEF << 8 )|ATOM_S6_CONFIG_DISPLAY_CHANGE_SHIFT | ATOM_FLAG_SET) ++#define CLEAR_ATOM_S0_LCD1 ((ATOM_DEVICE_CONNECT_INFO_DEF << 8 )| ATOM_S0_LCD1_SHIFT | ATOM_FLAG_CLEAR ) ++#define SET_ATOM_S7_DOS_8BIT_DAC_EN ((ATOM_DOS_MODE_INFO_DEF << 8 )|ATOM_S7_DOS_8BIT_DAC_EN_SHIFT | ATOM_FLAG_SET ) ++#define CLEAR_ATOM_S7_DOS_8BIT_DAC_EN ((ATOM_DOS_MODE_INFO_DEF << 8 )|ATOM_S7_DOS_8BIT_DAC_EN_SHIFT | ATOM_FLAG_CLEAR ) ++ ++/****************************************************************************/ ++//Portion II: Definitinos only used in Driver + /****************************************************************************/ + +-/* Macros used by driver */ ++// Macros used by driver ++#ifdef __cplusplus ++#define GetIndexIntoMasterTable(MasterOrData, FieldName) ((reinterpret_cast(&(static_cast(0))->FieldName)-static_cast(0))/sizeof(USHORT)) + +-#define GetIndexIntoMasterTable(MasterOrData, FieldName) (((char *)(&((ATOM_MASTER_LIST_OF_##MasterOrData##_TABLES *)0)->FieldName)-(char *)0)/sizeof(USHORT)) ++#define GET_COMMAND_TABLE_COMMANDSET_REVISION(TABLE_HEADER_OFFSET) (((static_cast(TABLE_HEADER_OFFSET))->ucTableFormatRevision )&0x3F) ++#define GET_COMMAND_TABLE_PARAMETER_REVISION(TABLE_HEADER_OFFSET) (((static_cast(TABLE_HEADER_OFFSET))->ucTableContentRevision)&0x3F) ++#else // not __cplusplus ++#define GetIndexIntoMasterTable(MasterOrData, FieldName) (((char*)(&((ATOM_MASTER_LIST_OF_##MasterOrData##_TABLES*)0)->FieldName)-(char*)0)/sizeof(USHORT)) + + #define GET_COMMAND_TABLE_COMMANDSET_REVISION(TABLE_HEADER_OFFSET) ((((ATOM_COMMON_TABLE_HEADER*)TABLE_HEADER_OFFSET)->ucTableFormatRevision)&0x3F) + #define GET_COMMAND_TABLE_PARAMETER_REVISION(TABLE_HEADER_OFFSET) ((((ATOM_COMMON_TABLE_HEADER*)TABLE_HEADER_OFFSET)->ucTableContentRevision)&0x3F) ++#endif // __cplusplus + + #define GET_DATA_TABLE_MAJOR_REVISION GET_COMMAND_TABLE_COMMANDSET_REVISION + #define GET_DATA_TABLE_MINOR_REVISION GET_COMMAND_TABLE_PARAMETER_REVISION + +-/****************************************************************************/ +-/* Portion III: Definitinos only used in VBIOS */ ++/****************************************************************************/ ++//Portion III: Definitinos only used in VBIOS + /****************************************************************************/ + #define ATOM_DAC_SRC 0x80 + #define ATOM_SRC_DAC1 0 + #define ATOM_SRC_DAC2 0x80 + +-#ifdef UEFI_BUILD +-#define USHORT UTEMP +-#endif +- +-typedef struct _MEMORY_PLLINIT_PARAMETERS { +- ULONG ulTargetMemoryClock; /* In 10Khz unit */ +- UCHAR ucAction; /* not define yet */ +- UCHAR ucFbDiv_Hi; /* Fbdiv Hi byte */ +- UCHAR ucFbDiv; /* FB value */ +- UCHAR ucPostDiv; /* Post div */ +-} MEMORY_PLLINIT_PARAMETERS; ++typedef struct _MEMORY_PLLINIT_PARAMETERS ++{ ++ ULONG ulTargetMemoryClock; //In 10Khz unit ++ UCHAR ucAction; //not define yet ++ UCHAR ucFbDiv_Hi; //Fbdiv Hi byte ++ UCHAR ucFbDiv; //FB value ++ UCHAR ucPostDiv; //Post div ++}MEMORY_PLLINIT_PARAMETERS; + + #define MEMORY_PLLINIT_PS_ALLOCATION MEMORY_PLLINIT_PARAMETERS + +-#define GPIO_PIN_WRITE 0x01 ++ ++#define GPIO_PIN_WRITE 0x01 + #define GPIO_PIN_READ 0x00 + +-typedef struct _GPIO_PIN_CONTROL_PARAMETERS { +- UCHAR ucGPIO_ID; /* return value, read from GPIO pins */ +- UCHAR ucGPIOBitShift; /* define which bit in uGPIOBitVal need to be update */ +- UCHAR ucGPIOBitVal; /* Set/Reset corresponding bit defined in ucGPIOBitMask */ +- UCHAR ucAction; /* =GPIO_PIN_WRITE: Read; =GPIO_PIN_READ: Write */ +-} GPIO_PIN_CONTROL_PARAMETERS; +- +-typedef struct _ENABLE_SCALER_PARAMETERS { +- UCHAR ucScaler; /* ATOM_SCALER1, ATOM_SCALER2 */ +- UCHAR ucEnable; /* ATOM_SCALER_DISABLE or ATOM_SCALER_CENTER or ATOM_SCALER_EXPANSION */ +- UCHAR ucTVStandard; /* */ +- UCHAR ucPadding[1]; +-} ENABLE_SCALER_PARAMETERS; +-#define ENABLE_SCALER_PS_ALLOCATION ENABLE_SCALER_PARAMETERS +- +-/* ucEnable: */ ++typedef struct _GPIO_PIN_CONTROL_PARAMETERS ++{ ++ UCHAR ucGPIO_ID; //return value, read from GPIO pins ++ UCHAR ucGPIOBitShift; //define which bit in uGPIOBitVal need to be update ++ UCHAR ucGPIOBitVal; //Set/Reset corresponding bit defined in ucGPIOBitMask ++ UCHAR ucAction; //=GPIO_PIN_WRITE: Read; =GPIO_PIN_READ: Write ++}GPIO_PIN_CONTROL_PARAMETERS; ++ ++typedef struct _ENABLE_SCALER_PARAMETERS ++{ ++ UCHAR ucScaler; // ATOM_SCALER1, ATOM_SCALER2 ++ UCHAR ucEnable; // ATOM_SCALER_DISABLE or ATOM_SCALER_CENTER or ATOM_SCALER_EXPANSION ++ UCHAR ucTVStandard; // ++ UCHAR ucPadding[1]; ++}ENABLE_SCALER_PARAMETERS; ++#define ENABLE_SCALER_PS_ALLOCATION ENABLE_SCALER_PARAMETERS ++ ++//ucEnable: + #define SCALER_BYPASS_AUTO_CENTER_NO_REPLICATION 0 + #define SCALER_BYPASS_AUTO_CENTER_AUTO_REPLICATION 1 + #define SCALER_ENABLE_2TAP_ALPHA_MODE 2 + #define SCALER_ENABLE_MULTITAP_MODE 3 + +-typedef struct _ENABLE_HARDWARE_ICON_CURSOR_PARAMETERS { +- ULONG usHWIconHorzVertPosn; /* Hardware Icon Vertical position */ +- UCHAR ucHWIconVertOffset; /* Hardware Icon Vertical offset */ +- UCHAR ucHWIconHorzOffset; /* Hardware Icon Horizontal offset */ +- UCHAR ucSelection; /* ATOM_CURSOR1 or ATOM_ICON1 or ATOM_CURSOR2 or ATOM_ICON2 */ +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +-} ENABLE_HARDWARE_ICON_CURSOR_PARAMETERS; +- +-typedef struct _ENABLE_HARDWARE_ICON_CURSOR_PS_ALLOCATION { +- ENABLE_HARDWARE_ICON_CURSOR_PARAMETERS sEnableIcon; +- ENABLE_CRTC_PARAMETERS sReserved; +-} ENABLE_HARDWARE_ICON_CURSOR_PS_ALLOCATION; +- +-typedef struct _ENABLE_GRAPH_SURFACE_PARAMETERS { +- USHORT usHight; /* Image Hight */ +- USHORT usWidth; /* Image Width */ +- UCHAR ucSurface; /* Surface 1 or 2 */ +- UCHAR ucPadding[3]; +-} ENABLE_GRAPH_SURFACE_PARAMETERS; +- +-typedef struct _ENABLE_GRAPH_SURFACE_PARAMETERS_V1_2 { +- USHORT usHight; /* Image Hight */ +- USHORT usWidth; /* Image Width */ +- UCHAR ucSurface; /* Surface 1 or 2 */ +- UCHAR ucEnable; /* ATOM_ENABLE or ATOM_DISABLE */ +- UCHAR ucPadding[2]; +-} ENABLE_GRAPH_SURFACE_PARAMETERS_V1_2; +- +-typedef struct _ENABLE_GRAPH_SURFACE_PS_ALLOCATION { +- ENABLE_GRAPH_SURFACE_PARAMETERS sSetSurface; +- ENABLE_YUV_PS_ALLOCATION sReserved; /* Don't set this one */ +-} ENABLE_GRAPH_SURFACE_PS_ALLOCATION; +- +-typedef struct _MEMORY_CLEAN_UP_PARAMETERS { +- USHORT usMemoryStart; /* in 8Kb boundry, offset from memory base address */ +- USHORT usMemorySize; /* 8Kb blocks aligned */ +-} MEMORY_CLEAN_UP_PARAMETERS; ++typedef struct _ENABLE_HARDWARE_ICON_CURSOR_PARAMETERS ++{ ++ ULONG usHWIconHorzVertPosn; // Hardware Icon Vertical position ++ UCHAR ucHWIconVertOffset; // Hardware Icon Vertical offset ++ UCHAR ucHWIconHorzOffset; // Hardware Icon Horizontal offset ++ UCHAR ucSelection; // ATOM_CURSOR1 or ATOM_ICON1 or ATOM_CURSOR2 or ATOM_ICON2 ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++}ENABLE_HARDWARE_ICON_CURSOR_PARAMETERS; ++ ++typedef struct _ENABLE_HARDWARE_ICON_CURSOR_PS_ALLOCATION ++{ ++ ENABLE_HARDWARE_ICON_CURSOR_PARAMETERS sEnableIcon; ++ ENABLE_CRTC_PARAMETERS sReserved; ++}ENABLE_HARDWARE_ICON_CURSOR_PS_ALLOCATION; ++ ++typedef struct _ENABLE_GRAPH_SURFACE_PARAMETERS ++{ ++ USHORT usHight; // Image Hight ++ USHORT usWidth; // Image Width ++ UCHAR ucSurface; // Surface 1 or 2 ++ UCHAR ucPadding[3]; ++}ENABLE_GRAPH_SURFACE_PARAMETERS; ++ ++typedef struct _ENABLE_GRAPH_SURFACE_PARAMETERS_V1_2 ++{ ++ USHORT usHight; // Image Hight ++ USHORT usWidth; // Image Width ++ UCHAR ucSurface; // Surface 1 or 2 ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ UCHAR ucPadding[2]; ++}ENABLE_GRAPH_SURFACE_PARAMETERS_V1_2; ++ ++typedef struct _ENABLE_GRAPH_SURFACE_PARAMETERS_V1_3 ++{ ++ USHORT usHight; // Image Hight ++ USHORT usWidth; // Image Width ++ UCHAR ucSurface; // Surface 1 or 2 ++ UCHAR ucEnable; // ATOM_ENABLE or ATOM_DISABLE ++ USHORT usDeviceId; // Active Device Id for this surface. If no device, set to 0. ++}ENABLE_GRAPH_SURFACE_PARAMETERS_V1_3; ++ ++typedef struct _ENABLE_GRAPH_SURFACE_PS_ALLOCATION ++{ ++ ENABLE_GRAPH_SURFACE_PARAMETERS sSetSurface; ++ ENABLE_YUV_PS_ALLOCATION sReserved; // Don't set this one ++}ENABLE_GRAPH_SURFACE_PS_ALLOCATION; ++ ++typedef struct _MEMORY_CLEAN_UP_PARAMETERS ++{ ++ USHORT usMemoryStart; //in 8Kb boundry, offset from memory base address ++ USHORT usMemorySize; //8Kb blocks aligned ++}MEMORY_CLEAN_UP_PARAMETERS; + #define MEMORY_CLEAN_UP_PS_ALLOCATION MEMORY_CLEAN_UP_PARAMETERS + +-typedef struct _GET_DISPLAY_SURFACE_SIZE_PARAMETERS { +- USHORT usX_Size; /* When use as input parameter, usX_Size indicates which CRTC */ +- USHORT usY_Size; +-} GET_DISPLAY_SURFACE_SIZE_PARAMETERS; ++typedef struct _GET_DISPLAY_SURFACE_SIZE_PARAMETERS ++{ ++ USHORT usX_Size; //When use as input parameter, usX_Size indicates which CRTC ++ USHORT usY_Size; ++}GET_DISPLAY_SURFACE_SIZE_PARAMETERS; + +-typedef struct _INDIRECT_IO_ACCESS { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR IOAccessSequence[256]; ++typedef struct _INDIRECT_IO_ACCESS ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR IOAccessSequence[256]; + } INDIRECT_IO_ACCESS; + + #define INDIRECT_READ 0x00 +@@ -3615,93 +4414,108 @@ typedef struct _INDIRECT_IO_ACCESS { + #define INDIRECT_IO_NBMISC_READ INDIRECT_IO_NBMISC | INDIRECT_READ + #define INDIRECT_IO_NBMISC_WRITE INDIRECT_IO_NBMISC | INDIRECT_WRITE + +-typedef struct _ATOM_OEM_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; +-} ATOM_OEM_INFO; +- +-typedef struct _ATOM_TV_MODE { +- UCHAR ucVMode_Num; /* Video mode number */ +- UCHAR ucTV_Mode_Num; /* Internal TV mode number */ +-} ATOM_TV_MODE; +- +-typedef struct _ATOM_BIOS_INT_TVSTD_MODE { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usTV_Mode_LUT_Offset; /* Pointer to standard to internal number conversion table */ +- USHORT usTV_FIFO_Offset; /* Pointer to FIFO entry table */ +- USHORT usNTSC_Tbl_Offset; /* Pointer to SDTV_Mode_NTSC table */ +- USHORT usPAL_Tbl_Offset; /* Pointer to SDTV_Mode_PAL table */ +- USHORT usCV_Tbl_Offset; /* Pointer to SDTV_Mode_PAL table */ +-} ATOM_BIOS_INT_TVSTD_MODE; +- +-typedef struct _ATOM_TV_MODE_SCALER_PTR { +- USHORT ucFilter0_Offset; /* Pointer to filter format 0 coefficients */ +- USHORT usFilter1_Offset; /* Pointer to filter format 0 coefficients */ +- UCHAR ucTV_Mode_Num; +-} ATOM_TV_MODE_SCALER_PTR; +- +-typedef struct _ATOM_STANDARD_VESA_TIMING { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_DTD_FORMAT aModeTimings[16]; /* 16 is not the real array number, just for initial allocation */ +-} ATOM_STANDARD_VESA_TIMING; +- +-typedef struct _ATOM_STD_FORMAT { +- USHORT usSTD_HDisp; +- USHORT usSTD_VDisp; +- USHORT usSTD_RefreshRate; +- USHORT usReserved; +-} ATOM_STD_FORMAT; +- +-typedef struct _ATOM_VESA_TO_EXTENDED_MODE { +- USHORT usVESA_ModeNumber; +- USHORT usExtendedModeNumber; +-} ATOM_VESA_TO_EXTENDED_MODE; +- +-typedef struct _ATOM_VESA_TO_INTENAL_MODE_LUT { +- ATOM_COMMON_TABLE_HEADER sHeader; +- ATOM_VESA_TO_EXTENDED_MODE asVESA_ToExtendedModeInfo[76]; +-} ATOM_VESA_TO_INTENAL_MODE_LUT; ++typedef struct _ATOM_OEM_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; ++}ATOM_OEM_INFO; ++ ++typedef struct _ATOM_TV_MODE ++{ ++ UCHAR ucVMode_Num; //Video mode number ++ UCHAR ucTV_Mode_Num; //Internal TV mode number ++}ATOM_TV_MODE; ++ ++typedef struct _ATOM_BIOS_INT_TVSTD_MODE ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usTV_Mode_LUT_Offset; // Pointer to standard to internal number conversion table ++ USHORT usTV_FIFO_Offset; // Pointer to FIFO entry table ++ USHORT usNTSC_Tbl_Offset; // Pointer to SDTV_Mode_NTSC table ++ USHORT usPAL_Tbl_Offset; // Pointer to SDTV_Mode_PAL table ++ USHORT usCV_Tbl_Offset; // Pointer to SDTV_Mode_PAL table ++}ATOM_BIOS_INT_TVSTD_MODE; ++ ++ ++typedef struct _ATOM_TV_MODE_SCALER_PTR ++{ ++ USHORT ucFilter0_Offset; //Pointer to filter format 0 coefficients ++ USHORT usFilter1_Offset; //Pointer to filter format 0 coefficients ++ UCHAR ucTV_Mode_Num; ++}ATOM_TV_MODE_SCALER_PTR; ++ ++typedef struct _ATOM_STANDARD_VESA_TIMING ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_DTD_FORMAT aModeTimings[16]; // 16 is not the real array number, just for initial allocation ++}ATOM_STANDARD_VESA_TIMING; ++ ++ ++typedef struct _ATOM_STD_FORMAT ++{ ++ USHORT usSTD_HDisp; ++ USHORT usSTD_VDisp; ++ USHORT usSTD_RefreshRate; ++ USHORT usReserved; ++}ATOM_STD_FORMAT; ++ ++typedef struct _ATOM_VESA_TO_EXTENDED_MODE ++{ ++ USHORT usVESA_ModeNumber; ++ USHORT usExtendedModeNumber; ++}ATOM_VESA_TO_EXTENDED_MODE; ++ ++typedef struct _ATOM_VESA_TO_INTENAL_MODE_LUT ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ATOM_VESA_TO_EXTENDED_MODE asVESA_ToExtendedModeInfo[76]; ++}ATOM_VESA_TO_INTENAL_MODE_LUT; + + /*************** ATOM Memory Related Data Structure ***********************/ +-typedef struct _ATOM_MEMORY_VENDOR_BLOCK { +- UCHAR ucMemoryType; +- UCHAR ucMemoryVendor; +- UCHAR ucAdjMCId; +- UCHAR ucDynClkId; +- ULONG ulDllResetClkRange; +-} ATOM_MEMORY_VENDOR_BLOCK; +- +-typedef struct _ATOM_MEMORY_SETTING_ID_CONFIG { ++typedef struct _ATOM_MEMORY_VENDOR_BLOCK{ ++ UCHAR ucMemoryType; ++ UCHAR ucMemoryVendor; ++ UCHAR ucAdjMCId; ++ UCHAR ucDynClkId; ++ ULONG ulDllResetClkRange; ++}ATOM_MEMORY_VENDOR_BLOCK; ++ ++ ++typedef struct _ATOM_MEMORY_SETTING_ID_CONFIG{ + #if ATOM_BIG_ENDIAN +- ULONG ucMemBlkId:8; +- ULONG ulMemClockRange:24; ++ ULONG ucMemBlkId:8; ++ ULONG ulMemClockRange:24; + #else +- ULONG ulMemClockRange:24; +- ULONG ucMemBlkId:8; ++ ULONG ulMemClockRange:24; ++ ULONG ucMemBlkId:8; + #endif +-} ATOM_MEMORY_SETTING_ID_CONFIG; +- +-typedef union _ATOM_MEMORY_SETTING_ID_CONFIG_ACCESS { +- ATOM_MEMORY_SETTING_ID_CONFIG slAccess; +- ULONG ulAccess; +-} ATOM_MEMORY_SETTING_ID_CONFIG_ACCESS; +- +-typedef struct _ATOM_MEMORY_SETTING_DATA_BLOCK { +- ATOM_MEMORY_SETTING_ID_CONFIG_ACCESS ulMemoryID; +- ULONG aulMemData[1]; +-} ATOM_MEMORY_SETTING_DATA_BLOCK; +- +-typedef struct _ATOM_INIT_REG_INDEX_FORMAT { +- USHORT usRegIndex; /* MC register index */ +- UCHAR ucPreRegDataLength; /* offset in ATOM_INIT_REG_DATA_BLOCK.saRegDataBuf */ +-} ATOM_INIT_REG_INDEX_FORMAT; +- +-typedef struct _ATOM_INIT_REG_BLOCK { +- USHORT usRegIndexTblSize; /* size of asRegIndexBuf */ +- USHORT usRegDataBlkSize; /* size of ATOM_MEMORY_SETTING_DATA_BLOCK */ +- ATOM_INIT_REG_INDEX_FORMAT asRegIndexBuf[1]; +- ATOM_MEMORY_SETTING_DATA_BLOCK asRegDataBuf[1]; +-} ATOM_INIT_REG_BLOCK; ++}ATOM_MEMORY_SETTING_ID_CONFIG; ++ ++typedef union _ATOM_MEMORY_SETTING_ID_CONFIG_ACCESS ++{ ++ ATOM_MEMORY_SETTING_ID_CONFIG slAccess; ++ ULONG ulAccess; ++}ATOM_MEMORY_SETTING_ID_CONFIG_ACCESS; ++ ++ ++typedef struct _ATOM_MEMORY_SETTING_DATA_BLOCK{ ++ ATOM_MEMORY_SETTING_ID_CONFIG_ACCESS ulMemoryID; ++ ULONG aulMemData[1]; ++}ATOM_MEMORY_SETTING_DATA_BLOCK; ++ ++ ++typedef struct _ATOM_INIT_REG_INDEX_FORMAT{ ++ USHORT usRegIndex; // MC register index ++ UCHAR ucPreRegDataLength; // offset in ATOM_INIT_REG_DATA_BLOCK.saRegDataBuf ++}ATOM_INIT_REG_INDEX_FORMAT; ++ ++ ++typedef struct _ATOM_INIT_REG_BLOCK{ ++ USHORT usRegIndexTblSize; //size of asRegIndexBuf ++ USHORT usRegDataBlkSize; //size of ATOM_MEMORY_SETTING_DATA_BLOCK ++ ATOM_INIT_REG_INDEX_FORMAT asRegIndexBuf[1]; ++ ATOM_MEMORY_SETTING_DATA_BLOCK asRegDataBuf[1]; ++}ATOM_INIT_REG_BLOCK; + + #define END_OF_REG_INDEX_BLOCK 0x0ffff + #define END_OF_REG_DATA_BLOCK 0x00000000 +@@ -3716,16 +4530,19 @@ typedef struct _ATOM_INIT_REG_BLOCK { + #define INDEX_ACCESS_RANGE_END (INDEX_ACCESS_RANGE_BEGIN + 1) + #define VALUE_INDEX_ACCESS_SINGLE (INDEX_ACCESS_RANGE_END + 1) + +-typedef struct _ATOM_MC_INIT_PARAM_TABLE { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usAdjustARB_SEQDataOffset; +- USHORT usMCInitMemTypeTblOffset; +- USHORT usMCInitCommonTblOffset; +- USHORT usMCInitPowerDownTblOffset; +- ULONG ulARB_SEQDataBuf[32]; +- ATOM_INIT_REG_BLOCK asMCInitMemType; +- ATOM_INIT_REG_BLOCK asMCInitCommon; +-} ATOM_MC_INIT_PARAM_TABLE; ++ ++typedef struct _ATOM_MC_INIT_PARAM_TABLE ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usAdjustARB_SEQDataOffset; ++ USHORT usMCInitMemTypeTblOffset; ++ USHORT usMCInitCommonTblOffset; ++ USHORT usMCInitPowerDownTblOffset; ++ ULONG ulARB_SEQDataBuf[32]; ++ ATOM_INIT_REG_BLOCK asMCInitMemType; ++ ATOM_INIT_REG_BLOCK asMCInitCommon; ++}ATOM_MC_INIT_PARAM_TABLE; ++ + + #define _4Mx16 0x2 + #define _4Mx32 0x3 +@@ -3751,221 +4568,272 @@ typedef struct _ATOM_MC_INIT_PARAM_TABLE { + + #define QIMONDA INFINEON + #define PROMOS MOSEL ++#define KRETON INFINEON + +-/* ///////////Support for GDDR5 MC uCode to reside in upper 64K of ROM///////////// */ ++/////////////Support for GDDR5 MC uCode to reside in upper 64K of ROM///////////// + + #define UCODE_ROM_START_ADDRESS 0x1c000 +-#define UCODE_SIGNATURE 0x4375434d /* 'MCuC' - MC uCode */ +- +-/* uCode block header for reference */ +- +-typedef struct _MCuCodeHeader { +- ULONG ulSignature; +- UCHAR ucRevision; +- UCHAR ucChecksum; +- UCHAR ucReserved1; +- UCHAR ucReserved2; +- USHORT usParametersLength; +- USHORT usUCodeLength; +- USHORT usReserved1; +- USHORT usReserved2; ++#define UCODE_SIGNATURE 0x4375434d // 'MCuC' - MC uCode ++ ++//uCode block header for reference ++ ++typedef struct _MCuCodeHeader ++{ ++ ULONG ulSignature; ++ UCHAR ucRevision; ++ UCHAR ucChecksum; ++ UCHAR ucReserved1; ++ UCHAR ucReserved2; ++ USHORT usParametersLength; ++ USHORT usUCodeLength; ++ USHORT usReserved1; ++ USHORT usReserved2; + } MCuCodeHeader; + +-/* //////////////////////////////////////////////////////////////////////////////// */ ++////////////////////////////////////////////////////////////////////////////////// + + #define ATOM_MAX_NUMBER_OF_VRAM_MODULE 16 + + #define ATOM_VRAM_MODULE_MEMORY_VENDOR_ID_MASK 0xF +-typedef struct _ATOM_VRAM_MODULE_V1 { +- ULONG ulReserved; +- USHORT usEMRSValue; +- USHORT usMRSValue; +- USHORT usReserved; +- UCHAR ucExtMemoryID; /* An external indicator (by hardcode, callback or pin) to tell what is the current memory module */ +- UCHAR ucMemoryType; /* [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4;[3:0] reserved; */ +- UCHAR ucMemoryVenderID; /* Predefined,never change across designs or memory type/vender */ +- UCHAR ucMemoryDeviceCfg; /* [7:4]=0x0:4M;=0x1:8M;=0x2:16M;0x3:32M....[3:0]=0x0:x4;=0x1:x8;=0x2:x16;=0x3:x32... */ +- UCHAR ucRow; /* Number of Row,in power of 2; */ +- UCHAR ucColumn; /* Number of Column,in power of 2; */ +- UCHAR ucBank; /* Nunber of Bank; */ +- UCHAR ucRank; /* Number of Rank, in power of 2 */ +- UCHAR ucChannelNum; /* Number of channel; */ +- UCHAR ucChannelConfig; /* [3:0]=Indication of what channel combination;[4:7]=Channel bit width, in number of 2 */ +- UCHAR ucDefaultMVDDQ_ID; /* Default MVDDQ setting for this memory block, ID linking to MVDDQ info table to find real set-up data; */ +- UCHAR ucDefaultMVDDC_ID; /* Default MVDDC setting for this memory block, ID linking to MVDDC info table to find real set-up data; */ +- UCHAR ucReserved[2]; +-} ATOM_VRAM_MODULE_V1; +- +-typedef struct _ATOM_VRAM_MODULE_V2 { +- ULONG ulReserved; +- ULONG ulFlags; /* To enable/disable functionalities based on memory type */ +- ULONG ulEngineClock; /* Override of default engine clock for particular memory type */ +- ULONG ulMemoryClock; /* Override of default memory clock for particular memory type */ +- USHORT usEMRS2Value; /* EMRS2 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usEMRS3Value; /* EMRS3 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usEMRSValue; +- USHORT usMRSValue; +- USHORT usReserved; +- UCHAR ucExtMemoryID; /* An external indicator (by hardcode, callback or pin) to tell what is the current memory module */ +- UCHAR ucMemoryType; /* [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4;[3:0] - must not be used for now; */ +- UCHAR ucMemoryVenderID; /* Predefined,never change across designs or memory type/vender. If not predefined, vendor detection table gets executed */ +- UCHAR ucMemoryDeviceCfg; /* [7:4]=0x0:4M;=0x1:8M;=0x2:16M;0x3:32M....[3:0]=0x0:x4;=0x1:x8;=0x2:x16;=0x3:x32... */ +- UCHAR ucRow; /* Number of Row,in power of 2; */ +- UCHAR ucColumn; /* Number of Column,in power of 2; */ +- UCHAR ucBank; /* Nunber of Bank; */ +- UCHAR ucRank; /* Number of Rank, in power of 2 */ +- UCHAR ucChannelNum; /* Number of channel; */ +- UCHAR ucChannelConfig; /* [3:0]=Indication of what channel combination;[4:7]=Channel bit width, in number of 2 */ +- UCHAR ucDefaultMVDDQ_ID; /* Default MVDDQ setting for this memory block, ID linking to MVDDQ info table to find real set-up data; */ +- UCHAR ucDefaultMVDDC_ID; /* Default MVDDC setting for this memory block, ID linking to MVDDC info table to find real set-up data; */ +- UCHAR ucRefreshRateFactor; +- UCHAR ucReserved[3]; +-} ATOM_VRAM_MODULE_V2; +- +-typedef struct _ATOM_MEMORY_TIMING_FORMAT { +- ULONG ulClkRange; /* memory clock in 10kHz unit, when target memory clock is below this clock, use this memory timing */ +- union { +- USHORT usMRS; /* mode register */ +- USHORT usDDR3_MR0; +- }; +- union { +- USHORT usEMRS; /* extended mode register */ +- USHORT usDDR3_MR1; +- }; +- UCHAR ucCL; /* CAS latency */ +- UCHAR ucWL; /* WRITE Latency */ +- UCHAR uctRAS; /* tRAS */ +- UCHAR uctRC; /* tRC */ +- UCHAR uctRFC; /* tRFC */ +- UCHAR uctRCDR; /* tRCDR */ +- UCHAR uctRCDW; /* tRCDW */ +- UCHAR uctRP; /* tRP */ +- UCHAR uctRRD; /* tRRD */ +- UCHAR uctWR; /* tWR */ +- UCHAR uctWTR; /* tWTR */ +- UCHAR uctPDIX; /* tPDIX */ +- UCHAR uctFAW; /* tFAW */ +- UCHAR uctAOND; /* tAOND */ +- union { +- struct { +- UCHAR ucflag; /* flag to control memory timing calculation. bit0= control EMRS2 Infineon */ +- UCHAR ucReserved; +- }; +- USHORT usDDR3_MR2; +- }; +-} ATOM_MEMORY_TIMING_FORMAT; +- +-typedef struct _ATOM_MEMORY_TIMING_FORMAT_V1 { +- ULONG ulClkRange; /* memory clock in 10kHz unit, when target memory clock is below this clock, use this memory timing */ +- USHORT usMRS; /* mode register */ +- USHORT usEMRS; /* extended mode register */ +- UCHAR ucCL; /* CAS latency */ +- UCHAR ucWL; /* WRITE Latency */ +- UCHAR uctRAS; /* tRAS */ +- UCHAR uctRC; /* tRC */ +- UCHAR uctRFC; /* tRFC */ +- UCHAR uctRCDR; /* tRCDR */ +- UCHAR uctRCDW; /* tRCDW */ +- UCHAR uctRP; /* tRP */ +- UCHAR uctRRD; /* tRRD */ +- UCHAR uctWR; /* tWR */ +- UCHAR uctWTR; /* tWTR */ +- UCHAR uctPDIX; /* tPDIX */ +- UCHAR uctFAW; /* tFAW */ +- UCHAR uctAOND; /* tAOND */ +- UCHAR ucflag; /* flag to control memory timing calculation. bit0= control EMRS2 Infineon */ +-/* ///////////////////////GDDR parameters/////////////////////////////////// */ +- UCHAR uctCCDL; /* */ +- UCHAR uctCRCRL; /* */ +- UCHAR uctCRCWL; /* */ +- UCHAR uctCKE; /* */ +- UCHAR uctCKRSE; /* */ +- UCHAR uctCKRSX; /* */ +- UCHAR uctFAW32; /* */ +- UCHAR ucReserved1; /* */ +- UCHAR ucReserved2; /* */ +- UCHAR ucTerminator; +-} ATOM_MEMORY_TIMING_FORMAT_V1; +- +-typedef struct _ATOM_MEMORY_FORMAT { +- ULONG ulDllDisClock; /* memory DLL will be disable when target memory clock is below this clock */ +- union { +- USHORT usEMRS2Value; /* EMRS2 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usDDR3_Reserved; /* Not used for DDR3 memory */ +- }; +- union { +- USHORT usEMRS3Value; /* EMRS3 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usDDR3_MR3; /* Used for DDR3 memory */ +- }; +- UCHAR ucMemoryType; /* [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4;[3:0] - must not be used for now; */ +- UCHAR ucMemoryVenderID; /* Predefined,never change across designs or memory type/vender. If not predefined, vendor detection table gets executed */ +- UCHAR ucRow; /* Number of Row,in power of 2; */ +- UCHAR ucColumn; /* Number of Column,in power of 2; */ +- UCHAR ucBank; /* Nunber of Bank; */ +- UCHAR ucRank; /* Number of Rank, in power of 2 */ +- UCHAR ucBurstSize; /* burst size, 0= burst size=4 1= burst size=8 */ +- UCHAR ucDllDisBit; /* position of DLL Enable/Disable bit in EMRS ( Extended Mode Register ) */ +- UCHAR ucRefreshRateFactor; /* memory refresh rate in unit of ms */ +- UCHAR ucDensity; /* _8Mx32, _16Mx32, _16Mx16, _32Mx16 */ +- UCHAR ucPreamble; /* [7:4] Write Preamble, [3:0] Read Preamble */ +- UCHAR ucMemAttrib; /* Memory Device Addribute, like RDBI/WDBI etc */ +- ATOM_MEMORY_TIMING_FORMAT asMemTiming[5]; /* Memory Timing block sort from lower clock to higher clock */ +-} ATOM_MEMORY_FORMAT; +- +-typedef struct _ATOM_VRAM_MODULE_V3 { +- ULONG ulChannelMapCfg; /* board dependent paramenter:Channel combination */ +- USHORT usSize; /* size of ATOM_VRAM_MODULE_V3 */ +- USHORT usDefaultMVDDQ; /* board dependent parameter:Default Memory Core Voltage */ +- USHORT usDefaultMVDDC; /* board dependent parameter:Default Memory IO Voltage */ +- UCHAR ucExtMemoryID; /* An external indicator (by hardcode, callback or pin) to tell what is the current memory module */ +- UCHAR ucChannelNum; /* board dependent parameter:Number of channel; */ +- UCHAR ucChannelSize; /* board dependent parameter:32bit or 64bit */ +- UCHAR ucVREFI; /* board dependnt parameter: EXT or INT +160mv to -140mv */ +- UCHAR ucNPL_RT; /* board dependent parameter:NPL round trip delay, used for calculate memory timing parameters */ +- UCHAR ucFlag; /* To enable/disable functionalities based on memory type */ +- ATOM_MEMORY_FORMAT asMemory; /* describ all of video memory parameters from memory spec */ +-} ATOM_VRAM_MODULE_V3; +- +-/* ATOM_VRAM_MODULE_V3.ucNPL_RT */ ++typedef struct _ATOM_VRAM_MODULE_V1 ++{ ++ ULONG ulReserved; ++ USHORT usEMRSValue; ++ USHORT usMRSValue; ++ USHORT usReserved; ++ UCHAR ucExtMemoryID; // An external indicator (by hardcode, callback or pin) to tell what is the current memory module ++ UCHAR ucMemoryType; // [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4;[3:0] reserved; ++ UCHAR ucMemoryVenderID; // Predefined,never change across designs or memory type/vender ++ UCHAR ucMemoryDeviceCfg; // [7:4]=0x0:4M;=0x1:8M;=0x2:16M;0x3:32M....[3:0]=0x0:x4;=0x1:x8;=0x2:x16;=0x3:x32... ++ UCHAR ucRow; // Number of Row,in power of 2; ++ UCHAR ucColumn; // Number of Column,in power of 2; ++ UCHAR ucBank; // Nunber of Bank; ++ UCHAR ucRank; // Number of Rank, in power of 2 ++ UCHAR ucChannelNum; // Number of channel; ++ UCHAR ucChannelConfig; // [3:0]=Indication of what channel combination;[4:7]=Channel bit width, in number of 2 ++ UCHAR ucDefaultMVDDQ_ID; // Default MVDDQ setting for this memory block, ID linking to MVDDQ info table to find real set-up data; ++ UCHAR ucDefaultMVDDC_ID; // Default MVDDC setting for this memory block, ID linking to MVDDC info table to find real set-up data; ++ UCHAR ucReserved[2]; ++}ATOM_VRAM_MODULE_V1; ++ ++ ++typedef struct _ATOM_VRAM_MODULE_V2 ++{ ++ ULONG ulReserved; ++ ULONG ulFlags; // To enable/disable functionalities based on memory type ++ ULONG ulEngineClock; // Override of default engine clock for particular memory type ++ ULONG ulMemoryClock; // Override of default memory clock for particular memory type ++ USHORT usEMRS2Value; // EMRS2 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usEMRS3Value; // EMRS3 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usEMRSValue; ++ USHORT usMRSValue; ++ USHORT usReserved; ++ UCHAR ucExtMemoryID; // An external indicator (by hardcode, callback or pin) to tell what is the current memory module ++ UCHAR ucMemoryType; // [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4;[3:0] - must not be used for now; ++ UCHAR ucMemoryVenderID; // Predefined,never change across designs or memory type/vender. If not predefined, vendor detection table gets executed ++ UCHAR ucMemoryDeviceCfg; // [7:4]=0x0:4M;=0x1:8M;=0x2:16M;0x3:32M....[3:0]=0x0:x4;=0x1:x8;=0x2:x16;=0x3:x32... ++ UCHAR ucRow; // Number of Row,in power of 2; ++ UCHAR ucColumn; // Number of Column,in power of 2; ++ UCHAR ucBank; // Nunber of Bank; ++ UCHAR ucRank; // Number of Rank, in power of 2 ++ UCHAR ucChannelNum; // Number of channel; ++ UCHAR ucChannelConfig; // [3:0]=Indication of what channel combination;[4:7]=Channel bit width, in number of 2 ++ UCHAR ucDefaultMVDDQ_ID; // Default MVDDQ setting for this memory block, ID linking to MVDDQ info table to find real set-up data; ++ UCHAR ucDefaultMVDDC_ID; // Default MVDDC setting for this memory block, ID linking to MVDDC info table to find real set-up data; ++ UCHAR ucRefreshRateFactor; ++ UCHAR ucReserved[3]; ++}ATOM_VRAM_MODULE_V2; ++ ++ ++typedef struct _ATOM_MEMORY_TIMING_FORMAT ++{ ++ ULONG ulClkRange; // memory clock in 10kHz unit, when target memory clock is below this clock, use this memory timing ++ union{ ++ USHORT usMRS; // mode register ++ USHORT usDDR3_MR0; ++ }; ++ union{ ++ USHORT usEMRS; // extended mode register ++ USHORT usDDR3_MR1; ++ }; ++ UCHAR ucCL; // CAS latency ++ UCHAR ucWL; // WRITE Latency ++ UCHAR uctRAS; // tRAS ++ UCHAR uctRC; // tRC ++ UCHAR uctRFC; // tRFC ++ UCHAR uctRCDR; // tRCDR ++ UCHAR uctRCDW; // tRCDW ++ UCHAR uctRP; // tRP ++ UCHAR uctRRD; // tRRD ++ UCHAR uctWR; // tWR ++ UCHAR uctWTR; // tWTR ++ UCHAR uctPDIX; // tPDIX ++ UCHAR uctFAW; // tFAW ++ UCHAR uctAOND; // tAOND ++ union ++ { ++ struct { ++ UCHAR ucflag; // flag to control memory timing calculation. bit0= control EMRS2 Infineon ++ UCHAR ucReserved; ++ }; ++ USHORT usDDR3_MR2; ++ }; ++}ATOM_MEMORY_TIMING_FORMAT; ++ ++ ++typedef struct _ATOM_MEMORY_TIMING_FORMAT_V1 ++{ ++ ULONG ulClkRange; // memory clock in 10kHz unit, when target memory clock is below this clock, use this memory timing ++ USHORT usMRS; // mode register ++ USHORT usEMRS; // extended mode register ++ UCHAR ucCL; // CAS latency ++ UCHAR ucWL; // WRITE Latency ++ UCHAR uctRAS; // tRAS ++ UCHAR uctRC; // tRC ++ UCHAR uctRFC; // tRFC ++ UCHAR uctRCDR; // tRCDR ++ UCHAR uctRCDW; // tRCDW ++ UCHAR uctRP; // tRP ++ UCHAR uctRRD; // tRRD ++ UCHAR uctWR; // tWR ++ UCHAR uctWTR; // tWTR ++ UCHAR uctPDIX; // tPDIX ++ UCHAR uctFAW; // tFAW ++ UCHAR uctAOND; // tAOND ++ UCHAR ucflag; // flag to control memory timing calculation. bit0= control EMRS2 Infineon ++////////////////////////////////////GDDR parameters/////////////////////////////////// ++ UCHAR uctCCDL; // ++ UCHAR uctCRCRL; // ++ UCHAR uctCRCWL; // ++ UCHAR uctCKE; // ++ UCHAR uctCKRSE; // ++ UCHAR uctCKRSX; // ++ UCHAR uctFAW32; // ++ UCHAR ucMR5lo; // ++ UCHAR ucMR5hi; // ++ UCHAR ucTerminator; ++}ATOM_MEMORY_TIMING_FORMAT_V1; ++ ++typedef struct _ATOM_MEMORY_TIMING_FORMAT_V2 ++{ ++ ULONG ulClkRange; // memory clock in 10kHz unit, when target memory clock is below this clock, use this memory timing ++ USHORT usMRS; // mode register ++ USHORT usEMRS; // extended mode register ++ UCHAR ucCL; // CAS latency ++ UCHAR ucWL; // WRITE Latency ++ UCHAR uctRAS; // tRAS ++ UCHAR uctRC; // tRC ++ UCHAR uctRFC; // tRFC ++ UCHAR uctRCDR; // tRCDR ++ UCHAR uctRCDW; // tRCDW ++ UCHAR uctRP; // tRP ++ UCHAR uctRRD; // tRRD ++ UCHAR uctWR; // tWR ++ UCHAR uctWTR; // tWTR ++ UCHAR uctPDIX; // tPDIX ++ UCHAR uctFAW; // tFAW ++ UCHAR uctAOND; // tAOND ++ UCHAR ucflag; // flag to control memory timing calculation. bit0= control EMRS2 Infineon ++////////////////////////////////////GDDR parameters/////////////////////////////////// ++ UCHAR uctCCDL; // ++ UCHAR uctCRCRL; // ++ UCHAR uctCRCWL; // ++ UCHAR uctCKE; // ++ UCHAR uctCKRSE; // ++ UCHAR uctCKRSX; // ++ UCHAR uctFAW32; // ++ UCHAR ucMR4lo; // ++ UCHAR ucMR4hi; // ++ UCHAR ucMR5lo; // ++ UCHAR ucMR5hi; // ++ UCHAR ucTerminator; ++ UCHAR ucReserved; ++}ATOM_MEMORY_TIMING_FORMAT_V2; ++ ++typedef struct _ATOM_MEMORY_FORMAT ++{ ++ ULONG ulDllDisClock; // memory DLL will be disable when target memory clock is below this clock ++ union{ ++ USHORT usEMRS2Value; // EMRS2 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usDDR3_Reserved; // Not used for DDR3 memory ++ }; ++ union{ ++ USHORT usEMRS3Value; // EMRS3 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usDDR3_MR3; // Used for DDR3 memory ++ }; ++ UCHAR ucMemoryType; // [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4;[3:0] - must not be used for now; ++ UCHAR ucMemoryVenderID; // Predefined,never change across designs or memory type/vender. If not predefined, vendor detection table gets executed ++ UCHAR ucRow; // Number of Row,in power of 2; ++ UCHAR ucColumn; // Number of Column,in power of 2; ++ UCHAR ucBank; // Nunber of Bank; ++ UCHAR ucRank; // Number of Rank, in power of 2 ++ UCHAR ucBurstSize; // burst size, 0= burst size=4 1= burst size=8 ++ UCHAR ucDllDisBit; // position of DLL Enable/Disable bit in EMRS ( Extended Mode Register ) ++ UCHAR ucRefreshRateFactor; // memory refresh rate in unit of ms ++ UCHAR ucDensity; // _8Mx32, _16Mx32, _16Mx16, _32Mx16 ++ UCHAR ucPreamble; //[7:4] Write Preamble, [3:0] Read Preamble ++ UCHAR ucMemAttrib; // Memory Device Addribute, like RDBI/WDBI etc ++ ATOM_MEMORY_TIMING_FORMAT asMemTiming[5]; //Memory Timing block sort from lower clock to higher clock ++}ATOM_MEMORY_FORMAT; ++ ++ ++typedef struct _ATOM_VRAM_MODULE_V3 ++{ ++ ULONG ulChannelMapCfg; // board dependent paramenter:Channel combination ++ USHORT usSize; // size of ATOM_VRAM_MODULE_V3 ++ USHORT usDefaultMVDDQ; // board dependent parameter:Default Memory Core Voltage ++ USHORT usDefaultMVDDC; // board dependent parameter:Default Memory IO Voltage ++ UCHAR ucExtMemoryID; // An external indicator (by hardcode, callback or pin) to tell what is the current memory module ++ UCHAR ucChannelNum; // board dependent parameter:Number of channel; ++ UCHAR ucChannelSize; // board dependent parameter:32bit or 64bit ++ UCHAR ucVREFI; // board dependnt parameter: EXT or INT +160mv to -140mv ++ UCHAR ucNPL_RT; // board dependent parameter:NPL round trip delay, used for calculate memory timing parameters ++ UCHAR ucFlag; // To enable/disable functionalities based on memory type ++ ATOM_MEMORY_FORMAT asMemory; // describ all of video memory parameters from memory spec ++}ATOM_VRAM_MODULE_V3; ++ ++ ++//ATOM_VRAM_MODULE_V3.ucNPL_RT + #define NPL_RT_MASK 0x0f + #define BATTERY_ODT_MASK 0xc0 + + #define ATOM_VRAM_MODULE ATOM_VRAM_MODULE_V3 + +-typedef struct _ATOM_VRAM_MODULE_V4 { +- ULONG ulChannelMapCfg; /* board dependent parameter: Channel combination */ +- USHORT usModuleSize; /* size of ATOM_VRAM_MODULE_V4, make it easy for VBIOS to look for next entry of VRAM_MODULE */ +- USHORT usPrivateReserved; /* BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! */ +- /* MC_ARB_RAMCFG (includes NOOFBANK,NOOFRANKS,NOOFROWS,NOOFCOLS) */ +- USHORT usReserved; +- UCHAR ucExtMemoryID; /* An external indicator (by hardcode, callback or pin) to tell what is the current memory module */ +- UCHAR ucMemoryType; /* [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4; 0x5:DDR5 [3:0] - Must be 0x0 for now; */ +- UCHAR ucChannelNum; /* Number of channels present in this module config */ +- UCHAR ucChannelWidth; /* 0 - 32 bits; 1 - 64 bits */ +- UCHAR ucDensity; /* _8Mx32, _16Mx32, _16Mx16, _32Mx16 */ +- UCHAR ucFlag; /* To enable/disable functionalities based on memory type */ +- UCHAR ucMisc; /* bit0: 0 - single rank; 1 - dual rank; bit2: 0 - burstlength 4, 1 - burstlength 8 */ +- UCHAR ucVREFI; /* board dependent parameter */ +- UCHAR ucNPL_RT; /* board dependent parameter:NPL round trip delay, used for calculate memory timing parameters */ +- UCHAR ucPreamble; /* [7:4] Write Preamble, [3:0] Read Preamble */ +- UCHAR ucMemorySize; /* BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! */ +- /* Total memory size in unit of 16MB for CONFIG_MEMSIZE - bit[23:0] zeros */ +- UCHAR ucReserved[3]; +- +-/* compare with V3, we flat the struct by merging ATOM_MEMORY_FORMAT (as is) into V4 as the same level */ +- union { +- USHORT usEMRS2Value; /* EMRS2 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usDDR3_Reserved; +- }; +- union { +- USHORT usEMRS3Value; /* EMRS3 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usDDR3_MR3; /* Used for DDR3 memory */ +- }; +- UCHAR ucMemoryVenderID; /* Predefined, If not predefined, vendor detection table gets executed */ +- UCHAR ucRefreshRateFactor; /* [1:0]=RefreshFactor (00=8ms, 01=16ms, 10=32ms,11=64ms) */ +- UCHAR ucReserved2[2]; +- ATOM_MEMORY_TIMING_FORMAT asMemTiming[5]; /* Memory Timing block sort from lower clock to higher clock */ +-} ATOM_VRAM_MODULE_V4; ++typedef struct _ATOM_VRAM_MODULE_V4 ++{ ++ ULONG ulChannelMapCfg; // board dependent parameter: Channel combination ++ USHORT usModuleSize; // size of ATOM_VRAM_MODULE_V4, make it easy for VBIOS to look for next entry of VRAM_MODULE ++ USHORT usPrivateReserved; // BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! ++ // MC_ARB_RAMCFG (includes NOOFBANK,NOOFRANKS,NOOFROWS,NOOFCOLS) ++ USHORT usReserved; ++ UCHAR ucExtMemoryID; // An external indicator (by hardcode, callback or pin) to tell what is the current memory module ++ UCHAR ucMemoryType; // [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4; 0x5:DDR5 [3:0] - Must be 0x0 for now; ++ UCHAR ucChannelNum; // Number of channels present in this module config ++ UCHAR ucChannelWidth; // 0 - 32 bits; 1 - 64 bits ++ UCHAR ucDensity; // _8Mx32, _16Mx32, _16Mx16, _32Mx16 ++ UCHAR ucFlag; // To enable/disable functionalities based on memory type ++ UCHAR ucMisc; // bit0: 0 - single rank; 1 - dual rank; bit2: 0 - burstlength 4, 1 - burstlength 8 ++ UCHAR ucVREFI; // board dependent parameter ++ UCHAR ucNPL_RT; // board dependent parameter:NPL round trip delay, used for calculate memory timing parameters ++ UCHAR ucPreamble; // [7:4] Write Preamble, [3:0] Read Preamble ++ UCHAR ucMemorySize; // BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! ++ // Total memory size in unit of 16MB for CONFIG_MEMSIZE - bit[23:0] zeros ++ UCHAR ucReserved[3]; ++ ++//compare with V3, we flat the struct by merging ATOM_MEMORY_FORMAT (as is) into V4 as the same level ++ union{ ++ USHORT usEMRS2Value; // EMRS2 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usDDR3_Reserved; ++ }; ++ union{ ++ USHORT usEMRS3Value; // EMRS3 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usDDR3_MR3; // Used for DDR3 memory ++ }; ++ UCHAR ucMemoryVenderID; // Predefined, If not predefined, vendor detection table gets executed ++ UCHAR ucRefreshRateFactor; // [1:0]=RefreshFactor (00=8ms, 01=16ms, 10=32ms,11=64ms) ++ UCHAR ucReserved2[2]; ++ ATOM_MEMORY_TIMING_FORMAT asMemTiming[5];//Memory Timing block sort from lower clock to higher clock ++}ATOM_VRAM_MODULE_V4; + + #define VRAM_MODULE_V4_MISC_RANK_MASK 0x3 + #define VRAM_MODULE_V4_MISC_DUAL_RANK 0x1 +@@ -3973,96 +4841,139 @@ typedef struct _ATOM_VRAM_MODULE_V4 { + #define VRAM_MODULE_V4_MISC_BL8 0x4 + #define VRAM_MODULE_V4_MISC_DUAL_CS 0x10 + +-typedef struct _ATOM_VRAM_MODULE_V5 { +- ULONG ulChannelMapCfg; /* board dependent parameter: Channel combination */ +- USHORT usModuleSize; /* size of ATOM_VRAM_MODULE_V4, make it easy for VBIOS to look for next entry of VRAM_MODULE */ +- USHORT usPrivateReserved; /* BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! */ +- /* MC_ARB_RAMCFG (includes NOOFBANK,NOOFRANKS,NOOFROWS,NOOFCOLS) */ +- USHORT usReserved; +- UCHAR ucExtMemoryID; /* An external indicator (by hardcode, callback or pin) to tell what is the current memory module */ +- UCHAR ucMemoryType; /* [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4; 0x5:DDR5 [3:0] - Must be 0x0 for now; */ +- UCHAR ucChannelNum; /* Number of channels present in this module config */ +- UCHAR ucChannelWidth; /* 0 - 32 bits; 1 - 64 bits */ +- UCHAR ucDensity; /* _8Mx32, _16Mx32, _16Mx16, _32Mx16 */ +- UCHAR ucFlag; /* To enable/disable functionalities based on memory type */ +- UCHAR ucMisc; /* bit0: 0 - single rank; 1 - dual rank; bit2: 0 - burstlength 4, 1 - burstlength 8 */ +- UCHAR ucVREFI; /* board dependent parameter */ +- UCHAR ucNPL_RT; /* board dependent parameter:NPL round trip delay, used for calculate memory timing parameters */ +- UCHAR ucPreamble; /* [7:4] Write Preamble, [3:0] Read Preamble */ +- UCHAR ucMemorySize; /* BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! */ +- /* Total memory size in unit of 16MB for CONFIG_MEMSIZE - bit[23:0] zeros */ +- UCHAR ucReserved[3]; ++typedef struct _ATOM_VRAM_MODULE_V5 ++{ ++ ULONG ulChannelMapCfg; // board dependent parameter: Channel combination ++ USHORT usModuleSize; // size of ATOM_VRAM_MODULE_V4, make it easy for VBIOS to look for next entry of VRAM_MODULE ++ USHORT usPrivateReserved; // BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! ++ // MC_ARB_RAMCFG (includes NOOFBANK,NOOFRANKS,NOOFROWS,NOOFCOLS) ++ USHORT usReserved; ++ UCHAR ucExtMemoryID; // An external indicator (by hardcode, callback or pin) to tell what is the current memory module ++ UCHAR ucMemoryType; // [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4; 0x5:DDR5 [3:0] - Must be 0x0 for now; ++ UCHAR ucChannelNum; // Number of channels present in this module config ++ UCHAR ucChannelWidth; // 0 - 32 bits; 1 - 64 bits ++ UCHAR ucDensity; // _8Mx32, _16Mx32, _16Mx16, _32Mx16 ++ UCHAR ucFlag; // To enable/disable functionalities based on memory type ++ UCHAR ucMisc; // bit0: 0 - single rank; 1 - dual rank; bit2: 0 - burstlength 4, 1 - burstlength 8 ++ UCHAR ucVREFI; // board dependent parameter ++ UCHAR ucNPL_RT; // board dependent parameter:NPL round trip delay, used for calculate memory timing parameters ++ UCHAR ucPreamble; // [7:4] Write Preamble, [3:0] Read Preamble ++ UCHAR ucMemorySize; // BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! ++ // Total memory size in unit of 16MB for CONFIG_MEMSIZE - bit[23:0] zeros ++ UCHAR ucReserved[3]; ++ ++//compare with V3, we flat the struct by merging ATOM_MEMORY_FORMAT (as is) into V4 as the same level ++ USHORT usEMRS2Value; // EMRS2 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usEMRS3Value; // EMRS3 Value is used for GDDR2 and GDDR4 memory type ++ UCHAR ucMemoryVenderID; // Predefined, If not predefined, vendor detection table gets executed ++ UCHAR ucRefreshRateFactor; // [1:0]=RefreshFactor (00=8ms, 01=16ms, 10=32ms,11=64ms) ++ UCHAR ucFIFODepth; // FIFO depth supposes to be detected during vendor detection, but if we dont do vendor detection we have to hardcode FIFO Depth ++ UCHAR ucCDR_Bandwidth; // [0:3]=Read CDR bandwidth, [4:7] - Write CDR Bandwidth ++ ATOM_MEMORY_TIMING_FORMAT_V1 asMemTiming[5];//Memory Timing block sort from lower clock to higher clock ++}ATOM_VRAM_MODULE_V5; ++ ++typedef struct _ATOM_VRAM_MODULE_V6 ++{ ++ ULONG ulChannelMapCfg; // board dependent parameter: Channel combination ++ USHORT usModuleSize; // size of ATOM_VRAM_MODULE_V4, make it easy for VBIOS to look for next entry of VRAM_MODULE ++ USHORT usPrivateReserved; // BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! ++ // MC_ARB_RAMCFG (includes NOOFBANK,NOOFRANKS,NOOFROWS,NOOFCOLS) ++ USHORT usReserved; ++ UCHAR ucExtMemoryID; // An external indicator (by hardcode, callback or pin) to tell what is the current memory module ++ UCHAR ucMemoryType; // [7:4]=0x1:DDR1;=0x2:DDR2;=0x3:DDR3;=0x4:DDR4; 0x5:DDR5 [3:0] - Must be 0x0 for now; ++ UCHAR ucChannelNum; // Number of channels present in this module config ++ UCHAR ucChannelWidth; // 0 - 32 bits; 1 - 64 bits ++ UCHAR ucDensity; // _8Mx32, _16Mx32, _16Mx16, _32Mx16 ++ UCHAR ucFlag; // To enable/disable functionalities based on memory type ++ UCHAR ucMisc; // bit0: 0 - single rank; 1 - dual rank; bit2: 0 - burstlength 4, 1 - burstlength 8 ++ UCHAR ucVREFI; // board dependent parameter ++ UCHAR ucNPL_RT; // board dependent parameter:NPL round trip delay, used for calculate memory timing parameters ++ UCHAR ucPreamble; // [7:4] Write Preamble, [3:0] Read Preamble ++ UCHAR ucMemorySize; // BIOS internal reserved space to optimize code size, updated by the compiler, shouldn't be modified manually!! ++ // Total memory size in unit of 16MB for CONFIG_MEMSIZE - bit[23:0] zeros ++ UCHAR ucReserved[3]; ++ ++//compare with V3, we flat the struct by merging ATOM_MEMORY_FORMAT (as is) into V4 as the same level ++ USHORT usEMRS2Value; // EMRS2 Value is used for GDDR2 and GDDR4 memory type ++ USHORT usEMRS3Value; // EMRS3 Value is used for GDDR2 and GDDR4 memory type ++ UCHAR ucMemoryVenderID; // Predefined, If not predefined, vendor detection table gets executed ++ UCHAR ucRefreshRateFactor; // [1:0]=RefreshFactor (00=8ms, 01=16ms, 10=32ms,11=64ms) ++ UCHAR ucFIFODepth; // FIFO depth supposes to be detected during vendor detection, but if we dont do vendor detection we have to hardcode FIFO Depth ++ UCHAR ucCDR_Bandwidth; // [0:3]=Read CDR bandwidth, [4:7] - Write CDR Bandwidth ++ ATOM_MEMORY_TIMING_FORMAT_V2 asMemTiming[5];//Memory Timing block sort from lower clock to higher clock ++}ATOM_VRAM_MODULE_V6; ++ ++ ++ ++typedef struct _ATOM_VRAM_INFO_V2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucNumOfVRAMModule; ++ ATOM_VRAM_MODULE aVramInfo[ATOM_MAX_NUMBER_OF_VRAM_MODULE]; // just for allocation, real number of blocks is in ucNumOfVRAMModule; ++}ATOM_VRAM_INFO_V2; + +-/* compare with V3, we flat the struct by merging ATOM_MEMORY_FORMAT (as is) into V4 as the same level */ +- USHORT usEMRS2Value; /* EMRS2 Value is used for GDDR2 and GDDR4 memory type */ +- USHORT usEMRS3Value; /* EMRS3 Value is used for GDDR2 and GDDR4 memory type */ +- UCHAR ucMemoryVenderID; /* Predefined, If not predefined, vendor detection table gets executed */ +- UCHAR ucRefreshRateFactor; /* [1:0]=RefreshFactor (00=8ms, 01=16ms, 10=32ms,11=64ms) */ +- UCHAR ucFIFODepth; /* FIFO depth supposes to be detected during vendor detection, but if we dont do vendor detection we have to hardcode FIFO Depth */ +- UCHAR ucCDR_Bandwidth; /* [0:3]=Read CDR bandwidth, [4:7] - Write CDR Bandwidth */ +- ATOM_MEMORY_TIMING_FORMAT_V1 asMemTiming[5]; /* Memory Timing block sort from lower clock to higher clock */ +-} ATOM_VRAM_MODULE_V5; +- +-typedef struct _ATOM_VRAM_INFO_V2 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucNumOfVRAMModule; +- ATOM_VRAM_MODULE aVramInfo[ATOM_MAX_NUMBER_OF_VRAM_MODULE]; /* just for allocation, real number of blocks is in ucNumOfVRAMModule; */ +-} ATOM_VRAM_INFO_V2; +- +-typedef struct _ATOM_VRAM_INFO_V3 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usMemAdjustTblOffset; /* offset of ATOM_INIT_REG_BLOCK structure for memory vendor specific MC adjust setting */ +- USHORT usMemClkPatchTblOffset; /* offset of ATOM_INIT_REG_BLOCK structure for memory clock specific MC setting */ +- USHORT usRerseved; +- UCHAR aVID_PinsShift[9]; /* 8 bit strap maximum+terminator */ +- UCHAR ucNumOfVRAMModule; +- ATOM_VRAM_MODULE aVramInfo[ATOM_MAX_NUMBER_OF_VRAM_MODULE]; /* just for allocation, real number of blocks is in ucNumOfVRAMModule; */ +- ATOM_INIT_REG_BLOCK asMemPatch; /* for allocation */ +- /* ATOM_INIT_REG_BLOCK aMemAdjust; */ +-} ATOM_VRAM_INFO_V3; ++typedef struct _ATOM_VRAM_INFO_V3 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usMemAdjustTblOffset; // offset of ATOM_INIT_REG_BLOCK structure for memory vendor specific MC adjust setting ++ USHORT usMemClkPatchTblOffset; // offset of ATOM_INIT_REG_BLOCK structure for memory clock specific MC setting ++ USHORT usRerseved; ++ UCHAR aVID_PinsShift[9]; // 8 bit strap maximum+terminator ++ UCHAR ucNumOfVRAMModule; ++ ATOM_VRAM_MODULE aVramInfo[ATOM_MAX_NUMBER_OF_VRAM_MODULE]; // just for allocation, real number of blocks is in ucNumOfVRAMModule; ++ ATOM_INIT_REG_BLOCK asMemPatch; // for allocation ++ // ATOM_INIT_REG_BLOCK aMemAdjust; ++}ATOM_VRAM_INFO_V3; + + #define ATOM_VRAM_INFO_LAST ATOM_VRAM_INFO_V3 + +-typedef struct _ATOM_VRAM_INFO_V4 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usMemAdjustTblOffset; /* offset of ATOM_INIT_REG_BLOCK structure for memory vendor specific MC adjust setting */ +- USHORT usMemClkPatchTblOffset; /* offset of ATOM_INIT_REG_BLOCK structure for memory clock specific MC setting */ +- USHORT usRerseved; +- UCHAR ucMemDQ7_0ByteRemap; /* DQ line byte remap, =0: Memory Data line BYTE0, =1: BYTE1, =2: BYTE2, =3: BYTE3 */ +- ULONG ulMemDQ7_0BitRemap; /* each DQ line ( 7~0) use 3bits, like: DQ0=Bit[2:0], DQ1:[5:3], ... DQ7:[23:21] */ +- UCHAR ucReservde[4]; +- UCHAR ucNumOfVRAMModule; +- ATOM_VRAM_MODULE_V4 aVramInfo[ATOM_MAX_NUMBER_OF_VRAM_MODULE]; /* just for allocation, real number of blocks is in ucNumOfVRAMModule; */ +- ATOM_INIT_REG_BLOCK asMemPatch; /* for allocation */ +- /* ATOM_INIT_REG_BLOCK aMemAdjust; */ +-} ATOM_VRAM_INFO_V4; +- +-typedef struct _ATOM_VRAM_GPIO_DETECTION_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR aVID_PinsShift[9]; /* 8 bit strap maximum+terminator */ +-} ATOM_VRAM_GPIO_DETECTION_INFO; +- +-typedef struct _ATOM_MEMORY_TRAINING_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucTrainingLoop; +- UCHAR ucReserved[3]; +- ATOM_INIT_REG_BLOCK asMemTrainingSetting; +-} ATOM_MEMORY_TRAINING_INFO; +- +-typedef struct SW_I2C_CNTL_DATA_PARAMETERS { +- UCHAR ucControl; +- UCHAR ucData; +- UCHAR ucSatus; +- UCHAR ucTemp; ++typedef struct _ATOM_VRAM_INFO_V4 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usMemAdjustTblOffset; // offset of ATOM_INIT_REG_BLOCK structure for memory vendor specific MC adjust setting ++ USHORT usMemClkPatchTblOffset; // offset of ATOM_INIT_REG_BLOCK structure for memory clock specific MC setting ++ USHORT usRerseved; ++ UCHAR ucMemDQ7_0ByteRemap; // DQ line byte remap, =0: Memory Data line BYTE0, =1: BYTE1, =2: BYTE2, =3: BYTE3 ++ ULONG ulMemDQ7_0BitRemap; // each DQ line ( 7~0) use 3bits, like: DQ0=Bit[2:0], DQ1:[5:3], ... DQ7:[23:21] ++ UCHAR ucReservde[4]; ++ UCHAR ucNumOfVRAMModule; ++ ATOM_VRAM_MODULE_V4 aVramInfo[ATOM_MAX_NUMBER_OF_VRAM_MODULE]; // just for allocation, real number of blocks is in ucNumOfVRAMModule; ++ ATOM_INIT_REG_BLOCK asMemPatch; // for allocation ++ // ATOM_INIT_REG_BLOCK aMemAdjust; ++}ATOM_VRAM_INFO_V4; ++ ++typedef struct _ATOM_VRAM_GPIO_DETECTION_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR aVID_PinsShift[9]; //8 bit strap maximum+terminator ++}ATOM_VRAM_GPIO_DETECTION_INFO; ++ ++ ++typedef struct _ATOM_MEMORY_TRAINING_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucTrainingLoop; ++ UCHAR ucReserved[3]; ++ ATOM_INIT_REG_BLOCK asMemTrainingSetting; ++}ATOM_MEMORY_TRAINING_INFO; ++ ++ ++typedef struct SW_I2C_CNTL_DATA_PARAMETERS ++{ ++ UCHAR ucControl; ++ UCHAR ucData; ++ UCHAR ucSatus; ++ UCHAR ucTemp; + } SW_I2C_CNTL_DATA_PARAMETERS; + + #define SW_I2C_CNTL_DATA_PS_ALLOCATION SW_I2C_CNTL_DATA_PARAMETERS + +-typedef struct _SW_I2C_IO_DATA_PARAMETERS { +- USHORT GPIO_Info; +- UCHAR ucAct; +- UCHAR ucData; +-} SW_I2C_IO_DATA_PARAMETERS; ++typedef struct _SW_I2C_IO_DATA_PARAMETERS ++{ ++ USHORT GPIO_Info; ++ UCHAR ucAct; ++ UCHAR ucData; ++ } SW_I2C_IO_DATA_PARAMETERS; + + #define SW_I2C_IO_DATA_PS_ALLOCATION SW_I2C_IO_DATA_PARAMETERS + +@@ -4087,127 +4998,136 @@ typedef struct _SW_I2C_IO_DATA_PARAMETERS { + #define SW_I2C_CNTL_CLOSE 5 + #define SW_I2C_CNTL_WRITE1BIT 6 + +-/* ==============================VESA definition Portion=============================== */ ++//==============================VESA definition Portion=============================== + #define VESA_OEM_PRODUCT_REV '01.00' +-#define VESA_MODE_ATTRIBUTE_MODE_SUPPORT 0xBB /* refer to VBE spec p.32, no TTY support */ ++#define VESA_MODE_ATTRIBUTE_MODE_SUPPORT 0xBB //refer to VBE spec p.32, no TTY support + #define VESA_MODE_WIN_ATTRIBUTE 7 + #define VESA_WIN_SIZE 64 + +-typedef struct _PTR_32_BIT_STRUCTURE { +- USHORT Offset16; +- USHORT Segment16; ++typedef struct _PTR_32_BIT_STRUCTURE ++{ ++ USHORT Offset16; ++ USHORT Segment16; + } PTR_32_BIT_STRUCTURE; + +-typedef union _PTR_32_BIT_UNION { +- PTR_32_BIT_STRUCTURE SegmentOffset; +- ULONG Ptr32_Bit; ++typedef union _PTR_32_BIT_UNION ++{ ++ PTR_32_BIT_STRUCTURE SegmentOffset; ++ ULONG Ptr32_Bit; + } PTR_32_BIT_UNION; + +-typedef struct _VBE_1_2_INFO_BLOCK_UPDATABLE { +- UCHAR VbeSignature[4]; +- USHORT VbeVersion; +- PTR_32_BIT_UNION OemStringPtr; +- UCHAR Capabilities[4]; +- PTR_32_BIT_UNION VideoModePtr; +- USHORT TotalMemory; ++typedef struct _VBE_1_2_INFO_BLOCK_UPDATABLE ++{ ++ UCHAR VbeSignature[4]; ++ USHORT VbeVersion; ++ PTR_32_BIT_UNION OemStringPtr; ++ UCHAR Capabilities[4]; ++ PTR_32_BIT_UNION VideoModePtr; ++ USHORT TotalMemory; + } VBE_1_2_INFO_BLOCK_UPDATABLE; + +-typedef struct _VBE_2_0_INFO_BLOCK_UPDATABLE { +- VBE_1_2_INFO_BLOCK_UPDATABLE CommonBlock; +- USHORT OemSoftRev; +- PTR_32_BIT_UNION OemVendorNamePtr; +- PTR_32_BIT_UNION OemProductNamePtr; +- PTR_32_BIT_UNION OemProductRevPtr; ++ ++typedef struct _VBE_2_0_INFO_BLOCK_UPDATABLE ++{ ++ VBE_1_2_INFO_BLOCK_UPDATABLE CommonBlock; ++ USHORT OemSoftRev; ++ PTR_32_BIT_UNION OemVendorNamePtr; ++ PTR_32_BIT_UNION OemProductNamePtr; ++ PTR_32_BIT_UNION OemProductRevPtr; + } VBE_2_0_INFO_BLOCK_UPDATABLE; + +-typedef union _VBE_VERSION_UNION { +- VBE_2_0_INFO_BLOCK_UPDATABLE VBE_2_0_InfoBlock; +- VBE_1_2_INFO_BLOCK_UPDATABLE VBE_1_2_InfoBlock; ++typedef union _VBE_VERSION_UNION ++{ ++ VBE_2_0_INFO_BLOCK_UPDATABLE VBE_2_0_InfoBlock; ++ VBE_1_2_INFO_BLOCK_UPDATABLE VBE_1_2_InfoBlock; + } VBE_VERSION_UNION; + +-typedef struct _VBE_INFO_BLOCK { +- VBE_VERSION_UNION UpdatableVBE_Info; +- UCHAR Reserved[222]; +- UCHAR OemData[256]; ++typedef struct _VBE_INFO_BLOCK ++{ ++ VBE_VERSION_UNION UpdatableVBE_Info; ++ UCHAR Reserved[222]; ++ UCHAR OemData[256]; + } VBE_INFO_BLOCK; + +-typedef struct _VBE_FP_INFO { +- USHORT HSize; +- USHORT VSize; +- USHORT FPType; +- UCHAR RedBPP; +- UCHAR GreenBPP; +- UCHAR BlueBPP; +- UCHAR ReservedBPP; +- ULONG RsvdOffScrnMemSize; +- ULONG RsvdOffScrnMEmPtr; +- UCHAR Reserved[14]; ++typedef struct _VBE_FP_INFO ++{ ++ USHORT HSize; ++ USHORT VSize; ++ USHORT FPType; ++ UCHAR RedBPP; ++ UCHAR GreenBPP; ++ UCHAR BlueBPP; ++ UCHAR ReservedBPP; ++ ULONG RsvdOffScrnMemSize; ++ ULONG RsvdOffScrnMEmPtr; ++ UCHAR Reserved[14]; + } VBE_FP_INFO; + +-typedef struct _VESA_MODE_INFO_BLOCK { +-/* Mandatory information for all VBE revisions */ +- USHORT ModeAttributes; /* dw ? ; mode attributes */ +- UCHAR WinAAttributes; /* db ? ; window A attributes */ +- UCHAR WinBAttributes; /* db ? ; window B attributes */ +- USHORT WinGranularity; /* dw ? ; window granularity */ +- USHORT WinSize; /* dw ? ; window size */ +- USHORT WinASegment; /* dw ? ; window A start segment */ +- USHORT WinBSegment; /* dw ? ; window B start segment */ +- ULONG WinFuncPtr; /* dd ? ; real mode pointer to window function */ +- USHORT BytesPerScanLine; /* dw ? ; bytes per scan line */ +- +-/* ; Mandatory information for VBE 1.2 and above */ +- USHORT XResolution; /* dw ? ; horizontal resolution in pixels or characters */ +- USHORT YResolution; /* dw ? ; vertical resolution in pixels or characters */ +- UCHAR XCharSize; /* db ? ; character cell width in pixels */ +- UCHAR YCharSize; /* db ? ; character cell height in pixels */ +- UCHAR NumberOfPlanes; /* db ? ; number of memory planes */ +- UCHAR BitsPerPixel; /* db ? ; bits per pixel */ +- UCHAR NumberOfBanks; /* db ? ; number of banks */ +- UCHAR MemoryModel; /* db ? ; memory model type */ +- UCHAR BankSize; /* db ? ; bank size in KB */ +- UCHAR NumberOfImagePages; /* db ? ; number of images */ +- UCHAR ReservedForPageFunction; /* db 1 ; reserved for page function */ +- +-/* ; Direct Color fields(required for direct/6 and YUV/7 memory models) */ +- UCHAR RedMaskSize; /* db ? ; size of direct color red mask in bits */ +- UCHAR RedFieldPosition; /* db ? ; bit position of lsb of red mask */ +- UCHAR GreenMaskSize; /* db ? ; size of direct color green mask in bits */ +- UCHAR GreenFieldPosition; /* db ? ; bit position of lsb of green mask */ +- UCHAR BlueMaskSize; /* db ? ; size of direct color blue mask in bits */ +- UCHAR BlueFieldPosition; /* db ? ; bit position of lsb of blue mask */ +- UCHAR RsvdMaskSize; /* db ? ; size of direct color reserved mask in bits */ +- UCHAR RsvdFieldPosition; /* db ? ; bit position of lsb of reserved mask */ +- UCHAR DirectColorModeInfo; /* db ? ; direct color mode attributes */ +- +-/* ; Mandatory information for VBE 2.0 and above */ +- ULONG PhysBasePtr; /* dd ? ; physical address for flat memory frame buffer */ +- ULONG Reserved_1; /* dd 0 ; reserved - always set to 0 */ +- USHORT Reserved_2; /* dw 0 ; reserved - always set to 0 */ +- +-/* ; Mandatory information for VBE 3.0 and above */ +- USHORT LinBytesPerScanLine; /* dw ? ; bytes per scan line for linear modes */ +- UCHAR BnkNumberOfImagePages; /* db ? ; number of images for banked modes */ +- UCHAR LinNumberOfImagPages; /* db ? ; number of images for linear modes */ +- UCHAR LinRedMaskSize; /* db ? ; size of direct color red mask(linear modes) */ +- UCHAR LinRedFieldPosition; /* db ? ; bit position of lsb of red mask(linear modes) */ +- UCHAR LinGreenMaskSize; /* db ? ; size of direct color green mask(linear modes) */ +- UCHAR LinGreenFieldPosition; /* db ? ; bit position of lsb of green mask(linear modes) */ +- UCHAR LinBlueMaskSize; /* db ? ; size of direct color blue mask(linear modes) */ +- UCHAR LinBlueFieldPosition; /* db ? ; bit position of lsb of blue mask(linear modes) */ +- UCHAR LinRsvdMaskSize; /* db ? ; size of direct color reserved mask(linear modes) */ +- UCHAR LinRsvdFieldPosition; /* db ? ; bit position of lsb of reserved mask(linear modes) */ +- ULONG MaxPixelClock; /* dd ? ; maximum pixel clock(in Hz) for graphics mode */ +- UCHAR Reserved; /* db 190 dup (0) */ ++typedef struct _VESA_MODE_INFO_BLOCK ++{ ++// Mandatory information for all VBE revisions ++ USHORT ModeAttributes; // dw ? ; mode attributes ++ UCHAR WinAAttributes; // db ? ; window A attributes ++ UCHAR WinBAttributes; // db ? ; window B attributes ++ USHORT WinGranularity; // dw ? ; window granularity ++ USHORT WinSize; // dw ? ; window size ++ USHORT WinASegment; // dw ? ; window A start segment ++ USHORT WinBSegment; // dw ? ; window B start segment ++ ULONG WinFuncPtr; // dd ? ; real mode pointer to window function ++ USHORT BytesPerScanLine;// dw ? ; bytes per scan line ++ ++//; Mandatory information for VBE 1.2 and above ++ USHORT XResolution; // dw ? ; horizontal resolution in pixels or characters ++ USHORT YResolution; // dw ? ; vertical resolution in pixels or characters ++ UCHAR XCharSize; // db ? ; character cell width in pixels ++ UCHAR YCharSize; // db ? ; character cell height in pixels ++ UCHAR NumberOfPlanes; // db ? ; number of memory planes ++ UCHAR BitsPerPixel; // db ? ; bits per pixel ++ UCHAR NumberOfBanks; // db ? ; number of banks ++ UCHAR MemoryModel; // db ? ; memory model type ++ UCHAR BankSize; // db ? ; bank size in KB ++ UCHAR NumberOfImagePages;// db ? ; number of images ++ UCHAR ReservedForPageFunction;//db 1 ; reserved for page function ++ ++//; Direct Color fields(required for direct/6 and YUV/7 memory models) ++ UCHAR RedMaskSize; // db ? ; size of direct color red mask in bits ++ UCHAR RedFieldPosition; // db ? ; bit position of lsb of red mask ++ UCHAR GreenMaskSize; // db ? ; size of direct color green mask in bits ++ UCHAR GreenFieldPosition; // db ? ; bit position of lsb of green mask ++ UCHAR BlueMaskSize; // db ? ; size of direct color blue mask in bits ++ UCHAR BlueFieldPosition; // db ? ; bit position of lsb of blue mask ++ UCHAR RsvdMaskSize; // db ? ; size of direct color reserved mask in bits ++ UCHAR RsvdFieldPosition; // db ? ; bit position of lsb of reserved mask ++ UCHAR DirectColorModeInfo;// db ? ; direct color mode attributes ++ ++//; Mandatory information for VBE 2.0 and above ++ ULONG PhysBasePtr; // dd ? ; physical address for flat memory frame buffer ++ ULONG Reserved_1; // dd 0 ; reserved - always set to 0 ++ USHORT Reserved_2; // dw 0 ; reserved - always set to 0 ++ ++//; Mandatory information for VBE 3.0 and above ++ USHORT LinBytesPerScanLine; // dw ? ; bytes per scan line for linear modes ++ UCHAR BnkNumberOfImagePages;// db ? ; number of images for banked modes ++ UCHAR LinNumberOfImagPages; // db ? ; number of images for linear modes ++ UCHAR LinRedMaskSize; // db ? ; size of direct color red mask(linear modes) ++ UCHAR LinRedFieldPosition; // db ? ; bit position of lsb of red mask(linear modes) ++ UCHAR LinGreenMaskSize; // db ? ; size of direct color green mask(linear modes) ++ UCHAR LinGreenFieldPosition;// db ? ; bit position of lsb of green mask(linear modes) ++ UCHAR LinBlueMaskSize; // db ? ; size of direct color blue mask(linear modes) ++ UCHAR LinBlueFieldPosition; // db ? ; bit position of lsb of blue mask(linear modes) ++ UCHAR LinRsvdMaskSize; // db ? ; size of direct color reserved mask(linear modes) ++ UCHAR LinRsvdFieldPosition; // db ? ; bit position of lsb of reserved mask(linear modes) ++ ULONG MaxPixelClock; // dd ? ; maximum pixel clock(in Hz) for graphics mode ++ UCHAR Reserved; // db 190 dup (0) + } VESA_MODE_INFO_BLOCK; + +-/* BIOS function CALLS */ +-#define ATOM_BIOS_EXTENDED_FUNCTION_CODE 0xA0 /* ATI Extended Function code */ ++// BIOS function CALLS ++#define ATOM_BIOS_EXTENDED_FUNCTION_CODE 0xA0 // ATI Extended Function code + #define ATOM_BIOS_FUNCTION_COP_MODE 0x00 + #define ATOM_BIOS_FUNCTION_SHORT_QUERY1 0x04 + #define ATOM_BIOS_FUNCTION_SHORT_QUERY2 0x05 + #define ATOM_BIOS_FUNCTION_SHORT_QUERY3 0x06 +-#define ATOM_BIOS_FUNCTION_GET_DDC 0x0B ++#define ATOM_BIOS_FUNCTION_GET_DDC 0x0B + #define ATOM_BIOS_FUNCTION_ASIC_DSTATE 0x0E + #define ATOM_BIOS_FUNCTION_DEBUG_PLAY 0x0F + #define ATOM_BIOS_FUNCTION_STV_STD 0x16 +@@ -4217,100 +5137,135 @@ typedef struct _VESA_MODE_INFO_BLOCK { + #define ATOM_BIOS_FUNCTION_PANEL_CONTROL 0x82 + #define ATOM_BIOS_FUNCTION_OLD_DEVICE_DET 0x83 + #define ATOM_BIOS_FUNCTION_OLD_DEVICE_SWITCH 0x84 +-#define ATOM_BIOS_FUNCTION_HW_ICON 0x8A ++#define ATOM_BIOS_FUNCTION_HW_ICON 0x8A + #define ATOM_BIOS_FUNCTION_SET_CMOS 0x8B +-#define SUB_FUNCTION_UPDATE_DISPLAY_INFO 0x8000 /* Sub function 80 */ +-#define SUB_FUNCTION_UPDATE_EXPANSION_INFO 0x8100 /* Sub function 80 */ ++#define SUB_FUNCTION_UPDATE_DISPLAY_INFO 0x8000 // Sub function 80 ++#define SUB_FUNCTION_UPDATE_EXPANSION_INFO 0x8100 // Sub function 80 + + #define ATOM_BIOS_FUNCTION_DISPLAY_INFO 0x8D + #define ATOM_BIOS_FUNCTION_DEVICE_ON_OFF 0x8E +-#define ATOM_BIOS_FUNCTION_VIDEO_STATE 0x8F +-#define ATOM_SUB_FUNCTION_GET_CRITICAL_STATE 0x0300 /* Sub function 03 */ +-#define ATOM_SUB_FUNCTION_GET_LIDSTATE 0x0700 /* Sub function 7 */ +-#define ATOM_SUB_FUNCTION_THERMAL_STATE_NOTICE 0x1400 /* Notify caller the current thermal state */ +-#define ATOM_SUB_FUNCTION_CRITICAL_STATE_NOTICE 0x8300 /* Notify caller the current critical state */ +-#define ATOM_SUB_FUNCTION_SET_LIDSTATE 0x8500 /* Sub function 85 */ +-#define ATOM_SUB_FUNCTION_GET_REQ_DISPLAY_FROM_SBIOS_MODE 0x8900 /* Sub function 89 */ +-#define ATOM_SUB_FUNCTION_INFORM_ADC_SUPPORT 0x9400 /* Notify caller that ADC is supported */ +- +-#define ATOM_BIOS_FUNCTION_VESA_DPMS 0x4F10 /* Set DPMS */ +-#define ATOM_SUB_FUNCTION_SET_DPMS 0x0001 /* BL: Sub function 01 */ +-#define ATOM_SUB_FUNCTION_GET_DPMS 0x0002 /* BL: Sub function 02 */ +-#define ATOM_PARAMETER_VESA_DPMS_ON 0x0000 /* BH Parameter for DPMS ON. */ +-#define ATOM_PARAMETER_VESA_DPMS_STANDBY 0x0100 /* BH Parameter for DPMS STANDBY */ +-#define ATOM_PARAMETER_VESA_DPMS_SUSPEND 0x0200 /* BH Parameter for DPMS SUSPEND */ +-#define ATOM_PARAMETER_VESA_DPMS_OFF 0x0400 /* BH Parameter for DPMS OFF */ +-#define ATOM_PARAMETER_VESA_DPMS_REDUCE_ON 0x0800 /* BH Parameter for DPMS REDUCE ON (NOT SUPPORTED) */ ++#define ATOM_BIOS_FUNCTION_VIDEO_STATE 0x8F ++#define ATOM_SUB_FUNCTION_GET_CRITICAL_STATE 0x0300 // Sub function 03 ++#define ATOM_SUB_FUNCTION_GET_LIDSTATE 0x0700 // Sub function 7 ++#define ATOM_SUB_FUNCTION_THERMAL_STATE_NOTICE 0x1400 // Notify caller the current thermal state ++#define ATOM_SUB_FUNCTION_CRITICAL_STATE_NOTICE 0x8300 // Notify caller the current critical state ++#define ATOM_SUB_FUNCTION_SET_LIDSTATE 0x8500 // Sub function 85 ++#define ATOM_SUB_FUNCTION_GET_REQ_DISPLAY_FROM_SBIOS_MODE 0x8900// Sub function 89 ++#define ATOM_SUB_FUNCTION_INFORM_ADC_SUPPORT 0x9400 // Notify caller that ADC is supported ++ ++ ++#define ATOM_BIOS_FUNCTION_VESA_DPMS 0x4F10 // Set DPMS ++#define ATOM_SUB_FUNCTION_SET_DPMS 0x0001 // BL: Sub function 01 ++#define ATOM_SUB_FUNCTION_GET_DPMS 0x0002 // BL: Sub function 02 ++#define ATOM_PARAMETER_VESA_DPMS_ON 0x0000 // BH Parameter for DPMS ON. ++#define ATOM_PARAMETER_VESA_DPMS_STANDBY 0x0100 // BH Parameter for DPMS STANDBY ++#define ATOM_PARAMETER_VESA_DPMS_SUSPEND 0x0200 // BH Parameter for DPMS SUSPEND ++#define ATOM_PARAMETER_VESA_DPMS_OFF 0x0400 // BH Parameter for DPMS OFF ++#define ATOM_PARAMETER_VESA_DPMS_REDUCE_ON 0x0800 // BH Parameter for DPMS REDUCE ON (NOT SUPPORTED) + + #define ATOM_BIOS_RETURN_CODE_MASK 0x0000FF00L + #define ATOM_BIOS_REG_HIGH_MASK 0x0000FF00L + #define ATOM_BIOS_REG_LOW_MASK 0x000000FFL + +-/* structure used for VBIOS only */ ++// structure used for VBIOS only + +-/* DispOutInfoTable */ +-typedef struct _ASIC_TRANSMITTER_INFO { ++//DispOutInfoTable ++typedef struct _ASIC_TRANSMITTER_INFO ++{ + USHORT usTransmitterObjId; + USHORT usSupportDevice; +- UCHAR ucTransmitterCmdTblId; +- UCHAR ucConfig; +- UCHAR ucEncoderID; /* available 1st encoder ( default ) */ +- UCHAR ucOptionEncoderID; /* available 2nd encoder ( optional ) */ +- UCHAR uc2ndEncoderID; +- UCHAR ucReserved; +-} ASIC_TRANSMITTER_INFO; +- +-typedef struct _ASIC_ENCODER_INFO { ++ UCHAR ucTransmitterCmdTblId; ++ UCHAR ucConfig; ++ UCHAR ucEncoderID; //available 1st encoder ( default ) ++ UCHAR ucOptionEncoderID; //available 2nd encoder ( optional ) ++ UCHAR uc2ndEncoderID; ++ UCHAR ucReserved; ++}ASIC_TRANSMITTER_INFO; ++ ++typedef struct _ASIC_ENCODER_INFO ++{ + UCHAR ucEncoderID; + UCHAR ucEncoderConfig; +- USHORT usEncoderCmdTblId; +-} ASIC_ENCODER_INFO; ++ USHORT usEncoderCmdTblId; ++}ASIC_ENCODER_INFO; ++ ++typedef struct _ATOM_DISP_OUT_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT ptrTransmitterInfo; ++ USHORT ptrEncoderInfo; ++ ASIC_TRANSMITTER_INFO asTransmitterInfo[1]; ++ ASIC_ENCODER_INFO asEncoderInfo[1]; ++}ATOM_DISP_OUT_INFO; + +-typedef struct _ATOM_DISP_OUT_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; ++typedef struct _ATOM_DISP_OUT_INFO_V2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; + USHORT ptrTransmitterInfo; + USHORT ptrEncoderInfo; +- ASIC_TRANSMITTER_INFO asTransmitterInfo[1]; +- ASIC_ENCODER_INFO asEncoderInfo[1]; +-} ATOM_DISP_OUT_INFO; ++ USHORT ptrMainCallParserFar; // direct address of main parser call in VBIOS binary. ++ ASIC_TRANSMITTER_INFO asTransmitterInfo[1]; ++ ASIC_ENCODER_INFO asEncoderInfo[1]; ++}ATOM_DISP_OUT_INFO_V2; + +-/* DispDevicePriorityInfo */ +-typedef struct _ATOM_DISPLAY_DEVICE_PRIORITY_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; ++// DispDevicePriorityInfo ++typedef struct _ATOM_DISPLAY_DEVICE_PRIORITY_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; + USHORT asDevicePriority[16]; +-} ATOM_DISPLAY_DEVICE_PRIORITY_INFO; +- +-/* ProcessAuxChannelTransactionTable */ +-typedef struct _PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS { +- USHORT lpAuxRequest; +- USHORT lpDataOut; +- UCHAR ucChannelID; +- union { +- UCHAR ucReplyStatus; +- UCHAR ucDelay; ++}ATOM_DISPLAY_DEVICE_PRIORITY_INFO; ++ ++//ProcessAuxChannelTransactionTable ++typedef struct _PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS ++{ ++ USHORT lpAuxRequest; ++ USHORT lpDataOut; ++ UCHAR ucChannelID; ++ union ++ { ++ UCHAR ucReplyStatus; ++ UCHAR ucDelay; ++ }; ++ UCHAR ucDataOutLen; ++ UCHAR ucReserved; ++}PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS; ++ ++//ProcessAuxChannelTransactionTable ++typedef struct _PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS_V2 ++{ ++ USHORT lpAuxRequest; ++ USHORT lpDataOut; ++ UCHAR ucChannelID; ++ union ++ { ++ UCHAR ucReplyStatus; ++ UCHAR ucDelay; + }; +- UCHAR ucDataOutLen; +- UCHAR ucReserved; +-} PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS; ++ UCHAR ucDataOutLen; ++ UCHAR ucHPD_ID; //=0: HPD1, =1: HPD2, =2: HPD3, =3: HPD4, =4: HPD5, =5: HPD6 ++}PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS_V2; + + #define PROCESS_AUX_CHANNEL_TRANSACTION_PS_ALLOCATION PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS + +-/* GetSinkType */ ++//GetSinkType + +-typedef struct _DP_ENCODER_SERVICE_PARAMETERS { ++typedef struct _DP_ENCODER_SERVICE_PARAMETERS ++{ + USHORT ucLinkClock; +- union { +- UCHAR ucConfig; /* for DP training command */ +- UCHAR ucI2cId; /* use for GET_SINK_TYPE command */ ++ union ++ { ++ UCHAR ucConfig; // for DP training command ++ UCHAR ucI2cId; // use for GET_SINK_TYPE command + }; + UCHAR ucAction; + UCHAR ucStatus; + UCHAR ucLaneNum; + UCHAR ucReserved[2]; +-} DP_ENCODER_SERVICE_PARAMETERS; ++}DP_ENCODER_SERVICE_PARAMETERS; + +-/* ucAction */ ++// ucAction + #define ATOM_DP_ACTION_GET_SINK_TYPE 0x01 ++/* obselete */ + #define ATOM_DP_ACTION_TRAINING_START 0x02 + #define ATOM_DP_ACTION_TRAINING_COMPLETE 0x03 + #define ATOM_DP_ACTION_TRAINING_PATTERN_SEL 0x04 +@@ -4318,7 +5273,7 @@ typedef struct _DP_ENCODER_SERVICE_PARAMETERS { + #define ATOM_DP_ACTION_GET_VSWING_PREEMP 0x06 + #define ATOM_DP_ACTION_BLANKING 0x07 + +-/* ucConfig */ ++// ucConfig + #define ATOM_DP_CONFIG_ENCODER_SEL_MASK 0x03 + #define ATOM_DP_CONFIG_DIG1_ENCODER 0x00 + #define ATOM_DP_CONFIG_DIG2_ENCODER 0x01 +@@ -4326,14 +5281,14 @@ typedef struct _DP_ENCODER_SERVICE_PARAMETERS { + #define ATOM_DP_CONFIG_LINK_SEL_MASK 0x04 + #define ATOM_DP_CONFIG_LINK_A 0x00 + #define ATOM_DP_CONFIG_LINK_B 0x04 +- ++/* /obselete */ + #define DP_ENCODER_SERVICE_PS_ALLOCATION WRITE_ONE_BYTE_HW_I2C_DATA_PARAMETERS + +-/* DP_TRAINING_TABLE */ +-#define DPCD_SET_LINKRATE_LANENUM_PATTERN1_TBL_ADDR ATOM_DP_TRAINING_TBL_ADDR ++// DP_TRAINING_TABLE ++#define DPCD_SET_LINKRATE_LANENUM_PATTERN1_TBL_ADDR ATOM_DP_TRAINING_TBL_ADDR + #define DPCD_SET_SS_CNTL_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 8 ) +-#define DPCD_SET_LANE_VSWING_PREEMP_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 16) +-#define DPCD_SET_TRAINING_PATTERN0_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 24) ++#define DPCD_SET_LANE_VSWING_PREEMP_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 16 ) ++#define DPCD_SET_TRAINING_PATTERN0_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 24 ) + #define DPCD_SET_TRAINING_PATTERN2_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 32) + #define DPCD_GET_LINKRATE_LANENUM_SS_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 40) + #define DPCD_GET_LANE_STATUS_ADJUST_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 48) +@@ -4341,183 +5296,241 @@ typedef struct _DP_ENCODER_SERVICE_PARAMETERS { + #define DP_I2C_AUX_DDC_WRITE_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 64) + #define DP_I2C_AUX_DDC_READ_START_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 72) + #define DP_I2C_AUX_DDC_READ_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 76) +-#define DP_I2C_AUX_DDC_READ_END_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 80) ++#define DP_I2C_AUX_DDC_WRITE_END_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 80) ++#define DP_I2C_AUX_DDC_READ_END_TBL_ADDR (ATOM_DP_TRAINING_TBL_ADDR + 84) + +-typedef struct _PROCESS_I2C_CHANNEL_TRANSACTION_PARAMETERS { +- UCHAR ucI2CSpeed; +- union { +- UCHAR ucRegIndex; +- UCHAR ucStatus; ++typedef struct _PROCESS_I2C_CHANNEL_TRANSACTION_PARAMETERS ++{ ++ UCHAR ucI2CSpeed; ++ union ++ { ++ UCHAR ucRegIndex; ++ UCHAR ucStatus; + }; +- USHORT lpI2CDataOut; +- UCHAR ucFlag; +- UCHAR ucTransBytes; +- UCHAR ucSlaveAddr; +- UCHAR ucLineNumber; +-} PROCESS_I2C_CHANNEL_TRANSACTION_PARAMETERS; ++ USHORT lpI2CDataOut; ++ UCHAR ucFlag; ++ UCHAR ucTransBytes; ++ UCHAR ucSlaveAddr; ++ UCHAR ucLineNumber; ++}PROCESS_I2C_CHANNEL_TRANSACTION_PARAMETERS; + + #define PROCESS_I2C_CHANNEL_TRANSACTION_PS_ALLOCATION PROCESS_I2C_CHANNEL_TRANSACTION_PARAMETERS + +-/* ucFlag */ ++//ucFlag + #define HW_I2C_WRITE 1 + #define HW_I2C_READ 0 ++#define I2C_2BYTE_ADDR 0x02 + ++typedef struct _SET_HWBLOCK_INSTANCE_PARAMETER_V2 ++{ ++ UCHAR ucHWBlkInst; // HW block instance, 0, 1, 2, ... ++ UCHAR ucReserved[3]; ++}SET_HWBLOCK_INSTANCE_PARAMETER_V2; ++ ++#define HWBLKINST_INSTANCE_MASK 0x07 ++#define HWBLKINST_HWBLK_MASK 0xF0 ++#define HWBLKINST_HWBLK_SHIFT 0x04 ++ ++//ucHWBlock ++#define SELECT_DISP_ENGINE 0 ++#define SELECT_DISP_PLL 1 ++#define SELECT_DCIO_UNIPHY_LINK0 2 ++#define SELECT_DCIO_UNIPHY_LINK1 3 ++#define SELECT_DCIO_IMPCAL 4 ++#define SELECT_DCIO_DIG 6 ++#define SELECT_CRTC_PIXEL_RATE 7 ++ ++/****************************************************************************/ ++//Portion VI: Definitinos for vbios MC scratch registers that driver used + /****************************************************************************/ +-/* Portion VI: Definitinos being oboselete */ ++ ++#define MC_MISC0__MEMORY_TYPE_MASK 0xF0000000 ++#define MC_MISC0__MEMORY_TYPE__GDDR1 0x10000000 ++#define MC_MISC0__MEMORY_TYPE__DDR2 0x20000000 ++#define MC_MISC0__MEMORY_TYPE__GDDR3 0x30000000 ++#define MC_MISC0__MEMORY_TYPE__GDDR4 0x40000000 ++#define MC_MISC0__MEMORY_TYPE__GDDR5 0x50000000 ++#define MC_MISC0__MEMORY_TYPE__DDR3 0xB0000000 ++ ++/****************************************************************************/ ++//Portion VI: Definitinos being oboselete + /****************************************************************************/ + +-/* ========================================================================================== */ +-/* Remove the definitions below when driver is ready! */ +-typedef struct _ATOM_DAC_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usMaxFrequency; /* in 10kHz unit */ +- USHORT usReserved; +-} ATOM_DAC_INFO; +- +-typedef struct _COMPASSIONATE_DATA { +- ATOM_COMMON_TABLE_HEADER sHeader; +- +- /* ============================== DAC1 portion */ +- UCHAR ucDAC1_BG_Adjustment; +- UCHAR ucDAC1_DAC_Adjustment; +- USHORT usDAC1_FORCE_Data; +- /* ============================== DAC2 portion */ +- UCHAR ucDAC2_CRT2_BG_Adjustment; +- UCHAR ucDAC2_CRT2_DAC_Adjustment; +- USHORT usDAC2_CRT2_FORCE_Data; +- USHORT usDAC2_CRT2_MUX_RegisterIndex; +- UCHAR ucDAC2_CRT2_MUX_RegisterInfo; /* Bit[4:0]=Bit position,Bit[7]=1:Active High;=0 Active Low */ +- UCHAR ucDAC2_NTSC_BG_Adjustment; +- UCHAR ucDAC2_NTSC_DAC_Adjustment; +- USHORT usDAC2_TV1_FORCE_Data; +- USHORT usDAC2_TV1_MUX_RegisterIndex; +- UCHAR ucDAC2_TV1_MUX_RegisterInfo; /* Bit[4:0]=Bit position,Bit[7]=1:Active High;=0 Active Low */ +- UCHAR ucDAC2_CV_BG_Adjustment; +- UCHAR ucDAC2_CV_DAC_Adjustment; +- USHORT usDAC2_CV_FORCE_Data; +- USHORT usDAC2_CV_MUX_RegisterIndex; +- UCHAR ucDAC2_CV_MUX_RegisterInfo; /* Bit[4:0]=Bit position,Bit[7]=1:Active High;=0 Active Low */ +- UCHAR ucDAC2_PAL_BG_Adjustment; +- UCHAR ucDAC2_PAL_DAC_Adjustment; +- USHORT usDAC2_TV2_FORCE_Data; +-} COMPASSIONATE_DATA; ++//========================================================================================== ++//Remove the definitions below when driver is ready! ++typedef struct _ATOM_DAC_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usMaxFrequency; // in 10kHz unit ++ USHORT usReserved; ++}ATOM_DAC_INFO; ++ ++ ++typedef struct _COMPASSIONATE_DATA ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ ++ //============================== DAC1 portion ++ UCHAR ucDAC1_BG_Adjustment; ++ UCHAR ucDAC1_DAC_Adjustment; ++ USHORT usDAC1_FORCE_Data; ++ //============================== DAC2 portion ++ UCHAR ucDAC2_CRT2_BG_Adjustment; ++ UCHAR ucDAC2_CRT2_DAC_Adjustment; ++ USHORT usDAC2_CRT2_FORCE_Data; ++ USHORT usDAC2_CRT2_MUX_RegisterIndex; ++ UCHAR ucDAC2_CRT2_MUX_RegisterInfo; //Bit[4:0]=Bit position,Bit[7]=1:Active High;=0 Active Low ++ UCHAR ucDAC2_NTSC_BG_Adjustment; ++ UCHAR ucDAC2_NTSC_DAC_Adjustment; ++ USHORT usDAC2_TV1_FORCE_Data; ++ USHORT usDAC2_TV1_MUX_RegisterIndex; ++ UCHAR ucDAC2_TV1_MUX_RegisterInfo; //Bit[4:0]=Bit position,Bit[7]=1:Active High;=0 Active Low ++ UCHAR ucDAC2_CV_BG_Adjustment; ++ UCHAR ucDAC2_CV_DAC_Adjustment; ++ USHORT usDAC2_CV_FORCE_Data; ++ USHORT usDAC2_CV_MUX_RegisterIndex; ++ UCHAR ucDAC2_CV_MUX_RegisterInfo; //Bit[4:0]=Bit position,Bit[7]=1:Active High;=0 Active Low ++ UCHAR ucDAC2_PAL_BG_Adjustment; ++ UCHAR ucDAC2_PAL_DAC_Adjustment; ++ USHORT usDAC2_TV2_FORCE_Data; ++}COMPASSIONATE_DATA; + + /****************************Supported Device Info Table Definitions**********************/ +-/* ucConnectInfo: */ +-/* [7:4] - connector type */ +-/* = 1 - VGA connector */ +-/* = 2 - DVI-I */ +-/* = 3 - DVI-D */ +-/* = 4 - DVI-A */ +-/* = 5 - SVIDEO */ +-/* = 6 - COMPOSITE */ +-/* = 7 - LVDS */ +-/* = 8 - DIGITAL LINK */ +-/* = 9 - SCART */ +-/* = 0xA - HDMI_type A */ +-/* = 0xB - HDMI_type B */ +-/* = 0xE - Special case1 (DVI+DIN) */ +-/* Others=TBD */ +-/* [3:0] - DAC Associated */ +-/* = 0 - no DAC */ +-/* = 1 - DACA */ +-/* = 2 - DACB */ +-/* = 3 - External DAC */ +-/* Others=TBD */ +-/* */ +- +-typedef struct _ATOM_CONNECTOR_INFO { ++// ucConnectInfo: ++// [7:4] - connector type ++// = 1 - VGA connector ++// = 2 - DVI-I ++// = 3 - DVI-D ++// = 4 - DVI-A ++// = 5 - SVIDEO ++// = 6 - COMPOSITE ++// = 7 - LVDS ++// = 8 - DIGITAL LINK ++// = 9 - SCART ++// = 0xA - HDMI_type A ++// = 0xB - HDMI_type B ++// = 0xE - Special case1 (DVI+DIN) ++// Others=TBD ++// [3:0] - DAC Associated ++// = 0 - no DAC ++// = 1 - DACA ++// = 2 - DACB ++// = 3 - External DAC ++// Others=TBD ++// ++ ++typedef struct _ATOM_CONNECTOR_INFO ++{ + #if ATOM_BIG_ENDIAN +- UCHAR bfConnectorType:4; +- UCHAR bfAssociatedDAC:4; ++ UCHAR bfConnectorType:4; ++ UCHAR bfAssociatedDAC:4; + #else +- UCHAR bfAssociatedDAC:4; +- UCHAR bfConnectorType:4; ++ UCHAR bfAssociatedDAC:4; ++ UCHAR bfConnectorType:4; + #endif +-} ATOM_CONNECTOR_INFO; ++}ATOM_CONNECTOR_INFO; ++ ++typedef union _ATOM_CONNECTOR_INFO_ACCESS ++{ ++ ATOM_CONNECTOR_INFO sbfAccess; ++ UCHAR ucAccess; ++}ATOM_CONNECTOR_INFO_ACCESS; + +-typedef union _ATOM_CONNECTOR_INFO_ACCESS { +- ATOM_CONNECTOR_INFO sbfAccess; +- UCHAR ucAccess; +-} ATOM_CONNECTOR_INFO_ACCESS; ++typedef struct _ATOM_CONNECTOR_INFO_I2C ++{ ++ ATOM_CONNECTOR_INFO_ACCESS sucConnectorInfo; ++ ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; ++}ATOM_CONNECTOR_INFO_I2C; + +-typedef struct _ATOM_CONNECTOR_INFO_I2C { +- ATOM_CONNECTOR_INFO_ACCESS sucConnectorInfo; +- ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; +-} ATOM_CONNECTOR_INFO_I2C; + +-typedef struct _ATOM_SUPPORTED_DEVICES_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usDeviceSupport; +- ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO]; +-} ATOM_SUPPORTED_DEVICES_INFO; ++typedef struct _ATOM_SUPPORTED_DEVICES_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usDeviceSupport; ++ ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO]; ++}ATOM_SUPPORTED_DEVICES_INFO; + + #define NO_INT_SRC_MAPPED 0xFF + +-typedef struct _ATOM_CONNECTOR_INC_SRC_BITMAP { +- UCHAR ucIntSrcBitmap; +-} ATOM_CONNECTOR_INC_SRC_BITMAP; +- +-typedef struct _ATOM_SUPPORTED_DEVICES_INFO_2 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usDeviceSupport; +- ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO_2]; +- ATOM_CONNECTOR_INC_SRC_BITMAP +- asIntSrcInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO_2]; +-} ATOM_SUPPORTED_DEVICES_INFO_2; +- +-typedef struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usDeviceSupport; +- ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE]; +- ATOM_CONNECTOR_INC_SRC_BITMAP asIntSrcInfo[ATOM_MAX_SUPPORTED_DEVICE]; +-} ATOM_SUPPORTED_DEVICES_INFO_2d1; ++typedef struct _ATOM_CONNECTOR_INC_SRC_BITMAP ++{ ++ UCHAR ucIntSrcBitmap; ++}ATOM_CONNECTOR_INC_SRC_BITMAP; ++ ++typedef struct _ATOM_SUPPORTED_DEVICES_INFO_2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usDeviceSupport; ++ ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO_2]; ++ ATOM_CONNECTOR_INC_SRC_BITMAP asIntSrcInfo[ATOM_MAX_SUPPORTED_DEVICE_INFO_2]; ++}ATOM_SUPPORTED_DEVICES_INFO_2; ++ ++typedef struct _ATOM_SUPPORTED_DEVICES_INFO_2d1 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usDeviceSupport; ++ ATOM_CONNECTOR_INFO_I2C asConnInfo[ATOM_MAX_SUPPORTED_DEVICE]; ++ ATOM_CONNECTOR_INC_SRC_BITMAP asIntSrcInfo[ATOM_MAX_SUPPORTED_DEVICE]; ++}ATOM_SUPPORTED_DEVICES_INFO_2d1; + + #define ATOM_SUPPORTED_DEVICES_INFO_LAST ATOM_SUPPORTED_DEVICES_INFO_2d1 + +-typedef struct _ATOM_MISC_CONTROL_INFO { +- USHORT usFrequency; +- UCHAR ucPLL_ChargePump; /* PLL charge-pump gain control */ +- UCHAR ucPLL_DutyCycle; /* PLL duty cycle control */ +- UCHAR ucPLL_VCO_Gain; /* PLL VCO gain control */ +- UCHAR ucPLL_VoltageSwing; /* PLL driver voltage swing control */ +-} ATOM_MISC_CONTROL_INFO; ++ ++ ++typedef struct _ATOM_MISC_CONTROL_INFO ++{ ++ USHORT usFrequency; ++ UCHAR ucPLL_ChargePump; // PLL charge-pump gain control ++ UCHAR ucPLL_DutyCycle; // PLL duty cycle control ++ UCHAR ucPLL_VCO_Gain; // PLL VCO gain control ++ UCHAR ucPLL_VoltageSwing; // PLL driver voltage swing control ++}ATOM_MISC_CONTROL_INFO; ++ + + #define ATOM_MAX_MISC_INFO 4 + +-typedef struct _ATOM_TMDS_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usMaxFrequency; /* in 10Khz */ +- ATOM_MISC_CONTROL_INFO asMiscInfo[ATOM_MAX_MISC_INFO]; +-} ATOM_TMDS_INFO; ++typedef struct _ATOM_TMDS_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usMaxFrequency; // in 10Khz ++ ATOM_MISC_CONTROL_INFO asMiscInfo[ATOM_MAX_MISC_INFO]; ++}ATOM_TMDS_INFO; ++ ++ ++typedef struct _ATOM_ENCODER_ANALOG_ATTRIBUTE ++{ ++ UCHAR ucTVStandard; //Same as TV standards defined above, ++ UCHAR ucPadding[1]; ++}ATOM_ENCODER_ANALOG_ATTRIBUTE; + +-typedef struct _ATOM_ENCODER_ANALOG_ATTRIBUTE { +- UCHAR ucTVStandard; /* Same as TV standards defined above, */ +- UCHAR ucPadding[1]; +-} ATOM_ENCODER_ANALOG_ATTRIBUTE; ++typedef struct _ATOM_ENCODER_DIGITAL_ATTRIBUTE ++{ ++ UCHAR ucAttribute; //Same as other digital encoder attributes defined above ++ UCHAR ucPadding[1]; ++}ATOM_ENCODER_DIGITAL_ATTRIBUTE; + +-typedef struct _ATOM_ENCODER_DIGITAL_ATTRIBUTE { +- UCHAR ucAttribute; /* Same as other digital encoder attributes defined above */ +- UCHAR ucPadding[1]; +-} ATOM_ENCODER_DIGITAL_ATTRIBUTE; ++typedef union _ATOM_ENCODER_ATTRIBUTE ++{ ++ ATOM_ENCODER_ANALOG_ATTRIBUTE sAlgAttrib; ++ ATOM_ENCODER_DIGITAL_ATTRIBUTE sDigAttrib; ++}ATOM_ENCODER_ATTRIBUTE; + +-typedef union _ATOM_ENCODER_ATTRIBUTE { +- ATOM_ENCODER_ANALOG_ATTRIBUTE sAlgAttrib; +- ATOM_ENCODER_DIGITAL_ATTRIBUTE sDigAttrib; +-} ATOM_ENCODER_ATTRIBUTE; + +-typedef struct _DVO_ENCODER_CONTROL_PARAMETERS { +- USHORT usPixelClock; +- USHORT usEncoderID; +- UCHAR ucDeviceType; /* Use ATOM_DEVICE_xxx1_Index to indicate device type only. */ +- UCHAR ucAction; /* ATOM_ENABLE/ATOM_DISABLE/ATOM_HPD_INIT */ +- ATOM_ENCODER_ATTRIBUTE usDevAttr; +-} DVO_ENCODER_CONTROL_PARAMETERS; ++typedef struct _DVO_ENCODER_CONTROL_PARAMETERS ++{ ++ USHORT usPixelClock; ++ USHORT usEncoderID; ++ UCHAR ucDeviceType; //Use ATOM_DEVICE_xxx1_Index to indicate device type only. ++ UCHAR ucAction; //ATOM_ENABLE/ATOM_DISABLE/ATOM_HPD_INIT ++ ATOM_ENCODER_ATTRIBUTE usDevAttr; ++}DVO_ENCODER_CONTROL_PARAMETERS; ++ ++typedef struct _DVO_ENCODER_CONTROL_PS_ALLOCATION ++{ ++ DVO_ENCODER_CONTROL_PARAMETERS sDVOEncoder; ++ WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; //Caller doesn't need to init this portion ++}DVO_ENCODER_CONTROL_PS_ALLOCATION; + +-typedef struct _DVO_ENCODER_CONTROL_PS_ALLOCATION { +- DVO_ENCODER_CONTROL_PARAMETERS sDVOEncoder; +- WRITE_ONE_BYTE_HW_I2C_DATA_PS_ALLOCATION sReserved; /* Caller doesn't need to init this portion */ +-} DVO_ENCODER_CONTROL_PS_ALLOCATION; + + #define ATOM_XTMDS_ASIC_SI164_ID 1 + #define ATOM_XTMDS_ASIC_SI178_ID 2 +@@ -4526,27 +5539,30 @@ typedef struct _DVO_ENCODER_CONTROL_PS_ALLOCATION { + #define ATOM_XTMDS_SUPPORTED_DUALLINK 0x00000002 + #define ATOM_XTMDS_MVPU_FPGA 0x00000004 + +-typedef struct _ATOM_XTMDS_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- USHORT usSingleLinkMaxFrequency; +- ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; /* Point the ID on which I2C is used to control external chip */ +- UCHAR ucXtransimitterID; +- UCHAR ucSupportedLink; /* Bit field, bit0=1, single link supported;bit1=1,dual link supported */ +- UCHAR ucSequnceAlterID; /* Even with the same external TMDS asic, it's possible that the program seqence alters */ +- /* due to design. This ID is used to alert driver that the sequence is not "standard"! */ +- UCHAR ucMasterAddress; /* Address to control Master xTMDS Chip */ +- UCHAR ucSlaveAddress; /* Address to control Slave xTMDS Chip */ +-} ATOM_XTMDS_INFO; +- +-typedef struct _DFP_DPMS_STATUS_CHANGE_PARAMETERS { +- UCHAR ucEnable; /* ATOM_ENABLE=On or ATOM_DISABLE=Off */ +- UCHAR ucDevice; /* ATOM_DEVICE_DFP1_INDEX.... */ +- UCHAR ucPadding[2]; +-} DFP_DPMS_STATUS_CHANGE_PARAMETERS; ++ ++typedef struct _ATOM_XTMDS_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ USHORT usSingleLinkMaxFrequency; ++ ATOM_I2C_ID_CONFIG_ACCESS sucI2cId; //Point the ID on which I2C is used to control external chip ++ UCHAR ucXtransimitterID; ++ UCHAR ucSupportedLink; // Bit field, bit0=1, single link supported;bit1=1,dual link supported ++ UCHAR ucSequnceAlterID; // Even with the same external TMDS asic, it's possible that the program seqence alters ++ // due to design. This ID is used to alert driver that the sequence is not "standard"! ++ UCHAR ucMasterAddress; // Address to control Master xTMDS Chip ++ UCHAR ucSlaveAddress; // Address to control Slave xTMDS Chip ++}ATOM_XTMDS_INFO; ++ ++typedef struct _DFP_DPMS_STATUS_CHANGE_PARAMETERS ++{ ++ UCHAR ucEnable; // ATOM_ENABLE=On or ATOM_DISABLE=Off ++ UCHAR ucDevice; // ATOM_DEVICE_DFP1_INDEX.... ++ UCHAR ucPadding[2]; ++}DFP_DPMS_STATUS_CHANGE_PARAMETERS; + + /****************************Legacy Power Play Table Definitions **********************/ + +-/* Definitions for ulPowerPlayMiscInfo */ ++//Definitions for ulPowerPlayMiscInfo + #define ATOM_PM_MISCINFO_SPLIT_CLOCK 0x00000000L + #define ATOM_PM_MISCINFO_USING_MCLK_SRC 0x00000001L + #define ATOM_PM_MISCINFO_USING_SCLK_SRC 0x00000002L +@@ -4558,8 +5574,8 @@ typedef struct _DFP_DPMS_STATUS_CHANGE_PARAMETERS { + + #define ATOM_PM_MISCINFO_ENGINE_CLOCK_CONTRL_EN 0x00000020L + #define ATOM_PM_MISCINFO_MEMORY_CLOCK_CONTRL_EN 0x00000040L +-#define ATOM_PM_MISCINFO_PROGRAM_VOLTAGE 0x00000080L /* When this bit set, ucVoltageDropIndex is not an index for GPIO pin, but a voltage ID that SW needs program */ +- ++#define ATOM_PM_MISCINFO_PROGRAM_VOLTAGE 0x00000080L //When this bit set, ucVoltageDropIndex is not an index for GPIO pin, but a voltage ID that SW needs program ++ + #define ATOM_PM_MISCINFO_ASIC_REDUCED_SPEED_SCLK_EN 0x00000100L + #define ATOM_PM_MISCINFO_ASIC_DYNAMIC_VOLTAGE_EN 0x00000200L + #define ATOM_PM_MISCINFO_ASIC_SLEEP_MODE_EN 0x00000400L +@@ -4569,22 +5585,22 @@ typedef struct _DFP_DPMS_STATUS_CHANGE_PARAMETERS { + #define ATOM_PM_MISCINFO_LOW_LCD_REFRESH_RATE 0x00004000L + + #define ATOM_PM_MISCINFO_DRIVER_DEFAULT_MODE 0x00008000L +-#define ATOM_PM_MISCINFO_OVER_CLOCK_MODE 0x00010000L ++#define ATOM_PM_MISCINFO_OVER_CLOCK_MODE 0x00010000L + #define ATOM_PM_MISCINFO_OVER_DRIVE_MODE 0x00020000L + #define ATOM_PM_MISCINFO_POWER_SAVING_MODE 0x00040000L + #define ATOM_PM_MISCINFO_THERMAL_DIODE_MODE 0x00080000L + +-#define ATOM_PM_MISCINFO_FRAME_MODULATION_MASK 0x00300000L /* 0-FM Disable, 1-2 level FM, 2-4 level FM, 3-Reserved */ +-#define ATOM_PM_MISCINFO_FRAME_MODULATION_SHIFT 20 ++#define ATOM_PM_MISCINFO_FRAME_MODULATION_MASK 0x00300000L //0-FM Disable, 1-2 level FM, 2-4 level FM, 3-Reserved ++#define ATOM_PM_MISCINFO_FRAME_MODULATION_SHIFT 20 + + #define ATOM_PM_MISCINFO_DYN_CLK_3D_IDLE 0x00400000L + #define ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_2 0x00800000L + #define ATOM_PM_MISCINFO_DYNAMIC_CLOCK_DIVIDER_BY_4 0x01000000L +-#define ATOM_PM_MISCINFO_DYNAMIC_HDP_BLOCK_EN 0x02000000L /* When set, Dynamic */ +-#define ATOM_PM_MISCINFO_DYNAMIC_MC_HOST_BLOCK_EN 0x04000000L /* When set, Dynamic */ +-#define ATOM_PM_MISCINFO_3D_ACCELERATION_EN 0x08000000L /* When set, This mode is for acceleated 3D mode */ ++#define ATOM_PM_MISCINFO_DYNAMIC_HDP_BLOCK_EN 0x02000000L //When set, Dynamic ++#define ATOM_PM_MISCINFO_DYNAMIC_MC_HOST_BLOCK_EN 0x04000000L //When set, Dynamic ++#define ATOM_PM_MISCINFO_3D_ACCELERATION_EN 0x08000000L //When set, This mode is for acceleated 3D mode + +-#define ATOM_PM_MISCINFO_POWERPLAY_SETTINGS_GROUP_MASK 0x70000000L /* 1-Optimal Battery Life Group, 2-High Battery, 3-Balanced, 4-High Performance, 5- Optimal Performance (Default state with Default clocks) */ ++#define ATOM_PM_MISCINFO_POWERPLAY_SETTINGS_GROUP_MASK 0x70000000L //1-Optimal Battery Life Group, 2-High Battery, 3-Balanced, 4-High Performance, 5- Optimal Performance (Default state with Default clocks) + #define ATOM_PM_MISCINFO_POWERPLAY_SETTINGS_GROUP_SHIFT 28 + #define ATOM_PM_MISCINFO_ENABLE_BACK_BIAS 0x80000000L + +@@ -4594,55 +5610,59 @@ typedef struct _DFP_DPMS_STATUS_CHANGE_PARAMETERS { + #define ATOM_PM_MISCINFO2_FS3D_OVERDRIVE_INFO 0x00000008L + #define ATOM_PM_MISCINFO2_FORCEDLOWPWR_MODE 0x00000010L + #define ATOM_PM_MISCINFO2_VDDCI_DYNAMIC_VOLTAGE_EN 0x00000020L +-#define ATOM_PM_MISCINFO2_VIDEO_PLAYBACK_CAPABLE 0x00000040L /* If this bit is set in multi-pp mode, then driver will pack up one with the minior power consumption. */ +- /* If it's not set in any pp mode, driver will use its default logic to pick a pp mode in video playback */ ++#define ATOM_PM_MISCINFO2_VIDEO_PLAYBACK_CAPABLE 0x00000040L //If this bit is set in multi-pp mode, then driver will pack up one with the minior power consumption. ++ //If it's not set in any pp mode, driver will use its default logic to pick a pp mode in video playback + #define ATOM_PM_MISCINFO2_NOT_VALID_ON_DC 0x00000080L + #define ATOM_PM_MISCINFO2_STUTTER_MODE_EN 0x00000100L +-#define ATOM_PM_MISCINFO2_UVD_SUPPORT_MODE 0x00000200L +- +-/* ucTableFormatRevision=1 */ +-/* ucTableContentRevision=1 */ +-typedef struct _ATOM_POWERMODE_INFO { +- ULONG ulMiscInfo; /* The power level should be arranged in ascending order */ +- ULONG ulReserved1; /* must set to 0 */ +- ULONG ulReserved2; /* must set to 0 */ +- USHORT usEngineClock; +- USHORT usMemoryClock; +- UCHAR ucVoltageDropIndex; /* index to GPIO table */ +- UCHAR ucSelectedPanel_RefreshRate; /* panel refresh rate */ +- UCHAR ucMinTemperature; +- UCHAR ucMaxTemperature; +- UCHAR ucNumPciELanes; /* number of PCIE lanes */ +-} ATOM_POWERMODE_INFO; +- +-/* ucTableFormatRevision=2 */ +-/* ucTableContentRevision=1 */ +-typedef struct _ATOM_POWERMODE_INFO_V2 { +- ULONG ulMiscInfo; /* The power level should be arranged in ascending order */ +- ULONG ulMiscInfo2; +- ULONG ulEngineClock; +- ULONG ulMemoryClock; +- UCHAR ucVoltageDropIndex; /* index to GPIO table */ +- UCHAR ucSelectedPanel_RefreshRate; /* panel refresh rate */ +- UCHAR ucMinTemperature; +- UCHAR ucMaxTemperature; +- UCHAR ucNumPciELanes; /* number of PCIE lanes */ +-} ATOM_POWERMODE_INFO_V2; +- +-/* ucTableFormatRevision=2 */ +-/* ucTableContentRevision=2 */ +-typedef struct _ATOM_POWERMODE_INFO_V3 { +- ULONG ulMiscInfo; /* The power level should be arranged in ascending order */ +- ULONG ulMiscInfo2; +- ULONG ulEngineClock; +- ULONG ulMemoryClock; +- UCHAR ucVoltageDropIndex; /* index to Core (VDDC) votage table */ +- UCHAR ucSelectedPanel_RefreshRate; /* panel refresh rate */ +- UCHAR ucMinTemperature; +- UCHAR ucMaxTemperature; +- UCHAR ucNumPciELanes; /* number of PCIE lanes */ +- UCHAR ucVDDCI_VoltageDropIndex; /* index to VDDCI votage table */ +-} ATOM_POWERMODE_INFO_V3; ++#define ATOM_PM_MISCINFO2_UVD_SUPPORT_MODE 0x00000200L ++ ++//ucTableFormatRevision=1 ++//ucTableContentRevision=1 ++typedef struct _ATOM_POWERMODE_INFO ++{ ++ ULONG ulMiscInfo; //The power level should be arranged in ascending order ++ ULONG ulReserved1; // must set to 0 ++ ULONG ulReserved2; // must set to 0 ++ USHORT usEngineClock; ++ USHORT usMemoryClock; ++ UCHAR ucVoltageDropIndex; // index to GPIO table ++ UCHAR ucSelectedPanel_RefreshRate;// panel refresh rate ++ UCHAR ucMinTemperature; ++ UCHAR ucMaxTemperature; ++ UCHAR ucNumPciELanes; // number of PCIE lanes ++}ATOM_POWERMODE_INFO; ++ ++//ucTableFormatRevision=2 ++//ucTableContentRevision=1 ++typedef struct _ATOM_POWERMODE_INFO_V2 ++{ ++ ULONG ulMiscInfo; //The power level should be arranged in ascending order ++ ULONG ulMiscInfo2; ++ ULONG ulEngineClock; ++ ULONG ulMemoryClock; ++ UCHAR ucVoltageDropIndex; // index to GPIO table ++ UCHAR ucSelectedPanel_RefreshRate;// panel refresh rate ++ UCHAR ucMinTemperature; ++ UCHAR ucMaxTemperature; ++ UCHAR ucNumPciELanes; // number of PCIE lanes ++}ATOM_POWERMODE_INFO_V2; ++ ++//ucTableFormatRevision=2 ++//ucTableContentRevision=2 ++typedef struct _ATOM_POWERMODE_INFO_V3 ++{ ++ ULONG ulMiscInfo; //The power level should be arranged in ascending order ++ ULONG ulMiscInfo2; ++ ULONG ulEngineClock; ++ ULONG ulMemoryClock; ++ UCHAR ucVoltageDropIndex; // index to Core (VDDC) votage table ++ UCHAR ucSelectedPanel_RefreshRate;// panel refresh rate ++ UCHAR ucMinTemperature; ++ UCHAR ucMaxTemperature; ++ UCHAR ucNumPciELanes; // number of PCIE lanes ++ UCHAR ucVDDCI_VoltageDropIndex; // index to VDDCI votage table ++}ATOM_POWERMODE_INFO_V3; ++ + + #define ATOM_MAX_NUMBEROF_POWER_BLOCK 8 + +@@ -4655,40 +5675,44 @@ typedef struct _ATOM_POWERMODE_INFO_V3 { + #define ATOM_PP_OVERDRIVE_THERMALCONTROLLER_MUA6649 0x04 + #define ATOM_PP_OVERDRIVE_THERMALCONTROLLER_LM64 0x05 + #define ATOM_PP_OVERDRIVE_THERMALCONTROLLER_F75375 0x06 +-#define ATOM_PP_OVERDRIVE_THERMALCONTROLLER_ASC7512 0x07 /* Andigilog */ +- +-typedef struct _ATOM_POWERPLAY_INFO { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucOverdriveThermalController; +- UCHAR ucOverdriveI2cLine; +- UCHAR ucOverdriveIntBitmap; +- UCHAR ucOverdriveControllerAddress; +- UCHAR ucSizeOfPowerModeEntry; +- UCHAR ucNumOfPowerModeEntries; +- ATOM_POWERMODE_INFO asPowerPlayInfo[ATOM_MAX_NUMBEROF_POWER_BLOCK]; +-} ATOM_POWERPLAY_INFO; +- +-typedef struct _ATOM_POWERPLAY_INFO_V2 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucOverdriveThermalController; +- UCHAR ucOverdriveI2cLine; +- UCHAR ucOverdriveIntBitmap; +- UCHAR ucOverdriveControllerAddress; +- UCHAR ucSizeOfPowerModeEntry; +- UCHAR ucNumOfPowerModeEntries; +- ATOM_POWERMODE_INFO_V2 asPowerPlayInfo[ATOM_MAX_NUMBEROF_POWER_BLOCK]; +-} ATOM_POWERPLAY_INFO_V2; +- +-typedef struct _ATOM_POWERPLAY_INFO_V3 { +- ATOM_COMMON_TABLE_HEADER sHeader; +- UCHAR ucOverdriveThermalController; +- UCHAR ucOverdriveI2cLine; +- UCHAR ucOverdriveIntBitmap; +- UCHAR ucOverdriveControllerAddress; +- UCHAR ucSizeOfPowerModeEntry; +- UCHAR ucNumOfPowerModeEntries; +- ATOM_POWERMODE_INFO_V3 asPowerPlayInfo[ATOM_MAX_NUMBEROF_POWER_BLOCK]; +-} ATOM_POWERPLAY_INFO_V3; ++#define ATOM_PP_OVERDRIVE_THERMALCONTROLLER_ASC7512 0x07 // Andigilog ++ ++ ++typedef struct _ATOM_POWERPLAY_INFO ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucOverdriveThermalController; ++ UCHAR ucOverdriveI2cLine; ++ UCHAR ucOverdriveIntBitmap; ++ UCHAR ucOverdriveControllerAddress; ++ UCHAR ucSizeOfPowerModeEntry; ++ UCHAR ucNumOfPowerModeEntries; ++ ATOM_POWERMODE_INFO asPowerPlayInfo[ATOM_MAX_NUMBEROF_POWER_BLOCK]; ++}ATOM_POWERPLAY_INFO; ++ ++typedef struct _ATOM_POWERPLAY_INFO_V2 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucOverdriveThermalController; ++ UCHAR ucOverdriveI2cLine; ++ UCHAR ucOverdriveIntBitmap; ++ UCHAR ucOverdriveControllerAddress; ++ UCHAR ucSizeOfPowerModeEntry; ++ UCHAR ucNumOfPowerModeEntries; ++ ATOM_POWERMODE_INFO_V2 asPowerPlayInfo[ATOM_MAX_NUMBEROF_POWER_BLOCK]; ++}ATOM_POWERPLAY_INFO_V2; ++ ++typedef struct _ATOM_POWERPLAY_INFO_V3 ++{ ++ ATOM_COMMON_TABLE_HEADER sHeader; ++ UCHAR ucOverdriveThermalController; ++ UCHAR ucOverdriveI2cLine; ++ UCHAR ucOverdriveIntBitmap; ++ UCHAR ucOverdriveControllerAddress; ++ UCHAR ucSizeOfPowerModeEntry; ++ UCHAR ucNumOfPowerModeEntries; ++ ATOM_POWERMODE_INFO_V3 asPowerPlayInfo[ATOM_MAX_NUMBEROF_POWER_BLOCK]; ++}ATOM_POWERPLAY_INFO_V3; + + /* New PPlib */ + /**************************************************************************/ +@@ -4873,40 +5897,42 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO + UCHAR ucMaxHTLinkWidth; // From SBIOS - {2, 4, 8, 16} + UCHAR ucMinHTLinkWidth; // From SBIOS - {2, 4, 8, 16}. Effective only if CDLW enabled. Minimum down stream width could be bigger as display BW requriement. + USHORT usHTLinkFreq; // See definition ATOM_PPLIB_RS780_HTLINKFREQ_xxx or in MHz(>=200). +- ULONG ulFlags; ++ ULONG ulFlags; + } ATOM_PPLIB_RS780_CLOCK_INFO; + +-#define ATOM_PPLIB_RS780_VOLTAGE_NONE 0 +-#define ATOM_PPLIB_RS780_VOLTAGE_LOW 1 +-#define ATOM_PPLIB_RS780_VOLTAGE_HIGH 2 +-#define ATOM_PPLIB_RS780_VOLTAGE_VARIABLE 3 ++#define ATOM_PPLIB_RS780_VOLTAGE_NONE 0 ++#define ATOM_PPLIB_RS780_VOLTAGE_LOW 1 ++#define ATOM_PPLIB_RS780_VOLTAGE_HIGH 2 ++#define ATOM_PPLIB_RS780_VOLTAGE_VARIABLE 3 + + #define ATOM_PPLIB_RS780_SPMCLK_NONE 0 // We cannot change the side port memory clock, leave it as it is. + #define ATOM_PPLIB_RS780_SPMCLK_LOW 1 + #define ATOM_PPLIB_RS780_SPMCLK_HIGH 2 + +-#define ATOM_PPLIB_RS780_HTLINKFREQ_NONE 0 +-#define ATOM_PPLIB_RS780_HTLINKFREQ_LOW 1 +-#define ATOM_PPLIB_RS780_HTLINKFREQ_HIGH 2 ++#define ATOM_PPLIB_RS780_HTLINKFREQ_NONE 0 ++#define ATOM_PPLIB_RS780_HTLINKFREQ_LOW 1 ++#define ATOM_PPLIB_RS780_HTLINKFREQ_HIGH 2 + + /**************************************************************************/ + +-/* Following definitions are for compatiblity issue in different SW components. */ ++ ++// Following definitions are for compatiblity issue in different SW components. + #define ATOM_MASTER_DATA_TABLE_REVISION 0x01 +-#define Object_Info Object_Header ++#define Object_Info Object_Header + #define AdjustARB_SEQ MC_InitParameter + #define VRAM_GPIO_DetectionInfo VoltageObjectInfo +-#define ASIC_VDDCI_Info ASIC_ProfilingInfo ++#define ASIC_VDDCI_Info ASIC_ProfilingInfo + #define ASIC_MVDDQ_Info MemoryTrainingInfo +-#define SS_Info PPLL_SS_Info ++#define SS_Info PPLL_SS_Info + #define ASIC_MVDDC_Info ASIC_InternalSS_Info + #define DispDevicePriorityInfo SaveRestoreInfo + #define DispOutInfo TV_VideoMode + ++ + #define ATOM_ENCODER_OBJECT_TABLE ATOM_OBJECT_TABLE + #define ATOM_CONNECTOR_OBJECT_TABLE ATOM_OBJECT_TABLE + +-/* New device naming, remove them when both DAL/VBIOS is ready */ ++//New device naming, remove them when both DAL/VBIOS is ready + #define DFP2I_OUTPUT_CONTROL_PARAMETERS CRT1_OUTPUT_CONTROL_PARAMETERS + #define DFP2I_OUTPUT_CONTROL_PS_ALLOCATION DFP2I_OUTPUT_CONTROL_PARAMETERS + +@@ -4921,7 +5947,7 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO + + #define ATOM_DEVICE_DFP1I_INDEX ATOM_DEVICE_DFP1_INDEX + #define ATOM_DEVICE_DFP1X_INDEX ATOM_DEVICE_DFP2_INDEX +- ++ + #define ATOM_DEVICE_DFP2I_INDEX 0x00000009 + #define ATOM_DEVICE_DFP2I_SUPPORT (0x1L << ATOM_DEVICE_DFP2I_INDEX) + +@@ -4939,7 +5965,7 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO + + #define ATOM_S3_DFP2I_ACTIVEb1 0x02 + +-#define ATOM_S3_DFP1I_ACTIVE ATOM_S3_DFP1_ACTIVE ++#define ATOM_S3_DFP1I_ACTIVE ATOM_S3_DFP1_ACTIVE + #define ATOM_S3_DFP1X_ACTIVE ATOM_S3_DFP2_ACTIVE + + #define ATOM_S3_DFP2I_ACTIVE 0x00000200L +@@ -4958,14 +5984,14 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO + #define ATOM_S6_ACC_REQ_DFP2Ib3 0x02 + #define ATOM_S6_ACC_REQ_DFP2I 0x02000000L + +-#define TMDS1XEncoderControl DVOEncoderControl ++#define TMDS1XEncoderControl DVOEncoderControl + #define DFP1XOutputControl DVOOutputControl + + #define ExternalDFPOutputControl DFP1XOutputControl + #define EnableExternalTMDS_Encoder TMDS1XEncoderControl + + #define DFP1IOutputControl TMDSAOutputControl +-#define DFP2IOutputControl LVTMAOutputControl ++#define DFP2IOutputControl LVTMAOutputControl + + #define DAC1_ENCODER_CONTROL_PARAMETERS DAC_ENCODER_CONTROL_PARAMETERS + #define DAC1_ENCODER_CONTROL_PS_ALLOCATION DAC_ENCODER_CONTROL_PS_ALLOCATION +@@ -4974,7 +6000,7 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO + #define DAC2_ENCODER_CONTROL_PS_ALLOCATION DAC_ENCODER_CONTROL_PS_ALLOCATION + + #define ucDac1Standard ucDacStandard +-#define ucDac2Standard ucDacStandard ++#define ucDac2Standard ucDacStandard + + #define TMDS1EncoderControl TMDSAEncoderControl + #define TMDS2EncoderControl LVTMAEncoderControl +@@ -4984,12 +6010,56 @@ typedef struct _ATOM_PPLIB_RS780_CLOCK_INFO + #define CRT1OutputControl DAC1OutputControl + #define CRT2OutputControl DAC2OutputControl + +-/* These two lines will be removed for sure in a few days, will follow up with Michael V. */ ++//These two lines will be removed for sure in a few days, will follow up with Michael V. + #define EnableLVDS_SS EnableSpreadSpectrumOnPPLL +-#define ENABLE_LVDS_SS_PARAMETERS_V3 ENABLE_SPREAD_SPECTRUM_ON_PPLL ++#define ENABLE_LVDS_SS_PARAMETERS_V3 ENABLE_SPREAD_SPECTRUM_ON_PPLL ++ ++//#define ATOM_S2_CRT1_DPMS_STATE 0x00010000L ++//#define ATOM_S2_LCD1_DPMS_STATE ATOM_S2_CRT1_DPMS_STATE ++//#define ATOM_S2_TV1_DPMS_STATE ATOM_S2_CRT1_DPMS_STATE ++//#define ATOM_S2_DFP1_DPMS_STATE ATOM_S2_CRT1_DPMS_STATE ++//#define ATOM_S2_CRT2_DPMS_STATE ATOM_S2_CRT1_DPMS_STATE ++ ++#define ATOM_S6_ACC_REQ_TV2 0x00400000L ++#define ATOM_DEVICE_TV2_INDEX 0x00000006 ++#define ATOM_DEVICE_TV2_SUPPORT (0x1L << ATOM_DEVICE_TV2_INDEX) ++#define ATOM_S0_TV2 0x00100000L ++#define ATOM_S3_TV2_ACTIVE ATOM_S3_DFP6_ACTIVE ++#define ATOM_S3_TV2_CRTC_ACTIVE ATOM_S3_DFP6_CRTC_ACTIVE ++ ++// ++#define ATOM_S2_CRT1_DPMS_STATE 0x00010000L ++#define ATOM_S2_LCD1_DPMS_STATE 0x00020000L ++#define ATOM_S2_TV1_DPMS_STATE 0x00040000L ++#define ATOM_S2_DFP1_DPMS_STATE 0x00080000L ++#define ATOM_S2_CRT2_DPMS_STATE 0x00100000L ++#define ATOM_S2_LCD2_DPMS_STATE 0x00200000L ++#define ATOM_S2_TV2_DPMS_STATE 0x00400000L ++#define ATOM_S2_DFP2_DPMS_STATE 0x00800000L ++#define ATOM_S2_CV_DPMS_STATE 0x01000000L ++#define ATOM_S2_DFP3_DPMS_STATE 0x02000000L ++#define ATOM_S2_DFP4_DPMS_STATE 0x04000000L ++#define ATOM_S2_DFP5_DPMS_STATE 0x08000000L ++ ++#define ATOM_S2_CRT1_DPMS_STATEb2 0x01 ++#define ATOM_S2_LCD1_DPMS_STATEb2 0x02 ++#define ATOM_S2_TV1_DPMS_STATEb2 0x04 ++#define ATOM_S2_DFP1_DPMS_STATEb2 0x08 ++#define ATOM_S2_CRT2_DPMS_STATEb2 0x10 ++#define ATOM_S2_LCD2_DPMS_STATEb2 0x20 ++#define ATOM_S2_TV2_DPMS_STATEb2 0x40 ++#define ATOM_S2_DFP2_DPMS_STATEb2 0x80 ++#define ATOM_S2_CV_DPMS_STATEb3 0x01 ++#define ATOM_S2_DFP3_DPMS_STATEb3 0x02 ++#define ATOM_S2_DFP4_DPMS_STATEb3 0x04 ++#define ATOM_S2_DFP5_DPMS_STATEb3 0x08 ++ ++#define ATOM_S3_ASIC_GUI_ENGINE_HUNGb3 0x20 ++#define ATOM_S3_ALLOW_FAST_PWR_SWITCHb3 0x40 ++#define ATOM_S3_RQST_GPU_USE_MIN_PWRb3 0x80 + + /*********************************************************************************/ + +-#pragma pack() /* BIOS data must use byte aligment */ ++#pragma pack() // BIOS data must use byte aligment + + #endif /* _ATOMBIOS_H */ +diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c +index af464e3..c076eac 100644 +--- a/drivers/gpu/drm/radeon/atombios_crtc.c ++++ b/drivers/gpu/drm/radeon/atombios_crtc.c +@@ -245,21 +245,25 @@ void atombios_crtc_dpms(struct drm_crtc *crtc, int mode) + + switch (mode) { + case DRM_MODE_DPMS_ON: +- atombios_enable_crtc(crtc, 1); ++ atombios_enable_crtc(crtc, ATOM_ENABLE); + if (ASIC_IS_DCE3(rdev)) +- atombios_enable_crtc_memreq(crtc, 1); +- atombios_blank_crtc(crtc, 0); +- drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); ++ atombios_enable_crtc_memreq(crtc, ATOM_ENABLE); ++ atombios_blank_crtc(crtc, ATOM_DISABLE); ++ /* XXX re-enable when interrupt support is added */ ++ if (!ASIC_IS_DCE4(rdev)) ++ drm_vblank_post_modeset(dev, radeon_crtc->crtc_id); + radeon_crtc_load_lut(crtc); + break; + case DRM_MODE_DPMS_STANDBY: + case DRM_MODE_DPMS_SUSPEND: + case DRM_MODE_DPMS_OFF: +- drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); +- atombios_blank_crtc(crtc, 1); ++ /* XXX re-enable when interrupt support is added */ ++ if (!ASIC_IS_DCE4(rdev)) ++ drm_vblank_pre_modeset(dev, radeon_crtc->crtc_id); ++ atombios_blank_crtc(crtc, ATOM_ENABLE); + if (ASIC_IS_DCE3(rdev)) +- atombios_enable_crtc_memreq(crtc, 0); +- atombios_enable_crtc(crtc, 0); ++ atombios_enable_crtc_memreq(crtc, ATOM_DISABLE); ++ atombios_enable_crtc(crtc, ATOM_DISABLE); + break; + } + } +@@ -363,6 +367,10 @@ static void atombios_set_ss(struct drm_crtc *crtc, int enable) + uint16_t percentage = 0; + uint8_t type = 0, step = 0, delay = 0, range = 0; + ++ /* XXX add ss support for DCE4 */ ++ if (ASIC_IS_DCE4(rdev)) ++ return; ++ + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + if (encoder->crtc == crtc) { + radeon_encoder = to_radeon_encoder(encoder); +@@ -409,6 +417,7 @@ static void atombios_set_ss(struct drm_crtc *crtc, int enable) + + union adjust_pixel_clock { + ADJUST_DISPLAY_PLL_PS_ALLOCATION v1; ++ ADJUST_DISPLAY_PLL_PS_ALLOCATION_V3 v3; + }; + + static u32 atombios_adjust_pll(struct drm_crtc *crtc, +@@ -420,6 +429,7 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc, + struct drm_encoder *encoder = NULL; + struct radeon_encoder *radeon_encoder = NULL; + u32 adjusted_clock = mode->clock; ++ int encoder_mode = 0; + + /* reset the pll flags */ + pll->flags = 0; +@@ -448,6 +458,7 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc, + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + if (encoder->crtc == crtc) { + radeon_encoder = to_radeon_encoder(encoder); ++ encoder_mode = atombios_get_encoder_mode(encoder); + if (ASIC_IS_AVIVO(rdev)) { + /* DVO wants 2x pixel clock if the DVO chip is in 12 bit mode */ + if (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1) +@@ -468,14 +479,9 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc, + */ + if (ASIC_IS_DCE3(rdev)) { + union adjust_pixel_clock args; +- struct radeon_encoder_atom_dig *dig; + u8 frev, crev; + int index; + +- if (!radeon_encoder->enc_priv) +- return adjusted_clock; +- dig = radeon_encoder->enc_priv; +- + index = GetIndexIntoMasterTable(COMMAND, AdjustDisplayPll); + atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, + &crev); +@@ -489,12 +495,56 @@ static u32 atombios_adjust_pll(struct drm_crtc *crtc, + case 2: + args.v1.usPixelClock = cpu_to_le16(mode->clock / 10); + args.v1.ucTransmitterID = radeon_encoder->encoder_id; +- args.v1.ucEncodeMode = atombios_get_encoder_mode(encoder); ++ args.v1.ucEncodeMode = encoder_mode; + + atom_execute_table(rdev->mode_info.atom_context, + index, (uint32_t *)&args); + adjusted_clock = le16_to_cpu(args.v1.usPixelClock) * 10; + break; ++ case 3: ++ args.v3.sInput.usPixelClock = cpu_to_le16(mode->clock / 10); ++ args.v3.sInput.ucTransmitterID = radeon_encoder->encoder_id; ++ args.v3.sInput.ucEncodeMode = encoder_mode; ++ args.v3.sInput.ucDispPllConfig = 0; ++ if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; ++ ++ if (encoder_mode == ATOM_ENCODER_MODE_DP) ++ args.v3.sInput.ucDispPllConfig |= ++ DISPPLL_CONFIG_COHERENT_MODE; ++ else { ++ if (dig->coherent_mode) ++ args.v3.sInput.ucDispPllConfig |= ++ DISPPLL_CONFIG_COHERENT_MODE; ++ if (mode->clock > 165000) ++ args.v3.sInput.ucDispPllConfig |= ++ DISPPLL_CONFIG_DUAL_LINK; ++ } ++ } else if (radeon_encoder->devices & (ATOM_DEVICE_LCD_SUPPORT)) { ++ /* may want to enable SS on DP/eDP eventually */ ++ /*args.v3.sInput.ucDispPllConfig |= ++ DISPPLL_CONFIG_SS_ENABLE;*/ ++ if (encoder_mode == ATOM_ENCODER_MODE_DP) ++ args.v3.sInput.ucDispPllConfig |= ++ DISPPLL_CONFIG_COHERENT_MODE; ++ else { ++ if (mode->clock > 165000) ++ args.v3.sInput.ucDispPllConfig |= ++ DISPPLL_CONFIG_DUAL_LINK; ++ } ++ } ++ atom_execute_table(rdev->mode_info.atom_context, ++ index, (uint32_t *)&args); ++ adjusted_clock = le32_to_cpu(args.v3.sOutput.ulDispPllFreq) * 10; ++ if (args.v3.sOutput.ucRefDiv) { ++ pll->flags |= RADEON_PLL_USE_REF_DIV; ++ pll->reference_div = args.v3.sOutput.ucRefDiv; ++ } ++ if (args.v3.sOutput.ucPostDiv) { ++ pll->flags |= RADEON_PLL_USE_POST_DIV; ++ pll->post_div = args.v3.sOutput.ucPostDiv; ++ } ++ break; + default: + DRM_ERROR("Unknown table version %d %d\n", frev, crev); + return adjusted_clock; +@@ -513,9 +563,47 @@ union set_pixel_clock { + PIXEL_CLOCK_PARAMETERS v1; + PIXEL_CLOCK_PARAMETERS_V2 v2; + PIXEL_CLOCK_PARAMETERS_V3 v3; ++ PIXEL_CLOCK_PARAMETERS_V5 v5; + }; + +-void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) ++static void atombios_crtc_set_dcpll(struct drm_crtc *crtc) ++{ ++ struct drm_device *dev = crtc->dev; ++ struct radeon_device *rdev = dev->dev_private; ++ u8 frev, crev; ++ int index; ++ union set_pixel_clock args; ++ ++ memset(&args, 0, sizeof(args)); ++ ++ index = GetIndexIntoMasterTable(COMMAND, SetPixelClock); ++ atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, ++ &crev); ++ ++ switch (frev) { ++ case 1: ++ switch (crev) { ++ case 5: ++ /* if the default dcpll clock is specified, ++ * SetPixelClock provides the dividers ++ */ ++ args.v5.ucCRTC = ATOM_CRTC_INVALID; ++ args.v5.usPixelClock = rdev->clock.default_dispclk; ++ args.v5.ucPpll = ATOM_DCPLL; ++ break; ++ default: ++ DRM_ERROR("Unknown table version %d %d\n", frev, crev); ++ return; ++ } ++ break; ++ default: ++ DRM_ERROR("Unknown table version %d %d\n", frev, crev); ++ return; ++ } ++ atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); ++} ++ ++static void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + { + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + struct drm_device *dev = crtc->dev; +@@ -529,12 +617,14 @@ void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + u32 ref_div = 0, fb_div = 0, frac_fb_div = 0, post_div = 0; + struct radeon_pll *pll; + u32 adjusted_clock; ++ int encoder_mode = 0; + + memset(&args, 0, sizeof(args)); + + list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { + if (encoder->crtc == crtc) { + radeon_encoder = to_radeon_encoder(encoder); ++ encoder_mode = atombios_get_encoder_mode(encoder); + break; + } + } +@@ -542,10 +632,18 @@ void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + if (!radeon_encoder) + return; + +- if (radeon_crtc->crtc_id == 0) ++ switch (radeon_crtc->pll_id) { ++ case ATOM_PPLL1: + pll = &rdev->clock.p1pll; +- else ++ break; ++ case ATOM_PPLL2: + pll = &rdev->clock.p2pll; ++ break; ++ case ATOM_DCPLL: ++ case ATOM_PPLL_INVALID: ++ pll = &rdev->clock.dcpll; ++ break; ++ } + + /* adjust pixel clock as needed */ + adjusted_clock = atombios_adjust_pll(crtc, mode, pll); +@@ -576,8 +674,7 @@ void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + args.v1.usFbDiv = cpu_to_le16(fb_div); + args.v1.ucFracFbDiv = frac_fb_div; + args.v1.ucPostDiv = post_div; +- args.v1.ucPpll = +- radeon_crtc->crtc_id ? ATOM_PPLL2 : ATOM_PPLL1; ++ args.v1.ucPpll = radeon_crtc->pll_id; + args.v1.ucCRTC = radeon_crtc->crtc_id; + args.v1.ucRefDivSrc = 1; + break; +@@ -587,8 +684,7 @@ void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + args.v2.usFbDiv = cpu_to_le16(fb_div); + args.v2.ucFracFbDiv = frac_fb_div; + args.v2.ucPostDiv = post_div; +- args.v2.ucPpll = +- radeon_crtc->crtc_id ? ATOM_PPLL2 : ATOM_PPLL1; ++ args.v2.ucPpll = radeon_crtc->pll_id; + args.v2.ucCRTC = radeon_crtc->crtc_id; + args.v2.ucRefDivSrc = 1; + break; +@@ -598,12 +694,22 @@ void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + args.v3.usFbDiv = cpu_to_le16(fb_div); + args.v3.ucFracFbDiv = frac_fb_div; + args.v3.ucPostDiv = post_div; +- args.v3.ucPpll = +- radeon_crtc->crtc_id ? ATOM_PPLL2 : ATOM_PPLL1; +- args.v3.ucMiscInfo = (radeon_crtc->crtc_id << 2); ++ args.v3.ucPpll = radeon_crtc->pll_id; ++ args.v3.ucMiscInfo = (radeon_crtc->pll_id << 2); + args.v3.ucTransmitterId = radeon_encoder->encoder_id; +- args.v3.ucEncoderMode = +- atombios_get_encoder_mode(encoder); ++ args.v3.ucEncoderMode = encoder_mode; ++ break; ++ case 5: ++ args.v5.ucCRTC = radeon_crtc->crtc_id; ++ args.v5.usPixelClock = cpu_to_le16(mode->clock / 10); ++ args.v5.ucRefDiv = ref_div; ++ args.v5.usFbDiv = cpu_to_le16(fb_div); ++ args.v5.ulFbDivDecFrac = cpu_to_le32(frac_fb_div * 100000); ++ args.v5.ucPostDiv = post_div; ++ args.v5.ucMiscInfo = 0; /* HDMI depth, etc. */ ++ args.v5.ucTransmitterID = radeon_encoder->encoder_id; ++ args.v5.ucEncoderMode = encoder_mode; ++ args.v5.ucPpll = radeon_crtc->pll_id; + break; + default: + DRM_ERROR("Unknown table version %d %d\n", frev, crev); +@@ -618,6 +724,140 @@ void atombios_crtc_set_pll(struct drm_crtc *crtc, struct drm_display_mode *mode) + atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); + } + ++static int evergreen_crtc_set_base(struct drm_crtc *crtc, int x, int y, ++ struct drm_framebuffer *old_fb) ++{ ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); ++ struct drm_device *dev = crtc->dev; ++ struct radeon_device *rdev = dev->dev_private; ++ struct radeon_framebuffer *radeon_fb; ++ struct drm_gem_object *obj; ++ struct radeon_bo *rbo; ++ uint64_t fb_location; ++ uint32_t fb_format, fb_pitch_pixels, tiling_flags; ++ int r; ++ ++ /* no fb bound */ ++ if (!crtc->fb) { ++ DRM_DEBUG("No FB bound\n"); ++ return 0; ++ } ++ ++ radeon_fb = to_radeon_framebuffer(crtc->fb); ++ ++ /* Pin framebuffer & get tilling informations */ ++ obj = radeon_fb->obj; ++ rbo = obj->driver_private; ++ r = radeon_bo_reserve(rbo, false); ++ if (unlikely(r != 0)) ++ return r; ++ r = radeon_bo_pin(rbo, RADEON_GEM_DOMAIN_VRAM, &fb_location); ++ if (unlikely(r != 0)) { ++ radeon_bo_unreserve(rbo); ++ return -EINVAL; ++ } ++ radeon_bo_get_tiling_flags(rbo, &tiling_flags, NULL); ++ radeon_bo_unreserve(rbo); ++ ++ switch (crtc->fb->bits_per_pixel) { ++ case 8: ++ fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_8BPP) | ++ EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_INDEXED)); ++ break; ++ case 15: ++ fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | ++ EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB1555)); ++ break; ++ case 16: ++ fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_16BPP) | ++ EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB565)); ++ break; ++ case 24: ++ case 32: ++ fb_format = (EVERGREEN_GRPH_DEPTH(EVERGREEN_GRPH_DEPTH_32BPP) | ++ EVERGREEN_GRPH_FORMAT(EVERGREEN_GRPH_FORMAT_ARGB8888)); ++ break; ++ default: ++ DRM_ERROR("Unsupported screen depth %d\n", ++ crtc->fb->bits_per_pixel); ++ return -EINVAL; ++ } ++ ++ switch (radeon_crtc->crtc_id) { ++ case 0: ++ WREG32(AVIVO_D1VGA_CONTROL, 0); ++ break; ++ case 1: ++ WREG32(AVIVO_D2VGA_CONTROL, 0); ++ break; ++ case 2: ++ WREG32(EVERGREEN_D3VGA_CONTROL, 0); ++ break; ++ case 3: ++ WREG32(EVERGREEN_D4VGA_CONTROL, 0); ++ break; ++ case 4: ++ WREG32(EVERGREEN_D5VGA_CONTROL, 0); ++ break; ++ case 5: ++ WREG32(EVERGREEN_D6VGA_CONTROL, 0); ++ break; ++ default: ++ break; ++ } ++ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, ++ upper_32_bits(fb_location)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, ++ upper_32_bits(fb_location)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, ++ (u32)fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + radeon_crtc->crtc_offset, ++ (u32) fb_location & EVERGREEN_GRPH_SURFACE_ADDRESS_MASK); ++ WREG32(EVERGREEN_GRPH_CONTROL + radeon_crtc->crtc_offset, fb_format); ++ ++ WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_X + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_GRPH_SURFACE_OFFSET_Y + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_GRPH_X_START + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_GRPH_Y_START + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_GRPH_X_END + radeon_crtc->crtc_offset, crtc->fb->width); ++ WREG32(EVERGREEN_GRPH_Y_END + radeon_crtc->crtc_offset, crtc->fb->height); ++ ++ fb_pitch_pixels = crtc->fb->pitch / (crtc->fb->bits_per_pixel / 8); ++ WREG32(EVERGREEN_GRPH_PITCH + radeon_crtc->crtc_offset, fb_pitch_pixels); ++ WREG32(EVERGREEN_GRPH_ENABLE + radeon_crtc->crtc_offset, 1); ++ ++ WREG32(EVERGREEN_DESKTOP_HEIGHT + radeon_crtc->crtc_offset, ++ crtc->mode.vdisplay); ++ x &= ~3; ++ y &= ~1; ++ WREG32(EVERGREEN_VIEWPORT_START + radeon_crtc->crtc_offset, ++ (x << 16) | y); ++ WREG32(EVERGREEN_VIEWPORT_SIZE + radeon_crtc->crtc_offset, ++ (crtc->mode.hdisplay << 16) | crtc->mode.vdisplay); ++ ++ if (crtc->mode.flags & DRM_MODE_FLAG_INTERLACE) ++ WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, ++ EVERGREEN_INTERLEAVE_EN); ++ else ++ WREG32(EVERGREEN_DATA_FORMAT + radeon_crtc->crtc_offset, 0); ++ ++ if (old_fb && old_fb != crtc->fb) { ++ radeon_fb = to_radeon_framebuffer(old_fb); ++ rbo = radeon_fb->obj->driver_private; ++ r = radeon_bo_reserve(rbo, false); ++ if (unlikely(r != 0)) ++ return r; ++ radeon_bo_unpin(rbo); ++ radeon_bo_unreserve(rbo); ++ } ++ ++ /* Bytes per pixel may have changed */ ++ radeon_bandwidth_update(rdev); ++ ++ return 0; ++} ++ + static int avivo_crtc_set_base(struct drm_crtc *crtc, int x, int y, + struct drm_framebuffer *old_fb) + { +@@ -755,7 +995,9 @@ int atombios_crtc_set_base(struct drm_crtc *crtc, int x, int y, + struct drm_device *dev = crtc->dev; + struct radeon_device *rdev = dev->dev_private; + +- if (ASIC_IS_AVIVO(rdev)) ++ if (ASIC_IS_DCE4(rdev)) ++ return evergreen_crtc_set_base(crtc, x, y, old_fb); ++ else if (ASIC_IS_AVIVO(rdev)) + return avivo_crtc_set_base(crtc, x, y, old_fb); + else + return radeon_crtc_set_base(crtc, x, y, old_fb); +@@ -785,6 +1027,46 @@ static void radeon_legacy_atom_fixup(struct drm_crtc *crtc) + } + } + ++static int radeon_atom_pick_pll(struct drm_crtc *crtc) ++{ ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); ++ struct drm_device *dev = crtc->dev; ++ struct radeon_device *rdev = dev->dev_private; ++ struct drm_encoder *test_encoder; ++ struct drm_crtc *test_crtc; ++ uint32_t pll_in_use = 0; ++ ++ if (ASIC_IS_DCE4(rdev)) { ++ /* if crtc is driving DP and we have an ext clock, use that */ ++ list_for_each_entry(test_encoder, &dev->mode_config.encoder_list, head) { ++ if (test_encoder->crtc && (test_encoder->crtc == crtc)) { ++ if (atombios_get_encoder_mode(test_encoder) == ATOM_ENCODER_MODE_DP) { ++ if (rdev->clock.dp_extclk) ++ return ATOM_PPLL_INVALID; ++ } ++ } ++ } ++ ++ /* otherwise, pick one of the plls */ ++ list_for_each_entry(test_crtc, &dev->mode_config.crtc_list, head) { ++ struct radeon_crtc *radeon_test_crtc; ++ ++ if (crtc == test_crtc) ++ continue; ++ ++ radeon_test_crtc = to_radeon_crtc(test_crtc); ++ if ((radeon_test_crtc->pll_id >= ATOM_PPLL1) && ++ (radeon_test_crtc->pll_id <= ATOM_PPLL2)) ++ pll_in_use |= (1 << radeon_test_crtc->pll_id); ++ } ++ if (!(pll_in_use & 1)) ++ return ATOM_PPLL1; ++ return ATOM_PPLL2; ++ } else ++ return radeon_crtc->crtc_id; ++ ++} ++ + int atombios_crtc_mode_set(struct drm_crtc *crtc, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode, +@@ -796,19 +1078,27 @@ int atombios_crtc_mode_set(struct drm_crtc *crtc, + + /* TODO color tiling */ + ++ /* pick pll */ ++ radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); ++ + atombios_set_ss(crtc, 0); ++ /* always set DCPLL */ ++ if (ASIC_IS_DCE4(rdev)) ++ atombios_crtc_set_dcpll(crtc); + atombios_crtc_set_pll(crtc, adjusted_mode); + atombios_set_ss(crtc, 1); +- atombios_crtc_set_timing(crtc, adjusted_mode); + +- if (ASIC_IS_AVIVO(rdev)) +- atombios_crtc_set_base(crtc, x, y, old_fb); ++ if (ASIC_IS_DCE4(rdev)) ++ atombios_set_crtc_dtd_timing(crtc, adjusted_mode); ++ else if (ASIC_IS_AVIVO(rdev)) ++ atombios_crtc_set_timing(crtc, adjusted_mode); + else { ++ atombios_crtc_set_timing(crtc, adjusted_mode); + if (radeon_crtc->crtc_id == 0) + atombios_set_crtc_dtd_timing(crtc, adjusted_mode); +- atombios_crtc_set_base(crtc, x, y, old_fb); + radeon_legacy_atom_fixup(crtc); + } ++ atombios_crtc_set_base(crtc, x, y, old_fb); + atombios_overscan_setup(crtc, mode, adjusted_mode); + atombios_scaler_setup(crtc); + return 0; +@@ -825,14 +1115,14 @@ static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, + + static void atombios_crtc_prepare(struct drm_crtc *crtc) + { +- atombios_lock_crtc(crtc, 1); ++ atombios_lock_crtc(crtc, ATOM_ENABLE); + atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); + } + + static void atombios_crtc_commit(struct drm_crtc *crtc) + { + atombios_crtc_dpms(crtc, DRM_MODE_DPMS_ON); +- atombios_lock_crtc(crtc, 0); ++ atombios_lock_crtc(crtc, ATOM_DISABLE); + } + + static const struct drm_crtc_helper_funcs atombios_helper_funcs = { +@@ -848,8 +1138,37 @@ static const struct drm_crtc_helper_funcs atombios_helper_funcs = { + void radeon_atombios_init_crtc(struct drm_device *dev, + struct radeon_crtc *radeon_crtc) + { +- if (radeon_crtc->crtc_id == 1) +- radeon_crtc->crtc_offset = +- AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; ++ struct radeon_device *rdev = dev->dev_private; ++ ++ if (ASIC_IS_DCE4(rdev)) { ++ switch (radeon_crtc->crtc_id) { ++ case 0: ++ default: ++ radeon_crtc->crtc_offset = EVERGREEN_CRTC0_REGISTER_OFFSET; ++ break; ++ case 1: ++ radeon_crtc->crtc_offset = EVERGREEN_CRTC1_REGISTER_OFFSET; ++ break; ++ case 2: ++ radeon_crtc->crtc_offset = EVERGREEN_CRTC2_REGISTER_OFFSET; ++ break; ++ case 3: ++ radeon_crtc->crtc_offset = EVERGREEN_CRTC3_REGISTER_OFFSET; ++ break; ++ case 4: ++ radeon_crtc->crtc_offset = EVERGREEN_CRTC4_REGISTER_OFFSET; ++ break; ++ case 5: ++ radeon_crtc->crtc_offset = EVERGREEN_CRTC5_REGISTER_OFFSET; ++ break; ++ } ++ } else { ++ if (radeon_crtc->crtc_id == 1) ++ radeon_crtc->crtc_offset = ++ AVIVO_D2CRTC_H_TOTAL - AVIVO_D1CRTC_H_TOTAL; ++ else ++ radeon_crtc->crtc_offset = 0; ++ } ++ radeon_crtc->pll_id = -1; + drm_crtc_helper_add(&radeon_crtc->base, &atombios_helper_funcs); + } +diff --git a/drivers/gpu/drm/radeon/atombios_dp.c b/drivers/gpu/drm/radeon/atombios_dp.c +index 99915a6..28b31c6 100644 +--- a/drivers/gpu/drm/radeon/atombios_dp.c ++++ b/drivers/gpu/drm/radeon/atombios_dp.c +@@ -321,6 +321,10 @@ static void dp_get_adjust_train(u8 link_status[DP_LINK_STATUS_SIZE], + train_set[lane] = v | p; + } + ++union aux_channel_transaction { ++ PROCESS_AUX_CHANNEL_TRANSACTION_PS_ALLOCATION v1; ++ PROCESS_AUX_CHANNEL_TRANSACTION_PARAMETERS_V2 v2; ++}; + + /* radeon aux chan functions */ + bool radeon_process_aux_ch(struct radeon_i2c_chan *chan, u8 *req_bytes, +@@ -329,7 +333,7 @@ bool radeon_process_aux_ch(struct radeon_i2c_chan *chan, u8 *req_bytes, + { + struct drm_device *dev = chan->dev; + struct radeon_device *rdev = dev->dev_private; +- PROCESS_AUX_CHANNEL_TRANSACTION_PS_ALLOCATION args; ++ union aux_channel_transaction args; + int index = GetIndexIntoMasterTable(COMMAND, ProcessAuxChannelTransaction); + unsigned char *base; + int retry_count = 0; +@@ -341,31 +345,33 @@ bool radeon_process_aux_ch(struct radeon_i2c_chan *chan, u8 *req_bytes, + retry: + memcpy(base, req_bytes, num_bytes); + +- args.lpAuxRequest = 0; +- args.lpDataOut = 16; +- args.ucDataOutLen = 0; +- args.ucChannelID = chan->rec.i2c_id; +- args.ucDelay = delay / 10; ++ args.v1.lpAuxRequest = 0; ++ args.v1.lpDataOut = 16; ++ args.v1.ucDataOutLen = 0; ++ args.v1.ucChannelID = chan->rec.i2c_id; ++ args.v1.ucDelay = delay / 10; ++ if (ASIC_IS_DCE4(rdev)) ++ args.v2.ucHPD_ID = chan->rec.hpd_id; + + atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); + +- if (args.ucReplyStatus && !args.ucDataOutLen) { +- if (args.ucReplyStatus == 0x20 && retry_count++ < 10) ++ if (args.v1.ucReplyStatus && !args.v1.ucDataOutLen) { ++ if (args.v1.ucReplyStatus == 0x20 && retry_count++ < 10) + goto retry; + DRM_DEBUG("failed to get auxch %02x%02x %02x %02x 0x%02x %02x after %d retries\n", + req_bytes[1], req_bytes[0], req_bytes[2], req_bytes[3], +- chan->rec.i2c_id, args.ucReplyStatus, retry_count); ++ chan->rec.i2c_id, args.v1.ucReplyStatus, retry_count); + return false; + } + +- if (args.ucDataOutLen && read_byte && read_buf_len) { +- if (read_buf_len < args.ucDataOutLen) { ++ if (args.v1.ucDataOutLen && read_byte && read_buf_len) { ++ if (read_buf_len < args.v1.ucDataOutLen) { + DRM_ERROR("Buffer to small for return answer %d %d\n", +- read_buf_len, args.ucDataOutLen); ++ read_buf_len, args.v1.ucDataOutLen); + return false; + } + { +- int len = min(read_buf_len, args.ucDataOutLen); ++ int len = min(read_buf_len, args.v1.ucDataOutLen); + memcpy(read_byte, base + 16, len); + } + } +@@ -626,12 +632,19 @@ void dp_link_train(struct drm_encoder *encoder, + dp_set_link_bw_lanes(radeon_connector, link_configuration); + /* disable downspread on the sink */ + dp_set_downspread(radeon_connector, 0); +- /* start training on the source */ +- radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_START, +- dig_connector->dp_clock, enc_id, 0); +- /* set training pattern 1 on the source */ +- radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_PATTERN_SEL, +- dig_connector->dp_clock, enc_id, 0); ++ if (ASIC_IS_DCE4(rdev)) { ++ /* start training on the source */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_LINK_TRAINING_START); ++ /* set training pattern 1 on the source */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN1); ++ } else { ++ /* start training on the source */ ++ radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_START, ++ dig_connector->dp_clock, enc_id, 0); ++ /* set training pattern 1 on the source */ ++ radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_PATTERN_SEL, ++ dig_connector->dp_clock, enc_id, 0); ++ } + + /* set initial vs/emph */ + memset(train_set, 0, 4); +@@ -691,8 +704,11 @@ void dp_link_train(struct drm_encoder *encoder, + /* set training pattern 2 on the sink */ + dp_set_training(radeon_connector, DP_TRAINING_PATTERN_2); + /* set training pattern 2 on the source */ +- radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_PATTERN_SEL, +- dig_connector->dp_clock, enc_id, 1); ++ if (ASIC_IS_DCE4(rdev)) ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_LINK_TRAINING_PATTERN2); ++ else ++ radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_PATTERN_SEL, ++ dig_connector->dp_clock, enc_id, 1); + + /* channel equalization loop */ + tries = 0; +@@ -731,8 +747,12 @@ void dp_link_train(struct drm_encoder *encoder, + /* disable the training pattern on the sink */ + dp_set_training(radeon_connector, DP_TRAINING_PATTERN_DISABLE); + +- radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_COMPLETE, +- dig_connector->dp_clock, enc_id, 0); ++ /* disable the training pattern on the source */ ++ if (ASIC_IS_DCE4(rdev)) ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_LINK_TRAINING_COMPLETE); ++ else ++ radeon_dp_encoder_service(rdev, ATOM_DP_ACTION_TRAINING_COMPLETE, ++ dig_connector->dp_clock, enc_id, 0); + } + + int radeon_dp_i2c_aux_ch(struct i2c_adapter *adapter, int mode, +diff --git a/drivers/gpu/drm/radeon/evergreen.c b/drivers/gpu/drm/radeon/evergreen.c +new file mode 100644 +index 0000000..c2f9752 +--- /dev/null ++++ b/drivers/gpu/drm/radeon/evergreen.c +@@ -0,0 +1,794 @@ ++/* ++ * Copyright 2010 Advanced Micro Devices, Inc. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR ++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ++ * OTHER DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Alex Deucher ++ */ ++#include ++#include ++#include "drmP.h" ++#include "radeon.h" ++#include "radeon_drm.h" ++#include "rv770d.h" ++#include "atom.h" ++#include "avivod.h" ++#include "evergreen_reg.h" ++ ++static void evergreen_gpu_init(struct radeon_device *rdev); ++void evergreen_fini(struct radeon_device *rdev); ++ ++bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd) ++{ ++ bool connected = false; ++ /* XXX */ ++ return connected; ++} ++ ++void evergreen_hpd_set_polarity(struct radeon_device *rdev, ++ enum radeon_hpd_id hpd) ++{ ++ /* XXX */ ++} ++ ++void evergreen_hpd_init(struct radeon_device *rdev) ++{ ++ /* XXX */ ++} ++ ++ ++void evergreen_bandwidth_update(struct radeon_device *rdev) ++{ ++ /* XXX */ ++} ++ ++void evergreen_hpd_fini(struct radeon_device *rdev) ++{ ++ /* XXX */ ++} ++ ++static int evergreen_mc_wait_for_idle(struct radeon_device *rdev) ++{ ++ unsigned i; ++ u32 tmp; ++ ++ for (i = 0; i < rdev->usec_timeout; i++) { ++ /* read MC_STATUS */ ++ tmp = RREG32(SRBM_STATUS) & 0x1F00; ++ if (!tmp) ++ return 0; ++ udelay(1); ++ } ++ return -1; ++} ++ ++/* ++ * GART ++ */ ++int evergreen_pcie_gart_enable(struct radeon_device *rdev) ++{ ++ u32 tmp; ++ int r, i; ++ ++ if (rdev->gart.table.vram.robj == NULL) { ++ dev_err(rdev->dev, "No VRAM object for PCIE GART.\n"); ++ return -EINVAL; ++ } ++ r = radeon_gart_table_vram_pin(rdev); ++ if (r) ++ return r; ++ /* Setup L2 cache */ ++ WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | ++ ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | ++ EFFECTIVE_L2_QUEUE_SIZE(7)); ++ WREG32(VM_L2_CNTL2, 0); ++ WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); ++ /* Setup TLB control */ ++ tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | ++ SYSTEM_ACCESS_MODE_NOT_IN_SYS | ++ SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | ++ EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); ++ WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); ++ WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); ++ WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); ++ WREG32(VM_CONTEXT0_PAGE_TABLE_START_ADDR, rdev->mc.gtt_start >> 12); ++ WREG32(VM_CONTEXT0_PAGE_TABLE_END_ADDR, rdev->mc.gtt_end >> 12); ++ WREG32(VM_CONTEXT0_PAGE_TABLE_BASE_ADDR, rdev->gart.table_addr >> 12); ++ WREG32(VM_CONTEXT0_CNTL, ENABLE_CONTEXT | PAGE_TABLE_DEPTH(0) | ++ RANGE_PROTECTION_FAULT_ENABLE_DEFAULT); ++ WREG32(VM_CONTEXT0_PROTECTION_FAULT_DEFAULT_ADDR, ++ (u32)(rdev->dummy_page.addr >> 12)); ++ for (i = 1; i < 7; i++) ++ WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); ++ ++ r600_pcie_gart_tlb_flush(rdev); ++ rdev->gart.ready = true; ++ return 0; ++} ++ ++void evergreen_pcie_gart_disable(struct radeon_device *rdev) ++{ ++ u32 tmp; ++ int i, r; ++ ++ /* Disable all tables */ ++ for (i = 0; i < 7; i++) ++ WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); ++ ++ /* Setup L2 cache */ ++ WREG32(VM_L2_CNTL, ENABLE_L2_FRAGMENT_PROCESSING | ++ EFFECTIVE_L2_QUEUE_SIZE(7)); ++ WREG32(VM_L2_CNTL2, 0); ++ WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); ++ /* Setup TLB control */ ++ tmp = EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); ++ WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); ++ WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); ++ WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); ++ if (rdev->gart.table.vram.robj) { ++ r = radeon_bo_reserve(rdev->gart.table.vram.robj, false); ++ if (likely(r == 0)) { ++ radeon_bo_kunmap(rdev->gart.table.vram.robj); ++ radeon_bo_unpin(rdev->gart.table.vram.robj); ++ radeon_bo_unreserve(rdev->gart.table.vram.robj); ++ } ++ } ++} ++ ++void evergreen_pcie_gart_fini(struct radeon_device *rdev) ++{ ++ evergreen_pcie_gart_disable(rdev); ++ radeon_gart_table_vram_free(rdev); ++ radeon_gart_fini(rdev); ++} ++ ++ ++void evergreen_agp_enable(struct radeon_device *rdev) ++{ ++ u32 tmp; ++ int i; ++ ++ /* Setup L2 cache */ ++ WREG32(VM_L2_CNTL, ENABLE_L2_CACHE | ENABLE_L2_FRAGMENT_PROCESSING | ++ ENABLE_L2_PTE_CACHE_LRU_UPDATE_BY_WRITE | ++ EFFECTIVE_L2_QUEUE_SIZE(7)); ++ WREG32(VM_L2_CNTL2, 0); ++ WREG32(VM_L2_CNTL3, BANK_SELECT(0) | CACHE_UPDATE_MODE(2)); ++ /* Setup TLB control */ ++ tmp = ENABLE_L1_TLB | ENABLE_L1_FRAGMENT_PROCESSING | ++ SYSTEM_ACCESS_MODE_NOT_IN_SYS | ++ SYSTEM_APERTURE_UNMAPPED_ACCESS_PASS_THRU | ++ EFFECTIVE_L1_TLB_SIZE(5) | EFFECTIVE_L1_QUEUE_SIZE(5); ++ WREG32(MC_VM_MD_L1_TLB0_CNTL, tmp); ++ WREG32(MC_VM_MD_L1_TLB1_CNTL, tmp); ++ WREG32(MC_VM_MD_L1_TLB2_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB0_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB1_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB2_CNTL, tmp); ++ WREG32(MC_VM_MB_L1_TLB3_CNTL, tmp); ++ for (i = 0; i < 7; i++) ++ WREG32(VM_CONTEXT0_CNTL + (i * 4), 0); ++} ++ ++static void evergreen_mc_stop(struct radeon_device *rdev, struct evergreen_mc_save *save) ++{ ++ save->vga_control[0] = RREG32(D1VGA_CONTROL); ++ save->vga_control[1] = RREG32(D2VGA_CONTROL); ++ save->vga_control[2] = RREG32(EVERGREEN_D3VGA_CONTROL); ++ save->vga_control[3] = RREG32(EVERGREEN_D4VGA_CONTROL); ++ save->vga_control[4] = RREG32(EVERGREEN_D5VGA_CONTROL); ++ save->vga_control[5] = RREG32(EVERGREEN_D6VGA_CONTROL); ++ save->vga_render_control = RREG32(VGA_RENDER_CONTROL); ++ save->vga_hdp_control = RREG32(VGA_HDP_CONTROL); ++ save->crtc_control[0] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET); ++ save->crtc_control[1] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET); ++ save->crtc_control[2] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET); ++ save->crtc_control[3] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET); ++ save->crtc_control[4] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET); ++ save->crtc_control[5] = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); ++ ++ /* Stop all video */ ++ WREG32(VGA_RENDER_CONTROL, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC0_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC1_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC2_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC3_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC4_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC5_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0); ++ ++ WREG32(D1VGA_CONTROL, 0); ++ WREG32(D2VGA_CONTROL, 0); ++ WREG32(EVERGREEN_D3VGA_CONTROL, 0); ++ WREG32(EVERGREEN_D4VGA_CONTROL, 0); ++ WREG32(EVERGREEN_D5VGA_CONTROL, 0); ++ WREG32(EVERGREEN_D6VGA_CONTROL, 0); ++} ++ ++static void evergreen_mc_resume(struct radeon_device *rdev, struct evergreen_mc_save *save) ++{ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC0_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC0_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + EVERGREEN_CRTC0_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + EVERGREEN_CRTC0_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC1_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC1_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + EVERGREEN_CRTC1_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + EVERGREEN_CRTC1_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC2_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC2_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + EVERGREEN_CRTC2_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + EVERGREEN_CRTC2_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC3_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC3_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + EVERGREEN_CRTC3_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + EVERGREEN_CRTC3_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC4_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC4_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + EVERGREEN_CRTC4_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + EVERGREEN_CRTC4_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC5_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH + EVERGREEN_CRTC5_REGISTER_OFFSET, ++ upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS + EVERGREEN_CRTC5_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ WREG32(EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS + EVERGREEN_CRTC5_REGISTER_OFFSET, ++ (u32)rdev->mc.vram_start); ++ ++ WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH, upper_32_bits(rdev->mc.vram_start)); ++ WREG32(EVERGREEN_VGA_MEMORY_BASE_ADDRESS, (u32)rdev->mc.vram_start); ++ /* Unlock host access */ ++ WREG32(VGA_HDP_CONTROL, save->vga_hdp_control); ++ mdelay(1); ++ /* Restore video state */ ++ WREG32(D1VGA_CONTROL, save->vga_control[0]); ++ WREG32(D2VGA_CONTROL, save->vga_control[1]); ++ WREG32(EVERGREEN_D3VGA_CONTROL, save->vga_control[2]); ++ WREG32(EVERGREEN_D4VGA_CONTROL, save->vga_control[3]); ++ WREG32(EVERGREEN_D5VGA_CONTROL, save->vga_control[4]); ++ WREG32(EVERGREEN_D6VGA_CONTROL, save->vga_control[5]); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC0_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC1_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC2_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC3_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC4_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC5_REGISTER_OFFSET, 1); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET, save->crtc_control[0]); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET, save->crtc_control[1]); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET, save->crtc_control[2]); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET, save->crtc_control[3]); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET, save->crtc_control[4]); ++ WREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET, save->crtc_control[5]); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC0_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC1_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC2_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC3_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC4_REGISTER_OFFSET, 0); ++ WREG32(EVERGREEN_CRTC_UPDATE_LOCK + EVERGREEN_CRTC5_REGISTER_OFFSET, 0); ++ WREG32(VGA_RENDER_CONTROL, save->vga_render_control); ++} ++ ++static void evergreen_mc_program(struct radeon_device *rdev) ++{ ++ struct evergreen_mc_save save; ++ u32 tmp; ++ int i, j; ++ ++ /* Initialize HDP */ ++ for (i = 0, j = 0; i < 32; i++, j += 0x18) { ++ WREG32((0x2c14 + j), 0x00000000); ++ WREG32((0x2c18 + j), 0x00000000); ++ WREG32((0x2c1c + j), 0x00000000); ++ WREG32((0x2c20 + j), 0x00000000); ++ WREG32((0x2c24 + j), 0x00000000); ++ } ++ WREG32(HDP_REG_COHERENCY_FLUSH_CNTL, 0); ++ ++ evergreen_mc_stop(rdev, &save); ++ if (evergreen_mc_wait_for_idle(rdev)) { ++ dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); ++ } ++ /* Lockout access through VGA aperture*/ ++ WREG32(VGA_HDP_CONTROL, VGA_MEMORY_DISABLE); ++ /* Update configuration */ ++ if (rdev->flags & RADEON_IS_AGP) { ++ if (rdev->mc.vram_start < rdev->mc.gtt_start) { ++ /* VRAM before AGP */ ++ WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, ++ rdev->mc.vram_start >> 12); ++ WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, ++ rdev->mc.gtt_end >> 12); ++ } else { ++ /* VRAM after AGP */ ++ WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, ++ rdev->mc.gtt_start >> 12); ++ WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, ++ rdev->mc.vram_end >> 12); ++ } ++ } else { ++ WREG32(MC_VM_SYSTEM_APERTURE_LOW_ADDR, ++ rdev->mc.vram_start >> 12); ++ WREG32(MC_VM_SYSTEM_APERTURE_HIGH_ADDR, ++ rdev->mc.vram_end >> 12); ++ } ++ WREG32(MC_VM_SYSTEM_APERTURE_DEFAULT_ADDR, 0); ++ tmp = ((rdev->mc.vram_end >> 24) & 0xFFFF) << 16; ++ tmp |= ((rdev->mc.vram_start >> 24) & 0xFFFF); ++ WREG32(MC_VM_FB_LOCATION, tmp); ++ WREG32(HDP_NONSURFACE_BASE, (rdev->mc.vram_start >> 8)); ++ WREG32(HDP_NONSURFACE_INFO, (2 << 7)); ++ WREG32(HDP_NONSURFACE_SIZE, (rdev->mc.mc_vram_size - 1) | 0x3FF); ++ if (rdev->flags & RADEON_IS_AGP) { ++ WREG32(MC_VM_AGP_TOP, rdev->mc.gtt_end >> 16); ++ WREG32(MC_VM_AGP_BOT, rdev->mc.gtt_start >> 16); ++ WREG32(MC_VM_AGP_BASE, rdev->mc.agp_base >> 22); ++ } else { ++ WREG32(MC_VM_AGP_BASE, 0); ++ WREG32(MC_VM_AGP_TOP, 0x0FFFFFFF); ++ WREG32(MC_VM_AGP_BOT, 0x0FFFFFFF); ++ } ++ if (evergreen_mc_wait_for_idle(rdev)) { ++ dev_warn(rdev->dev, "Wait for MC idle timedout !\n"); ++ } ++ evergreen_mc_resume(rdev, &save); ++ /* we need to own VRAM, so turn off the VGA renderer here ++ * to stop it overwriting our objects */ ++ rv515_vga_render_disable(rdev); ++} ++ ++#if 0 ++/* ++ * CP. ++ */ ++static void evergreen_cp_stop(struct radeon_device *rdev) ++{ ++ /* XXX */ ++} ++ ++ ++static int evergreen_cp_load_microcode(struct radeon_device *rdev) ++{ ++ /* XXX */ ++ ++ return 0; ++} ++ ++ ++/* ++ * Core functions ++ */ ++static u32 evergreen_get_tile_pipe_to_backend_map(u32 num_tile_pipes, ++ u32 num_backends, ++ u32 backend_disable_mask) ++{ ++ u32 backend_map = 0; ++ ++ return backend_map; ++} ++#endif ++ ++static void evergreen_gpu_init(struct radeon_device *rdev) ++{ ++ /* XXX */ ++} ++ ++int evergreen_mc_init(struct radeon_device *rdev) ++{ ++ fixed20_12 a; ++ u32 tmp; ++ int chansize, numchan; ++ int r; ++ ++ /* Get VRAM informations */ ++ rdev->mc.vram_is_ddr = true; ++ tmp = RREG32(MC_ARB_RAMCFG); ++ if (tmp & CHANSIZE_OVERRIDE) { ++ chansize = 16; ++ } else if (tmp & CHANSIZE_MASK) { ++ chansize = 64; ++ } else { ++ chansize = 32; ++ } ++ tmp = RREG32(MC_SHARED_CHMAP); ++ switch ((tmp & NOOFCHAN_MASK) >> NOOFCHAN_SHIFT) { ++ case 0: ++ default: ++ numchan = 1; ++ break; ++ case 1: ++ numchan = 2; ++ break; ++ case 2: ++ numchan = 4; ++ break; ++ case 3: ++ numchan = 8; ++ break; ++ } ++ rdev->mc.vram_width = numchan * chansize; ++ /* Could aper size report 0 ? */ ++ rdev->mc.aper_base = drm_get_resource_start(rdev->ddev, 0); ++ rdev->mc.aper_size = drm_get_resource_len(rdev->ddev, 0); ++ /* Setup GPU memory space */ ++ /* size in MB on evergreen */ ++ rdev->mc.mc_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024; ++ rdev->mc.real_vram_size = RREG32(CONFIG_MEMSIZE) * 1024 * 1024; ++ ++ if (rdev->mc.mc_vram_size > rdev->mc.aper_size) ++ rdev->mc.mc_vram_size = rdev->mc.aper_size; ++ ++ if (rdev->mc.real_vram_size > rdev->mc.aper_size) ++ rdev->mc.real_vram_size = rdev->mc.aper_size; ++ ++ if (rdev->flags & RADEON_IS_AGP) { ++ r = radeon_agp_init(rdev); ++ if (r) ++ return r; ++ /* gtt_size is setup by radeon_agp_init */ ++ rdev->mc.gtt_location = rdev->mc.agp_base; ++ tmp = 0xFFFFFFFFUL - rdev->mc.agp_base - rdev->mc.gtt_size; ++ /* Try to put vram before or after AGP because we ++ * we want SYSTEM_APERTURE to cover both VRAM and ++ * AGP so that GPU can catch out of VRAM/AGP access ++ */ ++ if (rdev->mc.gtt_location > rdev->mc.mc_vram_size) { ++ /* Enought place before */ ++ rdev->mc.vram_location = rdev->mc.gtt_location - ++ rdev->mc.mc_vram_size; ++ } else if (tmp > rdev->mc.mc_vram_size) { ++ /* Enought place after */ ++ rdev->mc.vram_location = rdev->mc.gtt_location + ++ rdev->mc.gtt_size; ++ } else { ++ /* Try to setup VRAM then AGP might not ++ * not work on some card ++ */ ++ rdev->mc.vram_location = 0x00000000UL; ++ rdev->mc.gtt_location = rdev->mc.mc_vram_size; ++ } ++ } else { ++ rdev->mc.vram_location = 0x00000000UL; ++ rdev->mc.gtt_location = rdev->mc.mc_vram_size; ++ rdev->mc.gtt_size = radeon_gart_size * 1024 * 1024; ++ } ++ rdev->mc.vram_start = rdev->mc.vram_location; ++ rdev->mc.vram_end = rdev->mc.vram_location + rdev->mc.mc_vram_size - 1; ++ rdev->mc.gtt_start = rdev->mc.gtt_location; ++ rdev->mc.gtt_end = rdev->mc.gtt_location + rdev->mc.gtt_size - 1; ++ /* FIXME: we should enforce default clock in case GPU is not in ++ * default setup ++ */ ++ a.full = rfixed_const(100); ++ rdev->pm.sclk.full = rfixed_const(rdev->clock.default_sclk); ++ rdev->pm.sclk.full = rfixed_div(rdev->pm.sclk, a); ++ return 0; ++} ++int evergreen_gpu_reset(struct radeon_device *rdev) ++{ ++ /* FIXME: implement for evergreen */ ++ return 0; ++} ++ ++static int evergreen_startup(struct radeon_device *rdev) ++{ ++#if 0 ++ int r; ++ ++ if (!rdev->me_fw || !rdev->pfp_fw || !rdev->rlc_fw) { ++ r = r600_init_microcode(rdev); ++ if (r) { ++ DRM_ERROR("Failed to load firmware!\n"); ++ return r; ++ } ++ } ++#endif ++ evergreen_mc_program(rdev); ++#if 0 ++ if (rdev->flags & RADEON_IS_AGP) { ++ evergreem_agp_enable(rdev); ++ } else { ++ r = evergreen_pcie_gart_enable(rdev); ++ if (r) ++ return r; ++ } ++#endif ++ evergreen_gpu_init(rdev); ++#if 0 ++ if (!rdev->r600_blit.shader_obj) { ++ r = r600_blit_init(rdev); ++ if (r) { ++ DRM_ERROR("radeon: failed blitter (%d).\n", r); ++ return r; ++ } ++ } ++ ++ r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false); ++ if (unlikely(r != 0)) ++ return r; ++ r = radeon_bo_pin(rdev->r600_blit.shader_obj, RADEON_GEM_DOMAIN_VRAM, ++ &rdev->r600_blit.shader_gpu_addr); ++ radeon_bo_unreserve(rdev->r600_blit.shader_obj); ++ if (r) { ++ DRM_ERROR("failed to pin blit object %d\n", r); ++ return r; ++ } ++ ++ /* Enable IRQ */ ++ r = r600_irq_init(rdev); ++ if (r) { ++ DRM_ERROR("radeon: IH init failed (%d).\n", r); ++ radeon_irq_kms_fini(rdev); ++ return r; ++ } ++ r600_irq_set(rdev); ++ ++ r = radeon_ring_init(rdev, rdev->cp.ring_size); ++ if (r) ++ return r; ++ r = evergreen_cp_load_microcode(rdev); ++ if (r) ++ return r; ++ r = r600_cp_resume(rdev); ++ if (r) ++ return r; ++ /* write back buffer are not vital so don't worry about failure */ ++ r600_wb_enable(rdev); ++#endif ++ return 0; ++} ++ ++int evergreen_resume(struct radeon_device *rdev) ++{ ++ int r; ++ ++ /* Do not reset GPU before posting, on rv770 hw unlike on r500 hw, ++ * posting will perform necessary task to bring back GPU into good ++ * shape. ++ */ ++ /* post card */ ++ atom_asic_init(rdev->mode_info.atom_context); ++ /* Initialize clocks */ ++ r = radeon_clocks_init(rdev); ++ if (r) { ++ return r; ++ } ++ ++ r = evergreen_startup(rdev); ++ if (r) { ++ DRM_ERROR("r600 startup failed on resume\n"); ++ return r; ++ } ++#if 0 ++ r = r600_ib_test(rdev); ++ if (r) { ++ DRM_ERROR("radeon: failled testing IB (%d).\n", r); ++ return r; ++ } ++#endif ++ return r; ++ ++} ++ ++int evergreen_suspend(struct radeon_device *rdev) ++{ ++#if 0 ++ int r; ++ ++ /* FIXME: we should wait for ring to be empty */ ++ r700_cp_stop(rdev); ++ rdev->cp.ready = false; ++ r600_wb_disable(rdev); ++ evergreen_pcie_gart_disable(rdev); ++ /* unpin shaders bo */ ++ r = radeon_bo_reserve(rdev->r600_blit.shader_obj, false); ++ if (likely(r == 0)) { ++ radeon_bo_unpin(rdev->r600_blit.shader_obj); ++ radeon_bo_unreserve(rdev->r600_blit.shader_obj); ++ } ++#endif ++ return 0; ++} ++ ++static bool evergreen_card_posted(struct radeon_device *rdev) ++{ ++ u32 reg; ++ ++ /* first check CRTCs */ ++ reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); ++ if (reg & EVERGREEN_CRTC_MASTER_EN) ++ return true; ++ ++ /* then check MEM_SIZE, in case the crtcs are off */ ++ if (RREG32(CONFIG_MEMSIZE)) ++ return true; ++ ++ return false; ++} ++ ++/* Plan is to move initialization in that function and use ++ * helper function so that radeon_device_init pretty much ++ * do nothing more than calling asic specific function. This ++ * should also allow to remove a bunch of callback function ++ * like vram_info. ++ */ ++int evergreen_init(struct radeon_device *rdev) ++{ ++ int r; ++ ++ r = radeon_dummy_page_init(rdev); ++ if (r) ++ return r; ++ /* This don't do much */ ++ r = radeon_gem_init(rdev); ++ if (r) ++ return r; ++ /* Read BIOS */ ++ if (!radeon_get_bios(rdev)) { ++ if (ASIC_IS_AVIVO(rdev)) ++ return -EINVAL; ++ } ++ /* Must be an ATOMBIOS */ ++ if (!rdev->is_atom_bios) { ++ dev_err(rdev->dev, "Expecting atombios for R600 GPU\n"); ++ return -EINVAL; ++ } ++ r = radeon_atombios_init(rdev); ++ if (r) ++ return r; ++ /* Post card if necessary */ ++ if (!evergreen_card_posted(rdev)) { ++ if (!rdev->bios) { ++ dev_err(rdev->dev, "Card not posted and no BIOS - ignoring\n"); ++ return -EINVAL; ++ } ++ DRM_INFO("GPU not posted. posting now...\n"); ++ atom_asic_init(rdev->mode_info.atom_context); ++ } ++ /* Initialize scratch registers */ ++ r600_scratch_init(rdev); ++ /* Initialize surface registers */ ++ radeon_surface_init(rdev); ++ /* Initialize clocks */ ++ radeon_get_clock_info(rdev->ddev); ++ r = radeon_clocks_init(rdev); ++ if (r) ++ return r; ++ /* Initialize power management */ ++ radeon_pm_init(rdev); ++ /* Fence driver */ ++ r = radeon_fence_driver_init(rdev); ++ if (r) ++ return r; ++ r = evergreen_mc_init(rdev); ++ if (r) ++ return r; ++ /* Memory manager */ ++ r = radeon_bo_init(rdev); ++ if (r) ++ return r; ++#if 0 ++ r = radeon_irq_kms_init(rdev); ++ if (r) ++ return r; ++ ++ rdev->cp.ring_obj = NULL; ++ r600_ring_init(rdev, 1024 * 1024); ++ ++ rdev->ih.ring_obj = NULL; ++ r600_ih_ring_init(rdev, 64 * 1024); ++ ++ r = r600_pcie_gart_init(rdev); ++ if (r) ++ return r; ++#endif ++ rdev->accel_working = false; ++ r = evergreen_startup(rdev); ++ if (r) { ++ evergreen_suspend(rdev); ++ /*r600_wb_fini(rdev);*/ ++ /*radeon_ring_fini(rdev);*/ ++ /*evergreen_pcie_gart_fini(rdev);*/ ++ rdev->accel_working = false; ++ } ++ if (rdev->accel_working) { ++ r = radeon_ib_pool_init(rdev); ++ if (r) { ++ DRM_ERROR("radeon: failed initializing IB pool (%d).\n", r); ++ rdev->accel_working = false; ++ } ++ r = r600_ib_test(rdev); ++ if (r) { ++ DRM_ERROR("radeon: failed testing IB (%d).\n", r); ++ rdev->accel_working = false; ++ } ++ } ++ return 0; ++} ++ ++void evergreen_fini(struct radeon_device *rdev) ++{ ++ evergreen_suspend(rdev); ++#if 0 ++ r600_blit_fini(rdev); ++ r600_irq_fini(rdev); ++ radeon_irq_kms_fini(rdev); ++ radeon_ring_fini(rdev); ++ r600_wb_fini(rdev); ++ evergreen_pcie_gart_fini(rdev); ++#endif ++ radeon_gem_fini(rdev); ++ radeon_fence_driver_fini(rdev); ++ radeon_clocks_fini(rdev); ++ radeon_agp_fini(rdev); ++ radeon_bo_fini(rdev); ++ radeon_atombios_fini(rdev); ++ kfree(rdev->bios); ++ rdev->bios = NULL; ++ radeon_dummy_page_fini(rdev); ++} +diff --git a/drivers/gpu/drm/radeon/evergreen_reg.h b/drivers/gpu/drm/radeon/evergreen_reg.h +new file mode 100644 +index 0000000..f7c7c96 +--- /dev/null ++++ b/drivers/gpu/drm/radeon/evergreen_reg.h +@@ -0,0 +1,176 @@ ++/* ++ * Copyright 2010 Advanced Micro Devices, Inc. ++ * ++ * Permission is hereby granted, free of charge, to any person obtaining a ++ * copy of this software and associated documentation files (the "Software"), ++ * to deal in the Software without restriction, including without limitation ++ * the rights to use, copy, modify, merge, publish, distribute, sublicense, ++ * and/or sell copies of the Software, and to permit persons to whom the ++ * Software is furnished to do so, subject to the following conditions: ++ * ++ * The above copyright notice and this permission notice shall be included in ++ * all copies or substantial portions of the Software. ++ * ++ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR ++ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, ++ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL ++ * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR ++ * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ++ * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR ++ * OTHER DEALINGS IN THE SOFTWARE. ++ * ++ * Authors: Alex Deucher ++ */ ++#ifndef __EVERGREEN_REG_H__ ++#define __EVERGREEN_REG_H__ ++ ++/* evergreen */ ++#define EVERGREEN_VGA_MEMORY_BASE_ADDRESS 0x310 ++#define EVERGREEN_VGA_MEMORY_BASE_ADDRESS_HIGH 0x324 ++#define EVERGREEN_D3VGA_CONTROL 0x3e0 ++#define EVERGREEN_D4VGA_CONTROL 0x3e4 ++#define EVERGREEN_D5VGA_CONTROL 0x3e8 ++#define EVERGREEN_D6VGA_CONTROL 0x3ec ++ ++#define EVERGREEN_P1PLL_SS_CNTL 0x414 ++#define EVERGREEN_P2PLL_SS_CNTL 0x454 ++# define EVERGREEN_PxPLL_SS_EN (1 << 12) ++/* GRPH blocks at 0x6800, 0x7400, 0x10000, 0x10c00, 0x11800, 0x12400 */ ++#define EVERGREEN_GRPH_ENABLE 0x6800 ++#define EVERGREEN_GRPH_CONTROL 0x6804 ++# define EVERGREEN_GRPH_DEPTH(x) (((x) & 0x3) << 0) ++# define EVERGREEN_GRPH_DEPTH_8BPP 0 ++# define EVERGREEN_GRPH_DEPTH_16BPP 1 ++# define EVERGREEN_GRPH_DEPTH_32BPP 2 ++# define EVERGREEN_GRPH_FORMAT(x) (((x) & 0x7) << 8) ++/* 8 BPP */ ++# define EVERGREEN_GRPH_FORMAT_INDEXED 0 ++/* 16 BPP */ ++# define EVERGREEN_GRPH_FORMAT_ARGB1555 0 ++# define EVERGREEN_GRPH_FORMAT_ARGB565 1 ++# define EVERGREEN_GRPH_FORMAT_ARGB4444 2 ++# define EVERGREEN_GRPH_FORMAT_AI88 3 ++# define EVERGREEN_GRPH_FORMAT_MONO16 4 ++# define EVERGREEN_GRPH_FORMAT_BGRA5551 5 ++/* 32 BPP */ ++# define EVERGREEN_GRPH_FORMAT_ARGB8888 0 ++# define EVERGREEN_GRPH_FORMAT_ARGB2101010 1 ++# define EVERGREEN_GRPH_FORMAT_32BPP_DIG 2 ++# define EVERGREEN_GRPH_FORMAT_8B_ARGB2101010 3 ++# define EVERGREEN_GRPH_FORMAT_BGRA1010102 4 ++# define EVERGREEN_GRPH_FORMAT_8B_BGRA1010102 5 ++# define EVERGREEN_GRPH_FORMAT_RGB111110 6 ++# define EVERGREEN_GRPH_FORMAT_BGR101111 7 ++#define EVERGREEN_GRPH_SWAP_CONTROL 0x680c ++# define EVERGREEN_GRPH_ENDIAN_SWAP(x) (((x) & 0x3) << 0) ++# define EVERGREEN_GRPH_ENDIAN_NONE 0 ++# define EVERGREEN_GRPH_ENDIAN_8IN16 1 ++# define EVERGREEN_GRPH_ENDIAN_8IN32 2 ++# define EVERGREEN_GRPH_ENDIAN_8IN64 3 ++# define EVERGREEN_GRPH_RED_CROSSBAR(x) (((x) & 0x3) << 4) ++# define EVERGREEN_GRPH_RED_SEL_R 0 ++# define EVERGREEN_GRPH_RED_SEL_G 1 ++# define EVERGREEN_GRPH_RED_SEL_B 2 ++# define EVERGREEN_GRPH_RED_SEL_A 3 ++# define EVERGREEN_GRPH_GREEN_CROSSBAR(x) (((x) & 0x3) << 6) ++# define EVERGREEN_GRPH_GREEN_SEL_G 0 ++# define EVERGREEN_GRPH_GREEN_SEL_B 1 ++# define EVERGREEN_GRPH_GREEN_SEL_A 2 ++# define EVERGREEN_GRPH_GREEN_SEL_R 3 ++# define EVERGREEN_GRPH_BLUE_CROSSBAR(x) (((x) & 0x3) << 8) ++# define EVERGREEN_GRPH_BLUE_SEL_B 0 ++# define EVERGREEN_GRPH_BLUE_SEL_A 1 ++# define EVERGREEN_GRPH_BLUE_SEL_R 2 ++# define EVERGREEN_GRPH_BLUE_SEL_G 3 ++# define EVERGREEN_GRPH_ALPHA_CROSSBAR(x) (((x) & 0x3) << 10) ++# define EVERGREEN_GRPH_ALPHA_SEL_A 0 ++# define EVERGREEN_GRPH_ALPHA_SEL_R 1 ++# define EVERGREEN_GRPH_ALPHA_SEL_G 2 ++# define EVERGREEN_GRPH_ALPHA_SEL_B 3 ++#define EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS 0x6810 ++#define EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS 0x6814 ++# define EVERGREEN_GRPH_DFQ_ENABLE (1 << 0) ++# define EVERGREEN_GRPH_SURFACE_ADDRESS_MASK 0xffffff00 ++#define EVERGREEN_GRPH_PITCH 0x6818 ++#define EVERGREEN_GRPH_PRIMARY_SURFACE_ADDRESS_HIGH 0x681c ++#define EVERGREEN_GRPH_SECONDARY_SURFACE_ADDRESS_HIGH 0x6820 ++#define EVERGREEN_GRPH_SURFACE_OFFSET_X 0x6824 ++#define EVERGREEN_GRPH_SURFACE_OFFSET_Y 0x6828 ++#define EVERGREEN_GRPH_X_START 0x682c ++#define EVERGREEN_GRPH_Y_START 0x6830 ++#define EVERGREEN_GRPH_X_END 0x6834 ++#define EVERGREEN_GRPH_Y_END 0x6838 ++ ++/* CUR blocks at 0x6998, 0x7598, 0x10198, 0x10d98, 0x11998, 0x12598 */ ++#define EVERGREEN_CUR_CONTROL 0x6998 ++# define EVERGREEN_CURSOR_EN (1 << 0) ++# define EVERGREEN_CURSOR_MODE(x) (((x) & 0x3) << 8) ++# define EVERGREEN_CURSOR_MONO 0 ++# define EVERGREEN_CURSOR_24_1 1 ++# define EVERGREEN_CURSOR_24_8_PRE_MULT 2 ++# define EVERGREEN_CURSOR_24_8_UNPRE_MULT 3 ++# define EVERGREEN_CURSOR_2X_MAGNIFY (1 << 16) ++# define EVERGREEN_CURSOR_FORCE_MC_ON (1 << 20) ++# define EVERGREEN_CURSOR_URGENT_CONTROL(x) (((x) & 0x7) << 24) ++# define EVERGREEN_CURSOR_URGENT_ALWAYS 0 ++# define EVERGREEN_CURSOR_URGENT_1_8 1 ++# define EVERGREEN_CURSOR_URGENT_1_4 2 ++# define EVERGREEN_CURSOR_URGENT_3_8 3 ++# define EVERGREEN_CURSOR_URGENT_1_2 4 ++#define EVERGREEN_CUR_SURFACE_ADDRESS 0x699c ++# define EVERGREEN_CUR_SURFACE_ADDRESS_MASK 0xfffff000 ++#define EVERGREEN_CUR_SIZE 0x69a0 ++#define EVERGREEN_CUR_SURFACE_ADDRESS_HIGH 0x69a4 ++#define EVERGREEN_CUR_POSITION 0x69a8 ++#define EVERGREEN_CUR_HOT_SPOT 0x69ac ++#define EVERGREEN_CUR_COLOR1 0x69b0 ++#define EVERGREEN_CUR_COLOR2 0x69b4 ++#define EVERGREEN_CUR_UPDATE 0x69b8 ++# define EVERGREEN_CURSOR_UPDATE_PENDING (1 << 0) ++# define EVERGREEN_CURSOR_UPDATE_TAKEN (1 << 1) ++# define EVERGREEN_CURSOR_UPDATE_LOCK (1 << 16) ++# define EVERGREEN_CURSOR_DISABLE_MULTIPLE_UPDATE (1 << 24) ++ ++/* LUT blocks at 0x69e0, 0x75e0, 0x101e0, 0x10de0, 0x119e0, 0x125e0 */ ++#define EVERGREEN_DC_LUT_RW_MODE 0x69e0 ++#define EVERGREEN_DC_LUT_RW_INDEX 0x69e4 ++#define EVERGREEN_DC_LUT_SEQ_COLOR 0x69e8 ++#define EVERGREEN_DC_LUT_PWL_DATA 0x69ec ++#define EVERGREEN_DC_LUT_30_COLOR 0x69f0 ++#define EVERGREEN_DC_LUT_VGA_ACCESS_ENABLE 0x69f4 ++#define EVERGREEN_DC_LUT_WRITE_EN_MASK 0x69f8 ++#define EVERGREEN_DC_LUT_AUTOFILL 0x69fc ++#define EVERGREEN_DC_LUT_CONTROL 0x6a00 ++#define EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE 0x6a04 ++#define EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN 0x6a08 ++#define EVERGREEN_DC_LUT_BLACK_OFFSET_RED 0x6a0c ++#define EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE 0x6a10 ++#define EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN 0x6a14 ++#define EVERGREEN_DC_LUT_WHITE_OFFSET_RED 0x6a18 ++ ++#define EVERGREEN_DATA_FORMAT 0x6b00 ++# define EVERGREEN_INTERLEAVE_EN (1 << 0) ++#define EVERGREEN_DESKTOP_HEIGHT 0x6b04 ++ ++#define EVERGREEN_VIEWPORT_START 0x6d70 ++#define EVERGREEN_VIEWPORT_SIZE 0x6d74 ++ ++/* display controller offsets used for crtc/cur/lut/grph/viewport/etc. */ ++#define EVERGREEN_CRTC0_REGISTER_OFFSET (0x6df0 - 0x6df0) ++#define EVERGREEN_CRTC1_REGISTER_OFFSET (0x79f0 - 0x6df0) ++#define EVERGREEN_CRTC2_REGISTER_OFFSET (0x105f0 - 0x6df0) ++#define EVERGREEN_CRTC3_REGISTER_OFFSET (0x111f0 - 0x6df0) ++#define EVERGREEN_CRTC4_REGISTER_OFFSET (0x11df0 - 0x6df0) ++#define EVERGREEN_CRTC5_REGISTER_OFFSET (0x129f0 - 0x6df0) ++ ++/* CRTC blocks at 0x6df0, 0x79f0, 0x105f0, 0x111f0, 0x11df0, 0x129f0 */ ++#define EVERGREEN_CRTC_CONTROL 0x6e70 ++# define EVERGREEN_CRTC_MASTER_EN (1 << 0) ++#define EVERGREEN_CRTC_UPDATE_LOCK 0x6ed4 ++ ++#define EVERGREEN_DC_GPIO_HPD_MASK 0x64b0 ++#define EVERGREEN_DC_GPIO_HPD_A 0x64b4 ++#define EVERGREEN_DC_GPIO_HPD_EN 0x64b8 ++#define EVERGREEN_DC_GPIO_HPD_Y 0x64bc ++ ++#endif +diff --git a/drivers/gpu/drm/radeon/radeon.h b/drivers/gpu/drm/radeon/radeon.h +index c0356bb..d564c62 100644 +--- a/drivers/gpu/drm/radeon/radeon.h ++++ b/drivers/gpu/drm/radeon/radeon.h +@@ -138,11 +138,14 @@ void radeon_dummy_page_fini(struct radeon_device *rdev); + struct radeon_clock { + struct radeon_pll p1pll; + struct radeon_pll p2pll; ++ struct radeon_pll dcpll; + struct radeon_pll spll; + struct radeon_pll mpll; + /* 10 Khz units */ + uint32_t default_mclk; + uint32_t default_sclk; ++ uint32_t default_dispclk; ++ uint32_t dp_extclk; + }; + + /* +@@ -830,6 +833,7 @@ struct radeon_device { + struct r600_ih ih; /* r6/700 interrupt ring */ + struct workqueue_struct *wq; + struct work_struct hotplug_work; ++ int num_crtc; /* number of crtcs */ + + /* audio stuff */ + struct timer_list audio_timer; +@@ -956,7 +960,7 @@ void r100_pll_errata_after_index(struct radeon_device *rdev); + #define ASIC_IS_AVIVO(rdev) ((rdev->family >= CHIP_RS600)) + #define ASIC_IS_DCE3(rdev) ((rdev->family >= CHIP_RV620)) + #define ASIC_IS_DCE32(rdev) ((rdev->family >= CHIP_RV730)) +- ++#define ASIC_IS_DCE4(rdev) ((rdev->family >= CHIP_CEDAR)) + + /* + * BIOS helpers. +@@ -1189,6 +1193,14 @@ extern void r600_hdmi_update_audio_settings(struct drm_encoder *encoder, + uint8_t status_bits, + uint8_t category_code); + ++/* evergreen */ ++struct evergreen_mc_save { ++ u32 vga_control[6]; ++ u32 vga_render_control; ++ u32 vga_hdp_control; ++ u32 crtc_control[6]; ++}; ++ + #include "radeon_object.h" + + #endif +diff --git a/drivers/gpu/drm/radeon/radeon_asic.h b/drivers/gpu/drm/radeon/radeon_asic.h +index 05ee1ae..f7734c3 100644 +--- a/drivers/gpu/drm/radeon/radeon_asic.h ++++ b/drivers/gpu/drm/radeon/radeon_asic.h +@@ -539,7 +539,7 @@ static struct radeon_asic r600_asic = { + .get_memory_clock = &radeon_atom_get_memory_clock, + .set_memory_clock = &radeon_atom_set_memory_clock, + .set_pcie_lanes = NULL, +- .set_clock_gating = &radeon_atom_set_clock_gating, ++ .set_clock_gating = NULL, + .set_surface_reg = r600_set_surface_reg, + .clear_surface_reg = r600_clear_surface_reg, + .bandwidth_update = &rv515_bandwidth_update, +@@ -595,4 +595,54 @@ static struct radeon_asic rv770_asic = { + .ioctl_wait_idle = r600_ioctl_wait_idle, + }; + ++/* ++ * evergreen ++ */ ++int evergreen_init(struct radeon_device *rdev); ++void evergreen_fini(struct radeon_device *rdev); ++int evergreen_suspend(struct radeon_device *rdev); ++int evergreen_resume(struct radeon_device *rdev); ++int evergreen_gpu_reset(struct radeon_device *rdev); ++void evergreen_bandwidth_update(struct radeon_device *rdev); ++void evergreen_hpd_init(struct radeon_device *rdev); ++void evergreen_hpd_fini(struct radeon_device *rdev); ++bool evergreen_hpd_sense(struct radeon_device *rdev, enum radeon_hpd_id hpd); ++void evergreen_hpd_set_polarity(struct radeon_device *rdev, ++ enum radeon_hpd_id hpd); ++ ++static struct radeon_asic evergreen_asic = { ++ .init = &evergreen_init, ++ .fini = &evergreen_fini, ++ .suspend = &evergreen_suspend, ++ .resume = &evergreen_resume, ++ .cp_commit = NULL, ++ .gpu_reset = &evergreen_gpu_reset, ++ .vga_set_state = &r600_vga_set_state, ++ .gart_tlb_flush = &r600_pcie_gart_tlb_flush, ++ .gart_set_page = &rs600_gart_set_page, ++ .ring_test = NULL, ++ .ring_ib_execute = NULL, ++ .irq_set = NULL, ++ .irq_process = NULL, ++ .get_vblank_counter = NULL, ++ .fence_ring_emit = NULL, ++ .cs_parse = NULL, ++ .copy_blit = NULL, ++ .copy_dma = NULL, ++ .copy = NULL, ++ .get_engine_clock = &radeon_atom_get_engine_clock, ++ .set_engine_clock = &radeon_atom_set_engine_clock, ++ .get_memory_clock = &radeon_atom_get_memory_clock, ++ .set_memory_clock = &radeon_atom_set_memory_clock, ++ .set_pcie_lanes = NULL, ++ .set_clock_gating = NULL, ++ .set_surface_reg = r600_set_surface_reg, ++ .clear_surface_reg = r600_clear_surface_reg, ++ .bandwidth_update = &evergreen_bandwidth_update, ++ .hpd_init = &evergreen_hpd_init, ++ .hpd_fini = &evergreen_hpd_fini, ++ .hpd_sense = &evergreen_hpd_sense, ++ .hpd_set_polarity = &evergreen_hpd_set_polarity, ++}; ++ + #endif +diff --git a/drivers/gpu/drm/radeon/radeon_atombios.c b/drivers/gpu/drm/radeon/radeon_atombios.c +index 4d88315..381ebdd 100644 +--- a/drivers/gpu/drm/radeon/radeon_atombios.c ++++ b/drivers/gpu/drm/radeon/radeon_atombios.c +@@ -159,8 +159,15 @@ static struct radeon_hpd radeon_atom_get_hpd_info_from_gpio(struct radeon_device + struct radeon_gpio_rec *gpio) + { + struct radeon_hpd hpd; ++ u32 reg; ++ ++ if (ASIC_IS_DCE4(rdev)) ++ reg = EVERGREEN_DC_GPIO_HPD_A; ++ else ++ reg = AVIVO_DC_GPIO_HPD_A; ++ + hpd.gpio = *gpio; +- if (gpio->reg == AVIVO_DC_GPIO_HPD_A) { ++ if (gpio->reg == reg) { + switch(gpio->mask) { + case (1 << 0): + hpd.hpd = RADEON_HPD_1; +@@ -574,6 +581,9 @@ bool radeon_get_atom_connector_info_from_object_table(struct drm_device *dev) + ddc_bus.valid = false; + } + ++ /* needed for aux chan transactions */ ++ ddc_bus.hpd_id = hpd.hpd ? (hpd.hpd - 1) : 0; ++ + conn_id = le16_to_cpu(path->usConnObjectId); + + if (!radeon_atom_apply_quirks +@@ -838,6 +848,7 @@ union firmware_info { + ATOM_FIRMWARE_INFO_V1_2 info_12; + ATOM_FIRMWARE_INFO_V1_3 info_13; + ATOM_FIRMWARE_INFO_V1_4 info_14; ++ ATOM_FIRMWARE_INFO_V2_1 info_21; + }; + + bool radeon_atom_get_clock_info(struct drm_device *dev) +@@ -849,6 +860,7 @@ bool radeon_atom_get_clock_info(struct drm_device *dev) + uint8_t frev, crev; + struct radeon_pll *p1pll = &rdev->clock.p1pll; + struct radeon_pll *p2pll = &rdev->clock.p2pll; ++ struct radeon_pll *dcpll = &rdev->clock.dcpll; + struct radeon_pll *spll = &rdev->clock.spll; + struct radeon_pll *mpll = &rdev->clock.mpll; + uint16_t data_offset; +@@ -951,8 +963,19 @@ bool radeon_atom_get_clock_info(struct drm_device *dev) + rdev->clock.default_mclk = + le32_to_cpu(firmware_info->info.ulDefaultMemoryClock); + ++ if (ASIC_IS_DCE4(rdev)) { ++ rdev->clock.default_dispclk = ++ le32_to_cpu(firmware_info->info_21.ulDefaultDispEngineClkFreq); ++ if (rdev->clock.default_dispclk == 0) ++ rdev->clock.default_dispclk = 60000; /* 600 Mhz */ ++ rdev->clock.dp_extclk = ++ le16_to_cpu(firmware_info->info_21.usUniphyDPModeExtClkFreq); ++ } ++ *dcpll = *p1pll; ++ + return true; + } ++ + return false; + } + +@@ -1395,16 +1418,6 @@ void radeon_atom_set_clock_gating(struct radeon_device *rdev, int enable) + atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); + } + +-void radeon_atom_static_pwrmgt_setup(struct radeon_device *rdev, int enable) +-{ +- ENABLE_ASIC_STATIC_PWR_MGT_PS_ALLOCATION args; +- int index = GetIndexIntoMasterTable(COMMAND, EnableASIC_StaticPwrMgt); +- +- args.ucEnable = enable; +- +- atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); +-} +- + uint32_t radeon_atom_get_engine_clock(struct radeon_device *rdev) + { + GET_ENGINE_CLOCK_PS_ALLOCATION args; +diff --git a/drivers/gpu/drm/radeon/radeon_clocks.c b/drivers/gpu/drm/radeon/radeon_clocks.c +index 73c4405..f64936c 100644 +--- a/drivers/gpu/drm/radeon/radeon_clocks.c ++++ b/drivers/gpu/drm/radeon/radeon_clocks.c +@@ -96,6 +96,7 @@ void radeon_get_clock_info(struct drm_device *dev) + struct radeon_device *rdev = dev->dev_private; + struct radeon_pll *p1pll = &rdev->clock.p1pll; + struct radeon_pll *p2pll = &rdev->clock.p2pll; ++ struct radeon_pll *dcpll = &rdev->clock.dcpll; + struct radeon_pll *spll = &rdev->clock.spll; + struct radeon_pll *mpll = &rdev->clock.mpll; + int ret; +@@ -204,6 +205,17 @@ void radeon_get_clock_info(struct drm_device *dev) + p2pll->max_frac_feedback_div = 0; + } + ++ /* dcpll is DCE4 only */ ++ dcpll->min_post_div = 2; ++ dcpll->max_post_div = 0x7f; ++ dcpll->min_frac_feedback_div = 0; ++ dcpll->max_frac_feedback_div = 9; ++ dcpll->min_ref_div = 2; ++ dcpll->max_ref_div = 0x3ff; ++ dcpll->min_feedback_div = 4; ++ dcpll->max_feedback_div = 0xfff; ++ dcpll->best_vco = 0; ++ + p1pll->min_ref_div = 2; + p1pll->max_ref_div = 0x3ff; + p1pll->min_feedback_div = 4; +@@ -846,8 +858,10 @@ int radeon_static_clocks_init(struct drm_device *dev) + /* XXX make sure engine is idle */ + + if (radeon_dynclks != -1) { +- if (radeon_dynclks) +- radeon_set_clock_gating(rdev, 1); ++ if (radeon_dynclks) { ++ if (rdev->asic->set_clock_gating) ++ radeon_set_clock_gating(rdev, 1); ++ } + } + radeon_apply_clock_quirks(rdev); + return 0; +diff --git a/drivers/gpu/drm/radeon/radeon_combios.c b/drivers/gpu/drm/radeon/radeon_combios.c +index e7b1944..e3388a9 100644 +--- a/drivers/gpu/drm/radeon/radeon_combios.c ++++ b/drivers/gpu/drm/radeon/radeon_combios.c +@@ -507,6 +507,7 @@ static struct radeon_i2c_bus_rec combios_setup_i2c_bus(struct radeon_device *rde + } + i2c.mm_i2c = false; + i2c.i2c_id = 0; ++ i2c.hpd_id = 0; + + if (ddc_line) + i2c.valid = true; +diff --git a/drivers/gpu/drm/radeon/radeon_cursor.c b/drivers/gpu/drm/radeon/radeon_cursor.c +index 28772a3..7ecf5e1 100644 +--- a/drivers/gpu/drm/radeon/radeon_cursor.c ++++ b/drivers/gpu/drm/radeon/radeon_cursor.c +@@ -36,7 +36,14 @@ static void radeon_lock_cursor(struct drm_crtc *crtc, bool lock) + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + uint32_t cur_lock; + +- if (ASIC_IS_AVIVO(rdev)) { ++ if (ASIC_IS_DCE4(rdev)) { ++ cur_lock = RREG32(EVERGREEN_CUR_UPDATE + radeon_crtc->crtc_offset); ++ if (lock) ++ cur_lock |= EVERGREEN_CURSOR_UPDATE_LOCK; ++ else ++ cur_lock &= ~EVERGREEN_CURSOR_UPDATE_LOCK; ++ WREG32(EVERGREEN_CUR_UPDATE + radeon_crtc->crtc_offset, cur_lock); ++ } else if (ASIC_IS_AVIVO(rdev)) { + cur_lock = RREG32(AVIVO_D1CUR_UPDATE + radeon_crtc->crtc_offset); + if (lock) + cur_lock |= AVIVO_D1CURSOR_UPDATE_LOCK; +@@ -58,7 +65,10 @@ static void radeon_hide_cursor(struct drm_crtc *crtc) + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + struct radeon_device *rdev = crtc->dev->dev_private; + +- if (ASIC_IS_AVIVO(rdev)) { ++ if (ASIC_IS_DCE4(rdev)) { ++ WREG32(RADEON_MM_INDEX, EVERGREEN_CUR_CONTROL + radeon_crtc->crtc_offset); ++ WREG32(RADEON_MM_DATA, EVERGREEN_CURSOR_MODE(EVERGREEN_CURSOR_24_8_PRE_MULT)); ++ } else if (ASIC_IS_AVIVO(rdev)) { + WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL + radeon_crtc->crtc_offset); + WREG32(RADEON_MM_DATA, (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT)); + } else { +@@ -81,10 +91,14 @@ static void radeon_show_cursor(struct drm_crtc *crtc) + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + struct radeon_device *rdev = crtc->dev->dev_private; + +- if (ASIC_IS_AVIVO(rdev)) { ++ if (ASIC_IS_DCE4(rdev)) { ++ WREG32(RADEON_MM_INDEX, EVERGREEN_CUR_CONTROL + radeon_crtc->crtc_offset); ++ WREG32(RADEON_MM_DATA, EVERGREEN_CURSOR_EN | ++ EVERGREEN_CURSOR_MODE(EVERGREEN_CURSOR_24_8_PRE_MULT)); ++ } else if (ASIC_IS_AVIVO(rdev)) { + WREG32(RADEON_MM_INDEX, AVIVO_D1CUR_CONTROL + radeon_crtc->crtc_offset); + WREG32(RADEON_MM_DATA, AVIVO_D1CURSOR_EN | +- (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT)); ++ (AVIVO_D1CURSOR_MODE_24BPP << AVIVO_D1CURSOR_MODE_SHIFT)); + } else { + switch (radeon_crtc->crtc_id) { + case 0: +@@ -109,7 +123,10 @@ static void radeon_set_cursor(struct drm_crtc *crtc, struct drm_gem_object *obj, + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); + struct radeon_device *rdev = crtc->dev->dev_private; + +- if (ASIC_IS_AVIVO(rdev)) { ++ if (ASIC_IS_DCE4(rdev)) { ++ WREG32(EVERGREEN_CUR_SURFACE_ADDRESS_HIGH + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_CUR_SURFACE_ADDRESS + radeon_crtc->crtc_offset, gpu_addr); ++ } else if (ASIC_IS_AVIVO(rdev)) { + if (rdev->family >= CHIP_RV770) { + if (radeon_crtc->crtc_id) + WREG32(R700_D2CUR_SURFACE_ADDRESS_HIGH, 0); +@@ -201,7 +218,20 @@ int radeon_crtc_cursor_move(struct drm_crtc *crtc, + yorigin = CURSOR_HEIGHT - 1; + + radeon_lock_cursor(crtc, true); +- if (ASIC_IS_AVIVO(rdev)) { ++ if (ASIC_IS_DCE4(rdev)) { ++ /* cursors are offset into the total surface */ ++ x += crtc->x; ++ y += crtc->y; ++ DRM_DEBUG("x %d y %d c->x %d c->y %d\n", x, y, crtc->x, crtc->y); ++ ++ /* XXX: check if evergreen has the same issues as avivo chips */ ++ WREG32(EVERGREEN_CUR_POSITION + radeon_crtc->crtc_offset, ++ ((xorigin ? 0 : x) << 16) | ++ (yorigin ? 0 : y)); ++ WREG32(EVERGREEN_CUR_HOT_SPOT + radeon_crtc->crtc_offset, (xorigin << 16) | yorigin); ++ WREG32(EVERGREEN_CUR_SIZE + radeon_crtc->crtc_offset, ++ ((radeon_crtc->cursor_width - 1) << 16) | (radeon_crtc->cursor_height - 1)); ++ } else if (ASIC_IS_AVIVO(rdev)) { + int w = radeon_crtc->cursor_width; + int i = 0; + struct drm_crtc *crtc_p; +diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c +index 768b150..4ca5ddc 100644 +--- a/drivers/gpu/drm/radeon/radeon_device.c ++++ b/drivers/gpu/drm/radeon/radeon_device.c +@@ -182,7 +182,16 @@ bool radeon_card_posted(struct radeon_device *rdev) + uint32_t reg; + + /* first check CRTCs */ +- if (ASIC_IS_AVIVO(rdev)) { ++ if (ASIC_IS_DCE4(rdev)) { ++ reg = RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC0_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC1_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC2_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC3_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC4_REGISTER_OFFSET) | ++ RREG32(EVERGREEN_CRTC_CONTROL + EVERGREEN_CRTC5_REGISTER_OFFSET); ++ if (reg & EVERGREEN_CRTC_MASTER_EN) ++ return true; ++ } else if (ASIC_IS_AVIVO(rdev)) { + reg = RREG32(AVIVO_D1CRTC_CONTROL) | + RREG32(AVIVO_D2CRTC_CONTROL); + if (reg & AVIVO_CRTC_EN) { +@@ -310,7 +319,7 @@ void radeon_register_accessor_init(struct radeon_device *rdev) + rdev->mc_rreg = &rs600_mc_rreg; + rdev->mc_wreg = &rs600_mc_wreg; + } +- if (rdev->family >= CHIP_R600) { ++ if ((rdev->family >= CHIP_R600) && (rdev->family <= CHIP_RV740)) { + rdev->pciep_rreg = &r600_pciep_rreg; + rdev->pciep_wreg = &r600_pciep_wreg; + } +@@ -387,6 +396,13 @@ int radeon_asic_init(struct radeon_device *rdev) + case CHIP_RV740: + rdev->asic = &rv770_asic; + break; ++ case CHIP_CEDAR: ++ case CHIP_REDWOOD: ++ case CHIP_JUNIPER: ++ case CHIP_CYPRESS: ++ case CHIP_HEMLOCK: ++ rdev->asic = &evergreen_asic; ++ break; + default: + /* FIXME: not supported yet */ + return -EINVAL; +diff --git a/drivers/gpu/drm/radeon/radeon_display.c b/drivers/gpu/drm/radeon/radeon_display.c +index 7e17a36..86a9f01 100644 +--- a/drivers/gpu/drm/radeon/radeon_display.c ++++ b/drivers/gpu/drm/radeon/radeon_display.c +@@ -68,6 +68,36 @@ static void avivo_crtc_load_lut(struct drm_crtc *crtc) + WREG32(AVIVO_D1GRPH_LUT_SEL + radeon_crtc->crtc_offset, radeon_crtc->crtc_id); + } + ++static void evergreen_crtc_load_lut(struct drm_crtc *crtc) ++{ ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); ++ struct drm_device *dev = crtc->dev; ++ struct radeon_device *rdev = dev->dev_private; ++ int i; ++ ++ DRM_DEBUG("%d\n", radeon_crtc->crtc_id); ++ WREG32(EVERGREEN_DC_LUT_CONTROL + radeon_crtc->crtc_offset, 0); ++ ++ WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_BLUE + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_GREEN + radeon_crtc->crtc_offset, 0); ++ WREG32(EVERGREEN_DC_LUT_BLACK_OFFSET_RED + radeon_crtc->crtc_offset, 0); ++ ++ WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_BLUE + radeon_crtc->crtc_offset, 0xffff); ++ WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_GREEN + radeon_crtc->crtc_offset, 0xffff); ++ WREG32(EVERGREEN_DC_LUT_WHITE_OFFSET_RED + radeon_crtc->crtc_offset, 0xffff); ++ ++ WREG32(EVERGREEN_DC_LUT_RW_MODE, radeon_crtc->crtc_id); ++ WREG32(EVERGREEN_DC_LUT_WRITE_EN_MASK, 0x00000007); ++ ++ WREG32(EVERGREEN_DC_LUT_RW_INDEX, 0); ++ for (i = 0; i < 256; i++) { ++ WREG32(EVERGREEN_DC_LUT_30_COLOR, ++ (radeon_crtc->lut_r[i] << 20) | ++ (radeon_crtc->lut_g[i] << 10) | ++ (radeon_crtc->lut_b[i] << 0)); ++ } ++} ++ + static void legacy_crtc_load_lut(struct drm_crtc *crtc) + { + struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); +@@ -100,7 +130,9 @@ void radeon_crtc_load_lut(struct drm_crtc *crtc) + if (!crtc->enabled) + return; + +- if (ASIC_IS_AVIVO(rdev)) ++ if (ASIC_IS_DCE4(rdev)) ++ evergreen_crtc_load_lut(crtc); ++ else if (ASIC_IS_AVIVO(rdev)) + avivo_crtc_load_lut(crtc); + else + legacy_crtc_load_lut(crtc); +@@ -819,7 +851,7 @@ static int radeon_modeset_create_props(struct radeon_device *rdev) + + int radeon_modeset_init(struct radeon_device *rdev) + { +- int num_crtc = 2, i; ++ int i; + int ret; + + drm_mode_config_init(rdev->ddev); +@@ -843,10 +875,16 @@ int radeon_modeset_init(struct radeon_device *rdev) + } + + if (rdev->flags & RADEON_SINGLE_CRTC) +- num_crtc = 1; ++ rdev->num_crtc = 1; ++ else { ++ if (ASIC_IS_DCE4(rdev)) ++ rdev->num_crtc = 6; ++ else ++ rdev->num_crtc = 2; ++ } + + /* allocate crtcs */ +- for (i = 0; i < num_crtc; i++) { ++ for (i = 0; i < rdev->num_crtc; i++) { + radeon_crtc_init(rdev->ddev, i); + } + +diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c +index 3c91724..cac9e06 100644 +--- a/drivers/gpu/drm/radeon/radeon_encoders.c ++++ b/drivers/gpu/drm/radeon/radeon_encoders.c +@@ -53,7 +53,7 @@ static uint32_t radeon_encoder_clones(struct drm_encoder *encoder) + /* DVO requires 2x ppll clocks depending on tmds chip */ + if (radeon_encoder->devices & ATOM_DEVICE_DFP2_SUPPORT) + return index_mask; +- ++ + count = -1; + list_for_each_entry(clone_encoder, &dev->mode_config.encoder_list, head) { + struct radeon_encoder *radeon_clone = to_radeon_encoder(clone_encoder); +@@ -228,6 +228,32 @@ radeon_get_connector_for_encoder(struct drm_encoder *encoder) + return NULL; + } + ++static struct radeon_connector_atom_dig * ++radeon_get_atom_connector_priv_from_encoder(struct drm_encoder *encoder) ++{ ++ struct drm_device *dev = encoder->dev; ++ struct radeon_device *rdev = dev->dev_private; ++ struct drm_connector *connector; ++ struct radeon_connector *radeon_connector; ++ struct radeon_connector_atom_dig *dig_connector; ++ ++ if (!rdev->is_atom_bios) ++ return NULL; ++ ++ connector = radeon_get_connector_for_encoder(encoder); ++ if (!connector) ++ return NULL; ++ ++ radeon_connector = to_radeon_connector(connector); ++ ++ if (!radeon_connector->con_priv) ++ return NULL; ++ ++ dig_connector = radeon_connector->con_priv; ++ ++ return dig_connector; ++} ++ + static bool radeon_atom_mode_fixup(struct drm_encoder *encoder, + struct drm_display_mode *mode, + struct drm_display_mode *adjusted_mode) +@@ -273,7 +299,7 @@ static bool radeon_atom_mode_fixup(struct drm_encoder *encoder, + } + + if (ASIC_IS_DCE3(rdev) && +- (radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT))) { ++ (radeon_encoder->active_device & (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT))) { + struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); + radeon_dp_set_link_config(connector, mode); + } +@@ -458,34 +484,20 @@ atombios_digital_setup(struct drm_encoder *encoder, int action) + struct drm_device *dev = encoder->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; ++ struct radeon_connector_atom_dig *dig_connector = ++ radeon_get_atom_connector_priv_from_encoder(encoder); + union lvds_encoder_control args; + int index = 0; + int hdmi_detected = 0; + uint8_t frev, crev; +- struct radeon_encoder_atom_dig *dig; +- struct drm_connector *connector; +- struct radeon_connector *radeon_connector; +- struct radeon_connector_atom_dig *dig_connector; +- +- connector = radeon_get_connector_for_encoder(encoder); +- if (!connector) +- return; +- +- radeon_connector = to_radeon_connector(connector); + +- if (!radeon_encoder->enc_priv) ++ if (!dig || !dig_connector) + return; + +- dig = radeon_encoder->enc_priv; +- +- if (!radeon_connector->con_priv) +- return; +- +- if (drm_detect_hdmi_monitor(radeon_connector->edid)) ++ if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_HDMI) + hdmi_detected = 1; + +- dig_connector = radeon_connector->con_priv; +- + memset(&args, 0, sizeof(args)); + + switch (radeon_encoder->encoder_id) { +@@ -586,7 +598,7 @@ atombios_get_encoder_mode(struct drm_encoder *encoder) + { + struct drm_connector *connector; + struct radeon_connector *radeon_connector; +- struct radeon_connector_atom_dig *radeon_dig_connector; ++ struct radeon_connector_atom_dig *dig_connector; + + connector = radeon_get_connector_for_encoder(encoder); + if (!connector) +@@ -617,9 +629,9 @@ atombios_get_encoder_mode(struct drm_encoder *encoder) + break; + case DRM_MODE_CONNECTOR_DisplayPort: + case DRM_MODE_CONNECTOR_eDP: +- radeon_dig_connector = radeon_connector->con_priv; +- if ((radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || +- (radeon_dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) ++ dig_connector = radeon_connector->con_priv; ++ if ((dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_DISPLAYPORT) || ++ (dig_connector->dp_sink_type == CONNECTOR_OBJECT_ID_eDP)) + return ATOM_ENCODER_MODE_DP; + else if (drm_detect_hdmi_monitor(radeon_connector->edid)) + return ATOM_ENCODER_MODE_HDMI; +@@ -656,6 +668,18 @@ atombios_get_encoder_mode(struct drm_encoder *encoder) + * - 2 DIG encoder blocks. + * DIG1/2 can drive UNIPHY0/1/2 link A or link B + * ++ * DCE 4.0 ++ * - 3 DIG transmitter blocks UNPHY0/1/2 (links A and B). ++ * Supports up to 6 digital outputs ++ * - 6 DIG encoder blocks. ++ * - DIG to PHY mapping is hardcoded ++ * DIG1 drives UNIPHY0 link A, A+B ++ * DIG2 drives UNIPHY0 link B ++ * DIG3 drives UNIPHY1 link A, A+B ++ * DIG4 drives UNIPHY1 link B ++ * DIG5 drives UNIPHY2 link A, A+B ++ * DIG6 drives UNIPHY2 link B ++ * + * Routing + * crtc -> dig encoder -> UNIPHY/LVTMA (1 or 2 links) + * Examples: +@@ -664,88 +688,77 @@ atombios_get_encoder_mode(struct drm_encoder *encoder) + * crtc0 -> dig1 -> UNIPHY2 link A -> LVDS + * crtc1 -> dig2 -> UNIPHY1 link B+A -> TMDS/HDMI + */ +-static void ++ ++union dig_encoder_control { ++ DIG_ENCODER_CONTROL_PS_ALLOCATION v1; ++ DIG_ENCODER_CONTROL_PARAMETERS_V2 v2; ++ DIG_ENCODER_CONTROL_PARAMETERS_V3 v3; ++}; ++ ++void + atombios_dig_encoder_setup(struct drm_encoder *encoder, int action) + { + struct drm_device *dev = encoder->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); +- DIG_ENCODER_CONTROL_PS_ALLOCATION args; +- int index = 0, num = 0; ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; ++ struct radeon_connector_atom_dig *dig_connector = ++ radeon_get_atom_connector_priv_from_encoder(encoder); ++ union dig_encoder_control args; ++ int index = 0; + uint8_t frev, crev; +- struct radeon_encoder_atom_dig *dig; +- struct drm_connector *connector; +- struct radeon_connector *radeon_connector; +- struct radeon_connector_atom_dig *dig_connector; +- +- connector = radeon_get_connector_for_encoder(encoder); +- if (!connector) +- return; +- +- radeon_connector = to_radeon_connector(connector); + +- if (!radeon_connector->con_priv) ++ if (!dig || !dig_connector) + return; + +- dig_connector = radeon_connector->con_priv; +- +- if (!radeon_encoder->enc_priv) +- return; +- +- dig = radeon_encoder->enc_priv; +- + memset(&args, 0, sizeof(args)); + +- if (dig->dig_encoder) +- index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); +- else +- index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); +- num = dig->dig_encoder + 1; ++ if (ASIC_IS_DCE4(rdev)) ++ index = GetIndexIntoMasterTable(COMMAND, DIGxEncoderControl); ++ else { ++ if (dig->dig_encoder) ++ index = GetIndexIntoMasterTable(COMMAND, DIG2EncoderControl); ++ else ++ index = GetIndexIntoMasterTable(COMMAND, DIG1EncoderControl); ++ } + + atom_parse_cmd_header(rdev->mode_info.atom_context, index, &frev, &crev); + +- args.ucAction = action; +- args.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); ++ args.v1.ucAction = action; ++ args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); ++ args.v1.ucEncoderMode = atombios_get_encoder_mode(encoder); + +- if (ASIC_IS_DCE32(rdev)) { ++ if (args.v1.ucEncoderMode == ATOM_ENCODER_MODE_DP) { ++ if (dig_connector->dp_clock == 270000) ++ args.v1.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ; ++ args.v1.ucLaneNum = dig_connector->dp_lane_count; ++ } else if (radeon_encoder->pixel_clock > 165000) ++ args.v1.ucLaneNum = 8; ++ else ++ args.v1.ucLaneNum = 4; ++ ++ if (ASIC_IS_DCE4(rdev)) { ++ args.v3.acConfig.ucDigSel = dig->dig_encoder; ++ args.v3.ucBitPerColor = PANEL_8BIT_PER_COLOR; ++ } else { + switch (radeon_encoder->encoder_id) { + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: +- args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1; ++ args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER1; + break; + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: +- args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2; ++ case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: ++ args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER2; + break; + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: +- args.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3; +- break; +- } +- } else { +- switch (radeon_encoder->encoder_id) { +- case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: +- args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER1; +- break; +- case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: +- args.ucConfig = ATOM_ENCODER_CONFIG_TRANSMITTER2; ++ args.v1.ucConfig = ATOM_ENCODER_CONFIG_V2_TRANSMITTER3; + break; + } ++ if (dig_connector->linkb) ++ args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKB; ++ else ++ args.v1.ucConfig |= ATOM_ENCODER_CONFIG_LINKA; + } + +- args.ucEncoderMode = atombios_get_encoder_mode(encoder); +- +- if (args.ucEncoderMode == ATOM_ENCODER_MODE_DP) { +- if (dig_connector->dp_clock == 270000) +- args.ucConfig |= ATOM_ENCODER_CONFIG_DPLINKRATE_2_70GHZ; +- args.ucLaneNum = dig_connector->dp_lane_count; +- } else if (radeon_encoder->pixel_clock > 165000) +- args.ucLaneNum = 8; +- else +- args.ucLaneNum = 4; +- +- if (dig_connector->linkb) +- args.ucConfig |= ATOM_ENCODER_CONFIG_LINKB; +- else +- args.ucConfig |= ATOM_ENCODER_CONFIG_LINKA; +- + atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); + + } +@@ -753,6 +766,7 @@ atombios_dig_encoder_setup(struct drm_encoder *encoder, int action) + union dig_transmitter_control { + DIG_TRANSMITTER_CONTROL_PS_ALLOCATION v1; + DIG_TRANSMITTER_CONTROL_PARAMETERS_V2 v2; ++ DIG_TRANSMITTER_CONTROL_PARAMETERS_V3 v3; + }; + + void +@@ -761,37 +775,29 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + struct drm_device *dev = encoder->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); +- union dig_transmitter_control args; +- int index = 0, num = 0; +- uint8_t frev, crev; +- struct radeon_encoder_atom_dig *dig; ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; ++ struct radeon_connector_atom_dig *dig_connector = ++ radeon_get_atom_connector_priv_from_encoder(encoder); + struct drm_connector *connector; + struct radeon_connector *radeon_connector; +- struct radeon_connector_atom_dig *dig_connector; ++ union dig_transmitter_control args; ++ int index = 0; ++ uint8_t frev, crev; + bool is_dp = false; ++ int pll_id = 0; + +- connector = radeon_get_connector_for_encoder(encoder); +- if (!connector) ++ if (!dig || !dig_connector) + return; + ++ connector = radeon_get_connector_for_encoder(encoder); + radeon_connector = to_radeon_connector(connector); + +- if (!radeon_encoder->enc_priv) +- return; +- +- dig = radeon_encoder->enc_priv; +- +- if (!radeon_connector->con_priv) +- return; +- +- dig_connector = radeon_connector->con_priv; +- + if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) + is_dp = true; + + memset(&args, 0, sizeof(args)); + +- if (ASIC_IS_DCE32(rdev)) ++ if (ASIC_IS_DCE32(rdev) || ASIC_IS_DCE4(rdev)) + index = GetIndexIntoMasterTable(COMMAND, UNIPHYTransmitterControl); + else { + switch (radeon_encoder->encoder_id) { +@@ -821,24 +827,64 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + else + args.v1.usPixelClock = cpu_to_le16(radeon_encoder->pixel_clock / 10); + } +- if (ASIC_IS_DCE32(rdev)) { +- if (dig->dig_encoder == 1) +- args.v2.acConfig.ucEncoderSel = 1; ++ if (ASIC_IS_DCE4(rdev)) { ++ if (is_dp) ++ args.v3.ucLaneNum = dig_connector->dp_lane_count; ++ else if (radeon_encoder->pixel_clock > 165000) ++ args.v3.ucLaneNum = 8; ++ else ++ args.v3.ucLaneNum = 4; ++ ++ if (dig_connector->linkb) { ++ args.v3.acConfig.ucLinkSel = 1; ++ args.v3.acConfig.ucEncoderSel = 1; ++ } ++ ++ /* Select the PLL for the PHY ++ * DP PHY should be clocked from external src if there is ++ * one. ++ */ ++ if (encoder->crtc) { ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); ++ pll_id = radeon_crtc->pll_id; ++ } ++ if (is_dp && rdev->clock.dp_extclk) ++ args.v3.acConfig.ucRefClkSource = 2; /* external src */ ++ else ++ args.v3.acConfig.ucRefClkSource = pll_id; ++ ++ switch (radeon_encoder->encoder_id) { ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: ++ args.v3.acConfig.ucTransmitterSel = 0; ++ break; ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: ++ args.v3.acConfig.ucTransmitterSel = 1; ++ break; ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: ++ args.v3.acConfig.ucTransmitterSel = 2; ++ break; ++ } ++ ++ if (is_dp) ++ args.v3.acConfig.fCoherentMode = 1; /* DP requires coherent */ ++ else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { ++ if (dig->coherent_mode) ++ args.v3.acConfig.fCoherentMode = 1; ++ } ++ } else if (ASIC_IS_DCE32(rdev)) { ++ args.v2.acConfig.ucEncoderSel = dig->dig_encoder; + if (dig_connector->linkb) + args.v2.acConfig.ucLinkSel = 1; + + switch (radeon_encoder->encoder_id) { + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: + args.v2.acConfig.ucTransmitterSel = 0; +- num = 0; + break; + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: + args.v2.acConfig.ucTransmitterSel = 1; +- num = 1; + break; + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: + args.v2.acConfig.ucTransmitterSel = 2; +- num = 2; + break; + } + +@@ -849,7 +895,6 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + args.v2.acConfig.fCoherentMode = 1; + } + } else { +- + args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL; + + if (dig->dig_encoder) +@@ -857,31 +902,25 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + else + args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_DIG1_ENCODER; + +- switch (radeon_encoder->encoder_id) { +- case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: +- if (rdev->flags & RADEON_IS_IGP) { +- if (radeon_encoder->pixel_clock > 165000) { +- if (dig_connector->igp_lane_info & 0x3) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7; +- else if (dig_connector->igp_lane_info & 0xc) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15; +- } else { +- if (dig_connector->igp_lane_info & 0x1) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3; +- else if (dig_connector->igp_lane_info & 0x2) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7; +- else if (dig_connector->igp_lane_info & 0x4) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11; +- else if (dig_connector->igp_lane_info & 0x8) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15; +- } ++ if ((rdev->flags & RADEON_IS_IGP) && ++ (radeon_encoder->encoder_id == ENCODER_OBJECT_ID_INTERNAL_UNIPHY)) { ++ if (is_dp || (radeon_encoder->pixel_clock <= 165000)) { ++ if (dig_connector->igp_lane_info & 0x1) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_3; ++ else if (dig_connector->igp_lane_info & 0x2) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_4_7; ++ else if (dig_connector->igp_lane_info & 0x4) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_11; ++ else if (dig_connector->igp_lane_info & 0x8) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_12_15; ++ } else { ++ if (dig_connector->igp_lane_info & 0x3) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_0_7; ++ else if (dig_connector->igp_lane_info & 0xc) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LANE_8_15; + } +- break; + } + +- if (radeon_encoder->pixel_clock > 165000) +- args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK; +- + if (dig_connector->linkb) + args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_LINKB; + else +@@ -892,6 +931,8 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { + if (dig->coherent_mode) + args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_COHERENT; ++ if (radeon_encoder->pixel_clock > 165000) ++ args.v1.ucConfig |= ATOM_TRANSMITTER_CONFIG_8LANE_LINK; + } + } + +@@ -998,16 +1039,25 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode) + if (is_dig) { + switch (mode) { + case DRM_MODE_DPMS_ON: +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0); +- { ++ if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) { + struct drm_connector *connector = radeon_get_connector_for_encoder(encoder); ++ + dp_link_train(encoder, connector); ++ if (ASIC_IS_DCE4(rdev)) ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_ON); + } ++ if (!ASIC_IS_DCE4(rdev)) ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE_OUTPUT, 0, 0); + break; + case DRM_MODE_DPMS_STANDBY: + case DRM_MODE_DPMS_SUSPEND: + case DRM_MODE_DPMS_OFF: +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0); ++ if (!ASIC_IS_DCE4(rdev)) ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE_OUTPUT, 0, 0); ++ if (atombios_get_encoder_mode(encoder) == ATOM_ENCODER_MODE_DP) { ++ if (ASIC_IS_DCE4(rdev)) ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_DP_VIDEO_OFF); ++ } + break; + } + } else { +@@ -1026,7 +1076,7 @@ radeon_atom_encoder_dpms(struct drm_encoder *encoder, int mode) + radeon_atombios_encoder_dpms_scratch_regs(encoder, (mode == DRM_MODE_DPMS_ON) ? true : false); + } + +-union crtc_sourc_param { ++union crtc_source_param { + SELECT_CRTC_SOURCE_PS_ALLOCATION v1; + SELECT_CRTC_SOURCE_PARAMETERS_V2 v2; + }; +@@ -1038,7 +1088,7 @@ atombios_set_encoder_crtc_source(struct drm_encoder *encoder) + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); + struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); +- union crtc_sourc_param args; ++ union crtc_source_param args; + int index = GetIndexIntoMasterTable(COMMAND, SelectCRTC_Source); + uint8_t frev, crev; + struct radeon_encoder_atom_dig *dig; +@@ -1107,10 +1157,26 @@ atombios_set_encoder_crtc_source(struct drm_encoder *encoder) + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: + case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: + dig = radeon_encoder->enc_priv; +- if (dig->dig_encoder) +- args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; +- else ++ switch (dig->dig_encoder) { ++ case 0: + args.v2.ucEncoderID = ASIC_INT_DIG1_ENCODER_ID; ++ break; ++ case 1: ++ args.v2.ucEncoderID = ASIC_INT_DIG2_ENCODER_ID; ++ break; ++ case 2: ++ args.v2.ucEncoderID = ASIC_INT_DIG3_ENCODER_ID; ++ break; ++ case 3: ++ args.v2.ucEncoderID = ASIC_INT_DIG4_ENCODER_ID; ++ break; ++ case 4: ++ args.v2.ucEncoderID = ASIC_INT_DIG5_ENCODER_ID; ++ break; ++ case 5: ++ args.v2.ucEncoderID = ASIC_INT_DIG6_ENCODER_ID; ++ break; ++ } + break; + case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_DVO1: + args.v2.ucEncoderID = ASIC_INT_DVO_ENCODER_ID; +@@ -1167,6 +1233,7 @@ atombios_apply_encoder_quirks(struct drm_encoder *encoder, + } + + /* set scaler clears this on some chips */ ++ /* XXX check DCE4 */ + if (!(radeon_encoder->active_device & (ATOM_DEVICE_TV_SUPPORT))) { + if (ASIC_IS_AVIVO(rdev) && (mode->flags & DRM_MODE_FLAG_INTERLACE)) + WREG32(AVIVO_D1MODE_DATA_FORMAT + radeon_crtc->crtc_offset, +@@ -1183,6 +1250,33 @@ static int radeon_atom_pick_dig_encoder(struct drm_encoder *encoder) + struct drm_encoder *test_encoder; + struct radeon_encoder_atom_dig *dig; + uint32_t dig_enc_in_use = 0; ++ ++ if (ASIC_IS_DCE4(rdev)) { ++ struct radeon_connector_atom_dig *dig_connector = ++ radeon_get_atom_connector_priv_from_encoder(encoder); ++ ++ switch (radeon_encoder->encoder_id) { ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY: ++ if (dig_connector->linkb) ++ return 1; ++ else ++ return 0; ++ break; ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: ++ if (dig_connector->linkb) ++ return 3; ++ else ++ return 2; ++ break; ++ case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: ++ if (dig_connector->linkb) ++ return 5; ++ else ++ return 4; ++ break; ++ } ++ } ++ + /* on DCE32 and encoder can driver any block so just crtc id */ + if (ASIC_IS_DCE32(rdev)) { + return radeon_crtc->crtc_id; +@@ -1254,15 +1348,26 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder, + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY1: + case ENCODER_OBJECT_ID_INTERNAL_UNIPHY2: + case ENCODER_OBJECT_ID_INTERNAL_KLDSCP_LVTMA: +- /* disable the encoder and transmitter */ +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); +- atombios_dig_encoder_setup(encoder, ATOM_DISABLE); +- +- /* setup and enable the encoder and transmitter */ +- atombios_dig_encoder_setup(encoder, ATOM_ENABLE); +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0); +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0); +- atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); ++ if (ASIC_IS_DCE4(rdev)) { ++ /* disable the transmitter */ ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); ++ /* setup and enable the encoder */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENCODER_CMD_SETUP); ++ ++ /* init and enable the transmitter */ ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); ++ } else { ++ /* disable the encoder and transmitter */ ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_DISABLE, 0, 0); ++ atombios_dig_encoder_setup(encoder, ATOM_DISABLE); ++ ++ /* setup and enable the encoder and transmitter */ ++ atombios_dig_encoder_setup(encoder, ATOM_ENABLE); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_INIT, 0, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_SETUP, 0, 0); ++ atombios_dig_transmitter_setup(encoder, ATOM_TRANSMITTER_ACTION_ENABLE, 0, 0); ++ } + break; + case ENCODER_OBJECT_ID_INTERNAL_DDI: + atombios_ddia_setup(encoder, ATOM_ENABLE); +@@ -1282,7 +1387,9 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder, + } + atombios_apply_encoder_quirks(encoder, adjusted_mode); + +- r600_hdmi_setmode(encoder, adjusted_mode); ++ /* XXX */ ++ if (!ASIC_IS_DCE4(rdev)) ++ r600_hdmi_setmode(encoder, adjusted_mode); + } + + static bool +@@ -1480,10 +1587,18 @@ radeon_add_atom_encoder(struct drm_device *dev, uint32_t encoder_id, uint32_t su + return; + + encoder = &radeon_encoder->base; +- if (rdev->flags & RADEON_SINGLE_CRTC) ++ switch (rdev->num_crtc) { ++ case 1: + encoder->possible_crtcs = 0x1; +- else ++ break; ++ case 2: ++ default: + encoder->possible_crtcs = 0x3; ++ break; ++ case 6: ++ encoder->possible_crtcs = 0x3f; ++ break; ++ } + + radeon_encoder->enc_priv = NULL; + +diff --git a/drivers/gpu/drm/radeon/radeon_family.h b/drivers/gpu/drm/radeon/radeon_family.h +index 797972e..93c7d5d 100644 +--- a/drivers/gpu/drm/radeon/radeon_family.h ++++ b/drivers/gpu/drm/radeon/radeon_family.h +@@ -75,6 +75,11 @@ enum radeon_family { + CHIP_RV730, + CHIP_RV710, + CHIP_RV740, ++ CHIP_CEDAR, ++ CHIP_REDWOOD, ++ CHIP_JUNIPER, ++ CHIP_CYPRESS, ++ CHIP_HEMLOCK, + CHIP_LAST, + }; + +diff --git a/drivers/gpu/drm/radeon/radeon_fb.c b/drivers/gpu/drm/radeon/radeon_fb.c +index d71e346..0059242 100644 +--- a/drivers/gpu/drm/radeon/radeon_fb.c ++++ b/drivers/gpu/drm/radeon/radeon_fb.c +@@ -148,7 +148,6 @@ int radeonfb_create(struct drm_device *dev, + unsigned long tmp; + bool fb_tiled = false; /* useful for testing */ + u32 tiling_flags = 0; +- int crtc_count; + + mode_cmd.width = surface_width; + mode_cmd.height = surface_height; +@@ -239,11 +238,7 @@ int radeonfb_create(struct drm_device *dev, + rfbdev = info->par; + rfbdev->helper.funcs = &radeon_fb_helper_funcs; + rfbdev->helper.dev = dev; +- if (rdev->flags & RADEON_SINGLE_CRTC) +- crtc_count = 1; +- else +- crtc_count = 2; +- ret = drm_fb_helper_init_crtc_count(&rfbdev->helper, crtc_count, ++ ret = drm_fb_helper_init_crtc_count(&rfbdev->helper, rdev->num_crtc, + RADEONFB_CONN_LIMIT); + if (ret) + goto out_unref; +diff --git a/drivers/gpu/drm/radeon/radeon_mode.h b/drivers/gpu/drm/radeon/radeon_mode.h +index e81b2ae..2f582a2 100644 +--- a/drivers/gpu/drm/radeon/radeon_mode.h ++++ b/drivers/gpu/drm/radeon/radeon_mode.h +@@ -83,6 +83,8 @@ struct radeon_i2c_bus_rec { + bool valid; + /* id used by atom */ + uint8_t i2c_id; ++ /* id used by atom */ ++ uint8_t hpd_id; + /* can be used with hw i2c engine */ + bool hw_capable; + /* uses multi-media i2c engine */ +@@ -193,7 +195,7 @@ struct radeon_mode_info { + struct card_info *atom_card_info; + enum radeon_connector_table connector_table; + bool mode_config_initialized; +- struct radeon_crtc *crtcs[2]; ++ struct radeon_crtc *crtcs[6]; + /* DVI-I properties */ + struct drm_property *coherent_mode_property; + /* DAC enable load detect */ +@@ -237,6 +239,7 @@ struct radeon_crtc { + fixed20_12 vsc; + fixed20_12 hsc; + struct drm_display_mode native_mode; ++ int pll_id; + }; + + struct radeon_encoder_primary_dac { +@@ -398,6 +401,7 @@ extern void dp_link_train(struct drm_encoder *encoder, + struct drm_connector *connector); + extern u8 radeon_dp_getsinktype(struct radeon_connector *radeon_connector); + extern bool radeon_dp_getdpcd(struct radeon_connector *radeon_connector); ++extern void atombios_dig_encoder_setup(struct drm_encoder *encoder, int action); + extern void atombios_dig_transmitter_setup(struct drm_encoder *encoder, + int action, uint8_t lane_num, + uint8_t lane_set); +diff --git a/drivers/gpu/drm/radeon/radeon_reg.h b/drivers/gpu/drm/radeon/radeon_reg.h +index 6d0a009..7f0c752 100644 +--- a/drivers/gpu/drm/radeon/radeon_reg.h ++++ b/drivers/gpu/drm/radeon/radeon_reg.h +@@ -54,7 +54,7 @@ + #include "r300_reg.h" + #include "r500_reg.h" + #include "r600_reg.h" +- ++#include "evergreen_reg.h" + + #define RADEON_MC_AGP_LOCATION 0x014c + #define RADEON_MC_AGP_START_MASK 0x0000FFFF +diff --git a/drivers/gpu/drm/radeon/rv770d.h b/drivers/gpu/drm/radeon/rv770d.h +index a1367ab..9506f8c 100644 +--- a/drivers/gpu/drm/radeon/rv770d.h ++++ b/drivers/gpu/drm/radeon/rv770d.h +@@ -343,4 +343,6 @@ + + #define WAIT_UNTIL 0x8040 + ++#define SRBM_STATUS 0x0E50 ++ + #endif +diff --git a/include/drm/drm_pciids.h b/include/drm/drm_pciids.h +index e6f3b12..403490c 100644 +--- a/include/drm/drm_pciids.h ++++ b/include/drm/drm_pciids.h +@@ -141,6 +141,41 @@ + {0x1002, 0x5e4c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x5e4d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x5e4f, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV410|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6880, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6888, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6889, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x688A, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6898, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x6899, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x689c, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HEMLOCK|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x689d, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_HEMLOCK|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x689e, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CYPRESS|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68a0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68a1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68a8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68a9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68b0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68b8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68b9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68be, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_JUNIPER|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68c0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68c1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68c8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68c9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68d8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68d9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68da, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68de, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_REDWOOD|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68e0, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68e1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68e4, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68e5, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68e8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68e9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68f1, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68f8, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68f9, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x68fe, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_CEDAR|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x7100, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x7101, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x7102, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_R520|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ diff --git a/drm-radeon-firemv-pciid.patch b/drm-radeon-firemv-pciid.patch new file mode 100644 index 000000000..1b4c1295c --- /dev/null +++ b/drm-radeon-firemv-pciid.patch @@ -0,0 +1,30 @@ +From 79b9517a33a283c5d9db875c263670ed1e055f7e Mon Sep 17 00:00:00 2001 +From: Dave Airlie +Date: Mon, 19 Apr 2010 17:54:31 +1000 +Subject: [PATCH] drm/radeon/kms: add FireMV 2400 PCI ID. + +This is an M24/X600 chip. + +From RH# 581927 + +cc: stable@kernel.org +Signed-off-by: Dave Airlie +--- + include/drm/drm_pciids.h | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + +diff --git a/include/drm/drm_pciids.h b/include/drm/drm_pciids.h +index 04a6ebc..2d428b0 100644 +--- a/include/drm/drm_pciids.h ++++ b/include/drm/drm_pciids.h +@@ -6,6 +6,7 @@ + {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \ + {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x3155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP}, \ +-- +1.6.6.1 + diff --git a/drm-radeon-fix-rs600-tlb.patch b/drm-radeon-fix-rs600-tlb.patch new file mode 100644 index 000000000..977dcd36c --- /dev/null +++ b/drm-radeon-fix-rs600-tlb.patch @@ -0,0 +1,32 @@ +From 30f69f3fb20bd719b5e1bf879339914063d38f47 Mon Sep 17 00:00:00 2001 +From: Jerome Glisse +Date: Fri, 16 Apr 2010 18:46:35 +0200 +Subject: [PATCH] drm/radeon/kms: fix rs600 tlb flush + +Typo in in flush leaded to no flush of the RS600 tlb which +ultimately leaded to massive system ram corruption, with +this patch everythings seems to work properly. + +Signed-off-by: Jerome Glisse +Cc: stable +Signed-off-by: Dave Airlie +--- + drivers/gpu/drm/radeon/rs600.c | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/drivers/gpu/drm/radeon/rs600.c b/drivers/gpu/drm/radeon/rs600.c +index abf824c..a81bc7a 100644 +--- a/drivers/gpu/drm/radeon/rs600.c ++++ b/drivers/gpu/drm/radeon/rs600.c +@@ -159,7 +159,7 @@ void rs600_gart_tlb_flush(struct radeon_device *rdev) + WREG32_MC(R_000100_MC_PT0_CNTL, tmp); + + tmp = RREG32_MC(R_000100_MC_PT0_CNTL); +- tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1); ++ tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) | S_000100_INVALIDATE_L2_CACHE(1); + WREG32_MC(R_000100_MC_PT0_CNTL, tmp); + + tmp = RREG32_MC(R_000100_MC_PT0_CNTL); +-- +1.6.6.1 + diff --git a/drm-radeon-kms-fix-dual-link-dvi.patch b/drm-radeon-kms-fix-dual-link-dvi.patch new file mode 100644 index 000000000..3e9d28f36 --- /dev/null +++ b/drm-radeon-kms-fix-dual-link-dvi.patch @@ -0,0 +1,39 @@ +From b317a9ce2259e64258a802a5ca70dec45ac15dda Mon Sep 17 00:00:00 2001 +From: Alex Deucher +Date: Thu, 15 Apr 2010 16:54:38 -0400 +Subject: [PATCH] drm/radeon/kms/atom: fix dual-link DVI on DCE3.2/4.0 + +Got broken during the evergreen merge. +Fixes fdo bug 27001. + +Signed-off-by: Alex Deucher +Signed-off-by: Dave Airlie +--- + drivers/gpu/drm/radeon/radeon_encoders.c | 4 ++++ + 1 files changed, 4 insertions(+), 0 deletions(-) + +diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c +index c52fc30..9f7f56a 100644 +--- a/drivers/gpu/drm/radeon/radeon_encoders.c ++++ b/drivers/gpu/drm/radeon/radeon_encoders.c +@@ -865,6 +865,8 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { + if (dig->coherent_mode) + args.v3.acConfig.fCoherentMode = 1; ++ if (radeon_encoder->pixel_clock > 165000) ++ args.v3.acConfig.fDualLinkConnector = 1; + } + } else if (ASIC_IS_DCE32(rdev)) { + args.v2.acConfig.ucEncoderSel = dig->dig_encoder; +@@ -888,6 +890,8 @@ atombios_dig_transmitter_setup(struct drm_encoder *encoder, int action, uint8_t + else if (radeon_encoder->devices & (ATOM_DEVICE_DFP_SUPPORT)) { + if (dig->coherent_mode) + args.v2.acConfig.fCoherentMode = 1; ++ if (radeon_encoder->pixel_clock > 165000) ++ args.v2.acConfig.fDualLinkConnector = 1; + } + } else { + args.v1.ucConfig = ATOM_TRANSMITTER_CONFIG_CLKSRC_PPLL; +-- +1.6.6.1 + diff --git a/drm-radeon-ss-fix.patch b/drm-radeon-ss-fix.patch new file mode 100644 index 000000000..ae081aa09 --- /dev/null +++ b/drm-radeon-ss-fix.patch @@ -0,0 +1,97 @@ +From 7aac5b711ff4c64bad5a6027cf6d38f1bbd53efe Mon Sep 17 00:00:00 2001 +From: Dave Airlie +Date: Tue, 20 Apr 2010 18:30:37 +1000 +Subject: [PATCH] drm/radeon/kms: further spread spectrum fixes + +Adjust modeset ordering to fix spread spectrum. +The spread spectrum command table relies on the +crtc routing to already be set in order to work +properly on some asics. + +Should fix fdo bug 25741. + +Signed-off-by: Alex Deucher +Signed-off-by: Dave Airlie + +Conflicts: + + drivers/gpu/drm/radeon/atombios_crtc.c +--- + drivers/gpu/drm/radeon/atombios_crtc.c | 5 +++++ + drivers/gpu/drm/radeon/radeon_encoders.c | 25 +++++++++++++++---------- + 2 files changed, 20 insertions(+), 10 deletions(-) + +diff --git a/drivers/gpu/drm/radeon/atombios_crtc.c b/drivers/gpu/drm/radeon/atombios_crtc.c +index c076eac..e70b575 100644 +--- a/drivers/gpu/drm/radeon/atombios_crtc.c ++++ b/drivers/gpu/drm/radeon/atombios_crtc.c +@@ -1115,6 +1115,11 @@ static bool atombios_crtc_mode_fixup(struct drm_crtc *crtc, + + static void atombios_crtc_prepare(struct drm_crtc *crtc) + { ++ struct radeon_crtc *radeon_crtc = to_radeon_crtc(crtc); ++ ++ /* pick pll */ ++ radeon_crtc->pll_id = radeon_atom_pick_pll(crtc); ++ + atombios_lock_crtc(crtc, ATOM_ENABLE); + atombios_crtc_dpms(crtc, DRM_MODE_DPMS_OFF); + } +diff --git a/drivers/gpu/drm/radeon/radeon_encoders.c b/drivers/gpu/drm/radeon/radeon_encoders.c +index cac9e06..ff28ad8 100644 +--- a/drivers/gpu/drm/radeon/radeon_encoders.c ++++ b/drivers/gpu/drm/radeon/radeon_encoders.c +@@ -1207,6 +1207,9 @@ atombios_set_encoder_crtc_source(struct drm_encoder *encoder) + } + + atom_execute_table(rdev->mode_info.atom_context, index, (uint32_t *)&args); ++ ++ /* update scratch regs with new routing */ ++ radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); + } + + static void +@@ -1317,19 +1320,9 @@ radeon_atom_encoder_mode_set(struct drm_encoder *encoder, + struct drm_device *dev = encoder->dev; + struct radeon_device *rdev = dev->dev_private; + struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); +- struct radeon_crtc *radeon_crtc = to_radeon_crtc(encoder->crtc); + +- if (radeon_encoder->active_device & +- (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) { +- struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; +- if (dig) +- dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder); +- } + radeon_encoder->pixel_clock = adjusted_mode->clock; + +- radeon_atombios_encoder_crtc_scratch_regs(encoder, radeon_crtc->crtc_id); +- atombios_set_encoder_crtc_source(encoder); +- + if (ASIC_IS_AVIVO(rdev)) { + if (radeon_encoder->active_device & (ATOM_DEVICE_CV_SUPPORT | ATOM_DEVICE_TV_SUPPORT)) + atombios_yuv_setup(encoder, true); +@@ -1483,8 +1476,20 @@ radeon_atom_dac_detect(struct drm_encoder *encoder, struct drm_connector *connec + + static void radeon_atom_encoder_prepare(struct drm_encoder *encoder) + { ++ struct radeon_encoder *radeon_encoder = to_radeon_encoder(encoder); ++ ++ if (radeon_encoder->active_device & ++ (ATOM_DEVICE_DFP_SUPPORT | ATOM_DEVICE_LCD_SUPPORT)) { ++ struct radeon_encoder_atom_dig *dig = radeon_encoder->enc_priv; ++ if (dig) ++ dig->dig_encoder = radeon_atom_pick_dig_encoder(encoder); ++ } ++ + radeon_atom_output_lock(encoder, true); + radeon_atom_encoder_dpms(encoder, DRM_MODE_DPMS_OFF); ++ ++ /* this is needed for the pll/ss setup to work correctly in some cases */ ++ atombios_set_encoder_crtc_source(encoder); + } + + static void radeon_atom_encoder_commit(struct drm_encoder *encoder) +-- +1.6.5.2 + diff --git a/ext4-issue-discard-operation-before-releasing-blocks.patch b/ext4-issue-discard-operation-before-releasing-blocks.patch new file mode 100644 index 000000000..b2b66f09a --- /dev/null +++ b/ext4-issue-discard-operation-before-releasing-blocks.patch @@ -0,0 +1,62 @@ +From: Theodore Ts'o +Date: Tue, 20 Apr 2010 20:51:59 +0000 (-0400) +Subject: ext4: Issue the discard operation *before* releasing the blocks to be reused +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=b90f687018e6d6c77d981b09203780f7001407e5 + +ext4: Issue the discard operation *before* releasing the blocks to be reused + +[ backported to 2.6.33 ] + +Otherwise, we can end up having data corruption because the blocks +could get reused and then discarded! + +https://bugzilla.kernel.org/show_bug.cgi?id=15579 + +Signed-off-by: "Theodore Ts'o" +--- + +diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c +index 54df209..e5ab41b 100644 +--- a/fs/ext4/mballoc.c ++++ b/fs/ext4/mballoc.c +@@ -2534,6 +2534,20 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) + mb_debug(1, "gonna free %u blocks in group %u (0x%p):", + entry->count, entry->group, entry); + ++ if (test_opt(sb, DISCARD)) { ++ ext4_fsblk_t discard_block; ++ struct ext4_super_block *es = EXT4_SB(sb)->s_es; ++ ++ discard_block = (ext4_fsblk_t)entry->group * ++ EXT4_BLOCKS_PER_GROUP(sb) ++ + entry->start_blk ++ + le32_to_cpu(es->s_first_data_block); ++ trace_ext4_discard_blocks(sb, ++ (unsigned long long)discard_block, ++ entry->count); ++ sb_issue_discard(sb, discard_block, entry->count); ++ } ++ + err = ext4_mb_load_buddy(sb, entry->group, &e4b); + /* we expect to find existing buddy because it's pinned */ + BUG_ON(err != 0); +@@ -2555,19 +2566,6 @@ static void release_blocks_on_commit(journal_t *journal, transaction_t *txn) + page_cache_release(e4b.bd_bitmap_page); + } + ext4_unlock_group(sb, entry->group); +- if (test_opt(sb, DISCARD)) { +- ext4_fsblk_t discard_block; +- struct ext4_super_block *es = EXT4_SB(sb)->s_es; +- +- discard_block = (ext4_fsblk_t)entry->group * +- EXT4_BLOCKS_PER_GROUP(sb) +- + entry->start_blk +- + le32_to_cpu(es->s_first_data_block); +- trace_ext4_discard_blocks(sb, +- (unsigned long long)discard_block, +- entry->count); +- sb_issue_discard(sb, discard_block, entry->count); +- } + kmem_cache_free(ext4_free_ext_cachep, entry); + ext4_mb_release_desc(&e4b); + } diff --git a/find-provides b/find-provides new file mode 100755 index 000000000..b28d1028f --- /dev/null +++ b/find-provides @@ -0,0 +1,44 @@ +#!/usr/bin/python +# +# find-provides: munge the provides dependencies from the kabideps file +# +# This software may be freely redistributed under the terms of the GNU +# General Public License (GPL). +# +# Takes a directory prefix, then outputs the kabideps file contents. + +__author__ = "Jon Masters " +__version__ = "1.0" +__date__ = "Tue 25 Jul 2006 04:00 GMT" +__copyright__ = "Copyright (C) 2006 Red Hat, Inc" +__license__ = "GPL" + +import os +import re +import string +import sys + +false = 0 +true = 1 + +kabideps="" + +p = re.compile('^(.*)/symvers-(.*).gz$') +while true: + foo = sys.stdin.readline() + if foo == "": + break + string.split(foo) + m = p.match(foo) + if m: + kabideps=sys.argv[1] + "/kernel-" + m.group(2) + "-kabideps" + +if kabideps == "": + sys.exit(0) + +if not (os.path.isfile(kabideps)): + sys.stderr.write(sys.argv[0] + ": cannot locate kabideps file: " + kabideps + "\n") + sys.exit(1) + +sys.stderr.write(sys.argv[0] + ": processing kABI: " + kabideps) +os.system("cat " + kabideps) diff --git a/fix-9p-fscache.patch b/fix-9p-fscache.patch new file mode 100644 index 000000000..3376f8911 --- /dev/null +++ b/fix-9p-fscache.patch @@ -0,0 +1,21 @@ +Subject: [PATCH] 9p: fscache: fix build breakage introduced by 201a15428bd54f83eccec8b7c64a04b8f9431204 + +While building 2.6.32-rc8-git2 for Fedora I noticed the following thinko in +201a15428bd54f83eccec8b7c64a04b8f9431204. Patch below looks to be correct? + +Signed-off-by: Kyle McMartin + +--- +diff --git a/fs/9p/cache.c b/fs/9p/cache.c +index bcc5357..e777961 100644 +--- a/fs/9p/cache.c ++++ b/fs/9p/cache.c +@@ -343,7 +343,7 @@ int __v9fs_fscache_release_page(struct page *page, gfp_t gfp) + + BUG_ON(!vcookie->fscache); + +- return fscache_maybe_release_page(vnode->cache, page, gfp); ++ return fscache_maybe_release_page(vcookie->fscache, page, gfp); + } + + void __v9fs_fscache_invalidate_page(struct page *page) diff --git a/fix_xen_guest_on_old_EC2.patch b/fix_xen_guest_on_old_EC2.patch new file mode 100644 index 000000000..e86200295 --- /dev/null +++ b/fix_xen_guest_on_old_EC2.patch @@ -0,0 +1,34 @@ + +Legacy hypervisors (RHEL 5.0 and RHEL 5.1) do not handle guest writes to +cr4 gracefully. If a guest attempts to write a bit of cr4 that is +unsupported, then the HV is so offended it crashes the domain. While +later guest kernels (such as RHEL6) don't assume the HV supports all +features, they do expect nicer responses. That assumption introduced +code that probes whether or not xsave is supported early in the boot. So +now when attempting to boot a RHEL6 guest on RHEL5.0 or RHEL5.1 an early +crash will occur. + +This patch is quite obviously an undesirable hack. The real fix for this +problem should be in the HV, and is, in later HVs. However, to support +running on old HVs, RHEL6 can take this small change. No impact will +occur for running on any RHEL HV (not even RHEL 5.5 supports xsave). +There is only potential for guest performance loss on upstream Xen. + +--- + arch/x86/xen/enlighten.c | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + +diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c +index 52f8e19..6db3d67 100644 +--- a/arch/x86/xen/enlighten.c ++++ b/arch/x86/xen/enlighten.c +@@ -802,6 +802,7 @@ static void xen_write_cr4(unsigned long cr4) + { + cr4 &= ~X86_CR4_PGE; + cr4 &= ~X86_CR4_PSE; ++ cr4 &= ~X86_CR4_OSXSAVE; + + native_write_cr4(cr4); + } +-- +1.6.6.1 diff --git a/genkey b/genkey new file mode 100644 index 000000000..49c6ce8be --- /dev/null +++ b/genkey @@ -0,0 +1,7 @@ +%pubring kernel.pub +%secring kernel.sec +Key-Type: DSA +Key-Length: 512 +Name-Real: Red Hat, Inc. +Name-Comment: Kernel Module GPG key +%commit diff --git a/git-bluetooth.patch b/git-bluetooth.patch new file mode 100644 index 000000000..023f09532 --- /dev/null +++ b/git-bluetooth.patch @@ -0,0 +1,319 @@ +commit 711909b33d6fdee149b5cb58bd888e7c10407acb +Author: Bastien Nocera +Date: Wed Apr 21 15:24:56 2010 +0100 + + Add support for the Wacom Intuos 4 wireless + + And to the HID blacklist. + + Same command set as the Graphire Bluetooth tablet. + + Signed-off-by: Bastien Nocera + +commit 1e03f3dc79ae5a9456545702f6dcac1023b06666 +Author: Antonio Ospite +Date: Thu Apr 29 23:59:34 2010 +0200 + + hid/hid-sony: fix sony_set_operational_bt + + Don't send the report type as part of the data, this prevents the + controller from going into the operational state at all. + + This is completely equivalent to what the code originally meant to accomplish: + as per in net/bluetooth/hidp/core.c::hidp_output_raw_report(), by using + HID_FEATURE_REPORT here, what will be actually sent is + (HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE) which is exactly 0x53. + + Signed-off-by: Antonio Ospite + +commit ea42416024fb33c970dbc10a6c69c0831126d75e +Author: Jiri Kosina +Date: Wed Feb 3 15:52:31 2010 +0100 + + HID: make Wacom modesetting failures non-fatal + + With Wacom tablet mode-setting moved from userspace into kernel, + we don't have to consider failures of device queries through the + _raw callback as hard failure, as the driver can safely continue + anyway. + + This is consistent with the current USB driver in wacom_sys.c + + Reported-by: Ping Cheng + Signed-off-by: Jiri Kosina + +commit a37234f5fcd6ad44ada8c477c2ab531f3ed9fbe5 +Author: Bastien Nocera +Date: Wed Jan 20 12:01:53 2010 +0000 + + HID: Enable Sixaxis controller over Bluetooth + + Now that hid_output_raw_report works, port the PS3 Sixaxis + Bluetooth quirk from user-space, into kernel-space. + + Signed-off-by: Bastien Nocera + Acked-by: Marcel Holtmann + Signed-off-by: Jiri Kosina + +commit 6bc702ac6551532774171d593a805c3565befb4e +Author: Bastien Nocera +Date: Wed Jan 20 12:00:53 2010 +0000 + + HID: Implement Wacom quirk in the kernel + + The hid-wacom driver required user-space to poke at the tablet + to make it send data about the cursor location. + + This patch makes it do the same thing but in the kernel. + + Signed-off-by: Bastien Nocera + Acked-by: Marcel Holtmann + Signed-off-by: Jiri Kosina + +commit 6fd920bdba1752fdd6411a55b3c17e0fda67b8d2 +Author: Jiri Kosina +Date: Fri Jan 29 15:03:36 2010 +0100 + + HID: make raw reports possible for both feature and output reports + + In commit 2da31939a42 ("Bluetooth: Implement raw output support for HIDP + layer"), support for Bluetooth hid_output_raw_report was added, but it + pushes the data to the intr socket instead of the ctrl one. This has been + fixed by 6bf8268f9a91f1 ("Bluetooth: Use the control channel for raw HID reports") + + Still, it is necessary to distinguish whether the report in question should be + either FEATURE or OUTPUT. For this, we have to extend the generic HID API, + so that hid_output_raw_report() callback provides means to specify this + value so that it can be passed down to lower level hardware drivers (currently + Bluetooth and USB). + + Based on original patch by Bastien Nocera + Acked-by: Marcel Holtmann + Signed-off-by: Jiri Kosina + +diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c +index 8455f3d..112568e 100644 +--- a/drivers/hid/hid-core.c ++++ b/drivers/hid/hid-core.c +@@ -1340,6 +1340,7 @@ static const struct hid_device_id hid_blacklist[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_PETALYNX, USB_DEVICE_ID_PETALYNX_MAXTER_REMOTE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SAMSUNG, USB_DEVICE_ID_SAMSUNG_IR_REMOTE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, ++ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SUNPLUS, USB_DEVICE_ID_SUNPLUS_WDESKTOP) }, + { HID_USB_DEVICE(USB_VENDOR_ID_THRUSTMASTER, 0xb300) }, +@@ -1352,6 +1353,7 @@ static const struct hid_device_id hid_blacklist[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_TWINHAN, USB_DEVICE_ID_TWINHAN_IR_REMOTE) }, + { HID_USB_DEVICE(USB_VENDOR_ID_WISEGROUP, USB_DEVICE_ID_SMARTJOY_PLUS) }, + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, ++ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0005) }, + { HID_USB_DEVICE(USB_VENDOR_ID_ZEROPLUS, 0x0030) }, + +diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h +index 793691f..4ccd60b 100644 +--- a/drivers/hid/hid-ids.h ++++ b/drivers/hid/hid-ids.h +@@ -428,6 +428,7 @@ + + #define USB_VENDOR_ID_WACOM 0x056a + #define USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH 0x81 ++#define USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH 0xbd + + #define USB_VENDOR_ID_WISEGROUP 0x0925 + #define USB_DEVICE_ID_SMARTJOY_PLUS 0x0005 +diff --git a/drivers/hid/hid-sony.c b/drivers/hid/hid-sony.c +index 4e84502..e71da89 100644 +--- a/drivers/hid/hid-sony.c ++++ b/drivers/hid/hid-sony.c +@@ -48,7 +48,7 @@ static void sony_report_fixup(struct hid_device *hdev, __u8 *rdesc, + * to "operational". Without this, the ps3 controller will not report any + * events. + */ +-static int sony_set_operational(struct hid_device *hdev) ++static int sony_set_operational_usb(struct hid_device *hdev) + { + struct usb_interface *intf = to_usb_interface(hdev->dev.parent); + struct usb_device *dev = interface_to_usbdev(intf); +@@ -73,6 +73,12 @@ static int sony_set_operational(struct hid_device *hdev) + return ret; + } + ++static int sony_set_operational_bt(struct hid_device *hdev) ++{ ++ unsigned char buf[] = { 0xf4, 0x42, 0x03, 0x00, 0x00 }; ++ return hdev->hid_output_raw_report(hdev, buf, sizeof(buf), HID_FEATURE_REPORT); ++} ++ + static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) + { + int ret; +@@ -101,7 +107,17 @@ static int sony_probe(struct hid_device *hdev, const struct hid_device_id *id) + goto err_free; + } + +- ret = sony_set_operational(hdev); ++ switch (hdev->bus) { ++ case BUS_USB: ++ ret = sony_set_operational_usb(hdev); ++ break; ++ case BUS_BLUETOOTH: ++ ret = sony_set_operational_bt(hdev); ++ break; ++ default: ++ ret = 0; ++ } ++ + if (ret < 0) + goto err_stop; + +@@ -121,6 +137,7 @@ static void sony_remove(struct hid_device *hdev) + + static const struct hid_device_id sony_devices[] = { + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, ++ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_PS3_CONTROLLER) }, + { HID_USB_DEVICE(USB_VENDOR_ID_SONY, USB_DEVICE_ID_SONY_VAIO_VGX_MOUSE), + .driver_data = VAIO_RDESC_CONSTANT }, + { } +diff --git a/drivers/hid/hid-wacom.c b/drivers/hid/hid-wacom.c +index 12dcda5..91dbae3 100644 +--- a/drivers/hid/hid-wacom.c ++++ b/drivers/hid/hid-wacom.c +@@ -156,7 +156,9 @@ static int wacom_probe(struct hid_device *hdev, + struct hid_input *hidinput; + struct input_dev *input; + struct wacom_data *wdata; ++ char rep_data[2]; + int ret; ++ int limit; + + wdata = kzalloc(sizeof(*wdata), GFP_KERNEL); + if (wdata == NULL) { +@@ -166,6 +168,7 @@ static int wacom_probe(struct hid_device *hdev, + + hid_set_drvdata(hdev, wdata); + ++ /* Parse the HID report now */ + ret = hid_parse(hdev); + if (ret) { + dev_err(&hdev->dev, "parse failed\n"); +@@ -178,6 +181,31 @@ static int wacom_probe(struct hid_device *hdev, + goto err_free; + } + ++ /* ++ * Note that if the raw queries fail, it's not a hard failure and it ++ * is safe to continue ++ */ ++ ++ /* Set Wacom mode2 */ ++ rep_data[0] = 0x03; rep_data[1] = 0x00; ++ limit = 3; ++ do { ++ ret = hdev->hid_output_raw_report(hdev, rep_data, 2, ++ HID_FEATURE_REPORT); ++ } while (ret < 0 && limit-- > 0); ++ if (ret < 0) ++ dev_warn(&hdev->dev, "failed to poke device #1, %d\n", ret); ++ ++ /* 0x06 - high reporting speed, 0x05 - low speed */ ++ rep_data[0] = 0x06; rep_data[1] = 0x00; ++ limit = 3; ++ do { ++ ret = hdev->hid_output_raw_report(hdev, rep_data, 2, ++ HID_FEATURE_REPORT); ++ } while (ret < 0 && limit-- > 0); ++ if (ret < 0) ++ dev_warn(&hdev->dev, "failed to poke device #2, %d\n", ret); ++ + hidinput = list_entry(hdev->inputs.next, struct hid_input, list); + input = hidinput->input; + +@@ -228,7 +256,7 @@ static void wacom_remove(struct hid_device *hdev) + + static const struct hid_device_id wacom_devices[] = { + { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_GRAPHIRE_BLUETOOTH) }, +- ++ { HID_BLUETOOTH_DEVICE(USB_VENDOR_ID_WACOM, USB_DEVICE_ID_WACOM_INTUOS4_BLUETOOTH) }, + { } + }; + MODULE_DEVICE_TABLE(hid, wacom_devices); +diff --git a/drivers/hid/hidraw.c b/drivers/hid/hidraw.c +index cdd1369..d044767 100644 +--- a/drivers/hid/hidraw.c ++++ b/drivers/hid/hidraw.c +@@ -134,7 +134,7 @@ static ssize_t hidraw_write(struct file *file, const char __user *buffer, size_t + goto out; + } + +- ret = dev->hid_output_raw_report(dev, buf, count); ++ ret = dev->hid_output_raw_report(dev, buf, count, HID_OUTPUT_REPORT); + out: + kfree(buf); + return ret; +diff --git a/drivers/hid/usbhid/hid-core.c b/drivers/hid/usbhid/hid-core.c +index 2f84237..83c9f94 100644 +--- a/drivers/hid/usbhid/hid-core.c ++++ b/drivers/hid/usbhid/hid-core.c +@@ -798,7 +798,8 @@ static int hid_alloc_buffers(struct usb_device *dev, struct hid_device *hid) + return 0; + } + +-static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count) ++static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t count, ++ unsigned char report_type) + { + struct usbhid_device *usbhid = hid->driver_data; + struct usb_device *dev = hid_to_usb_dev(hid); +@@ -809,7 +810,7 @@ static int usbhid_output_raw_report(struct hid_device *hid, __u8 *buf, size_t co + ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), + HID_REQ_SET_REPORT, + USB_DIR_OUT | USB_TYPE_CLASS | USB_RECIP_INTERFACE, +- ((HID_OUTPUT_REPORT + 1) << 8) | *buf, ++ ((report_type + 1) << 8) | *buf, + interface->desc.bInterfaceNumber, buf + 1, count - 1, + USB_CTRL_SET_TIMEOUT); + +diff --git a/include/linux/hid.h b/include/linux/hid.h +index 8709365..3661a62 100644 +--- a/include/linux/hid.h ++++ b/include/linux/hid.h +@@ -501,7 +501,7 @@ struct hid_device { /* device report descriptor */ + void (*hiddev_report_event) (struct hid_device *, struct hid_report *); + + /* handler for raw output data, used by hidraw */ +- int (*hid_output_raw_report) (struct hid_device *, __u8 *, size_t); ++ int (*hid_output_raw_report) (struct hid_device *, __u8 *, size_t, unsigned char); + + /* debugging support via debugfs */ + unsigned short debug; +diff --git a/net/bluetooth/hidp/core.c b/net/bluetooth/hidp/core.c +index fc6ec1e..280529a 100644 +--- a/net/bluetooth/hidp/core.c ++++ b/net/bluetooth/hidp/core.c +@@ -313,10 +313,21 @@ static int hidp_send_report(struct hidp_session *session, struct hid_report *rep + return hidp_queue_report(session, buf, rsize); + } + +-static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count) ++static int hidp_output_raw_report(struct hid_device *hid, unsigned char *data, size_t count, ++ unsigned char report_type) + { +- if (hidp_send_ctrl_message(hid->driver_data, +- HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE, ++ switch (report_type) { ++ case HID_FEATURE_REPORT: ++ report_type = HIDP_TRANS_SET_REPORT | HIDP_DATA_RTYPE_FEATURE; ++ break; ++ case HID_OUTPUT_REPORT: ++ report_type = HIDP_TRANS_DATA | HIDP_DATA_RTYPE_OUPUT; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ if (hidp_send_ctrl_message(hid->driver_data, report_type, + data, count)) + return -ENOMEM; + return count; diff --git a/git-cpufreq.patch b/git-cpufreq.patch new file mode 100644 index 000000000..e69de29bb diff --git a/git-linus.diff b/git-linus.diff new file mode 100644 index 000000000..8de691e33 --- /dev/null +++ b/git-linus.diff @@ -0,0 +1,1812 @@ +Rollup of the following patches from 2.6.34.4: + +(Patches commented out with '#' did not apply and have been dropped +for now.) + +x86-vmware-preset-lpj-values-when-on-vmware.patch # from 2.6.32.19 +ata_piix-fix-locking-around-sidpr-access.patch +powerpc-fix-build-with-make-3.82.patch +x86-kmmio-mmiotrace-fix-double-free-of-kmmio_fault_pages.patch +#x86-pci-use-host-bridge-_crs-info-on-asrock-alivesata2-glan.patch +x86-add-memory-modify-constraints-to-xchg-and-cmpxchg.patch +#staging-rt2870-add-usb-id-for-belkin-f6d4050-v2.patch +staging-line6-needs-to-select-snd_pcm.patch +staging-panel-prevent-double-calling-of-parport_release-fix-oops.patch +pci-do-not-run-nvidia-quirks-related-to-msi-with-msi-disabled.patch +pci-disable-msi-on-via-k8m800.patch +solos-pci-fix-race-condition-in-tasklet-rx-handling.patch +splice-fix-misuse-of-splice_f_nonblock.patch +#char-nozomi-fix-tty-count-counting.patch +#char-nozomi-set-tty-driver_data-appropriately.patch +mm-fix-corruption-of-hibernation-caused-by-reusing-swap-during-image-saving.patch +drivers-video-w100fb.c-ignore-void-return-value-fix-build-failure.patch +iwlwifi-fix-tx-tracer.patch +ide-cd-do-not-access-completed-requests-in-the-irq-handler.patch +md-raid10-fix-deadlock-with-unaligned-read-during-resync.patch +blkdev-cgroup-whitelist-permission-fix.patch +ecryptfs-handle-ioctl-calls-with-unlocked-and-compat-functions.patch +ecryptfs-release-reference-to-lower-mount-if-interpose-fails.patch +fs-ecryptfs-file.c-introduce-missing-free.patch +pxa-cm-x300-fix-ffuart-registration.patch +signalfd-fill-in-ssi_int-for-posix-timers-and-message-queues.patch +bio-fs-update-rwa_mask-reada-and-swrite-to-match-the-corresponding-bio_rw_-bits.patch +smsc911x-add-spinlocks-around-registers-access.patch +#arm-6299-1-errata-tlbiasidis-and-tlbimvais-operations-can-broadcast-a-faulty-asid.patch +arm-6280-1-imx-fix-build-failure-when-including-mach-gpio.h-without-linux-spinlock.h.patch +usb-ehci-remove-pci-assumption.patch +usb-resizing-usbmon-binary-interface-buffer-causes-protection-faults.patch +#usb-delay-init-quirk-for-logitech-harmony-700-series-devices.patch +usb-serial-enabling-support-for-segway-rmp-in-ftdi_sio.patch +usb-option-huawei-ets-1220-support-added.patch +usb-option-add-huawei-k3765-k4505-devices-to-work-properly.patch +usb-ftdi_sio-device-id-for-navitator.patch +usb-cp210x-add-four-new-device-ids.patch +usb-usbtest-avoid-to-free-coherent-buffer-in-atomic-context.patch +usb-fix-thread-unsafe-anchor-utiliy-routines.patch +drm-edid-fix-the-hdtv-hack-sync-adjustment.patch +bluetooth-added-support-for-controller-shipped-with-imac-i5.patch +mtd-gen_nand-fix-support-for-multiple-chips.patch +jfs-don-t-allow-os2-xattr-namespace-overlap-with-others.patch +arp_notify-allow-drivers-to-explicitly-request-a-notification-event.patch +xen-netfront-explicitly-generate-arp_notify-event-after-migration.patch +net-fix-netdev_notify_peers-to-not-conflict-with-netdev_bonding_deslave.patch +irq-add-new-irq-flag-irqf_no_suspend.patch +xen-do-not-suspend-ipi-irqs.patch +drm-i915-use-rsen-instead-of-htplg-for-tfp410-monitor-detection.patch +#i915-fix-ironlake-edp-panel-setup-v4.patch +ibmvfc-fix-command-completion-handling.patch +ibmvfc-reduce-error-recovery-timeout.patch +md-raid1-delay-reads-that-could-overtake-behind-writes.patch +mm-keep-a-guard-page-below-a-grow-down-stack-segment.patch +mm-fix-missing-page-table-unmap-for-stack-guard-page-failure-case.patch +x86-don-t-send-sigbus-for-kernel-page-faults.patch + +--- vanilla-2.6.33.7.orig/arch/arm/plat-mxc/include/mach/gpio.h ++++ vanilla-2.6.33.7/arch/arm/plat-mxc/include/mach/gpio.h +@@ -19,6 +19,7 @@ + #ifndef __ASM_ARCH_MXC_GPIO_H__ + #define __ASM_ARCH_MXC_GPIO_H__ + ++#include + #include + #include + +--- vanilla-2.6.33.7.orig/mm/memory.c ++++ vanilla-2.6.33.7/mm/memory.c +@@ -2655,6 +2655,26 @@ out_release: + } + + /* ++ * This is like a special single-page "expand_downwards()", ++ * except we must first make sure that 'address-PAGE_SIZE' ++ * doesn't hit another vma. ++ * ++ * The "find_vma()" will do the right thing even if we wrap ++ */ ++static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address) ++{ ++ address &= PAGE_MASK; ++ if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) { ++ address -= PAGE_SIZE; ++ if (find_vma(vma->vm_mm, address) != vma) ++ return -ENOMEM; ++ ++ expand_stack(vma, address); ++ } ++ return 0; ++} ++ ++/* + * We enter with non-exclusive mmap_sem (to exclude vma changes, + * but allow concurrent faults), and pte mapped but not yet locked. + * We return with mmap_sem still held, but pte unmapped and unlocked. +@@ -2667,6 +2687,11 @@ static int do_anonymous_page(struct mm_s + spinlock_t *ptl; + pte_t entry; + ++ if (check_stack_guard_page(vma, address) < 0) { ++ pte_unmap(page_table); ++ return VM_FAULT_SIGBUS; ++ } ++ + if (!(flags & FAULT_FLAG_WRITE)) { + entry = pte_mkspecial(pfn_pte(my_zero_pfn(address), + vma->vm_page_prot)); +--- vanilla-2.6.33.7.orig/arch/x86/kernel/cpu/vmware.c ++++ vanilla-2.6.33.7/arch/x86/kernel/cpu/vmware.c +@@ -22,6 +22,7 @@ + */ + + #include ++#include + #include + #include + #include +@@ -50,7 +51,7 @@ static inline int __vmware_platform(void + + static unsigned long vmware_get_tsc_khz(void) + { +- uint64_t tsc_hz; ++ uint64_t tsc_hz, lpj; + uint32_t eax, ebx, ecx, edx; + + VMWARE_PORT(GETHZ, eax, ebx, ecx, edx); +@@ -61,6 +62,13 @@ static unsigned long vmware_get_tsc_khz( + printk(KERN_INFO "TSC freq read from hypervisor : %lu.%03lu MHz\n", + (unsigned long) tsc_hz / 1000, + (unsigned long) tsc_hz % 1000); ++ ++ if (!preset_lpj) { ++ lpj = ((u64)tsc_hz * 1000); ++ do_div(lpj, HZ); ++ preset_lpj = lpj; ++ } ++ + return tsc_hz; + } + +--- vanilla-2.6.33.7.orig/drivers/ata/ata_piix.c ++++ vanilla-2.6.33.7/drivers/ata/ata_piix.c +@@ -157,6 +157,7 @@ struct piix_map_db { + struct piix_host_priv { + const int *map; + u32 saved_iocfg; ++ spinlock_t sidpr_lock; /* FIXME: remove once locking in EH is fixed */ + void __iomem *sidpr; + }; + +@@ -948,12 +949,15 @@ static int piix_sidpr_scr_read(struct at + unsigned int reg, u32 *val) + { + struct piix_host_priv *hpriv = link->ap->host->private_data; ++ unsigned long flags; + + if (reg >= ARRAY_SIZE(piix_sidx_map)) + return -EINVAL; + ++ spin_lock_irqsave(&hpriv->sidpr_lock, flags); + piix_sidpr_sel(link, reg); + *val = ioread32(hpriv->sidpr + PIIX_SIDPR_DATA); ++ spin_unlock_irqrestore(&hpriv->sidpr_lock, flags); + return 0; + } + +@@ -961,12 +965,15 @@ static int piix_sidpr_scr_write(struct a + unsigned int reg, u32 val) + { + struct piix_host_priv *hpriv = link->ap->host->private_data; ++ unsigned long flags; + + if (reg >= ARRAY_SIZE(piix_sidx_map)) + return -EINVAL; + ++ spin_lock_irqsave(&hpriv->sidpr_lock, flags); + piix_sidpr_sel(link, reg); + iowrite32(val, hpriv->sidpr + PIIX_SIDPR_DATA); ++ spin_unlock_irqrestore(&hpriv->sidpr_lock, flags); + return 0; + } + +@@ -1555,6 +1562,7 @@ static int __devinit piix_init_one(struc + hpriv = devm_kzalloc(dev, sizeof(*hpriv), GFP_KERNEL); + if (!hpriv) + return -ENOMEM; ++ spin_lock_init(&hpriv->sidpr_lock); + + /* Save IOCFG, this will be used for cable detection, quirk + * detection and restoration on detach. This is necessary +--- vanilla-2.6.33.7.orig/arch/powerpc/Makefile ++++ vanilla-2.6.33.7/arch/powerpc/Makefile +@@ -158,9 +158,11 @@ drivers-$(CONFIG_OPROFILE) += arch/power + # Default to zImage, override when needed + all: zImage + +-BOOT_TARGETS = zImage zImage.initrd uImage zImage% dtbImage% treeImage.% cuImage.% simpleImage.% ++# With make 3.82 we cannot mix normal and wildcard targets ++BOOT_TARGETS1 := zImage zImage.initrd uImaged ++BOOT_TARGETS2 := zImage% dtbImage% treeImage.% cuImage.% simpleImage.% + +-PHONY += $(BOOT_TARGETS) ++PHONY += $(BOOT_TARGETS1) $(BOOT_TARGETS2) + + boot := arch/$(ARCH)/boot + +@@ -175,10 +177,16 @@ relocs_check: arch/powerpc/relocs_check. + zImage: relocs_check + endif + +-$(BOOT_TARGETS): vmlinux ++$(BOOT_TARGETS1): vmlinux ++ $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) ++$(BOOT_TARGETS2): vmlinux ++ $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) ++ ++ ++bootwrapper_install: + $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) + +-bootwrapper_install %.dtb: ++%.dtb: + $(Q)$(MAKE) ARCH=ppc64 $(build)=$(boot) $(patsubst %,$(boot)/%,$@) + + define archhelp +--- vanilla-2.6.33.7.orig/arch/x86/mm/kmmio.c ++++ vanilla-2.6.33.7/arch/x86/mm/kmmio.c +@@ -44,6 +44,8 @@ struct kmmio_fault_page { + * Protected by kmmio_lock, when linked into kmmio_page_table. + */ + int count; ++ ++ bool scheduled_for_release; + }; + + struct kmmio_delayed_release { +@@ -397,8 +399,11 @@ static void release_kmmio_fault_page(uns + BUG_ON(f->count < 0); + if (!f->count) { + disarm_kmmio_fault_page(f); +- f->release_next = *release_list; +- *release_list = f; ++ if (!f->scheduled_for_release) { ++ f->release_next = *release_list; ++ *release_list = f; ++ f->scheduled_for_release = true; ++ } + } + } + +@@ -470,8 +475,10 @@ static void remove_kmmio_fault_pages(str + prevp = &f->release_next; + } else { + *prevp = f->release_next; ++ f->release_next = NULL; ++ f->scheduled_for_release = false; + } +- f = f->release_next; ++ f = *prevp; + } + spin_unlock_irqrestore(&kmmio_lock, flags); + +@@ -509,6 +516,9 @@ void unregister_kmmio_probe(struct kmmio + kmmio_count--; + spin_unlock_irqrestore(&kmmio_lock, flags); + ++ if (!release_list) ++ return; ++ + drelease = kmalloc(sizeof(*drelease), GFP_ATOMIC); + if (!drelease) { + pr_crit("leaking kmmio_fault_page objects.\n"); +--- vanilla-2.6.33.7.orig/arch/x86/mm/testmmiotrace.c ++++ vanilla-2.6.33.7/arch/x86/mm/testmmiotrace.c +@@ -90,6 +90,27 @@ static void do_test(unsigned long size) + iounmap(p); + } + ++/* ++ * Tests how mmiotrace behaves in face of multiple ioremap / iounmaps in ++ * a short time. We had a bug in deferred freeing procedure which tried ++ * to free this region multiple times (ioremap can reuse the same address ++ * for many mappings). ++ */ ++static void do_test_bulk_ioremapping(void) ++{ ++ void __iomem *p; ++ int i; ++ ++ for (i = 0; i < 10; ++i) { ++ p = ioremap_nocache(mmio_address, PAGE_SIZE); ++ if (p) ++ iounmap(p); ++ } ++ ++ /* Force freeing. If it will crash we will know why. */ ++ synchronize_rcu(); ++} ++ + static int __init init(void) + { + unsigned long size = (read_far) ? (8 << 20) : (16 << 10); +@@ -104,6 +125,7 @@ static int __init init(void) + "and writing 16 kB of rubbish in there.\n", + size >> 10, mmio_address); + do_test(size); ++ do_test_bulk_ioremapping(); + pr_info("All done.\n"); + return 0; + } +--- vanilla-2.6.33.7.orig/arch/x86/include/asm/cmpxchg_32.h ++++ vanilla-2.6.33.7/arch/x86/include/asm/cmpxchg_32.h +@@ -27,20 +27,20 @@ struct __xchg_dummy { + switch (size) { \ + case 1: \ + asm volatile("xchgb %b0,%1" \ +- : "=q" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=q" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + case 2: \ + asm volatile("xchgw %w0,%1" \ +- : "=r" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=r" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + case 4: \ + asm volatile("xchgl %0,%1" \ +- : "=r" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=r" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + default: \ +@@ -70,14 +70,14 @@ static inline void __set_64bit(unsigned + unsigned int low, unsigned int high) + { + asm volatile("\n1:\t" +- "movl (%0), %%eax\n\t" +- "movl 4(%0), %%edx\n\t" +- LOCK_PREFIX "cmpxchg8b (%0)\n\t" ++ "movl (%1), %%eax\n\t" ++ "movl 4(%1), %%edx\n\t" ++ LOCK_PREFIX "cmpxchg8b (%1)\n\t" + "jnz 1b" +- : /* no outputs */ +- : "D"(ptr), +- "b"(low), +- "c"(high) ++ : "=m" (*ptr) ++ : "D" (ptr), ++ "b" (low), ++ "c" (high) + : "ax", "dx", "memory"); + } + +@@ -121,21 +121,21 @@ extern void __cmpxchg_wrong_size(void); + __typeof__(*(ptr)) __new = (new); \ + switch (size) { \ + case 1: \ +- asm volatile(lock "cmpxchgb %b1,%2" \ +- : "=a"(__ret) \ +- : "q"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgb %b2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "q" (__new), "0" (__old) \ + : "memory"); \ + break; \ + case 2: \ +- asm volatile(lock "cmpxchgw %w1,%2" \ +- : "=a"(__ret) \ +- : "r"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgw %w2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "r" (__new), "0" (__old) \ + : "memory"); \ + break; \ + case 4: \ +- asm volatile(lock "cmpxchgl %1,%2" \ +- : "=a"(__ret) \ +- : "r"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgl %2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "r" (__new), "0" (__old) \ + : "memory"); \ + break; \ + default: \ +@@ -180,12 +180,12 @@ static inline unsigned long long __cmpxc + unsigned long long new) + { + unsigned long long prev; +- asm volatile(LOCK_PREFIX "cmpxchg8b %3" +- : "=A"(prev) +- : "b"((unsigned long)new), +- "c"((unsigned long)(new >> 32)), +- "m"(*__xg(ptr)), +- "0"(old) ++ asm volatile(LOCK_PREFIX "cmpxchg8b %1" ++ : "=A" (prev), ++ "+m" (*__xg(ptr)) ++ : "b" ((unsigned long)new), ++ "c" ((unsigned long)(new >> 32)), ++ "0" (old) + : "memory"); + return prev; + } +@@ -195,12 +195,12 @@ static inline unsigned long long __cmpxc + unsigned long long new) + { + unsigned long long prev; +- asm volatile("cmpxchg8b %3" +- : "=A"(prev) +- : "b"((unsigned long)new), +- "c"((unsigned long)(new >> 32)), +- "m"(*__xg(ptr)), +- "0"(old) ++ asm volatile("cmpxchg8b %1" ++ : "=A" (prev), ++ "+m" (*__xg(ptr)) ++ : "b" ((unsigned long)new), ++ "c" ((unsigned long)(new >> 32)), ++ "0" (old) + : "memory"); + return prev; + } +--- vanilla-2.6.33.7.orig/arch/x86/include/asm/cmpxchg_64.h ++++ vanilla-2.6.33.7/arch/x86/include/asm/cmpxchg_64.h +@@ -26,26 +26,26 @@ extern void __cmpxchg_wrong_size(void); + switch (size) { \ + case 1: \ + asm volatile("xchgb %b0,%1" \ +- : "=q" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=q" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + case 2: \ + asm volatile("xchgw %w0,%1" \ +- : "=r" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=r" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + case 4: \ + asm volatile("xchgl %k0,%1" \ +- : "=r" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=r" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + case 8: \ + asm volatile("xchgq %0,%1" \ +- : "=r" (__x) \ +- : "m" (*__xg(ptr)), "0" (__x) \ ++ : "=r" (__x), "+m" (*__xg(ptr)) \ ++ : "0" (__x) \ + : "memory"); \ + break; \ + default: \ +@@ -71,27 +71,27 @@ extern void __cmpxchg_wrong_size(void); + __typeof__(*(ptr)) __new = (new); \ + switch (size) { \ + case 1: \ +- asm volatile(lock "cmpxchgb %b1,%2" \ +- : "=a"(__ret) \ +- : "q"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgb %b2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "q" (__new), "0" (__old) \ + : "memory"); \ + break; \ + case 2: \ +- asm volatile(lock "cmpxchgw %w1,%2" \ +- : "=a"(__ret) \ +- : "r"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgw %w2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "r" (__new), "0" (__old) \ + : "memory"); \ + break; \ + case 4: \ +- asm volatile(lock "cmpxchgl %k1,%2" \ +- : "=a"(__ret) \ +- : "r"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgl %k2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "r" (__new), "0" (__old) \ + : "memory"); \ + break; \ + case 8: \ +- asm volatile(lock "cmpxchgq %1,%2" \ +- : "=a"(__ret) \ +- : "r"(__new), "m"(*__xg(ptr)), "0"(__old) \ ++ asm volatile(lock "cmpxchgq %2,%1" \ ++ : "=a" (__ret), "+m" (*__xg(ptr)) \ ++ : "r" (__new), "0" (__old) \ + : "memory"); \ + break; \ + default: \ +--- vanilla-2.6.33.7.orig/drivers/staging/line6/Kconfig ++++ vanilla-2.6.33.7/drivers/staging/line6/Kconfig +@@ -2,6 +2,7 @@ config LINE6_USB + tristate "Line6 USB support" + depends on USB && SND + select SND_RAWMIDI ++ select SND_PCM + help + This is a driver for the guitar amp, cab, and effects modeller + PODxt Pro by Line6 (and similar devices), supporting the +--- vanilla-2.6.33.7.orig/drivers/staging/panel/panel.c ++++ vanilla-2.6.33.7/drivers/staging/panel/panel.c +@@ -2181,6 +2181,7 @@ int panel_init(void) + if (pprt) { + parport_release(pprt); + parport_unregister_device(pprt); ++ pprt = NULL; + } + parport_unregister_driver(&panel_driver); + printk(KERN_ERR "Panel driver version " PANEL_VERSION +@@ -2230,6 +2231,7 @@ static void __exit panel_cleanup_module( + /* TODO: free all input signals */ + parport_release(pprt); + parport_unregister_device(pprt); ++ pprt = NULL; + } + parport_unregister_driver(&panel_driver); + } +--- vanilla-2.6.33.7.orig/drivers/pci/quirks.c ++++ vanilla-2.6.33.7/drivers/pci/quirks.c +@@ -2105,6 +2105,7 @@ DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AT + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3336, quirk_disable_all_msi); + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3351, quirk_disable_all_msi); + DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3364, quirk_disable_all_msi); ++DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8380_0, quirk_disable_all_msi); + + /* Disable MSI on chipsets that are known to not support it */ + static void __devinit quirk_disable_msi(struct pci_dev *dev) +@@ -2377,6 +2378,9 @@ static void __devinit __nv_msi_ht_cap_qu + int pos; + int found; + ++ if (!pci_msi_enabled()) ++ return; ++ + /* check if there is HT MSI cap or enabled on this device */ + found = ht_check_msi_mapping(dev); + +--- vanilla-2.6.33.7.orig/drivers/atm/solos-pci.c ++++ vanilla-2.6.33.7/drivers/atm/solos-pci.c +@@ -780,7 +780,8 @@ static struct atm_vcc *find_vcc(struct a + sk_for_each(s, node, head) { + vcc = atm_sk(s); + if (vcc->dev == dev && vcc->vci == vci && +- vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE) ++ vcc->vpi == vpi && vcc->qos.rxtp.traffic_class != ATM_NONE && ++ test_bit(ATM_VF_READY, &vcc->flags)) + goto out; + } + vcc = NULL; +@@ -906,6 +907,10 @@ static void pclose(struct atm_vcc *vcc) + clear_bit(ATM_VF_ADDR, &vcc->flags); + clear_bit(ATM_VF_READY, &vcc->flags); + ++ /* Hold up vcc_destroy_socket() (our caller) until solos_bh() in the ++ tasklet has finished processing any incoming packets (and, more to ++ the point, using the vcc pointer). */ ++ tasklet_unlock_wait(&card->tlet); + return; + } + +--- vanilla-2.6.33.7.orig/fs/splice.c ++++ vanilla-2.6.33.7/fs/splice.c +@@ -365,17 +365,7 @@ __generic_file_splice_read(struct file * + * If the page isn't uptodate, we may need to start io on it + */ + if (!PageUptodate(page)) { +- /* +- * If in nonblock mode then dont block on waiting +- * for an in-flight io page +- */ +- if (flags & SPLICE_F_NONBLOCK) { +- if (!trylock_page(page)) { +- error = -EAGAIN; +- break; +- } +- } else +- lock_page(page); ++ lock_page(page); + + /* + * Page was truncated, or invalidated by the +--- vanilla-2.6.33.7.orig/mm/swapfile.c ++++ vanilla-2.6.33.7/mm/swapfile.c +@@ -315,8 +315,10 @@ checks: + if (offset > si->highest_bit) + scan_base = offset = si->lowest_bit; + +- /* reuse swap entry of cache-only swap if not busy. */ +- if (vm_swap_full() && si->swap_map[offset] == SWAP_HAS_CACHE) { ++ /* reuse swap entry of cache-only swap if not hibernation. */ ++ if (vm_swap_full() ++ && usage == SWAP_HAS_CACHE ++ && si->swap_map[offset] == SWAP_HAS_CACHE) { + int swap_was_freed; + spin_unlock(&swap_lock); + swap_was_freed = __try_to_reclaim_swap(si, offset); +--- vanilla-2.6.33.7.orig/drivers/video/w100fb.c ++++ vanilla-2.6.33.7/drivers/video/w100fb.c +@@ -857,9 +857,9 @@ unsigned long w100fb_gpio_read(int port) + void w100fb_gpio_write(int port, unsigned long value) + { + if (port==W100_GPIO_PORT_A) +- value = writel(value, remapped_regs + mmGPIO_DATA); ++ writel(value, remapped_regs + mmGPIO_DATA); + else +- value = writel(value, remapped_regs + mmGPIO_DATA2); ++ writel(value, remapped_regs + mmGPIO_DATA2); + } + EXPORT_SYMBOL(w100fb_gpio_read); + EXPORT_SYMBOL(w100fb_gpio_write); +--- vanilla-2.6.33.7.orig/drivers/net/wireless/iwlwifi/iwl-devtrace.h ++++ vanilla-2.6.33.7/drivers/net/wireless/iwlwifi/iwl-devtrace.h +@@ -150,7 +150,7 @@ TRACE_EVENT(iwlwifi_dev_tx, + __entry->framelen = buf0_len + buf1_len; + memcpy(__get_dynamic_array(tfd), tfd, tfdlen); + memcpy(__get_dynamic_array(buf0), buf0, buf0_len); +- memcpy(__get_dynamic_array(buf1), buf1, buf0_len); ++ memcpy(__get_dynamic_array(buf1), buf1, buf1_len); + ), + TP_printk("[%p] TX %.2x (%zu bytes)", + __entry->priv, +--- vanilla-2.6.33.7.orig/drivers/ide/ide-cd.c ++++ vanilla-2.6.33.7/drivers/ide/ide-cd.c +@@ -506,15 +506,22 @@ int ide_cd_queue_pc(ide_drive_t *drive, + return (flags & REQ_FAILED) ? -EIO : 0; + } + +-static void ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd) ++/* ++ * returns true if rq has been completed ++ */ ++static bool ide_cd_error_cmd(ide_drive_t *drive, struct ide_cmd *cmd) + { + unsigned int nr_bytes = cmd->nbytes - cmd->nleft; + + if (cmd->tf_flags & IDE_TFLAG_WRITE) + nr_bytes -= cmd->last_xfer_len; + +- if (nr_bytes > 0) ++ if (nr_bytes > 0) { + ide_complete_rq(drive, 0, nr_bytes); ++ return true; ++ } ++ ++ return false; + } + + static ide_startstop_t cdrom_newpc_intr(ide_drive_t *drive) +@@ -679,7 +686,8 @@ out_end: + } + + if (uptodate == 0 && rq->bio) +- ide_cd_error_cmd(drive, cmd); ++ if (ide_cd_error_cmd(drive, cmd)) ++ return ide_stopped; + + /* make sure it's fully ended */ + if (blk_fs_request(rq) == 0) { +--- vanilla-2.6.33.7.orig/drivers/md/raid10.c ++++ vanilla-2.6.33.7/drivers/md/raid10.c +@@ -824,11 +824,29 @@ static int make_request(struct request_q + */ + bp = bio_split(bio, + chunk_sects - (bio->bi_sector & (chunk_sects - 1)) ); ++ ++ /* Each of these 'make_request' calls will call 'wait_barrier'. ++ * If the first succeeds but the second blocks due to the resync ++ * thread raising the barrier, we will deadlock because the ++ * IO to the underlying device will be queued in generic_make_request ++ * and will never complete, so will never reduce nr_pending. ++ * So increment nr_waiting here so no new raise_barriers will ++ * succeed, and so the second wait_barrier cannot block. ++ */ ++ spin_lock_irq(&conf->resync_lock); ++ conf->nr_waiting++; ++ spin_unlock_irq(&conf->resync_lock); ++ + if (make_request(q, &bp->bio1)) + generic_make_request(&bp->bio1); + if (make_request(q, &bp->bio2)) + generic_make_request(&bp->bio2); + ++ spin_lock_irq(&conf->resync_lock); ++ conf->nr_waiting--; ++ wake_up(&conf->wait_barrier); ++ spin_unlock_irq(&conf->resync_lock); ++ + bio_pair_release(bp); + return 0; + bad_map: +--- vanilla-2.6.33.7.orig/fs/block_dev.c ++++ vanilla-2.6.33.7/fs/block_dev.c +@@ -1185,10 +1185,12 @@ static int __blkdev_get(struct block_dev + /* + * hooks: /n/, see "layering violations". + */ +- ret = devcgroup_inode_permission(bdev->bd_inode, perm); +- if (ret != 0) { +- bdput(bdev); +- return ret; ++ if (!for_part) { ++ ret = devcgroup_inode_permission(bdev->bd_inode, perm); ++ if (ret != 0) { ++ bdput(bdev); ++ return ret; ++ } + } + + lock_kernel(); +--- vanilla-2.6.33.7.orig/fs/ecryptfs/file.c ++++ vanilla-2.6.33.7/fs/ecryptfs/file.c +@@ -198,7 +198,7 @@ static int ecryptfs_open(struct inode *i + "the persistent file for the dentry with name " + "[%s]; rc = [%d]\n", __func__, + ecryptfs_dentry->d_name.name, rc); +- goto out; ++ goto out_free; + } + } + if ((ecryptfs_inode_to_private(inode)->lower_file->f_flags & O_RDONLY) +@@ -206,7 +206,7 @@ static int ecryptfs_open(struct inode *i + rc = -EPERM; + printk(KERN_WARNING "%s: Lower persistent file is RO; eCryptfs " + "file must hence be opened RO\n", __func__); +- goto out; ++ goto out_free; + } + ecryptfs_set_file_lower( + file, ecryptfs_inode_to_private(inode)->lower_file); +@@ -293,12 +293,40 @@ static int ecryptfs_fasync(int fd, struc + return rc; + } + +-static int ecryptfs_ioctl(struct inode *inode, struct file *file, +- unsigned int cmd, unsigned long arg); ++static long ++ecryptfs_unlocked_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ++{ ++ struct file *lower_file = NULL; ++ long rc = -ENOTTY; ++ ++ if (ecryptfs_file_to_private(file)) ++ lower_file = ecryptfs_file_to_lower(file); ++ if (lower_file && lower_file->f_op && lower_file->f_op->unlocked_ioctl) ++ rc = lower_file->f_op->unlocked_ioctl(lower_file, cmd, arg); ++ return rc; ++} ++ ++#ifdef CONFIG_COMPAT ++static long ++ecryptfs_compat_ioctl(struct file *file, unsigned int cmd, unsigned long arg) ++{ ++ struct file *lower_file = NULL; ++ long rc = -ENOIOCTLCMD; ++ ++ if (ecryptfs_file_to_private(file)) ++ lower_file = ecryptfs_file_to_lower(file); ++ if (lower_file && lower_file->f_op && lower_file->f_op->compat_ioctl) ++ rc = lower_file->f_op->compat_ioctl(lower_file, cmd, arg); ++ return rc; ++} ++#endif + + const struct file_operations ecryptfs_dir_fops = { + .readdir = ecryptfs_readdir, +- .ioctl = ecryptfs_ioctl, ++ .unlocked_ioctl = ecryptfs_unlocked_ioctl, ++#ifdef CONFIG_COMPAT ++ .compat_ioctl = ecryptfs_compat_ioctl, ++#endif + .open = ecryptfs_open, + .flush = ecryptfs_flush, + .release = ecryptfs_release, +@@ -314,7 +342,10 @@ const struct file_operations ecryptfs_ma + .write = do_sync_write, + .aio_write = generic_file_aio_write, + .readdir = ecryptfs_readdir, +- .ioctl = ecryptfs_ioctl, ++ .unlocked_ioctl = ecryptfs_unlocked_ioctl, ++#ifdef CONFIG_COMPAT ++ .compat_ioctl = ecryptfs_compat_ioctl, ++#endif + .mmap = generic_file_mmap, + .open = ecryptfs_open, + .flush = ecryptfs_flush, +@@ -323,20 +354,3 @@ const struct file_operations ecryptfs_ma + .fasync = ecryptfs_fasync, + .splice_read = generic_file_splice_read, + }; +- +-static int +-ecryptfs_ioctl(struct inode *inode, struct file *file, unsigned int cmd, +- unsigned long arg) +-{ +- int rc = 0; +- struct file *lower_file = NULL; +- +- if (ecryptfs_file_to_private(file)) +- lower_file = ecryptfs_file_to_lower(file); +- if (lower_file && lower_file->f_op && lower_file->f_op->ioctl) +- rc = lower_file->f_op->ioctl(ecryptfs_inode_to_lower(inode), +- lower_file, cmd, arg); +- else +- rc = -ENOTTY; +- return rc; +-} +--- vanilla-2.6.33.7.orig/fs/ecryptfs/inode.c ++++ vanilla-2.6.33.7/fs/ecryptfs/inode.c +@@ -272,7 +272,7 @@ int ecryptfs_lookup_and_interpose_lower( + printk(KERN_ERR "%s: Out of memory whilst attempting " + "to allocate ecryptfs_dentry_info struct\n", + __func__); +- goto out_dput; ++ goto out_put; + } + ecryptfs_set_dentry_lower(ecryptfs_dentry, lower_dentry); + ecryptfs_set_dentry_lower_mnt(ecryptfs_dentry, lower_mnt); +@@ -346,8 +346,9 @@ int ecryptfs_lookup_and_interpose_lower( + out_free_kmem: + kmem_cache_free(ecryptfs_header_cache_2, page_virt); + goto out; +-out_dput: ++out_put: + dput(lower_dentry); ++ mntput(lower_mnt); + d_drop(ecryptfs_dentry); + out: + return rc; +--- vanilla-2.6.33.7.orig/arch/arm/mach-pxa/cm-x300.c ++++ vanilla-2.6.33.7/arch/arm/mach-pxa/cm-x300.c +@@ -667,9 +667,10 @@ static void __init cm_x300_init(void) + { + cm_x300_init_mfp(); + +- pxa_set_ffuart_info(NULL); + pxa_set_btuart_info(NULL); + pxa_set_stuart_info(NULL); ++ if (cpu_is_pxa300()) ++ pxa_set_ffuart_info(NULL); + + cm_x300_init_da9030(); + cm_x300_init_dm9000(); +--- vanilla-2.6.33.7.orig/fs/signalfd.c ++++ vanilla-2.6.33.7/fs/signalfd.c +@@ -87,6 +87,7 @@ static int signalfd_copyinfo(struct sign + err |= __put_user(kinfo->si_tid, &uinfo->ssi_tid); + err |= __put_user(kinfo->si_overrun, &uinfo->ssi_overrun); + err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr); ++ err |= __put_user(kinfo->si_int, &uinfo->ssi_int); + break; + case __SI_POLL: + err |= __put_user(kinfo->si_band, &uinfo->ssi_band); +@@ -110,6 +111,7 @@ static int signalfd_copyinfo(struct sign + err |= __put_user(kinfo->si_pid, &uinfo->ssi_pid); + err |= __put_user(kinfo->si_uid, &uinfo->ssi_uid); + err |= __put_user((long) kinfo->si_ptr, &uinfo->ssi_ptr); ++ err |= __put_user(kinfo->si_int, &uinfo->ssi_int); + break; + default: + /* +--- vanilla-2.6.33.7.orig/include/linux/fs.h ++++ vanilla-2.6.33.7/include/linux/fs.h +@@ -145,11 +145,11 @@ struct inodes_stat_t { + * + */ + #define RW_MASK 1 +-#define RWA_MASK 2 ++#define RWA_MASK 16 + #define READ 0 + #define WRITE 1 +-#define READA 2 /* read-ahead - don't block if no resources */ +-#define SWRITE 3 /* for ll_rw_block() - wait for buffer lock */ ++#define READA 16 /* readahead - don't block if no resources */ ++#define SWRITE 17 /* for ll_rw_block(), wait for buffer lock */ + #define READ_SYNC (READ | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_UNPLUG)) + #define READ_META (READ | (1 << BIO_RW_META)) + #define WRITE_SYNC_PLUG (WRITE | (1 << BIO_RW_SYNCIO) | (1 << BIO_RW_NOIDLE)) +--- vanilla-2.6.33.7.orig/drivers/net/smsc911x.c ++++ vanilla-2.6.33.7/drivers/net/smsc911x.c +@@ -85,8 +85,7 @@ struct smsc911x_data { + */ + spinlock_t mac_lock; + +- /* spinlock to ensure 16-bit accesses are serialised. +- * unused with a 32-bit bus */ ++ /* spinlock to ensure register accesses are serialised */ + spinlock_t dev_lock; + + struct phy_device *phy_dev; +@@ -119,37 +118,33 @@ struct smsc911x_data { + unsigned int hashlo; + }; + +-/* The 16-bit access functions are significantly slower, due to the locking +- * necessary. If your bus hardware can be configured to do this for you +- * (in response to a single 32-bit operation from software), you should use +- * the 32-bit access functions instead. */ +- +-static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg) ++static inline u32 __smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg) + { + if (pdata->config.flags & SMSC911X_USE_32BIT) + return readl(pdata->ioaddr + reg); + +- if (pdata->config.flags & SMSC911X_USE_16BIT) { +- u32 data; +- unsigned long flags; +- +- /* these two 16-bit reads must be performed consecutively, so +- * must not be interrupted by our own ISR (which would start +- * another read operation) */ +- spin_lock_irqsave(&pdata->dev_lock, flags); +- data = ((readw(pdata->ioaddr + reg) & 0xFFFF) | ++ if (pdata->config.flags & SMSC911X_USE_16BIT) ++ return ((readw(pdata->ioaddr + reg) & 0xFFFF) | + ((readw(pdata->ioaddr + reg + 2) & 0xFFFF) << 16)); +- spin_unlock_irqrestore(&pdata->dev_lock, flags); +- +- return data; +- } + + BUG(); + return 0; + } + +-static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg, +- u32 val) ++static inline u32 smsc911x_reg_read(struct smsc911x_data *pdata, u32 reg) ++{ ++ u32 data; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&pdata->dev_lock, flags); ++ data = __smsc911x_reg_read(pdata, reg); ++ spin_unlock_irqrestore(&pdata->dev_lock, flags); ++ ++ return data; ++} ++ ++static inline void __smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg, ++ u32 val) + { + if (pdata->config.flags & SMSC911X_USE_32BIT) { + writel(val, pdata->ioaddr + reg); +@@ -157,44 +152,54 @@ static inline void smsc911x_reg_write(st + } + + if (pdata->config.flags & SMSC911X_USE_16BIT) { +- unsigned long flags; +- +- /* these two 16-bit writes must be performed consecutively, so +- * must not be interrupted by our own ISR (which would start +- * another read operation) */ +- spin_lock_irqsave(&pdata->dev_lock, flags); + writew(val & 0xFFFF, pdata->ioaddr + reg); + writew((val >> 16) & 0xFFFF, pdata->ioaddr + reg + 2); +- spin_unlock_irqrestore(&pdata->dev_lock, flags); + return; + } + + BUG(); + } + ++static inline void smsc911x_reg_write(struct smsc911x_data *pdata, u32 reg, ++ u32 val) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&pdata->dev_lock, flags); ++ __smsc911x_reg_write(pdata, reg, val); ++ spin_unlock_irqrestore(&pdata->dev_lock, flags); ++} ++ + /* Writes a packet to the TX_DATA_FIFO */ + static inline void + smsc911x_tx_writefifo(struct smsc911x_data *pdata, unsigned int *buf, + unsigned int wordcount) + { ++ unsigned long flags; ++ ++ spin_lock_irqsave(&pdata->dev_lock, flags); ++ + if (pdata->config.flags & SMSC911X_SWAP_FIFO) { + while (wordcount--) +- smsc911x_reg_write(pdata, TX_DATA_FIFO, swab32(*buf++)); +- return; ++ __smsc911x_reg_write(pdata, TX_DATA_FIFO, ++ swab32(*buf++)); ++ goto out; + } + + if (pdata->config.flags & SMSC911X_USE_32BIT) { + writesl(pdata->ioaddr + TX_DATA_FIFO, buf, wordcount); +- return; ++ goto out; + } + + if (pdata->config.flags & SMSC911X_USE_16BIT) { + while (wordcount--) +- smsc911x_reg_write(pdata, TX_DATA_FIFO, *buf++); +- return; ++ __smsc911x_reg_write(pdata, TX_DATA_FIFO, *buf++); ++ goto out; + } + + BUG(); ++out: ++ spin_unlock_irqrestore(&pdata->dev_lock, flags); + } + + /* Reads a packet out of the RX_DATA_FIFO */ +@@ -202,24 +207,31 @@ static inline void + smsc911x_rx_readfifo(struct smsc911x_data *pdata, unsigned int *buf, + unsigned int wordcount) + { ++ unsigned long flags; ++ ++ spin_lock_irqsave(&pdata->dev_lock, flags); ++ + if (pdata->config.flags & SMSC911X_SWAP_FIFO) { + while (wordcount--) +- *buf++ = swab32(smsc911x_reg_read(pdata, RX_DATA_FIFO)); +- return; ++ *buf++ = swab32(__smsc911x_reg_read(pdata, ++ RX_DATA_FIFO)); ++ goto out; + } + + if (pdata->config.flags & SMSC911X_USE_32BIT) { + readsl(pdata->ioaddr + RX_DATA_FIFO, buf, wordcount); +- return; ++ goto out; + } + + if (pdata->config.flags & SMSC911X_USE_16BIT) { + while (wordcount--) +- *buf++ = smsc911x_reg_read(pdata, RX_DATA_FIFO); +- return; ++ *buf++ = __smsc911x_reg_read(pdata, RX_DATA_FIFO); ++ goto out; + } + + BUG(); ++out: ++ spin_unlock_irqrestore(&pdata->dev_lock, flags); + } + + /* waits for MAC not busy, with timeout. Only called by smsc911x_mac_read +--- vanilla-2.6.33.7.orig/drivers/usb/host/ehci-pci.c ++++ vanilla-2.6.33.7/drivers/usb/host/ehci-pci.c +@@ -111,6 +111,7 @@ static int ehci_pci_setup(struct usb_hcd + switch (pdev->vendor) { + case PCI_VENDOR_ID_INTEL: + ehci->need_io_watchdog = 0; ++ ehci->fs_i_thresh = 1; + if (pdev->device == 0x27cc) { + ehci->broken_periodic = 1; + ehci_info(ehci, "using broken periodic workaround\n"); +--- vanilla-2.6.33.7.orig/drivers/usb/host/ehci-sched.c ++++ vanilla-2.6.33.7/drivers/usb/host/ehci-sched.c +@@ -1398,7 +1398,6 @@ iso_stream_schedule ( + int status; + unsigned mod = ehci->periodic_size << 3; + struct ehci_iso_sched *sched = urb->hcpriv; +- struct pci_dev *pdev; + + if (sched->span > (mod - SCHEDULE_SLOP)) { + ehci_dbg (ehci, "iso request %p too long\n", urb); +@@ -1425,15 +1424,14 @@ iso_stream_schedule ( + * slot in the schedule, implicitly assuming URB_ISO_ASAP. + */ + if (likely (!list_empty (&stream->td_list))) { +- pdev = to_pci_dev(ehci_to_hcd(ehci)->self.controller); + start = stream->next_uframe; + + /* For high speed devices, allow scheduling within the +- * isochronous scheduling threshold. For full speed devices, +- * don't. (Work around for Intel ICH9 bug.) ++ * isochronous scheduling threshold. For full speed devices ++ * and Intel PCI-based controllers, don't (work around for ++ * Intel ICH9 bug). + */ +- if (!stream->highspeed && +- pdev->vendor == PCI_VENDOR_ID_INTEL) ++ if (!stream->highspeed && ehci->fs_i_thresh) + next = now + ehci->i_thresh; + else + next = now; +--- vanilla-2.6.33.7.orig/drivers/usb/host/ehci.h ++++ vanilla-2.6.33.7/drivers/usb/host/ehci.h +@@ -130,6 +130,7 @@ struct ehci_hcd { /* one per controlle + unsigned has_amcc_usb23:1; + unsigned need_io_watchdog:1; + unsigned broken_periodic:1; ++ unsigned fs_i_thresh:1; /* Intel iso scheduling */ + + /* required for usb32 quirk */ + #define OHCI_CTRL_HCFS (3 << 6) +--- vanilla-2.6.33.7.orig/drivers/usb/mon/mon_bin.c ++++ vanilla-2.6.33.7/drivers/usb/mon/mon_bin.c +@@ -1004,7 +1004,7 @@ static int mon_bin_ioctl(struct inode *i + + mutex_lock(&rp->fetch_lock); + spin_lock_irqsave(&rp->b_lock, flags); +- mon_free_buff(rp->b_vec, size/CHUNK_SIZE); ++ mon_free_buff(rp->b_vec, rp->b_size/CHUNK_SIZE); + kfree(rp->b_vec); + rp->b_vec = vec; + rp->b_size = size; +--- vanilla-2.6.33.7.orig/drivers/usb/serial/ftdi_sio.c ++++ vanilla-2.6.33.7/drivers/usb/serial/ftdi_sio.c +@@ -162,6 +162,9 @@ static struct usb_device_id id_table_com + { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_5_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_6_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_SCS_DEVICE_7_PID) }, ++ { USB_DEVICE(FTDI_VID, FTDI_USINT_CAT_PID) }, ++ { USB_DEVICE(FTDI_VID, FTDI_USINT_WKEY_PID) }, ++ { USB_DEVICE(FTDI_VID, FTDI_USINT_RS232_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_ACTZWAVE_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_IRTRANS_PID) }, + { USB_DEVICE(FTDI_VID, FTDI_IPLUS_PID) }, +@@ -752,6 +755,7 @@ static struct usb_device_id id_table_com + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, + { USB_DEVICE(FTDI_VID, XVERVE_SIGNALYZER_SH4_PID), + .driver_info = (kernel_ulong_t)&ftdi_jtag_quirk }, ++ { USB_DEVICE(FTDI_VID, SEGWAY_RMP200_PID) }, + { }, /* Optional parameter entry */ + { } /* Terminating entry */ + }; +--- vanilla-2.6.33.7.orig/drivers/usb/serial/ftdi_sio_ids.h ++++ vanilla-2.6.33.7/drivers/usb/serial/ftdi_sio_ids.h +@@ -40,6 +40,11 @@ + + #define FTDI_NXTCAM_PID 0xABB8 /* NXTCam for Mindstorms NXT */ + ++/* US Interface Navigator (http://www.usinterface.com/) */ ++#define FTDI_USINT_CAT_PID 0xb810 /* Navigator CAT and 2nd PTT lines */ ++#define FTDI_USINT_WKEY_PID 0xb811 /* Navigator WKEY and FSK lines */ ++#define FTDI_USINT_RS232_PID 0xb812 /* Navigator RS232 and CONFIG lines */ ++ + /* OOCDlink by Joern Kaipf + * (http://www.joernonline.de/dw/doku.php?id=start&idx=projects:oocdlink) */ + #define FTDI_OOCDLINK_PID 0xbaf8 /* Amontec JTAGkey */ +@@ -1039,3 +1044,8 @@ + #define XVERVE_SIGNALYZER_SH2_PID 0xBCA2 + #define XVERVE_SIGNALYZER_SH4_PID 0xBCA4 + ++/* ++ * Segway Robotic Mobility Platform USB interface (using VID 0x0403) ++ * Submitted by John G. Rogers ++ */ ++#define SEGWAY_RMP200_PID 0xe729 +--- vanilla-2.6.33.7.orig/drivers/usb/serial/option.c ++++ vanilla-2.6.33.7/drivers/usb/serial/option.c +@@ -165,7 +165,10 @@ static int option_resume(struct usb_ser + #define HUAWEI_PRODUCT_E143D 0x143D + #define HUAWEI_PRODUCT_E143E 0x143E + #define HUAWEI_PRODUCT_E143F 0x143F ++#define HUAWEI_PRODUCT_K4505 0x1464 ++#define HUAWEI_PRODUCT_K3765 0x1465 + #define HUAWEI_PRODUCT_E14AC 0x14AC ++#define HUAWEI_PRODUCT_ETS1220 0x1803 + + #define QUANTA_VENDOR_ID 0x0408 + #define QUANTA_PRODUCT_Q101 0xEA02 +@@ -469,6 +472,9 @@ static struct usb_device_id option_ids[] + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143D, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143E, 0xff, 0xff, 0xff) }, + { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E143F, 0xff, 0xff, 0xff) }, ++ { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K4505, 0xff, 0xff, 0xff) }, ++ { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_K3765, 0xff, 0xff, 0xff) }, ++ { USB_DEVICE_AND_INTERFACE_INFO(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_ETS1220, 0xff, 0xff, 0xff) }, + { USB_DEVICE(HUAWEI_VENDOR_ID, HUAWEI_PRODUCT_E14AC) }, + { USB_DEVICE(AMOI_VENDOR_ID, AMOI_PRODUCT_9508) }, + { USB_DEVICE(NOVATELWIRELESS_VENDOR_ID, NOVATELWIRELESS_PRODUCT_V640) }, /* Novatel Merlin V640/XV620 */ +@@ -1007,6 +1013,13 @@ static int option_probe(struct usb_seria + serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff) + return -ENODEV; + ++ /* Don't bind network interfaces on Huawei K3765 & K4505 */ ++ if (serial->dev->descriptor.idVendor == HUAWEI_VENDOR_ID && ++ (serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K3765 || ++ serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4505) && ++ serial->interface->cur_altsetting->desc.bInterfaceNumber == 1) ++ return -ENODEV; ++ + data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL); + if (!data) + return -ENOMEM; +--- vanilla-2.6.33.7.orig/drivers/usb/serial/cp210x.c ++++ vanilla-2.6.33.7/drivers/usb/serial/cp210x.c +@@ -128,6 +128,10 @@ static struct usb_device_id id_table [] + { USB_DEVICE(0x1843, 0x0200) }, /* Vaisala USB Instrument Cable */ + { USB_DEVICE(0x18EF, 0xE00F) }, /* ELV USB-I2C-Interface */ + { USB_DEVICE(0x413C, 0x9500) }, /* DW700 GPS USB interface */ ++ { USB_DEVICE(0x16DC, 0x0010) }, /* W-IE-NE-R Plein & Baus GmbH PL512 Power Supply */ ++ { USB_DEVICE(0x16DC, 0x0011) }, /* W-IE-NE-R Plein & Baus GmbH RCM Remote Control for MARATON Power Supply */ ++ { USB_DEVICE(0x16DC, 0x0012) }, /* W-IE-NE-R Plein & Baus GmbH MPOD Multi Channel Power Supply */ ++ { USB_DEVICE(0x16DC, 0x0015) }, /* W-IE-NE-R Plein & Baus GmbH CML Control, Monitoring and Data Logger */ + { } /* Terminating Entry */ + }; + +--- vanilla-2.6.33.7.orig/drivers/usb/misc/usbtest.c ++++ vanilla-2.6.33.7/drivers/usb/misc/usbtest.c +@@ -1383,7 +1383,6 @@ static void iso_callback (struct urb *ur + break; + } + } +- simple_free_urb (urb); + + ctx->pending--; + if (ctx->pending == 0) { +@@ -1500,6 +1499,7 @@ test_iso_queue (struct usbtest_dev *dev, + } + + simple_free_urb (urbs [i]); ++ urbs[i] = NULL; + context.pending--; + context.submit_error = 1; + break; +@@ -1509,6 +1509,10 @@ test_iso_queue (struct usbtest_dev *dev, + + wait_for_completion (&context.done); + ++ for (i = 0; i < param->sglen; i++) { ++ if (urbs[i]) ++ simple_free_urb(urbs[i]); ++ } + /* + * Isochronous transfers are expected to fail sometimes. As an + * arbitrary limit, we will report an error if any submissions +--- vanilla-2.6.33.7.orig/drivers/usb/core/urb.c ++++ vanilla-2.6.33.7/drivers/usb/core/urb.c +@@ -137,6 +137,16 @@ void usb_anchor_urb(struct urb *urb, str + } + EXPORT_SYMBOL_GPL(usb_anchor_urb); + ++/* Callers must hold anchor->lock */ ++static void __usb_unanchor_urb(struct urb *urb, struct usb_anchor *anchor) ++{ ++ urb->anchor = NULL; ++ list_del(&urb->anchor_list); ++ usb_put_urb(urb); ++ if (list_empty(&anchor->urb_list)) ++ wake_up(&anchor->wait); ++} ++ + /** + * usb_unanchor_urb - unanchors an URB + * @urb: pointer to the urb to anchor +@@ -156,17 +166,14 @@ void usb_unanchor_urb(struct urb *urb) + return; + + spin_lock_irqsave(&anchor->lock, flags); +- if (unlikely(anchor != urb->anchor)) { +- /* we've lost the race to another thread */ +- spin_unlock_irqrestore(&anchor->lock, flags); +- return; +- } +- urb->anchor = NULL; +- list_del(&urb->anchor_list); ++ /* ++ * At this point, we could be competing with another thread which ++ * has the same intention. To protect the urb from being unanchored ++ * twice, only the winner of the race gets the job. ++ */ ++ if (likely(anchor == urb->anchor)) ++ __usb_unanchor_urb(urb, anchor); + spin_unlock_irqrestore(&anchor->lock, flags); +- usb_put_urb(urb); +- if (list_empty(&anchor->urb_list)) +- wake_up(&anchor->wait); + } + EXPORT_SYMBOL_GPL(usb_unanchor_urb); + +@@ -739,20 +746,11 @@ EXPORT_SYMBOL_GPL(usb_unpoison_anchored_ + void usb_unlink_anchored_urbs(struct usb_anchor *anchor) + { + struct urb *victim; +- unsigned long flags; + +- spin_lock_irqsave(&anchor->lock, flags); +- while (!list_empty(&anchor->urb_list)) { +- victim = list_entry(anchor->urb_list.prev, struct urb, +- anchor_list); +- usb_get_urb(victim); +- spin_unlock_irqrestore(&anchor->lock, flags); +- /* this will unanchor the URB */ ++ while ((victim = usb_get_from_anchor(anchor)) != NULL) { + usb_unlink_urb(victim); + usb_put_urb(victim); +- spin_lock_irqsave(&anchor->lock, flags); + } +- spin_unlock_irqrestore(&anchor->lock, flags); + } + EXPORT_SYMBOL_GPL(usb_unlink_anchored_urbs); + +@@ -789,12 +787,11 @@ struct urb *usb_get_from_anchor(struct u + victim = list_entry(anchor->urb_list.next, struct urb, + anchor_list); + usb_get_urb(victim); +- spin_unlock_irqrestore(&anchor->lock, flags); +- usb_unanchor_urb(victim); ++ __usb_unanchor_urb(victim, anchor); + } else { +- spin_unlock_irqrestore(&anchor->lock, flags); + victim = NULL; + } ++ spin_unlock_irqrestore(&anchor->lock, flags); + + return victim; + } +@@ -816,12 +813,7 @@ void usb_scuttle_anchored_urbs(struct us + while (!list_empty(&anchor->urb_list)) { + victim = list_entry(anchor->urb_list.prev, struct urb, + anchor_list); +- usb_get_urb(victim); +- spin_unlock_irqrestore(&anchor->lock, flags); +- /* this may free the URB */ +- usb_unanchor_urb(victim); +- usb_put_urb(victim); +- spin_lock_irqsave(&anchor->lock, flags); ++ __usb_unanchor_urb(victim, anchor); + } + spin_unlock_irqrestore(&anchor->lock, flags); + } +--- vanilla-2.6.33.7.orig/drivers/gpu/drm/drm_edid.c ++++ vanilla-2.6.33.7/drivers/gpu/drm/drm_edid.c +@@ -576,8 +576,8 @@ struct drm_display_mode *drm_mode_std(st + mode = drm_cvt_mode(dev, hsize, vsize, vrefresh_rate, 0, 0, + false); + mode->hdisplay = 1366; +- mode->vsync_start = mode->vsync_start - 1; +- mode->vsync_end = mode->vsync_end - 1; ++ mode->hsync_start = mode->hsync_start - 1; ++ mode->hsync_end = mode->hsync_end - 1; + return mode; + } + mode = NULL; +--- vanilla-2.6.33.7.orig/drivers/bluetooth/btusb.c ++++ vanilla-2.6.33.7/drivers/bluetooth/btusb.c +@@ -59,6 +59,9 @@ static struct usb_device_id btusb_table[ + /* Generic Bluetooth USB device */ + { USB_DEVICE_INFO(0xe0, 0x01, 0x01) }, + ++ /* Apple iMac11,1 */ ++ { USB_DEVICE(0x05ac, 0x8215) }, ++ + /* AVM BlueFRITZ! USB v2.0 */ + { USB_DEVICE(0x057c, 0x3800) }, + +--- vanilla-2.6.33.7.orig/drivers/mtd/nand/plat_nand.c ++++ vanilla-2.6.33.7/drivers/mtd/nand/plat_nand.c +@@ -91,7 +91,7 @@ static int __devinit plat_nand_probe(str + } + + /* Scan to find existance of the device */ +- if (nand_scan(&data->mtd, 1)) { ++ if (nand_scan(&data->mtd, pdata->chip.nr_chips)) { + err = -ENXIO; + goto out; + } +--- vanilla-2.6.33.7.orig/fs/jfs/xattr.c ++++ vanilla-2.6.33.7/fs/jfs/xattr.c +@@ -85,46 +85,25 @@ struct ea_buffer { + #define EA_MALLOC 0x0008 + + ++static int is_known_namespace(const char *name) ++{ ++ if (strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN) && ++ strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && ++ strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) && ++ strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) ++ return false; ++ ++ return true; ++} ++ + /* + * These three routines are used to recognize on-disk extended attributes + * that are in a recognized namespace. If the attribute is not recognized, + * "os2." is prepended to the name + */ +-static inline int is_os2_xattr(struct jfs_ea *ea) ++static int is_os2_xattr(struct jfs_ea *ea) + { +- /* +- * Check for "system." +- */ +- if ((ea->namelen >= XATTR_SYSTEM_PREFIX_LEN) && +- !strncmp(ea->name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) +- return false; +- /* +- * Check for "user." +- */ +- if ((ea->namelen >= XATTR_USER_PREFIX_LEN) && +- !strncmp(ea->name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) +- return false; +- /* +- * Check for "security." +- */ +- if ((ea->namelen >= XATTR_SECURITY_PREFIX_LEN) && +- !strncmp(ea->name, XATTR_SECURITY_PREFIX, +- XATTR_SECURITY_PREFIX_LEN)) +- return false; +- /* +- * Check for "trusted." +- */ +- if ((ea->namelen >= XATTR_TRUSTED_PREFIX_LEN) && +- !strncmp(ea->name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN)) +- return false; +- /* +- * Add any other valid namespace prefixes here +- */ +- +- /* +- * We assume it's OS/2's flat namespace +- */ +- return true; ++ return !is_known_namespace(ea->name); + } + + static inline int name_size(struct jfs_ea *ea) +@@ -762,13 +741,23 @@ static int can_set_xattr(struct inode *i + if (!strncmp(name, XATTR_SYSTEM_PREFIX, XATTR_SYSTEM_PREFIX_LEN)) + return can_set_system_xattr(inode, name, value, value_len); + ++ if (!strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) { ++ /* ++ * This makes sure that we aren't trying to set an ++ * attribute in a different namespace by prefixing it ++ * with "os2." ++ */ ++ if (is_known_namespace(name + XATTR_OS2_PREFIX_LEN)) ++ return -EOPNOTSUPP; ++ return 0; ++ } ++ + /* + * Don't allow setting an attribute in an unknown namespace. + */ + if (strncmp(name, XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN) && + strncmp(name, XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN) && +- strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN) && +- strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN)) ++ strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) + return -EOPNOTSUPP; + + return 0; +@@ -950,19 +939,8 @@ ssize_t __jfs_getxattr(struct inode *ino + int xattr_size; + ssize_t size; + int namelen = strlen(name); +- char *os2name = NULL; + char *value; + +- if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { +- os2name = kmalloc(namelen - XATTR_OS2_PREFIX_LEN + 1, +- GFP_KERNEL); +- if (!os2name) +- return -ENOMEM; +- strcpy(os2name, name + XATTR_OS2_PREFIX_LEN); +- name = os2name; +- namelen -= XATTR_OS2_PREFIX_LEN; +- } +- + down_read(&JFS_IP(inode)->xattr_sem); + + xattr_size = ea_get(inode, &ea_buf, 0); +@@ -1000,8 +978,6 @@ ssize_t __jfs_getxattr(struct inode *ino + out: + up_read(&JFS_IP(inode)->xattr_sem); + +- kfree(os2name); +- + return size; + } + +@@ -1010,6 +986,19 @@ ssize_t jfs_getxattr(struct dentry *dent + { + int err; + ++ if (strncmp(name, XATTR_OS2_PREFIX, XATTR_OS2_PREFIX_LEN) == 0) { ++ /* ++ * skip past "os2." prefix ++ */ ++ name += XATTR_OS2_PREFIX_LEN; ++ /* ++ * Don't allow retrieving properly prefixed attributes ++ * by prepending them with "os2." ++ */ ++ if (is_known_namespace(name)) ++ return -EOPNOTSUPP; ++ } ++ + err = __jfs_getxattr(dentry->d_inode, name, data, buf_size); + + return err; +--- vanilla-2.6.33.7.orig/include/linux/netdevice.h ++++ vanilla-2.6.33.7/include/linux/netdevice.h +@@ -1625,6 +1625,8 @@ extern void netif_carrier_on(struct net_ + + extern void netif_carrier_off(struct net_device *dev); + ++extern void netif_notify_peers(struct net_device *dev); ++ + /** + * netif_dormant_on - mark device as dormant. + * @dev: network device +--- vanilla-2.6.33.7.orig/include/linux/notifier.h ++++ vanilla-2.6.33.7/include/linux/notifier.h +@@ -203,6 +203,7 @@ static inline int notifier_to_errno(int + #define NETDEV_BONDING_NEWTYPE 0x000F + #define NETDEV_POST_INIT 0x0010 + #define NETDEV_UNREGISTER_BATCH 0x0011 ++#define NETDEV_NOTIFY_PEERS 0x0013 + + #define SYS_DOWN 0x0001 /* Notify of system down */ + #define SYS_RESTART SYS_DOWN +--- vanilla-2.6.33.7.orig/net/ipv4/devinet.c ++++ vanilla-2.6.33.7/net/ipv4/devinet.c +@@ -1080,6 +1080,7 @@ static int inetdev_event(struct notifier + } + ip_mc_up(in_dev); + /* fall through */ ++ case NETDEV_NOTIFY_PEERS: + case NETDEV_CHANGEADDR: + /* Send gratuitous ARP to notify of link change */ + if (IN_DEV_ARP_NOTIFY(in_dev)) { +--- vanilla-2.6.33.7.orig/net/sched/sch_generic.c ++++ vanilla-2.6.33.7/net/sched/sch_generic.c +@@ -324,6 +324,24 @@ void netif_carrier_off(struct net_device + } + EXPORT_SYMBOL(netif_carrier_off); + ++/** ++ * netif_notify_peers - notify network peers about existence of @dev ++ * @dev: network device ++ * ++ * Generate traffic such that interested network peers are aware of ++ * @dev, such as by generating a gratuitous ARP. This may be used when ++ * a device wants to inform the rest of the network about some sort of ++ * reconfiguration such as a failover event or virtual machine ++ * migration. ++ */ ++void netif_notify_peers(struct net_device *dev) ++{ ++ rtnl_lock(); ++ call_netdevice_notifiers(NETDEV_NOTIFY_PEERS, dev); ++ rtnl_unlock(); ++} ++EXPORT_SYMBOL(netif_notify_peers); ++ + /* "NOOP" scheduler: the best scheduler, recommended for all interfaces + under all circumstances. It is difficult to invent anything faster or + cheaper. +--- vanilla-2.6.33.7.orig/drivers/net/xen-netfront.c ++++ vanilla-2.6.33.7/drivers/net/xen-netfront.c +@@ -1620,6 +1620,7 @@ static void backend_changed(struct xenbu + if (xennet_connect(netdev) != 0) + break; + xenbus_switch_state(dev, XenbusStateConnected); ++ netif_notify_peers(netdev); + break; + + case XenbusStateClosing: +--- vanilla-2.6.33.7.orig/include/linux/interrupt.h ++++ vanilla-2.6.33.7/include/linux/interrupt.h +@@ -52,16 +52,21 @@ + * IRQF_ONESHOT - Interrupt is not reenabled after the hardirq handler finished. + * Used by threaded interrupts which need to keep the + * irq line disabled until the threaded handler has been run. ++ * IRQF_NO_SUSPEND - Do not disable this IRQ during suspend ++ * + */ + #define IRQF_DISABLED 0x00000020 + #define IRQF_SAMPLE_RANDOM 0x00000040 + #define IRQF_SHARED 0x00000080 + #define IRQF_PROBE_SHARED 0x00000100 +-#define IRQF_TIMER 0x00000200 ++#define __IRQF_TIMER 0x00000200 + #define IRQF_PERCPU 0x00000400 + #define IRQF_NOBALANCING 0x00000800 + #define IRQF_IRQPOLL 0x00001000 + #define IRQF_ONESHOT 0x00002000 ++#define IRQF_NO_SUSPEND 0x00004000 ++ ++#define IRQF_TIMER (__IRQF_TIMER | IRQF_NO_SUSPEND) + + /* + * Bits used by threaded handlers: +--- vanilla-2.6.33.7.orig/kernel/irq/manage.c ++++ vanilla-2.6.33.7/kernel/irq/manage.c +@@ -200,7 +200,7 @@ static inline int setup_affinity(unsigne + void __disable_irq(struct irq_desc *desc, unsigned int irq, bool suspend) + { + if (suspend) { +- if (!desc->action || (desc->action->flags & IRQF_TIMER)) ++ if (!desc->action || (desc->action->flags & IRQF_NO_SUSPEND)) + return; + desc->status |= IRQ_SUSPENDED; + } +--- vanilla-2.6.33.7.orig/drivers/xen/events.c ++++ vanilla-2.6.33.7/drivers/xen/events.c +@@ -535,6 +535,7 @@ int bind_ipi_to_irqhandler(enum ipi_vect + if (irq < 0) + return irq; + ++ irqflags |= IRQF_NO_SUSPEND; + retval = request_irq(irq, handler, irqflags, devname, dev_id); + if (retval != 0) { + unbind_from_irq(irq); +--- vanilla-2.6.33.7.orig/drivers/gpu/drm/i915/dvo_tfp410.c ++++ vanilla-2.6.33.7/drivers/gpu/drm/i915/dvo_tfp410.c +@@ -216,7 +216,7 @@ static enum drm_connector_status tfp410_ + uint8_t ctl2; + + if (tfp410_readb(dvo, TFP410_CTL_2, &ctl2)) { +- if (ctl2 & TFP410_CTL_2_HTPLG) ++ if (ctl2 & TFP410_CTL_2_RSEN) + ret = connector_status_connected; + else + ret = connector_status_disconnected; +--- vanilla-2.6.33.7.orig/drivers/scsi/ibmvscsi/ibmvfc.c ++++ vanilla-2.6.33.7/drivers/scsi/ibmvscsi/ibmvfc.c +@@ -2243,7 +2243,7 @@ static int ibmvfc_wait_for_ops(struct ib + DECLARE_COMPLETION_ONSTACK(comp); + int wait; + unsigned long flags; +- signed long timeout = init_timeout * HZ; ++ signed long timeout = IBMVFC_ABORT_WAIT_TIMEOUT * HZ; + + ENTER; + do { +@@ -3011,6 +3011,7 @@ static struct ibmvfc_async_crq *ibmvfc_n + if (crq->valid & 0x80) { + if (++async_crq->cur == async_crq->size) + async_crq->cur = 0; ++ rmb(); + } else + crq = NULL; + +@@ -3033,6 +3034,7 @@ static struct ibmvfc_crq *ibmvfc_next_cr + if (crq->valid & 0x80) { + if (++queue->cur == queue->size) + queue->cur = 0; ++ rmb(); + } else + crq = NULL; + +@@ -3081,12 +3083,14 @@ static void ibmvfc_tasklet(void *data) + while ((async = ibmvfc_next_async_crq(vhost)) != NULL) { + ibmvfc_handle_async(async, vhost); + async->valid = 0; ++ wmb(); + } + + /* Pull all the valid messages off the CRQ */ + while ((crq = ibmvfc_next_crq(vhost)) != NULL) { + ibmvfc_handle_crq(crq, vhost); + crq->valid = 0; ++ wmb(); + } + + vio_enable_interrupts(vdev); +@@ -3094,10 +3098,12 @@ static void ibmvfc_tasklet(void *data) + vio_disable_interrupts(vdev); + ibmvfc_handle_async(async, vhost); + async->valid = 0; ++ wmb(); + } else if ((crq = ibmvfc_next_crq(vhost)) != NULL) { + vio_disable_interrupts(vdev); + ibmvfc_handle_crq(crq, vhost); + crq->valid = 0; ++ wmb(); + } else + done = 1; + } +--- vanilla-2.6.33.7.orig/drivers/scsi/ibmvscsi/ibmvfc.h ++++ vanilla-2.6.33.7/drivers/scsi/ibmvscsi/ibmvfc.h +@@ -38,6 +38,7 @@ + #define IBMVFC_ADISC_PLUS_CANCEL_TIMEOUT \ + (IBMVFC_ADISC_TIMEOUT + IBMVFC_ADISC_CANCEL_TIMEOUT) + #define IBMVFC_INIT_TIMEOUT 120 ++#define IBMVFC_ABORT_WAIT_TIMEOUT 40 + #define IBMVFC_MAX_REQUESTS_DEFAULT 100 + + #define IBMVFC_DEBUG 0 +--- vanilla-2.6.33.7.orig/drivers/md/bitmap.c ++++ vanilla-2.6.33.7/drivers/md/bitmap.c +@@ -1351,7 +1351,8 @@ void bitmap_endwrite(struct bitmap *bitm + { + if (!bitmap) return; + if (behind) { +- atomic_dec(&bitmap->behind_writes); ++ if (atomic_dec_and_test(&bitmap->behind_writes)) ++ wake_up(&bitmap->behind_wait); + PRINTK(KERN_DEBUG "dec write-behind count %d/%d\n", + atomic_read(&bitmap->behind_writes), bitmap->max_write_behind); + } +@@ -1675,6 +1676,7 @@ int bitmap_create(mddev_t *mddev) + atomic_set(&bitmap->pending_writes, 0); + init_waitqueue_head(&bitmap->write_wait); + init_waitqueue_head(&bitmap->overflow_wait); ++ init_waitqueue_head(&bitmap->behind_wait); + + bitmap->mddev = mddev; + +--- vanilla-2.6.33.7.orig/drivers/md/bitmap.h ++++ vanilla-2.6.33.7/drivers/md/bitmap.h +@@ -239,6 +239,7 @@ struct bitmap { + atomic_t pending_writes; /* pending writes to the bitmap file */ + wait_queue_head_t write_wait; + wait_queue_head_t overflow_wait; ++ wait_queue_head_t behind_wait; + + struct sysfs_dirent *sysfs_can_clear; + }; +--- vanilla-2.6.33.7.orig/drivers/md/raid1.c ++++ vanilla-2.6.33.7/drivers/md/raid1.c +@@ -865,6 +865,15 @@ static int make_request(struct request_q + } + mirror = conf->mirrors + rdisk; + ++ if (test_bit(WriteMostly, &mirror->rdev->flags) && ++ bitmap) { ++ /* Reading from a write-mostly device must ++ * take care not to over-take any writes ++ * that are 'behind' ++ */ ++ wait_event(bitmap->behind_wait, ++ atomic_read(&bitmap->behind_writes) == 0); ++ } + r1_bio->read_disk = rdisk; + + read_bio = bio_clone(bio, GFP_NOIO); +@@ -942,10 +951,14 @@ static int make_request(struct request_q + set_bit(R1BIO_Degraded, &r1_bio->state); + } + +- /* do behind I/O ? */ ++ /* do behind I/O ? ++ * Not if there are too many, or cannot allocate memory, ++ * or a reader on WriteMostly is waiting for behind writes ++ * to flush */ + if (bitmap && + (atomic_read(&bitmap->behind_writes) + < mddev->bitmap_info.max_write_behind) && ++ !waitqueue_active(&bitmap->behind_wait) && + (behind_pages = alloc_behind_pages(bio)) != NULL) + set_bit(R1BIO_BehindIO, &r1_bio->state); + +@@ -2146,15 +2159,13 @@ static int stop(mddev_t *mddev) + { + conf_t *conf = mddev->private; + struct bitmap *bitmap = mddev->bitmap; +- int behind_wait = 0; + + /* wait for behind writes to complete */ +- while (bitmap && atomic_read(&bitmap->behind_writes) > 0) { +- behind_wait++; +- printk(KERN_INFO "raid1: behind writes in progress on device %s, waiting to stop (%d)\n", mdname(mddev), behind_wait); +- set_current_state(TASK_UNINTERRUPTIBLE); +- schedule_timeout(HZ); /* wait a second */ ++ if (bitmap && atomic_read(&bitmap->behind_writes) > 0) { ++ printk(KERN_INFO "raid1: behind writes in progress on device %s, waiting to stop.\n", mdname(mddev)); + /* need to kick something here to make sure I/O goes? */ ++ wait_event(bitmap->behind_wait, ++ atomic_read(&bitmap->behind_writes) == 0); + } + + raise_barrier(conf); +--- vanilla-2.6.33.7.orig/arch/x86/mm/fault.c ++++ vanilla-2.6.33.7/arch/x86/mm/fault.c +@@ -802,8 +802,10 @@ do_sigbus(struct pt_regs *regs, unsigned + up_read(&mm->mmap_sem); + + /* Kernel mode? Handle exceptions or die: */ +- if (!(error_code & PF_USER)) ++ if (!(error_code & PF_USER)) { + no_context(regs, error_code, address); ++ return; ++ } + + /* User-space => ok to do another page fault: */ + if (is_prefetch(regs, error_code, address)) diff --git a/hda_intel-prealloc-4mb-dmabuffer.patch b/hda_intel-prealloc-4mb-dmabuffer.patch new file mode 100644 index 000000000..c80f11d9d --- /dev/null +++ b/hda_intel-prealloc-4mb-dmabuffer.patch @@ -0,0 +1,35 @@ +diff --git a/sound/pci/hda/hda_intel.c b/sound/pci/hda/hda_intel.c +index c8d9178..7d3bb15 100644 +--- a/sound/pci/hda/hda_intel.c ++++ b/sound/pci/hda/hda_intel.c +@@ -1774,6 +1774,7 @@ azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, + struct azx_pcm *apcm; + int pcm_dev = cpcm->device; + int s, err; ++ size_t prealloc_min = 64*1024; /* 64KB */ + + if (pcm_dev >= AZX_MAX_PCMS) { + snd_printk(KERN_ERR SFX "Invalid PCM device number %d\n", +@@ -1807,10 +1808,21 @@ azx_attach_pcm_stream(struct hda_bus *bus, struct hda_codec *codec, + if (cpcm->stream[s].substreams) + snd_pcm_set_ops(pcm, s, &azx_pcm_ops); + } ++ + /* buffer pre-allocation */ ++ ++ /* subtle, don't allocate a big buffer for modems... ++ * also, don't just test 32BIT_MASK, since azx supports ++ * 64-bit DMA in some cases. ++ */ ++ /* lennart wants a 2.2MB buffer for 2sec of 48khz */ ++ if (pcm->dev_class == SNDRV_PCM_CLASS_GENERIC && ++ chip->pci->dma_mask >= DMA_32BIT_MASK) ++ prealloc_min = 4 * 1024 * 1024; /* 4MB */ ++ + snd_pcm_lib_preallocate_pages_for_all(pcm, SNDRV_DMA_TYPE_DEV_SG, + snd_dma_pci_data(chip->pci), +- 1024 * 64, 32 * 1024 * 1024); ++ prealloc_min, 32 * 1024 * 1024); + return 0; + } + diff --git a/hdpvr-ir-enable.patch b/hdpvr-ir-enable.patch new file mode 100644 index 000000000..a5c7e922c --- /dev/null +++ b/hdpvr-ir-enable.patch @@ -0,0 +1,213 @@ +diff -Naurp a/drivers/media/video/hdpvr/hdpvr-core.c b/drivers/media/video/hdpvr/hdpvr-core.c +--- a/drivers/media/video/hdpvr/hdpvr-core.c 2010-07-06 17:36:44.000000000 -0400 ++++ b/drivers/media/video/hdpvr/hdpvr-core.c 2010-07-06 17:38:13.000000000 -0400 +@@ -363,9 +363,8 @@ static int hdpvr_probe(struct usb_interf + goto error; + } + +-#ifdef CONFIG_I2C +- /* until i2c is working properly */ +- retval = 0; /* hdpvr_register_i2c_adapter(dev); */ ++#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ++ retval = hdpvr_register_i2c_adapter(dev); + if (retval < 0) { + v4l2_err(&dev->v4l2_dev, "registering i2c adapter failed\n"); + goto error; +@@ -411,12 +410,9 @@ static void hdpvr_disconnect(struct usb_ + mutex_unlock(&dev->io_mutex); + + /* deregister I2C adapter */ +-#ifdef CONFIG_I2C ++#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) + mutex_lock(&dev->i2c_mutex); +- if (dev->i2c_adapter) +- i2c_del_adapter(dev->i2c_adapter); +- kfree(dev->i2c_adapter); +- dev->i2c_adapter = NULL; ++ i2c_del_adapter(&dev->i2c_adapter); + mutex_unlock(&dev->i2c_mutex); + #endif /* CONFIG_I2C */ + +diff -Naurp a/drivers/media/video/hdpvr/hdpvr.h b/drivers/media/video/hdpvr/hdpvr.h +--- a/drivers/media/video/hdpvr/hdpvr.h 2010-02-24 13:52:17.000000000 -0500 ++++ b/drivers/media/video/hdpvr/hdpvr.h 2010-07-06 17:42:20.000000000 -0400 +@@ -101,7 +101,7 @@ struct hdpvr_device { + struct work_struct worker; + + /* I2C adapter */ +- struct i2c_adapter *i2c_adapter; ++ struct i2c_adapter i2c_adapter; + /* I2C lock */ + struct mutex i2c_mutex; + +diff -Naurp a/drivers/media/video/hdpvr/hdpvr-i2c.c b/drivers/media/video/hdpvr/hdpvr-i2c.c +--- a/drivers/media/video/hdpvr/hdpvr-i2c.c 2010-07-06 17:36:51.000000000 -0400 ++++ b/drivers/media/video/hdpvr/hdpvr-i2c.c 2010-07-06 17:45:50.000000000 -0400 +@@ -10,6 +10,8 @@ + * + */ + ++#if defined(CONFIG_I2C) || defined(CONFIG_I2C_MODULE) ++ + #include + + #include "hdpvr.h" +@@ -19,10 +21,13 @@ + + #define REQTYPE_I2C_READ 0xb1 + #define REQTYPE_I2C_WRITE 0xb0 +-#define REQTYPE_I2C_WRITE_STATT 0xd0 ++#define REQTYPE_I2C_WRITE_STAT 0xd0 ++ ++#define HDPVR_HW_Z8F0811_IR_TX_I2C_ADDR 0x70 ++#define HDPVR_HW_Z8F0811_IR_RX_I2C_ADDR 0x71 + + static int hdpvr_i2c_read(struct hdpvr_device *dev, unsigned char addr, +- char *data, int len) ++ char *data, int len, int bus) + { + int ret; + char *buf = kmalloc(len, GFP_KERNEL); +@@ -32,7 +37,7 @@ static int hdpvr_i2c_read(struct hdpvr_d + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), + REQTYPE_I2C_READ, CTRL_READ_REQUEST, +- 0x100|addr, 0, buf, len, 1000); ++ bus<<8 | addr, 0, buf, len, 1000); + + if (ret == len) { + memcpy(data, buf, len); +@@ -46,7 +51,7 @@ static int hdpvr_i2c_read(struct hdpvr_d + } + + static int hdpvr_i2c_write(struct hdpvr_device *dev, unsigned char addr, +- char *data, int len) ++ char *data, int len, int bus) + { + int ret; + char *buf = kmalloc(len, GFP_KERNEL); +@@ -57,17 +62,17 @@ static int hdpvr_i2c_write(struct hdpvr_ + ret = usb_control_msg(dev->udev, + usb_sndctrlpipe(dev->udev, 0), + REQTYPE_I2C_WRITE, CTRL_WRITE_REQUEST, +- 0x100|addr, 0, buf, len, 1000); ++ bus<<8 | addr, 0, buf, len, 1000); + + if (ret < 0) + goto error; + + ret = usb_control_msg(dev->udev, + usb_rcvctrlpipe(dev->udev, 0), +- REQTYPE_I2C_WRITE_STATT, CTRL_READ_REQUEST, ++ REQTYPE_I2C_WRITE_STAT, CTRL_READ_REQUEST, + 0, 0, buf, 2, 1000); + +- if (ret == 2) ++ if (ret == 2 && buf[1] == (len - 1)) + ret = 0; + else if (ret >= 0) + ret = -EIO; +@@ -93,10 +98,10 @@ static int hdpvr_transfer(struct i2c_ada + + if (msgs[i].flags & I2C_M_RD) + retval = hdpvr_i2c_read(dev, addr, msgs[i].buf, +- msgs[i].len); ++ msgs[i].len, 1); + else + retval = hdpvr_i2c_write(dev, addr, msgs[i].buf, +- msgs[i].len); ++ msgs[i].len, 1); + } + + mutex_unlock(&dev->i2c_mutex); +@@ -114,31 +119,61 @@ static struct i2c_algorithm hdpvr_algo = + .functionality = hdpvr_functionality, + }; + ++static struct i2c_adapter hdpvr_i2c_adap_template = { ++ .name = "Hauppauge HD PVR I2C", ++ .owner = THIS_MODULE, ++ .id = I2C_HW_B_HDPVR, ++ .algo = &hdpvr_algo, ++ .algo_data = NULL, ++ .class = I2C_CLASS_TV_ANALOG, ++}; ++ ++static struct i2c_board_info hdpvr_i2c_board_info = { ++ I2C_BOARD_INFO("ir_tx_z8f0811_haup", HDPVR_HW_Z8F0811_IR_TX_I2C_ADDR), ++ I2C_BOARD_INFO("ir_rx_z8f0811_haup", HDPVR_HW_Z8F0811_IR_RX_I2C_ADDR), ++}; ++ ++static int hdpvr_activate_ir(struct hdpvr_device *dev) ++{ ++ char buffer[8]; ++ ++ mutex_lock(&dev->i2c_mutex); ++ ++ hdpvr_i2c_read(dev, 0x54, buffer, 1, 0); ++ ++ buffer[0] = 0; ++ buffer[1] = 0x8; ++ hdpvr_i2c_write(dev, 0x54, buffer, 2, 1); ++ ++ buffer[1] = 0x18; ++ hdpvr_i2c_write(dev, 0x54, buffer, 2, 1); ++ ++ mutex_unlock(&dev->i2c_mutex); ++ return 0; ++} ++ ++ + int hdpvr_register_i2c_adapter(struct hdpvr_device *dev) + { +- struct i2c_adapter *i2c_adap; + int retval = -ENOMEM; + +- i2c_adap = kzalloc(sizeof(struct i2c_adapter), GFP_KERNEL); +- if (i2c_adap == NULL) ++ hdpvr_activate_ir(dev); ++ ++ memcpy(&dev->i2c_adapter, &hdpvr_i2c_adap_template, ++ sizeof(struct i2c_adapter)); ++ dev->i2c_adapter.dev.parent = &dev->udev->dev; ++ ++ i2c_set_adapdata(&dev->i2c_adapter, dev); ++ ++ retval = i2c_add_adapter(&dev->i2c_adapter); ++ ++ if (retval) + goto error; + +- strlcpy(i2c_adap->name, "Hauppauge HD PVR I2C", +- sizeof(i2c_adap->name)); +- i2c_adap->algo = &hdpvr_algo; +- i2c_adap->class = I2C_CLASS_TV_ANALOG; +- i2c_adap->owner = THIS_MODULE; +- i2c_adap->dev.parent = &dev->udev->dev; +- +- i2c_set_adapdata(i2c_adap, dev); +- +- retval = i2c_add_adapter(i2c_adap); +- +- if (!retval) +- dev->i2c_adapter = i2c_adap; +- else +- kfree(i2c_adap); ++ i2c_new_device(&dev->i2c_adapter, &hdpvr_i2c_board_info); + + error: + return retval; + } ++ ++#endif /* CONFIG_I2C */ +diff -Naurp a/drivers/media/video/hdpvr/Makefile b/drivers/media/video/hdpvr/Makefile +--- a/drivers/media/video/hdpvr/Makefile 2010-07-06 17:36:38.000000000 -0400 ++++ b/drivers/media/video/hdpvr/Makefile 2010-07-06 17:35:17.000000000 -0400 +@@ -1,6 +1,4 @@ +-hdpvr-objs := hdpvr-control.o hdpvr-core.o hdpvr-video.o +- +-hdpvr-$(CONFIG_I2C) += hdpvr-i2c.o ++hdpvr-objs := hdpvr-control.o hdpvr-core.o hdpvr-i2c.o hdpvr-video.o + + obj-$(CONFIG_VIDEO_HDPVR) += hdpvr.o + diff --git a/ibmvscsi-fix-DMA-API-misuse.patch b/ibmvscsi-fix-DMA-API-misuse.patch new file mode 100644 index 000000000..5cb392e68 --- /dev/null +++ b/ibmvscsi-fix-DMA-API-misuse.patch @@ -0,0 +1,72 @@ +From b395ecef0de15c10459856e56a590ac1fe16be76 Mon Sep 17 00:00:00 2001 +From: FUJITA Tomonori +Date: Fri, 2 Apr 2010 15:50:24 +0900 +Subject: [SCSI] ibmvscsi: fix DMA API misuse + +ibmvscsi uses dma_unmap_single() for buffers mapped via +dma_map_sg(). It works however it's the API violation. The DMA debug +facility complains about it: + +http://marc.info/?l=linux-scsi&m=127018555013151&w=2 + +Reported-by: Sachin Sant +Tested-by: Sachin Sant +Signed-off-by: FUJITA Tomonori +Signed-off-by: James Bottomley + +(cherry picked from a71fa1fc43a29133f13ae6ada1a389ca298c0934) +--- + drivers/scsi/ibmvscsi/ibmvscsi.c | 29 ++--------------------------- + 1 files changed, 2 insertions(+), 27 deletions(-) + +diff --git a/drivers/scsi/ibmvscsi/ibmvscsi.c b/drivers/scsi/ibmvscsi/ibmvscsi.c +index e475b79..3b14bbe 100644 +--- a/drivers/scsi/ibmvscsi/ibmvscsi.c ++++ b/drivers/scsi/ibmvscsi/ibmvscsi.c +@@ -321,16 +321,6 @@ static void set_srp_direction(struct scsi_cmnd *cmd, + srp_cmd->buf_fmt = fmt; + } + +-static void unmap_sg_list(int num_entries, +- struct device *dev, +- struct srp_direct_buf *md) +-{ +- int i; +- +- for (i = 0; i < num_entries; ++i) +- dma_unmap_single(dev, md[i].va, md[i].len, DMA_BIDIRECTIONAL); +-} +- + /** + * unmap_cmd_data: - Unmap data pointed in srp_cmd based on the format + * @cmd: srp_cmd whose additional_data member will be unmapped +@@ -348,24 +338,9 @@ static void unmap_cmd_data(struct srp_cmd *cmd, + + if (out_fmt == SRP_NO_DATA_DESC && in_fmt == SRP_NO_DATA_DESC) + return; +- else if (out_fmt == SRP_DATA_DESC_DIRECT || +- in_fmt == SRP_DATA_DESC_DIRECT) { +- struct srp_direct_buf *data = +- (struct srp_direct_buf *) cmd->add_data; +- dma_unmap_single(dev, data->va, data->len, DMA_BIDIRECTIONAL); +- } else { +- struct srp_indirect_buf *indirect = +- (struct srp_indirect_buf *) cmd->add_data; +- int num_mapped = indirect->table_desc.len / +- sizeof(struct srp_direct_buf); + +- if (num_mapped <= MAX_INDIRECT_BUFS) { +- unmap_sg_list(num_mapped, dev, &indirect->desc_list[0]); +- return; +- } +- +- unmap_sg_list(num_mapped, dev, evt_struct->ext_list); +- } ++ if (evt_struct->cmnd) ++ scsi_dma_unmap(evt_struct->cmnd); + } + + static int map_sg_list(struct scsi_cmnd *cmd, int nseg, +-- +1.7.0.1 + diff --git a/inotify-fix-inotify-oneshot-support.patch b/inotify-fix-inotify-oneshot-support.patch new file mode 100644 index 000000000..ba63e1090 --- /dev/null +++ b/inotify-fix-inotify-oneshot-support.patch @@ -0,0 +1,25 @@ +#607327 + +During the large inotify rewrite to fsnotify I completely dropped support +for IN_ONESHOT. Reimplement that support. + +Signed-off-by: Eric Paris +--- + + fs/notify/inotify/inotify_fsnotify.c | 3 +++ + 1 files changed, 3 insertions(+), 0 deletions(-) + +diff --git a/fs/notify/inotify/inotify_fsnotify.c b/fs/notify/inotify/inotify_fsnotify.c +index daa666a..388a150 100644 +--- a/fs/notify/inotify/inotify_fsnotify.c ++++ b/fs/notify/inotify/inotify_fsnotify.c +@@ -126,6 +126,9 @@ static int inotify_handle_event(struct fsnotify_group *group, struct fsnotify_ev + ret = 0; + } + ++ if (entry->mask & IN_ONESHOT) ++ fsnotify_destroy_mark_by_entry(entry); ++ + /* + * If we hold the entry until after the event is on the queue + * IN_IGNORED won't be able to pass this event in the queue diff --git a/inotify-send-IN_UNMOUNT-events.patch b/inotify-send-IN_UNMOUNT-events.patch new file mode 100644 index 000000000..cf1d4c4bf --- /dev/null +++ b/inotify-send-IN_UNMOUNT-events.patch @@ -0,0 +1,29 @@ +#607327 ? + +Since the .31 or so notify rewrite inotify has not sent events about +inodes which are unmounted. This patch restores those events. + +Signed-off-by: Eric Paris +--- + + fs/notify/inotify/inotify_user.c | 7 +++++-- + 1 files changed, 5 insertions(+), 2 deletions(-) + +diff --git a/fs/notify/inotify/inotify_user.c b/fs/notify/inotify/inotify_user.c +index 44aeb0f..f381daf 100644 +--- a/fs/notify/inotify/inotify_user.c ++++ b/fs/notify/inotify/inotify_user.c +@@ -90,8 +90,11 @@ static inline __u32 inotify_arg_to_mask(u32 arg) + { + __u32 mask; + +- /* everything should accept their own ignored and cares about children */ +- mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD); ++ /* ++ * everything should accept their own ignored, cares about children, ++ * and should receive events when the inode is unmounted ++ */ ++ mask = (FS_IN_IGNORED | FS_EVENT_ON_CHILD | FS_UNMOUNT); + + /* mask off the flags used to open the fd */ + mask |= (arg & (IN_ALL_EVENTS | IN_ONESHOT)); diff --git a/iwlwifi-fix-internal-scan-race.patch b/iwlwifi-fix-internal-scan-race.patch new file mode 100644 index 000000000..18b315601 --- /dev/null +++ b/iwlwifi-fix-internal-scan-race.patch @@ -0,0 +1,123 @@ +From reinette.chatre@intel.com Thu May 13 17:49:59 2010 +Return-path: +Envelope-to: linville@tuxdriver.com +Delivery-date: Thu, 13 May 2010 17:49:59 -0400 +Received: from mga09.intel.com ([134.134.136.24]) + by smtp.tuxdriver.com with esmtp (Exim 4.63) + (envelope-from ) + id 1OCgI1-0007H3-Eg + for linville@tuxdriver.com; Thu, 13 May 2010 17:49:59 -0400 +Received: from orsmga002.jf.intel.com ([10.7.209.21]) + by orsmga102.jf.intel.com with ESMTP; 13 May 2010 14:48:04 -0700 +X-ExtLoop1: 1 +X-IronPort-AV: E=Sophos;i="4.53,224,1272870000"; + d="scan'208";a="517743256" +Received: from rchatre-desk.amr.corp.intel.com.jf.intel.com (HELO localhost.localdomain) ([134.134.15.94]) + by orsmga002.jf.intel.com with ESMTP; 13 May 2010 14:49:12 -0700 +From: Reinette Chatre +To: linville@tuxdriver.com +Cc: linux-wireless@vger.kernel.org, ipw3945-devel@lists.sourceforge.net, Reinette Chatre +Subject: [PATCH 1/2] iwlwifi: fix internal scan race +Date: Thu, 13 May 2010 14:49:44 -0700 +Message-Id: <1273787385-9248-2-git-send-email-reinette.chatre@intel.com> +X-Mailer: git-send-email 1.6.3.3 +In-Reply-To: <1273787385-9248-1-git-send-email-reinette.chatre@intel.com> +References: <1273787385-9248-1-git-send-email-reinette.chatre@intel.com> +X-Spam-Score: -4.2 (----) +X-Spam-Status: No +Status: RO +Content-Length: 3370 +Lines: 91 + +From: Reinette Chatre + +It is possible for internal scan to race against itself if the device is +not returning the scan results from first requests. What happens in this +case is the cleanup done during the abort of the first internal scan also +cleans up part of the new scan, causing it to access memory it shouldn't. + +Here are details: +* First internal scan is triggered and scan command sent to device. +* After seven seconds there is no scan results so the watchdog timer + triggers a scan abort. +* The scan abort succeeds and a SCAN_COMPLETE_NOTIFICATION is received for + failed scan. +* During processing of SCAN_COMPLETE_NOTIFICATION we clear STATUS_SCANNING + and queue the "scan_completed" work. +** At this time, since the problem that caused the internal scan in first + place is still present, a new internal scan is triggered. +The behavior at this point is a bit different between 2.6.34 and 2.6.35 +since 2.6.35 has a lot of this synchronized. The rest of the race +description will thus be generalized. +** As part of preparing for the scan "is_internal_short_scan" is set to +true. +* At this point the completion work for fist scan is run. As part of this + there is some locking missing around the "is_internal_short_scan" + variable and it is set to "false". +** Now the second scan runs and it considers itself a real (not internal0 + scan and thus causes problems with wrong memory being accessed. + +The fix is twofold. +* Since "is_internal_short_scan" should be protected by mutex, fix this in + scan completion work so that changes to it can be serialized. +* Do not queue a new internal scan if one is in progress. + +This fixes https://bugzilla.kernel.org/show_bug.cgi?id=15824 + +Signed-off-by: Reinette Chatre +--- + drivers/net/wireless/iwlwifi/iwl-scan.c | 21 ++++++++++++++++++--- + 1 files changed, 18 insertions(+), 3 deletions(-) + +diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c +index 2367286..a2c4855 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-scan.c ++++ b/drivers/net/wireless/iwlwifi/iwl-scan.c +@@ -560,6 +560,11 @@ static void iwl_bg_start_internal_scan(struct work_struct *work) + + mutex_lock(&priv->mutex); + ++ if (priv->is_internal_short_scan == true) { ++ IWL_DEBUG_SCAN(priv, "Internal scan already in progress\n"); ++ goto unlock; ++ } ++ + if (!iwl_is_ready_rf(priv)) { + IWL_DEBUG_SCAN(priv, "not ready or exit pending\n"); + goto unlock; +@@ -957,17 +962,27 @@ void iwl_bg_scan_completed(struct work_struct *work) + { + struct iwl_priv *priv = + container_of(work, struct iwl_priv, scan_completed); ++ bool internal = false; + + IWL_DEBUG_SCAN(priv, "SCAN complete scan\n"); + + cancel_delayed_work(&priv->scan_check); + +- if (!priv->is_internal_short_scan) +- ieee80211_scan_completed(priv->hw, false); +- else { ++ mutex_lock(&priv->mutex); ++ if (priv->is_internal_short_scan) { + priv->is_internal_short_scan = false; + IWL_DEBUG_SCAN(priv, "internal short scan completed\n"); ++ internal = true; + } ++ mutex_unlock(&priv->mutex); ++ ++ /* ++ * Do not hold mutex here since this will cause mac80211 to call ++ * into driver again into functions that will attempt to take ++ * mutex. ++ */ ++ if (!internal) ++ ieee80211_scan_completed(priv->hw, false); + + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return; +-- +1.6.3.3 + + + diff --git a/iwlwifi-fix-scan-races.patch b/iwlwifi-fix-scan-races.patch new file mode 100644 index 000000000..2e00f00ad --- /dev/null +++ b/iwlwifi-fix-scan-races.patch @@ -0,0 +1,139 @@ +commit 88be026490ed89c2ffead81a52531fbac5507e01 +Author: Johannes Berg +Date: Wed Apr 7 00:21:36 2010 -0700 + + iwlwifi: fix scan races + + When an internal scan is started, nothing protects the + is_internal_short_scan variable which can cause crashes, + cf. https://bugzilla.kernel.org/show_bug.cgi?id=15667. + Fix this by making the short scan request use the mutex + for locking, which requires making the request go to a + work struct so that it can sleep. + + Reported-by: Peter Zijlstra + Signed-off-by: Johannes Berg + Signed-off-by: Reinette Chatre + +diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c +index e4c2e1e..ba0fdba 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-agn.c ++++ b/drivers/net/wireless/iwlwifi/iwl-agn.c +@@ -3330,6 +3330,7 @@ static void iwl_cancel_deferred_work(struct iwl_priv *priv) + + cancel_delayed_work_sync(&priv->init_alive_start); + cancel_delayed_work(&priv->scan_check); ++ cancel_work_sync(&priv->start_internal_scan); + cancel_delayed_work(&priv->alive_start); + cancel_work_sync(&priv->beacon_update); + del_timer_sync(&priv->statistics_periodic); +diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c +index 894bcb8..1459cdb 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-core.c ++++ b/drivers/net/wireless/iwlwifi/iwl-core.c +@@ -3357,7 +3357,6 @@ static void iwl_force_rf_reset(struct iwl_priv *priv) + */ + IWL_DEBUG_INFO(priv, "perform radio reset.\n"); + iwl_internal_short_hw_scan(priv); +- return; + } + + +diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h +index 732590f..36940a9 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-core.h ++++ b/drivers/net/wireless/iwlwifi/iwl-core.h +@@ -506,7 +506,7 @@ void iwl_init_scan_params(struct iwl_priv *priv); + int iwl_scan_cancel(struct iwl_priv *priv); + int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); + int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req); +-int iwl_internal_short_hw_scan(struct iwl_priv *priv); ++void iwl_internal_short_hw_scan(struct iwl_priv *priv); + int iwl_force_reset(struct iwl_priv *priv, int mode); + u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, + const u8 *ie, int ie_len, int left); +diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h +index 6054c5f..ef1720a 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-dev.h ++++ b/drivers/net/wireless/iwlwifi/iwl-dev.h +@@ -1296,6 +1296,7 @@ struct iwl_priv { + struct work_struct tt_work; + struct work_struct ct_enter; + struct work_struct ct_exit; ++ struct work_struct start_internal_scan; + + struct tasklet_struct irq_tasklet; + +diff --git a/drivers/net/wireless/iwlwifi/iwl-scan.c b/drivers/net/wireless/iwlwifi/iwl-scan.c +index bd2f7c4..5062f4e 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-scan.c ++++ b/drivers/net/wireless/iwlwifi/iwl-scan.c +@@ -469,6 +469,8 @@ EXPORT_SYMBOL(iwl_init_scan_params); + + static int iwl_scan_initiate(struct iwl_priv *priv) + { ++ WARN_ON(!mutex_is_locked(&priv->mutex)); ++ + IWL_DEBUG_INFO(priv, "Starting scan...\n"); + set_bit(STATUS_SCANNING, &priv->status); + priv->is_internal_short_scan = false; +@@ -546,24 +548,31 @@ EXPORT_SYMBOL(iwl_mac_hw_scan); + * internal short scan, this function should only been called while associated. + * It will reset and tune the radio to prevent possible RF related problem + */ +-int iwl_internal_short_hw_scan(struct iwl_priv *priv) ++void iwl_internal_short_hw_scan(struct iwl_priv *priv) + { +- int ret = 0; ++ queue_work(priv->workqueue, &priv->start_internal_scan); ++} ++ ++static void iwl_bg_start_internal_scan(struct work_struct *work) ++{ ++ struct iwl_priv *priv = ++ container_of(work, struct iwl_priv, start_internal_scan); ++ ++ mutex_lock(&priv->mutex); + + if (!iwl_is_ready_rf(priv)) { +- ret = -EIO; + IWL_DEBUG_SCAN(priv, "not ready or exit pending\n"); +- goto out; ++ goto unlock; + } ++ + if (test_bit(STATUS_SCANNING, &priv->status)) { + IWL_DEBUG_SCAN(priv, "Scan already in progress.\n"); +- ret = -EAGAIN; +- goto out; ++ goto unlock; + } ++ + if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { + IWL_DEBUG_SCAN(priv, "Scan request while abort pending\n"); +- ret = -EAGAIN; +- goto out; ++ goto unlock; + } + + priv->scan_bands = 0; +@@ -576,9 +585,8 @@ int iwl_internal_short_hw_scan(struct iwl_priv *priv) + set_bit(STATUS_SCANNING, &priv->status); + priv->is_internal_short_scan = true; + queue_work(priv->workqueue, &priv->request_scan); +- +-out: +- return ret; ++ unlock: ++ mutex_unlock(&priv->mutex); + } + EXPORT_SYMBOL(iwl_internal_short_hw_scan); + +@@ -964,6 +972,7 @@ void iwl_setup_scan_deferred_work(struct iwl_priv *priv) + INIT_WORK(&priv->scan_completed, iwl_bg_scan_completed); + INIT_WORK(&priv->request_scan, iwl_bg_request_scan); + INIT_WORK(&priv->abort_scan, iwl_bg_abort_scan); ++ INIT_WORK(&priv->start_internal_scan, iwl_bg_start_internal_scan); + INIT_DELAYED_WORK(&priv->scan_check, iwl_bg_scan_check); + } + EXPORT_SYMBOL(iwl_setup_scan_deferred_work); diff --git a/iwlwifi-manage-QoS-by-mac-stack.patch b/iwlwifi-manage-QoS-by-mac-stack.patch new file mode 100644 index 000000000..940b8ea88 --- /dev/null +++ b/iwlwifi-manage-QoS-by-mac-stack.patch @@ -0,0 +1,361 @@ +From: Stanislaw Gruszka +To: kernel@lists.fedoraproject.org, "John W. Linville" +Subject: [PATCH 2/4 2.6.33.y] iwlwifi: manage QoS by mac stack +Date: Fri, 11 Jun 2010 17:04:18 +0200 + +commit e61146e36b40fd9d346118c40285913236c329f3 upstream. + +We activate/deactivate QoS and setup default queue parameters in iwlwifi +driver. Mac stack do the same, so we do not need repeat that work here. +Stack also will tell when disable QoS, this will fix driver when working +with older APs, that do not have QoS implemented. + +Patch make "force = true" in iwl_active_qos() assuming we always want +to do with QoS what mac stack wish. + +Patch also remove unused qos_cap bits, do not initialize qos_active = 0, +as we have it initialized to zero by kzalloc. + +Signed-off-by: Stanislaw Gruszka +--- + drivers/net/wireless/iwlwifi/iwl-agn.c | 15 --- + drivers/net/wireless/iwlwifi/iwl-core.c | 142 +++------------------------ + drivers/net/wireless/iwlwifi/iwl-core.h | 3 +- + drivers/net/wireless/iwlwifi/iwl-dev.h | 21 ---- + drivers/net/wireless/iwlwifi/iwl3945-base.c | 7 -- + 5 files changed, 17 insertions(+), 171 deletions(-) + +diff --git a/drivers/net/wireless/iwlwifi/iwl-agn.c b/drivers/net/wireless/iwlwifi/iwl-agn.c +index 5622a55..9ba4207 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-agn.c ++++ b/drivers/net/wireless/iwlwifi/iwl-agn.c +@@ -2327,7 +2327,6 @@ void iwl_post_associate(struct iwl_priv *priv) + { + struct ieee80211_conf *conf = NULL; + int ret = 0; +- unsigned long flags; + + if (priv->iw_mode == NL80211_IFTYPE_AP) { + IWL_ERR(priv, "%s Should not be called in AP mode\n", __func__); +@@ -2412,10 +2411,6 @@ void iwl_post_associate(struct iwl_priv *priv) + if (priv->iw_mode == NL80211_IFTYPE_ADHOC) + priv->assoc_station_added = 1; + +- spin_lock_irqsave(&priv->lock, flags); +- iwl_activate_qos(priv, 0); +- spin_unlock_irqrestore(&priv->lock, flags); +- + /* the chain noise calibration will enabled PM upon completion + * If chain noise has already been run, then we need to enable + * power management here */ +@@ -2602,7 +2597,6 @@ static int iwl_mac_tx(struct ieee80211_hw *hw, struct sk_buff *skb) + void iwl_config_ap(struct iwl_priv *priv) + { + int ret = 0; +- unsigned long flags; + + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return; +@@ -2654,10 +2648,6 @@ void iwl_config_ap(struct iwl_priv *priv) + /* restore RXON assoc */ + priv->staging_rxon.filter_flags |= RXON_FILTER_ASSOC_MSK; + iwlcore_commit_rxon(priv); +- iwl_reset_qos(priv); +- spin_lock_irqsave(&priv->lock, flags); +- iwl_activate_qos(priv, 1); +- spin_unlock_irqrestore(&priv->lock, flags); + iwl_add_bcast_station(priv); + } + iwl_send_beacon_cmd(priv); +@@ -3195,11 +3185,6 @@ static int iwl_init_drv(struct iwl_priv *priv) + + iwl_init_scan_params(priv); + +- iwl_reset_qos(priv); +- +- priv->qos_data.qos_active = 0; +- priv->qos_data.qos_cap.val = 0; +- + priv->rates_mask = IWL_RATES_MASK; + /* Set the tx_power_user_lmt to the lowest power level + * this value will get overwritten by channel max power avg +diff --git a/drivers/net/wireless/iwlwifi/iwl-core.c b/drivers/net/wireless/iwlwifi/iwl-core.c +index 6e9e156..d79b1e9 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-core.c ++++ b/drivers/net/wireless/iwlwifi/iwl-core.c +@@ -301,17 +301,13 @@ EXPORT_SYMBOL(iwl_hw_nic_init); + /* + * QoS support + */ +-void iwl_activate_qos(struct iwl_priv *priv, u8 force) ++static void iwl_update_qos(struct iwl_priv *priv) + { + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return; + + priv->qos_data.def_qos_parm.qos_flags = 0; + +- if (priv->qos_data.qos_cap.q_AP.queue_request && +- !priv->qos_data.qos_cap.q_AP.txop_request) +- priv->qos_data.def_qos_parm.qos_flags |= +- QOS_PARAM_FLG_TXOP_TYPE_MSK; + if (priv->qos_data.qos_active) + priv->qos_data.def_qos_parm.qos_flags |= + QOS_PARAM_FLG_UPDATE_EDCA_MSK; +@@ -319,118 +315,14 @@ void iwl_activate_qos(struct iwl_priv *priv, u8 force) + if (priv->current_ht_config.is_ht) + priv->qos_data.def_qos_parm.qos_flags |= QOS_PARAM_FLG_TGN_MSK; + +- if (force || iwl_is_associated(priv)) { +- IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", +- priv->qos_data.qos_active, +- priv->qos_data.def_qos_parm.qos_flags); ++ IWL_DEBUG_QOS(priv, "send QoS cmd with Qos active=%d FLAGS=0x%X\n", ++ priv->qos_data.qos_active, ++ priv->qos_data.def_qos_parm.qos_flags); + +- iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM, +- sizeof(struct iwl_qosparam_cmd), +- &priv->qos_data.def_qos_parm, NULL); +- } ++ iwl_send_cmd_pdu_async(priv, REPLY_QOS_PARAM, ++ sizeof(struct iwl_qosparam_cmd), ++ &priv->qos_data.def_qos_parm, NULL); + } +-EXPORT_SYMBOL(iwl_activate_qos); +- +-/* +- * AC CWmin CW max AIFSN TXOP Limit TXOP Limit +- * (802.11b) (802.11a/g) +- * AC_BK 15 1023 7 0 0 +- * AC_BE 15 1023 3 0 0 +- * AC_VI 7 15 2 6.016ms 3.008ms +- * AC_VO 3 7 2 3.264ms 1.504ms +- */ +-void iwl_reset_qos(struct iwl_priv *priv) +-{ +- u16 cw_min = 15; +- u16 cw_max = 1023; +- u8 aifs = 2; +- bool is_legacy = false; +- unsigned long flags; +- int i; +- +- spin_lock_irqsave(&priv->lock, flags); +- /* QoS always active in AP and ADHOC mode +- * In STA mode wait for association +- */ +- if (priv->iw_mode == NL80211_IFTYPE_ADHOC || +- priv->iw_mode == NL80211_IFTYPE_AP) +- priv->qos_data.qos_active = 1; +- else +- priv->qos_data.qos_active = 0; +- +- /* check for legacy mode */ +- if ((priv->iw_mode == NL80211_IFTYPE_ADHOC && +- (priv->active_rate & IWL_OFDM_RATES_MASK) == 0) || +- (priv->iw_mode == NL80211_IFTYPE_STATION && +- (priv->staging_rxon.flags & RXON_FLG_SHORT_SLOT_MSK) == 0)) { +- cw_min = 31; +- is_legacy = 1; +- } +- +- if (priv->qos_data.qos_active) +- aifs = 3; +- +- /* AC_BE */ +- priv->qos_data.def_qos_parm.ac[0].cw_min = cpu_to_le16(cw_min); +- priv->qos_data.def_qos_parm.ac[0].cw_max = cpu_to_le16(cw_max); +- priv->qos_data.def_qos_parm.ac[0].aifsn = aifs; +- priv->qos_data.def_qos_parm.ac[0].edca_txop = 0; +- priv->qos_data.def_qos_parm.ac[0].reserved1 = 0; +- +- if (priv->qos_data.qos_active) { +- /* AC_BK */ +- i = 1; +- priv->qos_data.def_qos_parm.ac[i].cw_min = cpu_to_le16(cw_min); +- priv->qos_data.def_qos_parm.ac[i].cw_max = cpu_to_le16(cw_max); +- priv->qos_data.def_qos_parm.ac[i].aifsn = 7; +- priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; +- priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; +- +- /* AC_VI */ +- i = 2; +- priv->qos_data.def_qos_parm.ac[i].cw_min = +- cpu_to_le16((cw_min + 1) / 2 - 1); +- priv->qos_data.def_qos_parm.ac[i].cw_max = +- cpu_to_le16(cw_min); +- priv->qos_data.def_qos_parm.ac[i].aifsn = 2; +- if (is_legacy) +- priv->qos_data.def_qos_parm.ac[i].edca_txop = +- cpu_to_le16(6016); +- else +- priv->qos_data.def_qos_parm.ac[i].edca_txop = +- cpu_to_le16(3008); +- priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; +- +- /* AC_VO */ +- i = 3; +- priv->qos_data.def_qos_parm.ac[i].cw_min = +- cpu_to_le16((cw_min + 1) / 4 - 1); +- priv->qos_data.def_qos_parm.ac[i].cw_max = +- cpu_to_le16((cw_min + 1) / 2 - 1); +- priv->qos_data.def_qos_parm.ac[i].aifsn = 2; +- priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; +- if (is_legacy) +- priv->qos_data.def_qos_parm.ac[i].edca_txop = +- cpu_to_le16(3264); +- else +- priv->qos_data.def_qos_parm.ac[i].edca_txop = +- cpu_to_le16(1504); +- } else { +- for (i = 1; i < 4; i++) { +- priv->qos_data.def_qos_parm.ac[i].cw_min = +- cpu_to_le16(cw_min); +- priv->qos_data.def_qos_parm.ac[i].cw_max = +- cpu_to_le16(cw_max); +- priv->qos_data.def_qos_parm.ac[i].aifsn = aifs; +- priv->qos_data.def_qos_parm.ac[i].edca_txop = 0; +- priv->qos_data.def_qos_parm.ac[i].reserved1 = 0; +- } +- } +- IWL_DEBUG_QOS(priv, "set QoS to default \n"); +- +- spin_unlock_irqrestore(&priv->lock, flags); +-} +-EXPORT_SYMBOL(iwl_reset_qos); + + #define MAX_BIT_RATE_40_MHZ 150 /* Mbps */ + #define MAX_BIT_RATE_20_MHZ 72 /* Mbps */ +@@ -2273,12 +2165,6 @@ int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, + cpu_to_le16((params->txop * 32)); + + priv->qos_data.def_qos_parm.ac[q].reserved1 = 0; +- priv->qos_data.qos_active = 1; +- +- if (priv->iw_mode == NL80211_IFTYPE_AP) +- iwl_activate_qos(priv, 1); +- else if (priv->assoc_id && iwl_is_associated(priv)) +- iwl_activate_qos(priv, 0); + + spin_unlock_irqrestore(&priv->lock, flags); + +@@ -2554,11 +2440,8 @@ int iwl_mac_beacon_update(struct ieee80211_hw *hw, struct sk_buff *skb) + IWL_DEBUG_MAC80211(priv, "leave\n"); + spin_unlock_irqrestore(&priv->lock, flags); + +- iwl_reset_qos(priv); +- + priv->cfg->ops->lib->post_associate(priv); + +- + return 0; + } + EXPORT_SYMBOL(iwl_mac_beacon_update); +@@ -2790,6 +2673,15 @@ int iwl_mac_config(struct ieee80211_hw *hw, u32 changed) + if (priv->cfg->ops->hcmd->set_rxon_chain) + priv->cfg->ops->hcmd->set_rxon_chain(priv); + ++ if (changed & IEEE80211_CONF_CHANGE_QOS) { ++ bool qos_active = !!(conf->flags & IEEE80211_CONF_QOS); ++ ++ spin_lock_irqsave(&priv->lock, flags); ++ priv->qos_data.qos_active = qos_active; ++ iwl_update_qos(priv); ++ spin_unlock_irqrestore(&priv->lock, flags); ++ } ++ + if (!iwl_is_ready(priv)) { + IWL_DEBUG_MAC80211(priv, "leave - not ready\n"); + goto out; +@@ -2860,8 +2752,6 @@ void iwl_mac_reset_tsf(struct ieee80211_hw *hw) + memset(&priv->current_ht_config, 0, sizeof(struct iwl_ht_config)); + spin_unlock_irqrestore(&priv->lock, flags); + +- iwl_reset_qos(priv); +- + spin_lock_irqsave(&priv->lock, flags); + priv->assoc_id = 0; + priv->assoc_capability = 0; +diff --git a/drivers/net/wireless/iwlwifi/iwl-core.h b/drivers/net/wireless/iwlwifi/iwl-core.h +index b69e972..403f512 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-core.h ++++ b/drivers/net/wireless/iwlwifi/iwl-core.h +@@ -298,8 +298,7 @@ struct iwl_cfg { + struct ieee80211_hw *iwl_alloc_all(struct iwl_cfg *cfg, + struct ieee80211_ops *hw_ops); + void iwl_hw_detect(struct iwl_priv *priv); +-void iwl_reset_qos(struct iwl_priv *priv); +-void iwl_activate_qos(struct iwl_priv *priv, u8 force); ++void iwl_activate_qos(struct iwl_priv *priv); + int iwl_mac_conf_tx(struct ieee80211_hw *hw, u16 queue, + const struct ieee80211_tx_queue_params *params); + void iwl_set_rxon_hwcrypto(struct iwl_priv *priv, int hw_decrypt); +diff --git a/drivers/net/wireless/iwlwifi/iwl-dev.h b/drivers/net/wireless/iwlwifi/iwl-dev.h +index 3822cf5..f2a9356 100644 +--- a/drivers/net/wireless/iwlwifi/iwl-dev.h ++++ b/drivers/net/wireless/iwlwifi/iwl-dev.h +@@ -518,30 +518,9 @@ struct iwl_ht_config { + u8 non_GF_STA_present; + }; + +-union iwl_qos_capabity { +- struct { +- u8 edca_count:4; /* bit 0-3 */ +- u8 q_ack:1; /* bit 4 */ +- u8 queue_request:1; /* bit 5 */ +- u8 txop_request:1; /* bit 6 */ +- u8 reserved:1; /* bit 7 */ +- } q_AP; +- struct { +- u8 acvo_APSD:1; /* bit 0 */ +- u8 acvi_APSD:1; /* bit 1 */ +- u8 ac_bk_APSD:1; /* bit 2 */ +- u8 ac_be_APSD:1; /* bit 3 */ +- u8 q_ack:1; /* bit 4 */ +- u8 max_len:2; /* bit 5-6 */ +- u8 more_data_ack:1; /* bit 7 */ +- } q_STA; +- u8 val; +-}; +- + /* QoS structures */ + struct iwl_qos_info { + int qos_active; +- union iwl_qos_capabity qos_cap; + struct iwl_qosparam_cmd def_qos_parm; + }; + +diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c +index adbb3ea..2280ba7 100644 +--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c ++++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c +@@ -3127,8 +3127,6 @@ void iwl3945_post_associate(struct iwl_priv *priv) + break; + } + +- iwl_activate_qos(priv, 0); +- + /* we have just associated, don't start scan too early */ + priv->next_scan_jiffies = jiffies + IWL_DELAY_NEXT_SCAN; + } +@@ -3841,11 +3839,6 @@ static int iwl3945_init_drv(struct iwl_priv *priv) + + priv->iw_mode = NL80211_IFTYPE_STATION; + +- iwl_reset_qos(priv); +- +- priv->qos_data.qos_active = 0; +- priv->qos_data.qos_cap.val = 0; +- + priv->rates_mask = IWL_RATES_MASK; + priv->tx_power_user_lmt = IWL_DEFAULT_TX_POWER; + +-- +1.6.2.5 + +_______________________________________________ +kernel mailing list +kernel@lists.fedoraproject.org +https://admin.fedoraproject.org/mailman/listinfo/kernel + diff --git a/iwlwifi-recover_from_tx_stall.patch b/iwlwifi-recover_from_tx_stall.patch new file mode 100644 index 000000000..0b69e44f5 --- /dev/null +++ b/iwlwifi-recover_from_tx_stall.patch @@ -0,0 +1,13 @@ +https://bugzilla.redhat.com/show_bug.cgi?id=589777#c5 + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c.orig 2010-05-19 16:07:15.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c 2010-05-19 16:09:42.000000000 -0400 +@@ -2794,6 +2794,7 @@ static struct iwl_lib_ops iwl3945_lib = + .post_associate = iwl3945_post_associate, + .isr = iwl_isr_legacy, + .config_ap = iwl3945_config_ap, ++ .recover_from_tx_stall = iwl_bg_monitor_recover, + }; + + static struct iwl_hcmd_utils_ops iwl3945_hcmd_utils = { diff --git a/iwlwifi_-Adjusting-PLCP-error-threshold-for-1000-NIC.patch b/iwlwifi_-Adjusting-PLCP-error-threshold-for-1000-NIC.patch new file mode 100644 index 000000000..ab6c4d62d --- /dev/null +++ b/iwlwifi_-Adjusting-PLCP-error-threshold-for-1000-NIC.patch @@ -0,0 +1,48 @@ +Backport of the following upstream commit... + +commit 6c3872e1d52290dcd506473028867cacc6b7393d +Author: Trieu 'Andrew' Nguyen +Date: Mon Feb 8 13:53:05 2010 -0800 + + iwlwifi: Adjusting PLCP error threshold for 1000 NIC + + While testing the station with the NIC 1000 family, it is found that + the plcp error can easily exceed 50 value in 100mSecs. This creates + unneccessary radio reset/tuning. This patch raises the PLCP error + threshold of the NIC 1000 from 50 to 200 error count. + + Signed-off-by: Trieu 'Andrew' Nguyen + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig 2010-04-13 13:44:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c 2010-04-13 13:45:51.000000000 -0400 +@@ -174,7 +174,7 @@ struct iwl_cfg iwl1000_bgn_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, +- .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl1000_bg_cfg = { +@@ -201,7 +201,7 @@ struct iwl_cfg iwl1000_bg_cfg = { + .led_compensation = 51, + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .support_ct_kill_exit = true, +- .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, + }; + + MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 13:44:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 13:45:06.000000000 -0400 +@@ -991,6 +991,7 @@ struct iwl_switch_rxon { + #define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (0) + #define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50) + #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100) ++#define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200) + #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255) + + enum iwl_reset { diff --git a/iwlwifi_-Logic-to-control-how-frequent-radio-should-be-reset-if-needed.patch b/iwlwifi_-Logic-to-control-how-frequent-radio-should-be-reset-if-needed.patch new file mode 100644 index 000000000..72618dd8d --- /dev/null +++ b/iwlwifi_-Logic-to-control-how-frequent-radio-should-be-reset-if-needed.patch @@ -0,0 +1,81 @@ +Backport of the following upstream commit... + +commit d4d59e88cb746165c6fe33eacb6f582d525c6ef1 +Author: Wey-Yi Guy +Date: Fri Jan 22 14:22:45 2010 -0800 + + iwlwifi: Logic to control how frequent radio should be reset if needed + + Add additional logic for internal scan routine to control how + frequent this function should be performed. + + The intent of this function is to reset/re-tune the radio and bring the + RF/PHY back to normal state, it does not make sense calling it too + frequent, + if reset the radio can not bring it back to normal state, it indicate + there are other reason to cause the radio not operate correctly. + + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + Signed-off-by: John W. Linville + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 11:53:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 11:59:18.000000000 -0400 +@@ -1034,6 +1034,7 @@ struct iwl_priv { + unsigned long scan_start; + unsigned long scan_pass_start; + unsigned long scan_start_tsf; ++ unsigned long last_internal_scan_jiffies; + void *scan; + int scan_bands; + struct cfg80211_scan_request *scan_request; +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c.orig 2010-04-13 11:53:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c 2010-04-13 12:01:06.000000000 -0400 +@@ -204,7 +204,8 @@ static void iwl_rx_scan_results_notif(st + #endif + + priv->last_scan_jiffies = jiffies; +- priv->next_scan_jiffies = 0; ++ if (!priv->is_internal_short_scan) ++ priv->next_scan_jiffies = 0; + } + + /* Service SCAN_COMPLETE_NOTIFICATION (0x84) */ +@@ -251,7 +252,11 @@ static void iwl_rx_scan_complete_notif(s + } + + priv->last_scan_jiffies = jiffies; +- priv->next_scan_jiffies = 0; ++ if (!priv->is_internal_short_scan) ++ priv->next_scan_jiffies = 0; ++ else ++ priv->last_internal_scan_jiffies = jiffies; ++ + IWL_DEBUG_INFO(priv, "Setting scan to off\n"); + + clear_bit(STATUS_SCANNING, &priv->status); +@@ -559,6 +564,8 @@ EXPORT_SYMBOL(iwl_mac_hw_scan); + * internal short scan, this function should only been called while associated. + * It will reset and tune the radio to prevent possible RF related problem + */ ++#define IWL_DELAY_NEXT_INTERNAL_SCAN (HZ*1) ++ + int iwl_internal_short_hw_scan(struct iwl_priv *priv) + { + int ret = 0; +@@ -578,6 +585,13 @@ int iwl_internal_short_hw_scan(struct iw + ret = -EAGAIN; + goto out; + } ++ if (priv->last_internal_scan_jiffies && ++ time_after(priv->last_internal_scan_jiffies + ++ IWL_DELAY_NEXT_INTERNAL_SCAN, jiffies)) { ++ IWL_DEBUG_SCAN(priv, "internal scan rejected\n"); ++ goto out; ++ } ++ + priv->scan_bands = 0; + if (priv->band == IEEE80211_BAND_5GHZ) + priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); diff --git a/iwlwifi_-Recover-TX-flow-failure.patch b/iwlwifi_-Recover-TX-flow-failure.patch new file mode 100644 index 000000000..a5566d6a0 --- /dev/null +++ b/iwlwifi_-Recover-TX-flow-failure.patch @@ -0,0 +1,131 @@ +Backport of the following upstream commit... + +commit d5a0ffa3eaf9e898f25a925813f1a723be7808f8 +Author: Wey-Yi Guy +Date: Thu Mar 4 13:38:59 2010 -0800 + + iwlwifi: Recover TX flow failure + + Monitors the tx statistics to detect the drop in throughput. + When the throughput drops, the ratio of the actual_ack_count and the + expected_ack_count also drops. At the same time, the aggregated + ba_timeout (the number of ba timeout retries) also rises. If the + actual_ack_count/expected_ack_count ratio is 0 and the number of ba + timeout retries rises to BA_TIMEOUT_MAX, no tx packets can be delivered. + Reloading the uCode and bring the system back to normal operational + state. + + Signed-off-by: Trieu 'Andrew' Nguyen + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig 2010-04-13 14:44:38.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c 2010-04-13 14:53:47.000000000 -0400 +@@ -2783,10 +2783,21 @@ static int iwl_mac_ampdu_action(struct i + return ret; + case IEEE80211_AMPDU_TX_START: + IWL_DEBUG_HT(priv, "start Tx\n"); +- return iwl_tx_agg_start(priv, sta->addr, tid, ssn); ++ ret = iwl_tx_agg_start(priv, sta->addr, tid, ssn); ++ if (ret == 0) { ++ priv->agg_tids_count++; ++ IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", ++ priv->agg_tids_count); ++ } ++ return ret; + case IEEE80211_AMPDU_TX_STOP: + IWL_DEBUG_HT(priv, "stop Tx\n"); + ret = iwl_tx_agg_stop(priv, sta->addr, tid); ++ if ((ret == 0) && (priv->agg_tids_count > 0)) { ++ priv->agg_tids_count--; ++ IWL_DEBUG_HT(priv, "priv->agg_tids_count = %u\n", ++ priv->agg_tids_count); ++ } + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return 0; + else +@@ -3204,6 +3215,7 @@ static int iwl_init_drv(struct iwl_priv + priv->band = IEEE80211_BAND_2GHZ; + + priv->iw_mode = NL80211_IFTYPE_STATION; ++ priv->agg_tids_count = 0; + + /* initialize force reset */ + priv->force_reset[IWL_RF_RESET].reset_duration = +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 14:44:38.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 14:53:19.000000000 -0400 +@@ -1239,6 +1239,11 @@ struct iwl_priv { + void *ict_tbl_vir; + u32 inta; + bool use_ict; ++ /* ++ * reporting the number of tids has AGG on. 0 means ++ * no AGGREGATION ++ */ ++ u8 agg_tids_count; + + u32 inta_mask; + /* Current association information needed to configure the +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig 2010-04-13 14:44:38.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c 2010-04-13 14:56:17.000000000 -0400 +@@ -593,9 +593,18 @@ static void iwl_accumulative_statistics( + + #define REG_RECALIB_PERIOD (60) + ++/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ ++#define ACK_CNT_RATIO (50) ++#define BA_TIMEOUT_CNT (5) ++#define BA_TIMEOUT_MAX (16) ++ + #define PLCP_MSG "plcp_err exceeded %u, %u, %u, %u, %u, %d, %u mSecs\n" + /* +- * This function checks for plcp error. ++ * This function checks for plcp error, ACK count ratios, aggregated BA ++ * timeout retries. ++ * - When the ACK count ratio is 0 and aggregated BA timeout retries is ++ * exceeding the BA_TIMEOUT_MAX, it will recover the failure by resetting ++ * the firmware. + * - When the plcp error is exceeding the thresholds, it will reset the radio + * to improve the throughput. + */ +@@ -605,6 +614,37 @@ void iwl_recover_from_statistics(struct + int combined_plcp_delta; + unsigned int plcp_msec; + unsigned long plcp_received_jiffies; ++ int actual_ack_cnt_delta; ++ int expected_ack_cnt_delta; ++ int ba_timeout_delta; ++ ++ actual_ack_cnt_delta = ++ le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) - ++ le32_to_cpu(priv->statistics.tx.actual_ack_cnt); ++ expected_ack_cnt_delta = ++ le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) - ++ le32_to_cpu(priv->statistics.tx.expected_ack_cnt); ++ ba_timeout_delta = ++ le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) - ++ le32_to_cpu(priv->statistics.tx.agg.ba_timeout); ++ if ((priv->agg_tids_count > 0) && ++ (expected_ack_cnt_delta > 0) && ++ (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta) ++ < ACK_CNT_RATIO) && ++ (ba_timeout_delta > BA_TIMEOUT_CNT)) { ++ IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d," ++ " expected_ack_cnt = %d\n", ++ actual_ack_cnt_delta, expected_ack_cnt_delta); ++ ++ IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n", ++ ba_timeout_delta); ++ if ((actual_ack_cnt_delta == 0) && ++ (ba_timeout_delta >= BA_TIMEOUT_MAX)) { ++ IWL_DEBUG_RADIO(priv, ++ "call iwl_force_reset(IWL_FW_RESET)\n"); ++ iwl_force_reset(priv, IWL_FW_RESET); ++ } ++ } + + /* + * check for plcp_err and trigger radio reset if it exceeds diff --git a/iwlwifi_-Recover-TX-flow-stall-due-to-stuck-queue.patch b/iwlwifi_-Recover-TX-flow-stall-due-to-stuck-queue.patch new file mode 100644 index 000000000..218a1b23a --- /dev/null +++ b/iwlwifi_-Recover-TX-flow-stall-due-to-stuck-queue.patch @@ -0,0 +1,472 @@ +Backport of the following upstream commit... + +commit b74e31a9bc1013e69b85b139072485dc153453dd +Author: Wey-Yi Guy +Date: Mon Mar 1 17:23:50 2010 -0800 + + iwlwifi: Recover TX flow stall due to stuck queue + + Monitors the internal TX queues periodically. When a queue is stuck + for some unknown conditions causing the throughput to drop and the + transfer is stop, the driver will force firmware reload and bring the + system back to normal operational state. + + The iwlwifi devices behave differently in this regard so this feature is + made part of the ops infrastructure so we can have more control on how to + monitor and recover from tx queue stall case per device. + + Signed-off-by: Trieu 'Andrew' Nguyen + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c 2010-04-13 14:34:23.000000000 -0400 +@@ -138,6 +138,7 @@ static struct iwl_lib_ops iwl1000_lib = + .temperature = iwl5000_temperature, + .set_ct_kill = iwl1000_set_ct_threshold, + }, ++ .recover_from_tx_stall = iwl_bg_monitor_recover, + }; + + static struct iwl_ops iwl1000_ops = { +@@ -175,6 +176,7 @@ struct iwl_cfg iwl1000_bgn_cfg = { + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl1000_bg_cfg = { +@@ -202,6 +204,7 @@ struct iwl_cfg iwl1000_bg_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .support_ct_kill_exit = true, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl3945-base.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl3945-base.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl3945-base.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl3945-base.c 2010-04-13 14:33:49.000000000 -0400 +@@ -2483,6 +2483,13 @@ static void iwl3945_alive_start(struct i + /* After the ALIVE response, we can send commands to 3945 uCode */ + set_bit(STATUS_ALIVE, &priv->status); + ++ if (priv->cfg->ops->lib->recover_from_tx_stall) { ++ /* Enable timer to monitor the driver queues */ ++ mod_timer(&priv->monitor_recover, ++ jiffies + ++ msecs_to_jiffies(priv->cfg->monitor_recover_period)); ++ } ++ + if (iwl_is_rfkill(priv)) + return; + +@@ -3768,6 +3775,13 @@ static void iwl3945_setup_deferred_work( + + iwl3945_hw_setup_deferred_work(priv); + ++ if (priv->cfg->ops->lib->recover_from_tx_stall) { ++ init_timer(&priv->monitor_recover); ++ priv->monitor_recover.data = (unsigned long)priv; ++ priv->monitor_recover.function = ++ priv->cfg->ops->lib->recover_from_tx_stall; ++ } ++ + tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) + iwl3945_irq_tasklet, (unsigned long)priv); + } +@@ -3780,6 +3794,8 @@ static void iwl3945_cancel_deferred_work + cancel_delayed_work(&priv->scan_check); + cancel_delayed_work(&priv->alive_start); + cancel_work_sync(&priv->beacon_update); ++ if (priv->cfg->ops->lib->recover_from_tx_stall) ++ del_timer_sync(&priv->monitor_recover); + } + + static struct attribute *iwl3945_sysfs_entries[] = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c 2010-04-13 14:33:49.000000000 -0400 +@@ -2829,6 +2829,7 @@ static struct iwl_cfg iwl3945_bg_cfg = { + .led_compensation = 64, + .broken_powersave = true, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + static struct iwl_cfg iwl3945_abg_cfg = { +@@ -2847,6 +2848,7 @@ static struct iwl_cfg iwl3945_abg_cfg = + .led_compensation = 64, + .broken_powersave = true, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct pci_device_id iwl3945_hw_card_ids[] = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c 2010-04-13 14:33:49.000000000 -0400 +@@ -2248,6 +2248,7 @@ struct iwl_cfg iwl4965_agn_cfg = { + .chain_noise_num_beacons = IWL4965_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + /* Module firmware */ +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c 2010-04-13 14:35:01.000000000 -0400 +@@ -1506,6 +1506,7 @@ struct iwl_lib_ops iwl5000_lib = { + .temperature = iwl5000_temperature, + .set_ct_kill = iwl5000_set_ct_threshold, + }, ++ .recover_from_tx_stall = iwl_bg_monitor_recover, + }; + + static struct iwl_lib_ops iwl5150_lib = { +@@ -1558,6 +1559,7 @@ static struct iwl_lib_ops iwl5150_lib = + .temperature = iwl5150_temperature, + .set_ct_kill = iwl5150_set_ct_threshold, + }, ++ .recover_from_tx_stall = iwl_bg_monitor_recover, + }; + + static struct iwl_ops iwl5000_ops = { +@@ -1607,6 +1609,7 @@ struct iwl_cfg iwl5300_agn_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl5100_bgn_cfg = { +@@ -1632,6 +1635,7 @@ struct iwl_cfg iwl5100_bgn_cfg = { + .use_rts_for_ht = true, /* use rts/cts protection */ + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl5100_abg_cfg = { +@@ -1655,6 +1659,7 @@ struct iwl_cfg iwl5100_abg_cfg = { + .led_compensation = 51, + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl5100_agn_cfg = { +@@ -1681,6 +1686,7 @@ struct iwl_cfg iwl5100_agn_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl5350_agn_cfg = { +@@ -1707,6 +1713,7 @@ struct iwl_cfg iwl5350_agn_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl5150_agn_cfg = { +@@ -1733,6 +1740,7 @@ struct iwl_cfg iwl5150_agn_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl5150_abg_cfg = { +@@ -1756,6 +1764,7 @@ struct iwl_cfg iwl5150_abg_cfg = { + .led_compensation = 51, + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c 2010-04-13 14:36:12.000000000 -0400 +@@ -250,6 +250,7 @@ static struct iwl_lib_ops iwl6000_lib = + .temperature = iwl5000_temperature, + .set_ct_kill = iwl6000_set_ct_threshold, + }, ++ .recover_from_tx_stall = iwl_bg_monitor_recover, + }; + + static struct iwl_ops iwl6000_ops = { +@@ -308,6 +309,7 @@ struct iwl_cfg iwl6000i_2agn_cfg = { + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl6000i_2abg_cfg = { +@@ -338,6 +340,7 @@ struct iwl_cfg iwl6000i_2abg_cfg = { + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl6000i_2bg_cfg = { +@@ -368,6 +371,7 @@ struct iwl_cfg iwl6000i_2bg_cfg = { + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl6050_2agn_cfg = { +@@ -400,6 +404,7 @@ struct iwl_cfg iwl6050_2agn_cfg = { + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DYNAMIC, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl6050_2abg_cfg = { +@@ -430,6 +435,7 @@ struct iwl_cfg iwl6050_2abg_cfg = { + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + struct iwl_cfg iwl6000_3agn_cfg = { +@@ -462,6 +468,7 @@ struct iwl_cfg iwl6000_3agn_cfg = { + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, + .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, ++ .monitor_recover_period = IWL_MONITORING_PERIOD, + }; + + MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c 2010-04-13 14:37:04.000000000 -0400 +@@ -1912,6 +1912,13 @@ static void iwl_alive_start(struct iwl_p + /* After the ALIVE response, we can send host commands to the uCode */ + set_bit(STATUS_ALIVE, &priv->status); + ++ if (priv->cfg->ops->lib->recover_from_tx_stall) { ++ /* Enable timer to monitor the driver queues */ ++ mod_timer(&priv->monitor_recover, ++ jiffies + ++ msecs_to_jiffies(priv->cfg->monitor_recover_period)); ++ } ++ + if (iwl_is_rfkill(priv)) + return; + +@@ -3126,6 +3133,13 @@ static void iwl_setup_deferred_work(stru + priv->statistics_periodic.data = (unsigned long)priv; + priv->statistics_periodic.function = iwl_bg_statistics_periodic; + ++ if (priv->cfg->ops->lib->recover_from_tx_stall) { ++ init_timer(&priv->monitor_recover); ++ priv->monitor_recover.data = (unsigned long)priv; ++ priv->monitor_recover.function = ++ priv->cfg->ops->lib->recover_from_tx_stall; ++ } ++ + if (!priv->cfg->use_isr_legacy) + tasklet_init(&priv->irq_tasklet, (void (*)(unsigned long)) + iwl_irq_tasklet, (unsigned long)priv); +@@ -3144,6 +3158,8 @@ static void iwl_cancel_deferred_work(str + cancel_delayed_work(&priv->alive_start); + cancel_work_sync(&priv->beacon_update); + del_timer_sync(&priv->statistics_periodic); ++ if (priv->cfg->ops->lib->recover_from_tx_stall) ++ del_timer_sync(&priv->monitor_recover); + } + + static void iwl_init_hw_rates(struct iwl_priv *priv, +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c 2010-04-13 14:33:49.000000000 -0400 +@@ -3263,6 +3263,99 @@ int iwl_force_reset(struct iwl_priv *pri + } + return 0; + } ++EXPORT_SYMBOL(iwl_force_reset); ++ ++/** ++ * iwl_bg_monitor_recover - Timer callback to check for stuck queue and recover ++ * ++ * During normal condition (no queue is stuck), the timer is continually set to ++ * execute every monitor_recover_period milliseconds after the last timer ++ * expired. When the queue read_ptr is at the same place, the timer is ++ * shorten to 100mSecs. This is ++ * 1) to reduce the chance that the read_ptr may wrap around (not stuck) ++ * 2) to detect the stuck queues quicker before the station and AP can ++ * disassociate each other. ++ * ++ * This function monitors all the tx queues and recover from it if any ++ * of the queues are stuck. ++ * 1. It first check the cmd queue for stuck conditions. If it is stuck, ++ * it will recover by resetting the firmware and return. ++ * 2. Then, it checks for station association. If it associates it will check ++ * other queues. If any queue is stuck, it will recover by resetting ++ * the firmware. ++ * Note: It the number of times the queue read_ptr to be at the same place to ++ * be MAX_REPEAT+1 in order to consider to be stuck. ++ */ ++/* ++ * The maximum number of times the read pointer of the tx queue at the ++ * same place without considering to be stuck. ++ */ ++#define MAX_REPEAT (2) ++static int iwl_check_stuck_queue(struct iwl_priv *priv, int cnt) ++{ ++ struct iwl_tx_queue *txq; ++ struct iwl_queue *q; ++ ++ txq = &priv->txq[cnt]; ++ q = &txq->q; ++ /* queue is empty, skip */ ++ if (q->read_ptr != q->write_ptr) { ++ if (q->read_ptr == q->last_read_ptr) { ++ /* a queue has not been read from last time */ ++ if (q->repeat_same_read_ptr > MAX_REPEAT) { ++ IWL_ERR(priv, ++ "queue %d stuck %d time. Fw reload.\n", ++ q->id, q->repeat_same_read_ptr); ++ q->repeat_same_read_ptr = 0; ++ iwl_force_reset(priv, IWL_FW_RESET); ++ } else { ++ q->repeat_same_read_ptr++; ++ IWL_DEBUG_RADIO(priv, ++ "queue %d, not read %d time\n", ++ q->id, ++ q->repeat_same_read_ptr); ++ mod_timer(&priv->monitor_recover, jiffies + ++ msecs_to_jiffies(IWL_ONE_HUNDRED_MSECS)); ++ } ++ return 1; ++ } else { ++ q->last_read_ptr = q->read_ptr; ++ q->repeat_same_read_ptr = 0; ++ } ++ } ++ return 0; ++} ++ ++void iwl_bg_monitor_recover(unsigned long data) ++{ ++ struct iwl_priv *priv = (struct iwl_priv *)data; ++ int cnt; ++ ++ if (test_bit(STATUS_EXIT_PENDING, &priv->status)) ++ return; ++ ++ /* monitor and check for stuck cmd queue */ ++ if (iwl_check_stuck_queue(priv, IWL_CMD_QUEUE_NUM)) ++ return; ++ ++ /* monitor and check for other stuck queues */ ++ if (iwl_is_associated(priv)) { ++ for (cnt = 0; cnt < priv->hw_params.max_txq_num; cnt++) { ++ /* skip as we already checked the command queue */ ++ if (cnt == IWL_CMD_QUEUE_NUM) ++ continue; ++ if (iwl_check_stuck_queue(priv, cnt)) ++ return; ++ } ++ } ++ /* ++ * Reschedule the timer to occur in ++ * priv->cfg->monitor_recover_period ++ */ ++ mod_timer(&priv->monitor_recover, ++ jiffies + msecs_to_jiffies(priv->cfg->monitor_recover_period)); ++} ++EXPORT_SYMBOL(iwl_bg_monitor_recover); + + #ifdef CONFIG_PM + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 14:38:21.000000000 -0400 +@@ -187,6 +187,8 @@ struct iwl_lib_ops { + + /* temperature */ + struct iwl_temp_ops temp_ops; ++ /* recover from tx queue stall */ ++ void (*recover_from_tx_stall)(unsigned long data); + }; + + struct iwl_led_ops { +@@ -292,6 +294,8 @@ struct iwl_cfg { + u8 sm_ps_mode; + const bool support_wimax_coexist; + u8 plcp_delta_threshold; ++ /* timer period for monitor the driver queues */ ++ u32 monitor_recover_period; + }; + + /*************************** +@@ -579,6 +583,9 @@ static inline u16 iwl_pcie_link_ctl(stru + pci_read_config_word(priv->pci_dev, pos + PCI_EXP_LNKCTL, &pci_lnk_ctl); + return pci_lnk_ctl; + } ++ ++void iwl_bg_monitor_recover(unsigned long data); ++ + #ifdef CONFIG_PM + int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state); + int iwl_pci_resume(struct pci_dev *pdev); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 14:38:52.000000000 -0400 +@@ -183,6 +183,10 @@ struct iwl_queue { + int n_bd; /* number of BDs in this queue */ + int write_ptr; /* 1-st empty entry (index) host_w*/ + int read_ptr; /* last used entry (index) host_r*/ ++ /* use for monitoring and recovering the stuck queue */ ++ int last_read_ptr; /* storing the last read_ptr */ ++ /* number of time read_ptr and last_read_ptr are the same */ ++ u8 repeat_same_read_ptr; + dma_addr_t dma_addr; /* physical addr for BD's */ + int n_window; /* safe queue window */ + u32 id; +@@ -997,6 +1001,11 @@ struct iwl_switch_rxon { + #define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3) + #define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5) + ++/* timer constants use to monitor and recover stuck tx queues in mSecs */ ++#define IWL_MONITORING_PERIOD (1000) ++#define IWL_ONE_HUNDRED_MSECS (100) ++#define IWL_SIXTY_SECS (60000) ++ + enum iwl_reset { + IWL_RF_RESET = 0, + IWL_FW_RESET, +@@ -1295,6 +1304,7 @@ struct iwl_priv { + u32 disable_tx_power_cal; + struct work_struct run_time_calib_work; + struct timer_list statistics_periodic; ++ struct timer_list monitor_recover; + bool hw_ready; + /*For 3945*/ + #define IWL_DEFAULT_TX_POWER 0x0F +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-tx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-tx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-tx.c.orig 2010-04-13 14:33:10.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-tx.c 2010-04-13 14:33:49.000000000 -0400 +@@ -288,6 +288,8 @@ static int iwl_queue_init(struct iwl_pri + q->high_mark = 2; + + q->write_ptr = q->read_ptr = 0; ++ q->last_read_ptr = 0; ++ q->repeat_same_read_ptr = 0; + + return 0; + } diff --git a/iwlwifi_-Tune-radio-to-prevent-unexpected-behavior.patch b/iwlwifi_-Tune-radio-to-prevent-unexpected-behavior.patch new file mode 100644 index 000000000..f53445c67 --- /dev/null +++ b/iwlwifi_-Tune-radio-to-prevent-unexpected-behavior.patch @@ -0,0 +1,394 @@ +Backport of the following upstream commit... + +commit 3e4fb5faefb57824f2e42305b3d5907845af978c +Author: Trieu 'Andrew' Nguyen +Date: Fri Jan 22 14:22:46 2010 -0800 + + iwlwifi: Tune radio to prevent unexpected behavior + + We have seen the throughput dropped due to external noisy environment + and the radio is out of tune. There are lot of plcp errors indicating + this condition. Eventually the station can get de-authenticated by the + Access Point. By resetting and tuning the radio, the plcp errors are + reduced or eliminated and the throughput starts to rise. + + To prevent unexpected behavior such as drop in throughput or deauthentication, + - The change provides the driver feature to monitor and tune the radio base on + the statistics notification from the uCode. + - It also allows the setting of the plcp error rate threshold via + the plcp_delta under debugfs interface. + + Signed-off-by: Trieu 'Andrew' Nguyen + Signed-off-by: Reinette Chatre + Signed-off-by: John W. Linville + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c 2010-04-13 14:30:41.000000000 -0400 +@@ -174,6 +174,7 @@ struct iwl_cfg iwl1000_bgn_cfg = { + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl1000_bg_cfg = { +@@ -200,6 +201,7 @@ struct iwl_cfg iwl1000_bg_cfg = { + .led_compensation = 51, + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .support_ct_kill_exit = true, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + MODULE_FIRMWARE(IWL1000_MODULE_FIRMWARE(IWL1000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-3945.c 2010-04-13 14:30:41.000000000 -0400 +@@ -2828,6 +2828,7 @@ static struct iwl_cfg iwl3945_bg_cfg = { + .ht_greenfield_support = false, + .led_compensation = 64, + .broken_powersave = true, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + static struct iwl_cfg iwl3945_abg_cfg = { +@@ -2845,6 +2846,7 @@ static struct iwl_cfg iwl3945_abg_cfg = + .ht_greenfield_support = false, + .led_compensation = 64, + .broken_powersave = true, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct pci_device_id iwl3945_hw_card_ids[] = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c 2010-04-13 14:30:41.000000000 -0400 +@@ -2247,6 +2247,7 @@ struct iwl_cfg iwl4965_agn_cfg = { + .led_compensation = 61, + .chain_noise_num_beacons = IWL4965_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + /* Module firmware */ +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c 2010-04-13 14:30:41.000000000 -0400 +@@ -1606,6 +1606,7 @@ struct iwl_cfg iwl5300_agn_cfg = { + .use_rts_for_ht = true, /* use rts/cts protection */ + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl5100_bgn_cfg = { +@@ -1630,6 +1631,7 @@ struct iwl_cfg iwl5100_bgn_cfg = { + .led_compensation = 51, + .use_rts_for_ht = true, /* use rts/cts protection */ + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl5100_abg_cfg = { +@@ -1652,6 +1654,7 @@ struct iwl_cfg iwl5100_abg_cfg = { + .use_bsm = false, + .led_compensation = 51, + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl5100_agn_cfg = { +@@ -1677,6 +1680,7 @@ struct iwl_cfg iwl5100_agn_cfg = { + .use_rts_for_ht = true, /* use rts/cts protection */ + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl5350_agn_cfg = { +@@ -1702,6 +1706,7 @@ struct iwl_cfg iwl5350_agn_cfg = { + .use_rts_for_ht = true, /* use rts/cts protection */ + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl5150_agn_cfg = { +@@ -1727,6 +1732,7 @@ struct iwl_cfg iwl5150_agn_cfg = { + .use_rts_for_ht = true, /* use rts/cts protection */ + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl5150_abg_cfg = { +@@ -1749,6 +1755,7 @@ struct iwl_cfg iwl5150_abg_cfg = { + .use_bsm = false, + .led_compensation = 51, + .chain_noise_num_beacons = IWL_CAL_NUM_BEACONS, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF, + }; + + MODULE_FIRMWARE(IWL5000_MODULE_FIRMWARE(IWL5000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c 2010-04-13 14:32:09.000000000 -0400 +@@ -307,6 +307,7 @@ struct iwl_cfg iwl6000i_2agn_cfg = { + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl6000i_2abg_cfg = { +@@ -336,6 +337,7 @@ struct iwl_cfg iwl6000i_2abg_cfg = { + .supports_idle = true, + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl6000i_2bg_cfg = { +@@ -365,6 +367,7 @@ struct iwl_cfg iwl6000i_2bg_cfg = { + .supports_idle = true, + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl6050_2agn_cfg = { +@@ -396,6 +399,7 @@ struct iwl_cfg iwl6050_2agn_cfg = { + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DYNAMIC, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl6050_2abg_cfg = { +@@ -425,6 +429,7 @@ struct iwl_cfg iwl6050_2abg_cfg = { + .supports_idle = true, + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + struct iwl_cfg iwl6000_3agn_cfg = { +@@ -456,6 +461,7 @@ struct iwl_cfg iwl6000_3agn_cfg = { + .adv_thermal_throttle = true, + .support_ct_kill_exit = true, + .sm_ps_mode = WLAN_HT_CAP_SM_PS_DISABLED, ++ .plcp_delta_threshold = IWL_MAX_PLCP_ERR_THRESHOLD_DEF, + }; + + MODULE_FIRMWARE(IWL6000_MODULE_FIRMWARE(IWL6000_UCODE_API_MAX)); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 14:30:41.000000000 -0400 +@@ -232,6 +232,8 @@ struct iwl_mod_params { + * @support_ct_kill_exit: support ct kill exit condition + * @sm_ps_mode: spatial multiplexing power save mode + * @support_wimax_coexist: support wimax/wifi co-exist ++ * @plcp_delta_threshold: plcp error rate threshold used to trigger ++ * radio tuning when there is a high receiving plcp error rate + * + * We enable the driver to be backward compatible wrt API version. The + * driver specifies which APIs it supports (with @ucode_api_max being the +@@ -289,6 +291,7 @@ struct iwl_cfg { + bool support_ct_kill_exit; + u8 sm_ps_mode; + const bool support_wimax_coexist; ++ u8 plcp_delta_threshold; + }; + + /*************************** +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2010-04-13 14:30:41.000000000 -0400 +@@ -1866,6 +1866,47 @@ static ssize_t iwl_dbgfs_internal_scan_w + return count; + } + ++static ssize_t iwl_dbgfs_plcp_delta_read(struct file *file, ++ char __user *user_buf, ++ size_t count, loff_t *ppos) { ++ ++ struct iwl_priv *priv = (struct iwl_priv *)file->private_data; ++ int pos = 0; ++ char buf[12]; ++ const size_t bufsz = sizeof(buf); ++ ssize_t ret; ++ ++ pos += scnprintf(buf + pos, bufsz - pos, "%u\n", ++ priv->cfg->plcp_delta_threshold); ++ ++ ret = simple_read_from_buffer(user_buf, count, ppos, buf, pos); ++ return ret; ++} ++ ++static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file, ++ const char __user *user_buf, ++ size_t count, loff_t *ppos) { ++ ++ struct iwl_priv *priv = file->private_data; ++ char buf[8]; ++ int buf_size; ++ int plcp; ++ ++ memset(buf, 0, sizeof(buf)); ++ buf_size = min(count, sizeof(buf) - 1); ++ if (copy_from_user(buf, user_buf, buf_size)) ++ return -EFAULT; ++ if (sscanf(buf, "%d", &plcp) != 1) ++ return -EINVAL; ++ if ((plcp <= IWL_MAX_PLCP_ERR_THRESHOLD_MIN) || ++ (plcp > IWL_MAX_PLCP_ERR_THRESHOLD_MAX)) ++ priv->cfg->plcp_delta_threshold = ++ IWL_MAX_PLCP_ERR_THRESHOLD_DEF; ++ else ++ priv->cfg->plcp_delta_threshold = plcp; ++ return count; ++} ++ + DEBUGFS_READ_FILE_OPS(rx_statistics); + DEBUGFS_READ_FILE_OPS(tx_statistics); + DEBUGFS_READ_WRITE_FILE_OPS(traffic_log); +@@ -1881,6 +1922,7 @@ DEBUGFS_READ_FILE_OPS(power_save_status) + DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics); + DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics); + DEBUGFS_WRITE_FILE_OPS(internal_scan); ++DEBUGFS_READ_WRITE_FILE_OPS(plcp_delta); + + /* + * Create the debugfs files and directories +@@ -1932,6 +1974,7 @@ int iwl_dbgfs_register(struct iwl_priv * + DEBUGFS_ADD_FILE(clear_ucode_statistics, debug, S_IWUSR); + DEBUGFS_ADD_FILE(clear_traffic_statistics, debug, S_IWUSR); + DEBUGFS_ADD_FILE(internal_scan, debug, S_IWUSR); ++ DEBUGFS_ADD_FILE(plcp_delta, debug, S_IWUSR | S_IRUSR); + if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) { + DEBUGFS_ADD_FILE(ucode_rx_stats, debug, S_IRUSR); + DEBUGFS_ADD_FILE(ucode_tx_stats, debug, S_IRUSR); +@@ -1990,6 +2033,7 @@ void iwl_dbgfs_unregister(struct iwl_pri + DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files. + file_clear_traffic_statistics); + DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_internal_scan); ++ DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_plcp_delta); + if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) { + DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files. + file_ucode_rx_stats); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h 2010-04-13 14:30:41.000000000 -0400 +@@ -110,6 +110,7 @@ struct iwl_debugfs { + struct dentry *file_clear_ucode_statistics; + struct dentry *file_clear_traffic_statistics; + struct dentry *file_internal_scan; ++ struct dentry *file_plcp_delta; + } dbgfs_debug_files; + u32 sram_offset; + u32 sram_len; +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 14:30:41.000000000 -0400 +@@ -984,6 +984,15 @@ struct iwl_switch_rxon { + __le16 channel; + }; + ++/* ++ * This is the threshold value of plcp error rate per 100mSecs. It is ++ * used to set and check for the validity of plcp_delta. ++ */ ++#define IWL_MAX_PLCP_ERR_THRESHOLD_MIN (0) ++#define IWL_MAX_PLCP_ERR_THRESHOLD_DEF (50) ++#define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100) ++#define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255) ++ + struct iwl_priv { + + /* ieee device used by generic ieee processing code */ +@@ -1012,6 +1021,9 @@ struct iwl_priv { + /* ucode beacon time */ + u32 ucode_beacon_time; + ++ /* storing the jiffies when the plcp error rate is received */ ++ unsigned long plcp_jiffies; ++ + /* we allocate array of iwl4965_channel_info for NIC's valid channels. + * Access via channel # using indirect index array */ + struct iwl_channel_info *channel_info; /* channel info array */ +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig 2010-04-13 14:30:36.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c 2010-04-13 14:30:41.000000000 -0400 +@@ -593,11 +593,15 @@ static void iwl_accumulative_statistics( + + #define REG_RECALIB_PERIOD (60) + ++#define PLCP_MSG "plcp_err exceeded %u, %u, %u, %u, %u, %d, %u mSecs\n" + void iwl_rx_statistics(struct iwl_priv *priv, + struct iwl_rx_mem_buffer *rxb) + { + int change; + struct iwl_rx_packet *pkt = rxb_addr(rxb); ++ int combined_plcp_delta; ++ unsigned int plcp_msec; ++ unsigned long plcp_received_jiffies; + + IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n", + (int)sizeof(priv->statistics), +@@ -612,6 +616,56 @@ void iwl_rx_statistics(struct iwl_priv * + #ifdef CONFIG_IWLWIFI_DEBUG + iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats); + #endif ++ /* ++ * check for plcp_err and trigger radio reset if it exceeds ++ * the plcp error threshold plcp_delta. ++ */ ++ plcp_received_jiffies = jiffies; ++ plcp_msec = jiffies_to_msecs((long) plcp_received_jiffies - ++ (long) priv->plcp_jiffies); ++ priv->plcp_jiffies = plcp_received_jiffies; ++ /* ++ * check to make sure plcp_msec is not 0 to prevent division ++ * by zero. ++ */ ++ if (plcp_msec) { ++ combined_plcp_delta = ++ (le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err) - ++ le32_to_cpu(priv->statistics.rx.ofdm.plcp_err)) + ++ (le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err) - ++ le32_to_cpu(priv->statistics.rx.ofdm_ht.plcp_err)); ++ ++ if ((combined_plcp_delta > 0) && ++ ((combined_plcp_delta * 100) / plcp_msec) > ++ priv->cfg->plcp_delta_threshold) { ++ /* ++ * if plcp_err exceed the threshold, the following ++ * data is printed in csv format: ++ * Text: plcp_err exceeded %d, ++ * Received ofdm.plcp_err, ++ * Current ofdm.plcp_err, ++ * Received ofdm_ht.plcp_err, ++ * Current ofdm_ht.plcp_err, ++ * combined_plcp_delta, ++ * plcp_msec ++ */ ++ IWL_DEBUG_RADIO(priv, PLCP_MSG, ++ priv->cfg->plcp_delta_threshold, ++ le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err), ++ le32_to_cpu(priv->statistics.rx.ofdm.plcp_err), ++ le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err), ++ le32_to_cpu( ++ priv->statistics.rx.ofdm_ht.plcp_err), ++ combined_plcp_delta, plcp_msec); ++ ++ /* ++ * Reset the RF radio due to the high plcp ++ * error rate ++ */ ++ iwl_force_rf_reset(priv); ++ } ++ } ++ + memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics)); + + set_bit(STATUS_STATISTICS, &priv->status); diff --git a/iwlwifi_-add-function-to-reset_tune-radio-if-needed.patch b/iwlwifi_-add-function-to-reset_tune-radio-if-needed.patch new file mode 100644 index 000000000..c523f9dd4 --- /dev/null +++ b/iwlwifi_-add-function-to-reset_tune-radio-if-needed.patch @@ -0,0 +1,374 @@ +Backport of the following upstream commit... + +commit afbdd69af0e6a0c40676d4d4b94a0a4414708eaa +Author: Wey-Yi Guy +Date: Fri Jan 22 14:22:43 2010 -0800 + + iwlwifi: add function to reset/tune radio if needed + + Adding "radio reset" function to help reset and stabilize the radio. + + During normal operation, sometime for unknown reason, radio encounter + problem and can not recover by itself; the best way to + recover from it is to reset and re-tune the radio. Currently, there is + no RF reset command available, but since radio will get reset when + switching channel, use internal hw scan request to force radio + reset and get back to normal operation state. + + The internal hw scan will only perform passive scan on the first + available channel (not the channel being used) in associated state. The + request should be ignored if already performing scan operation or STA is + not in associated state. + + Also include an "internal_scan" debugfs file to help trigger the + internal scan from user mode. + + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + Signed-off-by: John W. Linville + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig 2010-04-13 11:41:15.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c 2010-04-13 11:53:36.000000000 -0400 +@@ -3197,6 +3197,30 @@ void iwl_update_stats(struct iwl_priv *p + EXPORT_SYMBOL(iwl_update_stats); + #endif + ++void iwl_force_rf_reset(struct iwl_priv *priv) ++{ ++ if (test_bit(STATUS_EXIT_PENDING, &priv->status)) ++ return; ++ ++ if (!iwl_is_associated(priv)) { ++ IWL_DEBUG_SCAN(priv, "force reset rejected: not associated\n"); ++ return; ++ } ++ /* ++ * There is no easy and better way to force reset the radio, ++ * the only known method is switching channel which will force to ++ * reset and tune the radio. ++ * Use internal short scan (single channel) operation to should ++ * achieve this objective. ++ * Driver should reset the radio when number of consecutive missed ++ * beacon, or any other uCode error condition detected. ++ */ ++ IWL_DEBUG_INFO(priv, "perform radio reset.\n"); ++ iwl_internal_short_hw_scan(priv); ++ return; ++} ++EXPORT_SYMBOL(iwl_force_rf_reset); ++ + #ifdef CONFIG_PM + + int iwl_pci_suspend(struct pci_dev *pdev, pm_message_t state) +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 11:53:36.000000000 -0400 +@@ -497,6 +497,8 @@ void iwl_init_scan_params(struct iwl_pri + int iwl_scan_cancel(struct iwl_priv *priv); + int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); + int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req); ++int iwl_internal_short_hw_scan(struct iwl_priv *priv); ++void iwl_force_rf_reset(struct iwl_priv *priv); + u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, + const u8 *ie, int ie_len, int left); + void iwl_setup_rx_scan_handlers(struct iwl_priv *priv); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debugfs.c 2010-04-13 11:56:15.000000000 -0400 +@@ -1845,6 +1845,27 @@ static ssize_t iwl_dbgfs_clear_ucode_sta + return count; + } + ++static ssize_t iwl_dbgfs_internal_scan_write(struct file *file, ++ const char __user *user_buf, ++ size_t count, loff_t *ppos) ++{ ++ struct iwl_priv *priv = file->private_data; ++ char buf[8]; ++ int buf_size; ++ int scan; ++ ++ memset(buf, 0, sizeof(buf)); ++ buf_size = min(count, sizeof(buf) - 1); ++ if (copy_from_user(buf, user_buf, buf_size)) ++ return -EFAULT; ++ if (sscanf(buf, "%d", &scan) != 1) ++ return -EINVAL; ++ ++ iwl_internal_short_hw_scan(priv); ++ ++ return count; ++} ++ + DEBUGFS_READ_FILE_OPS(rx_statistics); + DEBUGFS_READ_FILE_OPS(tx_statistics); + DEBUGFS_READ_WRITE_FILE_OPS(traffic_log); +@@ -1859,6 +1880,7 @@ DEBUGFS_READ_FILE_OPS(tx_power); + DEBUGFS_READ_FILE_OPS(power_save_status); + DEBUGFS_WRITE_FILE_OPS(clear_ucode_statistics); + DEBUGFS_WRITE_FILE_OPS(clear_traffic_statistics); ++DEBUGFS_WRITE_FILE_OPS(internal_scan); + + /* + * Create the debugfs files and directories +@@ -1909,6 +1931,7 @@ int iwl_dbgfs_register(struct iwl_priv * + DEBUGFS_ADD_FILE(power_save_status, debug, S_IRUSR); + DEBUGFS_ADD_FILE(clear_ucode_statistics, debug, S_IWUSR); + DEBUGFS_ADD_FILE(clear_traffic_statistics, debug, S_IWUSR); ++ DEBUGFS_ADD_FILE(internal_scan, debug, S_IWUSR); + if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) { + DEBUGFS_ADD_FILE(ucode_rx_stats, debug, S_IRUSR); + DEBUGFS_ADD_FILE(ucode_tx_stats, debug, S_IRUSR); +@@ -1966,6 +1989,7 @@ void iwl_dbgfs_unregister(struct iwl_pri + file_clear_ucode_statistics); + DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files. + file_clear_traffic_statistics); ++ DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files.file_internal_scan); + if ((priv->hw_rev & CSR_HW_REV_TYPE_MSK) != CSR_HW_REV_TYPE_3945) { + DEBUGFS_REMOVE(priv->dbgfs->dbgfs_debug_files. + file_ucode_rx_stats); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-debug.h 2010-04-13 11:54:48.000000000 -0400 +@@ -109,6 +109,7 @@ struct iwl_debugfs { + struct dentry *file_power_save_status; + struct dentry *file_clear_ucode_statistics; + struct dentry *file_clear_traffic_statistics; ++ struct dentry *file_internal_scan; + } dbgfs_debug_files; + u32 sram_offset; + u32 sram_len; +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 11:53:36.000000000 -0400 +@@ -1037,6 +1037,7 @@ struct iwl_priv { + void *scan; + int scan_bands; + struct cfg80211_scan_request *scan_request; ++ bool is_internal_short_scan; + u8 scan_tx_ant[IEEE80211_NUM_BANDS]; + u8 mgmt_tx_ant; + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c 2010-04-13 11:53:36.000000000 -0400 +@@ -314,6 +314,72 @@ u16 iwl_get_passive_dwell_time(struct iw + } + EXPORT_SYMBOL(iwl_get_passive_dwell_time); + ++static int iwl_get_single_channel_for_scan(struct iwl_priv *priv, ++ enum ieee80211_band band, ++ struct iwl_scan_channel *scan_ch) ++{ ++ const struct ieee80211_supported_band *sband; ++ const struct iwl_channel_info *ch_info; ++ u16 passive_dwell = 0; ++ u16 active_dwell = 0; ++ int i, added = 0; ++ u16 channel = 0; ++ ++ sband = iwl_get_hw_mode(priv, band); ++ if (!sband) { ++ IWL_ERR(priv, "invalid band\n"); ++ return added; ++ } ++ ++ active_dwell = iwl_get_active_dwell_time(priv, band, 0); ++ passive_dwell = iwl_get_passive_dwell_time(priv, band); ++ ++ if (passive_dwell <= active_dwell) ++ passive_dwell = active_dwell + 1; ++ ++ /* only scan single channel, good enough to reset the RF */ ++ /* pick the first valid not in-use channel */ ++ if (band == IEEE80211_BAND_5GHZ) { ++ for (i = 14; i < priv->channel_count; i++) { ++ if (priv->channel_info[i].channel != ++ le16_to_cpu(priv->staging_rxon.channel)) { ++ channel = priv->channel_info[i].channel; ++ ch_info = iwl_get_channel_info(priv, ++ band, channel); ++ if (is_channel_valid(ch_info)) ++ break; ++ } ++ } ++ } else { ++ for (i = 0; i < 14; i++) { ++ if (priv->channel_info[i].channel != ++ le16_to_cpu(priv->staging_rxon.channel)) { ++ channel = ++ priv->channel_info[i].channel; ++ ch_info = iwl_get_channel_info(priv, ++ band, channel); ++ if (is_channel_valid(ch_info)) ++ break; ++ } ++ } ++ } ++ if (channel) { ++ scan_ch->channel = cpu_to_le16(channel); ++ scan_ch->type = SCAN_CHANNEL_TYPE_PASSIVE; ++ scan_ch->active_dwell = cpu_to_le16(active_dwell); ++ scan_ch->passive_dwell = cpu_to_le16(passive_dwell); ++ /* Set txpower levels to defaults */ ++ scan_ch->dsp_atten = 110; ++ if (band == IEEE80211_BAND_5GHZ) ++ scan_ch->tx_gain = ((1 << 5) | (3 << 3)) | 3; ++ else ++ scan_ch->tx_gain = ((1 << 5) | (5 << 3)); ++ added++; ++ } else ++ IWL_ERR(priv, "no valid channel found\n"); ++ return added; ++} ++ + static int iwl_get_channels_for_scan(struct iwl_priv *priv, + enum ieee80211_band band, + u8 is_active, u8 n_probes, +@@ -421,6 +487,7 @@ static int iwl_scan_initiate(struct iwl_ + + IWL_DEBUG_INFO(priv, "Starting scan...\n"); + set_bit(STATUS_SCANNING, &priv->status); ++ priv->is_internal_short_scan = false; + priv->scan_start = jiffies; + priv->scan_pass_start = priv->scan_start; + +@@ -488,6 +555,45 @@ out_unlock: + } + EXPORT_SYMBOL(iwl_mac_hw_scan); + ++/* ++ * internal short scan, this function should only been called while associated. ++ * It will reset and tune the radio to prevent possible RF related problem ++ */ ++int iwl_internal_short_hw_scan(struct iwl_priv *priv) ++{ ++ int ret = 0; ++ ++ if (!iwl_is_ready_rf(priv)) { ++ ret = -EIO; ++ IWL_DEBUG_SCAN(priv, "not ready or exit pending\n"); ++ goto out; ++ } ++ if (test_bit(STATUS_SCANNING, &priv->status)) { ++ IWL_DEBUG_SCAN(priv, "Scan already in progress.\n"); ++ ret = -EAGAIN; ++ goto out; ++ } ++ if (test_bit(STATUS_SCAN_ABORTING, &priv->status)) { ++ IWL_DEBUG_SCAN(priv, "Scan request while abort pending\n"); ++ ret = -EAGAIN; ++ goto out; ++ } ++ priv->scan_bands = 0; ++ if (priv->band == IEEE80211_BAND_5GHZ) ++ priv->scan_bands |= BIT(IEEE80211_BAND_5GHZ); ++ else ++ priv->scan_bands |= BIT(IEEE80211_BAND_2GHZ); ++ ++ IWL_DEBUG_SCAN(priv, "Start internal short scan...\n"); ++ set_bit(STATUS_SCANNING, &priv->status); ++ priv->is_internal_short_scan = true; ++ queue_work(priv->workqueue, &priv->request_scan); ++ ++out: ++ return ret; ++} ++EXPORT_SYMBOL(iwl_internal_short_hw_scan); ++ + #define IWL_SCAN_CHECK_WATCHDOG (7 * HZ) + + void iwl_bg_scan_check(struct work_struct *data) +@@ -551,7 +657,8 @@ u16 iwl_fill_probe_req(struct iwl_priv * + if (WARN_ON(left < ie_len)) + return len; + +- memcpy(pos, ies, ie_len); ++ if (ies) ++ memcpy(pos, ies, ie_len); + len += ie_len; + left -= ie_len; + +@@ -654,7 +761,6 @@ static void iwl_bg_request_scan(struct w + unsigned long flags; + + IWL_DEBUG_INFO(priv, "Scanning while associated...\n"); +- + spin_lock_irqsave(&priv->lock, flags); + interval = priv->beacon_int; + spin_unlock_irqrestore(&priv->lock, flags); +@@ -672,7 +778,9 @@ static void iwl_bg_request_scan(struct w + scan_suspend_time, interval); + } + +- if (priv->scan_request->n_ssids) { ++ if (priv->is_internal_short_scan) { ++ IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n"); ++ } else if (priv->scan_request->n_ssids) { + int i, p = 0; + IWL_DEBUG_SCAN(priv, "Kicking off active scan\n"); + for (i = 0; i < priv->scan_request->n_ssids; i++) { +@@ -753,24 +861,38 @@ static void iwl_bg_request_scan(struct w + rx_chain |= rx_ant << RXON_RX_CHAIN_FORCE_SEL_POS; + rx_chain |= 0x1 << RXON_RX_CHAIN_DRIVER_FORCE_POS; + scan->rx_chain = cpu_to_le16(rx_chain); +- cmd_len = iwl_fill_probe_req(priv, +- (struct ieee80211_mgmt *)scan->data, +- priv->scan_request->ie, +- priv->scan_request->ie_len, +- IWL_MAX_SCAN_SIZE - sizeof(*scan)); ++ if (!priv->is_internal_short_scan) { ++ cmd_len = iwl_fill_probe_req(priv, ++ (struct ieee80211_mgmt *)scan->data, ++ priv->scan_request->ie, ++ priv->scan_request->ie_len, ++ IWL_MAX_SCAN_SIZE - sizeof(*scan)); ++ } else { ++ cmd_len = iwl_fill_probe_req(priv, ++ (struct ieee80211_mgmt *)scan->data, ++ NULL, 0, ++ IWL_MAX_SCAN_SIZE - sizeof(*scan)); + ++ } + scan->tx_cmd.len = cpu_to_le16(cmd_len); +- + if (iwl_is_monitor_mode(priv)) + scan->filter_flags = RXON_FILTER_PROMISC_MSK; + + scan->filter_flags |= (RXON_FILTER_ACCEPT_GRP_MSK | + RXON_FILTER_BCON_AWARE_MSK); + +- scan->channel_count = +- iwl_get_channels_for_scan(priv, band, is_active, n_probes, +- (void *)&scan->data[le16_to_cpu(scan->tx_cmd.len)]); +- ++ if (priv->is_internal_short_scan) { ++ scan->channel_count = ++ iwl_get_single_channel_for_scan(priv, band, ++ (void *)&scan->data[le16_to_cpu( ++ scan->tx_cmd.len)]); ++ } else { ++ scan->channel_count = ++ iwl_get_channels_for_scan(priv, band, ++ is_active, n_probes, ++ (void *)&scan->data[le16_to_cpu( ++ scan->tx_cmd.len)]); ++ } + if (scan->channel_count == 0) { + IWL_DEBUG_SCAN(priv, "channel count %d\n", scan->channel_count); + goto done; +@@ -831,7 +953,12 @@ void iwl_bg_scan_completed(struct work_s + + cancel_delayed_work(&priv->scan_check); + +- ieee80211_scan_completed(priv->hw, false); ++ if (!priv->is_internal_short_scan) ++ ieee80211_scan_completed(priv->hw, false); ++ else { ++ priv->is_internal_short_scan = false; ++ IWL_DEBUG_SCAN(priv, "internal short scan completed\n"); ++ } + + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return; diff --git a/iwlwifi_-add-internal-short-scan-support-for-3945.patch b/iwlwifi_-add-internal-short-scan-support-for-3945.patch new file mode 100644 index 000000000..db132ee7b --- /dev/null +++ b/iwlwifi_-add-internal-short-scan-support-for-3945.patch @@ -0,0 +1,85 @@ +commit 4f4d4088b05155d4904e29d5c00316395ce32f27 +Author: Wey-Yi Guy +Date: Wed Feb 24 08:28:30 2010 -0800 + + iwlwifi: add internal short scan support for 3945 + + Add internal short scan support for 3945 NIC, This allows 3945 NIC + to support radio reset request like the other series of NICs. + + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff --git a/drivers/net/wireless/iwlwifi/iwl3945-base.c b/drivers/net/wireless/iwlwifi/iwl3945-base.c +index dd33251..252df12 100644 +--- a/drivers/net/wireless/iwlwifi/iwl3945-base.c ++++ b/drivers/net/wireless/iwlwifi/iwl3945-base.c +@@ -2799,7 +2799,6 @@ static void iwl3945_bg_request_scan(struct work_struct *data) + .len = sizeof(struct iwl3945_scan_cmd), + .flags = CMD_SIZE_HUGE, + }; +- int rc = 0; + struct iwl3945_scan_cmd *scan; + struct ieee80211_conf *conf = NULL; + u8 n_probes = 0; +@@ -2827,7 +2826,6 @@ static void iwl3945_bg_request_scan(struct work_struct *data) + if (test_bit(STATUS_SCAN_HW, &priv->status)) { + IWL_DEBUG_INFO(priv, "Multiple concurrent scan requests " + "Ignoring second request.\n"); +- rc = -EIO; + goto done; + } + +@@ -2862,7 +2860,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data) + priv->scan = kmalloc(sizeof(struct iwl3945_scan_cmd) + + IWL_MAX_SCAN_SIZE, GFP_KERNEL); + if (!priv->scan) { +- rc = -ENOMEM; ++ IWL_DEBUG_SCAN(priv, "Fail to allocate scan memory\n"); + goto done; + } + } +@@ -2905,7 +2903,9 @@ static void iwl3945_bg_request_scan(struct work_struct *data) + scan_suspend_time, interval); + } + +- if (priv->scan_request->n_ssids) { ++ if (priv->is_internal_short_scan) { ++ IWL_DEBUG_SCAN(priv, "Start internal passive scan.\n"); ++ } else if (priv->scan_request->n_ssids) { + int i, p = 0; + IWL_DEBUG_SCAN(priv, "Kicking off active scan\n"); + for (i = 0; i < priv->scan_request->n_ssids; i++) { +@@ -2952,13 +2952,20 @@ static void iwl3945_bg_request_scan(struct work_struct *data) + goto done; + } + +- scan->tx_cmd.len = cpu_to_le16( ++ if (!priv->is_internal_short_scan) { ++ scan->tx_cmd.len = cpu_to_le16( + iwl_fill_probe_req(priv, + (struct ieee80211_mgmt *)scan->data, + priv->scan_request->ie, + priv->scan_request->ie_len, + IWL_MAX_SCAN_SIZE - sizeof(*scan))); +- ++ } else { ++ scan->tx_cmd.len = cpu_to_le16( ++ iwl_fill_probe_req(priv, ++ (struct ieee80211_mgmt *)scan->data, ++ NULL, 0, ++ IWL_MAX_SCAN_SIZE - sizeof(*scan))); ++ } + /* select Rx antennas */ + scan->flags |= iwl3945_get_antenna_flags(priv); + +@@ -2980,8 +2987,7 @@ static void iwl3945_bg_request_scan(struct work_struct *data) + scan->len = cpu_to_le16(cmd.len); + + set_bit(STATUS_SCAN_HW, &priv->status); +- rc = iwl_send_cmd_sync(priv, &cmd); +- if (rc) ++ if (iwl_send_cmd_sync(priv, &cmd)) + goto done; + + queue_delayed_work(priv->workqueue, &priv->scan_check, diff --git a/iwlwifi_-code-cleanup-for-connectivity-recovery.patch b/iwlwifi_-code-cleanup-for-connectivity-recovery.patch new file mode 100644 index 000000000..bb7a4fede --- /dev/null +++ b/iwlwifi_-code-cleanup-for-connectivity-recovery.patch @@ -0,0 +1,254 @@ +Backport of the following upstream commit... + +commit fa8f130c504223d25c116b3d23787f465dfb1317 +Author: Wey-Yi Guy +Date: Fri Mar 5 14:22:46 2010 -0800 + + iwlwifi: code cleanup for connectivity recovery + + Split the connectivity check and recovery routine into separated + functions based on the types + 1. iwl_good_ack_health() - check for ack count + 2. iwl_good_plcp_health() - check for plcp error + + Based on the type of errors being detected, different recovery methods + will be used to bring the system back to normal operational state. + + Because different NIC has different HW and uCode, the behavior is also + different; these functions thus now form part of the ops infrastructure, + so we can have more control on how to monitor and recover from error condition + case per device. + + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig 2010-04-13 14:57:34.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c 2010-04-13 15:01:00.000000000 -0400 +@@ -139,7 +139,8 @@ static struct iwl_lib_ops iwl1000_lib = + .set_ct_kill = iwl1000_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, +- .recover_from_statistics = iwl_recover_from_statistics, ++ .check_plcp_health = iwl_good_plcp_health, ++ .check_ack_health = iwl_good_ack_health, + }; + + static struct iwl_ops iwl1000_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig 2010-04-13 14:57:34.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c 2010-04-13 15:02:23.000000000 -0400 +@@ -2213,7 +2213,7 @@ static struct iwl_lib_ops iwl4965_lib = + .temperature = iwl4965_temperature_calib, + .set_ct_kill = iwl4965_set_ct_threshold, + }, +- .recover_from_statistics = iwl_recover_from_statistics, ++ .check_plcp_health = iwl_good_plcp_health, + }; + + static struct iwl_ops iwl4965_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig 2010-04-13 14:57:34.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c 2010-04-13 15:01:00.000000000 -0400 +@@ -1507,7 +1507,8 @@ struct iwl_lib_ops iwl5000_lib = { + .set_ct_kill = iwl5000_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, +- .recover_from_statistics = iwl_recover_from_statistics, ++ .check_plcp_health = iwl_good_plcp_health, ++ .check_ack_health = iwl_good_ack_health, + }; + + static struct iwl_lib_ops iwl5150_lib = { +@@ -1561,7 +1562,8 @@ static struct iwl_lib_ops iwl5150_lib = + .set_ct_kill = iwl5150_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, +- .recover_from_statistics = iwl_recover_from_statistics, ++ .check_plcp_health = iwl_good_plcp_health, ++ .check_ack_health = iwl_good_ack_health, + }; + + static struct iwl_ops iwl5000_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig 2010-04-13 14:57:34.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c 2010-04-13 15:01:00.000000000 -0400 +@@ -251,7 +251,8 @@ static struct iwl_lib_ops iwl6000_lib = + .set_ct_kill = iwl6000_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, +- .recover_from_statistics = iwl_recover_from_statistics, ++ .check_plcp_health = iwl_good_plcp_health, ++ .check_ack_health = iwl_good_ack_health, + }; + + static struct iwl_ops iwl6000_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-04-13 14:57:34.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 15:04:33.000000000 -0400 +@@ -189,8 +189,11 @@ struct iwl_lib_ops { + struct iwl_temp_ops temp_ops; + /* recover from tx queue stall */ + void (*recover_from_tx_stall)(unsigned long data); +- /* recover from errors showed in statistics */ +- void (*recover_from_statistics)(struct iwl_priv *priv, ++ /* check for plcp health */ ++ bool (*check_plcp_health)(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt); ++ /* check for ack health */ ++ bool (*check_ack_health)(struct iwl_priv *priv, + struct iwl_rx_packet *pkt); + }; + +@@ -435,7 +438,9 @@ int iwl_tx_queue_reclaim(struct iwl_priv + /* Handlers */ + void iwl_rx_missed_beacon_notif(struct iwl_priv *priv, + struct iwl_rx_mem_buffer *rxb); +-void iwl_recover_from_statistics(struct iwl_priv *priv, ++bool iwl_good_plcp_health(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt); ++bool iwl_good_ack_health(struct iwl_priv *priv, + struct iwl_rx_packet *pkt); + void iwl_rx_statistics(struct iwl_priv *priv, + struct iwl_rx_mem_buffer *rxb); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig 2010-04-13 14:57:34.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c 2010-04-13 15:01:00.000000000 -0400 +@@ -598,24 +598,18 @@ static void iwl_accumulative_statistics( + #define BA_TIMEOUT_CNT (5) + #define BA_TIMEOUT_MAX (16) + +-#define PLCP_MSG "plcp_err exceeded %u, %u, %u, %u, %u, %d, %u mSecs\n" +-/* +- * This function checks for plcp error, ACK count ratios, aggregated BA +- * timeout retries. +- * - When the ACK count ratio is 0 and aggregated BA timeout retries is +- * exceeding the BA_TIMEOUT_MAX, it will recover the failure by resetting +- * the firmware. +- * - When the plcp error is exceeding the thresholds, it will reset the radio +- * to improve the throughput. ++/** ++ * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. ++ * ++ * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding ++ * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal ++ * operation state. + */ +-void iwl_recover_from_statistics(struct iwl_priv *priv, +- struct iwl_rx_packet *pkt) ++bool iwl_good_ack_health(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt) + { +- int combined_plcp_delta; +- unsigned int plcp_msec; +- unsigned long plcp_received_jiffies; +- int actual_ack_cnt_delta; +- int expected_ack_cnt_delta; ++ bool rc = true; ++ int actual_ack_cnt_delta, expected_ack_cnt_delta; + int ba_timeout_delta; + + actual_ack_cnt_delta = +@@ -638,13 +632,27 @@ void iwl_recover_from_statistics(struct + + IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n", + ba_timeout_delta); +- if ((actual_ack_cnt_delta == 0) && +- (ba_timeout_delta >= BA_TIMEOUT_MAX)) { +- IWL_DEBUG_RADIO(priv, +- "call iwl_force_reset(IWL_FW_RESET)\n"); +- iwl_force_reset(priv, IWL_FW_RESET); +- } ++ if (!actual_ack_cnt_delta && ++ (ba_timeout_delta >= BA_TIMEOUT_MAX)) ++ rc = false; + } ++ return rc; ++} ++EXPORT_SYMBOL(iwl_good_ack_health); ++ ++/** ++ * iwl_good_plcp_health - checks for plcp error. ++ * ++ * When the plcp error is exceeding the thresholds, reset the radio ++ * to improve the throughput. ++ */ ++bool iwl_good_plcp_health(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt) ++{ ++ bool rc = true; ++ int combined_plcp_delta; ++ unsigned int plcp_msec; ++ unsigned long plcp_received_jiffies; + + /* + * check for plcp_err and trigger radio reset if it exceeds +@@ -679,7 +687,8 @@ void iwl_recover_from_statistics(struct + * combined_plcp_delta, + * plcp_msec + */ +- IWL_DEBUG_RADIO(priv, PLCP_MSG, ++ IWL_DEBUG_RADIO(priv, "plcp_err exceeded %u, " ++ "%u, %u, %u, %u, %d, %u mSecs\n", + priv->cfg->plcp_delta_threshold, + le32_to_cpu(pkt->u.stats.rx.ofdm.plcp_err), + le32_to_cpu(priv->statistics.rx.ofdm.plcp_err), +@@ -687,15 +696,42 @@ void iwl_recover_from_statistics(struct + le32_to_cpu( + priv->statistics.rx.ofdm_ht.plcp_err), + combined_plcp_delta, plcp_msec); +- /* +- * Reset the RF radio due to the high plcp +- * error rate +- */ +- iwl_force_reset(priv, IWL_RF_RESET); ++ rc = false; ++ } ++ } ++ return rc; ++} ++EXPORT_SYMBOL(iwl_good_plcp_health); ++ ++static void iwl_recover_from_statistics(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt) ++{ ++ if (test_bit(STATUS_EXIT_PENDING, &priv->status)) ++ return; ++ if (iwl_is_associated(priv)) { ++ if (priv->cfg->ops->lib->check_ack_health) { ++ if (!priv->cfg->ops->lib->check_ack_health( ++ priv, pkt)) { ++ /* ++ * low ack count detected ++ * restart Firmware ++ */ ++ IWL_ERR(priv, "low ack count detected, " ++ "restart firmware\n"); ++ iwl_force_reset(priv, IWL_FW_RESET); ++ } ++ } else if (priv->cfg->ops->lib->check_plcp_health) { ++ if (!priv->cfg->ops->lib->check_plcp_health( ++ priv, pkt)) { ++ /* ++ * high plcp error detected ++ * reset Radio ++ */ ++ iwl_force_reset(priv, IWL_RF_RESET); ++ } + } + } + } +-EXPORT_SYMBOL(iwl_recover_from_statistics); + + void iwl_rx_statistics(struct iwl_priv *priv, + struct iwl_rx_mem_buffer *rxb) +@@ -717,8 +753,7 @@ void iwl_rx_statistics(struct iwl_priv * + #ifdef CONFIG_IWLWIFI_DEBUG + iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats); + #endif +- if (priv->cfg->ops->lib->recover_from_statistics) +- priv->cfg->ops->lib->recover_from_statistics(priv, pkt); ++ iwl_recover_from_statistics(priv, pkt); + + memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics)); + diff --git a/iwlwifi_-iwl_good_ack_health-only-apply-to-AGN-device.patch b/iwlwifi_-iwl_good_ack_health-only-apply-to-AGN-device.patch new file mode 100644 index 000000000..6072f0a2a --- /dev/null +++ b/iwlwifi_-iwl_good_ack_health-only-apply-to-AGN-device.patch @@ -0,0 +1,140 @@ +Backport of the following upstream commit... + +commit 872c8ddcbec06995c1c7caa3e41c921290a8b6df +Author: Wey-Yi Guy +Date: Tue Mar 16 10:46:31 2010 -0700 + + iwlwifi: iwl_good_ack_health() only apply to AGN device + + iwl_good_ack_health() check for expected and actual ack count which only + apply to aggregation mode. Move the function to iwlagn module. + + Reported-by: Chantry Xavier + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig 2010-04-13 15:15:47.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c 2010-04-13 15:20:00.000000000 -0400 +@@ -1316,6 +1316,52 @@ static void iwl_irq_tasklet(struct iwl_p + iwl_enable_interrupts(priv); + } + ++/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ ++#define ACK_CNT_RATIO (50) ++#define BA_TIMEOUT_CNT (5) ++#define BA_TIMEOUT_MAX (16) ++ ++/** ++ * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. ++ * ++ * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding ++ * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal ++ * operation state. ++ */ ++bool iwl_good_ack_health(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt) ++{ ++ bool rc = true; ++ int actual_ack_cnt_delta, expected_ack_cnt_delta; ++ int ba_timeout_delta; ++ ++ actual_ack_cnt_delta = ++ le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) - ++ le32_to_cpu(priv->statistics.tx.actual_ack_cnt); ++ expected_ack_cnt_delta = ++ le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) - ++ le32_to_cpu(priv->statistics.tx.expected_ack_cnt); ++ ba_timeout_delta = ++ le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) - ++ le32_to_cpu(priv->statistics.tx.agg.ba_timeout); ++ if ((priv->agg_tids_count > 0) && ++ (expected_ack_cnt_delta > 0) && ++ (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta) ++ < ACK_CNT_RATIO) && ++ (ba_timeout_delta > BA_TIMEOUT_CNT)) { ++ IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d," ++ " expected_ack_cnt = %d\n", ++ actual_ack_cnt_delta, expected_ack_cnt_delta); ++ ++ IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n", ++ ba_timeout_delta); ++ if (!actual_ack_cnt_delta && ++ (ba_timeout_delta >= BA_TIMEOUT_MAX)) ++ rc = false; ++ } ++ return rc; ++} ++ + + /****************************************************************************** + * +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-04-13 15:15:47.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 15:18:13.000000000 -0400 +@@ -584,6 +584,8 @@ void iwl_disable_ict(struct iwl_priv *pr + int iwl_alloc_isr_ict(struct iwl_priv *priv); + void iwl_free_isr_ict(struct iwl_priv *priv); + irqreturn_t iwl_isr_ict(int irq, void *data); ++bool iwl_good_ack_health(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt); + + static inline u16 iwl_pcie_link_ctl(struct iwl_priv *priv) + { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig 2010-04-13 15:15:47.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c 2010-04-13 15:18:52.000000000 -0400 +@@ -593,53 +593,6 @@ static void iwl_accumulative_statistics( + + #define REG_RECALIB_PERIOD (60) + +-/* the threshold ratio of actual_ack_cnt to expected_ack_cnt in percent */ +-#define ACK_CNT_RATIO (50) +-#define BA_TIMEOUT_CNT (5) +-#define BA_TIMEOUT_MAX (16) +- +-/** +- * iwl_good_ack_health - checks for ACK count ratios, BA timeout retries. +- * +- * When the ACK count ratio is 0 and aggregated BA timeout retries exceeding +- * the BA_TIMEOUT_MAX, reload firmware and bring system back to normal +- * operation state. +- */ +-bool iwl_good_ack_health(struct iwl_priv *priv, +- struct iwl_rx_packet *pkt) +-{ +- bool rc = true; +- int actual_ack_cnt_delta, expected_ack_cnt_delta; +- int ba_timeout_delta; +- +- actual_ack_cnt_delta = +- le32_to_cpu(pkt->u.stats.tx.actual_ack_cnt) - +- le32_to_cpu(priv->statistics.tx.actual_ack_cnt); +- expected_ack_cnt_delta = +- le32_to_cpu(pkt->u.stats.tx.expected_ack_cnt) - +- le32_to_cpu(priv->statistics.tx.expected_ack_cnt); +- ba_timeout_delta = +- le32_to_cpu(pkt->u.stats.tx.agg.ba_timeout) - +- le32_to_cpu(priv->statistics.tx.agg.ba_timeout); +- if ((priv->agg_tids_count > 0) && +- (expected_ack_cnt_delta > 0) && +- (((actual_ack_cnt_delta * 100) / expected_ack_cnt_delta) +- < ACK_CNT_RATIO) && +- (ba_timeout_delta > BA_TIMEOUT_CNT)) { +- IWL_DEBUG_RADIO(priv, "actual_ack_cnt delta = %d," +- " expected_ack_cnt = %d\n", +- actual_ack_cnt_delta, expected_ack_cnt_delta); +- +- IWL_DEBUG_RADIO(priv, "agg ba_timeout delta = %d\n", +- ba_timeout_delta); +- if (!actual_ack_cnt_delta && +- (ba_timeout_delta >= BA_TIMEOUT_MAX)) +- rc = false; +- } +- return rc; +-} +-EXPORT_SYMBOL(iwl_good_ack_health); +- + /** + * iwl_good_plcp_health - checks for plcp error. + * diff --git a/iwlwifi_-move-plcp-check-to-separated-function.patch b/iwlwifi_-move-plcp-check-to-separated-function.patch new file mode 100644 index 000000000..394eeb2b1 --- /dev/null +++ b/iwlwifi_-move-plcp-check-to-separated-function.patch @@ -0,0 +1,186 @@ +Backport of the following upstream commit... + +commit beac5498b792ed8420885ee23e8d4f2885ee2d13 +Author: Wey-Yi Guy +Date: Thu Mar 4 13:38:58 2010 -0800 + + iwlwifi: move plcp check to separated function + + Move the plcp error checking into stand alone function and pointed by ops + to accommodate devices not needing this recovery. + + Signed-off-by: Trieu 'Andrew' Nguyen + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c.orig 2010-04-13 14:40:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-1000.c 2010-04-13 14:40:43.000000000 -0400 +@@ -139,6 +139,7 @@ static struct iwl_lib_ops iwl1000_lib = + .set_ct_kill = iwl1000_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, ++ .recover_from_statistics = iwl_recover_from_statistics, + }; + + static struct iwl_ops iwl1000_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c.orig 2010-04-13 14:40:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-4965.c 2010-04-13 14:41:23.000000000 -0400 +@@ -2213,6 +2213,7 @@ static struct iwl_lib_ops iwl4965_lib = + .temperature = iwl4965_temperature_calib, + .set_ct_kill = iwl4965_set_ct_threshold, + }, ++ .recover_from_statistics = iwl_recover_from_statistics, + }; + + static struct iwl_ops iwl4965_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c.orig 2010-04-13 14:40:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-5000.c 2010-04-13 14:40:43.000000000 -0400 +@@ -1507,6 +1507,7 @@ struct iwl_lib_ops iwl5000_lib = { + .set_ct_kill = iwl5000_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, ++ .recover_from_statistics = iwl_recover_from_statistics, + }; + + static struct iwl_lib_ops iwl5150_lib = { +@@ -1560,6 +1561,7 @@ static struct iwl_lib_ops iwl5150_lib = + .set_ct_kill = iwl5150_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, ++ .recover_from_statistics = iwl_recover_from_statistics, + }; + + static struct iwl_ops iwl5000_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c.orig 2010-04-13 14:40:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-6000.c 2010-04-13 14:42:29.000000000 -0400 +@@ -251,6 +251,7 @@ static struct iwl_lib_ops iwl6000_lib = + .set_ct_kill = iwl6000_set_ct_threshold, + }, + .recover_from_tx_stall = iwl_bg_monitor_recover, ++ .recover_from_statistics = iwl_recover_from_statistics, + }; + + static struct iwl_ops iwl6000_ops = { +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-04-13 14:40:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 14:43:12.000000000 -0400 +@@ -189,6 +189,9 @@ struct iwl_lib_ops { + struct iwl_temp_ops temp_ops; + /* recover from tx queue stall */ + void (*recover_from_tx_stall)(unsigned long data); ++ /* recover from errors showed in statistics */ ++ void (*recover_from_statistics)(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt); + }; + + struct iwl_led_ops { +@@ -432,6 +435,8 @@ int iwl_tx_queue_reclaim(struct iwl_priv + /* Handlers */ + void iwl_rx_missed_beacon_notif(struct iwl_priv *priv, + struct iwl_rx_mem_buffer *rxb); ++void iwl_recover_from_statistics(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt); + void iwl_rx_statistics(struct iwl_priv *priv, + struct iwl_rx_mem_buffer *rxb); + void iwl_reply_statistics(struct iwl_priv *priv, +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig 2010-04-13 14:40:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c 2010-04-13 14:40:43.000000000 -0400 +@@ -594,28 +594,18 @@ static void iwl_accumulative_statistics( + #define REG_RECALIB_PERIOD (60) + + #define PLCP_MSG "plcp_err exceeded %u, %u, %u, %u, %u, %d, %u mSecs\n" +-void iwl_rx_statistics(struct iwl_priv *priv, +- struct iwl_rx_mem_buffer *rxb) ++/* ++ * This function checks for plcp error. ++ * - When the plcp error is exceeding the thresholds, it will reset the radio ++ * to improve the throughput. ++ */ ++void iwl_recover_from_statistics(struct iwl_priv *priv, ++ struct iwl_rx_packet *pkt) + { +- int change; +- struct iwl_rx_packet *pkt = rxb_addr(rxb); + int combined_plcp_delta; + unsigned int plcp_msec; + unsigned long plcp_received_jiffies; + +- IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n", +- (int)sizeof(priv->statistics), +- le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK); +- +- change = ((priv->statistics.general.temperature != +- pkt->u.stats.general.temperature) || +- ((priv->statistics.flag & +- STATISTICS_REPLY_FLG_HT40_MODE_MSK) != +- (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK))); +- +-#ifdef CONFIG_IWLWIFI_DEBUG +- iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats); +-#endif + /* + * check for plcp_err and trigger radio reset if it exceeds + * the plcp error threshold plcp_delta. +@@ -636,11 +626,11 @@ void iwl_rx_statistics(struct iwl_priv * + le32_to_cpu(priv->statistics.rx.ofdm_ht.plcp_err)); + + if ((combined_plcp_delta > 0) && +- ((combined_plcp_delta * 100) / plcp_msec) > ++ ((combined_plcp_delta * 100) / plcp_msec) > + priv->cfg->plcp_delta_threshold) { + /* +- * if plcp_err exceed the threshold, the following +- * data is printed in csv format: ++ * if plcp_err exceed the threshold, ++ * the following data is printed in csv format: + * Text: plcp_err exceeded %d, + * Received ofdm.plcp_err, + * Current ofdm.plcp_err, +@@ -655,9 +645,8 @@ void iwl_rx_statistics(struct iwl_priv * + le32_to_cpu(priv->statistics.rx.ofdm.plcp_err), + le32_to_cpu(pkt->u.stats.rx.ofdm_ht.plcp_err), + le32_to_cpu( +- priv->statistics.rx.ofdm_ht.plcp_err), ++ priv->statistics.rx.ofdm_ht.plcp_err), + combined_plcp_delta, plcp_msec); +- + /* + * Reset the RF radio due to the high plcp + * error rate +@@ -665,6 +654,31 @@ void iwl_rx_statistics(struct iwl_priv * + iwl_force_reset(priv, IWL_RF_RESET); + } + } ++} ++EXPORT_SYMBOL(iwl_recover_from_statistics); ++ ++void iwl_rx_statistics(struct iwl_priv *priv, ++ struct iwl_rx_mem_buffer *rxb) ++{ ++ int change; ++ struct iwl_rx_packet *pkt = rxb_addr(rxb); ++ ++ ++ IWL_DEBUG_RX(priv, "Statistics notification received (%d vs %d).\n", ++ (int)sizeof(priv->statistics), ++ le32_to_cpu(pkt->len_n_flags) & FH_RSCSR_FRAME_SIZE_MSK); ++ ++ change = ((priv->statistics.general.temperature != ++ pkt->u.stats.general.temperature) || ++ ((priv->statistics.flag & ++ STATISTICS_REPLY_FLG_HT40_MODE_MSK) != ++ (pkt->u.stats.flag & STATISTICS_REPLY_FLG_HT40_MODE_MSK))); ++ ++#ifdef CONFIG_IWLWIFI_DEBUG ++ iwl_accumulative_statistics(priv, (__le32 *)&pkt->u.stats); ++#endif ++ if (priv->cfg->ops->lib->recover_from_statistics) ++ priv->cfg->ops->lib->recover_from_statistics(priv, pkt); + + memcpy(&priv->statistics, &pkt->u.stats, sizeof(priv->statistics)); + diff --git a/iwlwifi_-multiple-force-reset-mode.patch b/iwlwifi_-multiple-force-reset-mode.patch new file mode 100644 index 000000000..e50971f59 --- /dev/null +++ b/iwlwifi_-multiple-force-reset-mode.patch @@ -0,0 +1,172 @@ +Backport of the following upstream commit... + +commit a93e7973d0983d22fcbe5f691244736211639fe7 +Author: Wey-Yi Guy +Date: Wed Feb 3 11:47:19 2010 -0800 + + iwlwifi: multiple force reset mode + + Provide the function to perform different type of uCode reset/reload operation. + When uCode detect error and can not fix itself, this iwl_force_reset() + function allow driver to perform the necessary reset/reload functions and help + to bring uCode back to normal operation state. + + Currently only 2 type of force reset are available: + - reset radio + - reload firmware + + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig 2010-04-13 13:36:35.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c 2010-04-13 13:38:40.000000000 -0400 +@@ -3197,7 +3197,7 @@ void iwl_update_stats(struct iwl_priv *p + EXPORT_SYMBOL(iwl_update_stats); + #endif + +-void iwl_force_rf_reset(struct iwl_priv *priv) ++static void iwl_force_rf_reset(struct iwl_priv *priv) + { + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return; +@@ -3219,7 +3219,47 @@ void iwl_force_rf_reset(struct iwl_priv + iwl_internal_short_hw_scan(priv); + return; + } +-EXPORT_SYMBOL(iwl_force_rf_reset); ++ ++#define IWL_DELAY_NEXT_FORCE_RESET (HZ*3) ++ ++int iwl_force_reset(struct iwl_priv *priv, int mode) ++{ ++ if (test_bit(STATUS_EXIT_PENDING, &priv->status)) ++ return -EINVAL; ++ ++ if (priv->last_force_reset_jiffies && ++ time_after(priv->last_force_reset_jiffies + ++ IWL_DELAY_NEXT_FORCE_RESET, jiffies)) { ++ IWL_DEBUG_INFO(priv, "force reset rejected\n"); ++ return -EAGAIN; ++ } ++ ++ IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode); ++ ++ switch (mode) { ++ case IWL_RF_RESET: ++ iwl_force_rf_reset(priv); ++ break; ++ case IWL_FW_RESET: ++ IWL_ERR(priv, "On demand firmware reload\n"); ++ /* Set the FW error flag -- cleared on iwl_down */ ++ set_bit(STATUS_FW_ERROR, &priv->status); ++ wake_up_interruptible(&priv->wait_command_queue); ++ /* ++ * Keep the restart process from trying to send host ++ * commands by clearing the INIT status bit ++ */ ++ clear_bit(STATUS_READY, &priv->status); ++ queue_work(priv->workqueue, &priv->restart); ++ break; ++ default: ++ IWL_DEBUG_INFO(priv, "invalid reset request.\n"); ++ return -EINVAL; ++ } ++ priv->last_force_reset_jiffies = jiffies; ++ ++ return 0; ++} + + #ifdef CONFIG_PM + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h.orig 2010-04-13 13:36:50.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.h 2010-04-13 13:38:40.000000000 -0400 +@@ -501,7 +501,7 @@ int iwl_scan_cancel(struct iwl_priv *pri + int iwl_scan_cancel_timeout(struct iwl_priv *priv, unsigned long ms); + int iwl_mac_hw_scan(struct ieee80211_hw *hw, struct cfg80211_scan_request *req); + int iwl_internal_short_hw_scan(struct iwl_priv *priv); +-void iwl_force_rf_reset(struct iwl_priv *priv); ++int iwl_force_reset(struct iwl_priv *priv, int mode); + u16 iwl_fill_probe_req(struct iwl_priv *priv, struct ieee80211_mgmt *frame, + const u8 *ie, int ie_len, int left); + void iwl_setup_rx_scan_handlers(struct iwl_priv *priv); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 13:36:50.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 13:38:40.000000000 -0400 +@@ -993,6 +993,11 @@ struct iwl_switch_rxon { + #define IWL_MAX_PLCP_ERR_LONG_THRESHOLD_DEF (100) + #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255) + ++enum iwl_reset { ++ IWL_RF_RESET = 0, ++ IWL_FW_RESET, ++}; ++ + struct iwl_priv { + + /* ieee device used by generic ieee processing code */ +@@ -1024,6 +1029,9 @@ struct iwl_priv { + /* storing the jiffies when the plcp error rate is received */ + unsigned long plcp_jiffies; + ++ /* force reset */ ++ unsigned long last_force_reset_jiffies; ++ + /* we allocate array of iwl4965_channel_info for NIC's valid channels. + * Access via channel # using indirect index array */ + struct iwl_channel_info *channel_info; /* channel info array */ +@@ -1046,7 +1054,6 @@ struct iwl_priv { + unsigned long scan_start; + unsigned long scan_pass_start; + unsigned long scan_start_tsf; +- unsigned long last_internal_scan_jiffies; + void *scan; + int scan_bands; + struct cfg80211_scan_request *scan_request; +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c.orig 2010-04-13 13:36:50.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-rx.c 2010-04-13 13:38:40.000000000 -0400 +@@ -662,7 +662,7 @@ void iwl_rx_statistics(struct iwl_priv * + * Reset the RF radio due to the high plcp + * error rate + */ +- iwl_force_rf_reset(priv); ++ iwl_force_reset(priv, IWL_RF_RESET); + } + } + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c.orig 2010-04-13 13:36:42.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-scan.c 2010-04-13 13:38:40.000000000 -0400 +@@ -254,8 +254,6 @@ static void iwl_rx_scan_complete_notif(s + priv->last_scan_jiffies = jiffies; + if (!priv->is_internal_short_scan) + priv->next_scan_jiffies = 0; +- else +- priv->last_internal_scan_jiffies = jiffies; + + IWL_DEBUG_INFO(priv, "Setting scan to off\n"); + +@@ -564,8 +562,6 @@ EXPORT_SYMBOL(iwl_mac_hw_scan); + * internal short scan, this function should only been called while associated. + * It will reset and tune the radio to prevent possible RF related problem + */ +-#define IWL_DELAY_NEXT_INTERNAL_SCAN (HZ*1) +- + int iwl_internal_short_hw_scan(struct iwl_priv *priv) + { + int ret = 0; +@@ -585,12 +581,6 @@ int iwl_internal_short_hw_scan(struct iw + ret = -EAGAIN; + goto out; + } +- if (priv->last_internal_scan_jiffies && +- time_after(priv->last_internal_scan_jiffies + +- IWL_DELAY_NEXT_INTERNAL_SCAN, jiffies)) { +- IWL_DEBUG_SCAN(priv, "internal scan rejected\n"); +- goto out; +- } + + priv->scan_bands = 0; + if (priv->band == IEEE80211_BAND_5GHZ) diff --git a/iwlwifi_-separated-time-check-for-different-type-of-force-reset.patch b/iwlwifi_-separated-time-check-for-different-type-of-force-reset.patch new file mode 100644 index 000000000..f70807460 --- /dev/null +++ b/iwlwifi_-separated-time-check-for-different-type-of-force-reset.patch @@ -0,0 +1,122 @@ +Backport of the following upstream commit... + +commit 8a472da431998b7357e6dc562e79a3061ed56cad +Author: Wey-Yi Guy +Date: Thu Feb 18 22:03:06 2010 -0800 + + iwlwifi: separated time check for different type of force reset + + Use different timing duration check for different type of force reset, + force reset request can come from different source and based on + different reason; one type of reset request should not block other type of + reset request. + + Adding structure to keep track of different force reset request. + + Signed-off-by: Wey-Yi Guy + Signed-off-by: Reinette Chatre + Signed-off-by: John W. Linville + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c.orig 2010-04-13 13:44:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-agn.c 2010-04-13 13:47:34.000000000 -0400 +@@ -3189,6 +3189,12 @@ static int iwl_init_drv(struct iwl_priv + + priv->iw_mode = NL80211_IFTYPE_STATION; + ++ /* initialize force reset */ ++ priv->force_reset[IWL_RF_RESET].reset_duration = ++ IWL_DELAY_NEXT_FORCE_RF_RESET; ++ priv->force_reset[IWL_FW_RESET].reset_duration = ++ IWL_DELAY_NEXT_FORCE_FW_RELOAD; ++ + /* Choose which receivers/antennas to use */ + if (priv->cfg->ops->hcmd->set_rxon_chain) + priv->cfg->ops->hcmd->set_rxon_chain(priv); +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c.orig 2010-04-13 13:44:14.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-core.c 2010-04-13 13:47:34.000000000 -0400 +@@ -3220,22 +3220,30 @@ static void iwl_force_rf_reset(struct iw + return; + } + +-#define IWL_DELAY_NEXT_FORCE_RESET (HZ*3) + + int iwl_force_reset(struct iwl_priv *priv, int mode) + { ++ struct iwl_force_reset *force_reset; ++ + if (test_bit(STATUS_EXIT_PENDING, &priv->status)) + return -EINVAL; + +- if (priv->last_force_reset_jiffies && +- time_after(priv->last_force_reset_jiffies + +- IWL_DELAY_NEXT_FORCE_RESET, jiffies)) { ++ if (mode >= IWL_MAX_FORCE_RESET) { ++ IWL_DEBUG_INFO(priv, "invalid reset request.\n"); ++ return -EINVAL; ++ } ++ force_reset = &priv->force_reset[mode]; ++ force_reset->reset_request_count++; ++ if (force_reset->last_force_reset_jiffies && ++ time_after(force_reset->last_force_reset_jiffies + ++ force_reset->reset_duration, jiffies)) { + IWL_DEBUG_INFO(priv, "force reset rejected\n"); ++ force_reset->reset_reject_count++; + return -EAGAIN; + } +- ++ force_reset->reset_success_count++; ++ force_reset->last_force_reset_jiffies = jiffies; + IWL_DEBUG_INFO(priv, "perform force reset (%d)\n", mode); +- + switch (mode) { + case IWL_RF_RESET: + iwl_force_rf_reset(priv); +@@ -3252,12 +3260,7 @@ int iwl_force_reset(struct iwl_priv *pri + clear_bit(STATUS_READY, &priv->status); + queue_work(priv->workqueue, &priv->restart); + break; +- default: +- IWL_DEBUG_INFO(priv, "invalid reset request.\n"); +- return -EINVAL; + } +- priv->last_force_reset_jiffies = jiffies; +- + return 0; + } + +diff -up linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h +--- linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h.orig 2010-04-13 13:45:06.000000000 -0400 ++++ linux-2.6.33.noarch/drivers/net/wireless/iwlwifi/iwl-dev.h 2010-04-13 13:47:34.000000000 -0400 +@@ -994,9 +994,21 @@ struct iwl_switch_rxon { + #define IWL_MAX_PLCP_ERR_EXT_LONG_THRESHOLD_DEF (200) + #define IWL_MAX_PLCP_ERR_THRESHOLD_MAX (255) + ++#define IWL_DELAY_NEXT_FORCE_RF_RESET (HZ*3) ++#define IWL_DELAY_NEXT_FORCE_FW_RELOAD (HZ*5) ++ + enum iwl_reset { + IWL_RF_RESET = 0, + IWL_FW_RESET, ++ IWL_MAX_FORCE_RESET, ++}; ++ ++struct iwl_force_reset { ++ int reset_request_count; ++ int reset_success_count; ++ int reset_reject_count; ++ unsigned long reset_duration; ++ unsigned long last_force_reset_jiffies; + }; + + struct iwl_priv { +@@ -1031,7 +1043,7 @@ struct iwl_priv { + unsigned long plcp_jiffies; + + /* force reset */ +- unsigned long last_force_reset_jiffies; ++ struct iwl_force_reset force_reset[IWL_MAX_FORCE_RESET]; + + /* we allocate array of iwl4965_channel_info for NIC's valid channels. + * Access via channel # using indirect index array */ diff --git a/kernel.spec b/kernel.spec new file mode 100644 index 000000000..e67bec8c1 --- /dev/null +++ b/kernel.spec @@ -0,0 +1,4580 @@ +# We have to override the new %%install behavior because, well... the kernel is special. +%global __spec_install_pre %{___build_pre} + +Summary: The Linux kernel + +# For a stable, released kernel, released_kernel should be 1. For rawhide +# and/or a kernel built from an rc or git snapshot, released_kernel should +# be 0. +%global released_kernel 1 + +# Save original buildid for later if it's defined +%if 0%{?buildid:1} +%global orig_buildid %{buildid} +%undefine buildid +%endif + +################################################################### +# Polite request for people who spin their own kernel rpms: +# please modify the "buildid" define in a way that identifies +# that the kernel isn't the stock distribution kernel, for example, +# by setting the define to ".local" or ".bz123456". This will be +# appended to the full kernel version. +# +# (Uncomment the '#' and both spaces below to set the buildid.) +# +# % define buildid .local +################################################################### + +# buildid can also be specified on the rpmbuild command line +# by adding --define="buildid .whatever". If both kinds of buildid +# are specified they will be concatenated together. +%if 0%{?orig_buildid:1} +%if 0%{?buildid:1} +%global srpm_buildid %{buildid} +%define buildid %{srpm_buildid}%{orig_buildid} +%else +%define buildid %{orig_buildid} +%endif +%endif + +# baserelease defines which build revision of this kernel version we're +# building. We used to call this fedora_build, but the magical name +# baserelease is matched by the rpmdev-bumpspec tool, which you should use. +# +# We used to have some extra magic weirdness to bump this automatically, +# but now we don't. Just use: rpmdev-bumpspec -c 'comment for changelog' +# When changing base_sublevel below or going from rc to a final kernel, +# reset this by hand to 1 (or to 0 and then use rpmdev-bumpspec). +# scripts/rebase.sh should be made to do that for you, actually. +# +%global baserelease 149 +%global fedora_build %{baserelease} + +# base_sublevel is the kernel version we're starting with and patching +# on top of -- for example, 2.6.22-rc7-git1 starts with a 2.6.21 base, +# which yields a base_sublevel of 21. +%define base_sublevel 33 + +## If this is a released kernel ## +%if 0%{?released_kernel} + +# Do we have a -stable update to apply? +%define stable_update 8 +# Is it a -stable RC? +%define stable_rc 0 +# Set rpm version accordingly +%if 0%{?stable_update} +%define stablerev .%{stable_update} +# Set stable_base for incremental stable patches that are not -rc's +%define stable_base 7 +%if 0%{?stable_rc} +# stable RCs are incremental patches, so we need the previous stable patch +%define stable_base %(echo $((%{stable_update} - 1))) +%endif +%endif +%define rpmversion 2.6.%{base_sublevel}%{?stablerev} + +## The not-released-kernel case ## +%else +# The next upstream release sublevel (base_sublevel+1) +%define upstream_sublevel %(echo $((%{base_sublevel} + 1))) +# The rc snapshot level +%define rcrev 0 +# The git snapshot level +%define gitrev 0 +# Set rpm version accordingly +%define rpmversion 2.6.%{upstream_sublevel} +%endif +# Nb: The above rcrev and gitrev values automagically define Patch00 and Patch01 below. + +# What parts do we want to build? We must build at least one kernel. +# These are the kernels that are built IF the architecture allows it. +# All should default to 1 (enabled) and be flipped to 0 (disabled) +# by later arch-specific checks. + +# The following build options are enabled by default. +# Use either --without in your rpmbuild command or force values +# to 0 in here to disable them. +# +# standard kernel +%define with_up %{?_without_up: 0} %{?!_without_up: 1} +# kernel-smp (only valid for ppc 32-bit) +%define with_smp %{?_without_smp: 0} %{?!_without_smp: 1} +# kernel-kdump +%define with_kdump %{?_without_kdump: 0} %{?!_without_kdump: 1} +# kernel-debug +%define with_debug %{?_without_debug: 0} %{?!_without_debug: 1} +# kernel-doc +%define with_doc %{?_without_doc: 0} %{?!_without_doc: 1} +# kernel-headers +%define with_headers %{?_without_headers: 0} %{?!_without_headers: 1} +# kernel-firmware +%define with_firmware %{?_with_firmware: 1} %{?!_with_firmware: 0} +# tools/perf +%define with_perftool %{?_without_perftool: 0} %{?!_without_perftool: 1} +# perf noarch subpkg +%define with_perf %{?_without_perf: 0} %{?!_without_perf: 1} +# kernel-debuginfo +%define with_debuginfo %{?_without_debuginfo: 0} %{?!_without_debuginfo: 1} +# kernel-bootwrapper (for creating zImages from kernel + initrd) +%define with_bootwrapper %{?_without_bootwrapper: 0} %{?!_without_bootwrapper: 1} +# Want to build a the vsdo directories installed +%define with_vdso_install %{?_without_vdso_install: 0} %{?!_without_vdso_install: 1} +# Use dracut instead of mkinitrd for initrd image generation +%define with_dracut %{?_without_dracut: 0} %{?!_without_dracut: 1} + +# Build the kernel-doc package, but don't fail the build if it botches. +# Here "true" means "continue" and "false" means "fail the build". +%if 0%{?released_kernel} +%define doc_build_fail true +%else +%define doc_build_fail true +%endif + +%define rawhide_skip_docs 0 +%if 0%{?rawhide_skip_docs} +%define with_doc 0 +%endif + +# Additional options for user-friendly one-off kernel building: +# +# Only build the base kernel (--with baseonly): +%define with_baseonly %{?_with_baseonly: 1} %{?!_with_baseonly: 0} +# Only build the smp kernel (--with smponly): +%define with_smponly %{?_with_smponly: 1} %{?!_with_smponly: 0} +# Only build the debug kernel (--with dbgonly): +%define with_dbgonly %{?_with_dbgonly: 1} %{?!_with_dbgonly: 0} + +# should we do C=1 builds with sparse +%define with_sparse %{?_with_sparse: 1} %{?!_with_sparse: 0} + +# Set debugbuildsenabled to 1 for production (build separate debug kernels) +# and 0 for rawhide (all kernels are debug kernels). +# See also 'make debug' and 'make release'. +%define debugbuildsenabled 1 + +# Want to build a vanilla kernel build without any non-upstream patches? +# (well, almost none, we need nonintconfig for build purposes). Default to 0 (off). +%define with_vanilla %{?_with_vanilla: 1} %{?!_with_vanilla: 0} + +# pkg_release is what we'll fill in for the rpm Release: field +%if 0%{?released_kernel} + +%if 0%{?stable_rc} +%define stable_rctag .rc%{stable_rc} +%endif +%define pkg_release %{fedora_build}%{?stable_rctag}%{?buildid}%{?dist} + +%else + +# non-released_kernel +%if 0%{?rcrev} +%define rctag .rc%rcrev +%else +%define rctag .rc0 +%endif +%if 0%{?gitrev} +%define gittag .git%gitrev +%else +%define gittag .git0 +%endif +%define pkg_release 0.%{fedora_build}%{?rctag}%{?gittag}%{?buildid}%{?dist} + +%endif + +# The kernel tarball/base version +%define kversion 2.6.%{base_sublevel} + +%define make_target bzImage + +%define KVERREL %{version}-%{release}.%{_target_cpu} +%define hdrarch %_target_cpu +%define asmarch %_target_cpu + +%if 0%{!?nopatches:1} +%define nopatches 0 +%endif + +%if %{with_vanilla} +%define nopatches 1 +%endif + +%if %{nopatches} +%define with_bootwrapper 0 +%define variant -vanilla +%else +%define variant_fedora -fedora +%endif + +%define using_upstream_branch 0 +%if 0%{?upstream_branch:1} +%define stable_update 0 +%define using_upstream_branch 1 +%define variant -%{upstream_branch}%{?variant_fedora} +%define pkg_release 0.%{fedora_build}%{upstream_branch_tag}%{?buildid}%{?dist} +%endif + +%if !%{debugbuildsenabled} +%define with_debug 0 +%endif + +%if !%{with_debuginfo} +%define _enable_debug_packages 0 +%endif +%define debuginfodir /usr/lib/debug + +# kernel-PAE is only built on i686. +%ifarch i686 +%define with_pae 1 +%else +%define with_pae 0 +%endif + +# if requested, only build base kernel +%if %{with_baseonly} +%define with_smp 0 +%define with_kdump 0 +%define with_debug 0 +%endif + +# if requested, only build smp kernel +%if %{with_smponly} +%define with_up 0 +%define with_kdump 0 +%define with_debug 0 +%endif + +# if requested, only build debug kernel +%if %{with_dbgonly} +%if %{debugbuildsenabled} +%define with_up 0 +%endif +%define with_smp 0 +%define with_pae 0 +%define with_xen 0 +%define with_kdump 0 +%define with_perftool 0 +%endif + +%define all_x86 i386 i686 + +%if %{with_vdso_install} +# These arches install vdso/ directories. +%define vdso_arches %{all_x86} x86_64 ppc ppc64 +%endif + +# Overrides for generic default options + +# only ppc and alphav56 need separate smp kernels +%ifnarch ppc alphaev56 +%define with_smp 0 +%endif + +%define with_kdump 0 + +# don't do debug builds on anything but i686 and x86_64 +%ifnarch i686 x86_64 +%define with_debug 0 +%endif + +# only package docs noarch +%ifnarch noarch +%define with_doc 0 +%define with_perf 0 +%endif + +# don't build noarch kernels or headers (duh) +%ifarch noarch +%define with_up 0 +%define with_headers 0 +%define all_arch_configs kernel-%{version}-*.config +%define with_firmware %{?_with_firmware: 1} %{?!_with_firmware: 0} +%endif + +# bootwrapper is only on ppc +%ifnarch ppc ppc64 +%define with_bootwrapper 0 +%endif + +# sparse blows up on ppc64 alpha and sparc64 +%ifarch ppc64 ppc alpha sparc64 +%define with_sparse 0 +%endif + +# Per-arch tweaks + +%ifarch %{all_x86} +%define asmarch x86 +%define hdrarch i386 +%define all_arch_configs kernel-%{version}-i?86*.config +%define image_install_path boot +%define kernel_image arch/x86/boot/bzImage +%endif + +%ifarch x86_64 +%define asmarch x86 +%define all_arch_configs kernel-%{version}-x86_64*.config +%define image_install_path boot +%define kernel_image arch/x86/boot/bzImage +%endif + +%ifarch ppc64 +%define asmarch powerpc +%define hdrarch powerpc +%define all_arch_configs kernel-%{version}-ppc64*.config +%define image_install_path boot +%define make_target vmlinux +%define kernel_image vmlinux +%define kernel_image_elf 1 +%endif + +%ifarch s390x +%define asmarch s390 +%define hdrarch s390 +%define all_arch_configs kernel-%{version}-s390x*.config +%define image_install_path boot +%define make_target image +%define kernel_image arch/s390/boot/image +%endif + +%ifarch sparc +# We only build sparc headers since we dont support sparc32 hardware +%endif + +%ifarch sparc64 +%define asmarch sparc +%define all_arch_configs kernel-%{version}-sparc64*.config +%define make_target image +%define kernel_image arch/sparc/boot/image +%define image_install_path boot +%define with_perftool 0 +%endif + +%ifarch ppc +%define asmarch powerpc +%define hdrarch powerpc +%define all_arch_configs kernel-%{version}-ppc{-,.}*config +%define image_install_path boot +%define make_target vmlinux +%define kernel_image vmlinux +%define kernel_image_elf 1 +%endif + +%ifarch ia64 +%define all_arch_configs kernel-%{version}-ia64*.config +%define image_install_path boot/efi/EFI/redhat +%define make_target compressed +%define kernel_image vmlinux.gz +%endif + +%ifarch alpha alphaev56 +%define all_arch_configs kernel-%{version}-alpha*.config +%define image_install_path boot +%define make_target vmlinux +%define kernel_image vmlinux +%endif + +%ifarch %{arm} +%define all_arch_configs kernel-%{version}-arm*.config +%define image_install_path boot +%define hdrarch arm +%define make_target vmlinux +%define kernel_image vmlinux +%endif + +%if %{nopatches} +# XXX temporary until last vdso patches are upstream +%define vdso_arches ppc ppc64 +%endif + +%if %{nopatches}%{using_upstream_branch} +# Ignore unknown options in our config-* files. +# Some options go with patches we're not applying. +%define oldconfig_target loose_nonint_oldconfig +%else +%define oldconfig_target nonint_oldconfig +%endif + +# To temporarily exclude an architecture from being built, add it to +# %nobuildarches. Do _NOT_ use the ExclusiveArch: line, because if we +# don't build kernel-headers then the new build system will no longer let +# us use the previous build of that package -- it'll just be completely AWOL. +# Which is a BadThing(tm). + +# We don't build a kernel on i386; we only do kernel-headers there, +# and we no longer build for 31bit s390. Same for 32bit sparc and arm. +%define nobuildarches i386 s390 sparc %{arm} + +%ifarch %nobuildarches +%define with_up 0 +%define with_smp 0 +%define with_pae 0 +%define with_kdump 0 +%define with_debuginfo 0 +%define with_perftool 0 +%define _enable_debug_packages 0 +%endif + +%define with_pae_debug 0 +%if %{with_pae} +%define with_pae_debug %{with_debug} +%endif + +# +# Three sets of minimum package version requirements in the form of Conflicts: +# to versions below the minimum +# + +# +# First the general kernel 2.6 required versions as per +# Documentation/Changes +# +%define kernel_dot_org_conflicts ppp < 2.4.3-3, isdn4k-utils < 3.2-32, nfs-utils < 1.0.7-12, e2fsprogs < 1.37-4, util-linux < 2.12, jfsutils < 1.1.7-2, reiserfs-utils < 3.6.19-2, xfsprogs < 2.6.13-4, procps < 3.2.5-6.3, oprofile < 0.9.1-2 + +# +# Then a series of requirements that are distribution specific, either +# because we add patches for something, or the older versions have +# problems with the newer kernel or lack certain things that make +# integration in the distro harder than needed. +# +%define package_conflicts initscripts < 7.23, udev < 063-6, iptables < 1.3.2-1, ipw2200-firmware < 2.4, iwl4965-firmware < 228.57.2, selinux-policy-targeted < 1.25.3-14, squashfs-tools < 4.0, wireless-tools < 29-3 + +# +# The ld.so.conf.d file we install uses syntax older ldconfig's don't grok. +# +%define kernel_xen_conflicts glibc < 2.3.5-1, xen < 3.0.1 + +%define kernel_PAE_obsoletes kernel-smp < 2.6.17, kernel-xen <= 2.6.27-0.2.rc0.git6.fc10 +%define kernel_PAE_provides kernel-xen = %{rpmversion}-%{pkg_release} + +%ifarch x86_64 +%define kernel_obsoletes kernel-xen <= 2.6.27-0.2.rc0.git6.fc10 +%define kernel_provides kernel-xen = %{rpmversion}-%{pkg_release} +%endif + +# We moved the drm include files into kernel-headers, make sure there's +# a recent enough libdrm-devel on the system that doesn't have those. +%define kernel_headers_conflicts libdrm-devel < 2.4.0-0.15 + +# +# Packages that need to be installed before the kernel is, because the %post +# scripts use them. +# +%define kernel_prereq fileutils, module-init-tools, initscripts >= 8.11.1-1, grubby >= 7.0.10-1 +%if %{with_dracut} +%define initrd_prereq dracut >= 001-7 +%else +%define initrd_prereq mkinitrd >= 6.0.61-1 +%endif + +# +# This macro does requires, provides, conflicts, obsoletes for a kernel package. +# %%kernel_reqprovconf +# It uses any kernel__conflicts and kernel__obsoletes +# macros defined above. +# +%define kernel_reqprovconf \ +Provides: kernel = %{rpmversion}-%{pkg_release}\ +Provides: kernel-%{_target_cpu} = %{rpmversion}-%{pkg_release}%{?1:.%{1}}\ +Provides: kernel-drm = 4.3.0\ +Provides: kernel-drm-nouveau = 16\ +Provides: kernel-modeset = 1\ +Provides: kernel-uname-r = %{KVERREL}%{?1:.%{1}}\ +Requires(pre): %{kernel_prereq}\ +Requires(pre): %{initrd_prereq}\ +%if %{with_firmware}\ +Requires(pre): kernel-firmware >= %{rpmversion}-%{pkg_release}\ +%else\ +Requires(pre): linux-firmware\ +%endif\ +Requires(post): /sbin/new-kernel-pkg\ +Requires(preun): /sbin/new-kernel-pkg\ +Conflicts: %{kernel_dot_org_conflicts}\ +Conflicts: %{package_conflicts}\ +%{expand:%%{?kernel%{?1:_%{1}}_conflicts:Conflicts: %%{kernel%{?1:_%{1}}_conflicts}}}\ +%{expand:%%{?kernel%{?1:_%{1}}_obsoletes:Obsoletes: %%{kernel%{?1:_%{1}}_obsoletes}}}\ +%{expand:%%{?kernel%{?1:_%{1}}_provides:Provides: %%{kernel%{?1:_%{1}}_provides}}}\ +# We can't let RPM do the dependencies automatic because it'll then pick up\ +# a correct but undesirable perl dependency from the module headers which\ +# isn't required for the kernel proper to function\ +AutoReq: no\ +AutoProv: yes\ +%{nil} + +Name: kernel%{?variant} +Group: System Environment/Kernel +License: GPLv2 +URL: http://www.kernel.org/ +Version: %{rpmversion} +Release: %{pkg_release} +# DO NOT CHANGE THE 'ExclusiveArch' LINE TO TEMPORARILY EXCLUDE AN ARCHITECTURE BUILD. +# SET %%nobuildarches (ABOVE) INSTEAD +ExclusiveArch: noarch %{all_x86} x86_64 ppc ppc64 ia64 sparc sparc64 s390 s390x alpha alphaev56 %{arm} +ExclusiveOS: Linux + +%kernel_reqprovconf +%ifarch x86_64 sparc64 +Obsoletes: kernel-smp +%endif + + +# +# List the packages used during the kernel build +# +BuildRequires: module-init-tools, patch >= 2.5.4, bash >= 2.03, sh-utils, tar +BuildRequires: bzip2, findutils, gzip, m4, perl, make >= 3.78, diffutils, gawk +BuildRequires: gcc >= 3.4.2, binutils >= 2.12, redhat-rpm-config +BuildRequires: net-tools +BuildRequires: xmlto, asciidoc +%if %{with_sparse} +BuildRequires: sparse >= 0.4.1 +%endif +%if %{with_perftool} +BuildRequires: elfutils-libelf-devel zlib-devel binutils-devel libdwarf-devel +%endif +BuildConflicts: rhbuildsys(DiskFree) < 500Mb + +%define fancy_debuginfo 0 +%if %{with_debuginfo} +%if 0%{?fedora} >= 8 || 0%{?rhel} >= 6 +%define fancy_debuginfo 1 +%endif +%endif + +%if %{fancy_debuginfo} +# Fancy new debuginfo generation introduced in Fedora 8. +BuildRequires: rpm-build >= 4.4.2.1-4 +%define debuginfo_args --strict-build-id +%endif + +Source0: ftp://ftp.kernel.org/pub/linux/kernel/v2.6/linux-%{kversion}.tar.bz2 + +Source11: genkey +Source14: find-provides +Source15: merge.pl + +Source20: Makefile.config +Source21: config-debug +Source22: config-nodebug +Source23: config-generic +Source24: config-rhel-generic + +Source30: config-x86-generic +Source31: config-i686-PAE + +Source40: config-x86_64-generic + +Source50: config-powerpc-generic +Source51: config-powerpc32-generic +Source52: config-powerpc32-smp +Source53: config-powerpc64 + +Source60: config-ia64-generic + +Source70: config-s390x + +Source90: config-sparc64-generic + +Source100: config-arm + +Source200: perf + +# Here should be only the patches up to the upstream canonical Linus tree. + +# For a stable release kernel +%if 0%{?stable_update} +%if 0%{?stable_base} +%define stable_patch_00 patch-2.6.%{base_sublevel}.%{stable_base}.bz2 +Patch00: %{stable_patch_00} +%endif +%if 0%{?stable_rc} +%define stable_patch_01 patch-2.6.%{base_sublevel}.%{stable_update}-rc%{stable_rc}.bz2 +Patch01: %{stable_patch_01} +%else +# Incremental stable update +%if %{stable_base} != %{stable_update} +%define stable_patch_01 patch-2.6.%{base_sublevel}.%{stable_base}-%{stable_update}.bz2 +Patch01: %{stable_patch_01} +%endif +%endif + +# non-released_kernel case +# These are automagically defined by the rcrev and gitrev values set up +# near the top of this spec file. +%else +%if 0%{?rcrev} +Patch00: patch-2.6.%{upstream_sublevel}-rc%{rcrev}.bz2 +%if 0%{?gitrev} +Patch01: patch-2.6.%{upstream_sublevel}-rc%{rcrev}-git%{gitrev}.bz2 +%endif +%else +# pre-{base_sublevel+1}-rc1 case +%if 0%{?gitrev} +Patch00: patch-2.6.%{base_sublevel}-git%{gitrev}.bz2 +%endif +%endif +%endif + +%if %{using_upstream_branch} +### BRANCH PATCH ### +%endif + +Patch02: git-linus.diff + +# we always need nonintconfig, even for -vanilla kernels +Patch03: linux-2.6-build-nonintconfig.patch + +# we also need compile fixes for -vanilla +Patch04: linux-2.6-compile-fixes.patch + +# build tweak for build ID magic, even for -vanilla +Patch05: linux-2.6-makefile-after_link.patch + +%if !%{nopatches} + +# revert upstream patches we get via other methods +Patch09: linux-2.6-upstream-reverts.patch +# Git trees. +Patch10: git-cpufreq.patch +Patch11: git-bluetooth.patch + +# Standalone patches +Patch20: linux-2.6-hotfixes.patch + +Patch21: linux-2.6-tracehook.patch +Patch22: linux-2.6-utrace.patch +Patch23: linux-2.6-utrace-ptrace.patch + +Patch143: linux-2.6-g5-therm-shutdown.patch +Patch144: linux-2.6-vio-modalias.patch + +Patch150: linux-2.6.29-sparc-IOC_TYPECHECK.patch + +Patch160: linux-2.6-execshield.patch + +Patch250: linux-2.6-debug-sizeof-structs.patch +Patch260: linux-2.6-debug-nmi-timeout.patch +Patch270: linux-2.6-debug-taint-vm.patch +Patch300: linux-2.6-driver-level-usb-autosuspend.diff +Patch303: linux-2.6-enable-btusb-autosuspend.patch +Patch304: linux-2.6-usb-uvc-autosuspend.diff +Patch305: linux-2.6-fix-btusb-autosuspend.patch +Patch310: linux-2.6-usb-wwan-update.patch + +Patch340: linux-2.6-debug-vm-would-have-oomkilled.patch +Patch360: linux-2.6-debug-always-inline-kzalloc.patch +Patch380: linux-2.6-defaults-pci_no_msi.patch +Patch381: linux-2.6-pciehp-update.patch +Patch382: linux-2.6-defaults-pciehp.patch +Patch383: linux-2.6-defaults-aspm.patch +Patch390: linux-2.6-defaults-acpi-video.patch +Patch391: linux-2.6-acpi-video-dos.patch +Patch392: linux-2.6-acpi-video-export-edid.patch +Patch450: linux-2.6-input-kill-stupid-messages.patch +Patch451: linux-2.6-input-fix-toshiba-hotkeys.patch +Patch452: linux-2.6.30-no-pcspkr-modalias.patch +Patch453: thinkpad-acpi-add-x100e.patch +Patch454: linux-2.6-input-hid-quirk-egalax.patch +Patch455: linux-2.6-input-clickpad-support.patch +Patch456: thinkpad-acpi-fix-backlight.patch +Patch457: ntrig-backport.patch + +Patch460: linux-2.6-serial-460800.patch + +Patch470: die-floppy-die.patch + +Patch510: linux-2.6-silence-noise.patch +Patch520: linux-2.6.30-hush-rom-warning.patch +Patch530: linux-2.6-silence-fbcon-logo.patch +Patch570: linux-2.6-selinux-mprotect-checks.patch +Patch580: linux-2.6-sparc-selinux-mprotect-checks.patch +Patch581: linux-2.6-selinux-avtab-size.patch + +Patch601: linux-2.6-acpi-indirect_fan_control.patch + +Patch610: hda_intel-prealloc-4mb-dmabuffer.patch + +Patch670: linux-2.6-ata-quirk.patch + +Patch681: linux-2.6-mac80211-age-scan-results-on-resume.patch + +Patch800: linux-2.6-crash-driver.patch + +Patch1515: lirc-2.6.33.patch +Patch1517: hdpvr-ir-enable.patch +Patch1520: crystalhd-2.6.34-staging.patch + +# virt + ksm patches +Patch1553: vhost_net-rollup.patch +Patch1554: virt_console-rollup.patch +Patch1555: virt_console-fix-race.patch +Patch1556: virt_console-fix-fix-race.patch +Patch1557: virt_console-rollup2.patch +Patch1558: vhost_net-rollup2.patch +# EC2 is running old xen hosts and wont upgrade so we have to work around it +Patch1559: fix_xen_guest_on_old_EC2.patch + +# fbdev x86-64 primary fix +Patch1700: linux-2.6-x86-64-fbdev-primary.patch + +Patch1800: drm-core-next.patch +# fix modeline for 1024x768@85 +Patch1801: drm-1024x768-85.patch + +# radeon kms backport +Patch1808: drm-radeon-evergreen.patch +Patch1809: drm-radeon-firemv-pciid.patch +Patch1810: drm-radeon-kms-fix-dual-link-dvi.patch +Patch1811: drm-radeon-fix-rs600-tlb.patch +Patch1812: drm-radeon-ss-fix.patch +# nouveau fixes +# - these not until 2.6.34 +Patch1815: drm-nouveau-abi16.patch +Patch1816: drm-nouveau-updates.patch +# requires code that hasn't been merged upstream yet +Patch1817: drm-nouveau-acpi-edid-fallback.patch +Patch1818: drm-nouveau-drm-fixed-header.patch + +# drm fixes +Patch1819: drm-intel-big-hammer.patch +# intel drm is all merged upstream +Patch1824: drm-intel-next.patch +# make sure the lvds comes back on lid open +Patch1825: drm-intel-make-lvds-work.patch +# disable iommu for gfx by default, just too broken +Patch1827: linux-2.6-intel-iommu-igfx.patch +# posted for upstream but not in an anholt tree yet +Patch1828: drm-intel-gen5-dither.patch +# thanks for the untested sdvo rework guys +Patch1829: drm-intel-sdvo-fix.patch +Patch1830: drm-intel-sdvo-fix-2.patch +# from 2.6.33.5 +Patch1840: drm-i915-use-pipe_control-instruction-on-ironlake-and-sandy-bridge.patch +Patch1841: drm-i915-fix-non-ironlake-965-class-crashes.patch +Patch1842: drm-i915-fix-edp-panels.patch + +Patch2100: linux-2.6-phylib-autoload.patch + +# linux1394 git patches +Patch2200: linux-2.6-firewire-git-update.patch +Patch2201: linux-2.6-firewire-git-pending.patch + +# Quiet boot fixes +# silence the ACPI blacklist code +Patch2802: linux-2.6-silence-acpi-blacklist.patch + +# Upstream V4L updates +Patch2899: linux-2.6-v4l-dvb-fixes.patch +Patch2900: linux-2.6-v4l-dvb-update.patch +Patch2901: linux-2.6-v4l-dvb-experimental.patch + +# Rebase gspca to what will be in 2.6.34 +Patch2904: linux-2.6-v4l-dvb-rebase-gspca-to-latest.patch +# Some cherry picked fixes from v4l-dvb-next +Patch2905: linux-2.6-v4l-dvb-gspca-fixes.patch + +# kworld ub435-q/340u usb atsc tuner support (still lingering +# in one of mkrufky's trees, pending push to v4l-dvb proper) +Patch2906: linux-2.6-v4l-dvb-add-lgdt3304-support.patch +Patch2907: linux-2.6-v4l-dvb-add-kworld-a340-support.patch + +# fs fixes +Patch3000: linux-2.6-btrfs-update.patch +Patch3002: btrfs-prohibit-a-operation-of-changing-acls-mask-when-noacl-mount-option-is-used.patch + +# NFSv4 +Patch3051: linux-2.6-nfs4-callback-hidden.patch + +Patch4000: linux-2.6-cpufreq-locking.patch + +# VIA Nano / VX8xx updates + +# patches headed upstream +Patch12010: linux-2.6-dell-laptop-rfkill-fix.patch +Patch12013: linux-2.6-rfkill-all.patch +Patch12014: linux-2.6-x86-cfi_sections.patch + +Patch12015: add-appleir-driver.patch + +Patch12017: prevent-runtime-conntrack-changes.patch + +Patch12018: neuter_intel_microcode_load.patch + +Patch12019: linux-2.6-umh-refactor.patch + +# make p54pci usable on slower hardware +Patch12103: linux-2.6-p54pci.patch + +Patch12200: acpi-ec-add-delay-before-write.patch + +# patches from Intel to address intermittent firmware failures with iwlagn +Patch12404: iwlwifi_-add-function-to-reset_tune-radio-if-needed.patch +Patch12405: iwlwifi_-Logic-to-control-how-frequent-radio-should-be-reset-if-needed.patch +Patch12406: iwlwifi_-Tune-radio-to-prevent-unexpected-behavior.patch +Patch12407: iwlwifi_-multiple-force-reset-mode.patch +Patch12409: iwlwifi_-Adjusting-PLCP-error-threshold-for-1000-NIC.patch +Patch12410: iwlwifi_-separated-time-check-for-different-type-of-force-reset.patch +Patch12411: iwlwifi_-add-internal-short-scan-support-for-3945.patch +Patch12412: iwlwifi_-Recover-TX-flow-stall-due-to-stuck-queue.patch +Patch12413: iwlwifi_-move-plcp-check-to-separated-function.patch +Patch12414: iwlwifi_-Recover-TX-flow-failure.patch +Patch12415: iwlwifi_-code-cleanup-for-connectivity-recovery.patch +Patch12416: iwlwifi_-iwl_good_ack_health-only-apply-to-AGN-device.patch + +Patch12500: alsa-usbmixer-add-possibility-to-remap-dB-values.patch + +# fix possible corruption with ssd +Patch12700: ext4-issue-discard-operation-before-releasing-blocks.patch + +Patch12820: ibmvscsi-fix-DMA-API-misuse.patch + +Patch12830: disable-i8042-check-on-apple-mac.patch + +Patch12850: crypto-aesni-kill-module_alias.patch + +# automatically mount debugfs when perf needs it +Patch12851: perf-mount-debugfs-automatically.patch + +# iwlwifi: fix scan races +Patch12910: iwlwifi-fix-scan-races.patch +# iwlwifi: fix internal scan race +Patch12911: iwlwifi-fix-internal-scan-race.patch +# iwlwifi: recover_from_tx_stall +Patch12912: iwlwifi-recover_from_tx_stall.patch + +Patch12913: iwlwifi-manage-QoS-by-mac-stack.patch +Patch12915: mac80211-explicitly-disable-enable-QoS.patch + +# Disable rt20xx and rt35xx chipset support in rt2800pci and rt2800usb +Patch13010: rt2x00-rt2800-Make-rt30xx-and-rt35xx-chipsets-configurable.patch + +Patch13074: inotify-fix-inotify-oneshot-support.patch +Patch13076: inotify-send-IN_UNMOUNT-events.patch + +Patch13080: kvm-mmu-fix-conflict-access-permissions-in-direct-sp.patch + +Patch13090: mm-fix-page-table-unmap-for-stack-guard-page-properly.patch +Patch13091: mm-fix-up-some-user-visible-effects-of-the-stack-guard-page.patch + +%endif + +BuildRoot: %{_tmppath}/kernel-%{KVERREL}-root + +%description +The kernel package contains the Linux kernel (vmlinuz), the core of any +Linux operating system. The kernel handles the basic functions +of the operating system: memory allocation, process allocation, device +input and output, etc. + + +%package doc +Summary: Various documentation bits found in the kernel source +Group: Documentation +%description doc +This package contains documentation files from the kernel +source. Various bits of information about the Linux kernel and the +device drivers shipped with it are documented in these files. + +You'll want to install this package if you need a reference to the +options that can be passed to Linux kernel modules at load time. + + +%package headers +Summary: Header files for the Linux kernel for use by glibc +Group: Development/System +Obsoletes: glibc-kernheaders +Provides: glibc-kernheaders = 3.0-46 +%description headers +Kernel-headers includes the C header files that specify the interface +between the Linux kernel and userspace libraries and programs. The +header files define structures and constants that are needed for +building most standard programs and are also needed for rebuilding the +glibc package. + +%package firmware +Summary: Firmware files used by the Linux kernel +Group: Development/System +# This is... complicated. +# Look at the WHENCE file. +License: GPL+ and GPLv2+ and MIT and Redistributable, no modification permitted +%if "x%{?variant}" != "x" +Provides: kernel-firmware = %{rpmversion}-%{pkg_release} +%endif +%description firmware +Kernel-firmware includes firmware files required for some devices to +operate. + +%package bootwrapper +Summary: Boot wrapper files for generating combined kernel + initrd images +Group: Development/System +Requires: gzip +%description bootwrapper +Kernel-bootwrapper contains the wrapper code which makes bootable "zImage" +files combining both kernel and initial ramdisk. + +%package debuginfo-common-%{_target_cpu} +Summary: Kernel source files used by %{name}-debuginfo packages +Group: Development/Debug +%description debuginfo-common-%{_target_cpu} +This package is required by %{name}-debuginfo subpackages. +It provides the kernel source files common to all builds. + +%package -n perf +Summary: Performance monitoring for the Linux kernel +Group: Development/System +License: GPLv2 +Requires: libdwarf +%description -n perf +This package provides the perf shell script, supporting documentation and +required libraries for the perf tool shipped in each kernel image subpackage. + +# +# This macro creates a kernel--debuginfo package. +# %%kernel_debuginfo_package +# +%define kernel_debuginfo_package() \ +%package %{?1:%{1}-}debuginfo\ +Summary: Debug information for package %{name}%{?1:-%{1}}\ +Group: Development/Debug\ +Requires: %{name}-debuginfo-common-%{_target_cpu} = %{version}-%{release}\ +Provides: %{name}%{?1:-%{1}}-debuginfo-%{_target_cpu} = %{version}-%{release}\ +AutoReqProv: no\ +%description -n %{name}%{?1:-%{1}}-debuginfo\ +This package provides debug information for package %{name}%{?1:-%{1}}.\ +This is required to use SystemTap with %{name}%{?1:-%{1}}-%{KVERREL}.\ +%{expand:%%global debuginfo_args %{?debuginfo_args} -p '/.*/%%{KVERREL}%{?1:\.%{1}}/.*|/.*%%{KVERREL}%{?1:\.%{1}}(\.debug)?' -o debuginfo%{?1}.list}\ +%{nil} + +# +# This macro creates a kernel--devel package. +# %%kernel_devel_package +# +%define kernel_devel_package() \ +%package %{?1:%{1}-}devel\ +Summary: Development package for building kernel modules to match the %{?2:%{2} }kernel\ +Group: System Environment/Kernel\ +Provides: kernel%{?1:-%{1}}-devel-%{_target_cpu} = %{version}-%{release}\ +Provides: kernel-devel-%{_target_cpu} = %{version}-%{release}%{?1:.%{1}}\ +Provides: kernel-devel = %{version}-%{release}%{?1:.%{1}}\ +Provides: kernel-devel-uname-r = %{KVERREL}%{?1:.%{1}}\ +AutoReqProv: no\ +Requires(pre): /usr/bin/find\ +%description -n kernel%{?variant}%{?1:-%{1}}-devel\ +This package provides kernel headers and makefiles sufficient to build modules\ +against the %{?2:%{2} }kernel package.\ +%{nil} + +# +# This macro creates a kernel- and its -devel and -debuginfo too. +# %%define variant_summary The Linux kernel compiled for +# %%kernel_variant_package [-n ] +# +%define kernel_variant_package(n:) \ +%package %1\ +Summary: %{variant_summary}\ +Group: System Environment/Kernel\ +%kernel_reqprovconf\ +%{expand:%%kernel_devel_package %1 %{!?-n:%1}%{?-n:%{-n*}}}\ +%{expand:%%kernel_debuginfo_package %1}\ +%{nil} + + +# First the auxiliary packages of the main kernel package. +%kernel_devel_package +%kernel_debuginfo_package + + +# Now, each variant package. + +%define variant_summary The Linux kernel compiled for SMP machines +%kernel_variant_package -n SMP smp +%description smp +This package includes a SMP version of the Linux kernel. It is +required only on machines with two or more CPUs as well as machines with +hyperthreading technology. + +Install the kernel-smp package if your machine uses two or more CPUs. + + +%define variant_summary The Linux kernel compiled for PAE capable machines +%kernel_variant_package PAE +%description PAE +This package includes a version of the Linux kernel with support for up to +64GB of high memory. It requires a CPU with Physical Address Extensions (PAE). +The non-PAE kernel can only address up to 4GB of memory. +Install the kernel-PAE package if your machine has more than 4GB of memory. + + +%define variant_summary The Linux kernel compiled with extra debugging enabled for PAE capable machines +%kernel_variant_package PAEdebug +Obsoletes: kernel-PAE-debug +%description PAEdebug +This package includes a version of the Linux kernel with support for up to +64GB of high memory. It requires a CPU with Physical Address Extensions (PAE). +The non-PAE kernel can only address up to 4GB of memory. +Install the kernel-PAE package if your machine has more than 4GB of memory. + +This variant of the kernel has numerous debugging options enabled. +It should only be installed when trying to gather additional information +on kernel bugs, as some of these options impact performance noticably. + + +%define variant_summary The Linux kernel compiled with extra debugging enabled +%kernel_variant_package debug +%description debug +The kernel package contains the Linux kernel (vmlinuz), the core of any +Linux operating system. The kernel handles the basic functions +of the operating system: memory allocation, process allocation, device +input and output, etc. + +This variant of the kernel has numerous debugging options enabled. +It should only be installed when trying to gather additional information +on kernel bugs, as some of these options impact performance noticably. + + +%define variant_summary A minimal Linux kernel compiled for crash dumps +%kernel_variant_package kdump +%description kdump +This package includes a kdump version of the Linux kernel. It is +required only on machines which will use the kexec-based kernel crash dump +mechanism. + + +%prep +# do a few sanity-checks for --with *only builds +%if %{with_baseonly} +%if !%{with_up}%{with_pae} +echo "Cannot build --with baseonly, up build is disabled" +exit 1 +%endif +%endif + +%if %{with_smponly} +%if !%{with_smp} +echo "Cannot build --with smponly, smp build is disabled" +exit 1 +%endif +%endif + +# more sanity checking; do it quietly +if [ "%{patches}" != "%%{patches}" ] ; then + for patch in %{patches} ; do + if [ ! -f $patch ] ; then + echo "ERROR: Patch ${patch##/*/} listed in specfile but is missing" + exit 1 + fi + done +fi 2>/dev/null + +patch_command='patch -p1 -F1 -s' +ApplyPatch() +{ + local patch=$1 + shift + if [ ! -f $RPM_SOURCE_DIR/$patch ]; then + exit 1 + fi +%if !%{using_upstream_branch} + if ! egrep "^Patch[0-9]+: $patch\$" %{_specdir}/${RPM_PACKAGE_NAME%%%%%{?variant}}.spec ; then + if [ "${patch:0:10}" != "patch-2.6." ] ; then + echo "ERROR: Patch $patch not listed as a source patch in specfile" + exit 1 + fi + fi 2>/dev/null +%endif + case "$patch" in + *.bz2) bunzip2 < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;; + *.gz) gunzip < "$RPM_SOURCE_DIR/$patch" | $patch_command ${1+"$@"} ;; + *) $patch_command ${1+"$@"} < "$RPM_SOURCE_DIR/$patch" ;; + esac +} + +# don't apply patch if it's empty +ApplyOptionalPatch() +{ + local patch=$1 + shift + if [ ! -f $RPM_SOURCE_DIR/$patch ]; then + exit 1 + fi + local C=$(wc -l $RPM_SOURCE_DIR/$patch | awk '{print $1}') + if [ "$C" -gt 9 ]; then + ApplyPatch $patch ${1+"$@"} + fi +} + +# we don't want a .config file when building firmware: it just confuses the build system +%define build_firmware \ + mv .config .config.firmware_save \ + make INSTALL_FW_PATH=$RPM_BUILD_ROOT/lib/firmware firmware_install \ + mv .config.firmware_save .config + +# First we unpack the kernel tarball. +# If this isn't the first make prep, we use links to the existing clean tarball +# which speeds things up quite a bit. + +# Update to latest upstream. +%if 0%{?released_kernel} +%define vanillaversion 2.6.%{base_sublevel} +# non-released_kernel case +%else +%if 0%{?rcrev} +%define vanillaversion 2.6.%{upstream_sublevel}-rc%{rcrev} +%if 0%{?gitrev} +%define vanillaversion 2.6.%{upstream_sublevel}-rc%{rcrev}-git%{gitrev} +%endif +%else +# pre-{base_sublevel+1}-rc1 case +%if 0%{?gitrev} +%define vanillaversion 2.6.%{base_sublevel}-git%{gitrev} +%else +%define vanillaversion 2.6.%{base_sublevel} +%endif +%endif +%endif + +# %{vanillaversion} : the full version name, e.g. 2.6.35-rc6-git3 +# %{kversion} : the base version, e.g. 2.6.34 + +# Use kernel-%{kversion}%{?dist} as the top-level directory name +# so we can prep different trees within a single git directory. + +# Build a list of the other top-level kernel tree directories. +# This will be used to hardlink identical vanilla subdirs. +sharedirs=$(find "$PWD" -maxdepth 1 -type d -name 'kernel-2.6.*' \ + | grep -x -v "$PWD"/kernel-%{kversion}%{?dist}) ||: + +if [ ! -d kernel-%{kversion}%{?dist}/vanilla-%{vanillaversion} ]; then + + if [ -d kernel-%{kversion}%{?dist}/vanilla-%{kversion} ]; then + + # The base vanilla version already exists. + cd kernel-%{kversion}%{?dist} + + # Any vanilla-* directories other than the base one are stale. + for dir in vanilla-*; do + [ "$dir" = vanilla-%{kversion} ] || rm -rf $dir & + done + + else + + rm -f pax_global_header + # Look for an identical base vanilla dir that can be hardlinked. + for sharedir in $sharedirs ; do + if [[ ! -z $sharedir && -d $sharedir/vanilla-%{kversion} ]] ; then + break + fi + done + if [[ ! -z $sharedir && -d $sharedir/vanilla-%{kversion} ]] ; then +%setup -q -n kernel-%{kversion}%{?dist} -c -T + cp -rl $sharedir/vanilla-%{kversion} . + else +%setup -q -n kernel-%{kversion}%{?dist} -c + mv linux-%{kversion} vanilla-%{kversion} + fi + + fi + +%if "%{kversion}" != "%{vanillaversion}" + + for sharedir in $sharedirs ; do + if [[ ! -z $sharedir && -d $sharedir/vanilla-%{vanillaversion} ]] ; then + break + fi + done + if [[ ! -z $sharedir && -d $sharedir/vanilla-%{vanillaversion} ]] ; then + + cp -rl $sharedir/vanilla-%{vanillaversion} . + + else + + # Need to apply patches to the base vanilla version. + cp -rl vanilla-%{kversion} vanilla-%{vanillaversion} + cd vanilla-%{vanillaversion} + +# Update vanilla to the latest upstream. +# (non-released_kernel case only) +%if 0%{?rcrev} + ApplyPatch patch-2.6.%{upstream_sublevel}-rc%{rcrev}.bz2 +%if 0%{?gitrev} + ApplyPatch patch-2.6.%{upstream_sublevel}-rc%{rcrev}-git%{gitrev}.bz2 +%endif +%else +# pre-{base_sublevel+1}-rc1 case +%if 0%{?gitrev} + ApplyPatch patch-2.6.%{base_sublevel}-git%{gitrev}.bz2 +%endif +%endif + + cd .. + + fi + +%endif + +else + + # We already have all vanilla dirs, just change to the top-level directory. + cd kernel-%{kversion}%{?dist} + +fi + +# Now build the fedora kernel tree. +if [ -d linux-%{kversion}.%{_target_cpu} ]; then + # Just in case we ctrl-c'd a prep already + rm -rf deleteme.%{_target_cpu} + # Move away the stale away, and delete in background. + mv linux-%{kversion}.%{_target_cpu} deleteme.%{_target_cpu} + rm -rf deleteme.%{_target_cpu} & +fi + +cp -rl vanilla-%{vanillaversion} linux-%{kversion}.%{_target_cpu} + +cd linux-%{kversion}.%{_target_cpu} + +# released_kernel with possible stable updates +%if 0%{?stable_base} +ApplyPatch %{stable_patch_00} +%endif +%if 0%{?stable_rc} +ApplyPatch %{stable_patch_01} +%else +# Incremental update, not an -rc +%if %{stable_base} != %{stable_update} +ApplyPatch %{stable_patch_01} +%endif +%endif + +%if %{using_upstream_branch} +### BRANCH APPLY ### +%endif + +# Drop some necessary files from the source dir into the buildroot +cp $RPM_SOURCE_DIR/config-* . +cp %{SOURCE15} . + +# Dynamically generate kernel .config files from config-* files +make -f %{SOURCE20} VERSION=%{version} configs + +#if a rhel kernel, apply the rhel config options +%if 0%{?rhel} + for i in %{all_arch_configs} + do + mv $i $i.tmp + ./merge.pl config-rhel-generic $i.tmp > $i + rm $i.tmp + done +%endif + +ApplyOptionalPatch git-linus.diff + +# This patch adds a "make nonint_oldconfig" which is non-interactive and +# also gives a list of missing options at the end. Useful for automated +# builds (as used in the buildsystem). +ApplyPatch linux-2.6-build-nonintconfig.patch + +ApplyPatch linux-2.6-makefile-after_link.patch + +# +# misc small stuff to make things compile +# +ApplyOptionalPatch linux-2.6-compile-fixes.patch + +%if !%{nopatches} + +# revert patches from upstream that conflict or that we get via other means +ApplyOptionalPatch linux-2.6-upstream-reverts.patch -R + +#ApplyPatch git-cpufreq.patch +ApplyPatch git-bluetooth.patch + +ApplyPatch linux-2.6-hotfixes.patch + +# Roland's utrace ptrace replacement. +ApplyPatch linux-2.6-tracehook.patch +ApplyPatch linux-2.6-utrace.patch +ApplyPatch linux-2.6-utrace-ptrace.patch + +# Architecture patches +# x86(-64) +ApplyPatch linux-2.6-dell-laptop-rfkill-fix.patch +ApplyPatch linux-2.6-x86-cfi_sections.patch + +# +# Intel IOMMU +# + +# +# PowerPC +# +### NOT (YET) UPSTREAM: +# Alleviate G5 thermal shutdown problems +ApplyPatch linux-2.6-g5-therm-shutdown.patch +# Provide modalias in sysfs for vio devices +ApplyPatch linux-2.6-vio-modalias.patch + +# +# SPARC64 +# +ApplyPatch linux-2.6.29-sparc-IOC_TYPECHECK.patch + +# +# Exec shield +# +ApplyPatch linux-2.6-execshield.patch + +# +# bugfixes to drivers and filesystems +# + +# ext4 + +# xfs + +# btrfs +ApplyPatch linux-2.6-btrfs-update.patch + +ApplyPatch btrfs-prohibit-a-operation-of-changing-acls-mask-when-noacl-mount-option-is-used.patch + +# eCryptfs + +# NFSv4 +ApplyPatch linux-2.6-nfs4-callback-hidden.patch + +# CPUFREQ +ApplyPatch linux-2.6-cpufreq-locking.patch + +# USB +ApplyPatch linux-2.6-driver-level-usb-autosuspend.diff +ApplyPatch linux-2.6-enable-btusb-autosuspend.patch +ApplyPatch linux-2.6-usb-uvc-autosuspend.diff +#ApplyPatch linux-2.6-fix-btusb-autosuspend.patch +ApplyPatch linux-2.6-usb-wwan-update.patch + +# WMI + +# ACPI +ApplyPatch linux-2.6-defaults-acpi-video.patch +ApplyPatch linux-2.6-acpi-video-dos.patch +ApplyPatch linux-2.6-acpi-video-export-edid.patch + +ApplyPatch acpi-ec-add-delay-before-write.patch + +# Various low-impact patches to aid debugging. +ApplyPatch linux-2.6-debug-sizeof-structs.patch +ApplyPatch linux-2.6-debug-nmi-timeout.patch +ApplyPatch linux-2.6-debug-taint-vm.patch +ApplyPatch linux-2.6-debug-vm-would-have-oomkilled.patch +ApplyPatch linux-2.6-debug-always-inline-kzalloc.patch + +# +# PCI +# +# disable message signaled interrupts +ApplyPatch linux-2.6-defaults-pci_no_msi.patch +# update the pciehp driver +#ApplyPatch linux-2.6-pciehp-update.patch +# default to enabling passively listening for hotplug events +#ApplyPatch linux-2.6-defaults-pciehp.patch +# enable ASPM by default on hardware we expect to work +ApplyPatch linux-2.6-defaults-aspm.patch + +# +# SCSI Bits. +# + +# ACPI +ApplyPatch linux-2.6-acpi-indirect_fan_control.patch + +# ALSA +ApplyPatch hda_intel-prealloc-4mb-dmabuffer.patch + +# Networking + +# Misc fixes +# The input layer spews crap no-one cares about. +ApplyPatch linux-2.6-input-kill-stupid-messages.patch + +# stop floppy.ko from autoloading during udev... +ApplyPatch die-floppy-die.patch + +# Get away from having to poll Toshibas +#ApplyPatch linux-2.6-input-fix-toshiba-hotkeys.patch + +ApplyPatch linux-2.6.30-no-pcspkr-modalias.patch + +ApplyPatch linux-2.6-input-hid-quirk-egalax.patch +ApplyPatch linux-2.6-input-clickpad-support.patch +ApplyPatch thinkpad-acpi-add-x100e.patch +ApplyPatch thinkpad-acpi-fix-backlight.patch +ApplyPatch ntrig-backport.patch + +# Allow to use 480600 baud on 16C950 UARTs +ApplyPatch linux-2.6-serial-460800.patch + +# Silence some useless messages that still get printed with 'quiet' +ApplyPatch linux-2.6-silence-noise.patch +ApplyPatch linux-2.6.30-hush-rom-warning.patch + +# Make fbcon not show the penguins with 'quiet' +ApplyPatch linux-2.6-silence-fbcon-logo.patch + +# Fix the SELinux mprotect checks on executable mappings +#ApplyPatch linux-2.6-selinux-mprotect-checks.patch +# Fix SELinux for sparc +#ApplyPatch linux-2.6-sparc-selinux-mprotect-checks.patch +# Shirk size of memory allocation required to load policy. In 2.6.34 +ApplyPatch linux-2.6-selinux-avtab-size.patch + +# Changes to upstream defaults. + + +# ia64 ata quirk +ApplyPatch linux-2.6-ata-quirk.patch + +# back-port scan result aging patches +#ApplyPatch linux-2.6-mac80211-age-scan-results-on-resume.patch + +# /dev/crash driver. +ApplyPatch linux-2.6-crash-driver.patch + +# http://www.lirc.org/ +ApplyPatch lirc-2.6.33.patch +# enable IR receiver on Hauppauge HD PVR (v4l-dvb merge pending) +ApplyPatch hdpvr-ir-enable.patch +# Broadcom Crystal HD video decoder +ApplyPatch crystalhd-2.6.34-staging.patch + +# Assorted Virt Fixes +ApplyPatch vhost_net-rollup.patch +ApplyPatch virt_console-rollup.patch +ApplyPatch virt_console-fix-race.patch +ApplyPatch virt_console-fix-fix-race.patch +ApplyPatch virt_console-rollup2.patch +ApplyPatch vhost_net-rollup2.patch +ApplyPatch fix_xen_guest_on_old_EC2.patch + +# fix x86-64 fbdev primary GPU selection +ApplyPatch linux-2.6-x86-64-fbdev-primary.patch + +ApplyPatch drm-core-next.patch +ApplyPatch drm-1024x768-85.patch + +# Nouveau DRM + drm fixes +ApplyPatch drm-radeon-evergreen.patch +ApplyPatch drm-radeon-firemv-pciid.patch +ApplyPatch drm-radeon-kms-fix-dual-link-dvi.patch +ApplyPatch drm-radeon-fix-rs600-tlb.patch +ApplyPatch drm-radeon-ss-fix.patch +ApplyPatch drm-nouveau-abi16.patch +ApplyPatch drm-nouveau-updates.patch +ApplyPatch drm-nouveau-acpi-edid-fallback.patch +ApplyPatch drm-nouveau-drm-fixed-header.patch +# pm broken on my thinkpad t60p - airlied +ApplyPatch drm-intel-big-hammer.patch +ApplyOptionalPatch drm-intel-next.patch +ApplyPatch drm-intel-make-lvds-work.patch +ApplyPatch linux-2.6-intel-iommu-igfx.patch +ApplyPatch drm-intel-gen5-dither.patch +ApplyPatch drm-intel-sdvo-fix.patch +ApplyPatch drm-intel-sdvo-fix-2.patch +# from 2.6.33.5 +ApplyPatch drm-i915-use-pipe_control-instruction-on-ironlake-and-sandy-bridge.patch +ApplyPatch drm-i915-fix-non-ironlake-965-class-crashes.patch +ApplyPatch drm-i915-fix-edp-panels.patch + +ApplyPatch linux-2.6-phylib-autoload.patch + +# linux1394 git patches +#ApplyPatch linux-2.6-firewire-git-update.patch +#ApplyOptionalPatch linux-2.6-firewire-git-pending.patch + +# silence the ACPI blacklist code +ApplyPatch linux-2.6-silence-acpi-blacklist.patch + +# V4L/DVB updates/fixes/experimental drivers +# Upstream trees, applied only if non-empty +ApplyOptionalPatch linux-2.6-v4l-dvb-fixes.patch +ApplyOptionalPatch linux-2.6-v4l-dvb-update.patch +ApplyOptionalPatch linux-2.6-v4l-dvb-experimental.patch + +ApplyPatch linux-2.6-v4l-dvb-rebase-gspca-to-latest.patch +ApplyPatch linux-2.6-v4l-dvb-gspca-fixes.patch + +ApplyPatch linux-2.6-v4l-dvb-add-lgdt3304-support.patch +ApplyPatch linux-2.6-v4l-dvb-add-kworld-a340-support.patch + +# Patches headed upstream +ApplyPatch linux-2.6-rfkill-all.patch + +# appleir remote controller +ApplyPatch add-appleir-driver.patch + +ApplyPatch neuter_intel_microcode_load.patch + +# Refactor UserModeHelper code & satisfy abrt recursion check request +ApplyPatch linux-2.6-umh-refactor.patch + +ApplyPatch alsa-usbmixer-add-possibility-to-remap-dB-values.patch + +# make p54pci usable on slower hardware +ApplyPatch linux-2.6-p54pci.patch + +# patches from Intel to address intermittent firmware failures with iwlagn +ApplyPatch iwlwifi_-add-function-to-reset_tune-radio-if-needed.patch +ApplyPatch iwlwifi_-Logic-to-control-how-frequent-radio-should-be-reset-if-needed.patch +ApplyPatch iwlwifi_-Tune-radio-to-prevent-unexpected-behavior.patch +ApplyPatch iwlwifi_-multiple-force-reset-mode.patch +ApplyPatch iwlwifi_-Adjusting-PLCP-error-threshold-for-1000-NIC.patch +ApplyPatch iwlwifi_-separated-time-check-for-different-type-of-force-reset.patch +ApplyPatch iwlwifi_-add-internal-short-scan-support-for-3945.patch +ApplyPatch iwlwifi_-Recover-TX-flow-stall-due-to-stuck-queue.patch +ApplyPatch iwlwifi_-move-plcp-check-to-separated-function.patch +ApplyPatch iwlwifi_-Recover-TX-flow-failure.patch +ApplyPatch iwlwifi_-code-cleanup-for-connectivity-recovery.patch +ApplyPatch iwlwifi_-iwl_good_ack_health-only-apply-to-AGN-device.patch + +# fix possible corruption with ssd +ApplyPatch ext4-issue-discard-operation-before-releasing-blocks.patch + +ApplyPatch ibmvscsi-fix-DMA-API-misuse.patch + +ApplyPatch disable-i8042-check-on-apple-mac.patch + +ApplyPatch crypto-aesni-kill-module_alias.patch + +# automagically mount debugfs for perf +ApplyPatch perf-mount-debugfs-automatically.patch + +# iwlwifi: fix scan races +ApplyPatch iwlwifi-fix-scan-races.patch +# iwlwifi: fix internal scan race +ApplyPatch iwlwifi-fix-internal-scan-race.patch +# iwlwifi: recover_from_tx_stall +ApplyPatch iwlwifi-recover_from_tx_stall.patch + +# mac80211/iwlwifi fix connections to some APs (rhbz#558002) +ApplyPatch mac80211-explicitly-disable-enable-QoS.patch +ApplyPatch iwlwifi-manage-QoS-by-mac-stack.patch + +# Disable rt20xx and rt35xx chipset support in rt2800pci and rt2800usb +ApplyPatch rt2x00-rt2800-Make-rt30xx-and-rt35xx-chipsets-configurable.patch + +# fix broken oneshot support and missing umount events (#607327) +ApplyPatch inotify-fix-inotify-oneshot-support.patch +ApplyPatch inotify-send-IN_UNMOUNT-events.patch + +# RHBZ#610911 +ApplyPatch kvm-mmu-fix-conflict-access-permissions-in-direct-sp.patch + +# fix fallout from stack guard page fixes +ApplyPatch mm-fix-page-table-unmap-for-stack-guard-page-properly.patch +ApplyPatch mm-fix-up-some-user-visible-effects-of-the-stack-guard-page.patch + +# END OF PATCH APPLICATIONS + +%endif + +# Any further pre-build tree manipulations happen here. + +chmod +x scripts/checkpatch.pl + +# only deal with configs if we are going to build for the arch +%ifnarch %nobuildarches + +mkdir configs + +# Remove configs not for the buildarch +for cfg in kernel-%{version}-*.config; do + if [ `echo %{all_arch_configs} | grep -c $cfg` -eq 0 ]; then + rm -f $cfg + fi +done + +%if !%{debugbuildsenabled} +rm -f kernel-%{version}-*debug.config +%endif + +# now run oldconfig over all the config files +for i in *.config +do + mv $i .config + Arch=`head -1 .config | cut -b 3-` + make ARCH=$Arch %{oldconfig_target} > /dev/null + echo "# $Arch" > configs/$i + cat .config >> configs/$i +done +# end of kernel config +%endif + +# get rid of unwanted files resulting from patch fuzz +find . \( -name "*.orig" -o -name "*~" \) -exec rm -f {} \; >/dev/null + +cd .. + +### +### build +### +%build + +%if %{with_sparse} +%define sparse_mflags C=1 +%endif + +%if %{fancy_debuginfo} +# This override tweaks the kernel makefiles so that we run debugedit on an +# object before embedding it. When we later run find-debuginfo.sh, it will +# run debugedit again. The edits it does change the build ID bits embedded +# in the stripped object, but repeating debugedit is a no-op. We do it +# beforehand to get the proper final build ID bits into the embedded image. +# This affects the vDSO images in vmlinux, and the vmlinux image in bzImage. +export AFTER_LINK=\ +'sh -xc "/usr/lib/rpm/debugedit -b $$RPM_BUILD_DIR -d /usr/src/debug \ + -i $@ > $@.id"' +%endif + +cp_vmlinux() +{ + eu-strip --remove-comment -o "$2" "$1" +} + +BuildKernel() { + MakeTarget=$1 + KernelImage=$2 + Flavour=$3 + InstallName=${4:-vmlinuz} + + # Pick the right config file for the kernel we're building + Config=kernel-%{version}-%{_target_cpu}${Flavour:+-${Flavour}}.config + DevelDir=/usr/src/kernels/%{KVERREL}${Flavour:+.${Flavour}} + + # When the bootable image is just the ELF kernel, strip it. + # We already copy the unstripped file into the debuginfo package. + if [ "$KernelImage" = vmlinux ]; then + CopyKernel=cp_vmlinux + else + CopyKernel=cp + fi + + KernelVer=%{version}-%{release}.%{_target_cpu}${Flavour:+.${Flavour}} + echo BUILDING A KERNEL FOR ${Flavour} %{_target_cpu}... + + # make sure EXTRAVERSION says what we want it to say + perl -p -i -e "s/^EXTRAVERSION.*/EXTRAVERSION = %{?stablerev}-%{release}.%{_target_cpu}${Flavour:+.${Flavour}}/" Makefile + + # if pre-rc1 devel kernel, must fix up SUBLEVEL for our versioning scheme + %if !0%{?rcrev} + %if 0%{?gitrev} + perl -p -i -e 's/^SUBLEVEL.*/SUBLEVEL = %{upstream_sublevel}/' Makefile + %endif + %endif + + # and now to start the build process + + make -s mrproper + cp configs/$Config .config + + Arch=`head -1 .config | cut -b 3-` + echo USING ARCH=$Arch + + make -s ARCH=$Arch %{oldconfig_target} > /dev/null + make -s ARCH=$Arch V=1 %{?_smp_mflags} $MakeTarget %{?sparse_mflags} + make -s ARCH=$Arch V=1 %{?_smp_mflags} modules %{?sparse_mflags} || exit 1 + +%if %{with_perftool} + pushd tools/perf +# make sure the scripts are executable... won't be in tarball until 2.6.31 :/ + chmod +x util/generate-cmdlist.sh util/PERF-VERSION-GEN + make -s V=1 NO_DEMANGLE=1 %{?_smp_mflags} perf + mkdir -p $RPM_BUILD_ROOT/usr/libexec/ + install -m 755 perf $RPM_BUILD_ROOT/usr/libexec/perf.$KernelVer + popd +%endif + + # Start installing the results +%if %{with_debuginfo} + mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/boot + mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/%{image_install_path} +%endif + mkdir -p $RPM_BUILD_ROOT/%{image_install_path} + install -m 644 .config $RPM_BUILD_ROOT/boot/config-$KernelVer + install -m 644 System.map $RPM_BUILD_ROOT/boot/System.map-$KernelVer +%if %{with_dracut} + # We estimate the size of the initramfs because rpm needs to take this size + # into consideration when performing disk space calculations. (See bz #530778) + dd if=/dev/zero of=$RPM_BUILD_ROOT/boot/initramfs-$KernelVer.img bs=1M count=20 +%else + dd if=/dev/zero of=$RPM_BUILD_ROOT/boot/initrd-$KernelVer.img bs=1M count=5 +%endif + if [ -f arch/$Arch/boot/zImage.stub ]; then + cp arch/$Arch/boot/zImage.stub $RPM_BUILD_ROOT/%{image_install_path}/zImage.stub-$KernelVer || : + fi + $CopyKernel $KernelImage \ + $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer + chmod 755 $RPM_BUILD_ROOT/%{image_install_path}/$InstallName-$KernelVer + + mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer + # Override $(mod-fw) because we don't want it to install any firmware + # We'll do that ourselves with 'make firmware_install' + make -s ARCH=$Arch INSTALL_MOD_PATH=$RPM_BUILD_ROOT modules_install KERNELRELEASE=$KernelVer mod-fw= + +%ifarch %{vdso_arches} + make -s ARCH=$Arch INSTALL_MOD_PATH=$RPM_BUILD_ROOT vdso_install KERNELRELEASE=$KernelVer + if grep '^CONFIG_XEN=y$' .config >/dev/null; then + echo > ldconfig-kernel.conf "\ +# This directive teaches ldconfig to search in nosegneg subdirectories +# and cache the DSOs there with extra bit 0 set in their hwcap match +# fields. In Xen guest kernels, the vDSO tells the dynamic linker to +# search in nosegneg subdirectories and to match this extra hwcap bit +# in the ld.so.cache file. +hwcap 0 nosegneg" + fi + if [ ! -s ldconfig-kernel.conf ]; then + echo > ldconfig-kernel.conf "\ +# Placeholder file, no vDSO hwcap entries used in this kernel." + fi + %{__install} -D -m 444 ldconfig-kernel.conf \ + $RPM_BUILD_ROOT/etc/ld.so.conf.d/kernel-$KernelVer.conf +%endif + + # And save the headers/makefiles etc for building modules against + # + # This all looks scary, but the end result is supposed to be: + # * all arch relevant include/ files + # * all Makefile/Kconfig files + # * all script/ files + + rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/source + mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + (cd $RPM_BUILD_ROOT/lib/modules/$KernelVer ; ln -s build source) + # dirs for additional modules per module-init-tools, kbuild/modules.txt + mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/extra + mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/updates + mkdir -p $RPM_BUILD_ROOT/lib/modules/$KernelVer/weak-updates + # first copy everything + cp --parents `find -type f -name "Makefile*" -o -name "Kconfig*"` $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + cp Module.symvers $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + cp System.map $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + if [ -s Module.markers ]; then + cp Module.markers $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + fi + # then drop all but the needed Makefiles/Kconfig files + rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/Documentation + rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts + rm -rf $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include + cp .config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + cp -a scripts $RPM_BUILD_ROOT/lib/modules/$KernelVer/build + if [ -d arch/$Arch/scripts ]; then + cp -a arch/$Arch/scripts $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/arch/%{_arch} || : + fi + if [ -f arch/$Arch/*lds ]; then + cp -a arch/$Arch/*lds $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/arch/%{_arch}/ || : + fi + rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts/*.o + rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/scripts/*/*.o +%ifarch ppc + cp -a --parents arch/powerpc/lib/crtsavres.[So] $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/ +%endif + if [ -d arch/%{asmarch}/include ]; then + cp -a --parents arch/%{asmarch}/include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/ + fi + cp -a include $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include + + # Make sure the Makefile and version.h have a matching timestamp so that + # external modules can be built + touch -r $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/Makefile $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/linux/version.h + touch -r $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/.config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/linux/autoconf.h + # Copy .config to include/config/auto.conf so "make prepare" is unnecessary. + cp $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/.config $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/include/config/auto.conf + + if test -s vmlinux.id; then + cp vmlinux.id $RPM_BUILD_ROOT/lib/modules/$KernelVer/build/vmlinux.id + else + echo >&2 "*** WARNING *** no vmlinux build ID! ***" + fi + + # + # save the vmlinux file for kernel debugging into the kernel-debuginfo rpm + # +%if %{with_debuginfo} + mkdir -p $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer + cp vmlinux $RPM_BUILD_ROOT%{debuginfodir}/lib/modules/$KernelVer +%endif + + find $RPM_BUILD_ROOT/lib/modules/$KernelVer -name "*.ko" -type f >modnames + + # mark modules executable so that strip-to-file can strip them + xargs --no-run-if-empty chmod u+x < modnames + + # Generate a list of modules for block and networking. + + fgrep /drivers/ modnames | xargs --no-run-if-empty nm -upA | + sed -n 's,^.*/\([^/]*\.ko\): *U \(.*\)$,\1 \2,p' > drivers.undef + + collect_modules_list() + { + sed -r -n -e "s/^([^ ]+) \\.?($2)\$/\\1/p" drivers.undef | + LC_ALL=C sort -u > $RPM_BUILD_ROOT/lib/modules/$KernelVer/modules.$1 + } + + collect_modules_list networking \ + 'register_netdev|ieee80211_register_hw|usbnet_probe|phy_driver_register' + collect_modules_list block \ + 'ata_scsi_ioctl|scsi_add_host|scsi_add_host_with_dma|blk_init_queue|register_mtd_blktrans|scsi_esp_register|scsi_register_device_handler' + collect_modules_list drm \ + 'drm_open|drm_init' + collect_modules_list modesetting \ + 'drm_crtc_init' + + # detect missing or incorrect license tags + rm -f modinfo + while read i + do + echo -n "${i#$RPM_BUILD_ROOT/lib/modules/$KernelVer/} " >> modinfo + /sbin/modinfo -l $i >> modinfo + done < modnames + + egrep -v \ + 'GPL( v2)?$|Dual BSD/GPL$|Dual MPL/GPL$|GPL and additional rights$' \ + modinfo && exit 1 + + rm -f modinfo modnames + + # remove files that will be auto generated by depmod at rpm -i time + for i in alias alias.bin ccwmap dep dep.bin ieee1394map inputmap isapnpmap ofmap pcimap seriomap symbols symbols.bin usbmap + do + rm -f $RPM_BUILD_ROOT/lib/modules/$KernelVer/modules.$i + done + + # Move the devel headers out of the root file system + mkdir -p $RPM_BUILD_ROOT/usr/src/kernels + mv $RPM_BUILD_ROOT/lib/modules/$KernelVer/build $RPM_BUILD_ROOT/$DevelDir + ln -sf ../../..$DevelDir $RPM_BUILD_ROOT/lib/modules/$KernelVer/build +} + +### +# DO it... +### + +# prepare directories +rm -rf $RPM_BUILD_ROOT +mkdir -p $RPM_BUILD_ROOT/boot + +cd linux-%{kversion}.%{_target_cpu} + +%if %{with_debug} +BuildKernel %make_target %kernel_image debug +%endif + +%if %{with_pae_debug} +BuildKernel %make_target %kernel_image PAEdebug +%endif + +%if %{with_pae} +BuildKernel %make_target %kernel_image PAE +%endif + +%if %{with_up} +BuildKernel %make_target %kernel_image +%endif + +%if %{with_smp} +BuildKernel %make_target %kernel_image smp +%endif + +%if %{with_kdump} +BuildKernel vmlinux vmlinux kdump vmlinux +%endif + +%if %{with_doc} +# Make the HTML and man pages. +make %{?_smp_mflags} htmldocs mandocs || %{doc_build_fail} + +# sometimes non-world-readable files sneak into the kernel source tree +chmod -R a=rX Documentation +find Documentation -type d | xargs chmod u+w +%endif + +%if %{with_perf} +pushd tools/perf +make %{?_smp_mflags} man || %{doc_build_fail} +popd +%endif + +### +### Special hacks for debuginfo subpackages. +### + +# This macro is used by %%install, so we must redefine it before that. +%define debug_package %{nil} + +%if %{fancy_debuginfo} +%define __debug_install_post \ + /usr/lib/rpm/find-debuginfo.sh %{debuginfo_args} %{_builddir}/%{?buildsubdir}\ +%{nil} +%endif + +%if %{with_debuginfo} +%ifnarch noarch +%global __debug_package 1 +%files -f debugfiles.list debuginfo-common-%{_target_cpu} +%defattr(-,root,root) +%endif +%endif + +### +### install +### + +%install + +cd linux-%{kversion}.%{_target_cpu} + +%if %{with_doc} +docdir=$RPM_BUILD_ROOT%{_datadir}/doc/kernel-doc-%{rpmversion} +man9dir=$RPM_BUILD_ROOT%{_datadir}/man/man9 + +# copy the source over +mkdir -p $docdir +tar -f - --exclude=man --exclude='.*' -c Documentation | tar xf - -C $docdir + +# Install man pages for the kernel API. +mkdir -p $man9dir +find Documentation/DocBook/man -name '*.9.gz' -print0 | +xargs -0 --no-run-if-empty %{__install} -m 444 -t $man9dir $m +ls $man9dir | grep -q '' || > $man9dir/BROKEN +%endif # with_doc + +%if %{with_perf} +# perf docs +mandir=$RPM_BUILD_ROOT%{_datadir}/man +man1dir=$mandir/man1 +pushd tools/perf/Documentation +make install-man mandir=$mandir +popd + +pushd $man1dir +for d in *.1; do + gzip $d; +done +popd + +# perf shell wrapper and examples +mkdir -p $RPM_BUILD_ROOT/usr/sbin/ +cp $RPM_SOURCE_DIR/perf $RPM_BUILD_ROOT/usr/sbin/perf +chmod 0755 $RPM_BUILD_ROOT/usr/sbin/perf +mkdir -p $RPM_BUILD_ROOT%{_datadir}/doc/perf +cp tools/perf/Documentation/examples.txt $RPM_BUILD_ROOT%{_datadir}/doc/perf +%endif # with_perf + +%if %{with_headers} +# Install kernel headers +make ARCH=%{hdrarch} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr headers_install + +# Do headers_check but don't die if it fails. +make ARCH=%{hdrarch} INSTALL_HDR_PATH=$RPM_BUILD_ROOT/usr headers_check \ + > hdrwarnings.txt || : +if grep -q exist hdrwarnings.txt; then + sed s:^$RPM_BUILD_ROOT/usr/include/:: hdrwarnings.txt + # Temporarily cause a build failure if header inconsistencies. + # exit 1 +fi + +find $RPM_BUILD_ROOT/usr/include \ + \( -name .install -o -name .check -o \ + -name ..install.cmd -o -name ..check.cmd \) | xargs rm -f + +# glibc provides scsi headers for itself, for now +rm -rf $RPM_BUILD_ROOT/usr/include/scsi +rm -f $RPM_BUILD_ROOT/usr/include/asm*/atomic.h +rm -f $RPM_BUILD_ROOT/usr/include/asm*/io.h +rm -f $RPM_BUILD_ROOT/usr/include/asm*/irq.h +%endif + +%if %{with_firmware} +%{build_firmware} +%endif + +%if %{with_bootwrapper} +make DESTDIR=$RPM_BUILD_ROOT bootwrapper_install WRAPPER_OBJDIR=%{_libdir}/kernel-wrapper WRAPPER_DTSDIR=%{_libdir}/kernel-wrapper/dts +%endif + + +### +### clean +### + +%clean +rm -rf $RPM_BUILD_ROOT + +### +### scripts +### + +# +# This macro defines a %%post script for a kernel*-devel package. +# %%kernel_devel_post [] +# +%define kernel_devel_post() \ +%{expand:%%post %{?1:%{1}-}devel}\ +if [ -f /etc/sysconfig/kernel ]\ +then\ + . /etc/sysconfig/kernel || exit $?\ +fi\ +if [ "$HARDLINK" != "no" -a -x /usr/sbin/hardlink ]\ +then\ + (cd /usr/src/kernels/%{KVERREL}%{?1:.%{1}} &&\ + /usr/bin/find . -type f | while read f; do\ + hardlink -c /usr/src/kernels/*.fc*.*/$f $f\ + done)\ +fi\ +%{nil} + +# This macro defines a %%posttrans script for a kernel package. +# %%kernel_variant_posttrans [] +# More text can follow to go at the end of this variant's %%post. +# +%define kernel_variant_posttrans() \ +%{expand:%%posttrans %{?1}}\ +%{expand:\ +%if %{with_dracut}\ +/sbin/new-kernel-pkg --package kernel%{?-v:-%{-v*}} --mkinitrd --dracut --depmod --update %{KVERREL}%{?-v:.%{-v*}} || exit $?\ +%else\ +/sbin/new-kernel-pkg --package kernel%{?-v:-%{-v*}} --mkinitrd --depmod --update %{KVERREL}%{?-v:.%{-v*}} || exit $?\ +%endif}\ +/sbin/new-kernel-pkg --package kernel%{?1:-%{1}} --rpmposttrans %{KVERREL}%{?1:.%{1}} || exit $?\ +%{nil} + +# +# This macro defines a %%post script for a kernel package and its devel package. +# %%kernel_variant_post [-v ] [-r ] +# More text can follow to go at the end of this variant's %%post. +# +%define kernel_variant_post(v:r:) \ +%{expand:%%kernel_devel_post %{?-v*}}\ +%{expand:%%kernel_variant_posttrans %{?-v*}}\ +%{expand:%%post %{?-v*}}\ +%{-r:\ +if [ `uname -i` == "x86_64" -o `uname -i` == "i386" ] &&\ + [ -f /etc/sysconfig/kernel ]; then\ + /bin/sed -r -i -e 's/^DEFAULTKERNEL=%{-r*}$/DEFAULTKERNEL=kernel%{?-v:-%{-v*}}/' /etc/sysconfig/kernel || exit $?\ +fi}\ +%{expand:\ +/sbin/new-kernel-pkg --package kernel%{?-v:-%{-v*}} --install %{KVERREL}%{?-v:.%{-v*}} || exit $?\ +}\ +#if [ -x /sbin/weak-modules ]\ +#then\ +# /sbin/weak-modules --add-kernel %{KVERREL}%{?-v*} || exit $?\ +#fi\ +%{nil} + +# +# This macro defines a %%preun script for a kernel package. +# %%kernel_variant_preun +# +%define kernel_variant_preun() \ +%{expand:%%preun %{?1}}\ +/sbin/new-kernel-pkg --rminitrd --rmmoddep --remove %{KVERREL}%{?1:.%{1}} || exit $?\ +#if [ -x /sbin/weak-modules ]\ +#then\ +# /sbin/weak-modules --remove-kernel %{KVERREL}%{?1} || exit $?\ +#fi\ +%{nil} + +%kernel_variant_preun +%ifarch x86_64 +%kernel_variant_post -r (kernel-smp|kernel-xen) +%else +%kernel_variant_post -r kernel-smp +%endif + +%kernel_variant_preun smp +%kernel_variant_post -v smp + +%kernel_variant_preun PAE +%kernel_variant_post -v PAE -r (kernel|kernel-smp|kernel-xen) + +%kernel_variant_preun debug +%kernel_variant_post -v debug + +%kernel_variant_post -v PAEdebug -r (kernel|kernel-smp|kernel-xen) +%kernel_variant_preun PAEdebug + +if [ -x /sbin/ldconfig ] +then + /sbin/ldconfig -X || exit $? +fi + +### +### file lists +### + +%if %{with_headers} +%files headers +%defattr(-,root,root) +/usr/include/* +%endif + +%if %{with_firmware} +%files firmware +%defattr(-,root,root) +/lib/firmware/* +%doc linux-%{kversion}.%{_target_cpu}/firmware/WHENCE +%endif + +%if %{with_bootwrapper} +%files bootwrapper +%defattr(-,root,root) +/usr/sbin/* +%{_libdir}/kernel-wrapper +%endif + +# only some architecture builds need kernel-doc +%if %{with_doc} +%files doc +%defattr(-,root,root) +%{_datadir}/doc/kernel-doc-%{rpmversion}/Documentation/* +%dir %{_datadir}/doc/kernel-doc-%{rpmversion}/Documentation +%dir %{_datadir}/doc/kernel-doc-%{rpmversion} +%{_datadir}/man/man9/* +%endif + +%if %{with_perf} +%files -n perf +%defattr(-,root,root) +%{_datadir}/doc/perf +/usr/sbin/perf +%{_datadir}/man/man1/* +%endif + +# This is %{image_install_path} on an arch where that includes ELF files, +# or empty otherwise. +%define elf_image_install_path %{?kernel_image_elf:%{image_install_path}} + +# +# This macro defines the %%files sections for a kernel package +# and its devel and debuginfo packages. +# %%kernel_variant_files [-k vmlinux] +# +%define kernel_variant_files(k:) \ +%if %{1}\ +%{expand:%%files %{?2}}\ +%defattr(-,root,root)\ +/%{image_install_path}/%{?-k:%{-k*}}%{!?-k:vmlinuz}-%{KVERREL}%{?2:.%{2}}\ +/boot/System.map-%{KVERREL}%{?2:.%{2}}\ +%if %{with_perftool}\ +/usr/libexec/perf.%{KVERREL}%{?2:.%{2}}\ +%endif\ +#/boot/symvers-%{KVERREL}%{?2:.%{2}}.gz\ +/boot/config-%{KVERREL}%{?2:.%{2}}\ +%dir /lib/modules/%{KVERREL}%{?2:.%{2}}\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/kernel\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/build\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/source\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/extra\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/updates\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/weak-updates\ +%ifarch %{vdso_arches}\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/vdso\ +/etc/ld.so.conf.d/kernel-%{KVERREL}%{?2:.%{2}}.conf\ +%endif\ +/lib/modules/%{KVERREL}%{?2:.%{2}}/modules.*\ +%if %{with_dracut}\ +%ghost /boot/initramfs-%{KVERREL}%{?2:.%{2}}.img\ +%else\ +%ghost /boot/initrd-%{KVERREL}%{?2:.%{2}}.img\ +%endif\ +%{expand:%%files %{?2:%{2}-}devel}\ +%defattr(-,root,root)\ +%verify(not mtime) /usr/src/kernels/%{KVERREL}%{?2:.%{2}}\ +/usr/src/kernels/%{KVERREL}%{?2:.%{2}}\ +%if %{with_debuginfo}\ +%ifnarch noarch\ +%if %{fancy_debuginfo}\ +%{expand:%%files -f debuginfo%{?2}.list %{?2:%{2}-}debuginfo}\ +%else\ +%{expand:%%files %{?2:%{2}-}debuginfo}\ +%endif\ +%defattr(-,root,root)\ +%if !%{fancy_debuginfo}\ +%if "%{elf_image_install_path}" != ""\ +%{debuginfodir}/%{elf_image_install_path}/*-%{KVERREL}%{?2:.%{2}}.debug\ +%endif\ +%{debuginfodir}/lib/modules/%{KVERREL}%{?2:.%{2}}\ +%{debuginfodir}/usr/src/kernels/%{KVERREL}%{?2:.%{2}}\ +%endif\ +%endif\ +%endif\ +%endif\ +%{nil} + + +%kernel_variant_files %{with_up} +%kernel_variant_files %{with_smp} smp +%kernel_variant_files %{with_debug} debug +%kernel_variant_files %{with_pae} PAE +%kernel_variant_files %{with_pae_debug} PAEdebug +%kernel_variant_files -k vmlinux %{with_kdump} kdump + + +%changelog +* Tue Aug 17 2010 Chuck Ebbert 2.6.33.8-149 +- Fix fallout from the stack guard page fixes. + (mm-fix-page-table-unmap-for-stack-guard-page-properly.patch, + mm-fix-up-some-user-visible-effects-of-the-stack-guard-page.patch) + +* Sun Aug 15 2010 Chuck Ebbert 2.6.33.8-148 +- Add all the patches from 2.6.34.4 that apply cleanly. +- Roll up the 2.6.34.4 patches as git-linus.diff +- Fix up usb-wwan-update and drm-core-next patches. + +* Sun Aug 15 2010 Chuck Ebbert +- 2.6.33.8 from http://git.kernel.org/?p=linux/kernel/git/jkacur/jk-2.6.git stable/2.6.33.y +- Unrevert stable patch from .33.7: + ssb-handle-netbook-devices-where-the-sprom-address-is-changed.patch +- Drop patches merged in 2.6.33.8: + ssb_check_for_sprom.patch + +* Sat Aug 14 2010 Chuck Ebbert 2.6.33.7-148 +- Update to kernel 2.6.33.7 +- Drop patches merged in 2.6.33.7: + drm-i915-add-reclaimable-to-page-allocations.patch + drm-i915-fix-hibernate-memory-corruption.patch + drm-radeon-fix-shared-ddc-handling.patch + linux-2.6-acpi-sleep-live-sci-live.patch + drm-i915-make-G4X-style-PLL-search-more-permissive.patch + drm-intel-945gm-stability-fixes.patch + mac80211-do-not-wipe-out-old-supported-rates.patch + mac80211-fix-supported-rates-IE-if-AP-doesnt-give-us-its-rates.patch + iwlwifi-cancel-scan-watchdog-in-iwl_bg_abort_scan.patch + sched-fix-over-scheduling-bug.patch + ethtool-fix-buffer-overflow.patch + x86-debug-clear-reserved-bits-of-dr6.patch + x86-debug-send-sigtrap-for-user-icebp.patch + cifs-fix-malicious-redirect-problem-in-the-dns-lookup-code.patch +- Revert broken ssb patch from 2.6.33.7: + ssb-handle-netbook-devices-where-the-sprom-address-is-changed.patch + +* Fri Jul 23 2010 Chuck Ebbert 2.6.33.6-147.2.4 +- inotify-fix-inotify-oneshot-support.patch, + inotify-send-IN_UNMOUNT-events.patch: + Fix broken oneshot support and missing umount events. (#607327) + +* Fri Jul 23 2010 Chuck Ebbert 2.6.33.6-147.2.3 +- drm-i915-add-reclaimable-to-page-allocations.patch: + Additional fix for hibernation memory corruption bugs. +- drm-intel-945gm-stability-fixes.patch: fix 945GM stability issues +- drm-i915-make-G4X-style-PLL-search-more-permissive.patch (#572799) +- drm-radeon-fix-shared-ddc-handling.patch (#593429) + +* Fri Jul 23 2010 Chuck Ebbert 2.6.33.6-147.2.2 +- kvm-mmu-fix-conflict-access-permissions-in-direct-sp.patch: + Fix crash in guest Python programs (#610911) + +* Fri Jul 23 2010 Chuck Ebbert 2.6.33.6-147.2.1 +- cifs-fix-malicious-redirect-problem-in-the-dns-lookup-code.patch: + Fix a malicious redirect problem in the DNS lookup code (CVE-2010-2524) + +* Tue Jul 06 2010 Jarod Wilson 2.6.33.6-147 +- Really make hdpvr i2c IR part register this time, so something can + actually be bound to it (like, say, lirc_zilog) + +* Tue Jul 06 2010 Chuck Ebbert 2.6.33.6-146 +- x86-debug-send-sigtrap-for-user-icebp.patch, + x86-debug-clear-reserved-bits-of-dr6.patch (#609548) + +* Tue Jul 06 2010 Chuck Ebbert 2.6.33.6-145 +- ethtool-fix-buffer-overflow.patch: ethtool buffer overflow (CVE-2010-2478) + +* Tue Jul 06 2010 Chuck Ebbert 2.6.33.6-144 +- sched-fix-over-scheduling-bug.patch: fix scheduler bug with CGROUPS + +* Tue Jul 06 2010 Chuck Ebbert 2.6.33.6-143 +- Linux 2.6.33.6 + +* Fri Jul 02 2010 Ben Skeggs 2.6.33.6-142.rc1 +- nouveau: fix connector ordering issues (rhbz#602492) + +* Fri Jul 02 2010 Chuck Ebbert 2.6.33.6-141.rc1 +- Linux 2.6.33.6-rc1 +- Drop patches merged upstream: + btrfs-should-add-permission-check-for-setfacl.patch (CVE-2010-2071) + iwlwifi-reset-card-during-probe.patch + iwlwifi-recalculate-average-tpt-if-not-current.patch + keys-find-keyring-by-name-can-gain-access-to-the-freed-keyring.patch + l2tp-fix-oops-in-pppol2tp_xmit.patch +- Revert DRM patches we already have: + drm-edid-fix-1024x768-85hz.patch + drm-i915-fix-82854-pci-id-and-treat-it-like-other-85x.patch +- Fix up usb-wwan-update.patch for upstream additions. + +* Fri Jul 02 2010 Dave Airlie 2.6.33.5-140 +- attempt to fix hibernate on Intel GPUs (kernel.org #13811) + +* Wed Jun 30 2010 Kyle McMartin +- Disable MRST here too. + +* Mon Jun 28 2010 Chuck Ebbert 2.6.33.5-138 +- ppc64: enable active memory sharing and DLPAR memory remove (#607175) + +* Mon Jun 28 2010 Dave Airlie 2.6.33.5-137 +- i915: fix edp panels betterer. + +* Fri Jun 25 2010 Dave Airlie 2.6.33.5-136 +- i915: fix edp on a number of notebooks (including whot's one) + +* Fri Jun 25 2010 Ben Skeggs 2.6.33.5-135 +- nouveau: backport important fixes from upstream +- Fixes unPOSTed detection + support nv4x multi-card (rhbz#607190) +- Various VBIOS parser fixes (potential culprit for many suspend bugs) +- Fixes memory detection on some GF8 IGPs, and boards with 4GiB VRAM +- Corrects various problems in the behaviour of GF8 dual-link TMDS + +* Wed Jun 23 2010 Kyle McMartin 2.6.33.5-134 +- l2tp: fix oops in pppol2tp_xmit (#607054) + +* Fri Jun 18 2010 Roland McGrath 2.6.33.5-133 +- make execshield respect PF_RANDOMIZE and ADDR_NO_RANDOMIZE (#220892) + +* Thu Jun 17 2010 Kyle McMartin +- make ghash-clmulni modular to get rid of early boot noise (rhbz#586954) + (not a /fix/ but it should at least quiet boot down a bit if you have + the cpu support) + +* Tue Jun 15 2010 John W. Linville 2.6.33.5-131 +- iwlwifi: cancel scan watchdog in iwl_bg_abort_scan (#590436) + +* Mon Jun 14 2010 Kyle McMartin 2.6.33.5-129 +- Add btrfs ACL fixes from CVE-2010-2071. + +* Sun Jun 13 2010 Kyle McMartin 2.6.33.5-128 +- mac80211/iwlwifi fix connections to some APs (rhbz#558002) + patches from sgruszka@. + +* Fri Jun 11 2010 Justin M. Forbes 2.6.33.5-127 +- Disable xsave for so that kernel will boot on ancient EC2 hosts. + +* Fri Jun 11 2010 Kyle McMartin 2.6.33.5-126 +- ALSA: usbmixer - add possibility to remap dB values (rhbz#578131) + +* Fri Jun 11 2010 Kyle McMartin 2.6.33.5-124 +- Drop writeback patches, they appear to be able to cause oopses. + +* Wed Jun 09 2010 John W. Linville +- Disable rt20xx and rt35xx chipset support in rt2800 drivers (#570869) + +* Wed Jun 09 2010 David Woodhouse +- Include PHY modules in modules.networking (#602155) + +* Wed Jun 09 2010 Kyle McMartin 2.6.33.5-121 +- doc_build_fail FAIL. + +* Wed Jun 09 2010 Kyle McMartin 2.6.33.5-120 +- backport ntrig hid driver from git head. (rhbz#584593) + +* Mon Jun 07 2010 Matthew Garrett +- linux-2.6-acpi-indirect_fan_control.patch: fix some ACPI fans (rh#531916) + +* Mon Jun 07 2010 Ben Skeggs +- nouveau: fix iommu errors on GeForce 8 and newer chipsets (rh#561267) + +* Thu Jun 03 2010 Kyle McMartin +- But keep it for kernel-headers... + +* Thu Jun 03 2010 Dave Jones +- remove the 31bit s390 support again. + +* Tue Jun 01 2010 Jarod Wilson +- Wire up all s390{,x} bits to match RHEL6 kernel spec + +* Wed May 27 2010 Chuck Ebbert 2.6.33.5-112 +- CVE-2010-1437: keyrings: find_keyring_by_name() can gain the freed keyring + +* Wed May 27 2010 Chuck Ebbert 2.6.33.5-111 +- Linux 2.6.33.5 +- Drop patches merged in -stable: + iwlwifi_-check-for-aggregation-frame-and-queue.patch + iwlwifi_-clear-all-the-stop_queue-flag-after-load-firmware.patch + revert-ath9k_-fix-lockdep-warning-when-unloading-module.patch + btrfs-check-for-read-permission-on-src-file-in-clone-ioctl.patch +- Revert drm patch already in F-13: drm-i915-disable-fbc-on-915gm-and-945gm.patch +- Apply DRM patches from -stable on top of F-13 DRM updates: + drm-i915-use-pipe_control-instruction-on-ironlake-and-sandy-bridge.patch + drm-i915-fix-non-ironlake-965-class-crashes.patch + +* Thu May 27 2010 Ben Skeggs +- drm-nouveau-updates.patch: add nv50 gpio fix (rh#582621) + +* Wed May 26 2010 Adam Jackson +- linux-2.6-cantiga-iommu-gfx.patch: Drop, redundant. +- config-generic: Disable i830.ko, userspace will never load it. + +* Mon May 24 2010 John W. Linville +- iwlwifi: recover_from_tx_stall (#589777) + +* Thu May 20 2010 Chuck Ebbert 2.6.33.4-106 +- Remove "PatchNNNN" entries for dropped patches. +- More writeback fixes from block-2.6 tree (#593669) + +* Thu May 20 2010 Kyle McMartin +- kill some dead patches. + +* Wed May 19 2010 John W. Linville +- iwlwifi: fix scan races +- iwlwifi: fix internal scan race + +* Wed May 19 2010 Dave Airlie +- disable vmwgfx at request of vmware + +* Wed May 19 2010 Roland McGrath +- x86: put assembly CFI in .debug_frame + +* Tue May 18 2010 Kyle McMartin +- btrfs: check for read permission on src file in the clone ioctl + (rhbz#593226) + +* Mon May 17 2010 Matthew Garrett +- thinkpad-acpi-fix-backlight.patch: Fix backlight control on some recent + Thinkpads + +* Mon May 17 2010 Kyle McMartin 2.6.33.4-97 +- perf-mount-debugfs-automatically.patch (#570821) + +* Mon May 17 2010 Ben Skeggs 2.6.33.4-96 +- drm: fix edid modeline for 1024x768@85Hz (#582472) + +* Thu May 13 2010 Jarod Wilson 2.6.33.4-95 +- Enable support for kworld ub435-q and 340u usb atsc tuners + +* Thu May 13 2010 Peter Hutterer +- linux-2.6-input-clickpad-support.patch: add support for ClickPad + touchpads (#590835) + +* Wed May 12 2010 Chuck Ebbert 2.6.33.4-93 +- Linux 2.6.33.4 +- Drop patches merged upstream: + linux-2.6-pci-fixup-resume.patch + linux-2.6-tun-orphan_an_skb_on_tx.patch + libata-fix-accesses-at-LBA28-boundary.patch + linux-2.6-creds_are_invalid-race.patch + hugetlb-fix-infinite-loop-in-get-futex-key.patch + reiserfs-fix-permissions-on-reiserfs-priv.patch + ath9k-reorder-ieee80211_free_hw-behind-ath9k_uninit_.patch +- Revert -stable DRM patches we already have: + drm-i915-add-initial-bits-for-vga-modesetting-bringup-on-sandybridge.patch + drm-i915-fix-tiling-limits-for-i915-class-hw-v2.patch +- Fix up patches to apply on top of 2.6.33.4: + linux-2.6-p54pci.patch + vhost_net-rollup.patch + +* Wed May 12 2010 Roland McGrath +- utrace update (#590954) + +* Mon May 10 2010 Kyle McMartin +- don't link binutils against perf. sigh. stupid gpl versions. + +* Mon May 10 2010 Eric Paris +- reduce size of selinux poliy memory allocation (rhbz#590363) + +* Mon May 10 2010 Kyle McMartin +- crypto-aesni-kill-module_alias.patch: kill MODULE_ALIAS to prevent + aesni-intel from autoloading. + +* Mon May 10 2010 Ben Skeggs +- add linux-2.6-input-hid-quirk-egalax.patch, missed from F-12, requested + by Peter Hutterer. + +* Sun May 09 2010 Kyle McMartin +- fs-explicitly-pass-in-whether-sb-is-pinned-or-not.patch (rhbz#588930) + +* Sat May 08 2010 Kyle McMartin +- Link perf against libbfd.a for name-demangling support. (rhbz#590289) + +* Thu May 06 2010 Adam Jackson 2.6.33.3-85 +- drm-intel-next: Enable the display even harder (#587171) + +* Wed May 5 2010 Kyle McMartin 2.6.33.3-84 +- CONFIG_HWMON=y => CONFIG_THERMAL_HWMON. Kconfig is worse than rabies. + +* Wed May 5 2010 Kyle McMartin 2.6.33.3-83 +- disable-i8042-check-on-apple-mac.patch: fix build on ppc. + +* Tue May 4 2010 John W. Linville 2.6.33.3-82 +- iwlwifi: recalculate average tpt if not current (#588021) + +* Tue May 4 2010 Kyle McMartin 2.6.33.3-81 +- disable-i8042-check-on-apple-mac.patch: avoid long delay or hang booting + on Intel Apple Macs. + +* Tue May 4 2010 Kyle McMartin 2.6.33.3-80 +- ibmvscsi-fix-DMA-API-misuse.patch (#579454) + +* Mon May 3 2010 Kyle McMartin 2.6.33.3-79 +- disable aesni. (#571577) + +* Fri Apr 30 2010 John W. Linville 2.6.33.3-78 +- ath9k: reorder ieee80211_free_hw behind ath9k_uninit_hw to avoid + oops (#586787) + +* Fri Apr 30 2010 Kyle McMartin +- add-appleir-driver.patch: update from hadess, split out some other patches. +- git-bluetooth.patch: and put them in git-bluetooth, along with other fixes. + +* Thu Apr 29 2010 Adam Jackson +- drm-intel-sdvo-fix-2.patch: Require that the A/D bit of EDID match the + A/D-ness of the connector. (#584229) + +* Thu Apr 29 2010 Kyle McMartin +- add-appleir-usb-driver.patch: updates from hadess. + +* Thu Apr 29 2010 Ben Skeggs 2.6.33.3-73 +- nouveau: initial eDP support + DP suspend/resume fixes +- nouveau: fix monitor detection on certain chipsets with DP support +- nouveau: better CRTC PLL calculation on latest chipsets +- nouveau: send hotplug events down to userspace + +* Wed Apr 28 2010 John W. Linville 2.6.33.3-72 +- Revert "ath9k: fix lockdep warning when unloading module" + +* Tue Apr 27 2010 Chuck Ebbert 2.6.33.3-71 +- Linux 2.6.33.3 +- Drop patches merged upstream: + acpi-ec-allow-multibyte-access-to-ec.patch + acpi-ec-limit-burst-to-64-bit.patch + b43_-Allow-PIO-mode-to-be-selected-at-module-load.patch + b43_-fall-back-gracefully-to-PIO-mode-after-fatal-DMA-errors.patch + mac80211_-tear-down-all-agg-queues-when-restart_reconfig-hw.patch + iwlwifi_-clear-all-tx-queues-when-firmware-ready.patch + iwlwifi_-fix-scan-race.patch +- Revert DRM patches we already have: + drm-radeon-kms-add-firemv-2400-pci-id.patch + drm-radeon-kms-fix-rs600-tlb-flush.patch + drm-edid-quirks-envision-en2028.patch + drm-return-enodev-if-the-inode-mapping-changes.patch + drm-remove-the-edid-blob-stored-in-the-edid-property-when-it-is-disconnected.patch + drm-edid-allow-certain-bogus-edids-to-hit-a-fixup-path-rather-than-fail.patch +- Fix up drm-core-next to apply after 2.6.33.3 + +* Tue Apr 27 2010 Justin M. Forbes +- Orphan an skb on tx for tun/tap devices. + +* Tue Apr 27 2010 Chuck Ebbert 2.6.33.2-68 +- Fix possible data corruption with ext4 mounted with -o discard + +* Mon Apr 26 2010 Chuck Ebbert +- hugetlb-fix-infinite-loop-in-get-futex-key.patch (F12#552557) +- reiserfs-fix-permissions-on-reiserfs-priv.patch (CVE-2010-1146) + +* Mon Apr 26 2010 Chuck Ebbert 2.6.33.2-66 +- Turn off debugging and enable debug kernel builds. + +* Mon Apr 26 2010 Dave Jones +- Revert PCI changes from 2.6.33.2. + Possibly causing networking problems with some drivers. + +* Mon Apr 26 2010 Adam Jackson +- drm-intel-sdvo-fix.patch: Fix DDC bus selection for SDVO (#584229) + +* Thu Apr 22 2010 Hans de Goede +- Make p54pci wlan work on slower computers (#583623) + +* Thu Apr 22 2010 Matthew Garrett +- linux-2.6-pci-fixup-resume.patch: Make sure we enable power resources on D0 + +* Wed Apr 21 2010 Justin M. Forbes +- vhost-net fixes from upstream + +* Wed Apr 21 2010 Roland McGrath 2.6.33.2-60 +- fix race crash from bogus cred.c debugging code (#583843) + +* Wed Apr 21 2010 Matthew Garrett +- thinkpad-acpi-add-x100e.patch: Add EC path for Thinkpad X100 + +* Tue Apr 20 2010 Dave Airlie 2.6.33.2-57 +- drm-radeon-ss-fix.patch: backport spread spectrum fix (#571874) + +* Mon Apr 19 2010 Adam Jackson 2.6.33.2-56 +- drm-intel-next.patch: 2.6.34 as of today, plus anholt's for-linus tree as + of today, plus most of drm-intel-next except for the AGP/GTT split and a + broken TV detect fix. Tested on 945GM, GM45, and gen5. +- drm-intel-make-lvds-work.patch: Rebase to match. +- drm-intel-acpi-populate-didl.patch: Drop, merged in -intel-next +- drm-intel-gen5-dither.patch: Use better dither on gen5. + +* Mon Apr 19 2010 Matthew Garrett +- linux-2.6-acpi-sleep-live-sci-live.patch: Try harder to switch to ACPI mode + +* Mon Apr 19 2010 Adam Jackson +- linux-2.6-intel-iommu-igfx.patch: Disable IOMMU for GFX by default, just too + broken. intel_iommu=igfx_on to turn it on. (Adel Gadllah) + +* Mon Apr 19 2010 Dave Airlie +- radeon: add rs600 + firemv pciid + dual-link fix + +* Fri Apr 16 2010 John W. Linville +- Patches from Intel to address intermittent firmware failures with iwlagn + +* Fri Apr 16 2010 Adam Jackson +- drm-core-next.patch: Update EDID and other core bits to airlied's tree +- drm-nouveau-abi16.patch: Rediff to match + +* Fri Apr 16 2010 Ben Skeggs 2.6.33.2-49 +- nouveau: fix dereference-after-free bug (rh#575224) +- drm-nouveau-acpi-edid-fallback.patch: fix ppc build + potential crasher + +* Thu Apr 15 2010 Eric Paris +- enable CONFIG_INTEL_TXT on x86_64 + +* Wed Apr 14 2010 David Woodhouse +- Fix autoloading of phy modules (#525966) + +* Wed Apr 14 2010 Chuck Ebbert 2.6.33.2-46 +- libata-fix-accesses-at-LBA28-boundary.patch + +* Tue Apr 13 2010 Justin M. Forbes +- virt_console: Fixes from upstream + +* Tue Apr 13 2010 Chuck Ebbert +- Fix ACPI errors on boot caused by EC burst mode patch (#581535) +- Re-enable ACPI EC delay patch (#579510) + +* Tue Apr 13 2010 Ben Skeggs +- drm-nouveau-acpi-edid-fallback.patch: fix oops on cards without _DSM method + +* Mon Apr 12 2010 Matthew Garrett +- linux-2.6-acpi-video-export-edid.patch: + drm-nouveau-acpi-edid-fallback.patch: Let nouveau get an EDID from ACPI + +* Fri Apr 09 2010 John W. Linville 2.6.33.2-41 +- b43: Allow PIO mode to be selected at module load +- b43: fall back gracefully to PIO mode after fatal DMA errors + +* Fri Apr 09 2010 Chuck Ebbert +- virt_console: fix a bug in the original race fix + +* Fri Apr 09 2010 Ben Skeggs +- nouveau: fixes from upstream + NVA3 support + +* Thu Apr 08 2010 Dave Airlie +- Backport radeon r800 modesetting support + +* Wed Apr 07 2010 Chuck Ebbert +- Disable async multicore RAID4/5/6 stripe processing (F12#575402) + +* Tue Apr 06 2010 Hans de Goede +- gspca-vc032x: Use YUYV output for OV7670 (#537332) + +* Mon Apr 05 2010 Chuck Ebbert +- Build eeepc-laptop driver for x86_64 (#565582) + +* Mon Apr 05 2010 Chuck Ebbert +- Linux 2.6.33.2 +- Dropped patches merged upstream: + coredump-uid-pipe-check.patch + iwlwifi-use-dma_alloc_coherent.patch + r8169-offical-fix-for-CVE-2009-4537.patch +- Dropped from drm-nouveau-updates.patch: + "drm/nouveau: report unknown connector state if lid closed" +- New sparc64 config option: + CONFIG_FB_XVR1000=y +- Reverted from upstream: + usb-qcserial-add-new-device-ids.patch: Already in wwan-update patch + +* Mon Apr 05 2010 Chuck Ebbert +- Comment out acpi-ec-add-delay-before-write.patch: breaks + boot on some machines. + +* Mon Apr 05 2010 Jarod Wilson 2.6.33.1-32 +- Fix oops in lirc_it87 driver (#579270) +- Support more imon 0xffdc key combinations + +* Sat Apr 03 2010 Chuck Ebbert +- Build all of the DVB frontend drivers instead of just the automatically + selected ones. (#578755) + +* Thu Apr 01 2010 Matthew Garrett +- drm-intel-acpi-populate-didl.patch: Fix brightness hotkeys on some machines +- linux-2.6-usb-wwan-update.patch: Update wwan code and fix qcserial + +* Wed Mar 31 2010 Matthew Garrett +- drm-intel-make-lvds-work.patch: Make sure LVDS gets turned back on + +* Tue Mar 30 2010 Chuck Ebbert +- Allow setting buildid on both command line and in the SRPM. + +* Tue Mar 30 2010 Chuck Ebbert 2.6.33.1-26 +- r8169-offical-fix-for-CVE-2009-4537.patch + +* Tue Mar 30 2010 Chuck Ebbert +- ACPI EC fixes pending upstream: + acpi-ec-add-delay-before-write.patch + acpi-ec-allow-multibyte-access-to-ec.patch + +* Tue Mar 30 2010 Dave Jones +- Fix broken locking in cpufreq. + +* Tue Mar 30 2010 John W. Linville 2.6.33.1-24 +- Avoid null pointer dereference introduced by 'ssb: check for sprom' (#577463) + +* Mon Mar 29 2010 John W. Linville 2.6.33.1-23 +- iwlwifi: reset card during probe (#557084) +- iwlwifi: use dma_alloc_coherent (#574146) + +* Mon Mar 29 2010 Ben Skeggs 2.6.33.1-22 +- nouveau: sync with nouveau upstream + +* Wed Mar 24 2010 Josef Bacik 2.6.33.1-21 +- Update btrfs so it includes the default subvolume stuff, for the rollback + feature + +* Mon Mar 22 2010 Jarod Wilson +- A few more imon driver button additions +- Fix minor init issue w/topseed 0x0008 mceusb transceivers + +* Fri Mar 19 2010 John W. Linville 2.6.33.1-19 +- ssb: check for sprom (#533746) + +* Fri Mar 19 2010 Jarod Wilson 2.6.33.1-18 +- Improve mouse button and pad handling on 0xffdc imon devices +- Add xmit support to topseed 0x0008 lirc_mceusb transceiver + +* Fri Mar 19 2010 David Woodhouse +- Apply fix for #538163 again (Cantiga shadow GTT chipset b0rkage). + +* Fri Mar 19 2010 Hans de Goede +- Cherry pick various webcam driver fixes + (#571188, #572302, #572373) + +* Thu Mar 18 2010 Neil Horman +- Disable TIPC protocol in config + +* Wed Mar 17 2010 Jarod Wilson +- lirc driver update: + * fix lirc_i2c on cx2341x hauppauge cards (#573675) + * fix null ptr deref in lirc_imon (#545599) + * fix lirc_zilog on cx2341x hauppauge cards + * adds a few new lirc_mceusb device ids +- imon input layer driver update, adds better support for 0xffdc + devices and handles failed key lookups better + +* Tue Mar 16 2010 Chuck Ebbert +- Linux 2.6.33.1 + +* Tue Mar 16 2010 Chuck Ebbert +- Add examples.txt to perf docs, require libdwarf with perf package. + (#568309, #569506) + +* Mon Mar 15 2010 Chuck Ebbert +- Linux 2.6.33.1-rc1 +- Drop merged patch: + x86-pci-prevent-mmconfig-memory-corruption.patch +- Revert V4l patch we already have: + v4l-dvb-13991-gspca_mr973010a-fix-cif-type-1-cameras-not-streaming-on-uhci-controllers.patch + +* Mon Mar 15 2010 Ben Skeggs +- nouveau: pull in more fixes from upstream + +* Sat Mar 06 2010 Kyle McMartin +- Add libdwarf dep if %with_perftool. + +* Fri Mar 05 2010 Kyle McMartin +- Fix race between hvc_close and hvc_remove. (rhbz#568621) + +* Thu Mar 04 2010 Kyle McMartin +- Enable CGROUP_DEBUG. + +* Mon Mar 01 2010 Dave Jones +- Don't own /usr/src/kernels any more, it's now owned by filesystem. (#569438) + +* Sat Feb 27 2010 Chuck Ebbert +- Add patch from the 2.6.33 stable queue to fix memory corruption + in the PCI MMCONFIG code. + +* Thu Feb 25 2010 Ben Skeggs +- nouveau: rebase to nouveau/linux-2.6 git + +* Wed Feb 24 2010 Chuck Ebbert +- Drop/clear obsolete V4L patches, use ApplyOptionalPatch +- Fix two typos in config-generic probably caused by vi users + +* Wed Feb 24 2010 Dave Jones +- Remove unnecessary redefinition of KEY_RFKILL from linux-2.6-rfkill-all.patch + +* Wed Feb 24 2010 Kyle McMartin 2.6.33-1 +- Linux 2.6.33 + +* Wed Feb 24 2010 Dave Jones 2.6.33-0.53.rc8.git9 +- 2.6.33-rc8-git9 +- dropped: drm-nouveau-old-vgaload.patch - merged upstream. +- dropped: drm-nouveau-gf8-igp.patch - merged upstream. + +* Tue Feb 23 2010 Ben Skeggs 2.6.33-0.52.rc8.git6 +- nouveau: bring to latest upstream, reorganise patches to be more sensible + +* Mon Feb 22 2010 Kyle McMartin +- coredump-uid-pipe-check.patch: commit it to a useful branch. + +* Mon Feb 22 2010 Dave Jones 2.6.33-0.50.rc8.git6 +- 2.6.33-rc8-git6 + +* Sun Feb 21 2010 Hans de Goede +- Rebase gspca usb webcam driver + sub drivers to latest upstream, this + adds support for the following webcam bridge chipsets: benq, cpia1, sn9c2028; + and support for new devices and many bugfixes in other gspca-subdrivers + +* Fri Feb 19 2010 Kyle McMartin 2.6.33-0.48.rc8.git4 +- 2.6.33-rc8-git4 + +* Wed Feb 17 2010 Ben Skeggs 2.6.33-0.47.rc8.git1 +- nouveau: update to new kernel interface +- drm_nouveau_ucode.patch: drop, in linux-firmware now + +* Tue Feb 16 2010 Kyle McMartin 2.6.33-0.46.rc8.git1 +- 2.6.33-rc8-git1 +- virt_console-rollup.patch: fixes from linux-next from Amit. + +* Mon Feb 15 2010 Neil Horman +- Refactor usermodehelper code and change recursion check for abrt + with linux-2.6-umh-refactor.patch from -mm + fixes bz 557386 + +* Fri Feb 12 2010 Chuck Ebbert 2.6.33-0.44.rc8 +- 2.6.33-rc8 + +* Fri Feb 12 2010 Chuck Ebbert 2.6.33-0.43.rc7.git6 +- 2.6.33-rc7-git6 + +* Thu Feb 11 2010 Chuck Ebbert 2.6.33-0.42.rc7.git5 +- 2.6.33-rc7-git5 +- Drop merged patches: + fix-conntrack-bug-with-namespaces.patch + commit ad60a9154887bb6162e427b0969fefd2f34e94a6 from git-bluetooth.patch + +* Mon Feb 08 2010 Josh Boyer +- Drop ppc ps3_storage and imac-transparent bridge patches + +* Sat Feb 06 2010 Kyle McMartin 2.6.33-0.40.rc7.git0 +- Add libdwarf-devel to build deps so perf gets linked to it. + +* Sat Feb 06 2010 Kyle McMartin +- virt_console-rollup.patch, for feature F13/VirtioSerial, patches + are all targetted at 2.6.34 (and in linux-next.) + +* Sat Feb 06 2010 Kyle McMartin +- git-bluetooth.patch: selection of backports from next for hadess. + (rhbz#562245) + +* Sat Feb 06 2010 Kyle McMartin 2.6.33-0.36.rc7.git0 +- Linux 2.6.33-rc7 (oops, jumped the gun on -git6 I guess. :) + +* Sat Feb 06 2010 Kyle McMartin +- 2.6.33-rc6-git6 + +* Sat Feb 06 2010 Kyle McMartin +- Hack around delay loading microcode.ko, on intel, we don't split out + the firmware into cpuid specific versions (in fact, I don't know who does...) + so just patch out the request_firmware calls in microcode_intel.c, and + microcode_ctl.init will do the right thing. (fixes rhbz#560031) + (side note: I'll fix microcode_ctl to do one better at some point.) + +* Sat Feb 06 2010 Kyle McMartin +- Don't want linux-firmware if %with_firmware, yet. (Think F-11/F-12 2.6.33) + +* Fri Feb 05 2010 Peter Jones +- Move initrd creation to %%posttrans + Resolves: rhbz#557922 + +* Fri Feb 05 2010 Kyle McMartin +- If %with_firmware, continue with kernel-firmware, otherwise prereq on the + separate linux-firmware pkg. Thanks to dzickus for noticing. + +* Thu Feb 04 2010 Kyle McMartin 2.6.33-0.29.rc6.git4 +- 2.6.33-rc6-git4 + +* Wed Feb 03 2010 Kyle McMartin +- prevent-runtime-conntrack-changes.patch: fix another conntrack issue + identified by jcm. + +* Wed Feb 03 2010 Kyle McMartin +- fix-conntrack-bug-with-namespaces.patch: Patch for issue identified + by jcm. (Ref: http://lkml.org/lkml/2010/2/3/112) + +* Mon Feb 02 2010 Chuck Ebbert 2.6.33-0.26.rc6.git1 +- 2.6.33-rc6-git1 + +* Fri Jan 29 2010 Chuck Ebbert 2.6.33-0.25.rc6.git0 +- 2.6.33-rc6 + +* Wed Jan 27 2010 Roland McGrath 2.6.33-0.24.rc5.git1 +- Fix include/ copying for kernel-devel. + +* Mon Jan 25 2010 Kyle McMartin 2.6.33-0.23.rc5.git1 +- 2.6.33-rc5-git1 +- arm: MTD_PISMO is not set + +* Mon Jan 25 2010 Dave Jones +- Disable CONFIG_X86_CPU_DEBUG + +* Mon Jan 25 2010 Josh Boyer +- Turn off CONFIG_USB_FHCI_HCD. It doesn't build + +* Fri Jan 22 2010 Kyle McMartin 2.6.33-0.20.rc5.git0 +- 2.6.33-rc5 + +* Thu Jan 21 2010 Jarod Wilson +- Merge crystalhd powerpc build fix from airlied + +* Wed Jan 20 2010 Kyle McMartin 2.6.33-0.18.rc4.git7 +- 2.6.32-rc4-git7 +- dvb mantis drivers as modules + +* Wed Jan 20 2010 Kyle McMartin 2.6.33-0.17.rc4.git6 +- add appleir usb driver + +* Mon Jan 18 2010 Kyle McMartin 2.6.33-0.16.rc4.git6 +- 2.6.33-rc4-git6 +- execshield: rebase for mm_types.h reject + +* Mon Jan 18 2010 Kyle McMartin +- vhost_net-rollup.patch: https://fedoraproject.org/wiki/Features/VHostNet + from davem/net-next-2.6.git + +* Sat Jan 16 2010 Kyle McMartin 2.6.33-0.14.rc4.git3 +- DEBUG_STRICT_USER_COPY_CHECKS off for now, tickles issue in lirc_it87.c + +* Sat Jan 16 2010 Kyle McMartin 2.6.33-0.13.rc4.git3 +- 2.6.33-rc4-git3 + +* Thu Jan 14 2010 Steve Dickson +- Enabled the NFS4.1 (CONFIG_NFS_V4_1) kernel config + +* Wed Jan 13 2010 Kyle McMartin 2.6.33-0.11.rc4 +- Linux 2.6.33-rc4 + +* Wed Jan 13 2010 Kyle McMartin 2.6.33-0.10.rc3.git5 +- 2.6.33-rc3-git5 + +* Wed Jan 13 2010 Dave Airlie +- Add fbdev fix for multi-card primary console on x86-64 +- clean up all the drm- patches + +* Tue Jan 12 2010 Jarod Wilson +- Update lirc patch for 2.6.33 kfifo changes +- Add Broadcom Crystal HD video decoder driver from staging + +* Mon Jan 11 2010 Kyle McMartin +- include/asm is gone, kludge it for now. + +* Mon Jan 11 2010 Dave Jones +- Rebase exec-shield. + +* Mon Jan 11 2010 Kyle McMartin +- drop e1000 patch. + +* Mon Jan 11 2010 Kyle McMartin +- lirc broken due to kfifo mess. + +* Mon Jan 11 2010 Kyle McMartin +- drm-intel-big-hammer: fix IS_I855 macro. + +* Mon Jan 11 2010 Kyle McMartin +- Linux 2.6.33-rc3 +- utrace: rebased from roland's people page. +- via-hwmon-temp-sensor.patch: upstream. +- linux-2.6-defaults-alsa-hda-beep-off.patch: new config option supercedes. +- readd nouveau ctxprogs as firmware/ like it should be. +- linux-2.6-pci-cacheline-sizing.patch: upstream. +- linux-2.6-intel-agp-clear-gtt.patch: upstream. +- linux-2.6-nfsd4-proots.patch: upstream? +- rebased the rest. + +* Mon Jan 11 2010 Kyle McMartin 2.6.32.3-21 +- Linux 2.6.32.3 +- drm-intel-no-tv-hotplug.patch: re-add lost patch from F-12 + 2.6.31 (#522611, #544671) + +* Mon Jan 11 2010 Kyle McMartin 2.6.32.2-20 +- Re-enable ATM_HE (#545289) + +* Fri Jan 08 2010 Chuck Ebbert 2.6.32.2-19 +- Add another symbol to look for when generating modules.block + +* Thu Jan 07 2010 David Woodhouse 2.6.32.2-18 +- Drop kernel-firmware package now that it's packaged separately. + +* Mon Jan 04 2010 Dave Jones +- Drop some of the vm/spinlock taint patches. dump_stack() already does same. + +* Thu Dec 24 2009 Kyle McMartin 2.6.32.2-15 +- Add patch from dri-devel to fix vblanks on r600. + [http://marc.info/?l=dri-devel&m=126137027403059&w=2] + +* Fri Dec 18 2009 Kyle McMartin 2.6.32.2-14 +- Linux 2.6.32.2 +- dropped upstream patches. + +* Fri Dec 18 2009 Roland McGrath - 2.6.32.1-13 +- minor utrace update + +* Thu Dec 17 2009 Matthew Garrett 2.6.32.1-12 +- linux-2.6-driver-level-usb-autosuspend.diff: fix so it works properly... +- linux-2.6-fix-btusb-autosuspend.patch: avoid bluetooth connection drops +- linux-2.6-enable-btusb-autosuspend.patch: and default it to on +- linux-2.6-autoload-wmi.patch: autoload WMI drivers + +* Thu Dec 17 2009 Jarod Wilson 2.6.32.1-11 +- Split off onboard decode imon devices into pure input driver, + leaving lirc_imon for the ancient imon devices only +- Fix NULL ptr deref in lirc_serial (#543886) +- Assorted lirc_mceusb fixups suggested by Mauro +- Dropped compat ioctls from lirc_dev, main ioctls should now be + compatible between 32-bit and 64-bit (also at Mauro's suggestion) + +* Wed Dec 16 2009 Roland McGrath 2.6.32.1-10 +- utrace update, now testing the utrace-based ptrace! + +* Mon Dec 14 2009 Kyle McMartin 2.6.32.1-9 +- 2.6.32.1 +- ext4 patches and more... + +* Wed Dec 09 2009 Kyle McMartin 2.6.32-8 +- Add a patch off lkml from krh to fix perf when DEBUG_PERF_USE_VMALLOC + (rhbz#542791) +- Re-enable CONFIG_DEBUG_PERF_USE_VMALLOC on debug kernels. + +* Wed Dec 09 2009 Kyle McMartin 2.6.32-7 +- ext4-fix-insufficient-checks-in-EXT4_IOC_MOVE_EXT.patch: CVE-2009-4131 + fix insufficient permission checking which could result in arbitrary + data corruption by a local unprivileged user. + +* Tue Dec 08 2009 Chuck Ebbert 2.6.32-6 +- Copy fix for #540580 from F-12. + +* Tue Dec 08 2009 Kyle McMartin 2.6.32-5 +- new rpm changes: + - %{PACKAGE_VERSION} -> %{version} + - %{PACKAGE_RELEASE} -> %{release} + +* Tue Dec 08 2009 Kyle McMartin 2.6.32-4 +- Disable CONFIG_DEBUG_PERF_USE_VMALLOC for now, causes issues + on x86_64. (rhbz#542791) + +* Mon Dec 7 2009 Justin M. Forbes 2.6.32-3 +- Allow userspace to adjust kvmclock offset (#530389) + +* Mon Dec 7 2009 Steve Dickson 2.6.32-2 +- Updated the NFS4 pseudo root code to the latest release. + +* Thu Dec 03 2009 Kyle McMartin 2.6.32-1 +- Linux 2.6.32 + +* Wed Dec 02 2009 Kyle McMartin 2.6.32-0.65.rc8.git5 +- 2.6.32-rc8-git5 +- nuke 9p cachefiles fix, upstream. +- SLOW_WORK_PROC was renamed to SLOW_WORK_DEBUG, debugfs instead of procfs. + +* Wed Dec 02 2009 John W. Linville 2.6.32-0.64.rc8.git2 +- ath9k: add fixes suggested by upstream maintainer + +* Wed Dec 02 2009 David Woodhouse 2.6.32-0.63.rc8.git2 +- forward port IOMMU fixes from F-12 for HP BIOS brokenness +- Fix oops with intel_iommu=igfx_off +- agp/intel: Clear full GTT at startup + +* Wed Dec 02 2009 Dave Airlie 2.6.32-0.62.rc8.git2 +- forward port radeon fixes from F-12 + add radeon display port support + +* Mon Nov 30 2009 Kyle McMartin 2.6.32-0.61.rc8.git2 +- fix-9p-fscache.patch: fix build. + +* Mon Nov 30 2009 Kyle McMartin 2.6.32-0.60.rc8.git2 +- 2.6.32-rc8-git2 daily snapshot +- nuke include/generated nuke-age since the patch was reverted upstream +- config changes: + - generic: + +CONFIG_FSCACHE_OBJECT_LIST=y + +CONFIG_SLOW_WORK_PROC=y + +* Mon Nov 30 2009 Kyle McMartin +- drm-i915-fix-sync-to-vbl-when-vga-is-off.patch: add, (rhbz#541670) + +* Sun Nov 29 2009 Kyle McMartin +- linux-2.6-sysrq-c.patch: drop, was made consistent upstream. + +* Sat Nov 28 2009 Jarod Wilson 2.6.32-0.55.rc8.git1 +- add device name to lirc_zilog, fixes issues w/multiple target devices +- add lirc_imon pure input mode support for onboard decode devices + +* Fri Nov 27 2009 Dave Airlie 2.6.32-0.54.rc8.git1 +- attempt to put nouveau back - same patch as F-12 should work + +* Mon Nov 23 2009 Roland McGrath +- Install vmlinux.id file in kernel-devel rpm. + +* Fri Nov 20 2009 Chuck Ebbert 2.6.32-0.52.rc8.git1 +- 2.6.32-rc8-git1 +- Enable CONFIG_MEMORY_HOTPLUG (and HOTREMOVE) on x86_64 + +* Thu Nov 19 2009 Kyle McMartin 2.6.32-0.51.rc7.git2 +- Oops, re-enable debug builds for rawhide... didn't mean to commit that. + +* Thu Nov 19 2009 Kyle McMartin 2.6.32-0.50.rc7.git2 +- Disable FUNCTION_TRACER and DYNAMIC_FTRACE in non-debug builds for + Fedora 13. Some pondering required to see if it's actually worth doing + though. Anecdotal evidence worth half as much as benchmarks. + STACK_TRACER selects FUNCTION_TRACER, so it has to go off too, sadly, + since it hooks every mcount to log the stack depth for the task. + +* Thu Nov 19 2009 Kyle McMartin 2.6.32-0.49.rc7.git2 +- 2.6.32-rc7-git2 + +* Mon Nov 16 2009 Dave Airlie 2.6.32-0.48.rc7.git1 +- backout gpg change now that koji is fixed + +* Sun Nov 15 2009 Chuck Ebbert 2.6.32-0.47.rc7.git1 +- Buildrequire gpg + +* Sun Nov 15 2009 Chuck Ebbert +- Fix oops in VIA Padlock driver. + +* Sun Nov 15 2009 Chuck Ebbert +- Linux 2.6.32-rc7-git1 + +* Fri Nov 13 2009 Chuck Ebbert +- Linux 2.6.32-rc7 + +* Thu Nov 05 2009 Jarod Wilson +- Add --with dbgonly rpmbuild option to build only debug kernels + +* Wed Nov 04 2009 Kyle McMartin +- Make JBD2_DEBUG a toggleable config option. + +* Wed Nov 04 2009 Kyle McMartin 2.6.32-0.39.rc6.git0 +- 2.6.32-rc6, fix for NULL ptr deref in cfg80211. + +* Mon Nov 02 2009 Kyle McMartin 2.6.32-0.39.rc5.git6 +- 2.6.32-rc5-git6 (with sandeen's reversion of "ext4: Remove journal_checksum + mount option and enable it by default") + +* Mon Nov 02 2009 Chuck Ebbert +- 2.6.32-rc5-git5 + +* Tue Oct 27 2009 John W. Linville +- Disable build of prism54 module + +* Tue Oct 27 2009 Dave Airlie +- Get dd command line args correct. + +* Mon Oct 26 2009 Dave Jones +- Make a 20MB initramfs file so rpm gets its diskspace calculations right. (#530778) + +* Sat Oct 23 2009 Chuck Ebbert +- 2.6.32-rc5-git3 +- Drop merged patch: + linux-2.6-virtio_blk-revert-QUEUE_FLAG_VIRT-addition.patch + +* Sat Oct 17 2009 Chuck Ebbert 2.6.32-0.33.rc5.git1 +- 2.6.32-rc5-git1 + +* Fri Oct 16 2009 Chuck Ebbert +- 2.6.32-rc5 +- New config option: CONFIG_VMXNET3=m + +* Wed Oct 14 2009 Chuck Ebbert +- 2.6.32-rc4-git4 + +* Wed Oct 14 2009 Steve Dickson +- Updated the NFS v4 pseudo root patch so it will apply +- Fixed hang during NFS installs (bz 528537) + +* Wed Oct 14 2009 Peter Jones +- Add scsi_register_device_handler to modules.block's symbol list so + we'll have scsi device handlers in installer images. + +* Tue Oct 13 2009 Kyle McMartin +- Always build perf docs, regardless of whether we build kernel-doc. + Seems rather unfair to not ship the manpages half the time. + Also, drop BuildRequires %if when not with_doc, the rules about %if + there are f*!&^ing complicated. + +* Tue Oct 13 2009 Kyle McMartin +- Build perf manpages properly. + +* Tue Oct 13 2009 Dave Airlie +- cleanup some of drm vga arb bits that are upstream + +* Mon Oct 12 2009 Jarod Wilson +- Merge lirc compile fixes into lirc patch +- Refresh lirc patch with additional irq handling fixage +- Fix IR transmit on port 1 of 1st-gen mceusb transceiver +- Support another mouse button variant on imon devices + +* Mon Oct 12 2009 Chuck Ebbert 2.6.32-0.24.rc4.git0 +- Last-minute USB fix from upstream. + +* Sun Oct 11 2009 Chuck Ebbert +- Fix lirc build after header changes. +- Fix bug in lirc interrupt processing. + +* Sun Oct 11 2009 Chuck Ebbert +- Fix up multiple definition of debug options + (EXT4_DEBUG, DEBUG_FORCE_WEAK_PER_CPU) + +* Sun Oct 11 2009 Chuck Ebbert +- 2.6.32-rc4 +- New config options: + CONFIG_BE2ISCSI=m + CONFIG_SCSI_BFA_FC=m + CONFIG_USB_MUSB_HDRC is not set + +* Sun Oct 11 2009 Kyle McMartin +- 2.6.32-rc3-git3 + +* Thu Oct 08 2009 Ben Skeggs +- ppc: compile nvidiafb as a module only, nvidiafb+nouveau = bang! (rh#491308) + +* Wed Oct 07 2009 Dave Jones +- Enable FUNCTION_GRAPH_TRACER on x86-64. + +* Wed Oct 07 2009 Dave Jones +- Disable CONFIG_IRQSOFF_TRACER on srostedt's recommendation. + (Adds unwanted overhead when not in use). + +* Sun Oct 04 2009 Kyle McMartin 2.6.32-0.17.rc3.git0 +- 2.6.32-rc3 (bah, rebase script didn't catch it.) + +* Sun Oct 04 2009 Kyle McMartin +- 2.6.32-rc1-git7 +- [x86,x86_64] ACPI_PROCESSOR_AGGREGATOR=m + +* Mon Sep 28 2009 Kyle McMartin +- 2.6.32-rc1 +- rebased crash-driver patchset, ia64_ksyms.c conflicts. move x86 crash.h + file to the right place. +- full changelog forthcoming & to fedora-kernel-list. + +* Mon Sep 28 2009 Kyle McMartin +- sick of rejects. + +* Mon Sep 28 2009 Chuck Ebbert +- Fix up some items missing in make debug vs. make release, + rearrange so the options are in the same order. +- Add new debug options: + CONFIG_EXT4_DEBUG + CONFIG_DEBUG_FORCE_WEAK_PER_CPU + +* Sun Sep 27 2009 Kyle McMartin +- Must now make mrproper after each config pass, due to Kbuild + stashing away the $ARCH variable. + +* Sun Sep 27 2009 Kyle McMartin +- 2.6.31-git18 +- rebased: + - hdpvr-ir-enable.patch + - linux-2.6-build-nonintconfig.patch + - linux-2.6-debug-sizeof-structs.patch + - linux-2.6-debug-vm-would-have-oomkilled.patch + - linux-2.6-execshield.patch + - linux-2.6-makefile-after_link.patch + - linux-2.6-serial-460800.patch + - linux-2.6-utrace.patch + - via-hwmon-temp-sensor.patch +- merged: + - linux-2.6-tracehook.patch + - linux-2.6-die-closed-source-bios-muppets-die.patch + - linux-2.6-intel-iommu-updates.patch + - linux-2.6-ksm.patch + - linux-2.6-ksm-updates.patch + - linux-2.6-ksm-fix-munlock.patch + - linux-2.6-vga-arb.patch + - v4l-dvb-fix-cx25840-firmware-loading.patch + - linux-2.6-rtc-show-hctosys.patch + +* Fri Sep 18 2009 Dave Jones +- %ghost the dracut initramfs file. + +* Thu Sep 17 2009 Hans de Goede +- Now that we have %%post generation of dracut images we do not need to + Require dracut-kernel anymore + +* Thu Sep 17 2009 Chuck Ebbert +- Disable drm-nouveau too -- it won't build without other + drm updates. + +* Wed Sep 16 2009 Roland McGrath +- Remove workaround for gcc bug #521991, now fixed. + +* Tue Sep 15 2009 Kyle McMartin +- 2.6.31-git4 +- rebased: + - linux-2.6-execshield.patch: split paravirt_types.h + - linux-2.6-buildnonintconfig.patch +- disabled: + - ksm, drm. +- merged: + - linux-2.6-kvm-pvmmu-do-not-batch-pte-updates-from-interrupt-context.patch + - linux-2.6-kvm-vmx-check-cpl-before-emulating-debug-register-access.patch + - linux-2.6-use-__pa_symbol-to-calculate-address-of-C-symbol.patch + - linux-2.6-xen-stack-protector-fix.patch + - linux-2.6-bluetooth-autosuspend.diff + - hid-ignore-all-recent-imon-devices.patch +- config changes: + - arm: + - CONFIG_HIGHPTE off, seems safer this way. + - generic: + - RDS_RDMA/RDS_TCP=m + - SCSI_PMCRAID=m + - WLAN=y, CFG80211_DEFAULT_PS=y, NL80211_TESTMODE off. + - WL12XX=m + - B43_PHY_LP=y + - BT_MRVL=m + - new MISDN stuff modular. + - sparc: + - enable PERF_COUNTERS & EVENT_PROFILE + - ppc: + - XILINX_EMACSLITE=m + +* Mon Sep 14 2009 Chuck Ebbert +- 2.6.31-git2 +- Drop merged patches: + sched-introduce-SCHED_RESET_ON_FORK-scheduling-policy-flag.patch + linux-2.6-nfs4-ver4opt.patch + linux-2.6-alsa-improve-hda-powerdown.patch + alsa-tell-user-that-stream-to-be-rewound-is-suspended.patch + linux-2.6-ahci-export-capabilities.patch +- New s390 config option: + CONFIG_SCLP_ASYNC=m +- New generic config options: + CONFIG_ATA_VERBOSE_ERROR=y + CONFIG_PATA_RDC=m + CONFIG_SOUND_OSS_CORE_PRECLAIM=y + CONFIG_SND_HDA_PATCH_LOADER=y + CONFIG_SND_HDA_CODEC_CIRRUS=y + CONFIG_OPROFILE_EVENT_MULTIPLEX=y + CONFIG_CRYPTO_VMAC=m + CONFIG_CRYPTO_GHASH=m +- New debug option: + CONFIG_DEBUG_CREDENTIALS=y in debug kernels + +* Mon Sep 14 2009 Steve Dickson +- Added support for -o v4 mount parsing + +* Fri Sep 11 2009 Dave Jones +- Apply NX/RO to modules + +* Fri Sep 11 2009 Dave Jones +- Mark kernel data section as NX + +* Fri Sep 11 2009 Ben Skeggs +- nouveau: bring in Matthew Garret's initial switchable graphics support + +* Fri Sep 11 2009 Ben Skeggs +- nouveau: fixed use of strap-based panel mode when required (rh#522649) +- nouveau: temporarily block accel on NVAC chipsets (rh#522361, rh#522575) + +* Thu Sep 10 2009 Matthew Garrett +- linux-2.6-ahci-export-capabilities.patch: Backport from upstream +- linux-2.6-rtc-show-hctosys.patch: Export the hctosys state of an rtc +- linux-2.6-rfkill-all.patch: Support for keys that toggle all rfkill state + +* Thu Sep 10 2009 Ben Skeggs +- drm-nouveau.patch: add some scaler-only modes for LVDS, GEM/TTM fixes + +* Wed Sep 09 2009 Dennis Gilmore 2.6.31-2 +- touch the dracut initrd file when using %%{with_dracut} + +* Wed Sep 09 2009 Chuck Ebbert 2.6.31-1 +- Linux 2.6.31 + +* Wed Sep 09 2009 Chuck Ebbert +- Enable VXpocket and PDaudioCF PCMCIA sound drivers. + +* Wed Sep 09 2009 Hans de Goede +- Move to %%post generation of dracut initrd, because of GPL issues surrounding + shipping a prebuild initrd +- Require grubby >= 7.0.4-1, for %%post generation + +* Wed Sep 9 2009 Steve Dickson +- Updated the NFS4 pseudo root code to the latest release. + +* Wed Sep 09 2009 Justin M. Forbes +- Revert virtio_blk to rotational mode. (#509383) + +* Wed Sep 09 2009 Dave Airlie 2.6.31-0.219.rc9.git +- uggh lost nouveau bits in page flip + +* Wed Sep 09 2009 Dave Airlie 2.6.31-0.218.rc9.git2 +- fix r600 oops with page flip patch (#520766) + +* Wed Sep 09 2009 Ben Skeggs +- drm-nouveau.patch: fix display resume on pre-G8x chips + +* Wed Sep 09 2009 Ben Skeggs +- drm-nouveau.patch: add getparam to know using tile_flags is ok for scanout + +* Wed Sep 09 2009 Chuck Ebbert +- 2.6.31-rc9-git2 + +* Wed Sep 9 2009 Roland McGrath 2.6.31-0.214.rc9.git1 +- compile with -fno-var-tracking-assignments, work around gcc bug #521991 + +* Wed Sep 09 2009 Dave Airlie 2.6.31-0.213.rc9.git1 +- fix two bugs in r600 kms, fencing + mobile lvds + +* Tue Sep 08 2009 Ben Skeggs 2.6.31-0.212.rc9.git1 +- drm-nouveau.patch: fix ppc build + +* Tue Sep 08 2009 Ben Skeggs 2.6.31-0.211.rc9.git1 +- drm-nouveau.patch: more misc fixes + +* Tue Sep 08 2009 Dave Airlie 2.6.31-0.210.rc9.git1 +- drm-page-flip.patch: rebase again + +* Tue Sep 08 2009 Dave Airlie 2.6.31-0.209.rc9.git1 +- drm-next.patch: fix r600 signal interruption return value + +* Tue Sep 08 2009 Ben Skeggs 2.6.31-0.208.rc9.git1 +- drm-nouveau.patch: latest upstream + rebase onto drm-next + +* Tue Sep 08 2009 Dave Airlie 2.6.31-0.207.rc9.git1 +- drm-vga-arb.patch: update to avoid lockdep + add r600 support + +* Tue Sep 08 2009 Dave Airlie 2.6.31-0.206.rc9.git1 +- drm: rebase to drm-next - r600 accel + kms should start working now + +* Mon Sep 07 2009 Chuck Ebbert 2.6.31-0.205.rc9.git1 +- 2.6.31-rc9-git1 +- Temporarily hack the drm-next patch so it still applies; the result + should still be safe to build. + +* Sat Sep 05 2009 Chuck Ebbert 2.6.31-0.204.rc9 +- 2.6.31-rc9 + +* Fri Sep 04 2009 Chuck Ebbert 2.6.31-0.203.rc8.git2 +- Fix kernel build errors when building firmware by removing the + .config file before that step and restoring it afterward. + +* Thu Sep 03 2009 Adam Jackson +- drm-ddc-caching-bug.patch: Empty the connector's mode list when it's + disconnected. + +* Thu Sep 03 2009 Jarod Wilson +- Update hdpvr and lirc_zilog drivers for 2.6.31 i2c + +* Thu Sep 03 2009 Justin M.Forbes +- Fix xen guest with stack protector. (#508120) +- Small kvm fixes. + +* Wed Sep 02 2009 Adam Jackson 2.6.31-0.199.rc8.git2 +- drm-intel-pm.patch: Disable by default, too flickery on too many machines. + Enable with i915.powersave=1. + +* Wed Sep 02 2009 Dave Jones +- Add missing scriptlet dependancy. (#520788) + +* Tue Sep 01 2009 Adam Jackson +- Make DRM less chatty about EDID failures. No one cares. + +* Tue Sep 01 2009 Chuck Ebbert +- 2.6.31-rc8-git2 +- Blank out drm-intel-next: entire contents are now upstream. + +* Tue Sep 01 2009 Dave Jones +- Make firmware buildarch noarch. (Suggested by drago01 on irc) + +* Tue Sep 01 2009 Jarod Wilson +- Fix up lirc_zilog to enable functional IR transmit and receive + on the Hauppauge HD PVR +- Fix audio on PVR-500 when used in same system as HVR-1800 (#480728) + +* Sun Aug 30 2009 Chuck Ebbert +- 2.6.31-rc8-git1 +- Drop linux-2.6-inotify-accounting.patch, merged upstream. + +* Sun Aug 30 2009 Jarod Wilson +- fix lirc_imon oops on older devices w/o tx ctrl ep (#520008) + +* Fri Aug 28 2009 Eric Paris 2.6.31-0.190.rc8 +- fix inotify length accounting and send inotify events + +* Fri Aug 28 2009 David Woodhouse +- Enable Solos DSL driver + +* Fri Aug 28 2009 Chuck Ebbert +- 2.6.31-rc8 + +* Thu Aug 27 2009 Chuck Ebbert 2.6.31-0.185.rc7.git6 +- 2.6.31-rc7-git6 +- Drop patch merged upstream: + xen-fb-probe-fix.patch + +* Thu Aug 27 2009 Adam Jackson +- drm-rv710-ucode-fix.patch: Treat successful microcode load on RV710 as, + you know, success. (#519718) + +* Thu Aug 27 2009 Chuck Ebbert +- 2.6.31-rc7-git5 +- Drop patch linux-2.6-ima-leak.patch, now merged upstream. + +* Wed Aug 26 2009 Jarod Wilson +- Fix up hdpvr ir enable patch for use w/modular i2c (David Engel) + +* Wed Aug 26 2009 Eric Paris +- fix iint_cache leak in IMA code + drop the ima=0 patch + +* Wed Aug 26 2009 Justin M. Forbes +- Fix munlock with KSM (#516909) +- Re-enable KSM + +* Wed Aug 26 2009 Chuck Ebbert +- 2.6.31-rc7-git4 +- Drop patches merged upstream: + xen-x86-fix-stackprotect.patch + xen-x86-no-stackprotect.patch + +* Wed Aug 26 2009 Adam Jackson +- drm-intel-next.patch: Update, various output setup fixes. + +* Wed Aug 26 2009 David Woodhouse +- Make WiMAX modular (#512070) + +* Tue Aug 25 2009 Kyle McMartin +- allow-disabling-ima.diff: debugging patch... adds ima=0 kernel + param to disable initialization of IMA. + +* Tue Aug 25 2009 Ben Skeggs 2.6.31-0.174.rc7.git2 +- drm-nouveau.patch: upstream update, pre-nv50 tv-out + misc fixes + +* Tue Aug 25 2009 Chuck Ebbert 2.6.31-0.173.rc7.git2 +- Fix Xen boot (#508120) + +* Tue Aug 25 2009 Dave Airlie +- pull in drm-next tree + rebase around it + +* Mon Aug 24 2009 Chuck Ebbert +- 2.6.31-rc7-git2 + +* Mon Aug 24 2009 Chuck Ebbert +- 2.6.31-rc7-git1 + +* Sat Aug 22 2009 Chuck Ebbert +- 2.6.31-rc7 + +* Thu Aug 20 2009 Mark McLoughlin +- Disable LZMA for xen (#515831) + +* Thu Aug 20 2009 Chuck Ebbert +- 2.6.31-rc6-git5 +- Fix up drm-r600-kms.patch +- Drop fix-perf-make-man-failure.patch + +* Wed Aug 19 2009 Chuck Ebbert +- 2.6.31-rc6-git5 +- Revert linux-2.6-debug-vm-would-have-oomkilled.patch to v1.2 + because upstream changes to oom-kill.c were all reverted. + +* Tue Aug 18 2009 Kyle McMartin +- Fix up perf so that it builds docs now that they are fixed. +- with_docs disables perf docs too. be warned. (logic is that the + build deps are (mostly) the same, so if you don't want one, odds are...) + +* Tue Aug 18 2009 Dave Jones +- 2.6.31-rc6-git3 + +* Mon Aug 17 2009 Dave Jones 2.6.31-0.161.rc6.git2 +- 2.6.31-rc6-git2 + +* Mon Aug 17 2009 Chuck Ebbert +- Stop generating the (unused) ppc64-kdump.config file. + +* Mon Aug 17 2009 Jarod Wilson +- Add new lirc driver for built-in ENE0100 device on some laptops + +* Sun Aug 16 2009 Kyle McMartin 2.6.31-0.158.rc6 +- Improve the perf script so it prints something helpful if the + perf binary doesn't exist. + +* Sat Aug 15 2009 Dave Jones 2.6.31-0.157.rc6 +- Disable KSM patches on a hunch. Chasing the "encrypted VGs don't work" bug. + +* Fri Aug 14 2009 Dave Jones 2.6.31-0.155.rc6 +- 2.6.31-rc6 + +* Wed Aug 12 2009 Kyle McMartin +- fix perf. +- move perf to perf.$ver instead of perf-$ver... + +* Wed Aug 12 2009 Dennis Gilmore +- Obsolete kernel-smp on sparc64 +- Require grubby >= 7.0.2-1 since thats what introduces the dracut options we use + +* Wed Aug 12 2009 Kristian Høgsberg +- Fix drm-page-flip.patch to not break radeon kms and to not reset + crtc offset into fb on flip. + +* Wed Aug 12 2009 Adam Jackson +- Update drm-intel-next patch + +* Tue Aug 11 2009 Dennis Gilmore - 2.6.31-0.149.rc5.git3 +- disable building the -smp kernel on sparc64 +- disable building kernel-perf on sparc64 syscalls not supported + +* Tue Aug 11 2009 Eric Paris +- Enable config IMA + +* Tue Aug 11 2009 Ben Skeggs +- nouveau: various cleanups and fixes + more sanity checking in dma paths + +* Mon Aug 10 2009 Jarod Wilson +- Add new device ID to lirc_mceusb (#512483) +- Fix some lockdep false positives +- Add support for setting and enabling iMON clock via sysfs +- Add tunable pad threshold support to lirc_imon +- Add new pseudo-IR protocl to lirc_imon for universals w/o a pad +- Fix mouse device support on older iMON devices + +* Mon Aug 10 2009 David Woodhouse 2.6.31-0.145.rc5.git3 +- Merge latest Intel IOMMU fixes and BIOS workarounds, re-enable by default. + +* Sun Aug 09 2009 Kyle McMartin +- btusb autosuspend: fix build on !CONFIG_PM by stubbing out + suspend/resume methods. + +* Sat Aug 08 2009 Dennis Gilmore 2.6.31-0.141.rc5.git3 +- disable kgdb on sparc64 uni-processor kernel +- set max cpus to 256 on sparc64 +- enable AT keyboard on sparc64 + +* Fri Aug 07 2009 Justin M. Forbes +- Apply KSM updates from upstream + +* Fri Aug 07 2009 Hans de Goede +- When building a dracut generic initrd tell new-kernel-pkg to use that + instead of running mkinitrd + +* Fri Aug 07 2009 Dave Airlie 2.6.31-0.139.rc5.git3 +- drm-r600-kms.patch - update r600 KMS +- drm-radeon-fixes.patch - patches for queue to Linus + +* Thu Aug 06 2009 Justin M. Forbes 2.6.31-0.138.rc5.git3 +- Fix kvm virtio_blk errors (#514901) + +* Thu Aug 06 2009 Adam Jackson +- Hush DRM vblank warnings, they're constant (and harmless) under DRI2. + +* Thu Aug 06 2009 Dave Airlie 2.6.31.0.134.rc5.git3 +- fixup vga arb warning at startup and handover between gpus + +* Thu Aug 06 2009 Kyle McMartin 2.6.31.0.133.rc5.git3 +- die-floppy-die.patch: it's the 21st century, let's not rely on + steam powered technology. + +* Wed Aug 05 2009 Dave Airlie 2.6.31.0.132.rc5.git3 +- revert-ftrace-powerpc-snafu.patch - fix ppc build + +* Wed Aug 05 2009 Ben Skeggs +- nouveau: respect nomodeset + +* Wed Aug 05 2009 Chuck Ebbert +- Fix /usr/sbin/perf script. (#515494) + +* Wed Aug 05 2009 Dave Jones +- Fix shift in pci cacheline size printk. + +* Wed Aug 05 2009 Dave Airlie 2.6.31.0.128.rc5.git3 +- 2.6.31-rc5-git3 +- drop cpufreq + set memory fixes + +* Wed Aug 05 2009 Dave Airlie +- Add Jeromes initial r600 kms work. +- rebase arb patch + +* Tue Aug 04 2009 Kyle McMartin +- alsa-tell-user-that-stream-to-be-rewound-is-suspended.patch: apply patch + destined for 2.6.32, requested by Lennart. + +* Tue Aug 04 2009 Ben Skeggs +- nouveau: more code share between nv50/ +- update VGA arb patches again + +* Mon Aug 03 2009 Adam Jackson +- Update intel drm from anholt's tree +- Rebase drm-intel-pm.patch to match +- Drop gen3 fb hack, merged +- Drop previous watermark setup change + +* Mon Aug 03 2009 Dave Jones 2.6.31-0.122.rc5.git2 +- 2.6.31-rc5-git2 + +* Mon Aug 03 2009 Adam Jackson +- (Attempt to) fix watermark setup on Intel 9xx parts. + +* Mon Aug 03 2009 Jarod Wilson +- make usbhid driver ignore all recent SoundGraph iMON devices, so the + lirc_imon driver can grab them instead + +* Mon Aug 03 2009 Dave Airlie +- update VGA arb patches + +* Sat Aug 01 2009 David Woodhouse 2.6.31-0.118.rc5 +- Fix boot failures on ppc32 (#514010, #505071) + +* Fri Jul 31 2009 Kyle McMartin 2.6.31-0.117.rc5 +- Linux 2.6.31-rc5 + +* Fri Jul 31 2009 Matthew Garrett +- linux-2.6-dell-laptop-rfkill-fix.patch: Fix up Dell rfkill + +* Fri Jul 31 2009 Ben Skeggs +- nouveau: build against 2.6.31-rc4-git6, fix script parsing on some G8x chips + +* Thu Jul 30 2009 Chuck Ebbert +- Linux 2.6.31-rc4-git6 + New config item: CONFIG_BATTERY_DS2782 is not set +- Add last-minute set_memory_wc() fix from LKML. + +* Thu Jul 30 2009 Matthew Garrett +- drm-intel-pm.patch: Don't reclock external outputs. Increase the reduced + clock slightly to avoid upsetting some hardware. Disable renderclock + adjustment for the moment - it's breaking on some hardware. + +* Thu Jul 30 2009 Ben Skeggs +- nouveau: another DCB 1.5 entry, G80 corruption fixes, small +- fix VGA ARB + kms + +* Wed Jul 29 2009 Dave Jones +- Add support for dracut. (Harald Hoyer) + +* Wed Jul 29 2009 Ben Skeggs +- drm-nouveau.patch: nv50/nva0 tiled scanout fixes, nv40 kms fixes + +* Wed Jul 29 2009 Chuck Ebbert +- Linux 2.6.31-rc4-git3 +- Drop linux-2.6-ecryptfs-overflow-fixes.patch, merged upstream now. + +* Wed Jul 29 2009 Dave Airlie +- update VGA arb patches + +* Tue Jul 28 2009 Adam Jackson +- Remove the pcspkr modalias. If you're still living in 1994, load it + by hand. + +* Tue Jul 28 2009 Eric Sandeen 2.6.31-0.102.rc4.git2 +- Fix eCryptfs overflow issues (CVE-2009-2406, CVE-2009-2407) + +* Tue Jul 28 2009 Kyle McMartin 2.6.31-0.101.rc4.git2 +- 2.6.31-rc4-git2 +- rebase linux-2.6-fix-usb-serial-autosuspend.diff +- config changes: + - USB_GSPCA_SN9C20X=m (_EVDEV=y) + +* Tue Jul 28 2009 Ben Skeggs +- drm-nouveau.patch: cleanup userspace API, various bugfixes. + Looks worse than it is, register macros got cleaned up, which + touches pretty much everywhere.. + +* Mon Jul 27 2009 Adam Jackson +- Warn quieter about not finding PCI bus parents for ROM BARs, they're + not usually needed and there's nothing you can do about it anyway. + +* Mon Jul 27 2009 Matthew Garrett +- linux-2.6-alsa-improve-hda-powerdown.patch - attempt to reduce audio glitches + caused by HDA powerdown +- disable CONFIG_DEBUG_KOBJECT again for now, since it produces huge dmesg spew + +* Mon Jul 27 2009 Dave Airlie +- update vga arb code + +* Mon Jul 27 2009 Matthew Garrett +- drm-intel-pm.patch - Add runtime PM for Intel graphics + +* Fri Jul 24 2009 Kristian Høgsberg +- Add drm-page-flip.patch to support vsynced page flipping on intel + chipsets. +- Really add patch. +- Fix patch to not break nouveau. + +* Fri Jul 24 2009 Chuck Ebbert +- Enable CONFIG_DEBUG_KOBJECT in debug kernels. (#513606) + +* Thu Jul 23 2009 Kyle McMartin +- perf BuildRequires binutils-devel now. + +* Thu Jul 23 2009 Justin M. Forbes +- Add KSM support + +* Thu Jul 23 2009 Kyle McMartin 2.6.31-0.87.rc4 +- Linux 2.6.31-rc4 +- config changes: + - USB_CDC_PHONET=m [all] + - EVENT_PROFILE=y [i386, x86_64, powerpc, s390] + +* Wed Jul 22 2009 Tom "spot" Callaway +- We have to override the new %%install behavior because, well... the kernel is special. + +* Wed Jul 22 2009 Dave Jones +- 2.6.31-rc3-git5 + +* Wed Jul 22 2009 Ben Skeggs 2.6.31-0.82.rc3.git4 +- Enable KMS for nouveau + +* Wed Jul 22 2009 Ben Skeggs +- Update nouveau from upstream (initial suspend/resume + misc bugfixes) + +* Mon Jul 20 2009 Adam Jackson +- Disable VGA arbiter patches for a moment + +* Mon Jul 20 2009 Adam Jackson +- Revive 4k framebuffers for intel gen3 + +* Mon Jul 20 2009 Dave Jones 2.6.31-0.78.rc3.git4 +- Enable CONFIG_RTC_HCTOSYS (#489494) + +* Mon Jul 20 2009 Dave Jones 2.6.31-0.77.rc3.git4 +- Don't build 586 kernels any more. + +* Sun Jul 19 2009 Dave Jones 2.6.31-0.75.rc3.git4 +- build a 'full' package on i686 (Bill Nottingham) + +* Sun Jul 19 2009 Dave Jones 2.6.31-0.74.rc3.git4 +- 2.6.31-rc3-git4 + +* Sat Jul 18 2009 Matthew Garrett +- linux-2.6-driver-level-usb-autosuspend.diff - allow drivers to enable autopm +- linux-2.6-fix-usb-serial-autosuspend.diff - fix generic usb-serial autopm +- linux-2.6-qcserial-autosuspend.diff - enable autopm by default on qcserial +- linux-2.6-bluetooth-autosuspend.diff - enable autopm by default on btusb +- linux-2.6-usb-uvc-autosuspend.diff - enable autopm by default on uvc + +* Thu Jul 16 2009 Chuck Ebbert +- 2.6.31-rc3-git3 + +* Thu Jul 16 2009 Matthew Garrett +- linux-2.6-defaults-aspm.patch - default ASPM to on for PCIe >= 1.1 hardware + +* Thu Jul 16 2009 Dave Airlie 2.6.31-0.69.rc3 +- linux-2.6-vga-arb.patch - add VGA arbiter. +- drm-vga-arb.patch - add VGA arbiter support to drm + +* Tue Jul 14 2009 Kyle McMartin 2.6.31-0.68-rc3 +- 2.6.31-rc3 +- config changes: + - RTL8192SU is not set, (staging) + +* Mon Jul 13 2009 Kyle McMartin 2.6.31-0.67.rc2.git9 +- 2.6.31-rc2-git9 +- config changes: + - BLK_DEV_OSD=m + +* Mon Jul 13 2009 Ben Skeggs +- drm-nouveau.patch: update from upstream + +* Fri Jul 10 2009 Chuck Ebbert +- 2.6.31-rc2-git6 +- Drop dmadebug-spinlock patch -- merged upstream. + +* Fri Jul 10 2009 Dave Jones 2.6.31-0.64.rc2.git5 +- Don't jump through hoops that ppc powerbooks have to on sensible systems + in cpufreq_suspend. + +* Fri Jul 10 2009 Dave Jones +- 2.6.31-rc2-git5 + +* Thu Jul 09 2009 Dave Jones 2.6.31-0.62.rc2.git4 +- Use correct spinlock initialization in dma-debug + +* Thu Jul 09 2009 Chuck Ebbert 2.6.31-0.61.rc2.git4 +- 2.6.31-rc2-git4 + +* Thu Jul 09 2009 Jarod Wilson +- Enable IR receiver on the Hauppauge HD PVR +- Trim the changelog, axing everything before 2.6.29 (see cvs + if you still really want to see that far back) + +* Wed Jul 08 2009 Dave Jones +- Enable a bunch of debugging options that were missed somehow. + +* Wed Jul 08 2009 Kyle McMartin +- Bump NR_CPUS on x86_64 to 512. + +* Wed Jul 08 2009 Adam Jackson +- drm-no-gem-on-i8xx.patch: Drop, intel 2D driver requires GEM now. This + should be entertaining. + +* Wed Jul 08 2009 Kyle McMartin +- First cut of /usr/sbin/perf wrapper script and 'perf' + subpackage. + +* Wed Jul 08 2009 Kyle McMartin 2.6.31-0.54.rc2.git2 +- Rebase and re-apply all the Fedora-specific linux-2.6-debug-* + patches. +- Cull a bunch of upstreamed patches from the spec. + +* Wed Jul 08 2009 Steve Dickson +- Added NFSD v4 dynamic pseudo root patch which allows + NFS v3 exports to be mounted by v4 clients. + +* Tue Jul 07 2009 Jarod Wilson +- See if we can't make lirc_streamzap behave better... (#508952) + +* Tue Jul 07 2009 Chuck Ebbert 2.6.31-0.47.rc2.git2 +- 2.6.31-rc2-git2 + +* Tue Jul 07 2009 Jarod Wilson +- Make lirc_i2c actually work with 2.6.31 i2c + +* Mon Jul 06 2009 Chuck Ebbert +- Use LZMA for kernel compression on X86. + +* Mon Jul 06 2009 Jarod Wilson +- Hack up lirc_i2c and lirc_zilog to compile with 2.6.31 i2c + changes. The drivers might not actually be functional now, but + at least they compile again. Will fix later, if need be... + +* Sat Jul 04 2009 Dave Jones 2.6.31-0.42.rc2 +- 2.6.31-rc2 + +* Sat Jul 04 2009 Chuck Ebbert +- 2.6.31-rc1-git11 + +* Fri Jul 03 2009 Hans de Goede +- Disable v4l1 ov511 and quickcam_messenger drivers (obsoleted by + v4l2 gspca subdrivers) + +* Thu Jul 02 2009 Kyle McMartin 2.6.31-0.39.rc1.git9 +- 2.6.31-rc1-git9 +- linux-2.6-dm-fix-exstore-search.patch: similar patch merged upstream. + +* Tue Jun 30 2009 Chuck Ebbert 2.6.31-0.38.rc1.git7 +- 2.6.31-rc1-git7 + +* Tue Jun 30 2009 Dave Jones 2.6.31-0.37.rc1.git5 +- Disable kmemleak. Way too noisy, and not finding any real bugs. + +* Tue Jun 30 2009 Ben Skeggs +- drm-nouveau.patch: match upstream + +* Mon Jun 29 2009 Chuck Ebbert 2.6.31-0.35.rc1.git5 +- 2.6.31-rc1-git5 +- CONFIG_LEDS_LP3944=m + +* Mon Jun 29 2009 Chuck Ebbert +- Try to fix the dm overlay bug for real (#505121) + +* Sat Jun 27 2009 Ben Skeggs 2.6.31-0.33.rc1.git2 +- drm-nouveau.patch: fix conflicts from 2.6.31-rc1-git2 + +* Fri Jun 26 2009 Dave Jones 2.6.31-0.31.rc1.git2 +- Further improvements to kmemleak + +* Fri Jun 26 2009 Dave Jones 2.6.31-0.30.rc1.git2 +- 2.6.31-rc1-git2 + +* Fri Jun 26 2009 Ben Skeggs +- drm-nouveau.patch: latest upstream + reenable + +* Thu Jun 25 2009 Dave Jones 2.6.31-0.29.rc1 +- Make kmemleak scan process stacks by default. + Should reduce false positives (which does also increase false negatives, + but that's at least less noisy) + +* Wed Jun 24 2009 Kyle McMartin 2.6.31-0.28.rc1 +- 2.6.31-rc1 +- linux-2.6-utrace.patch: rebase on kernel/Makefile changes +- config changes: + - generic: + - CONFIG_DM_LOG_USERSPACE=m + - CONFIG_DM_MULTIPATH_QL=m + - CONFIG_DM_MULTIPATH_ST=m + - CONFIG_BATTERY_MAX17040=m + - CONFIG_I2C_DESIGNWARE is off (depends on clk.h) + +* Wed Jun 24 2009 Kyle McMartin +- Move perf to /usr/libexec/perf-$KernelVer. + +* Wed Jun 24 2009 Kyle McMartin +- config changes: + - generic: + - CONFIG_SCSI_DEBUG=m (was off, requested by davidz) + +* Wed Jun 24 2009 Dave Jones 2.6.31-0.22.rc0.git22 +- 2.6.30-git22 + +* Tue Jun 23 2009 Dave Jones 2.6.31-0.22.rc0.git20 +- 2.6.30-git20 + +* Mon Jun 22 2009 Kyle McMartin 2.6.31-0.24.rc0.git18 +- Enable tools/perf, installed as /bin/perf-$KernelVer. Docs and a /bin/perf + wrapper come next if this builds ok. + +* Mon Jun 22 2009 Kyle McMartin +- sched-introduce-SCHED_RESET_ON_FORK-scheduling-policy-flag.patch: pull in + two fixes from Mike Galbraith from tip.git + +* Sun Jun 21 2009 Dave Jones 2.6.31-0.21.rc0.git18 +- Add patch to possibly fix the pktlen problem on via-velocity. + +* Sun Jun 21 2009 Dave Jones 2.6.31-0.20.rc0.git18 +- 2.6.30-git18 + VIA crypto & mmc patches now upstream. + +* Sun Jun 21 2009 Dave Jones +- Determine cacheline sizes in a generic manner. + +* Sun Jun 21 2009 Chuck Ebbert 2.6.31-0.18.rc0.git17 +- 2.6.30-git17 +- Config changes: + - powerpc32-generic + CONFIG_PERF_COUNTERS=y + - generic + CONFIG_KEYBOARD_LM8323 is not set + CONFIG_MOUSE_SYNAPTICS_I2C=m + CONFIG_TOUCHSCREEN_EETI=m + CONFIG_TOUCHSCREEN_W90X900=m +- Dropped agp-set_memory_ucwb.patch, all fixed upstream now. + +* Sat Jun 20 2009 Kyle McMartin 2.6.31.0.17.rc0.git15 +- config changes: + - ppc generic: + - CONFIG_PPC_DISABLE_WERROR=y (switched... chrp fails otherwise, stack + frame size.) + +* Sat Jun 20 2009 Kyle McMartin 2.6.31.0.16.rc0.git15 +- 2.6.30-git15 +- config changes: + - generic: + - CONFIG_LBDAF=y + - staging: + - CONFIG_USB_SERIAL_QUATECH2 is not set + - CONFIG_VT6655 is not set + - CONFIG_USB_CPC is not set + - CONFIG_RDC_17F3101X is not set + - CONFIG_FB_UDL is not set + - ppc32: + - CONFIG_KMETER1=y + - ppc generic: + - CONFIG_PPC_DISABLE_WERROR is not set +- lirc disabled due to i2c detach_client removal. + +* Sat Jun 20 2009 Kyle McMartin +- sched-introduce-SCHED_RESET_ON_FORK-scheduling-policy-flag.patch: add, + queued in tip/sched/core (ca94c442535a44d508c99a77e54f21a59f4fc462) + +* Fri Jun 19 2009 Kyle McMartin 2.6.31.0.15.rc0.git14 +- Fix up ptrace, hopefully. Builds on x86_64 at least. + +* Fri Jun 19 2009 Chuck Ebbert +- linux-2.6-tip.git-203abd67b75f7714ce98ab0cdbd6cfd7ad79dec4.patch + Fixes oops on boot with qemu (#507007) + +* Fri Jun 19 2009 Kyle McMartin 2.6.31-0.13.rc0.git14 +- 2.6.30-git14 + +* Fri Jun 19 2009 Chuck Ebbert +- Fix up the via-sdmmc and via-hwmon-temp-sensor patches. +- Drop VIA Padlock patches merged upstream: + via-rng-enable-64bit.patch + via-padlock-10-enable-64bit.patch + via-padlock-20-add-x86-dependency.patch + +* Thu Jun 18 2009 Kyle McMartin 2.6.31-0.11.rc0.git13 +- 2.6.30-git13 +- config changes: + - arm: + - CONFIG_UACCESS_WITH_MEMCPY is not set + - i686-PAE: + - CONFIG_XEN_DEV_EVTCHN=m + - CONFIG_XEN_SYS_HYPERVISOR=y + - ia64: + - CONFIG_RCU_FANOUT=64 + - nodebug: + - CONFIG_DEBUG_KMEMLEAK is not set + - CONFIG_DEBUG_KMEMLEAK_TEST=m + - powerpc: + - CONFIG_CAN_SJA1000_OF_PLATFORM=m + - CONFIG_PPC_EMULATED_STATS=y + - CONFIG_SWIOTLB=y + - CONFIG_RDS is not set (broken on ppc32) + - powerpc32: + - CONFIG_RCU_FANOUT=32 + - powerpc64: + - CONFIG_RCU_FANOUT=64 + - CONFIG_PERF_COUNTERS=y + - s390x: + - CONFIG_RCU_FANOUT=64 + - CONFIG_SECCOMP=y + - CONFIG_PM=y + - CONFIG_HIBERNATION=y + - CONFIG_PM_STD_PARTITION="/dev/jokes" + - sparc64: + - CONFIG_RCU_FANOUT=64 + - x86: + - CONFIG_RCU_FANOUT=32 + - CONFIG_IOMMU_STRESS is not set + - CONFIG_PERF_COUNTERS=y + - CONFIG_X86_OLD_MCE is not set + - CONFIG_X86_MCE_INTEL=y + - CONFIG_X86_MCE_AMD=y + - CONFIG_X86_ANCIENT_MCE is not set + - CONFIG_X86_MCE_INJECT is not set + - x86_64: + - CONFIG_EDAC_AMD64=m + - CONFIG_EDAC_AMD64_ERROR_INJECTION is not set + - CONFIG_XEN_DEV_EVTCHN=m + - CONFIG_XEN_SYS_HYPERVISOR=y + - CONFIG_RCU_FANOUT=64 + - CONFIG_IOMMU_STRESS is not set + - CONFIG_PERF_COUNTERS=y + - CONFIG_X86_MCE_INJECT is not set + - generic: + - CONFIG_RCU_FANOUT=32 + - CONFIG_MMC_SDHCI_PLTFM=m + - CONFIG_MMC_CB710=m + - CONFIG_CB710_CORE=m + - CONFIG_CB710_DEBUG is not set + - CONFIG_SCSI_MVSAS_DEBUG is not set + - CONFIG_SCSI_BNX2_ISCSI=m + - CONFIG_NETFILTER_XT_MATCH_OSF=m + - CONFIG_RFKILL_INPUT=y (used to be =m, which was invalid) + - CONFIG_DE2104X_DSL=0 + - CONFIG_KS8842 is not set + - CONFIG_CFG80211_DEBUGFS=y + - CONFIG_MAC80211_DEFAULT_PS=y + - CONFIG_IWM=m + - CONFIG_IWM_DEBUG is not set + - CONFIG_RT2800USB=m + - CONFIG_CAN_DEV=m + - CONFIG_CAN_CALC_BITTIMING=y + - CONFIG_CAN_SJA1000=m + - CONFIG_CAN_SJA1000_PLATFORM=m + - CONFIG_CAN_EMS_PCI=m + - CONFIG_CAN_KVASER_PCI=m + - CONFIG_EEPROM_MAX6875=m + - CONFIG_SENSORS_TMP401=m + - CONFIG_MEDIA_SUPPORT=m + - CONFIG_SND_CTXFI=m + - CONFIG_SND_LX6464ES=m + - CONFIG_SND_HDA_CODEC_CA0110=y + - CONFIG_USB_XHCI_HCD=m + - CONFIG_USB_XHCI_HCD_DEBUGGING is not set + - CONFIG_DRAGONRISE_FF=y (used to be =m) + - CONFIG_GREENASIA_FF=y (used to be =m) + - CONFIG_SMARTJOYPLUS_FF=y (used to be =m) + - CONFIG_USB_NET_INT51X1=m + - CONFIG_CUSE=m + - CONFIG_FUNCTION_PROFILER=y + - CONFIG_RING_BUFFER_BENCHMARK=m + - CONFIG_REGULATOR_USERSPACE_CONSUMER=m + - CONFIG_REGULATOR_MAX1586=m + - CONFIG_REGULATOR_LP3971=m + - CONFIG_RCU_FANOUT_EXACT is not set + - CONFIG_DEFAULT_MMAP_MIN_ADDR=4096 + - CONFIG_FSNOTIFY=y + - CONFIG_IEEE802154=m + - CONFIG_IEEE802154_DRIVERS=m + - CONFIG_IEEE802154_FAKEHARD=m + - CONFIG_CNIC=m + +* Wed Jun 17 2009 Jarod Wilson +- New lirc_imon hotness, update 2: + * support dual-interface devices with a single lirc device + * directional pad functions as an input device mouse + * touchscreen devices finally properly supported + * support for using MCE/RC-6 protocol remotes + * fix oops in RF remote association code (F10 bug #475496) + * fix re-enabling case/panel buttons and/or knobs +- Add some misc additional lirc_mceusb2 transceiver IDs +- Add missing unregister_chrdev_region() call to lirc_dev exit +- Add it8720 support to lirc_it87 + +* Tue Jun 16 2009 Chuck Ebbert +- Update via-sdmmc driver + +* Mon Jun 15 2009 Jarod Wilson +- Update lirc patches w/new imon hotness + +* Fri Jun 12 2009 Chuck Ebbert +- Update VIA temp sensor and mmc drivers. + +* Fri Jun 12 2009 John W. Linville 2.6.30-6 +- neigh: fix state transition INCOMPLETE->FAILED via Netlink request +- enable CONFIG_ARPD (used by OpenNHRP) + +* Wed Jun 10 2009 Chuck Ebbert +- VIA Nano updates: + Enable Padlock AES encryption and random number generator on x86-64 + Add via-sdmmc and via-cputemp drivers + +* Wed Jun 10 2009 Kyle McMartin 2.6.30-1 +- Linux 2.6.30 rebase. + +* Tue Jun 09 2009 John W. Linville +- Clean-up some wireless bits in config-generic + +* Tue Jun 09 2009 Chuck Ebbert +- Add support for ACPI P-states on VIA processors. +- Disable the e_powersaver driver. + +* Tue Jun 09 2009 Chuck Ebbert +- Linux 2.6.30-rc8-git6 + +* Fri Jun 05 2009 Chuck Ebbert +- Linux 2.6.30-rc8-git1 + +* Wed Jun 03 2009 Kyle McMartin +- Linux 2.6.30-rc8 + +* Tue Jun 2 2009 Roland McGrath +- utrace update (fixes stap PR10185) + +* Tue Jun 02 2009 Dave Jones +- For reasons unknown, RT2X00 driver was being built-in. + Make it modular. + +* Tue Jun 02 2009 Dave Jones +- 2.6.30-rc7-git5 + +* Sat May 30 2009 Dave Jones +- 2.6.30-rc7-git4 + +* Thu May 28 2009 Dave Jones +- 2.6.30-rc7-git2 + +* Tue May 26 2009 Dave Jones +- Various cpufreq patches from git. + +* Tue May 26 2009 Dave Jones +- 2.6.30-rc7-git1 + +* Mon May 25 2009 Kyle McMartin +- rds-only-on-64-bit-or-x86.patch: drop patch, issue is fixed upstream. + +* Sat May 23 2009 Dave Jones +- 2.6.30-rc7 + +* Thu May 21 2009 Dave Jones +- 2.6.30-rc6-git6 + +* Wed May 20 2009 Chuck Ebbert +- Enable Divas (formerly Eicon) ISDN drivers on x86_64. (#480837) + +* Wed May 20 2009 Dave Jones +- 2.6.30-rc6-git5 + +* Mon May 18 2009 Dave Jones +- 2.6.30-rc6-git3 + +* Sun May 17 2009 Dave Jones +- 2.6.30-rc6-git2 + +* Sat May 16 2009 Dave Jones +- 2.6.30-rc6 + +* Mon May 11 2009 Kyle McMartin +- Linux 2.6.30-rc5-git1 + +* Fri May 08 2009 Kyle McMartin +- Linux 2.6.30-rc5 + +* Fri May 08 2009 Kyle McMartin +- Linux 2.6.30-rc4-git4 + +* Wed May 06 2009 Kyle McMartin +- Linux 2.6.30-rc4-git3 +- linux-2.6-cdrom-door-status.patch: merged upstream. +- linux-2.6-iwl3945-remove-useless-exports.patch: merged upstream. +- linux-2.6-utrace.patch: rebase against changes to fs/proc/array.c +- USB_NET_CDC_EEM=m + +* Fri May 01 2009 Eric Sandeen +- Fix ext4 corruption on partial write into prealloc block + +* Thu Apr 30 2009 Kyle McMartin +- 2.6.30-rc4 + +* Wed Apr 29 2009 Dave Jones +- 2.6.30-rc3-git6 + +* Tue Apr 28 2009 Dave Jones +- 2.6.30-rc3-git4 + +* Tue Apr 28 2009 Chuck Ebbert +- Make the kernel-vanilla package buildable again. +- Allow building with older versions of RPM. + +* Tue Apr 28 2009 Neil Horman +- Backport missing snmp stats (bz 492391) + +* Tue Apr 28 2009 Chuck Ebbert 2.6.30-0.72.rc3.git3 +- Drop unused exports from the iwl3945 driver. + +* Tue Apr 28 2009 Chuck Ebbert +- Linux 2.6.30-rc3-git3 + +* Mon Apr 27 2009 Dave Jones +- 2.6.30-rc3-git2 + +* Sun Apr 26 2009 Chuck Ebbert 2.6.30-0.68.rc3.git1 +- Linux 2.6.30-rc3-git1 + +* Wed Apr 22 2009 Dave Jones 2.6.30-0.67.rc3 +- Disable SYSFS_DEPRECATED on ia64 + +* Wed Apr 22 2009 Kyle McMartin +- Linux 2.6.30-rc3 +- PROC_VMCORE=y: Exports the dump image of crashed + kernel in ELF format + +* Wed Apr 22 2009 Neil Horman +- Enable RELOCATABLE and CRASH_DUMP for powerpc64 +- With this we can remove the -kdump build variant +- for the ppc64 arch + +* Tue Apr 21 2009 Chuck Ebbert +- Don't include the modules.*.bin files in the RPM package. + +* Tue Apr 21 2009 Dave Jones +- 2.6.30-rc2-git7 + +* Mon Apr 20 2009 Dave Jones +- Various s390x config tweaks. (#496596, #496601, #496605, #496607) + +* Mon Apr 20 2009 Dave Jones +- 2.6.30-rc2-git6 + +* Sat Apr 18 2009 Chuck Ebbert +- Set CONFIG_UEVENT_HELPER_PATH to the empty string (#496296) + +* Fri Apr 17 2009 Dave Jones +- 2.6.30-rc2-git3 + +* Thu Apr 16 2009 Kyle McMartin 2.6.30-0.58.rc2.git1 +- 2.6.30-rc2-git1 + +* Wed Apr 15 2009 Kyle McMartin 2.6.30-0.57.rc2 +- 2.6.30-rc2 + +* Tue Apr 14 2009 Kyle McMartin +- 2.6.30-rc1-git7 +- CONFIG_TOUCHSCREEN_AD7879_I2C=m +- CONFIG_STRIP_ASM_SYMS=y, off for -debug + +* Mon Apr 13 2009 Kyle McMartin +- ppc-fix-parport_pc.patch: add from linuxppc-dev@ + +* Mon Apr 13 2009 Kyle McMartin +- execshield: fix build (load_user_cs_desc is 32-bit only in tlb.c) + +* Sun Apr 12 2009 Kyle McMartin +- 2.6.30-rc1-git5 +- revert-fix-modules_install-via-nfs.patch: reverted upstream + +* Thu Apr 09 2009 Kyle McMartin +- actually drop utrace-ftrace from srpm. + +* Thu Apr 09 2009 Kyle McMartin +- 2.6.30-rc1-git2 +- CONFIG_IGBVF=m +- CONFIG_NETFILTER_XT_TARGET_LED=m + +* Thu Apr 09 2009 Dave Jones +- Bring back the /dev/crash driver. (#492803) + +* Wed Apr 08 2009 Dave Jones +- disable MMIOTRACE in non-debug builds (#494584) + +* Wed Apr 08 2009 Kyle McMartin 2.6.30-0.44.rc1 +- 2.6.30-rc1 +- linux-2.6-hwmon-atk0110.patch: drop +- CONFIG_DETECT_HUNG_TASK=y +- # CONFIG_BOOTPARAM_HUNG_TASK_PANIC is not set + +* Tue Apr 7 2009 Roland McGrath +- utrace update, drop unfinished utrace-ftrace + +* Tue Apr 07 2009 Kyle McMartin +- Linux 2.6.29-git15 +- EXT3_DEFAULTS_TO_ORDERED on for now. +- X86_X2APIC enabled. +- LEDS_LP5521, LEDS_BD2802 off... look not generally relevant. +- LIBFCOE on. + +* Tue Apr 07 2009 Dave Jones +- Enable CONFIG_CIFS_STATS (#494545) + +* Mon Apr 06 2009 Kyle McMartin +- linux-2.6-execshield.patch: rebase for 2.6.30 + +* Mon Apr 06 2009 Kyle McMartin +- Linux 2.6.29-git13 +- drop patches merged upstream: + - fix-ppc-debug_kmap_atomic.patch + - fix-staging-at76.patch + - linux-2.6-acpi-video-didl-intel-outputs.patch + - linux-2.6-acpi-strict-resources.patch + - linux-2.6-sony-laptop-rfkill.patch + - linux-2.6-btrfs-fix-umount-hang.patch + - linux-2.6-fiemap-header-install.patch + - linux-2.6-debug-dma-api.patch + - dma-api-debug-fixes.patch + - linux-2.6-ext4-flush-on-close.patch + - linux-2.6-relatime-by-default.patch + - linux-2.6-pci-sysfs-remove-id.patch + - linux-2.6-scsi-cpqarray-set-master.patch + - alsa-rewrite-hw_ptr-updaters.patch + - alsa-pcm-always-reset-invalid-position.patch + - alsa-pcm-fix-delta-calc-at-overlap.patch + - alsa-pcm-safer-boundary-checks.patch + - linux-2.6-input-hid-extra-gamepad.patch + - linux-2.6-ipw2x00-age-scan-results-on-resume.patch + - linux-2.6-dropwatch-protocol.patch + - linux-2.6-net-fix-gro-bug.patch + - linux-2.6-net-fix-another-gro-bug.patch + - linux-2.6-net-xfrm-fix-spin-unlock.patch + - linux-2.6.29-pat-change-is_linear_pfn_mapping-to-not-use-vm_pgoff.patch + - linux-2.6.29-pat-pci-change-prot-for-inherit.patch + +* Thu Apr 02 2009 Josef Bacik +- linux-2.6-btrfs-fix-umount-hang.patch: fix umount hang on btrfs + +* Thu Apr 02 2009 Kyle McMartin +- fix-ppc-debug_kmap_atomic.patch: fix build failures on ppc. + +* Thu Apr 02 2009 Kyle McMartin +- Linux 2.6.29-git9 + +* Tue Mar 31 2009 Kyle McMartin +- rds-only-on-64-bit-or-x86.patch: add +- at76-netdev_ops.patch: add + +* Tue Mar 31 2009 Kyle McMartin +- Linux 2.6.29-git8 +- linux-2.6-net-fix-another-gro-bug.patch: upstream. + +* Tue Mar 31 2009 Eric Sandeen +- add fiemap.h to kernel-headers +- build ext4 (and jbd2 and crc16) into the kernel + +* Tue Mar 31 2009 Kyle McMartin +- Linux 2.6.29-git7 +- fix-staging-at76.patch: pull patch from linux-wireless to fix... + +* Mon Mar 30 2009 Kyle McMartin 2.6.30-0.28.rc0.git6 +- Linux 2.6.29-git6 +- Bunch of stuff disabled, most merged, some needs rebasing. + +* Mon Mar 30 2009 Chuck Ebbert +- Make the .shared-srctree file a list so more than two checkouts + can share source files. + +* Mon Mar 30 2009 Chuck Ebbert +- Separate PAT fixes that are headed for -stable from our out-of-tree ones. + +* Mon Mar 30 2009 Dave Jones +- Make io schedulers selectable at boot time again. (#492817) + +* Mon Mar 30 2009 Dave Jones +- Add a strict-devmem=0 boot argument (#492803) + +* Mon Mar 30 2009 Adam Jackson +- linux-2.6.29-pat-fixes.patch: Fix PAT/GTT interaction + +* Mon Mar 30 2009 Mauro Carvalho Chehab +- some fixes of troubles caused by v4l2 subdev conversion + +* Mon Mar 30 2009 Mark McLoughlin 2.6.29-21 +- Fix guest->remote network stall with virtio/GSO (#490266) + +* Mon Mar 30 2009 Ben Skeggs +- drm-nouveau.patch + - rewrite nouveau PCI(E) GART functions, should fix rh#492492 + - kms: kernel option to allow dual-link dvi + - modinfo descriptions for module parameters + +* Sun Mar 29 2009 Mauro Carvalho Chehab +- more v4l/dvb updates: v4l subdev conversion and some driver improvements + +* Sun Mar 29 2009 Chuck Ebbert +- More fixes for ALSA hardware pointer updating. + +* Sat Mar 28 2009 Mauro Carvalho Chehab +- linux-2.6-revert-dvb-net-kabi-change.patch: attempt to fix dvb net breakage +- update v4l fixes patch to reflect what's ready for 2.6.30 +- update v4l devel patch to reflect what will be kept on linux-next for a while + +* Fri Mar 27 2009 Chuck Ebbert 2.6.29-16 +- Fix 2.6.29 networking lockups. +- Fix locking in net/xfrm/xfrm_state.c (#489764) + +* Fri Mar 27 2009 Ben Skeggs +- drm-nouveau.patch: do nothing for dac_{prepare,commit}, it's useless + and breaks some things in strange ways. + +* Fri Mar 27 2009 Ben Skeggs +- nv50: clear 0x1900/8 on init, possible fix for rh#492240 +- forcibly disable GEM also if KMS requested where not supported +- inform the user if we disable KMS because of it not being supported + +* Thu Mar 26 2009 Matthew Garrett +- linux-2.6-relatime-by-default.patch: Backport relatime code from 2.6.30 + +* Thu Mar 26 2009 Dave Jones +- Check for modesetting enabled before forcing mode on 915. (#490336) + +* Thu Mar 26 2009 Dave Jones +- Set kernel-PAE as default in grub. (#487578) + +* Thu Mar 26 2009 Dave Jones +- Enable CONFIG_MOUSE_PS2_ELANTECH (#492163) + +* Thu Mar 26 2009 Kyle McMartin +- linux-2.6-v4l-pvrusb2-fixes.patch: fix build for uncle steve. + +* Thu Mar 26 2009 Mauro Carvalho Chehab +- Move all 2.6.30 stuff into linux-2.6-v4l-dvb-fixes.patch, in + preparation for upstream pull; +- Added two new drivers: gspca sq905c and DVB Intel ce6230 +- Updated to the latest v4l-dvb drivers. + +* Wed Mar 25 2009 Mauro Carvalho Chehab +- remove duplicated Cinergy T2 entry at config-generic + +* Wed Mar 25 2009 Neil Horman +- Add dropmonitor/dropwatch protocol from 2.6.30 + +* Wed Mar 25 2009 Kyle McMartin +- alsa-rewrite-hw_ptr-updaters.patch: snd_pcm_update_hw_ptr() tries to + detect the unexpected hwptr jumps more strictly to avoid the position + mess-up, which often results in the bad quality I/O with pulseaudio. + +* Wed Mar 25 2009 Ben Skeggs +- drm-nouveau.patch: idle channels better before destroying them + +* Tue Mar 24 2009 Kyle McMartin +- Disable DMAR by default until suspend & resume is fixed. + +* Tue Mar 24 2009 Josef Bacik +- fsync replay fixes for btrfs + +* Mon Mar 23 2009 Dave Jones +- 2.6.29 + +### +# The following Emacs magic makes C-c C-e use UTC dates. +# Local Variables: +# rpm-change-log-uses-utc: t +# End: +### diff --git a/kvm-mmu-fix-conflict-access-permissions-in-direct-sp.patch b/kvm-mmu-fix-conflict-access-permissions-in-direct-sp.patch new file mode 100644 index 000000000..863817842 --- /dev/null +++ b/kvm-mmu-fix-conflict-access-permissions-in-direct-sp.patch @@ -0,0 +1,52 @@ +From 567b1bbf982637ce3f0ac8597af91ae8106648c8 Mon Sep 17 00:00:00 2001 +From: Xiao Guangrong +Date: Wed, 30 Jun 2010 16:02:45 +0800 +Subject: [PATCH] KVM: MMU: fix conflict access permissions in direct sp + +In no-direct mapping, we mark sp is 'direct' when we mapping the +guest's larger page, but its access is encoded form upper page-struct +entire not include the last mapping, it will cause access conflict. + +For example, have this mapping: + [W] + / PDE1 -> |---| + P[W] | | LPA + \ PDE2 -> |---| + [R] + +P have two children, PDE1 and PDE2, both PDE1 and PDE2 mapping the +same lage page(LPA). The P's access is WR, PDE1's access is WR, +PDE2's access is RO(just consider read-write permissions here) + +When guest access PDE1, we will create a direct sp for LPA, the sp's +access is from P, is W, then we will mark the ptes is W in this sp. + +Then, guest access PDE2, we will find LPA's shadow page, is the same as +PDE's, and mark the ptes is RO. + +So, if guest access PDE1, the incorrect #PF is occured. + +Fixed by encode the last mapping access into direct shadow page + +Signed-off-by: Xiao Guangrong +Signed-off-by: Marcelo Tosatti +Signed-off-by: Avi Kivity +--- + arch/x86/kvm/paging_tmpl.h | 1 + + 1 files changed, 1 insertions(+), 0 deletions(-) + +diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h +index ede2131..b473c0f 100644 +--- a/arch/x86/kvm/paging_tmpl.h ++++ b/arch/x86/kvm/paging_tmpl.h +@@ -336,6 +336,7 @@ static u64 *FNAME(fetch)(struct kvm_vcpu *vcpu, gva_t addr, + /* advance table_gfn when emulating 1gb pages with 4k */ + if (delta == 0) + table_gfn += PT_INDEX(addr, level); ++ access &= gw->pte_access; + } else { + direct = 0; + table_gfn = gw->table_gfn[level - 2]; +-- +1.7.1 + diff --git a/linux-2.6-acpi-indirect_fan_control.patch b/linux-2.6-acpi-indirect_fan_control.patch new file mode 100644 index 000000000..88e2818e6 --- /dev/null +++ b/linux-2.6-acpi-indirect_fan_control.patch @@ -0,0 +1,48 @@ +commit 0c99c5288eb9b1bbc9684b0ec0fd7efc578749b3 +Author: Zhang Rui +Date: Thu Dec 17 16:02:08 2009 +0800 + + ACPI: Disable explicit power state retrieval on fans + + If the ACPI power state can be got both directly and indirectly, + we prefer to get it indirectly. + + https://bugzilla.redhat.com/show_bug.cgi?id=531916 describes a + system with a _PSC method for the fan that always returns "on". + There's no benefit in us always requesting the state of the fan + when performing transitions - we want to do everything we can + to ensure that the fan turns on when it should do, not risk + hardware damage by believing the hardware when it tells us the + fan is already on. Given that the Leading Other OS(tm) works fine + on this machine, it seems likely that it behaves in much this way. + + inspired-by: Matthew Garrett + Signed-off-by: Zhang Rui + Signed-off-by: Len Brown + +diff --git a/drivers/acpi/bus.c b/drivers/acpi/bus.c +index cf761b9..ae9226d 100644 +--- a/drivers/acpi/bus.c ++++ b/drivers/acpi/bus.c +@@ -190,16 +190,16 @@ int acpi_bus_get_power(acpi_handle handle, int *state) + * Get the device's power state either directly (via _PSC) or + * indirectly (via power resources). + */ +- if (device->power.flags.explicit_get) { ++ if (device->power.flags.power_resources) { ++ result = acpi_power_get_inferred_state(device); ++ if (result) ++ return result; ++ } else if (device->power.flags.explicit_get) { + status = acpi_evaluate_integer(device->handle, "_PSC", + NULL, &psc); + if (ACPI_FAILURE(status)) + return -ENODEV; + device->power.state = (int)psc; +- } else if (device->power.flags.power_resources) { +- result = acpi_power_get_inferred_state(device); +- if (result) +- return result; + } + + *state = device->power.state; diff --git a/linux-2.6-acpi-video-dos.patch b/linux-2.6-acpi-video-dos.patch new file mode 100644 index 000000000..3e2085193 --- /dev/null +++ b/linux-2.6-acpi-video-dos.patch @@ -0,0 +1,17 @@ +Disable firmware video brightness change on AC/Battery switch by default + +-- mjg59 + +diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c +index bac2901..93b1a9e 100644 +--- a/drivers/acpi/video.c ++++ b/drivers/acpi/video.c +@@ -1818,7 +1818,7 @@ static int acpi_video_bus_put_devices(struct acpi_video_bus *video) + + static int acpi_video_bus_start_devices(struct acpi_video_bus *video) + { +- return acpi_video_bus_DOS(video, 0, 0); ++ return acpi_video_bus_DOS(video, 0, 1); + } + + static int acpi_video_bus_stop_devices(struct acpi_video_bus *video) diff --git a/linux-2.6-acpi-video-export-edid.patch b/linux-2.6-acpi-video-export-edid.patch new file mode 100644 index 000000000..3721b0264 --- /dev/null +++ b/linux-2.6-acpi-video-export-edid.patch @@ -0,0 +1,184 @@ +diff -up linux-2.6.33.noarch/drivers/acpi/video.c.orig linux-2.6.33.noarch/drivers/acpi/video.c +--- linux-2.6.33.noarch/drivers/acpi/video.c.orig 2010-04-12 13:42:53.637966231 -0400 ++++ linux-2.6.33.noarch/drivers/acpi/video.c 2010-04-12 13:43:07.290978352 -0400 +@@ -43,6 +43,7 @@ + #include + #include + #include ++#include + + #define PREFIX "ACPI: " + +@@ -63,11 +64,6 @@ + + #define MAX_NAME_LEN 20 + +-#define ACPI_VIDEO_DISPLAY_CRT 1 +-#define ACPI_VIDEO_DISPLAY_TV 2 +-#define ACPI_VIDEO_DISPLAY_DVI 3 +-#define ACPI_VIDEO_DISPLAY_LCD 4 +- + #define _COMPONENT ACPI_VIDEO_COMPONENT + ACPI_MODULE_NAME("video"); + +@@ -1731,11 +1727,27 @@ acpi_video_get_device_attr(struct acpi_v + } + + static int ++acpi_video_get_device_type(struct acpi_video_bus *video, ++ unsigned long device_id) ++{ ++ struct acpi_video_enumerated_device *ids; ++ int i; ++ ++ for (i = 0; i < video->attached_count; i++) { ++ ids = &video->attached_array[i]; ++ if ((ids->value.int_val & 0xffff) == device_id) ++ return ids->value.int_val; ++ } ++ ++ return 0; ++} ++ ++static int + acpi_video_bus_get_one_device(struct acpi_device *device, + struct acpi_video_bus *video) + { + unsigned long long device_id; +- int status; ++ int status, device_type; + struct acpi_video_device *data; + struct acpi_video_device_attrib* attribute; + +@@ -1780,8 +1792,25 @@ acpi_video_bus_get_one_device(struct acp + } + if(attribute->bios_can_detect) + data->flags.bios = 1; +- } else +- data->flags.unknown = 1; ++ } else { ++ /* Check for legacy IDs */ ++ device_type = acpi_video_get_device_type(video, ++ device_id); ++ /* Ignore bits 16 and 18-20 */ ++ switch (device_type & 0xffe2ffff) { ++ case ACPI_VIDEO_DISPLAY_LEGACY_MONITOR: ++ data->flags.crt = 1; ++ break; ++ case ACPI_VIDEO_DISPLAY_LEGACY_PANEL: ++ data->flags.lcd = 1; ++ break; ++ case ACPI_VIDEO_DISPLAY_LEGACY_TV: ++ data->flags.tvout = 1; ++ break; ++ default: ++ data->flags.unknown = 1; ++ } ++ } + + acpi_video_device_bind(video, data); + acpi_video_device_find_cap(data); +@@ -2015,6 +2044,71 @@ out: + return result; + } + ++int acpi_video_get_edid(struct acpi_device *device, int type, int device_id, ++ void **edid) ++{ ++ struct acpi_video_bus *video; ++ struct acpi_video_device *video_device; ++ union acpi_object *buffer = NULL; ++ acpi_status status; ++ int i, length; ++ ++ if (!device || !acpi_driver_data(device)) ++ return -EINVAL; ++ ++ video = acpi_driver_data(device); ++ ++ for (i = 0; i < video->attached_count; i++) { ++ video_device = video->attached_array[i].bind_info; ++ length = 256; ++ ++ if (!video_device) ++ continue; ++ ++ if (type) { ++ switch (type) { ++ case ACPI_VIDEO_DISPLAY_CRT: ++ if (!video_device->flags.crt) ++ continue; ++ break; ++ case ACPI_VIDEO_DISPLAY_TV: ++ if (!video_device->flags.tvout) ++ continue; ++ break; ++ case ACPI_VIDEO_DISPLAY_DVI: ++ if (!video_device->flags.dvi) ++ continue; ++ break; ++ case ACPI_VIDEO_DISPLAY_LCD: ++ if (!video_device->flags.lcd) ++ continue; ++ break; ++ } ++ } else if (video_device->device_id != device_id) { ++ continue; ++ } ++ ++ status = acpi_video_device_EDID(video_device, &buffer, length); ++ ++ if (ACPI_FAILURE(status) || !buffer || ++ buffer->type != ACPI_TYPE_BUFFER) { ++ length = 128; ++ status = acpi_video_device_EDID(video_device, &buffer, ++ length); ++ if (ACPI_FAILURE(status) || !buffer || ++ buffer->type != ACPI_TYPE_BUFFER) { ++ continue; ++ } ++ } ++ ++ *edid = buffer->buffer.pointer; ++ return length; ++ } ++ ++ return -ENODEV; ++} ++EXPORT_SYMBOL(acpi_video_get_edid); ++ + static int + acpi_video_bus_get_devices(struct acpi_video_bus *video, + struct acpi_device *device) +diff -up linux-2.6.33.noarch/include/acpi/video.h.orig linux-2.6.33.noarch/include/acpi/video.h +--- linux-2.6.33.noarch/include/acpi/video.h.orig 2010-04-12 13:42:53.638966251 -0400 ++++ linux-2.6.33.noarch/include/acpi/video.h 2010-04-12 13:43:07.292841571 -0400 +@@ -1,12 +1,28 @@ + #ifndef __ACPI_VIDEO_H + #define __ACPI_VIDEO_H + ++#define ACPI_VIDEO_DISPLAY_CRT 1 ++#define ACPI_VIDEO_DISPLAY_TV 2 ++#define ACPI_VIDEO_DISPLAY_DVI 3 ++#define ACPI_VIDEO_DISPLAY_LCD 4 ++ ++#define ACPI_VIDEO_DISPLAY_LEGACY_MONITOR 0x0100 ++#define ACPI_VIDEO_DISPLAY_LEGACY_PANEL 0x0110 ++#define ACPI_VIDEO_DISPLAY_LEGACY_TV 0x0200 ++ + #if (defined CONFIG_ACPI_VIDEO || defined CONFIG_ACPI_VIDEO_MODULE) + extern int acpi_video_register(void); + extern void acpi_video_unregister(void); ++extern int acpi_video_get_edid(struct acpi_device *device, int type, ++ int device_id, void **edid); + #else + static inline int acpi_video_register(void) { return 0; } + static inline void acpi_video_unregister(void) { return; } ++static inline int acpi_video_get_edid(struct acpi_device *device, int type, ++ int device_id, void **edid) ++{ ++ return -ENODEV; ++} + #endif + + #endif diff --git a/linux-2.6-ata-quirk.patch b/linux-2.6-ata-quirk.patch new file mode 100644 index 000000000..32096d463 --- /dev/null +++ b/linux-2.6-ata-quirk.patch @@ -0,0 +1,58 @@ +--- linux-2.6.20/arch/ia64/kernel/quirks.c 1969-12-31 19:00:00.000000000 -0500 ++++ linux-2.6.20_fix/arch/ia64/kernel/quirks.c 2007-02-13 13:56:34.000000000 -0500 +@@ -0,0 +1,45 @@ ++/* ++ * This file contains work-arounds for ia64 platform bugs. ++ */ ++#include ++ ++/* ++ * quirk_intel_ide_controller: If an ide/ata controller is ++ * at legacy mode, BIOS might initiates BAR(bar 0~3 and 5) ++ * with incorrect value. This quirk will reset the incorrect ++ * value to 0. ++ */ ++static void __devinit quirk_intel_ide_controller(struct pci_dev *dev) ++{ ++ unsigned int pos; ++ struct resource *res; ++ int fixed = 0; ++ u8 tmp8; ++ ++ if ((dev->class >> 8) != PCI_CLASS_STORAGE_IDE) ++ return; ++ ++ /* TODO: What if one channel is in native mode ... */ ++ pci_read_config_byte(dev, PCI_CLASS_PROG, &tmp8); ++ if ((tmp8 & 5) == 5) ++ return; ++ ++ for( pos = 0; pos < 6; pos ++ ) { ++ res = &dev->resource[pos]; ++ if (!(res->flags & (IORESOURCE_IO | IORESOURCE_MEM))) ++ continue; ++ ++ if (!res->start && res->end) { ++ res->start = res->end = 0; ++ res->flags = 0; ++ fixed = 1; ++ } ++ } ++ if (fixed) ++ printk(KERN_WARNING ++ "PCI device %s: BIOS resource configuration fixed.\n", ++ pci_name(dev)); ++} ++ ++DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_11, quirk_intel_ide_controller); ++ +--- linux-2.6.21.noarch/arch/ia64/kernel/Makefile~ 2007-05-27 23:23:36.000000000 -0400 ++++ linux-2.6.21.noarch/arch/ia64/kernel/Makefile 2007-05-27 23:23:48.000000000 -0400 +@@ -33,6 +33,7 @@ obj-$(CONFIG_CRASH_DUMP) += crash_dump.o + obj-$(CONFIG_IA64_UNCACHED_ALLOCATOR) += uncached.o + obj-$(CONFIG_AUDIT) += audit.o + obj-$(CONFIG_PCI_MSI) += msi_ia64.o ++obj-$(CONFIG_PCI) += quirks.o + mca_recovery-y += mca_drv.o mca_drv_asm.o + obj-$(CONFIG_IA64_MC_ERR_INJECT)+= err_inject.o + diff --git a/linux-2.6-btrfs-update.patch b/linux-2.6-btrfs-update.patch new file mode 100644 index 000000000..c3325a25d --- /dev/null +++ b/linux-2.6-btrfs-update.patch @@ -0,0 +1,2819 @@ +diff --git a/fs/btrfs/btrfs_inode.h b/fs/btrfs/btrfs_inode.h +index 3f1f50d..7a4dee1 100644 +--- a/fs/btrfs/btrfs_inode.h ++++ b/fs/btrfs/btrfs_inode.h +@@ -153,6 +153,11 @@ struct btrfs_inode { + unsigned ordered_data_close:1; + unsigned dummy_inode:1; + ++ /* ++ * always compress this one file ++ */ ++ unsigned force_compress:1; ++ + struct inode vfs_inode; + }; + +diff --git a/fs/btrfs/compression.c b/fs/btrfs/compression.c +index a11a320..28b92a7 100644 +--- a/fs/btrfs/compression.c ++++ b/fs/btrfs/compression.c +@@ -478,7 +478,7 @@ static noinline int add_ra_bio_pages(struct inode *inode, + goto next; + } + +- page = alloc_page(mapping_gfp_mask(mapping) | GFP_NOFS); ++ page = alloc_page(mapping_gfp_mask(mapping) & ~__GFP_FS); + if (!page) + break; + +diff --git a/fs/btrfs/ctree.h b/fs/btrfs/ctree.h +index 8b5cfdd..0af2e38 100644 +--- a/fs/btrfs/ctree.h ++++ b/fs/btrfs/ctree.h +@@ -373,11 +373,13 @@ struct btrfs_super_block { + * ones specified below then we will fail to mount + */ + #define BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF (1ULL << 0) ++#define BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL (2ULL << 0) + + #define BTRFS_FEATURE_COMPAT_SUPP 0ULL + #define BTRFS_FEATURE_COMPAT_RO_SUPP 0ULL + #define BTRFS_FEATURE_INCOMPAT_SUPP \ +- BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF ++ (BTRFS_FEATURE_INCOMPAT_MIXED_BACKREF | \ ++ BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL) + + /* + * A leaf is full of items. offset and size tell us where to find +@@ -1182,7 +1184,6 @@ struct btrfs_root { + #define BTRFS_INODE_NOATIME (1 << 9) + #define BTRFS_INODE_DIRSYNC (1 << 10) + +- + /* some macros to generate set/get funcs for the struct fields. This + * assumes there is a lefoo_to_cpu for every type, so lets make a simple + * one for u8: +@@ -1842,7 +1843,7 @@ BTRFS_SETGET_STACK_FUNCS(super_num_devices, struct btrfs_super_block, + BTRFS_SETGET_STACK_FUNCS(super_compat_flags, struct btrfs_super_block, + compat_flags, 64); + BTRFS_SETGET_STACK_FUNCS(super_compat_ro_flags, struct btrfs_super_block, +- compat_flags, 64); ++ compat_ro_flags, 64); + BTRFS_SETGET_STACK_FUNCS(super_incompat_flags, struct btrfs_super_block, + incompat_flags, 64); + BTRFS_SETGET_STACK_FUNCS(super_csum_type, struct btrfs_super_block, +@@ -2310,7 +2311,8 @@ int btrfs_truncate_inode_items(struct btrfs_trans_handle *trans, + u32 min_type); + + int btrfs_start_delalloc_inodes(struct btrfs_root *root, int delay_iput); +-int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end); ++int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, ++ struct extent_state **cached_state); + int btrfs_writepages(struct address_space *mapping, + struct writeback_control *wbc); + int btrfs_create_subvol_root(struct btrfs_trans_handle *trans, +@@ -2335,7 +2337,7 @@ int btrfs_init_cachep(void); + void btrfs_destroy_cachep(void); + long btrfs_ioctl_trans_end(struct file *file); + struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, +- struct btrfs_root *root); ++ struct btrfs_root *root, int *was_new); + int btrfs_commit_write(struct file *file, struct page *page, + unsigned from, unsigned to); + struct extent_map *btrfs_get_extent(struct inode *inode, struct page *page, +@@ -2386,7 +2388,6 @@ void btrfs_sysfs_del_super(struct btrfs_fs_info *root); + ssize_t btrfs_listxattr(struct dentry *dentry, char *buffer, size_t size); + + /* super.c */ +-u64 btrfs_parse_size(char *str); + int btrfs_parse_options(struct btrfs_root *root, char *options); + int btrfs_sync_fs(struct super_block *sb, int wait); + +diff --git a/fs/btrfs/disk-io.c b/fs/btrfs/disk-io.c +index 2b59201..11d0ad3 100644 +--- a/fs/btrfs/disk-io.c ++++ b/fs/btrfs/disk-io.c +@@ -263,13 +263,15 @@ static int csum_tree_block(struct btrfs_root *root, struct extent_buffer *buf, + static int verify_parent_transid(struct extent_io_tree *io_tree, + struct extent_buffer *eb, u64 parent_transid) + { ++ struct extent_state *cached_state = NULL; + int ret; + + if (!parent_transid || btrfs_header_generation(eb) == parent_transid) + return 0; + +- lock_extent(io_tree, eb->start, eb->start + eb->len - 1, GFP_NOFS); +- if (extent_buffer_uptodate(io_tree, eb) && ++ lock_extent_bits(io_tree, eb->start, eb->start + eb->len - 1, ++ 0, &cached_state, GFP_NOFS); ++ if (extent_buffer_uptodate(io_tree, eb, cached_state) && + btrfs_header_generation(eb) == parent_transid) { + ret = 0; + goto out; +@@ -282,10 +284,10 @@ static int verify_parent_transid(struct extent_io_tree *io_tree, + (unsigned long long)btrfs_header_generation(eb)); + } + ret = 1; +- clear_extent_buffer_uptodate(io_tree, eb); ++ clear_extent_buffer_uptodate(io_tree, eb, &cached_state); + out: +- unlock_extent(io_tree, eb->start, eb->start + eb->len - 1, +- GFP_NOFS); ++ unlock_extent_cached(io_tree, eb->start, eb->start + eb->len - 1, ++ &cached_state, GFP_NOFS); + return ret; + } + +@@ -901,7 +903,7 @@ static int __setup_root(u32 nodesize, u32 leafsize, u32 sectorsize, + root->highest_objectid = 0; + root->name = NULL; + root->in_sysfs = 0; +- root->inode_tree.rb_node = NULL; ++ root->inode_tree = RB_ROOT; + + INIT_LIST_HEAD(&root->dirty_list); + INIT_LIST_HEAD(&root->orphan_list); +@@ -1673,7 +1675,7 @@ struct btrfs_root *open_ctree(struct super_block *sb, + insert_inode_hash(fs_info->btree_inode); + + spin_lock_init(&fs_info->block_group_cache_lock); +- fs_info->block_group_cache_tree.rb_node = NULL; ++ fs_info->block_group_cache_tree = RB_ROOT; + + extent_io_tree_init(&fs_info->freed_extents[0], + fs_info->btree_inode->i_mapping, GFP_NOFS); +@@ -2497,7 +2499,8 @@ int btrfs_buffer_uptodate(struct extent_buffer *buf, u64 parent_transid) + int ret; + struct inode *btree_inode = buf->first_page->mapping->host; + +- ret = extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree, buf); ++ ret = extent_buffer_uptodate(&BTRFS_I(btree_inode)->io_tree, buf, ++ NULL); + if (!ret) + return ret; + +diff --git a/fs/btrfs/export.c b/fs/btrfs/export.c +index ba5c3fd..951ef09 100644 +--- a/fs/btrfs/export.c ++++ b/fs/btrfs/export.c +@@ -95,7 +95,7 @@ static struct dentry *btrfs_get_dentry(struct super_block *sb, u64 objectid, + btrfs_set_key_type(&key, BTRFS_INODE_ITEM_KEY); + key.offset = 0; + +- inode = btrfs_iget(sb, &key, root); ++ inode = btrfs_iget(sb, &key, root, NULL); + if (IS_ERR(inode)) { + err = PTR_ERR(inode); + goto fail; +@@ -223,7 +223,7 @@ static struct dentry *btrfs_get_parent(struct dentry *child) + + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; +- dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root)); ++ dentry = d_obtain_alias(btrfs_iget(root->fs_info->sb, &key, root, NULL)); + if (!IS_ERR(dentry)) + dentry->d_op = &btrfs_dentry_operations; + return dentry; +diff --git a/fs/btrfs/extent-tree.c b/fs/btrfs/extent-tree.c +index 559f724..1727b26 100644 +--- a/fs/btrfs/extent-tree.c ++++ b/fs/btrfs/extent-tree.c +@@ -6561,6 +6561,7 @@ static noinline int invalidate_extent_cache(struct btrfs_root *root, + struct btrfs_key key; + struct inode *inode = NULL; + struct btrfs_file_extent_item *fi; ++ struct extent_state *cached_state = NULL; + u64 num_bytes; + u64 skip_objectid = 0; + u32 nritems; +@@ -6589,12 +6590,14 @@ static noinline int invalidate_extent_cache(struct btrfs_root *root, + } + num_bytes = btrfs_file_extent_num_bytes(leaf, fi); + +- lock_extent(&BTRFS_I(inode)->io_tree, key.offset, +- key.offset + num_bytes - 1, GFP_NOFS); ++ lock_extent_bits(&BTRFS_I(inode)->io_tree, key.offset, ++ key.offset + num_bytes - 1, 0, &cached_state, ++ GFP_NOFS); + btrfs_drop_extent_cache(inode, key.offset, + key.offset + num_bytes - 1, 1); +- unlock_extent(&BTRFS_I(inode)->io_tree, key.offset, +- key.offset + num_bytes - 1, GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, key.offset, ++ key.offset + num_bytes - 1, &cached_state, ++ GFP_NOFS); + cond_resched(); + } + iput(inode); +diff --git a/fs/btrfs/extent_io.c b/fs/btrfs/extent_io.c +index b177ed3..c99121a 100644 +--- a/fs/btrfs/extent_io.c ++++ b/fs/btrfs/extent_io.c +@@ -104,8 +104,8 @@ void extent_io_exit(void) + void extent_io_tree_init(struct extent_io_tree *tree, + struct address_space *mapping, gfp_t mask) + { +- tree->state.rb_node = NULL; +- tree->buffer.rb_node = NULL; ++ tree->state = RB_ROOT; ++ tree->buffer = RB_ROOT; + tree->ops = NULL; + tree->dirty_bytes = 0; + spin_lock_init(&tree->lock); +@@ -513,7 +513,10 @@ int clear_extent_bit(struct extent_io_tree *tree, u64 start, u64 end, + u64 last_end; + int err; + int set = 0; ++ int clear = 0; + ++ if (bits & (EXTENT_IOBITS | EXTENT_BOUNDARY)) ++ clear = 1; + again: + if (!prealloc && (mask & __GFP_WAIT)) { + prealloc = alloc_extent_state(mask); +@@ -524,14 +527,20 @@ again: + spin_lock(&tree->lock); + if (cached_state) { + cached = *cached_state; +- *cached_state = NULL; +- cached_state = NULL; ++ ++ if (clear) { ++ *cached_state = NULL; ++ cached_state = NULL; ++ } ++ + if (cached && cached->tree && cached->start == start) { +- atomic_dec(&cached->refs); ++ if (clear) ++ atomic_dec(&cached->refs); + state = cached; + goto hit_next; + } +- free_extent_state(cached); ++ if (clear) ++ free_extent_state(cached); + } + /* + * this search will find the extents that end after +@@ -946,11 +955,11 @@ int clear_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + } + + int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, +- gfp_t mask) ++ struct extent_state **cached_state, gfp_t mask) + { + return set_extent_bit(tree, start, end, + EXTENT_DELALLOC | EXTENT_DIRTY | EXTENT_UPTODATE, +- 0, NULL, NULL, mask); ++ 0, NULL, cached_state, mask); + } + + int clear_extent_dirty(struct extent_io_tree *tree, u64 start, u64 end, +@@ -984,10 +993,11 @@ int set_extent_uptodate(struct extent_io_tree *tree, u64 start, u64 end, + } + + static int clear_extent_uptodate(struct extent_io_tree *tree, u64 start, +- u64 end, gfp_t mask) ++ u64 end, struct extent_state **cached_state, ++ gfp_t mask) + { + return clear_extent_bit(tree, start, end, EXTENT_UPTODATE, 0, 0, +- NULL, mask); ++ cached_state, mask); + } + + int wait_on_extent_writeback(struct extent_io_tree *tree, u64 start, u64 end) +@@ -1171,7 +1181,8 @@ out: + * 1 is returned if we find something, 0 if nothing was in the tree + */ + static noinline u64 find_delalloc_range(struct extent_io_tree *tree, +- u64 *start, u64 *end, u64 max_bytes) ++ u64 *start, u64 *end, u64 max_bytes, ++ struct extent_state **cached_state) + { + struct rb_node *node; + struct extent_state *state; +@@ -1203,8 +1214,11 @@ static noinline u64 find_delalloc_range(struct extent_io_tree *tree, + *end = state->end; + goto out; + } +- if (!found) ++ if (!found) { + *start = state->start; ++ *cached_state = state; ++ atomic_inc(&state->refs); ++ } + found++; + *end = state->end; + cur_start = state->end + 1; +@@ -1336,10 +1350,11 @@ again: + delalloc_start = *start; + delalloc_end = 0; + found = find_delalloc_range(tree, &delalloc_start, &delalloc_end, +- max_bytes); ++ max_bytes, &cached_state); + if (!found || delalloc_end <= *start) { + *start = delalloc_start; + *end = delalloc_end; ++ free_extent_state(cached_state); + return found; + } + +@@ -1722,7 +1737,7 @@ static void end_bio_extent_writepage(struct bio *bio, int err) + } + + if (!uptodate) { +- clear_extent_uptodate(tree, start, end, GFP_NOFS); ++ clear_extent_uptodate(tree, start, end, NULL, GFP_NOFS); + ClearPageUptodate(page); + SetPageError(page); + } +@@ -1750,7 +1765,8 @@ static void end_bio_extent_writepage(struct bio *bio, int err) + static void end_bio_extent_readpage(struct bio *bio, int err) + { + int uptodate = test_bit(BIO_UPTODATE, &bio->bi_flags); +- struct bio_vec *bvec = bio->bi_io_vec + bio->bi_vcnt - 1; ++ struct bio_vec *bvec_end = bio->bi_io_vec + bio->bi_vcnt - 1; ++ struct bio_vec *bvec = bio->bi_io_vec; + struct extent_io_tree *tree; + u64 start; + u64 end; +@@ -1773,7 +1789,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err) + else + whole_page = 0; + +- if (--bvec >= bio->bi_io_vec) ++ if (++bvec <= bvec_end) + prefetchw(&bvec->bv_page->flags); + + if (uptodate && tree->ops && tree->ops->readpage_end_io_hook) { +@@ -1818,7 +1834,7 @@ static void end_bio_extent_readpage(struct bio *bio, int err) + } + check_page_locked(tree, page); + } +- } while (bvec >= bio->bi_io_vec); ++ } while (bvec <= bvec_end); + + bio_put(bio); + } +@@ -2704,6 +2720,7 @@ int extent_readpages(struct extent_io_tree *tree, + int extent_invalidatepage(struct extent_io_tree *tree, + struct page *page, unsigned long offset) + { ++ struct extent_state *cached_state = NULL; + u64 start = ((u64)page->index << PAGE_CACHE_SHIFT); + u64 end = start + PAGE_CACHE_SIZE - 1; + size_t blocksize = page->mapping->host->i_sb->s_blocksize; +@@ -2712,12 +2729,12 @@ int extent_invalidatepage(struct extent_io_tree *tree, + if (start > end) + return 0; + +- lock_extent(tree, start, end, GFP_NOFS); ++ lock_extent_bits(tree, start, end, 0, &cached_state, GFP_NOFS); + wait_on_page_writeback(page); + clear_extent_bit(tree, start, end, + EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | + EXTENT_DO_ACCOUNTING, +- 1, 1, NULL, GFP_NOFS); ++ 1, 1, &cached_state, GFP_NOFS); + return 0; + } + +@@ -2920,16 +2937,17 @@ sector_t extent_bmap(struct address_space *mapping, sector_t iblock, + get_extent_t *get_extent) + { + struct inode *inode = mapping->host; ++ struct extent_state *cached_state = NULL; + u64 start = iblock << inode->i_blkbits; + sector_t sector = 0; + size_t blksize = (1 << inode->i_blkbits); + struct extent_map *em; + +- lock_extent(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, +- GFP_NOFS); ++ lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, ++ 0, &cached_state, GFP_NOFS); + em = get_extent(inode, NULL, 0, start, blksize, 0); +- unlock_extent(&BTRFS_I(inode)->io_tree, start, start + blksize - 1, +- GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, ++ start + blksize - 1, &cached_state, GFP_NOFS); + if (!em || IS_ERR(em)) + return 0; + +@@ -2951,6 +2969,7 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, + u32 flags = 0; + u64 disko = 0; + struct extent_map *em = NULL; ++ struct extent_state *cached_state = NULL; + int end = 0; + u64 em_start = 0, em_len = 0; + unsigned long emflags; +@@ -2959,8 +2978,8 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, + if (len == 0) + return -EINVAL; + +- lock_extent(&BTRFS_I(inode)->io_tree, start, start + len, +- GFP_NOFS); ++ lock_extent_bits(&BTRFS_I(inode)->io_tree, start, start + len, 0, ++ &cached_state, GFP_NOFS); + em = get_extent(inode, NULL, 0, off, max - off, 0); + if (!em) + goto out; +@@ -3023,8 +3042,8 @@ int extent_fiemap(struct inode *inode, struct fiemap_extent_info *fieinfo, + out_free: + free_extent_map(em); + out: +- unlock_extent(&BTRFS_I(inode)->io_tree, start, start + len, +- GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, start, start + len, ++ &cached_state, GFP_NOFS); + return ret; + } + +@@ -3264,7 +3283,8 @@ int set_extent_buffer_dirty(struct extent_io_tree *tree, + } + + int clear_extent_buffer_uptodate(struct extent_io_tree *tree, +- struct extent_buffer *eb) ++ struct extent_buffer *eb, ++ struct extent_state **cached_state) + { + unsigned long i; + struct page *page; +@@ -3274,7 +3294,7 @@ int clear_extent_buffer_uptodate(struct extent_io_tree *tree, + clear_bit(EXTENT_BUFFER_UPTODATE, &eb->bflags); + + clear_extent_uptodate(tree, eb->start, eb->start + eb->len - 1, +- GFP_NOFS); ++ cached_state, GFP_NOFS); + for (i = 0; i < num_pages; i++) { + page = extent_buffer_page(eb, i); + if (page) +@@ -3334,7 +3354,8 @@ int extent_range_uptodate(struct extent_io_tree *tree, + } + + int extent_buffer_uptodate(struct extent_io_tree *tree, +- struct extent_buffer *eb) ++ struct extent_buffer *eb, ++ struct extent_state *cached_state) + { + int ret = 0; + unsigned long num_pages; +@@ -3346,7 +3367,7 @@ int extent_buffer_uptodate(struct extent_io_tree *tree, + return 1; + + ret = test_range_bit(tree, eb->start, eb->start + eb->len - 1, +- EXTENT_UPTODATE, 1, NULL); ++ EXTENT_UPTODATE, 1, cached_state); + if (ret) + return ret; + +diff --git a/fs/btrfs/extent_io.h b/fs/btrfs/extent_io.h +index 36de250..bbab481 100644 +--- a/fs/btrfs/extent_io.h ++++ b/fs/btrfs/extent_io.h +@@ -163,6 +163,8 @@ int lock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); + int lock_extent_bits(struct extent_io_tree *tree, u64 start, u64 end, + int bits, struct extent_state **cached, gfp_t mask); + int unlock_extent(struct extent_io_tree *tree, u64 start, u64 end, gfp_t mask); ++int unlock_extent_cached(struct extent_io_tree *tree, u64 start, u64 end, ++ struct extent_state **cached, gfp_t mask); + int try_lock_extent(struct extent_io_tree *tree, u64 start, u64 end, + gfp_t mask); + int extent_read_full_page(struct extent_io_tree *tree, struct page *page, +@@ -196,7 +198,7 @@ int clear_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end, + int clear_extent_ordered_metadata(struct extent_io_tree *tree, u64 start, + u64 end, gfp_t mask); + int set_extent_delalloc(struct extent_io_tree *tree, u64 start, u64 end, +- gfp_t mask); ++ struct extent_state **cached_state, gfp_t mask); + int set_extent_ordered(struct extent_io_tree *tree, u64 start, u64 end, + gfp_t mask); + int find_first_extent_bit(struct extent_io_tree *tree, u64 start, +@@ -281,9 +283,11 @@ int test_extent_buffer_dirty(struct extent_io_tree *tree, + int set_extent_buffer_uptodate(struct extent_io_tree *tree, + struct extent_buffer *eb); + int clear_extent_buffer_uptodate(struct extent_io_tree *tree, +- struct extent_buffer *eb); ++ struct extent_buffer *eb, ++ struct extent_state **cached_state); + int extent_buffer_uptodate(struct extent_io_tree *tree, +- struct extent_buffer *eb); ++ struct extent_buffer *eb, ++ struct extent_state *cached_state); + int map_extent_buffer(struct extent_buffer *eb, unsigned long offset, + unsigned long min_len, char **token, char **map, + unsigned long *map_start, +diff --git a/fs/btrfs/extent_map.c b/fs/btrfs/extent_map.c +index 428fcac..28d87ba 100644 +--- a/fs/btrfs/extent_map.c ++++ b/fs/btrfs/extent_map.c +@@ -35,7 +35,7 @@ void extent_map_exit(void) + */ + void extent_map_tree_init(struct extent_map_tree *tree, gfp_t mask) + { +- tree->map.rb_node = NULL; ++ tree->map = RB_ROOT; + rwlock_init(&tree->lock); + } + +diff --git a/fs/btrfs/file.c b/fs/btrfs/file.c +index 6ed434a..ee3323c 100644 +--- a/fs/btrfs/file.c ++++ b/fs/btrfs/file.c +@@ -123,7 +123,8 @@ static noinline int dirty_and_release_pages(struct btrfs_trans_handle *trans, + root->sectorsize - 1) & ~((u64)root->sectorsize - 1); + + end_of_last_block = start_pos + num_bytes - 1; +- err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block); ++ err = btrfs_set_extent_delalloc(inode, start_pos, end_of_last_block, ++ NULL); + if (err) + return err; + +@@ -753,6 +754,7 @@ static noinline int prepare_pages(struct btrfs_root *root, struct file *file, + loff_t pos, unsigned long first_index, + unsigned long last_index, size_t write_bytes) + { ++ struct extent_state *cached_state = NULL; + int i; + unsigned long index = pos >> PAGE_CACHE_SHIFT; + struct inode *inode = fdentry(file)->d_inode; +@@ -781,16 +783,18 @@ again: + } + if (start_pos < inode->i_size) { + struct btrfs_ordered_extent *ordered; +- lock_extent(&BTRFS_I(inode)->io_tree, +- start_pos, last_pos - 1, GFP_NOFS); ++ lock_extent_bits(&BTRFS_I(inode)->io_tree, ++ start_pos, last_pos - 1, 0, &cached_state, ++ GFP_NOFS); + ordered = btrfs_lookup_first_ordered_extent(inode, + last_pos - 1); + if (ordered && + ordered->file_offset + ordered->len > start_pos && + ordered->file_offset < last_pos) { + btrfs_put_ordered_extent(ordered); +- unlock_extent(&BTRFS_I(inode)->io_tree, +- start_pos, last_pos - 1, GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, ++ start_pos, last_pos - 1, ++ &cached_state, GFP_NOFS); + for (i = 0; i < num_pages; i++) { + unlock_page(pages[i]); + page_cache_release(pages[i]); +@@ -802,12 +806,13 @@ again: + if (ordered) + btrfs_put_ordered_extent(ordered); + +- clear_extent_bits(&BTRFS_I(inode)->io_tree, start_pos, ++ clear_extent_bit(&BTRFS_I(inode)->io_tree, start_pos, + last_pos - 1, EXTENT_DIRTY | EXTENT_DELALLOC | +- EXTENT_DO_ACCOUNTING, ++ EXTENT_DO_ACCOUNTING, 0, 0, &cached_state, + GFP_NOFS); +- unlock_extent(&BTRFS_I(inode)->io_tree, +- start_pos, last_pos - 1, GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, ++ start_pos, last_pos - 1, &cached_state, ++ GFP_NOFS); + } + for (i = 0; i < num_pages; i++) { + clear_page_dirty_for_io(pages[i]); +diff --git a/fs/btrfs/free-space-cache.c b/fs/btrfs/free-space-cache.c +index cb2849f..dd831ed 100644 +--- a/fs/btrfs/free-space-cache.c ++++ b/fs/btrfs/free-space-cache.c +@@ -870,7 +870,7 @@ __btrfs_return_cluster_to_free_space( + tree_insert_offset(&block_group->free_space_offset, + entry->offset, &entry->offset_index, 0); + } +- cluster->root.rb_node = NULL; ++ cluster->root = RB_ROOT; + + out: + spin_unlock(&cluster->lock); +@@ -1355,7 +1355,7 @@ void btrfs_init_free_cluster(struct btrfs_free_cluster *cluster) + { + spin_lock_init(&cluster->lock); + spin_lock_init(&cluster->refill_lock); +- cluster->root.rb_node = NULL; ++ cluster->root = RB_ROOT; + cluster->max_size = 0; + cluster->points_to_bitmap = false; + INIT_LIST_HEAD(&cluster->block_group_list); +diff --git a/fs/btrfs/inode.c b/fs/btrfs/inode.c +index c41db6d..02bb099 100644 +--- a/fs/btrfs/inode.c ++++ b/fs/btrfs/inode.c +@@ -379,7 +379,8 @@ again: + * change at any time if we discover bad compression ratios. + */ + if (!(BTRFS_I(inode)->flags & BTRFS_INODE_NOCOMPRESS) && +- btrfs_test_opt(root, COMPRESS)) { ++ (btrfs_test_opt(root, COMPRESS) || ++ (BTRFS_I(inode)->force_compress))) { + WARN_ON(pages); + pages = kzalloc(sizeof(struct page *) * nr_pages, GFP_NOFS); + +@@ -483,8 +484,10 @@ again: + nr_pages_ret = 0; + + /* flag the file so we don't compress in the future */ +- if (!btrfs_test_opt(root, FORCE_COMPRESS)) ++ if (!btrfs_test_opt(root, FORCE_COMPRESS) && ++ !(BTRFS_I(inode)->force_compress)) { + BTRFS_I(inode)->flags |= BTRFS_INODE_NOCOMPRESS; ++ } + } + if (will_compress) { + *num_added += 1; +@@ -570,8 +573,8 @@ retry: + unsigned long nr_written = 0; + + lock_extent(io_tree, async_extent->start, +- async_extent->start + +- async_extent->ram_size - 1, GFP_NOFS); ++ async_extent->start + ++ async_extent->ram_size - 1, GFP_NOFS); + + /* allocate blocks */ + ret = cow_file_range(inode, async_cow->locked_page, +@@ -1211,7 +1214,8 @@ static int run_delalloc_range(struct inode *inode, struct page *locked_page, + else if (BTRFS_I(inode)->flags & BTRFS_INODE_PREALLOC) + ret = run_delalloc_nocow(inode, locked_page, start, end, + page_started, 0, nr_written); +- else if (!btrfs_test_opt(root, COMPRESS)) ++ else if (!btrfs_test_opt(root, COMPRESS) && ++ !(BTRFS_I(inode)->force_compress)) + ret = cow_file_range(inode, locked_page, start, end, + page_started, nr_written, 1); + else +@@ -1508,12 +1512,13 @@ static noinline int add_pending_csums(struct btrfs_trans_handle *trans, + return 0; + } + +-int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end) ++int btrfs_set_extent_delalloc(struct inode *inode, u64 start, u64 end, ++ struct extent_state **cached_state) + { + if ((end & (PAGE_CACHE_SIZE - 1)) == 0) + WARN_ON(1); + return set_extent_delalloc(&BTRFS_I(inode)->io_tree, start, end, +- GFP_NOFS); ++ cached_state, GFP_NOFS); + } + + /* see btrfs_writepage_start_hook for details on why this is required */ +@@ -1526,6 +1531,7 @@ static void btrfs_writepage_fixup_worker(struct btrfs_work *work) + { + struct btrfs_writepage_fixup *fixup; + struct btrfs_ordered_extent *ordered; ++ struct extent_state *cached_state = NULL; + struct page *page; + struct inode *inode; + u64 page_start; +@@ -1544,7 +1550,8 @@ again: + page_start = page_offset(page); + page_end = page_offset(page) + PAGE_CACHE_SIZE - 1; + +- lock_extent(&BTRFS_I(inode)->io_tree, page_start, page_end, GFP_NOFS); ++ lock_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, 0, ++ &cached_state, GFP_NOFS); + + /* already ordered? We're done */ + if (PagePrivate2(page)) +@@ -1552,17 +1559,18 @@ again: + + ordered = btrfs_lookup_ordered_extent(inode, page_start); + if (ordered) { +- unlock_extent(&BTRFS_I(inode)->io_tree, page_start, +- page_end, GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, ++ page_end, &cached_state, GFP_NOFS); + unlock_page(page); + btrfs_start_ordered_extent(inode, ordered, 1); + goto again; + } + +- btrfs_set_extent_delalloc(inode, page_start, page_end); ++ btrfs_set_extent_delalloc(inode, page_start, page_end, &cached_state); + ClearPageChecked(page); + out: +- unlock_extent(&BTRFS_I(inode)->io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, page_start, page_end, ++ &cached_state, GFP_NOFS); + out_page: + unlock_page(page); + page_cache_release(page); +@@ -1691,14 +1699,14 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) + struct btrfs_trans_handle *trans; + struct btrfs_ordered_extent *ordered_extent = NULL; + struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; ++ struct extent_state *cached_state = NULL; + int compressed = 0; + int ret; + +- ret = btrfs_dec_test_ordered_pending(inode, start, end - start + 1); ++ ret = btrfs_dec_test_ordered_pending(inode, &ordered_extent, start, ++ end - start + 1); + if (!ret) + return 0; +- +- ordered_extent = btrfs_lookup_ordered_extent(inode, start); + BUG_ON(!ordered_extent); + + if (test_bit(BTRFS_ORDERED_NOCOW, &ordered_extent->flags)) { +@@ -1713,9 +1721,9 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) + goto out; + } + +- lock_extent(io_tree, ordered_extent->file_offset, +- ordered_extent->file_offset + ordered_extent->len - 1, +- GFP_NOFS); ++ lock_extent_bits(io_tree, ordered_extent->file_offset, ++ ordered_extent->file_offset + ordered_extent->len - 1, ++ 0, &cached_state, GFP_NOFS); + + trans = btrfs_join_transaction(root, 1); + +@@ -1742,9 +1750,10 @@ static int btrfs_finish_ordered_io(struct inode *inode, u64 start, u64 end) + ordered_extent->len); + BUG_ON(ret); + } +- unlock_extent(io_tree, ordered_extent->file_offset, +- ordered_extent->file_offset + ordered_extent->len - 1, +- GFP_NOFS); ++ unlock_extent_cached(io_tree, ordered_extent->file_offset, ++ ordered_extent->file_offset + ++ ordered_extent->len - 1, &cached_state, GFP_NOFS); ++ + add_pending_csums(trans, inode, ordered_extent->file_offset, + &ordered_extent->list); + +@@ -2153,7 +2162,7 @@ void btrfs_orphan_cleanup(struct btrfs_root *root) + found_key.objectid = found_key.offset; + found_key.type = BTRFS_INODE_ITEM_KEY; + found_key.offset = 0; +- inode = btrfs_iget(root->fs_info->sb, &found_key, root); ++ inode = btrfs_iget(root->fs_info->sb, &found_key, root, NULL); + if (IS_ERR(inode)) + break; + +@@ -3081,6 +3090,7 @@ static int btrfs_truncate_page(struct address_space *mapping, loff_t from) + struct btrfs_root *root = BTRFS_I(inode)->root; + struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; + struct btrfs_ordered_extent *ordered; ++ struct extent_state *cached_state = NULL; + char *kaddr; + u32 blocksize = root->sectorsize; + pgoff_t index = from >> PAGE_CACHE_SHIFT; +@@ -3127,12 +3137,14 @@ again: + } + wait_on_page_writeback(page); + +- lock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state, ++ GFP_NOFS); + set_page_extent_mapped(page); + + ordered = btrfs_lookup_ordered_extent(inode, page_start); + if (ordered) { +- unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(io_tree, page_start, page_end, ++ &cached_state, GFP_NOFS); + unlock_page(page); + page_cache_release(page); + btrfs_start_ordered_extent(inode, ordered, 1); +@@ -3140,13 +3152,15 @@ again: + goto again; + } + +- clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, ++ clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end, + EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, +- GFP_NOFS); ++ 0, 0, &cached_state, GFP_NOFS); + +- ret = btrfs_set_extent_delalloc(inode, page_start, page_end); ++ ret = btrfs_set_extent_delalloc(inode, page_start, page_end, ++ &cached_state); + if (ret) { +- unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(io_tree, page_start, page_end, ++ &cached_state, GFP_NOFS); + goto out_unlock; + } + +@@ -3159,7 +3173,8 @@ again: + } + ClearPageChecked(page); + set_page_dirty(page); +- unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(io_tree, page_start, page_end, &cached_state, ++ GFP_NOFS); + + out_unlock: + if (ret) +@@ -3177,6 +3192,7 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) + struct btrfs_root *root = BTRFS_I(inode)->root; + struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; + struct extent_map *em; ++ struct extent_state *cached_state = NULL; + u64 mask = root->sectorsize - 1; + u64 hole_start = (inode->i_size + mask) & ~mask; + u64 block_end = (size + mask) & ~mask; +@@ -3192,11 +3208,13 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) + struct btrfs_ordered_extent *ordered; + btrfs_wait_ordered_range(inode, hole_start, + block_end - hole_start); +- lock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); ++ lock_extent_bits(io_tree, hole_start, block_end - 1, 0, ++ &cached_state, GFP_NOFS); + ordered = btrfs_lookup_ordered_extent(inode, hole_start); + if (!ordered) + break; +- unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); ++ unlock_extent_cached(io_tree, hole_start, block_end - 1, ++ &cached_state, GFP_NOFS); + btrfs_put_ordered_extent(ordered); + } + +@@ -3241,7 +3259,8 @@ int btrfs_cont_expand(struct inode *inode, loff_t size) + break; + } + +- unlock_extent(io_tree, hole_start, block_end - 1, GFP_NOFS); ++ unlock_extent_cached(io_tree, hole_start, block_end - 1, &cached_state, ++ GFP_NOFS); + return err; + } + +@@ -3639,6 +3658,7 @@ static noinline void init_btrfs_i(struct inode *inode) + bi->index_cnt = (u64)-1; + bi->last_unlink_trans = 0; + bi->ordered_data_close = 0; ++ bi->force_compress = 0; + extent_map_tree_init(&BTRFS_I(inode)->extent_tree, GFP_NOFS); + extent_io_tree_init(&BTRFS_I(inode)->io_tree, + inode->i_mapping, GFP_NOFS); +@@ -3687,7 +3707,7 @@ static struct inode *btrfs_iget_locked(struct super_block *s, + * Returns in *is_new if the inode was read from disk + */ + struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, +- struct btrfs_root *root) ++ struct btrfs_root *root, int *new) + { + struct inode *inode; + +@@ -3702,6 +3722,8 @@ struct inode *btrfs_iget(struct super_block *s, struct btrfs_key *location, + + inode_tree_add(inode); + unlock_new_inode(inode); ++ if (new) ++ *new = 1; + } + + return inode; +@@ -3754,7 +3776,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) + return NULL; + + if (location.type == BTRFS_INODE_ITEM_KEY) { +- inode = btrfs_iget(dir->i_sb, &location, root); ++ inode = btrfs_iget(dir->i_sb, &location, root, NULL); + return inode; + } + +@@ -3769,7 +3791,7 @@ struct inode *btrfs_lookup_dentry(struct inode *dir, struct dentry *dentry) + else + inode = new_simple_dir(dir->i_sb, &location, sub_root); + } else { +- inode = btrfs_iget(dir->i_sb, &location, sub_root); ++ inode = btrfs_iget(dir->i_sb, &location, sub_root, NULL); + } + srcu_read_unlock(&root->fs_info->subvol_srcu, index); + +@@ -4501,7 +4523,7 @@ static int btrfs_mkdir(struct inode *dir, struct dentry *dentry, int mode) + err = btrfs_find_free_objectid(trans, root, dir->i_ino, &objectid); + if (err) { + err = -ENOSPC; +- goto out_unlock; ++ goto out_fail; + } + + inode = btrfs_new_inode(trans, root, dir, dentry->d_name.name, +@@ -4979,6 +5001,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) + { + struct extent_io_tree *tree; + struct btrfs_ordered_extent *ordered; ++ struct extent_state *cached_state = NULL; + u64 page_start = page_offset(page); + u64 page_end = page_start + PAGE_CACHE_SIZE - 1; + +@@ -4997,7 +5020,8 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) + btrfs_releasepage(page, GFP_NOFS); + return; + } +- lock_extent(tree, page_start, page_end, GFP_NOFS); ++ lock_extent_bits(tree, page_start, page_end, 0, &cached_state, ++ GFP_NOFS); + ordered = btrfs_lookup_ordered_extent(page->mapping->host, + page_offset(page)); + if (ordered) { +@@ -5008,7 +5032,7 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) + clear_extent_bit(tree, page_start, page_end, + EXTENT_DIRTY | EXTENT_DELALLOC | + EXTENT_LOCKED | EXTENT_DO_ACCOUNTING, 1, 0, +- NULL, GFP_NOFS); ++ &cached_state, GFP_NOFS); + /* + * whoever cleared the private bit is responsible + * for the finish_ordered_io +@@ -5018,11 +5042,13 @@ static void btrfs_invalidatepage(struct page *page, unsigned long offset) + page_start, page_end); + } + btrfs_put_ordered_extent(ordered); +- lock_extent(tree, page_start, page_end, GFP_NOFS); ++ cached_state = NULL; ++ lock_extent_bits(tree, page_start, page_end, 0, &cached_state, ++ GFP_NOFS); + } + clear_extent_bit(tree, page_start, page_end, + EXTENT_LOCKED | EXTENT_DIRTY | EXTENT_DELALLOC | +- EXTENT_DO_ACCOUNTING, 1, 1, NULL, GFP_NOFS); ++ EXTENT_DO_ACCOUNTING, 1, 1, &cached_state, GFP_NOFS); + __btrfs_releasepage(page, GFP_NOFS); + + ClearPageChecked(page); +@@ -5055,6 +5081,7 @@ int btrfs_page_mkwrite(struct vm_area_struct *vma, struct vm_fault *vmf) + struct btrfs_root *root = BTRFS_I(inode)->root; + struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; + struct btrfs_ordered_extent *ordered; ++ struct extent_state *cached_state = NULL; + char *kaddr; + unsigned long zero_start; + loff_t size; +@@ -5093,7 +5120,8 @@ again: + } + wait_on_page_writeback(page); + +- lock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ lock_extent_bits(io_tree, page_start, page_end, 0, &cached_state, ++ GFP_NOFS); + set_page_extent_mapped(page); + + /* +@@ -5102,7 +5130,8 @@ again: + */ + ordered = btrfs_lookup_ordered_extent(inode, page_start); + if (ordered) { +- unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(io_tree, page_start, page_end, ++ &cached_state, GFP_NOFS); + unlock_page(page); + btrfs_start_ordered_extent(inode, ordered, 1); + btrfs_put_ordered_extent(ordered); +@@ -5116,13 +5145,15 @@ again: + * is probably a better way to do this, but for now keep consistent with + * prepare_pages in the normal write path. + */ +- clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, page_end, ++ clear_extent_bit(&BTRFS_I(inode)->io_tree, page_start, page_end, + EXTENT_DIRTY | EXTENT_DELALLOC | EXTENT_DO_ACCOUNTING, +- GFP_NOFS); ++ 0, 0, &cached_state, GFP_NOFS); + +- ret = btrfs_set_extent_delalloc(inode, page_start, page_end); ++ ret = btrfs_set_extent_delalloc(inode, page_start, page_end, ++ &cached_state); + if (ret) { +- unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(io_tree, page_start, page_end, ++ &cached_state, GFP_NOFS); + ret = VM_FAULT_SIGBUS; + btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); + goto out_unlock; +@@ -5148,7 +5179,7 @@ again: + BTRFS_I(inode)->last_trans = root->fs_info->generation; + BTRFS_I(inode)->last_sub_trans = BTRFS_I(inode)->root->log_transid; + +- unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ unlock_extent_cached(io_tree, page_start, page_end, &cached_state, GFP_NOFS); + + out_unlock: + btrfs_unreserve_metadata_for_delalloc(root, inode, 1); +@@ -5827,6 +5858,7 @@ stop_trans: + static long btrfs_fallocate(struct inode *inode, int mode, + loff_t offset, loff_t len) + { ++ struct extent_state *cached_state = NULL; + u64 cur_offset; + u64 last_byte; + u64 alloc_start; +@@ -5865,16 +5897,17 @@ static long btrfs_fallocate(struct inode *inode, int mode, + /* the extent lock is ordered inside the running + * transaction + */ +- lock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, +- GFP_NOFS); ++ lock_extent_bits(&BTRFS_I(inode)->io_tree, alloc_start, ++ locked_end, 0, &cached_state, GFP_NOFS); + ordered = btrfs_lookup_first_ordered_extent(inode, + alloc_end - 1); + if (ordered && + ordered->file_offset + ordered->len > alloc_start && + ordered->file_offset < alloc_end) { + btrfs_put_ordered_extent(ordered); +- unlock_extent(&BTRFS_I(inode)->io_tree, +- alloc_start, locked_end, GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, ++ alloc_start, locked_end, ++ &cached_state, GFP_NOFS); + /* + * we can't wait on the range with the transaction + * running or with the extent lock held +@@ -5916,8 +5949,8 @@ static long btrfs_fallocate(struct inode *inode, int mode, + break; + } + } +- unlock_extent(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, +- GFP_NOFS); ++ unlock_extent_cached(&BTRFS_I(inode)->io_tree, alloc_start, locked_end, ++ &cached_state, GFP_NOFS); + + btrfs_free_reserved_data_space(BTRFS_I(inode)->root, inode, + alloc_end - alloc_start); +diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c +index 645a179..2845c6c 100644 +--- a/fs/btrfs/ioctl.c ++++ b/fs/btrfs/ioctl.c +@@ -48,6 +48,7 @@ + #include "print-tree.h" + #include "volumes.h" + #include "locking.h" ++#include "ctree.h" + + /* Mask out flags that are inappropriate for the given type of inode. */ + static inline __u32 btrfs_mask_flags(umode_t mode, __u32 flags) +@@ -474,7 +475,79 @@ out_unlock: + return error; + } + +-static int btrfs_defrag_file(struct file *file) ++static int should_defrag_range(struct inode *inode, u64 start, u64 len, ++ int thresh, u64 *last_len, u64 *skip, ++ u64 *defrag_end) ++{ ++ struct extent_io_tree *io_tree = &BTRFS_I(inode)->io_tree; ++ struct extent_map *em = NULL; ++ struct extent_map_tree *em_tree = &BTRFS_I(inode)->extent_tree; ++ int ret = 1; ++ ++ ++ if (thresh == 0) ++ thresh = 256 * 1024; ++ ++ /* ++ * make sure that once we start defragging and extent, we keep on ++ * defragging it ++ */ ++ if (start < *defrag_end) ++ return 1; ++ ++ *skip = 0; ++ ++ /* ++ * hopefully we have this extent in the tree already, try without ++ * the full extent lock ++ */ ++ read_lock(&em_tree->lock); ++ em = lookup_extent_mapping(em_tree, start, len); ++ read_unlock(&em_tree->lock); ++ ++ if (!em) { ++ /* get the big lock and read metadata off disk */ ++ lock_extent(io_tree, start, start + len - 1, GFP_NOFS); ++ em = btrfs_get_extent(inode, NULL, 0, start, len, 0); ++ unlock_extent(io_tree, start, start + len - 1, GFP_NOFS); ++ ++ if (!em) ++ return 0; ++ } ++ ++ /* this will cover holes, and inline extents */ ++ if (em->block_start >= EXTENT_MAP_LAST_BYTE) ++ ret = 0; ++ ++ /* ++ * we hit a real extent, if it is big don't bother defragging it again ++ */ ++ if ((*last_len == 0 || *last_len >= thresh) && em->len >= thresh) ++ ret = 0; ++ ++ /* ++ * last_len ends up being a counter of how many bytes we've defragged. ++ * every time we choose not to defrag an extent, we reset *last_len ++ * so that the next tiny extent will force a defrag. ++ * ++ * The end result of this is that tiny extents before a single big ++ * extent will force at least part of that big extent to be defragged. ++ */ ++ if (ret) { ++ *last_len += len; ++ *defrag_end = extent_map_end(em); ++ } else { ++ *last_len = 0; ++ *skip = extent_map_end(em); ++ *defrag_end = 0; ++ } ++ ++ free_extent_map(em); ++ return ret; ++} ++ ++static int btrfs_defrag_file(struct file *file, ++ struct btrfs_ioctl_defrag_range_args *range) + { + struct inode *inode = fdentry(file)->d_inode; + struct btrfs_root *root = BTRFS_I(inode)->root; +@@ -486,37 +559,96 @@ static int btrfs_defrag_file(struct file *file) + unsigned long total_read = 0; + u64 page_start; + u64 page_end; ++ u64 last_len = 0; ++ u64 skip = 0; ++ u64 defrag_end = 0; + unsigned long i; + int ret; + +- ret = btrfs_check_data_free_space(root, inode, inode->i_size); +- if (ret) +- return -ENOSPC; ++ if (inode->i_size == 0) ++ return 0; ++ ++ if (range->start + range->len > range->start) { ++ last_index = min_t(u64, inode->i_size - 1, ++ range->start + range->len - 1) >> PAGE_CACHE_SHIFT; ++ } else { ++ last_index = (inode->i_size - 1) >> PAGE_CACHE_SHIFT; ++ } ++ ++ i = range->start >> PAGE_CACHE_SHIFT; ++ while (i <= last_index) { ++ if (!should_defrag_range(inode, (u64)i << PAGE_CACHE_SHIFT, ++ PAGE_CACHE_SIZE, ++ range->extent_thresh, ++ &last_len, &skip, ++ &defrag_end)) { ++ unsigned long next; ++ /* ++ * the should_defrag function tells us how much to skip ++ * bump our counter by the suggested amount ++ */ ++ next = (skip + PAGE_CACHE_SIZE - 1) >> PAGE_CACHE_SHIFT; ++ i = max(i + 1, next); ++ continue; ++ } + +- mutex_lock(&inode->i_mutex); +- last_index = inode->i_size >> PAGE_CACHE_SHIFT; +- for (i = 0; i <= last_index; i++) { + if (total_read % ra_pages == 0) { + btrfs_force_ra(inode->i_mapping, &file->f_ra, file, i, + min(last_index, i + ra_pages - 1)); + } + total_read++; ++ mutex_lock(&inode->i_mutex); ++ if (range->flags & BTRFS_DEFRAG_RANGE_COMPRESS) ++ BTRFS_I(inode)->force_compress = 1; ++ ++ ret = btrfs_check_data_free_space(root, inode, PAGE_CACHE_SIZE); ++ if (ret) { ++ ret = -ENOSPC; ++ break; ++ } ++ ++ ret = btrfs_reserve_metadata_for_delalloc(root, inode, 1); ++ if (ret) { ++ btrfs_free_reserved_data_space(root, inode, ++ PAGE_CACHE_SIZE); ++ ret = -ENOSPC; ++ break; ++ } + again: ++ if (inode->i_size == 0 || ++ i > ((inode->i_size - 1) >> PAGE_CACHE_SHIFT)) { ++ ret = 0; ++ goto err_reservations; ++ } ++ + page = grab_cache_page(inode->i_mapping, i); + if (!page) +- goto out_unlock; ++ goto err_reservations; ++ + if (!PageUptodate(page)) { + btrfs_readpage(NULL, page); + lock_page(page); + if (!PageUptodate(page)) { + unlock_page(page); + page_cache_release(page); +- goto out_unlock; ++ goto err_reservations; + } + } + ++ if (page->mapping != inode->i_mapping) { ++ unlock_page(page); ++ page_cache_release(page); ++ goto again; ++ } ++ + wait_on_page_writeback(page); + ++ if (PageDirty(page)) { ++ btrfs_free_reserved_data_space(root, inode, ++ PAGE_CACHE_SIZE); ++ goto loop_unlock; ++ } ++ + page_start = (u64)page->index << PAGE_CACHE_SHIFT; + page_end = page_start + PAGE_CACHE_SIZE - 1; + lock_extent(io_tree, page_start, page_end, GFP_NOFS); +@@ -537,18 +669,54 @@ again: + * page if it is dirtied again later + */ + clear_page_dirty_for_io(page); ++ clear_extent_bits(&BTRFS_I(inode)->io_tree, page_start, ++ page_end, EXTENT_DIRTY | EXTENT_DELALLOC | ++ EXTENT_DO_ACCOUNTING, GFP_NOFS); + +- btrfs_set_extent_delalloc(inode, page_start, page_end); ++ btrfs_set_extent_delalloc(inode, page_start, page_end, NULL); ++ ClearPageChecked(page); + set_page_dirty(page); + unlock_extent(io_tree, page_start, page_end, GFP_NOFS); ++ ++loop_unlock: + unlock_page(page); + page_cache_release(page); ++ mutex_unlock(&inode->i_mutex); ++ ++ btrfs_unreserve_metadata_for_delalloc(root, inode, 1); + balance_dirty_pages_ratelimited_nr(inode->i_mapping, 1); ++ i++; ++ } ++ ++ if ((range->flags & BTRFS_DEFRAG_RANGE_START_IO)) ++ filemap_flush(inode->i_mapping); ++ ++ if ((range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) { ++ /* the filemap_flush will queue IO into the worker threads, but ++ * we have to make sure the IO is actually started and that ++ * ordered extents get created before we return ++ */ ++ atomic_inc(&root->fs_info->async_submit_draining); ++ while (atomic_read(&root->fs_info->nr_async_submits) || ++ atomic_read(&root->fs_info->async_delalloc_pages)) { ++ wait_event(root->fs_info->async_submit_wait, ++ (atomic_read(&root->fs_info->nr_async_submits) == 0 && ++ atomic_read(&root->fs_info->async_delalloc_pages) == 0)); ++ } ++ atomic_dec(&root->fs_info->async_submit_draining); ++ ++ mutex_lock(&inode->i_mutex); ++ BTRFS_I(inode)->force_compress = 0; ++ mutex_unlock(&inode->i_mutex); + } + +-out_unlock: +- mutex_unlock(&inode->i_mutex); + return 0; ++ ++err_reservations: ++ mutex_unlock(&inode->i_mutex); ++ btrfs_free_reserved_data_space(root, inode, PAGE_CACHE_SIZE); ++ btrfs_unreserve_metadata_for_delalloc(root, inode, 1); ++ return ret; + } + + static noinline int btrfs_ioctl_resize(struct btrfs_root *root, +@@ -608,7 +776,7 @@ static noinline int btrfs_ioctl_resize(struct btrfs_root *root, + mod = 1; + sizestr++; + } +- new_size = btrfs_parse_size(sizestr); ++ new_size = memparse(sizestr, NULL); + if (new_size == 0) { + ret = -EINVAL; + goto out_unlock; +@@ -743,6 +911,327 @@ out: + return ret; + } + ++static noinline int key_in_sk(struct btrfs_key *key, ++ struct btrfs_ioctl_search_key *sk) ++{ ++ struct btrfs_key test; ++ int ret; ++ ++ test.objectid = sk->min_objectid; ++ test.type = sk->min_type; ++ test.offset = sk->min_offset; ++ ++ ret = btrfs_comp_cpu_keys(key, &test); ++ if (ret < 0) ++ return 0; ++ ++ test.objectid = sk->max_objectid; ++ test.type = sk->max_type; ++ test.offset = sk->max_offset; ++ ++ ret = btrfs_comp_cpu_keys(key, &test); ++ if (ret > 0) ++ return 0; ++ return 1; ++} ++ ++static noinline int copy_to_sk(struct btrfs_root *root, ++ struct btrfs_path *path, ++ struct btrfs_key *key, ++ struct btrfs_ioctl_search_key *sk, ++ char *buf, ++ unsigned long *sk_offset, ++ int *num_found) ++{ ++ u64 found_transid; ++ struct extent_buffer *leaf; ++ struct btrfs_ioctl_search_header sh; ++ unsigned long item_off; ++ unsigned long item_len; ++ int nritems; ++ int i; ++ int slot; ++ int found = 0; ++ int ret = 0; ++ ++ leaf = path->nodes[0]; ++ slot = path->slots[0]; ++ nritems = btrfs_header_nritems(leaf); ++ ++ if (btrfs_header_generation(leaf) > sk->max_transid) { ++ i = nritems; ++ goto advance_key; ++ } ++ found_transid = btrfs_header_generation(leaf); ++ ++ for (i = slot; i < nritems; i++) { ++ item_off = btrfs_item_ptr_offset(leaf, i); ++ item_len = btrfs_item_size_nr(leaf, i); ++ ++ if (item_len > BTRFS_SEARCH_ARGS_BUFSIZE) ++ item_len = 0; ++ ++ if (sizeof(sh) + item_len + *sk_offset > ++ BTRFS_SEARCH_ARGS_BUFSIZE) { ++ ret = 1; ++ goto overflow; ++ } ++ ++ btrfs_item_key_to_cpu(leaf, key, i); ++ if (!key_in_sk(key, sk)) ++ continue; ++ ++ sh.objectid = key->objectid; ++ sh.offset = key->offset; ++ sh.type = key->type; ++ sh.len = item_len; ++ sh.transid = found_transid; ++ ++ /* copy search result header */ ++ memcpy(buf + *sk_offset, &sh, sizeof(sh)); ++ *sk_offset += sizeof(sh); ++ ++ if (item_len) { ++ char *p = buf + *sk_offset; ++ /* copy the item */ ++ read_extent_buffer(leaf, p, ++ item_off, item_len); ++ *sk_offset += item_len; ++ } ++ found++; ++ ++ if (*num_found >= sk->nr_items) ++ break; ++ } ++advance_key: ++ ret = 0; ++ if (key->offset < (u64)-1 && key->offset < sk->max_offset) ++ key->offset++; ++ else if (key->type < (u8)-1 && key->type < sk->max_type) { ++ key->offset = 0; ++ key->type++; ++ } else if (key->objectid < (u64)-1 && key->objectid < sk->max_objectid) { ++ key->offset = 0; ++ key->type = 0; ++ key->objectid++; ++ } else ++ ret = 1; ++overflow: ++ *num_found += found; ++ return ret; ++} ++ ++static noinline int search_ioctl(struct inode *inode, ++ struct btrfs_ioctl_search_args *args) ++{ ++ struct btrfs_root *root; ++ struct btrfs_key key; ++ struct btrfs_key max_key; ++ struct btrfs_path *path; ++ struct btrfs_ioctl_search_key *sk = &args->key; ++ struct btrfs_fs_info *info = BTRFS_I(inode)->root->fs_info; ++ int ret; ++ int num_found = 0; ++ unsigned long sk_offset = 0; ++ ++ path = btrfs_alloc_path(); ++ if (!path) ++ return -ENOMEM; ++ ++ if (sk->tree_id == 0) { ++ /* search the root of the inode that was passed */ ++ root = BTRFS_I(inode)->root; ++ } else { ++ key.objectid = sk->tree_id; ++ key.type = BTRFS_ROOT_ITEM_KEY; ++ key.offset = (u64)-1; ++ root = btrfs_read_fs_root_no_name(info, &key); ++ if (IS_ERR(root)) { ++ printk(KERN_ERR "could not find root %llu\n", ++ sk->tree_id); ++ btrfs_free_path(path); ++ return -ENOENT; ++ } ++ } ++ ++ key.objectid = sk->min_objectid; ++ key.type = sk->min_type; ++ key.offset = sk->min_offset; ++ ++ max_key.objectid = sk->max_objectid; ++ max_key.type = sk->max_type; ++ max_key.offset = sk->max_offset; ++ ++ path->keep_locks = 1; ++ ++ while(1) { ++ ret = btrfs_search_forward(root, &key, &max_key, path, 0, ++ sk->min_transid); ++ if (ret != 0) { ++ if (ret > 0) ++ ret = 0; ++ goto err; ++ } ++ ret = copy_to_sk(root, path, &key, sk, args->buf, ++ &sk_offset, &num_found); ++ btrfs_release_path(root, path); ++ if (ret || num_found >= sk->nr_items) ++ break; ++ ++ } ++ ret = 0; ++err: ++ sk->nr_items = num_found; ++ btrfs_free_path(path); ++ return ret; ++} ++ ++static noinline int btrfs_ioctl_tree_search(struct file *file, ++ void __user *argp) ++{ ++ struct btrfs_ioctl_search_args *args; ++ struct inode *inode; ++ int ret; ++ ++ if (!capable(CAP_SYS_ADMIN)) ++ return -EPERM; ++ ++ args = kmalloc(sizeof(*args), GFP_KERNEL); ++ if (!args) ++ return -ENOMEM; ++ ++ if (copy_from_user(args, argp, sizeof(*args))) { ++ kfree(args); ++ return -EFAULT; ++ } ++ inode = fdentry(file)->d_inode; ++ ret = search_ioctl(inode, args); ++ if (ret == 0 && copy_to_user(argp, args, sizeof(*args))) ++ ret = -EFAULT; ++ kfree(args); ++ return ret; ++} ++ ++/* ++ * Search INODE_REFs to identify path name of 'dirid' directory ++ * in a 'tree_id' tree. and sets path name to 'name'. ++ */ ++static noinline int btrfs_search_path_in_tree(struct btrfs_fs_info *info, ++ u64 tree_id, u64 dirid, char *name) ++{ ++ struct btrfs_root *root; ++ struct btrfs_key key; ++ char *ptr; ++ int ret = -1; ++ int slot; ++ int len; ++ int total_len = 0; ++ struct btrfs_inode_ref *iref; ++ struct extent_buffer *l; ++ struct btrfs_path *path; ++ ++ if (dirid == BTRFS_FIRST_FREE_OBJECTID) { ++ name[0]='\0'; ++ return 0; ++ } ++ ++ path = btrfs_alloc_path(); ++ if (!path) ++ return -ENOMEM; ++ ++ ptr = &name[BTRFS_INO_LOOKUP_PATH_MAX]; ++ ++ key.objectid = tree_id; ++ key.type = BTRFS_ROOT_ITEM_KEY; ++ key.offset = (u64)-1; ++ root = btrfs_read_fs_root_no_name(info, &key); ++ if (IS_ERR(root)) { ++ printk(KERN_ERR "could not find root %llu\n", tree_id); ++ ret = -ENOENT; ++ goto out; ++ } ++ ++ key.objectid = dirid; ++ key.type = BTRFS_INODE_REF_KEY; ++ key.offset = (u64)-1; ++ ++ while(1) { ++ ret = btrfs_search_slot(NULL, root, &key, path, 0, 0); ++ if (ret < 0) ++ goto out; ++ ++ l = path->nodes[0]; ++ slot = path->slots[0]; ++ if (ret > 0 && slot > 0) ++ slot--; ++ btrfs_item_key_to_cpu(l, &key, slot); ++ ++ if (ret > 0 && (key.objectid != dirid || ++ key.type != BTRFS_INODE_REF_KEY)) { ++ ret = -ENOENT; ++ goto out; ++ } ++ ++ iref = btrfs_item_ptr(l, slot, struct btrfs_inode_ref); ++ len = btrfs_inode_ref_name_len(l, iref); ++ ptr -= len + 1; ++ total_len += len + 1; ++ if (ptr < name) ++ goto out; ++ ++ *(ptr + len) = '/'; ++ read_extent_buffer(l, ptr,(unsigned long)(iref + 1), len); ++ ++ if (key.offset == BTRFS_FIRST_FREE_OBJECTID) ++ break; ++ ++ btrfs_release_path(root, path); ++ key.objectid = key.offset; ++ key.offset = (u64)-1; ++ dirid = key.objectid; ++ ++ } ++ if (ptr < name) ++ goto out; ++ memcpy(name, ptr, total_len); ++ name[total_len]='\0'; ++ ret = 0; ++out: ++ btrfs_free_path(path); ++ return ret; ++} ++ ++static noinline int btrfs_ioctl_ino_lookup(struct file *file, ++ void __user *argp) ++{ ++ struct btrfs_ioctl_ino_lookup_args *args; ++ struct inode *inode; ++ int ret; ++ ++ if (!capable(CAP_SYS_ADMIN)) ++ return -EPERM; ++ ++ args = kmalloc(sizeof(*args), GFP_KERNEL); ++ if (copy_from_user(args, argp, sizeof(*args))) { ++ kfree(args); ++ return -EFAULT; ++ } ++ inode = fdentry(file)->d_inode; ++ ++ if (args->treeid == 0) ++ args->treeid = BTRFS_I(inode)->root->root_key.objectid; ++ ++ ret = btrfs_search_path_in_tree(BTRFS_I(inode)->root->fs_info, ++ args->treeid, args->objectid, ++ args->name); ++ ++ if (ret == 0 && copy_to_user(argp, args, sizeof(*args))) ++ ret = -EFAULT; ++ ++ kfree(args); ++ return ret; ++} ++ + static noinline int btrfs_ioctl_snap_destroy(struct file *file, + void __user *arg) + { +@@ -849,10 +1338,11 @@ out: + return err; + } + +-static int btrfs_ioctl_defrag(struct file *file) ++static int btrfs_ioctl_defrag(struct file *file, void __user *argp) + { + struct inode *inode = fdentry(file)->d_inode; + struct btrfs_root *root = BTRFS_I(inode)->root; ++ struct btrfs_ioctl_defrag_range_args *range; + int ret; + + ret = mnt_want_write(file->f_path.mnt); +@@ -873,7 +1363,30 @@ static int btrfs_ioctl_defrag(struct file *file) + ret = -EINVAL; + goto out; + } +- btrfs_defrag_file(file); ++ ++ range = kzalloc(sizeof(*range), GFP_KERNEL); ++ if (!range) { ++ ret = -ENOMEM; ++ goto out; ++ } ++ ++ if (argp) { ++ if (copy_from_user(range, argp, ++ sizeof(*range))) { ++ ret = -EFAULT; ++ kfree(range); ++ } ++ /* compression requires us to start the IO */ ++ if ((range->flags & BTRFS_DEFRAG_RANGE_COMPRESS)) { ++ range->flags |= BTRFS_DEFRAG_RANGE_START_IO; ++ range->extent_thresh = (u32)-1; ++ } ++ } else { ++ /* the rest are all set to zero by kzalloc */ ++ range->len = (u64)-1; ++ } ++ btrfs_defrag_file(file, range); ++ kfree(range); + break; + } + out: +@@ -1274,6 +1787,157 @@ out: + return ret; + } + ++static long btrfs_ioctl_default_subvol(struct file *file, void __user *argp) ++{ ++ struct inode *inode = fdentry(file)->d_inode; ++ struct btrfs_root *root = BTRFS_I(inode)->root; ++ struct btrfs_root *new_root; ++ struct btrfs_dir_item *di; ++ struct btrfs_trans_handle *trans; ++ struct btrfs_path *path; ++ struct btrfs_key location; ++ struct btrfs_disk_key disk_key; ++ struct btrfs_super_block *disk_super; ++ u64 features; ++ u64 objectid = 0; ++ u64 dir_id; ++ ++ if (!capable(CAP_SYS_ADMIN)) ++ return -EPERM; ++ ++ if (copy_from_user(&objectid, argp, sizeof(objectid))) ++ return -EFAULT; ++ ++ if (!objectid) ++ objectid = root->root_key.objectid; ++ ++ location.objectid = objectid; ++ location.type = BTRFS_ROOT_ITEM_KEY; ++ location.offset = (u64)-1; ++ ++ new_root = btrfs_read_fs_root_no_name(root->fs_info, &location); ++ if (IS_ERR(new_root)) ++ return PTR_ERR(new_root); ++ ++ if (btrfs_root_refs(&new_root->root_item) == 0) ++ return -ENOENT; ++ ++ path = btrfs_alloc_path(); ++ if (!path) ++ return -ENOMEM; ++ path->leave_spinning = 1; ++ ++ trans = btrfs_start_transaction(root, 1); ++ if (!trans) { ++ btrfs_free_path(path); ++ return -ENOMEM; ++ } ++ ++ dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); ++ di = btrfs_lookup_dir_item(trans, root->fs_info->tree_root, path, ++ dir_id, "default", 7, 1); ++ if (!di) { ++ btrfs_free_path(path); ++ btrfs_end_transaction(trans, root); ++ printk(KERN_ERR "Umm, you don't have the default dir item, " ++ "this isn't going to work\n"); ++ return -ENOENT; ++ } ++ ++ btrfs_cpu_key_to_disk(&disk_key, &new_root->root_key); ++ btrfs_set_dir_item_key(path->nodes[0], di, &disk_key); ++ btrfs_mark_buffer_dirty(path->nodes[0]); ++ btrfs_free_path(path); ++ ++ disk_super = &root->fs_info->super_copy; ++ features = btrfs_super_incompat_flags(disk_super); ++ if (!(features & BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL)) { ++ features |= BTRFS_FEATURE_INCOMPAT_DEFAULT_SUBVOL; ++ btrfs_set_super_incompat_flags(disk_super, features); ++ } ++ btrfs_end_transaction(trans, root); ++ ++ return 0; ++} ++ ++long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg) ++{ ++ struct btrfs_ioctl_space_args space_args; ++ struct btrfs_ioctl_space_info space; ++ struct btrfs_ioctl_space_info *dest; ++ struct btrfs_ioctl_space_info *dest_orig; ++ struct btrfs_ioctl_space_info *user_dest; ++ struct btrfs_space_info *info; ++ int alloc_size; ++ int ret = 0; ++ int slot_count = 0; ++ ++ if (copy_from_user(&space_args, ++ (struct btrfs_ioctl_space_args __user *)arg, ++ sizeof(space_args))) ++ return -EFAULT; ++ ++ /* first we count slots */ ++ rcu_read_lock(); ++ list_for_each_entry_rcu(info, &root->fs_info->space_info, list) ++ slot_count++; ++ rcu_read_unlock(); ++ ++ /* space_slots == 0 means they are asking for a count */ ++ if (space_args.space_slots == 0) { ++ space_args.total_spaces = slot_count; ++ goto out; ++ } ++ alloc_size = sizeof(*dest) * slot_count; ++ /* we generally have at most 6 or so space infos, one for each raid ++ * level. So, a whole page should be more than enough for everyone ++ */ ++ if (alloc_size > PAGE_CACHE_SIZE) ++ return -ENOMEM; ++ ++ space_args.total_spaces = 0; ++ dest = kmalloc(alloc_size, GFP_NOFS); ++ if (!dest) ++ return -ENOMEM; ++ dest_orig = dest; ++ ++ /* now we have a buffer to copy into */ ++ rcu_read_lock(); ++ list_for_each_entry_rcu(info, &root->fs_info->space_info, list) { ++ /* make sure we don't copy more than we allocated ++ * in our buffer ++ */ ++ if (slot_count == 0) ++ break; ++ slot_count--; ++ ++ /* make sure userland has enough room in their buffer */ ++ if (space_args.total_spaces >= space_args.space_slots) ++ break; ++ ++ space.flags = info->flags; ++ space.total_bytes = info->total_bytes; ++ space.used_bytes = info->bytes_used; ++ memcpy(dest, &space, sizeof(space)); ++ dest++; ++ space_args.total_spaces++; ++ } ++ rcu_read_unlock(); ++ ++ user_dest = (struct btrfs_ioctl_space_info *) ++ (arg + sizeof(struct btrfs_ioctl_space_args)); ++ ++ if (copy_to_user(user_dest, dest_orig, alloc_size)) ++ ret = -EFAULT; ++ ++ kfree(dest_orig); ++out: ++ if (ret == 0 && copy_to_user(arg, &space_args, sizeof(space_args))) ++ ret = -EFAULT; ++ ++ return ret; ++} ++ + /* + * there are many ways the trans_start and trans_end ioctls can lead + * to deadlocks. They should only be used by applications that +@@ -1320,8 +1984,12 @@ long btrfs_ioctl(struct file *file, unsigned int + return btrfs_ioctl_snap_create(file, argp, 1); + case BTRFS_IOC_SNAP_DESTROY: + return btrfs_ioctl_snap_destroy(file, argp); ++ case BTRFS_IOC_DEFAULT_SUBVOL: ++ return btrfs_ioctl_default_subvol(file, argp); + case BTRFS_IOC_DEFRAG: +- return btrfs_ioctl_defrag(file); ++ return btrfs_ioctl_defrag(file, NULL); ++ case BTRFS_IOC_DEFRAG_RANGE: ++ return btrfs_ioctl_defrag(file, argp); + case BTRFS_IOC_RESIZE: + return btrfs_ioctl_resize(root, argp); + case BTRFS_IOC_ADD_DEV: +@@ -1338,6 +2006,12 @@ long btrfs_ioctl(struct file *file, unsigned int + return btrfs_ioctl_trans_start(file); + case BTRFS_IOC_TRANS_END: + return btrfs_ioctl_trans_end(file); ++ case BTRFS_IOC_TREE_SEARCH: ++ return btrfs_ioctl_tree_search(file, argp); ++ case BTRFS_IOC_INO_LOOKUP: ++ return btrfs_ioctl_ino_lookup(file, argp); ++ case BTRFS_IOC_SPACE_INFO: ++ return btrfs_ioctl_space_info(root, argp); + case BTRFS_IOC_SYNC: + btrfs_sync_fs(file->f_dentry->d_sb, 1); + return 0; +diff --git a/fs/btrfs/ioctl.h b/fs/btrfs/ioctl.h +index bc49914..424694a 100644 +--- a/fs/btrfs/ioctl.h ++++ b/fs/btrfs/ioctl.h +@@ -30,12 +30,114 @@ struct btrfs_ioctl_vol_args { + char name[BTRFS_PATH_NAME_MAX + 1]; + }; + ++#define BTRFS_INO_LOOKUP_PATH_MAX 4080 ++struct btrfs_ioctl_ino_lookup_args { ++ __u64 treeid; ++ __u64 objectid; ++ char name[BTRFS_INO_LOOKUP_PATH_MAX]; ++}; ++ ++struct btrfs_ioctl_search_key { ++ /* which root are we searching. 0 is the tree of tree roots */ ++ __u64 tree_id; ++ ++ /* keys returned will be >= min and <= max */ ++ __u64 min_objectid; ++ __u64 max_objectid; ++ ++ /* keys returned will be >= min and <= max */ ++ __u64 min_offset; ++ __u64 max_offset; ++ ++ /* max and min transids to search for */ ++ __u64 min_transid; ++ __u64 max_transid; ++ ++ /* keys returned will be >= min and <= max */ ++ __u32 min_type; ++ __u32 max_type; ++ ++ /* ++ * how many items did userland ask for, and how many are we ++ * returning ++ */ ++ __u32 nr_items; ++ ++ /* align to 64 bits */ ++ __u32 unused; ++ ++ /* some extra for later */ ++ __u64 unused1; ++ __u64 unused2; ++ __u64 unused3; ++ __u64 unused4; ++}; ++ ++struct btrfs_ioctl_search_header { ++ __u64 transid; ++ __u64 objectid; ++ __u64 offset; ++ __u32 type; ++ __u32 len; ++}; ++ ++#define BTRFS_SEARCH_ARGS_BUFSIZE (4096 - sizeof(struct btrfs_ioctl_search_key)) ++/* ++ * the buf is an array of search headers where ++ * each header is followed by the actual item ++ * the type field is expanded to 32 bits for alignment ++ */ ++struct btrfs_ioctl_search_args { ++ struct btrfs_ioctl_search_key key; ++ char buf[BTRFS_SEARCH_ARGS_BUFSIZE]; ++}; ++ + struct btrfs_ioctl_clone_range_args { + __s64 src_fd; + __u64 src_offset, src_length; + __u64 dest_offset; + }; + ++/* flags for the defrag range ioctl */ ++#define BTRFS_DEFRAG_RANGE_COMPRESS 1 ++#define BTRFS_DEFRAG_RANGE_START_IO 2 ++ ++struct btrfs_ioctl_defrag_range_args { ++ /* start of the defrag operation */ ++ __u64 start; ++ ++ /* number of bytes to defrag, use (u64)-1 to say all */ ++ __u64 len; ++ ++ /* ++ * flags for the operation, which can include turning ++ * on compression for this one defrag ++ */ ++ __u64 flags; ++ ++ /* ++ * any extent bigger than this will be considered ++ * already defragged. Use 0 to take the kernel default ++ * Use 1 to say every single extent must be rewritten ++ */ ++ __u32 extent_thresh; ++ ++ /* spare for later */ ++ __u32 unused[5]; ++}; ++ ++struct btrfs_ioctl_space_info { ++ __u64 flags; ++ __u64 total_bytes; ++ __u64 used_bytes; ++}; ++ ++struct btrfs_ioctl_space_args { ++ __u64 space_slots; ++ __u64 total_spaces; ++ struct btrfs_ioctl_space_info spaces[0]; ++}; ++ + #define BTRFS_IOC_SNAP_CREATE _IOW(BTRFS_IOCTL_MAGIC, 1, \ + struct btrfs_ioctl_vol_args) + #define BTRFS_IOC_DEFRAG _IOW(BTRFS_IOCTL_MAGIC, 2, \ +@@ -67,4 +169,13 @@ struct btrfs_ioctl_clone_range_args { + struct btrfs_ioctl_vol_args) + #define BTRFS_IOC_SNAP_DESTROY _IOW(BTRFS_IOCTL_MAGIC, 15, \ + struct btrfs_ioctl_vol_args) ++#define BTRFS_IOC_DEFRAG_RANGE _IOW(BTRFS_IOCTL_MAGIC, 16, \ ++ struct btrfs_ioctl_defrag_range_args) ++#define BTRFS_IOC_TREE_SEARCH _IOWR(BTRFS_IOCTL_MAGIC, 17, \ ++ struct btrfs_ioctl_search_args) ++#define BTRFS_IOC_INO_LOOKUP _IOWR(BTRFS_IOCTL_MAGIC, 18, \ ++ struct btrfs_ioctl_ino_lookup_args) ++#define BTRFS_IOC_DEFAULT_SUBVOL _IOW(BTRFS_IOCTL_MAGIC, 19, u64) ++#define BTRFS_IOC_SPACE_INFO _IOWR(BTRFS_IOCTL_MAGIC, 20, \ ++ struct btrfs_ioctl_space_args) + #endif +diff --git a/fs/btrfs/ordered-data.c b/fs/btrfs/ordered-data.c +index 5c2a9e7..a8ffecd 100644 +--- a/fs/btrfs/ordered-data.c ++++ b/fs/btrfs/ordered-data.c +@@ -174,7 +174,6 @@ int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, + if (!entry) + return -ENOMEM; + +- mutex_lock(&tree->mutex); + entry->file_offset = file_offset; + entry->start = start; + entry->len = len; +@@ -190,16 +189,17 @@ int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, + INIT_LIST_HEAD(&entry->list); + INIT_LIST_HEAD(&entry->root_extent_list); + ++ spin_lock(&tree->lock); + node = tree_insert(&tree->tree, file_offset, + &entry->rb_node); + BUG_ON(node); ++ spin_unlock(&tree->lock); + + spin_lock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); + list_add_tail(&entry->root_extent_list, + &BTRFS_I(inode)->root->fs_info->ordered_extents); + spin_unlock(&BTRFS_I(inode)->root->fs_info->ordered_extent_lock); + +- mutex_unlock(&tree->mutex); + BUG_ON(node); + return 0; + } +@@ -216,9 +216,9 @@ int btrfs_add_ordered_sum(struct inode *inode, + struct btrfs_ordered_inode_tree *tree; + + tree = &BTRFS_I(inode)->ordered_tree; +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + list_add_tail(&sum->list, &entry->list); +- mutex_unlock(&tree->mutex); ++ spin_unlock(&tree->lock); + return 0; + } + +@@ -232,15 +232,16 @@ int btrfs_add_ordered_sum(struct inode *inode, + * to make sure this function only returns 1 once for a given ordered extent. + */ + int btrfs_dec_test_ordered_pending(struct inode *inode, ++ struct btrfs_ordered_extent **cached, + u64 file_offset, u64 io_size) + { + struct btrfs_ordered_inode_tree *tree; + struct rb_node *node; +- struct btrfs_ordered_extent *entry; ++ struct btrfs_ordered_extent *entry = NULL; + int ret; + + tree = &BTRFS_I(inode)->ordered_tree; +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + node = tree_search(tree, file_offset); + if (!node) { + ret = 1; +@@ -264,7 +265,11 @@ int btrfs_dec_test_ordered_pending(struct inode *inode, + else + ret = 1; + out: +- mutex_unlock(&tree->mutex); ++ if (!ret && cached && entry) { ++ *cached = entry; ++ atomic_inc(&entry->refs); ++ } ++ spin_unlock(&tree->lock); + return ret == 0; + } + +@@ -291,7 +296,7 @@ int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry) + + /* + * remove an ordered extent from the tree. No references are dropped +- * and you must wake_up entry->wait. You must hold the tree mutex ++ * and you must wake_up entry->wait. You must hold the tree lock + * while you call this function. + */ + static int __btrfs_remove_ordered_extent(struct inode *inode, +@@ -340,9 +345,9 @@ int btrfs_remove_ordered_extent(struct inode *inode, + int ret; + + tree = &BTRFS_I(inode)->ordered_tree; +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + ret = __btrfs_remove_ordered_extent(inode, entry); +- mutex_unlock(&tree->mutex); ++ spin_unlock(&tree->lock); + wake_up(&entry->wait); + + return ret; +@@ -567,7 +572,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode, + struct btrfs_ordered_extent *entry = NULL; + + tree = &BTRFS_I(inode)->ordered_tree; +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + node = tree_search(tree, file_offset); + if (!node) + goto out; +@@ -578,7 +583,7 @@ struct btrfs_ordered_extent *btrfs_lookup_ordered_extent(struct inode *inode, + if (entry) + atomic_inc(&entry->refs); + out: +- mutex_unlock(&tree->mutex); ++ spin_unlock(&tree->lock); + return entry; + } + +@@ -594,7 +599,7 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset) + struct btrfs_ordered_extent *entry = NULL; + + tree = &BTRFS_I(inode)->ordered_tree; +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + node = tree_search(tree, file_offset); + if (!node) + goto out; +@@ -602,7 +607,7 @@ btrfs_lookup_first_ordered_extent(struct inode *inode, u64 file_offset) + entry = rb_entry(node, struct btrfs_ordered_extent, rb_node); + atomic_inc(&entry->refs); + out: +- mutex_unlock(&tree->mutex); ++ spin_unlock(&tree->lock); + return entry; + } + +@@ -629,7 +634,7 @@ int btrfs_ordered_update_i_size(struct inode *inode, u64 offset, + else + offset = ALIGN(offset, BTRFS_I(inode)->root->sectorsize); + +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + disk_i_size = BTRFS_I(inode)->disk_i_size; + + /* truncate file */ +@@ -735,7 +740,7 @@ out: + */ + if (ordered) + __btrfs_remove_ordered_extent(inode, ordered); +- mutex_unlock(&tree->mutex); ++ spin_unlock(&tree->lock); + if (ordered) + wake_up(&ordered->wait); + return ret; +@@ -762,7 +767,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, + if (!ordered) + return 1; + +- mutex_lock(&tree->mutex); ++ spin_lock(&tree->lock); + list_for_each_entry_reverse(ordered_sum, &ordered->list, list) { + if (disk_bytenr >= ordered_sum->bytenr) { + num_sectors = ordered_sum->len / sectorsize; +@@ -777,7 +782,7 @@ int btrfs_find_ordered_sum(struct inode *inode, u64 offset, u64 disk_bytenr, + } + } + out: +- mutex_unlock(&tree->mutex); ++ spin_unlock(&tree->lock); + btrfs_put_ordered_extent(ordered); + return ret; + } +diff --git a/fs/btrfs/ordered-data.h b/fs/btrfs/ordered-data.h +index 1fe1282..c82f76a 100644 +--- a/fs/btrfs/ordered-data.h ++++ b/fs/btrfs/ordered-data.h +@@ -21,7 +21,7 @@ + + /* one of these per inode */ + struct btrfs_ordered_inode_tree { +- struct mutex mutex; ++ spinlock_t lock; + struct rb_root tree; + struct rb_node *last; + }; +@@ -128,8 +128,8 @@ static inline int btrfs_ordered_sum_size(struct btrfs_root *root, + static inline void + btrfs_ordered_inode_tree_init(struct btrfs_ordered_inode_tree *t) + { +- mutex_init(&t->mutex); +- t->tree.rb_node = NULL; ++ spin_lock_init(&t->lock); ++ t->tree = RB_ROOT; + t->last = NULL; + } + +@@ -137,7 +137,8 @@ int btrfs_put_ordered_extent(struct btrfs_ordered_extent *entry); + int btrfs_remove_ordered_extent(struct inode *inode, + struct btrfs_ordered_extent *entry); + int btrfs_dec_test_ordered_pending(struct inode *inode, +- u64 file_offset, u64 io_size); ++ struct btrfs_ordered_extent **cached, ++ u64 file_offset, u64 io_size); + int btrfs_add_ordered_extent(struct inode *inode, u64 file_offset, + u64 start, u64 len, u64 disk_len, int tyep); + int btrfs_add_ordered_sum(struct inode *inode, +diff --git a/fs/btrfs/ref-cache.h b/fs/btrfs/ref-cache.h +index bc283ad..e2a55cb 100644 +--- a/fs/btrfs/ref-cache.h ++++ b/fs/btrfs/ref-cache.h +@@ -52,7 +52,7 @@ static inline size_t btrfs_leaf_ref_size(int nr_extents) + + static inline void btrfs_leaf_ref_tree_init(struct btrfs_leaf_ref_tree *tree) + { +- tree->root.rb_node = NULL; ++ tree->root = RB_ROOT; + INIT_LIST_HEAD(&tree->list); + spin_lock_init(&tree->lock); + } +diff --git a/fs/btrfs/relocation.c b/fs/btrfs/relocation.c +index ab7ab53..0b23942 100644 +--- a/fs/btrfs/relocation.c ++++ b/fs/btrfs/relocation.c +@@ -170,14 +170,14 @@ struct async_merge { + + static void mapping_tree_init(struct mapping_tree *tree) + { +- tree->rb_root.rb_node = NULL; ++ tree->rb_root = RB_ROOT; + spin_lock_init(&tree->lock); + } + + static void backref_cache_init(struct backref_cache *cache) + { + int i; +- cache->rb_root.rb_node = NULL; ++ cache->rb_root = RB_ROOT; + for (i = 0; i < BTRFS_MAX_LEVEL; i++) + INIT_LIST_HEAD(&cache->pending[i]); + spin_lock_init(&cache->lock); +@@ -2659,7 +2659,7 @@ static int relocate_file_extent_cluster(struct inode *inode, + EXTENT_BOUNDARY, GFP_NOFS); + nr++; + } +- btrfs_set_extent_delalloc(inode, page_start, page_end); ++ btrfs_set_extent_delalloc(inode, page_start, page_end, NULL); + + set_page_dirty(page); + dirty_page++; +@@ -3487,7 +3487,7 @@ static struct inode *create_reloc_inode(struct btrfs_fs_info *fs_info, + key.objectid = objectid; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; +- inode = btrfs_iget(root->fs_info->sb, &key, root); ++ inode = btrfs_iget(root->fs_info->sb, &key, root, NULL); + BUG_ON(IS_ERR(inode) || is_bad_inode(inode)); + BTRFS_I(inode)->index_cnt = group->key.objectid; + +diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c +index 8a1ea6e..9ac612e 100644 +--- a/fs/btrfs/super.c ++++ b/fs/btrfs/super.c +@@ -63,10 +63,10 @@ static void btrfs_put_super(struct super_block *sb) + } + + enum { +- Opt_degraded, Opt_subvol, Opt_device, Opt_nodatasum, Opt_nodatacow, +- Opt_max_extent, Opt_max_inline, Opt_alloc_start, Opt_nobarrier, +- Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, Opt_noacl, +- Opt_compress, Opt_compress_force, Opt_notreelog, Opt_ratio, ++ Opt_degraded, Opt_subvol, Opt_subvolid, Opt_device, Opt_nodatasum, ++ Opt_nodatacow, Opt_max_extent, Opt_max_inline, Opt_alloc_start, ++ Opt_nobarrier, Opt_ssd, Opt_nossd, Opt_ssd_spread, Opt_thread_pool, ++ Opt_noacl, Opt_compress, Opt_compress_force, Opt_notreelog, Opt_ratio, + Opt_flushoncommit, + Opt_discard, Opt_err, + }; +@@ -74,6 +74,7 @@ enum { + static match_table_t tokens = { + {Opt_degraded, "degraded"}, + {Opt_subvol, "subvol=%s"}, ++ {Opt_subvolid, "subvolid=%d"}, + {Opt_device, "device=%s"}, + {Opt_nodatasum, "nodatasum"}, + {Opt_nodatacow, "nodatacow"}, +@@ -95,31 +96,6 @@ static match_table_t tokens = { + {Opt_err, NULL}, + }; + +-u64 btrfs_parse_size(char *str) +-{ +- u64 res; +- int mult = 1; +- char *end; +- char last; +- +- res = simple_strtoul(str, &end, 10); +- +- last = end[0]; +- if (isalpha(last)) { +- last = tolower(last); +- switch (last) { +- case 'g': +- mult *= 1024; +- case 'm': +- mult *= 1024; +- case 'k': +- mult *= 1024; +- } +- res = res * mult; +- } +- return res; +-} +- + /* + * Regular mount options parser. Everything that is needed only when + * reading in a new superblock is parsed here. +@@ -128,7 +104,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + { + struct btrfs_fs_info *info = root->fs_info; + substring_t args[MAX_OPT_ARGS]; +- char *p, *num; ++ char *p, *num, *orig; + int intarg; + int ret = 0; + +@@ -143,6 +119,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + if (!options) + return -ENOMEM; + ++ orig = options; + + while ((p = strsep(&options, ",")) != NULL) { + int token; +@@ -156,6 +133,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + btrfs_set_opt(info->mount_opt, DEGRADED); + break; + case Opt_subvol: ++ case Opt_subvolid: + case Opt_device: + /* + * These are parsed by btrfs_parse_early_options +@@ -213,7 +191,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + case Opt_max_extent: + num = match_strdup(&args[0]); + if (num) { +- info->max_extent = btrfs_parse_size(num); ++ info->max_extent = memparse(num, NULL); + kfree(num); + + info->max_extent = max_t(u64, +@@ -225,7 +203,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + case Opt_max_inline: + num = match_strdup(&args[0]); + if (num) { +- info->max_inline = btrfs_parse_size(num); ++ info->max_inline = memparse(num, NULL); + kfree(num); + + if (info->max_inline) { +@@ -240,7 +218,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + case Opt_alloc_start: + num = match_strdup(&args[0]); + if (num) { +- info->alloc_start = btrfs_parse_size(num); ++ info->alloc_start = memparse(num, NULL); + kfree(num); + printk(KERN_INFO + "btrfs: allocations start at %llu\n", +@@ -280,7 +258,7 @@ int btrfs_parse_options(struct btrfs_root *root, char *options) + } + } + out: +- kfree(options); ++ kfree(orig); + return ret; + } + +@@ -291,12 +269,13 @@ out: + * only when we need to allocate a new super block. + */ + static int btrfs_parse_early_options(const char *options, fmode_t flags, +- void *holder, char **subvol_name, ++ void *holder, char **subvol_name, u64 *subvol_objectid, + struct btrfs_fs_devices **fs_devices) + { + substring_t args[MAX_OPT_ARGS]; + char *opts, *p; + int error = 0; ++ int intarg; + + if (!options) + goto out; +@@ -319,6 +298,18 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, + case Opt_subvol: + *subvol_name = match_strdup(&args[0]); + break; ++ case Opt_subvolid: ++ intarg = 0; ++ error = match_int(&args[0], &intarg); ++ if (!error) { ++ /* we want the original fs_tree */ ++ if (!intarg) ++ *subvol_objectid = ++ BTRFS_FS_TREE_OBJECTID; ++ else ++ *subvol_objectid = intarg; ++ } ++ break; + case Opt_device: + error = btrfs_scan_one_device(match_strdup(&args[0]), + flags, holder, fs_devices); +@@ -346,6 +337,110 @@ static int btrfs_parse_early_options(const char *options, fmode_t flags, + return error; + } + ++static struct dentry *get_default_root(struct super_block *sb, ++ u64 subvol_objectid) ++{ ++ struct btrfs_root *root = sb->s_fs_info; ++ struct btrfs_root *new_root; ++ struct btrfs_dir_item *di; ++ struct btrfs_path *path; ++ struct btrfs_key location; ++ struct inode *inode; ++ struct dentry *dentry; ++ u64 dir_id; ++ int new = 0; ++ ++ /* ++ * We have a specific subvol we want to mount, just setup location and ++ * go look up the root. ++ */ ++ if (subvol_objectid) { ++ location.objectid = subvol_objectid; ++ location.type = BTRFS_ROOT_ITEM_KEY; ++ location.offset = (u64)-1; ++ goto find_root; ++ } ++ ++ path = btrfs_alloc_path(); ++ if (!path) ++ return ERR_PTR(-ENOMEM); ++ path->leave_spinning = 1; ++ ++ /* ++ * Find the "default" dir item which points to the root item that we ++ * will mount by default if we haven't been given a specific subvolume ++ * to mount. ++ */ ++ dir_id = btrfs_super_root_dir(&root->fs_info->super_copy); ++ di = btrfs_lookup_dir_item(NULL, root, path, dir_id, "default", 7, 0); ++ if (!di) { ++ /* ++ * Ok the default dir item isn't there. This is weird since ++ * it's always been there, but don't freak out, just try and ++ * mount to root most subvolume. ++ */ ++ btrfs_free_path(path); ++ dir_id = BTRFS_FIRST_FREE_OBJECTID; ++ new_root = root->fs_info->fs_root; ++ goto setup_root; ++ } ++ ++ btrfs_dir_item_key_to_cpu(path->nodes[0], di, &location); ++ btrfs_free_path(path); ++ ++find_root: ++ new_root = btrfs_read_fs_root_no_name(root->fs_info, &location); ++ if (IS_ERR(new_root)) ++ return ERR_PTR(PTR_ERR(new_root)); ++ ++ if (btrfs_root_refs(&new_root->root_item) == 0) ++ return ERR_PTR(-ENOENT); ++ ++ dir_id = btrfs_root_dirid(&new_root->root_item); ++setup_root: ++ location.objectid = dir_id; ++ location.type = BTRFS_INODE_ITEM_KEY; ++ location.offset = 0; ++ ++ inode = btrfs_iget(sb, &location, new_root, &new); ++ if (!inode) ++ return ERR_PTR(-ENOMEM); ++ ++ /* ++ * If we're just mounting the root most subvol put the inode and return ++ * a reference to the dentry. We will have already gotten a reference ++ * to the inode in btrfs_fill_super so we're good to go. ++ */ ++ if (!new && sb->s_root->d_inode == inode) { ++ iput(inode); ++ return dget(sb->s_root); ++ } ++ ++ if (new) { ++ const struct qstr name = { .name = "/", .len = 1 }; ++ ++ /* ++ * New inode, we need to make the dentry a sibling of s_root so ++ * everything gets cleaned up properly on unmount. ++ */ ++ dentry = d_alloc(sb->s_root, &name); ++ if (!dentry) { ++ iput(inode); ++ return ERR_PTR(-ENOMEM); ++ } ++ d_splice_alias(inode, dentry); ++ } else { ++ /* ++ * We found the inode in cache, just find a dentry for it and ++ * put the reference to the inode we just got. ++ */ ++ dentry = d_find_alias(inode); ++ iput(inode); ++ } ++ ++ return dentry; ++} ++ + static int btrfs_fill_super(struct super_block *sb, + struct btrfs_fs_devices *fs_devices, + void *data, int silent) +@@ -379,7 +474,7 @@ static int btrfs_fill_super(struct super_block *sb, + key.objectid = BTRFS_FIRST_FREE_OBJECTID; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; +- inode = btrfs_iget(sb, &key, tree_root->fs_info->fs_root); ++ inode = btrfs_iget(sb, &key, tree_root->fs_info->fs_root, NULL); + if (IS_ERR(inode)) { + err = PTR_ERR(inode); + goto fail_close; +@@ -391,12 +486,6 @@ static int btrfs_fill_super(struct super_block *sb, + err = -ENOMEM; + goto fail_close; + } +-#if 0 +- /* this does the super kobj at the same time */ +- err = btrfs_sysfs_add_super(tree_root->fs_info); +- if (err) +- goto fail_close; +-#endif + + sb->s_root = root_dentry; + +@@ -488,19 +577,22 @@ static int btrfs_test_super(struct super_block *s, void *data) + static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + const char *dev_name, void *data, struct vfsmount *mnt) + { +- char *subvol_name = NULL; + struct block_device *bdev = NULL; + struct super_block *s; + struct dentry *root; + struct btrfs_fs_devices *fs_devices = NULL; + fmode_t mode = FMODE_READ; ++ char *subvol_name = NULL; ++ u64 subvol_objectid = 0; + int error = 0; ++ int found = 0; + + if (!(flags & MS_RDONLY)) + mode |= FMODE_WRITE; + + error = btrfs_parse_early_options(data, mode, fs_type, +- &subvol_name, &fs_devices); ++ &subvol_name, &subvol_objectid, ++ &fs_devices); + if (error) + return error; + +@@ -529,6 +621,7 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + goto error_close_devices; + } + ++ found = 1; + btrfs_close_devices(fs_devices); + } else { + char b[BDEVNAME_SIZE]; +@@ -546,25 +639,35 @@ static int btrfs_get_sb(struct file_system_type *fs_type, int flags, + s->s_flags |= MS_ACTIVE; + } + +- if (!strcmp(subvol_name, ".")) +- root = dget(s->s_root); +- else { +- mutex_lock(&s->s_root->d_inode->i_mutex); +- root = lookup_one_len(subvol_name, s->s_root, ++ root = get_default_root(s, subvol_objectid); ++ if (IS_ERR(root)) { ++ error = PTR_ERR(root); ++ deactivate_locked_super(s); ++ goto error; ++ } ++ /* if they gave us a subvolume name bind mount into that */ ++ if (strcmp(subvol_name, ".")) { ++ struct dentry *new_root; ++ mutex_lock(&root->d_inode->i_mutex); ++ new_root = lookup_one_len(subvol_name, root, + strlen(subvol_name)); +- mutex_unlock(&s->s_root->d_inode->i_mutex); ++ mutex_unlock(&root->d_inode->i_mutex); + +- if (IS_ERR(root)) { ++ if (IS_ERR(new_root)) { + deactivate_locked_super(s); +- error = PTR_ERR(root); +- goto error_free_subvol_name; ++ error = PTR_ERR(new_root); ++ dput(root); ++ goto error_close_devices; + } +- if (!root->d_inode) { ++ if (!new_root->d_inode) { + dput(root); ++ dput(new_root); + deactivate_locked_super(s); + error = -ENXIO; +- goto error_free_subvol_name; ++ goto error_close_devices; + } ++ dput(root); ++ root = new_root; + } + + mnt->mnt_sb = s; +@@ -579,6 +682,7 @@ error_close_devices: + btrfs_close_devices(fs_devices); + error_free_subvol_name: + kfree(subvol_name); ++error: + return error; + } + +@@ -623,14 +727,37 @@ static int btrfs_statfs(struct dentry *dentry, struct kstatfs *buf) + { + struct btrfs_root *root = btrfs_sb(dentry->d_sb); + struct btrfs_super_block *disk_super = &root->fs_info->super_copy; ++ struct list_head *head = &root->fs_info->space_info; ++ struct btrfs_space_info *found; ++ u64 total_used = 0; ++ u64 data_used = 0; + int bits = dentry->d_sb->s_blocksize_bits; + __be32 *fsid = (__be32 *)root->fs_info->fsid; + ++ rcu_read_lock(); ++ list_for_each_entry_rcu(found, head, list) { ++ if (found->flags & (BTRFS_BLOCK_GROUP_DUP| ++ BTRFS_BLOCK_GROUP_RAID10| ++ BTRFS_BLOCK_GROUP_RAID1)) { ++ total_used += found->bytes_used; ++ if (found->flags & BTRFS_BLOCK_GROUP_DATA) ++ data_used += found->bytes_used; ++ else ++ data_used += found->total_bytes; ++ } ++ ++ total_used += found->bytes_used; ++ if (found->flags & BTRFS_BLOCK_GROUP_DATA) ++ data_used += found->bytes_used; ++ else ++ data_used += found->total_bytes; ++ } ++ rcu_read_unlock(); ++ + buf->f_namelen = BTRFS_NAME_LEN; + buf->f_blocks = btrfs_super_total_bytes(disk_super) >> bits; +- buf->f_bfree = buf->f_blocks - +- (btrfs_super_bytes_used(disk_super) >> bits); +- buf->f_bavail = buf->f_bfree; ++ buf->f_bfree = buf->f_blocks - (total_used >> bits); ++ buf->f_bavail = buf->f_blocks - (data_used >> bits); + buf->f_bsize = dentry->d_sb->s_blocksize; + buf->f_type = BTRFS_SUPER_MAGIC; + +diff --git a/fs/btrfs/transaction.c b/fs/btrfs/transaction.c +index b2acc79..2d654c1 100644 +--- a/fs/btrfs/transaction.c ++++ b/fs/btrfs/transaction.c +@@ -69,7 +69,7 @@ static noinline int join_transaction(struct btrfs_root *root) + cur_trans->commit_done = 0; + cur_trans->start_time = get_seconds(); + +- cur_trans->delayed_refs.root.rb_node = NULL; ++ cur_trans->delayed_refs.root = RB_ROOT; + cur_trans->delayed_refs.num_entries = 0; + cur_trans->delayed_refs.num_heads_ready = 0; + cur_trans->delayed_refs.num_heads = 0; +@@ -997,13 +997,10 @@ int btrfs_commit_transaction(struct btrfs_trans_handle *trans, + + mutex_unlock(&root->fs_info->trans_mutex); + +- if (flush_on_commit) { ++ if (flush_on_commit || snap_pending) { + btrfs_start_delalloc_inodes(root, 1); + ret = btrfs_wait_ordered_extents(root, 0, 1); + BUG_ON(ret); +- } else if (snap_pending) { +- ret = btrfs_wait_ordered_extents(root, 0, 1); +- BUG_ON(ret); + } + + /* +diff --git a/fs/btrfs/tree-log.c b/fs/btrfs/tree-log.c +index 4a9434b..1255fcc 100644 +--- a/fs/btrfs/tree-log.c ++++ b/fs/btrfs/tree-log.c +@@ -445,7 +445,7 @@ static noinline struct inode *read_one_inode(struct btrfs_root *root, + key.objectid = objectid; + key.type = BTRFS_INODE_ITEM_KEY; + key.offset = 0; +- inode = btrfs_iget(root->fs_info->sb, &key, root); ++ inode = btrfs_iget(root->fs_info->sb, &key, root, NULL); + if (IS_ERR(inode)) { + inode = NULL; + } else if (is_bad_inode(inode)) { +diff --git a/fs/btrfs/volumes.c b/fs/btrfs/volumes.c +index 41ecbb2..9df8e3f 100644 +--- a/fs/btrfs/volumes.c ++++ b/fs/btrfs/volumes.c +@@ -256,13 +256,13 @@ loop_lock: + wake_up(&fs_info->async_submit_wait); + + BUG_ON(atomic_read(&cur->bi_cnt) == 0); +- submit_bio(cur->bi_rw, cur); +- num_run++; +- batch_run++; + + if (bio_rw_flagged(cur, BIO_RW_SYNCIO)) + num_sync_run++; + ++ submit_bio(cur->bi_rw, cur); ++ num_run++; ++ batch_run++; + if (need_resched()) { + if (num_sync_run) { + blk_run_backing_dev(bdi, NULL); +@@ -325,16 +325,6 @@ loop_lock: + num_sync_run = 0; + blk_run_backing_dev(bdi, NULL); + } +- +- cond_resched(); +- if (again) +- goto loop; +- +- spin_lock(&device->io_lock); +- if (device->pending_bios.head || device->pending_sync_bios.head) +- goto loop_lock; +- spin_unlock(&device->io_lock); +- + /* + * IO has already been through a long path to get here. Checksumming, + * async helper threads, perhaps compression. We've done a pretty +@@ -346,6 +336,16 @@ loop_lock: + * cared about found its way down here. + */ + blk_run_backing_dev(bdi, NULL); ++ ++ cond_resched(); ++ if (again) ++ goto loop; ++ ++ spin_lock(&device->io_lock); ++ if (device->pending_bios.head || device->pending_sync_bios.head) ++ goto loop_lock; ++ spin_unlock(&device->io_lock); ++ + done: + return 0; + } +@@ -365,6 +365,7 @@ static noinline int device_list_add(const char *path, + struct btrfs_device *device; + struct btrfs_fs_devices *fs_devices; + u64 found_transid = btrfs_super_generation(disk_super); ++ char *name; + + fs_devices = find_fsid(disk_super->fsid); + if (!fs_devices) { +@@ -411,6 +412,12 @@ static noinline int device_list_add(const char *path, + + device->fs_devices = fs_devices; + fs_devices->num_devices++; ++ } else if (strcmp(device->name, path)) { ++ name = kstrdup(path, GFP_NOFS); ++ if (!name) ++ return -ENOMEM; ++ kfree(device->name); ++ device->name = name; + } + + if (found_transid > fs_devices->latest_trans) { +@@ -592,7 +599,7 @@ static int __btrfs_open_devices(struct btrfs_fs_devices *fs_devices, + goto error_close; + + disk_super = (struct btrfs_super_block *)bh->b_data; +- devid = le64_to_cpu(disk_super->dev_item.devid); ++ devid = btrfs_stack_device_id(&disk_super->dev_item); + if (devid != device->devid) + goto error_brelse; + +@@ -694,7 +701,7 @@ int btrfs_scan_one_device(const char *path, fmode_t flags, void *holder, + goto error_close; + } + disk_super = (struct btrfs_super_block *)bh->b_data; +- devid = le64_to_cpu(disk_super->dev_item.devid); ++ devid = btrfs_stack_device_id(&disk_super->dev_item); + transid = btrfs_super_generation(disk_super); + if (disk_super->label[0]) + printk(KERN_INFO "device label %s ", disk_super->label); +@@ -1187,7 +1194,7 @@ int btrfs_rm_device(struct btrfs_root *root, char *device_path) + goto error_close; + } + disk_super = (struct btrfs_super_block *)bh->b_data; +- devid = le64_to_cpu(disk_super->dev_item.devid); ++ devid = btrfs_stack_device_id(&disk_super->dev_item); + dev_uuid = disk_super->dev_item.uuid; + device = btrfs_find_device(root, devid, dev_uuid, + disk_super->fsid); diff --git a/linux-2.6-build-nonintconfig.patch b/linux-2.6-build-nonintconfig.patch new file mode 100644 index 000000000..e88e0ea1e --- /dev/null +++ b/linux-2.6-build-nonintconfig.patch @@ -0,0 +1,128 @@ +diff --git a/scripts/kconfig/Makefile b/scripts/kconfig/Makefile +index 6d69c7c..ff84d12 100644 +--- a/scripts/kconfig/Makefile ++++ b/scripts/kconfig/Makefile +@@ -58,6 +58,11 @@ localyesconfig: $(obj)/streamline_config.pl $(obj)/conf + fi + $(Q)rm -f .tmp.config + ++nonint_oldconfig: $(obj)/conf ++ $< -b $(Kconfig) ++loose_nonint_oldconfig: $(obj)/conf ++ $< -B $(Kconfig) ++ + # Create new linux.pot file + # Adjust charset to UTF-8 in .po file to accept UTF-8 in Kconfig files + # The symlink is used to repair a deficiency in arch/um +diff --git a/scripts/kconfig/conf.c b/scripts/kconfig/conf.c +index 9960d1c..ac8d455 100644 +--- a/scripts/kconfig/conf.c ++++ b/scripts/kconfig/conf.c +@@ -23,6 +23,8 @@ enum { + ask_all, + ask_new, + ask_silent, ++ dont_ask, ++ dont_ask_dont_tell, + set_default, + set_yes, + set_mod, +@@ -360,7 +362,10 @@ static void conf(struct menu *menu) + + switch (prop->type) { + case P_MENU: +- if (input_mode == ask_silent && rootEntry != menu) { ++ if ((input_mode == ask_silent || ++ input_mode == dont_ask || ++ input_mode == dont_ask_dont_tell) && ++ rootEntry != menu) { + check_conf(menu); + return; + } +@@ -406,6 +411,8 @@ conf_childs: + indent -= 2; + } + ++static int return_value; ++ + static void check_conf(struct menu *menu) + { + struct symbol *sym; +@@ -418,12 +425,21 @@ static void check_conf(struct menu *menu) + if (sym && !sym_has_value(sym)) { + if (sym_is_changable(sym) || + (sym_is_choice(sym) && sym_get_tristate_value(sym) == yes)) { ++ if (input_mode == dont_ask || ++ input_mode == dont_ask_dont_tell) { ++ if (input_mode == dont_ask && ++ sym->name && !sym_is_choice_value(sym)) { ++ fprintf(stderr,"CONFIG_%s\n",sym->name); ++ ++return_value; ++ } ++ } else { + if (!conf_cnt++) + printf(_("*\n* Restart config...\n*\n")); + rootEntry = menu_get_parent_menu(menu); + conf(rootEntry); + } + } ++ } + + for (child = menu->list; child; child = child->next) + check_conf(child); +@@ -439,7 +455,7 @@ int main(int ac, char **av) + bindtextdomain(PACKAGE, LOCALEDIR); + textdomain(PACKAGE); + +- while ((opt = getopt(ac, av, "osdD:nmyrh")) != -1) { ++ while ((opt = getopt(ac, av, "osbBdD:nmyrh")) != -1) { + switch (opt) { + case 'o': + input_mode = ask_silent; +@@ -448,6 +464,12 @@ int main(int ac, char **av) + input_mode = ask_silent; + sync_kconfig = 1; + break; ++ case 'b': ++ input_mode = dont_ask; ++ break; ++ case 'B': ++ input_mode = dont_ask_dont_tell; ++ break; + case 'd': + input_mode = set_default; + break; +@@ -525,6 +547,8 @@ int main(int ac, char **av) + case ask_silent: + case ask_all: + case ask_new: ++ case dont_ask: ++ case dont_ask_dont_tell: + conf_read(NULL); + break; + case set_no: +@@ -586,12 +610,16 @@ int main(int ac, char **av) + conf(&rootmenu); + input_mode = ask_silent; + /* fall through */ ++ case dont_ask: ++ case dont_ask_dont_tell: + case ask_silent: + /* Update until a loop caused no more changes */ + do { + conf_cnt = 0; + check_conf(&rootmenu); +- } while (conf_cnt); ++ } while (conf_cnt && ++ (input_mode != dont_ask && ++ input_mode != dont_ask_dont_tell)); + break; + } + +@@ -613,5 +641,5 @@ int main(int ac, char **av) + exit(1); + } + } +- return 0; ++ return return_value; + } diff --git a/linux-2.6-compile-fixes.patch b/linux-2.6-compile-fixes.patch new file mode 100644 index 000000000..34c08ce47 --- /dev/null +++ b/linux-2.6-compile-fixes.patch @@ -0,0 +1,6 @@ +# +# Small compile fixes (For more involved fixes, please use a separate patch). +# +# Please add the errors from gcc before the diffs to save others having +# to do a compile to figure out what your diff is fixing. Thanks. +# diff --git a/linux-2.6-cpufreq-locking.patch b/linux-2.6-cpufreq-locking.patch new file mode 100644 index 000000000..358028982 --- /dev/null +++ b/linux-2.6-cpufreq-locking.patch @@ -0,0 +1,98 @@ +Date: Thu, 4 Mar 2010 03:23:46 -0500 +From: Amerigo Wang +To: linux-kernel@vger.kernel.org +Cc: Dave Jones , cpufreq@vger.kernel.org, + Amerigo Wang , + Johannes Berg , akpm@linux-foundation.org, + Venkatesh Pallipadi +Subject: [CPUFREQ] fix a lockdep warning + +There is no need to do sysfs_remove_link() or kobject_put() etc. +when policy_rwsem_write is held, move them after releasing the lock. + +This fixes the lockdep warning: + +halt/4071 is trying to acquire lock: + (s_active){++++.+}, at: [] .sysfs_addrm_finish+0x58/0xc0 + +but task is already holding lock: + (&per_cpu(cpu_policy_rwsem, cpu)){+.+.+.}, at: [] .lock_policy_rwsem_write+0x84/0xf4 + +Reported-by: Benjamin Herrenschmidt +Signed-off-by: WANG Cong +Cc: Johannes Berg +Cc: Venkatesh Pallipadi +Signed-off-by: Dave Jones + +--- +diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c +index 67bc2ec..e196084 100644 +--- a/drivers/cpufreq/cpufreq.c ++++ b/drivers/cpufreq/cpufreq.c +@@ -1113,6 +1113,8 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) + unsigned int cpu = sys_dev->id; + unsigned long flags; + struct cpufreq_policy *data; ++ struct kobject *kobj; ++ struct completion *cmp; + #ifdef CONFIG_SMP + struct sys_device *cpu_sys_dev; + unsigned int j; +@@ -1141,10 +1143,11 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) + dprintk("removing link\n"); + cpumask_clear_cpu(cpu, data->cpus); + spin_unlock_irqrestore(&cpufreq_driver_lock, flags); +- sysfs_remove_link(&sys_dev->kobj, "cpufreq"); ++ kobj = &sys_dev->kobj; + cpufreq_cpu_put(data); + cpufreq_debug_enable_ratelimit(); + unlock_policy_rwsem_write(cpu); ++ sysfs_remove_link(kobj, "cpufreq"); + return 0; + } + #endif +@@ -1181,7 +1184,10 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) + data->governor->name, CPUFREQ_NAME_LEN); + #endif + cpu_sys_dev = get_cpu_sysdev(j); +- sysfs_remove_link(&cpu_sys_dev->kobj, "cpufreq"); ++ kobj = &cpu_sys_dev->kobj; ++ unlock_policy_rwsem_write(cpu); ++ sysfs_remove_link(kobj, "cpufreq"); ++ lock_policy_rwsem_write(cpu); + cpufreq_cpu_put(data); + } + } +@@ -1192,19 +1198,22 @@ static int __cpufreq_remove_dev(struct sys_device *sys_dev) + if (cpufreq_driver->target) + __cpufreq_governor(data, CPUFREQ_GOV_STOP); + +- kobject_put(&data->kobj); ++ kobj = &data->kobj; ++ cmp = &data->kobj_unregister; ++ unlock_policy_rwsem_write(cpu); ++ kobject_put(kobj); + + /* we need to make sure that the underlying kobj is actually + * not referenced anymore by anybody before we proceed with + * unloading. + */ + dprintk("waiting for dropping of refcount\n"); +- wait_for_completion(&data->kobj_unregister); ++ wait_for_completion(cmp); + dprintk("wait complete\n"); + ++ lock_policy_rwsem_write(cpu); + if (cpufreq_driver->exit) + cpufreq_driver->exit(data); +- + unlock_policy_rwsem_write(cpu); + + free_cpumask_var(data->related_cpus); + + +-- +To unsubscribe from this list: send the line "unsubscribe cpufreq" in +the body of a message to majordomo@vger.kernel.org +More majordomo info at http://vger.kernel.org/majordomo-info.html + diff --git a/linux-2.6-crash-driver.patch b/linux-2.6-crash-driver.patch new file mode 100644 index 000000000..5669f7aaf --- /dev/null +++ b/linux-2.6-crash-driver.patch @@ -0,0 +1,363 @@ +diff --git a/arch/ia64/include/asm/crash.h b/arch/ia64/include/asm/crash.h +new file mode 100644 +index 0000000..541af84 +--- /dev/null ++++ b/arch/ia64/include/asm/crash.h +@@ -0,0 +1,90 @@ ++#ifndef _ASM_IA64_CRASH_H ++#define _ASM_IA64_CRASH_H ++ ++/* ++ * linux/include/asm-ia64/crash.h ++ * ++ * Copyright (c) 2004 Red Hat, Inc. All rights reserved. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2, or (at your option) ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ */ ++ ++#ifdef __KERNEL__ ++ ++#include ++#include ++#include ++ ++static inline void * ++map_virtual(u64 offset, struct page **pp) ++{ ++ struct page *page; ++ unsigned long pfn; ++ u32 type; ++ ++ if (REGION_NUMBER(offset) == 5) { ++ char byte; ++ ++ if (__get_user(byte, (char *)offset) == 0) ++ return (void *)offset; ++ else ++ return NULL; ++ } ++ ++ switch (type = efi_mem_type(offset)) ++ { ++ case EFI_LOADER_CODE: ++ case EFI_LOADER_DATA: ++ case EFI_BOOT_SERVICES_CODE: ++ case EFI_BOOT_SERVICES_DATA: ++ case EFI_CONVENTIONAL_MEMORY: ++ break; ++ ++ default: ++ printk(KERN_INFO ++ "crash memory driver: invalid memory type for %lx: %d\n", ++ offset, type); ++ return NULL; ++ } ++ ++ pfn = offset >> PAGE_SHIFT; ++ ++ if (!pfn_valid(pfn)) { ++ printk(KERN_INFO ++ "crash memory driver: invalid pfn: %lx )\n", pfn); ++ return NULL; ++ } ++ ++ page = pfn_to_page(pfn); ++ ++ if (!page->virtual) { ++ printk(KERN_INFO ++ "crash memory driver: offset: %lx page: %lx page->virtual: NULL\n", ++ offset, (unsigned long)page); ++ return NULL; ++ } ++ ++ return (page->virtual + (offset & (PAGE_SIZE-1))); ++} ++ ++static inline void unmap_virtual(struct page *page) ++{ ++ return; ++} ++ ++#endif /* __KERNEL__ */ ++ ++#endif /* _ASM_IA64_CRASH_H */ +diff --git a/arch/ia64/kernel/ia64_ksyms.c b/arch/ia64/kernel/ia64_ksyms.c +index 14d39e3..cf3d040 100644 +--- a/arch/ia64/kernel/ia64_ksyms.c ++++ b/arch/ia64/kernel/ia64_ksyms.c +@@ -84,6 +84,9 @@ EXPORT_SYMBOL(ia64_save_scratch_fpregs); + #include + EXPORT_SYMBOL(unw_init_running); + ++#include ++EXPORT_SYMBOL_GPL(efi_mem_type); ++ + #if defined(CONFIG_IA64_ESI) || defined(CONFIG_IA64_ESI_MODULE) + extern void esi_call_phys (void); + EXPORT_SYMBOL_GPL(esi_call_phys); +diff --git a/arch/x86/include/asm/crash.h b/arch/x86/include/asm/crash.h +new file mode 100644 +index 0000000..dfcc006 +--- /dev/null ++++ b/arch/x86/include/asm/crash.h +@@ -0,0 +1,75 @@ ++#ifndef _ASM_I386_CRASH_H ++#define _ASM_I386_CRASH_H ++ ++/* ++ * linux/include/asm-i386/crash.h ++ * ++ * Copyright (c) 2004 Red Hat, Inc. All rights reserved. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2, or (at your option) ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ */ ++ ++#ifdef __KERNEL__ ++ ++#include ++#include ++#include ++ ++extern int page_is_ram(unsigned long); ++ ++static inline void * ++map_virtual(u64 offset, struct page **pp) ++{ ++ struct page *page; ++ unsigned long pfn; ++ void *vaddr; ++ ++ pfn = (unsigned long)(offset >> PAGE_SHIFT); ++ ++ if (!page_is_ram(pfn)) { ++ printk(KERN_INFO ++ "crash memory driver: !page_is_ram(pfn: %lx)\n", pfn); ++ return NULL; ++ } ++ ++ if (!pfn_valid(pfn)) { ++ printk(KERN_INFO ++ "crash memory driver: invalid pfn: %lx )\n", pfn); ++ return NULL; ++ } ++ ++ page = pfn_to_page(pfn); ++ ++ vaddr = kmap(page); ++ if (!vaddr) { ++ printk(KERN_INFO ++ "crash memory driver: pfn: %lx kmap(page: %lx) failed\n", ++ pfn, (unsigned long)page); ++ return NULL; ++ } ++ ++ *pp = page; ++ return (vaddr + (offset & (PAGE_SIZE-1))); ++} ++ ++static inline void unmap_virtual(struct page *page) ++{ ++ kunmap(page); ++} ++ ++#endif /* __KERNEL__ */ ++ ++#endif /* _ASM_I386_CRASH_H */ +diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c +index 334e63c..8e1ccbc 100644 +--- a/arch/x86/mm/ioremap.c ++++ b/arch/x86/mm/ioremap.c +@@ -60,6 +60,7 @@ int page_is_ram(unsigned long pagenr) + } + return 0; + } ++EXPORT_SYMBOL_GPL(page_is_ram); + + /* + * Fix up the linear direct mapping of the kernel to avoid cache attribute +diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig +index 08a6f50..8bc5e9a 100644 +--- a/drivers/char/Kconfig ++++ b/drivers/char/Kconfig +@@ -484,6 +484,8 @@ config LEGACY_PTYS + security. This option enables these legacy devices; on most + systems, it is safe to say N. + ++config CRASH ++ tristate "Crash Utility memory driver" + + config LEGACY_PTY_COUNT + int "Maximum number of legacy PTY in use" +diff --git a/drivers/char/Makefile b/drivers/char/Makefile +index 19a79dd..0bee860 100644 +--- a/drivers/char/Makefile ++++ b/drivers/char/Makefile +@@ -112,6 +112,8 @@ obj-$(CONFIG_PS3_FLASH) += ps3flash.o + obj-$(CONFIG_JS_RTC) += js-rtc.o + js-rtc-y = rtc.o + ++obj-$(CONFIG_CRASH) += crash.o ++ + # Files generated that shall be removed upon make clean + clean-files := consolemap_deftbl.c defkeymap.c + +diff --git a/drivers/char/crash.c b/drivers/char/crash.c +new file mode 100644 +index 0000000..e5437de +--- /dev/null ++++ b/drivers/char/crash.c +@@ -0,0 +1,128 @@ ++/* ++ * linux/drivers/char/crash.c ++ * ++ * Copyright (C) 2004 Dave Anderson ++ * Copyright (C) 2004 Red Hat, Inc. ++ */ ++ ++/****************************************************************************** ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2, or (at your option) ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ * ++ *****************************************************************************/ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define CRASH_VERSION "1.0" ++ ++/* ++ * These are the file operation functions that allow crash utility ++ * access to physical memory. ++ */ ++ ++static loff_t ++crash_llseek(struct file * file, loff_t offset, int orig) ++{ ++ switch (orig) { ++ case 0: ++ file->f_pos = offset; ++ return file->f_pos; ++ case 1: ++ file->f_pos += offset; ++ return file->f_pos; ++ default: ++ return -EINVAL; ++ } ++} ++ ++/* ++ * Determine the page address for an address offset value, ++ * get a virtual address for it, and copy it out. ++ * Accesses must fit within a page. ++ */ ++static ssize_t ++crash_read(struct file *file, char *buf, size_t count, loff_t *poff) ++{ ++ void *vaddr; ++ struct page *page; ++ u64 offset; ++ ssize_t read; ++ ++ offset = *poff; ++ if (offset >> PAGE_SHIFT != (offset+count-1) >> PAGE_SHIFT) ++ return -EINVAL; ++ ++ vaddr = map_virtual(offset, &page); ++ if (!vaddr) ++ return -EFAULT; ++ ++ if (copy_to_user(buf, vaddr, count)) { ++ unmap_virtual(page); ++ return -EFAULT; ++ } ++ unmap_virtual(page); ++ ++ read = count; ++ *poff += read; ++ return read; ++} ++ ++static struct file_operations crash_fops = { ++ .owner = THIS_MODULE, ++ .llseek = crash_llseek, ++ .read = crash_read, ++}; ++ ++static struct miscdevice crash_dev = { ++ MISC_DYNAMIC_MINOR, ++ "crash", ++ &crash_fops ++}; ++ ++static int __init ++crash_init(void) ++{ ++ int ret; ++ ++ ret = misc_register(&crash_dev); ++ if (ret) { ++ printk(KERN_ERR ++ "crash memory driver: cannot misc_register (MISC_DYNAMIC_MINOR)\n"); ++ goto out; ++ } ++ ++ ret = 0; ++ printk(KERN_INFO "crash memory driver: version %s\n", CRASH_VERSION); ++out: ++ return ret; ++} ++ ++static void __exit ++crash_cleanup_module(void) ++{ ++ misc_deregister(&crash_dev); ++} ++ ++module_init(crash_init); ++module_exit(crash_cleanup_module); ++ ++MODULE_LICENSE("GPL"); diff --git a/linux-2.6-debug-always-inline-kzalloc.patch b/linux-2.6-debug-always-inline-kzalloc.patch new file mode 100644 index 000000000..24f665ca6 --- /dev/null +++ b/linux-2.6-debug-always-inline-kzalloc.patch @@ -0,0 +1,25 @@ +From 76ec0e2e6d6edf81abc0331d5e7873ef7b2f6019 Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Wed, 8 Jul 2009 13:06:01 -0400 +Subject: [PATCH 6/6] fedora: linux-2.6-debug-always-inline-kzalloc.patch + +--- + include/linux/slab.h | 2 +- + 1 files changed, 1 insertions(+), 1 deletions(-) + +diff --git a/include/linux/slab.h b/include/linux/slab.h +index 2da8372..d4ef74f 100644 +--- a/include/linux/slab.h ++++ b/include/linux/slab.h +@@ -310,7 +310,7 @@ static inline void *kmem_cache_zalloc(struct kmem_cache *k, gfp_t flags) + * @size: how many bytes of memory are required. + * @flags: the type of memory to allocate (see kmalloc). + */ +-static inline void *kzalloc(size_t size, gfp_t flags) ++static __always_inline void *kzalloc(size_t size, gfp_t flags) + { + return kmalloc(size, flags | __GFP_ZERO); + } +-- +1.6.2.5 + diff --git a/linux-2.6-debug-nmi-timeout.patch b/linux-2.6-debug-nmi-timeout.patch new file mode 100644 index 000000000..15249d583 --- /dev/null +++ b/linux-2.6-debug-nmi-timeout.patch @@ -0,0 +1,45 @@ +From c2dcc88ee3aca407471246c38c11a100cca39076 Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Mon, 11 Jan 2010 08:20:51 -0500 +Subject: linux-2.6-debug-nmi-timeout.patch + +--- + arch/x86/kernel/apic/nmi.c | 2 +- + lib/Kconfig.debug | 8 ++++++++ + 2 files changed, 9 insertions(+), 1 deletions(-) + +diff --git a/arch/x86/kernel/apic/nmi.c b/arch/x86/kernel/apic/nmi.c +index 0159a69..2bbca2b 100644 +--- a/arch/x86/kernel/apic/nmi.c ++++ b/arch/x86/kernel/apic/nmi.c +@@ -439,7 +439,7 @@ nmi_watchdog_tick(struct pt_regs *regs, unsigned reason) + * wait a few IRQs (5 seconds) before doing the oops ... + */ + __this_cpu_inc(per_cpu_var(alert_counter)); +- if (__this_cpu_read(per_cpu_var(alert_counter)) == 5 * nmi_hz) ++ if (__this_cpu_read(per_cpu_var(alert_counter)) == CONFIG_DEBUG_NMI_TIMEOUT * nmi_hz) + /* + * die_nmi will return ONLY if NOTIFY_STOP happens.. + */ +diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug +index 25c3ed5..6d67975 100644 +--- a/lib/Kconfig.debug ++++ b/lib/Kconfig.debug +@@ -253,6 +253,14 @@ config SCHEDSTATS + application, you can say N to avoid the very slight overhead + this adds. + ++config DEBUG_NMI_TIMEOUT ++ int "Number of seconds before NMI timeout" ++ depends on X86 ++ default 5 ++ help ++ This value is the number of seconds the NMI watchdog will tick ++ before it decides the machine has hung. ++ + config TIMER_STATS + bool "Collect kernel timers statistics" + depends on DEBUG_KERNEL && PROC_FS +-- +1.6.5.2 + diff --git a/linux-2.6-debug-sizeof-structs.patch b/linux-2.6-debug-sizeof-structs.patch new file mode 100644 index 000000000..cc7747d1f --- /dev/null +++ b/linux-2.6-debug-sizeof-structs.patch @@ -0,0 +1,31 @@ +diff --git a/init/main.c b/init/main.c +index 7449819..98cfaae 100644 +--- a/init/main.c ++++ b/init/main.c +@@ -369,6 +369,10 @@ static void __init setup_nr_cpu_ids(void) + nr_cpu_ids = find_last_bit(cpumask_bits(cpu_possible_mask),NR_CPUS) + 1; + } + ++#include ++#include ++#include ++ + /* Called by boot processor to activate the rest. */ + static void __init smp_init(void) + { +@@ -391,6 +395,15 @@ static void __init smp_init(void) + /* Any cleanup work */ + printk(KERN_INFO "Brought up %ld CPUs\n", (long)num_online_cpus()); + smp_cpus_done(setup_max_cpus); ++ ++ printk(KERN_DEBUG "sizeof(vma)=%u bytes\n", (unsigned int) sizeof(struct vm_area_struct)); ++ printk(KERN_DEBUG "sizeof(page)=%u bytes\n", (unsigned int) sizeof(struct page)); ++ printk(KERN_DEBUG "sizeof(inode)=%u bytes\n", (unsigned int) sizeof(struct inode)); ++ printk(KERN_DEBUG "sizeof(dentry)=%u bytes\n", (unsigned int) sizeof(struct dentry)); ++ printk(KERN_DEBUG "sizeof(ext3inode)=%u bytes\n", (unsigned int) sizeof(struct ext3_inode_info)); ++ printk(KERN_DEBUG "sizeof(buffer_head)=%u bytes\n", (unsigned int) sizeof(struct buffer_head)); ++ printk(KERN_DEBUG "sizeof(skbuff)=%u bytes\n", (unsigned int) sizeof(struct sk_buff)); ++ printk(KERN_DEBUG "sizeof(task_struct)=%u bytes\n", (unsigned int) sizeof(struct task_struct)); + } + + #endif diff --git a/linux-2.6-debug-taint-vm.patch b/linux-2.6-debug-taint-vm.patch new file mode 100644 index 000000000..ee367d45a --- /dev/null +++ b/linux-2.6-debug-taint-vm.patch @@ -0,0 +1,65 @@ +From b04c57d9dc889462951312be2ac81ff6c702e954 Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Wed, 8 Jul 2009 13:05:09 -0400 +Subject: [PATCH 3/6] fedora: linux-2.6-debug-taint-vm.patch + +--- + kernel/panic.c | 4 +++- + mm/slab.c | 8 ++++---- + mm/slub.c | 2 +- + 4 files changed, 11 insertions(+), 8 deletions(-) + +diff --git a/kernel/panic.c b/kernel/panic.c +index 984b3ec..6d1c3be 100644 +--- a/kernel/panic.c ++++ b/kernel/panic.c +@@ -199,6 +199,7 @@ const char *print_tainted(void) + + return buf; + } ++EXPORT_SYMBOL(print_tainted); + + int test_taint(unsigned flag) + { +diff --git a/mm/slab.c b/mm/slab.c +index e74a16e..7bc287e 100644 +--- a/mm/slab.c ++++ b/mm/slab.c +@@ -1803,8 +1803,8 @@ static void check_poison_obj(struct kmem_cache *cachep, void *objp) + /* Print header */ + if (lines == 0) { + printk(KERN_ERR +- "Slab corruption: %s start=%p, len=%d\n", +- cachep->name, realobj, size); ++ "Slab corruption (%s): %s start=%p, len=%d\n", ++ print_tainted(), cachep->name, realobj, size); + print_objinfo(cachep, objp, 0); + } + /* Hexdump the affected line */ +@@ -2902,8 +2902,8 @@ static void check_slabp(struct kmem_cache *cachep, struct slab *slabp) + if (entries != cachep->num - slabp->inuse) { + bad: + printk(KERN_ERR "slab: Internal list corruption detected in " +- "cache '%s'(%d), slabp %p(%d). Hexdump:\n", +- cachep->name, cachep->num, slabp, slabp->inuse); ++ "cache '%s'(%d), slabp %p(%d). Tainted(%s). Hexdump:\n", ++ cachep->name, cachep->num, slabp, slabp->inuse, print_tainted()); + for (i = 0; + i < sizeof(*slabp) + cachep->num * sizeof(kmem_bufctl_t); + i++) { +diff --git a/mm/slub.c b/mm/slub.c +index 819f056..8eff0f4 100644 +--- a/mm/slub.c ++++ b/mm/slub.c +@@ -433,7 +433,7 @@ static void slab_bug(struct kmem_cache *s, char *fmt, ...) + va_end(args); + printk(KERN_ERR "========================================" + "=====================================\n"); +- printk(KERN_ERR "BUG %s: %s\n", s->name, buf); ++ printk(KERN_ERR "BUG %s (%s): %s\n", s->name, print_tainted(), buf); + printk(KERN_ERR "----------------------------------------" + "-------------------------------------\n\n"); + } +-- +1.6.2.5 + diff --git a/linux-2.6-debug-vm-would-have-oomkilled.patch b/linux-2.6-debug-vm-would-have-oomkilled.patch new file mode 100644 index 000000000..dd8ba3f0a --- /dev/null +++ b/linux-2.6-debug-vm-would-have-oomkilled.patch @@ -0,0 +1,64 @@ +From 03657519851cd180983db4bd0c38eaeed4aa2962 Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Mon, 11 Jan 2010 08:25:12 -0500 +Subject: linux-2.6-debug-vm-would-have-oomkilled.patch + +--- + kernel/sysctl.c | 8 ++++++++ + mm/oom_kill.c | 7 +++++++ + 2 files changed, 15 insertions(+), 0 deletions(-) + +diff --git a/kernel/sysctl.c b/kernel/sysctl.c +index 8a68b24..72a4ff1 100644 +--- a/kernel/sysctl.c ++++ b/kernel/sysctl.c +@@ -71,6 +71,7 @@ extern int sysctl_overcommit_ratio; + extern int sysctl_panic_on_oom; + extern int sysctl_oom_kill_allocating_task; + extern int sysctl_oom_dump_tasks; ++extern int sysctl_would_have_oomkilled; + extern int max_threads; + extern int core_uses_pid; + extern int suid_dumpable; +@@ -973,6 +974,13 @@ static struct ctl_table vm_table[] = { + .proc_handler = proc_dointvec, + }, + { ++ .procname = "would_have_oomkilled", ++ .data = &sysctl_would_have_oomkilled, ++ .maxlen = sizeof(sysctl_would_have_oomkilled), ++ .mode = 0644, ++ .proc_handler = &proc_dointvec, ++ }, ++ { + .procname = "overcommit_ratio", + .data = &sysctl_overcommit_ratio, + .maxlen = sizeof(sysctl_overcommit_ratio), +diff --git a/mm/oom_kill.c b/mm/oom_kill.c +index f52481b..a892f07 100644 +--- a/mm/oom_kill.c ++++ b/mm/oom_kill.c +@@ -31,6 +31,7 @@ + int sysctl_panic_on_oom; + int sysctl_oom_kill_allocating_task; + int sysctl_oom_dump_tasks; ++int sysctl_would_have_oomkilled; + static DEFINE_SPINLOCK(zone_scan_lock); + /* #define DEBUG */ + +@@ -396,6 +397,12 @@ static void __oom_kill_task(struct task_struct *p, int verbose) + return; + } + ++ if (sysctl_would_have_oomkilled == 1) { ++ printk(KERN_ERR "Would have killed process %d (%s). But continuing instead.\n", ++ task_pid_nr(p), p->comm); ++ return; ++ } ++ + if (verbose) + printk(KERN_ERR "Killed process %d (%s) " + "vsz:%lukB, anon-rss:%lukB, file-rss:%lukB\n", +-- +1.6.5.2 + diff --git a/linux-2.6-defaults-acpi-video.patch b/linux-2.6-defaults-acpi-video.patch new file mode 100644 index 000000000..af883b0d3 --- /dev/null +++ b/linux-2.6-defaults-acpi-video.patch @@ -0,0 +1,13 @@ +diff --git a/drivers/acpi/video.c b/drivers/acpi/video.c +index d8d7596..a1b7117 100644 +--- a/drivers/acpi/video.c ++++ b/drivers/acpi/video.c +@@ -71,7 +71,7 @@ MODULE_AUTHOR("Bruno Ducrot"); + MODULE_DESCRIPTION("ACPI Video Driver"); + MODULE_LICENSE("GPL"); + +-static int brightness_switch_enabled = 1; ++static int brightness_switch_enabled = 0; + module_param(brightness_switch_enabled, bool, 0644); + + static int acpi_video_bus_add(struct acpi_device *device); diff --git a/linux-2.6-defaults-aspm.patch b/linux-2.6-defaults-aspm.patch new file mode 100644 index 000000000..49b832d2c --- /dev/null +++ b/linux-2.6-defaults-aspm.patch @@ -0,0 +1,12 @@ +diff -up linux-2.6.30.noarch/drivers/pci/pcie/aspm.c.mjg linux-2.6.30.noarch/drivers/pci/pcie/aspm.c +--- linux-2.6.30.noarch/drivers/pci/pcie/aspm.c.mjg 2009-07-16 22:01:11.000000000 +0100 ++++ linux-2.6.30.noarch/drivers/pci/pcie/aspm.c 2009-07-16 22:01:30.000000000 +0100 +@@ -65,7 +65,7 @@ static LIST_HEAD(link_list); + #define POLICY_DEFAULT 0 /* BIOS default setting */ + #define POLICY_PERFORMANCE 1 /* high performance */ + #define POLICY_POWERSAVE 2 /* high power saving */ +-static int aspm_policy; ++static int aspm_policy = POLICY_POWERSAVE; + static const char *policy_str[] = { + [POLICY_DEFAULT] = "default", + [POLICY_PERFORMANCE] = "performance", diff --git a/linux-2.6-defaults-pci_no_msi.patch b/linux-2.6-defaults-pci_no_msi.patch new file mode 100644 index 000000000..fad6a53b2 --- /dev/null +++ b/linux-2.6-defaults-pci_no_msi.patch @@ -0,0 +1,92 @@ +--- linux-2.6.30.noarch/Documentation/kernel-parameters.txt~ 2009-06-24 14:25:04.000000000 -0400 ++++ linux-2.6.30.noarch/Documentation/kernel-parameters.txt 2009-06-24 14:25:32.000000000 -0400 +@@ -1811,6 +1811,9 @@ and is between 256 and 4096 characters. + check_enable_amd_mmconf [X86] check for and enable + properly configured MMIO access to PCI + config space on AMD family 10h CPU ++ msi [MSI] If the PCI_MSI kernel config parameter is ++ enabled, this kernel boot option can be used to ++ enable the use of MSI interrupts system-wide. + nomsi [MSI] If the PCI_MSI kernel config parameter is + enabled, this kernel boot option can be used to + disable the use of MSI interrupts system-wide. +diff --git a/drivers/pci/Kconfig b/drivers/pci/Kconfig +index 2a4501d..209758c 100644 +--- a/drivers/pci/Kconfig ++++ b/drivers/pci/Kconfig +@@ -21,6 +21,18 @@ config PCI_MSI + + If you don't know what to do here, say N. + ++config PCI_MSI_DEFAULT_ON ++ def_bool y ++ prompt "Use Message Signaled Interrupts by default" ++ depends on PCI_MSI ++ help ++ Selecting this option will enable use of PCI MSI where applicable ++ by default. Support for MSI can be disabled through the use of the ++ pci=nomsi boot flag. Conversely, if this option is not selected, ++ support for PCI MSI can be enabled by passing the pci=msi flag. ++ ++ If you don't know what to do here, say N. ++ + config PCI_LEGACY + bool "Enable deprecated pci_find_* API" + depends on PCI +diff --git a/drivers/pci/msi.c b/drivers/pci/msi.c +index 896a15d..53df583 100644 +--- a/drivers/pci/msi.c ++++ b/drivers/pci/msi.c +@@ -23,7 +23,11 @@ + #include "pci.h" + #include "msi.h" + ++#ifdef CONFIG_PCI_MSI_DEFAULT_ON + static int pci_msi_enable = 1; ++#else ++static int pci_msi_enable = 0; ++#endif /*CONFIG_PCI_MSI_DEFAULT_ON*/ + + /* Arch hooks */ + +@@ -786,6 +790,11 @@ int pci_msi_enabled(void) + } + EXPORT_SYMBOL(pci_msi_enabled); + ++void pci_yes_msi(void) ++{ ++ pci_msi_enable = 1; ++} ++ + void pci_msi_init_pci_dev(struct pci_dev *dev) + { + INIT_LIST_HEAD(&dev->msi_list); +diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c +index 17bd932..e9bc9fe 100644 +--- a/drivers/pci/pci.c ++++ b/drivers/pci/pci.c +@@ -2393,6 +2393,8 @@ static int __init pci_setup(char *str) + if (*str && (str = pcibios_setup(str)) && *str) { + if (!strcmp(str, "nomsi")) { + pci_no_msi(); ++ } else if (!strcmp(str, "msi")) { ++ pci_yes_msi(); + } else if (!strcmp(str, "noaer")) { + pci_no_aer(); + } else if (!strcmp(str, "nodomains")) { +diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h +index 26ddf78..85efe81 100644 +--- a/drivers/pci/pci.h ++++ b/drivers/pci/pci.h +@@ -111,9 +111,11 @@ extern unsigned int pci_pm_d3_delay; + + #ifdef CONFIG_PCI_MSI + void pci_no_msi(void); ++void pci_yes_msi(void); + extern void pci_msi_init_pci_dev(struct pci_dev *dev); + #else + static inline void pci_no_msi(void) { } ++static inline void pci_yes_msi(void) { } + static inline void pci_msi_init_pci_dev(struct pci_dev *dev) { } + #endif + diff --git a/linux-2.6-defaults-pciehp.patch b/linux-2.6-defaults-pciehp.patch new file mode 100644 index 000000000..07f2670c7 --- /dev/null +++ b/linux-2.6-defaults-pciehp.patch @@ -0,0 +1,13 @@ +diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c +index e7f3c9e..4f2b037 100644 +--- a/drivers/pci/hotplug/pciehp_core.c ++++ b/drivers/pci/hotplug/pciehp_core.c +@@ -41,7 +41,7 @@ int pciehp_debug; + int pciehp_poll_mode; + int pciehp_poll_time; + int pciehp_force; +-int pciehp_passive; ++int pciehp_passive=1; + struct workqueue_struct *pciehp_wq; + + #define DRIVER_VERSION "0.4" diff --git a/linux-2.6-dell-laptop-rfkill-fix.patch b/linux-2.6-dell-laptop-rfkill-fix.patch new file mode 100644 index 000000000..911179ab5 --- /dev/null +++ b/linux-2.6-dell-laptop-rfkill-fix.patch @@ -0,0 +1,319 @@ +From caca5447fae9bfc87ab7d4af664d8bc95db6904d Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Mon, 11 Jan 2010 08:08:02 -0500 +Subject: linux-2.6-dell-laptop-rfkill-fix.patch + +--- + drivers/input/input.c | 91 ++++++++++++++++++++++++++++----- + drivers/platform/x86/dell-laptop.c | 100 ++++++++++++++++++++++++++++++++++++ + include/linux/input.h | 5 ++ + 3 files changed, 183 insertions(+), 13 deletions(-) + +diff --git a/drivers/input/input.c b/drivers/input/input.c +index ab06071..1911c3a 100644 +--- a/drivers/input/input.c ++++ b/drivers/input/input.c +@@ -90,19 +90,26 @@ static int input_defuzz_abs_event(int value, int old_val, int fuzz) + */ + static void input_pass_event(struct input_dev *dev, + unsigned int type, unsigned int code, int value) +-{ +- struct input_handle *handle; ++ ++{ struct input_handle *handle; + + rcu_read_lock(); + + handle = rcu_dereference(dev->grab); +- if (handle) ++ if (handle) { + handle->handler->event(handle, type, code, value); +- else +- list_for_each_entry_rcu(handle, &dev->h_list, d_node) +- if (handle->open) +- handle->handler->event(handle, +- type, code, value); ++ goto out; ++ } ++ ++ handle = rcu_dereference(dev->filter); ++ if (handle && handle->handler->filter(handle, type, code, value)) ++ goto out; ++ ++ list_for_each_entry_rcu(handle, &dev->h_list, d_node) ++ if (handle->open) ++ handle->handler->event(handle, ++ type, code, value); ++out: + rcu_read_unlock(); + } + +@@ -383,12 +390,15 @@ int input_grab_device(struct input_handle *handle) + } + EXPORT_SYMBOL(input_grab_device); + +-static void __input_release_device(struct input_handle *handle) ++static void __input_release_device(struct input_handle *handle, bool filter) + { + struct input_dev *dev = handle->dev; + +- if (dev->grab == handle) { +- rcu_assign_pointer(dev->grab, NULL); ++ if (handle == (filter ? dev->filter : dev->grab)) { ++ if (filter) ++ rcu_assign_pointer(dev->filter, NULL); ++ else ++ rcu_assign_pointer(dev->grab, NULL); + /* Make sure input_pass_event() notices that grab is gone */ + synchronize_rcu(); + +@@ -412,12 +422,65 @@ void input_release_device(struct input_handle *handle) + struct input_dev *dev = handle->dev; + + mutex_lock(&dev->mutex); +- __input_release_device(handle); ++ __input_release_device(handle, false); + mutex_unlock(&dev->mutex); + } + EXPORT_SYMBOL(input_release_device); + + /** ++ * input_filter_device - allow input events to be filtered from higher layers ++ * @handle: input handle that wants to filter the device ++ * ++ * When a device is filtered by an input handle all events generated by ++ * the device are to this handle. If the filter function returns true then ++ * the event is discarded rather than being passed to any other input handles, ++ * otherwise it is passed to them as normal. Grabs will be handled before ++ * filters, so a grabbed device will not deliver events to a filter function. ++ */ ++int input_filter_device(struct input_handle *handle) ++{ ++ struct input_dev *dev = handle->dev; ++ int retval; ++ ++ retval = mutex_lock_interruptible(&dev->mutex); ++ if (retval) ++ return retval; ++ ++ if (dev->filter) { ++ retval = -EBUSY; ++ goto out; ++ } ++ ++ rcu_assign_pointer(dev->filter, handle); ++ synchronize_rcu(); ++ ++ out: ++ mutex_unlock(&dev->mutex); ++ return retval; ++} ++EXPORT_SYMBOL(input_filter_device); ++ ++/** ++ * input_unfilter_device - removes a filter from a device ++ * @handle: input handle that owns the device ++ * ++ * Removes the filter from a device so that other input handles can ++ * start receiving unfiltered input events. Upon release all handlers ++ * attached to the device have their start() method called so they ++ * have a change to synchronize device state with the rest of the ++ * system. ++ */ ++void input_unfilter_device(struct input_handle *handle) ++{ ++ struct input_dev *dev = handle->dev; ++ ++ mutex_lock(&dev->mutex); ++ __input_release_device(handle, true); ++ mutex_unlock(&dev->mutex); ++} ++EXPORT_SYMBOL(input_unfilter_device); ++ ++/** + * input_open_device - open input device + * @handle: handle through which device is being accessed + * +@@ -490,7 +553,9 @@ void input_close_device(struct input_handle *handle) + + mutex_lock(&dev->mutex); + +- __input_release_device(handle); ++ /* Release both grabs and filters */ ++ __input_release_device(handle, false); ++ __input_release_device(handle, true); + + if (!--dev->users && dev->close) + dev->close(dev); +diff --git a/drivers/platform/x86/dell-laptop.c b/drivers/platform/x86/dell-laptop.c +index 3780994..25247be 100644 +--- a/drivers/platform/x86/dell-laptop.c ++++ b/drivers/platform/x86/dell-laptop.c +@@ -22,6 +22,7 @@ + #include + #include + #include ++#include + #include "../../firmware/dcdbas.h" + + #define BRIGHTNESS_TOKEN 0x7d +@@ -214,6 +215,16 @@ static const struct rfkill_ops dell_rfkill_ops = { + .query = dell_rfkill_query, + }; + ++static void dell_rfkill_update(void) ++{ ++ if (wifi_rfkill) ++ dell_rfkill_query(wifi_rfkill, (void *)1); ++ if (bluetooth_rfkill) ++ dell_rfkill_query(bluetooth_rfkill, (void *)2); ++ if (wwan_rfkill) ++ dell_rfkill_query(wwan_rfkill, (void *)3); ++} ++ + static int __init dell_setup_rfkill(void) + { + struct calling_interface_buffer buffer; +@@ -338,6 +349,90 @@ static struct backlight_ops dell_ops = { + .update_status = dell_send_intensity, + }; + ++static const struct input_device_id dell_input_ids[] = { ++ { ++ .bustype = 0x11, ++ .vendor = 0x01, ++ .product = 0x01, ++ .version = 0xab41, ++ .flags = INPUT_DEVICE_ID_MATCH_BUS | ++ INPUT_DEVICE_ID_MATCH_VENDOR | ++ INPUT_DEVICE_ID_MATCH_PRODUCT | ++ INPUT_DEVICE_ID_MATCH_VERSION ++ }, ++ { }, ++}; ++ ++static bool dell_input_filter(struct input_handle *handle, unsigned int type, ++ unsigned int code, int value) ++{ ++ if (type == EV_KEY && code == KEY_WLAN && value == 1) { ++ dell_rfkill_update(); ++ return 1; ++ } ++ ++ return 0; ++} ++ ++static void dell_input_event(struct input_handle *handle, unsigned int type, ++ unsigned int code, int value) ++{ ++} ++ ++static int dell_input_connect(struct input_handler *handler, ++ struct input_dev *dev, ++ const struct input_device_id *id) ++{ ++ struct input_handle *handle; ++ int error; ++ ++ handle = kzalloc(sizeof(struct input_handle), GFP_KERNEL); ++ if (!handle) ++ return -ENOMEM; ++ ++ handle->dev = dev; ++ handle->handler = handler; ++ handle->name = "dell-laptop"; ++ ++ error = input_register_handle(handle); ++ if (error) ++ goto err_free_handle; ++ ++ error = input_open_device(handle); ++ if (error) ++ goto err_unregister_handle; ++ ++ error = input_filter_device(handle); ++ if (error) ++ goto err_close_handle; ++ ++ return 0; ++ ++err_close_handle: ++ input_close_device(handle); ++err_unregister_handle: ++ input_unregister_handle(handle); ++err_free_handle: ++ kfree(handle); ++ return error; ++} ++ ++static void dell_input_disconnect(struct input_handle *handle) ++{ ++ input_close_device(handle); ++ input_unregister_handle(handle); ++ kfree(handle); ++} ++ ++static struct input_handler dell_input_handler = { ++ .name = "dell-laptop", ++ .filter = dell_input_filter, ++ .event = dell_input_event, ++ .connect = dell_input_connect, ++ .disconnect = dell_input_disconnect, ++ .id_table = dell_input_ids, ++}; ++ + static int __init dell_init(void) + { + struct calling_interface_buffer buffer; +@@ -373,6 +468,10 @@ static int __init dell_init(void) + goto fail_rfkill; + } + ++ if (input_register_handler(&dell_input_handler)) ++ printk(KERN_INFO ++ "dell-laptop: Could not register input filter\n"); ++ + #ifdef CONFIG_ACPI + /* In the event of an ACPI backlight being available, don't + * register the platform controller. +@@ -426,6 +525,7 @@ static void __exit dell_exit(void) + { + backlight_device_unregister(dell_backlight_device); + dell_cleanup_rfkill(); ++ input_unregister_handler(&dell_input_handler); + } + + module_init(dell_init); +diff --git a/include/linux/input.h b/include/linux/input.h +index 7be8a65..7d49094 100644 +--- a/include/linux/input.h ++++ b/include/linux/input.h +@@ -1127,6 +1127,7 @@ struct input_dev { + int (*event)(struct input_dev *dev, unsigned int type, unsigned int code, int value); + + struct input_handle *grab; ++ struct input_handle *filter; + + spinlock_t event_lock; + struct mutex mutex; +@@ -1227,6 +1228,7 @@ struct input_handler { + void *private; + + void (*event)(struct input_handle *handle, unsigned int type, unsigned int code, int value); ++ bool (*filter)(struct input_handle *handle, unsigned int type, unsigned int code, int value); + int (*connect)(struct input_handler *handler, struct input_dev *dev, const struct input_device_id *id); + void (*disconnect)(struct input_handle *handle); + void (*start)(struct input_handle *handle); +@@ -1307,6 +1309,9 @@ void input_unregister_handle(struct input_handle *); + int input_grab_device(struct input_handle *); + void input_release_device(struct input_handle *); + ++int input_filter_device(struct input_handle *); ++void input_unfilter_device(struct input_handle *); ++ + int input_open_device(struct input_handle *); + void input_close_device(struct input_handle *); + +-- +1.6.5.2 + diff --git a/linux-2.6-driver-level-usb-autosuspend.diff b/linux-2.6-driver-level-usb-autosuspend.diff new file mode 100644 index 000000000..00384ccf5 --- /dev/null +++ b/linux-2.6-driver-level-usb-autosuspend.diff @@ -0,0 +1,69 @@ +commit 7d0d20a25c6f477fb198b85510c78156d7d7c5af +Author: Matthew Garrett +Date: Tue Jun 9 20:11:47 2009 +0100 + + usb: Allow drivers to enable USB autosuspend on a per-device basis + + USB autosuspend is currently only enabled by default for hubs. On other + hardware the decision is made by userspace. This is unnecessary in cases + where we know that the hardware supports autosuspend, so this patch adds + a function to allow drivers to enable it at probe time. + + Signed-off-by: Matthew Garrett + +--- + drivers/usb/core/driver.c | 16 ++++++++++++++++ + include/linux/usb.h | 4 ++++ + 2 files changed, 20 insertions(+), 0 deletions(-) + +diff --git a/drivers/usb/core/driver.c b/drivers/usb/core/driver.c +index 60a45f1..03e0228 100644 +--- a/drivers/usb/core/driver.c ++++ b/drivers/usb/core/driver.c +@@ -1648,6 +1648,21 @@ void usb_autopm_put_interface_async(struct usb_interface *intf) + EXPORT_SYMBOL_GPL(usb_autopm_put_interface_async); + + /** ++ * usb_device_autosuspend_enable - enable autosuspend on a device ++ * @udev: the usb_device to be autosuspended ++ * ++ * This routine should be called by an interface driver when it knows that ++ * the device in question supports USB autosuspend. ++ * ++ */ ++void usb_device_autosuspend_enable(struct usb_device *udev) ++{ ++ udev->autosuspend_disabled = 0; ++ usb_external_suspend_device(udev, PMSG_USER_SUSPEND); ++} ++EXPORT_SYMBOL_GPL(usb_device_autosuspend_enable); ++ ++/** + * usb_autopm_get_interface - increment a USB interface's PM-usage counter + * @intf: the usb_interface whose counter should be incremented + * +diff --git a/include/linux/usb.h b/include/linux/usb.h +index e101a2d..dd47590 100644 +--- a/include/linux/usb.h ++++ b/include/linux/usb.h +@@ -540,6 +540,7 @@ extern struct usb_device *usb_find_device(u16 vendor_id, u16 product_id); + + /* USB autosuspend and autoresume */ + #ifdef CONFIG_USB_SUSPEND ++extern void usb_device_autosuspend_enable(struct usb_device *udev); + extern int usb_autopm_get_interface(struct usb_interface *intf); + extern void usb_autopm_put_interface(struct usb_interface *intf); + extern int usb_autopm_get_interface_async(struct usb_interface *intf); +@@ -563,6 +564,9 @@ static inline void usb_mark_last_busy(struct usb_device *udev) + + #else + ++static inline void usb_device_autosuspend_enable(struct usb_device *udev) ++{ } ++ + static inline int usb_autopm_get_interface(struct usb_interface *intf) + { return 0; } + static inline int usb_autopm_get_interface_async(struct usb_interface *intf) +-- +1.6.5.2 + diff --git a/linux-2.6-enable-btusb-autosuspend.patch b/linux-2.6-enable-btusb-autosuspend.patch new file mode 100644 index 000000000..7e75341bb --- /dev/null +++ b/linux-2.6-enable-btusb-autosuspend.patch @@ -0,0 +1,18 @@ +commit 8e962bd41a2cbf7f0e55191a757b87f793a725a8 +Author: Matthew Garrett +Date: Tue Jun 9 20:47:51 2009 +0100 + + btusb: Enable autosuspend by default + +diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c +index 44bc8bb..4c33417 100644 +--- a/drivers/bluetooth/btusb.c ++++ b/drivers/bluetooth/btusb.c +@@ -1020,6 +1020,7 @@ static int btusb_probe(struct usb_interface *intf, + } + + usb_set_intfdata(intf, data); ++ usb_device_autosuspend_enable(data->udev); + + return 0; + } diff --git a/linux-2.6-execshield.patch b/linux-2.6-execshield.patch new file mode 100644 index 000000000..b6ee042c0 --- /dev/null +++ b/linux-2.6-execshield.patch @@ -0,0 +1,935 @@ +--- a/arch/x86/include/asm/desc.h ++++ b/arch/x86/include/asm/desc.h +@@ -5,6 +5,7 @@ + #include + #include + #include ++#include + + static inline void fill_ldt(struct desc_struct *desc, + const struct user_desc *info) +@@ -93,6 +94,9 @@ static inline int desc_empty(const void *ptr) + + #define load_TLS(t, cpu) native_load_tls(t, cpu) + #define set_ldt native_set_ldt ++#ifdef CONFIG_X86_32 ++#define load_user_cs_desc native_load_user_cs_desc ++#endif /*CONFIG_X86_32*/ + + #define write_ldt_entry(dt, entry, desc) \ + native_write_ldt_entry(dt, entry, desc) +@@ -392,4 +396,25 @@ static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist) + _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS); + } + ++#ifdef CONFIG_X86_32 ++static inline void set_user_cs(struct desc_struct *desc, unsigned long limit) ++{ ++ limit = (limit - 1) / PAGE_SIZE; ++ desc->a = limit & 0xffff; ++ desc->b = (limit & 0xf0000) | 0x00c0fb00; ++} ++ ++static inline void native_load_user_cs_desc(int cpu, struct mm_struct *mm) ++{ ++ get_cpu_gdt_table(cpu)[GDT_ENTRY_DEFAULT_USER_CS] = (mm)->context.user_cs; ++} ++ ++#define arch_add_exec_range arch_add_exec_range ++#define arch_remove_exec_range arch_remove_exec_range ++#define arch_flush_exec_range arch_flush_exec_range ++extern void arch_add_exec_range(struct mm_struct *mm, unsigned long limit); ++extern void arch_remove_exec_range(struct mm_struct *mm, unsigned long limit); ++extern void arch_flush_exec_range(struct mm_struct *mm); ++#endif /* CONFIG_X86_32 */ ++ + #endif /* _ASM_X86_DESC_H */ +--- a/arch/x86/include/asm/mmu.h ++++ b/arch/x86/include/asm/mmu.h +@@ -7,12 +7,19 @@ + /* + * The x86 doesn't have a mmu context, but + * we put the segment information here. ++ * ++ * exec_limit is used to track the range PROT_EXEC ++ * mappings span. + */ + typedef struct { + void *ldt; + int size; + struct mutex lock; + void *vdso; ++#ifdef CONFIG_X86_32 ++ struct desc_struct user_cs; ++ unsigned long exec_limit; ++#endif + } mm_context_t; + + #ifdef CONFIG_SMP +--- a/arch/x86/include/asm/paravirt.h ++++ b/arch/x86/include/asm/paravirt.h +@@ -289,6 +289,12 @@ static inline void set_ldt(const void *addr, unsigned entries) + { + PVOP_VCALL2(pv_cpu_ops.set_ldt, addr, entries); + } ++#ifdef CONFIG_X86_32 ++static inline void load_user_cs_desc(unsigned int cpu, struct mm_struct *mm) ++{ ++ PVOP_VCALL2(pv_cpu_ops.load_user_cs_desc, cpu, mm); ++} ++#endif /*CONFIG_X86_32*/ + static inline void store_gdt(struct desc_ptr *dtr) + { + PVOP_VCALL1(pv_cpu_ops.store_gdt, dtr); +--- a/arch/x86/include/asm/paravirt_types.h ++++ b/arch/x86/include/asm/paravirt_types.h +@@ -118,6 +118,9 @@ struct pv_cpu_ops { + void (*store_gdt)(struct desc_ptr *); + void (*store_idt)(struct desc_ptr *); + void (*set_ldt)(const void *desc, unsigned entries); ++#ifdef CONFIG_X86_32 ++ void (*load_user_cs_desc)(int cpu, struct mm_struct *mm); ++#endif + unsigned long (*store_tr)(void); + void (*load_tls)(struct thread_struct *t, unsigned int cpu); + #ifdef CONFIG_X86_64 +--- a/arch/x86/include/asm/processor.h ++++ b/arch/x86/include/asm/processor.h +@@ -162,6 +162,9 @@ static inline int hlt_works(int cpu) + + #define cache_line_size() (boot_cpu_data.x86_cache_alignment) + ++#define __HAVE_ARCH_ALIGN_STACK ++extern unsigned long arch_align_stack(unsigned long sp); ++ + extern void cpu_detect(struct cpuinfo_x86 *c); + + extern struct pt_regs *idle_regs(struct pt_regs *); +--- a/arch/x86/kernel/cpu/common.c ++++ b/arch/x86/kernel/cpu/common.c +@@ -802,6 +802,20 @@ static void __cpuinit identify_cpu(struct cpuinfo_x86 *c) + /* Filter out anything that depends on CPUID levels we don't have */ + filter_cpuid_features(c, true); + ++ /* ++ * emulation of NX with segment limits unfortunately means ++ * we have to disable the fast system calls, due to the way that ++ * sysexit clears the segment limits on return. ++ * If we have either disabled exec-shield on the boot command line, ++ * or we have NX, then we don't need to do this. ++ */ ++ if (exec_shield != 0) { ++#ifdef CONFIG_X86_PAE ++ if (!test_cpu_cap(c, X86_FEATURE_NX)) ++#endif ++ clear_cpu_cap(c, X86_FEATURE_SEP); ++ } ++ + /* If the model name is still unset, do table lookup. */ + if (!c->x86_model_id[0]) { + const char *p; +--- a/arch/x86/kernel/paravirt.c ++++ b/arch/x86/kernel/paravirt.c +@@ -345,6 +345,9 @@ struct pv_cpu_ops pv_cpu_ops = { + .read_tscp = native_read_tscp, + .load_tr_desc = native_load_tr_desc, + .set_ldt = native_set_ldt, ++#ifdef CONFIG_X86_32 ++ .load_user_cs_desc = native_load_user_cs_desc, ++#endif /*CONFIG_X86_32*/ + .load_gdt = native_load_gdt, + .load_idt = native_load_idt, + .store_gdt = native_store_gdt, +--- a/arch/x86/kernel/process_32.c ++++ b/arch/x86/kernel/process_32.c +@@ -257,7 +257,10 @@ int copy_thread(unsigned long clone_flags, unsigned long sp, + void + start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp) + { ++ int cpu; ++ + set_user_gs(regs, 0); ++ + regs->fs = 0; + set_fs(USER_DS); + regs->ds = __USER_DS; +@@ -266,6 +269,11 @@ start_thread(struct pt_regs *regs, unsigned long new_ip, unsigned long new_sp) + regs->cs = __USER_CS; + regs->ip = new_ip; + regs->sp = new_sp; ++ ++ cpu = get_cpu(); ++ load_user_cs_desc(cpu, current->mm); ++ put_cpu(); ++ + /* + * Free the old FP and other extended state + */ +@@ -325,6 +333,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p) + if (preload_fpu) + prefetch(next->xstate); + ++ if (next_p->mm) ++ load_user_cs_desc(cpu, next_p->mm); ++ + /* + * Reload esp0. + */ +@@ -418,3 +429,40 @@ unsigned long get_wchan(struct task_struct *p) + return 0; + } + ++static void modify_cs(struct mm_struct *mm, unsigned long limit) ++{ ++ mm->context.exec_limit = limit; ++ set_user_cs(&mm->context.user_cs, limit); ++ if (mm == current->mm) { ++ int cpu; ++ ++ cpu = get_cpu(); ++ load_user_cs_desc(cpu, mm); ++ put_cpu(); ++ } ++} ++ ++void arch_add_exec_range(struct mm_struct *mm, unsigned long limit) ++{ ++ if (limit > mm->context.exec_limit) ++ modify_cs(mm, limit); ++} ++ ++void arch_remove_exec_range(struct mm_struct *mm, unsigned long old_end) ++{ ++ struct vm_area_struct *vma; ++ unsigned long limit = PAGE_SIZE; ++ ++ if (old_end == mm->context.exec_limit) { ++ for (vma = mm->mmap; vma; vma = vma->vm_next) ++ if ((vma->vm_flags & VM_EXEC) && (vma->vm_end > limit)) ++ limit = vma->vm_end; ++ modify_cs(mm, limit); ++ } ++} ++ ++void arch_flush_exec_range(struct mm_struct *mm) ++{ ++ mm->context.exec_limit = 0; ++ set_user_cs(&mm->context.user_cs, 0); ++} +--- a/arch/x86/kernel/traps.c ++++ b/arch/x86/kernel/traps.c +@@ -115,6 +115,76 @@ die_if_kernel(const char *str, struct pt_regs *regs, long err) + if (!user_mode_vm(regs)) + die(str, regs, err); + } ++ ++static inline int ++__compare_user_cs_desc(const struct desc_struct *desc1, ++ const struct desc_struct *desc2) ++{ ++ return ((desc1->limit0 != desc2->limit0) || ++ (desc1->limit != desc2->limit) || ++ (desc1->base0 != desc2->base0) || ++ (desc1->base1 != desc2->base1) || ++ (desc1->base2 != desc2->base2)); ++} ++ ++/* ++ * lazy-check for CS validity on exec-shield binaries: ++ * ++ * the original non-exec stack patch was written by ++ * Solar Designer . Thanks! ++ */ ++static int ++check_lazy_exec_limit(int cpu, struct pt_regs *regs, long error_code) ++{ ++ struct desc_struct *desc1, *desc2; ++ struct vm_area_struct *vma; ++ unsigned long limit; ++ ++ if (current->mm == NULL) ++ return 0; ++ ++ limit = -1UL; ++ if (current->mm->context.exec_limit != -1UL) { ++ limit = PAGE_SIZE; ++ spin_lock(¤t->mm->page_table_lock); ++ for (vma = current->mm->mmap; vma; vma = vma->vm_next) ++ if ((vma->vm_flags & VM_EXEC) && (vma->vm_end > limit)) ++ limit = vma->vm_end; ++ vma = get_gate_vma(current); ++ if (vma && (vma->vm_flags & VM_EXEC) && (vma->vm_end > limit)) ++ limit = vma->vm_end; ++ spin_unlock(¤t->mm->page_table_lock); ++ if (limit >= TASK_SIZE) ++ limit = -1UL; ++ current->mm->context.exec_limit = limit; ++ } ++ set_user_cs(¤t->mm->context.user_cs, limit); ++ ++ desc1 = ¤t->mm->context.user_cs; ++ desc2 = get_cpu_gdt_table(cpu) + GDT_ENTRY_DEFAULT_USER_CS; ++ ++ if (__compare_user_cs_desc(desc1, desc2)) { ++ /* ++ * The CS was not in sync - reload it and retry the ++ * instruction. If the instruction still faults then ++ * we won't hit this branch next time around. ++ */ ++ if (print_fatal_signals >= 2) { ++ printk(KERN_ERR "#GPF fixup (%ld[seg:%lx]) at %08lx, CPU#%d.\n", ++ error_code, error_code/8, regs->ip, ++ smp_processor_id()); ++ printk(KERN_ERR "exec_limit: %08lx, user_cs: %08x/%08x, CPU_cs: %08x/%08x.\n", ++ current->mm->context.exec_limit, ++ desc1->a, desc1->b, desc2->a, desc2->b); ++ } ++ ++ load_user_cs_desc(cpu, current->mm); ++ ++ return 1; ++ } ++ ++ return 0; ++} + #endif + + static void __kprobes +@@ -273,6 +343,29 @@ do_general_protection(struct pt_regs *regs, long error_code) + if (!user_mode(regs)) + goto gp_in_kernel; + ++#ifdef CONFIG_X86_32 ++{ ++ int cpu; ++ int ok; ++ ++ cpu = get_cpu(); ++ ok = check_lazy_exec_limit(cpu, regs, error_code); ++ put_cpu(); ++ ++ if (ok) ++ return; ++ ++ if (print_fatal_signals) { ++ printk(KERN_ERR "#GPF(%ld[seg:%lx]) at %08lx, CPU#%d.\n", ++ error_code, error_code/8, regs->ip, smp_processor_id()); ++ printk(KERN_ERR "exec_limit: %08lx, user_cs: %08x/%08x.\n", ++ current->mm->context.exec_limit, ++ current->mm->context.user_cs.a, ++ current->mm->context.user_cs.b); ++ } ++} ++#endif /*CONFIG_X86_32*/ ++ + tsk->thread.error_code = error_code; + tsk->thread.trap_no = 13; + +@@ -860,19 +953,37 @@ do_device_not_available(struct pt_regs *regs, long error_code) + } + + #ifdef CONFIG_X86_32 ++/* ++ * The fixup code for errors in iret jumps to here (iret_exc). It loses ++ * the original trap number and erorr code. The bogus trap 32 and error ++ * code 0 are what the vanilla kernel delivers via: ++ * DO_ERROR_INFO(32, SIGSEGV, "iret exception", iret_error, ILL_BADSTK, 0, 1) ++ * ++ * NOTE: Because of the final "1" in the macro we need to enable interrupts. ++ * ++ * In case of a general protection fault in the iret instruction, we ++ * need to check for a lazy CS update for exec-shield. ++ */ + dotraplinkage void do_iret_error(struct pt_regs *regs, long error_code) + { +- siginfo_t info; ++ int ok; ++ int cpu; ++ + local_irq_enable(); + +- info.si_signo = SIGILL; +- info.si_errno = 0; +- info.si_code = ILL_BADSTK; +- info.si_addr = NULL; +- if (notify_die(DIE_TRAP, "iret exception", +- regs, error_code, 32, SIGILL) == NOTIFY_STOP) +- return; +- do_trap(32, SIGILL, "iret exception", regs, error_code, &info); ++ cpu = get_cpu(); ++ ok = check_lazy_exec_limit(cpu, regs, error_code); ++ put_cpu(); ++ ++ if (!ok && notify_die(DIE_TRAP, "iret exception", regs, ++ error_code, 32, SIGSEGV) != NOTIFY_STOP) { ++ siginfo_t info; ++ info.si_signo = SIGSEGV; ++ info.si_errno = 0; ++ info.si_code = ILL_BADSTK; ++ info.si_addr = 0; ++ do_trap(32, SIGSEGV, "iret exception", regs, error_code, &info); ++ } + } + #endif + +--- a/arch/x86/mm/mmap.c ++++ b/arch/x86/mm/mmap.c +@@ -124,13 +124,16 @@ static unsigned long mmap_legacy_base(void) + */ + void arch_pick_mmap_layout(struct mm_struct *mm) + { +- if (mmap_is_legacy()) { ++ if (!(2 & exec_shield) && mmap_is_legacy()) { + mm->mmap_base = mmap_legacy_base(); + mm->get_unmapped_area = arch_get_unmapped_area; + mm->unmap_area = arch_unmap_area; + } else { + mm->mmap_base = mmap_base(); + mm->get_unmapped_area = arch_get_unmapped_area_topdown; ++ if (!(current->personality & READ_IMPLIES_EXEC) ++ && mmap_is_ia32()) ++ mm->get_unmapped_exec_area = arch_get_unmapped_exec_area; + mm->unmap_area = arch_unmap_area_topdown; + } + } +--- a/arch/x86/mm/setup_nx.c ++++ b/arch/x86/mm/setup_nx.c +@@ -1,3 +1,4 @@ ++#include + #include + #include + #include +@@ -23,6 +24,7 @@ static int __init noexec_setup(char *str) + disable_nx = 0; + } else if (!strncmp(str, "off", 3)) { + disable_nx = 1; ++ exec_shield = 0; + } + x86_configure_nx(); + return 0; +@@ -40,6 +42,10 @@ void __cpuinit x86_configure_nx(void) + void __init x86_report_nx(void) + { + if (!cpu_has_nx) { ++ if (exec_shield) ++ printk(KERN_INFO "Using x86 segment limits to approximate NX protection\n"); ++ else ++ + printk(KERN_NOTICE "Notice: NX (Execute Disable) protection " + "missing in CPU or disabled in BIOS!\n"); + } else { +--- a/arch/x86/mm/tlb.c ++++ b/arch/x86/mm/tlb.c +@@ -6,6 +6,7 @@ + #include + #include + ++#include + #include + #include + #include +@@ -131,6 +132,12 @@ void smp_invalidate_interrupt(struct pt_regs *regs) + union smp_flush_state *f; + + cpu = smp_processor_id(); ++ ++#ifdef CONFIG_X86_32 ++ if (current->active_mm) ++ load_user_cs_desc(cpu, current->active_mm); ++#endif ++ + /* + * orig_rax contains the negated interrupt vector. + * Use that to determine where the sender put the data. +--- a/arch/x86/vdso/vdso32-setup.c ++++ b/arch/x86/vdso/vdso32-setup.c +@@ -331,7 +331,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp) + if (compat) + addr = VDSO_HIGH_BASE; + else { +- addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0); ++ addr = get_unmapped_area_prot(NULL, 0, PAGE_SIZE, 0, 0, 1); + if (IS_ERR_VALUE(addr)) { + ret = addr; + goto up_fail; +--- a/arch/x86/xen/enlighten.c ++++ b/arch/x86/xen/enlighten.c +@@ -333,6 +333,24 @@ static void xen_set_ldt(const void *addr, unsigned entries) + xen_mc_issue(PARAVIRT_LAZY_CPU); + } + ++#ifdef CONFIG_X86_32 ++static void xen_load_user_cs_desc(int cpu, struct mm_struct *mm) ++{ ++ void *gdt; ++ xmaddr_t mgdt; ++ u64 descriptor; ++ struct desc_struct user_cs; ++ ++ gdt = &get_cpu_gdt_table(cpu)[GDT_ENTRY_DEFAULT_USER_CS]; ++ mgdt = virt_to_machine(gdt); ++ ++ user_cs = mm->context.user_cs; ++ descriptor = (u64) user_cs.a | ((u64) user_cs.b) << 32; ++ ++ HYPERVISOR_update_descriptor(mgdt.maddr, descriptor); ++} ++#endif /*CONFIG_X86_32*/ ++ + static void xen_load_gdt(const struct desc_ptr *dtr) + { + unsigned long va = dtr->address; +@@ -959,6 +977,9 @@ static const struct pv_cpu_ops xen_cpu_ops __initdata = { + + .load_tr_desc = paravirt_nop, + .set_ldt = xen_set_ldt, ++#ifdef CONFIG_X86_32 ++ .load_user_cs_desc = xen_load_user_cs_desc, ++#endif /*CONFIG_X86_32*/ + .load_gdt = xen_load_gdt, + .load_idt = xen_load_idt, + .load_tls = xen_load_tls, +--- a/fs/binfmt_elf.c ++++ b/fs/binfmt_elf.c +@@ -73,7 +73,7 @@ static struct linux_binfmt elf_format = { + .hasvdso = 1 + }; + +-#define BAD_ADDR(x) ((unsigned long)(x) >= TASK_SIZE) ++#define BAD_ADDR(x) IS_ERR_VALUE(x) + + static int set_brk(unsigned long start, unsigned long end) + { +@@ -721,6 +721,11 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs) + break; + } + ++ if (current->personality == PER_LINUX && (exec_shield & 2)) { ++ executable_stack = EXSTACK_DISABLE_X; ++ current->flags |= PF_RANDOMIZE; ++ } ++ + /* Some simple consistency checks for the interpreter */ + if (elf_interpreter) { + retval = -ELIBBAD; +@@ -740,6 +745,15 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs) + if (retval) + goto out_free_dentry; + ++#ifdef CONFIG_X86_32 ++ /* ++ * Turn off the CS limit completely if exec-shield disabled or ++ * NX active: ++ */ ++ if (!exec_shield || executable_stack != EXSTACK_DISABLE_X || (__supported_pte_mask & _PAGE_NX)) ++ arch_add_exec_range(current->mm, -1); ++#endif ++ + /* OK, This is the point of no return */ + current->flags &= ~PF_FORKNOEXEC; + current->mm->def_flags = def_flags; +@@ -747,7 +761,8 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs) + /* Do this immediately, since STACK_TOP as used in setup_arg_pages + may depend on the personality. */ + SET_PERSONALITY(loc->elf_ex); +- if (elf_read_implies_exec(loc->elf_ex, executable_stack)) ++ if (!(exec_shield & 2) && ++ elf_read_implies_exec(loc->elf_ex, executable_stack)) + current->personality |= READ_IMPLIES_EXEC; + + if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space) +@@ -912,7 +927,7 @@ static int load_elf_binary(struct linux_binprm *bprm, struct pt_regs *regs) + interpreter, + &interp_map_addr, + load_bias); +- if (!IS_ERR((void *)elf_entry)) { ++ if (!BAD_ADDR(elf_entry)) { + /* + * load_elf_interp() returns relocation + * adjustment +--- a/include/linux/mm.h ++++ b/include/linux/mm.h +@@ -1148,7 +1148,13 @@ extern int install_special_mapping(struct mm_struct *mm, + unsigned long addr, unsigned long len, + unsigned long flags, struct page **pages); + +-extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long); ++extern unsigned long get_unmapped_area_prot(struct file *, unsigned long, unsigned long, unsigned long, unsigned long, int); ++ ++static inline unsigned long get_unmapped_area(struct file *file, unsigned long addr, ++ unsigned long len, unsigned long pgoff, unsigned long flags) ++{ ++ return get_unmapped_area_prot(file, addr, len, pgoff, flags, 0); ++} + + extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr, + unsigned long len, unsigned long prot, +--- a/include/linux/mm_types.h ++++ b/include/linux/mm_types.h +@@ -209,6 +209,9 @@ struct mm_struct { + unsigned long (*get_unmapped_area) (struct file *filp, + unsigned long addr, unsigned long len, + unsigned long pgoff, unsigned long flags); ++ unsigned long (*get_unmapped_exec_area) (struct file *filp, ++ unsigned long addr, unsigned long len, ++ unsigned long pgoff, unsigned long flags); + void (*unmap_area) (struct mm_struct *mm, unsigned long addr); + #endif + unsigned long mmap_base; /* base of mmap area */ +--- a/include/linux/resource.h ++++ b/include/linux/resource.h +@@ -53,8 +53,11 @@ struct rlimit { + /* + * Limit the stack by to some sane default: root can always + * increase this limit if needed.. 8MB seems reasonable. ++ * ++ * (2MB more to cover randomization effects.) + */ +-#define _STK_LIM (8*1024*1024) ++#define _STK_LIM (10*1024*1024) ++#define EXEC_STACK_BIAS (2*1024*1024) + + /* + * GPG2 wants 64kB of mlocked memory, to make sure pass phrases +--- a/include/linux/sched.h ++++ b/include/linux/sched.h +@@ -102,6 +102,9 @@ struct fs_struct; + struct bts_context; + struct perf_event_context; + ++extern int exec_shield; ++extern int print_fatal_signals; ++ + /* + * List of flags we want to share for kernel threads, + * if only because they are not used by them anyway. +@@ -382,6 +385,10 @@ extern void arch_pick_mmap_layout(struct mm_struct *mm); + extern unsigned long + arch_get_unmapped_area(struct file *, unsigned long, unsigned long, + unsigned long, unsigned long); ++ ++extern unsigned long ++arch_get_unmapped_exec_area(struct file *, unsigned long, unsigned long, ++ unsigned long, unsigned long); + extern unsigned long + arch_get_unmapped_area_topdown(struct file *filp, unsigned long addr, + unsigned long len, unsigned long pgoff, +--- a/kernel/sysctl.c ++++ b/kernel/sysctl.c +@@ -87,6 +87,26 @@ extern int sysctl_nr_open_min, sysctl_nr_open_max; + #ifndef CONFIG_MMU + extern int sysctl_nr_trim_pages; + #endif ++ ++int exec_shield = (1<<0); ++/* exec_shield is a bitmask: ++ * 0: off; vdso at STACK_TOP, 1 page below TASK_SIZE ++ * (1<<0) 1: on [also on if !=0] ++ * (1<<1) 2: force noexecstack regardless of PT_GNU_STACK ++ * The old settings ++ * (1<<2) 4: vdso just below .text of main (unless too low) ++ * (1<<3) 8: vdso just below .text of PT_INTERP (unless too low) ++ * are ignored because the vdso is placed completely randomly ++ */ ++ ++static int __init setup_exec_shield(char *str) ++{ ++ get_option(&str, &exec_shield); ++ ++ return 1; ++} ++__setup("exec-shield=", setup_exec_shield); ++ + #ifdef CONFIG_RCU_TORTURE_TEST + extern int rcutorture_runnable; + #endif /* #ifdef CONFIG_RCU_TORTURE_TEST */ +@@ -410,6 +430,14 @@ static struct ctl_table kern_table[] = { + .mode = 0644, + .proc_handler = proc_dointvec, + }, ++ { ++ .procname = "exec-shield", ++ .data = &exec_shield, ++ .maxlen = sizeof(int), ++ .mode = 0644, ++ .proc_handler = &proc_dointvec, ++ }, ++ + #ifdef CONFIG_PROC_SYSCTL + { + .procname = "tainted", +--- b/mm/mmap.c ++++ linux-2.6.33.noarch/mm/mmap.c +@@ -28,6 +28,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -44,6 +45,18 @@ + #define arch_rebalance_pgtables(addr, len) (addr) + #endif + ++/* No sane architecture will #define these to anything else */ ++#ifndef arch_add_exec_range ++#define arch_add_exec_range(mm, limit) do { ; } while (0) ++#endif ++#ifndef arch_flush_exec_range ++#define arch_flush_exec_range(mm) do { ; } while (0) ++#endif ++#ifndef arch_remove_exec_range ++#define arch_remove_exec_range(mm, limit) do { ; } while (0) ++#endif ++ ++ + static void unmap_region(struct mm_struct *mm, + struct vm_area_struct *vma, struct vm_area_struct *prev, + unsigned long start, unsigned long end); +@@ -388,6 +401,8 @@ + __vma_link_list(struct mm_struct *mm, struct vm_area_struct *vma, + struct vm_area_struct *prev, struct rb_node *rb_parent) + { ++ if (vma->vm_flags & VM_EXEC) ++ arch_add_exec_range(mm, vma->vm_end); + if (prev) { + vma->vm_next = prev->vm_next; + prev->vm_next = vma; +@@ -490,6 +505,8 @@ + rb_erase(&vma->vm_rb, &mm->mm_rb); + if (mm->mmap_cache == vma) + mm->mmap_cache = prev; ++ if (vma->vm_flags & VM_EXEC) ++ arch_remove_exec_range(mm, vma->vm_end); + } + + /* +@@ -797,6 +814,8 @@ + } else /* cases 2, 5, 7 */ + vma_adjust(prev, prev->vm_start, + end, prev->vm_pgoff, NULL); ++ if (prev->vm_flags & VM_EXEC) ++ arch_add_exec_range(mm, prev->vm_end); + return prev; + } + +@@ -947,7 +966,8 @@ + /* Obtain the address to map to. we verify (or select) it and ensure + * that it represents a valid section of the address space. + */ +- addr = get_unmapped_area(file, addr, len, pgoff, flags); ++ addr = get_unmapped_area_prot(file, addr, len, pgoff, flags, ++ prot & PROT_EXEC); + if (addr & ~PAGE_MASK) + return addr; + +@@ -1479,8 +1499,8 @@ + } + + unsigned long +-get_unmapped_area(struct file *file, unsigned long addr, unsigned long len, +- unsigned long pgoff, unsigned long flags) ++get_unmapped_area_prot(struct file *file, unsigned long addr, unsigned long len, ++ unsigned long pgoff, unsigned long flags, int exec) + { + unsigned long (*get_area)(struct file *, unsigned long, + unsigned long, unsigned long, unsigned long); +@@ -1493,7 +1513,11 @@ + if (len > TASK_SIZE) + return -ENOMEM; + +- get_area = current->mm->get_unmapped_area; ++ if (exec && current->mm->get_unmapped_exec_area) ++ get_area = current->mm->get_unmapped_exec_area; ++ else ++ get_area = current->mm->get_unmapped_area; ++ + if (file && file->f_op && file->f_op->get_unmapped_area) + get_area = file->f_op->get_unmapped_area; + addr = get_area(file, addr, len, pgoff, flags); +@@ -1507,8 +1531,83 @@ + + return arch_rebalance_pgtables(addr, len); + } ++EXPORT_SYMBOL(get_unmapped_area_prot); ++ ++static bool should_randomize(void) ++{ ++ return (current->flags & PF_RANDOMIZE) && ++ !(current->personality & ADDR_NO_RANDOMIZE); ++} ++ ++#define SHLIB_BASE 0x00110000 ++ ++unsigned long ++arch_get_unmapped_exec_area(struct file *filp, unsigned long addr0, ++ unsigned long len0, unsigned long pgoff, unsigned long flags) ++{ ++ unsigned long addr = addr0, len = len0; ++ struct mm_struct *mm = current->mm; ++ struct vm_area_struct *vma; ++ unsigned long tmp; ++ ++ if (len > TASK_SIZE) ++ return -ENOMEM; ++ ++ if (flags & MAP_FIXED) ++ return addr; ++ ++ if (!addr) ++ addr = !should_randomize() ? SHLIB_BASE : ++ randomize_range(SHLIB_BASE, 0x01000000, len); ++ ++ if (addr) { ++ addr = PAGE_ALIGN(addr); ++ vma = find_vma(mm, addr); ++ if (TASK_SIZE - len >= addr && ++ (!vma || addr + len <= vma->vm_start)) ++ return addr; ++ } ++ ++ addr = SHLIB_BASE; ++ for (vma = find_vma(mm, addr); ; vma = vma->vm_next) { ++ /* At this point: (!vma || addr < vma->vm_end). */ ++ if (TASK_SIZE - len < addr) ++ return -ENOMEM; ++ ++ if (!vma || addr + len <= vma->vm_start) { ++ /* ++ * Must not let a PROT_EXEC mapping get into the ++ * brk area: ++ */ ++ if (addr + len > mm->brk) ++ goto failed; ++ ++ /* ++ * Up until the brk area we randomize addresses ++ * as much as possible: ++ */ ++ if (addr >= 0x01000000 && should_randomize()) { ++ tmp = randomize_range(0x01000000, ++ PAGE_ALIGN(max(mm->start_brk, ++ (unsigned long)0x08000000)), len); ++ vma = find_vma(mm, tmp); ++ if (TASK_SIZE - len >= tmp && ++ (!vma || tmp + len <= vma->vm_start)) ++ return tmp; ++ } ++ /* ++ * Ok, randomization didnt work out - return ++ * the result of the linear search: ++ */ ++ return addr; ++ } ++ addr = vma->vm_end; ++ } ++ ++failed: ++ return current->mm->get_unmapped_area(filp, addr0, len0, pgoff, flags); ++} + +-EXPORT_SYMBOL(get_unmapped_area); + + /* Look up the first VMA which satisfies addr < vm_end, NULL if none. */ + struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr) +@@ -1583,6 +1682,14 @@ + return prev ? prev->vm_next : vma; + } + ++static int over_stack_limit(unsigned long sz) ++{ ++ if (sz < EXEC_STACK_BIAS) ++ return 0; ++ return (sz - EXEC_STACK_BIAS) > ++ current->signal->rlim[RLIMIT_STACK].rlim_cur; ++} ++ + /* + * Verify that the stack growth is acceptable and + * update accounting. This is shared with both the +@@ -1599,7 +1706,7 @@ + return -ENOMEM; + + /* Stack limit test */ +- if (size > rlim[RLIMIT_STACK].rlim_cur) ++ if (over_stack_limit(size)) + return -ENOMEM; + + /* mlock limit tests */ +@@ -1906,10 +2013,14 @@ + if (new->vm_ops && new->vm_ops->open) + new->vm_ops->open(new); + +- if (new_below) ++ if (new_below) { ++ unsigned long old_end = vma->vm_end; ++ + vma_adjust(vma, addr, vma->vm_end, vma->vm_pgoff + + ((addr - new->vm_start) >> PAGE_SHIFT), new); +- else ++ if (vma->vm_flags & VM_EXEC) ++ arch_remove_exec_range(mm, old_end); ++ } else + vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new); + + return 0; +@@ -2176,6 +2287,7 @@ + + free_pgtables(tlb, vma, FIRST_USER_ADDRESS, 0); + tlb_finish_mmu(tlb, 0, end); ++ arch_flush_exec_range(mm); + + /* + * Walk the list again, actually closing and freeing it, +--- a/mm/mprotect.c ++++ b/mm/mprotect.c +@@ -26,9 +26,14 @@ + #include + #include + #include ++#include + #include + #include + ++#ifndef arch_remove_exec_range ++#define arch_remove_exec_range(mm, limit) do { ; } while (0) ++#endif ++ + #ifndef pgprot_modify + static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot) + { +@@ -139,7 +144,7 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev, + struct mm_struct *mm = vma->vm_mm; + unsigned long oldflags = vma->vm_flags; + long nrpages = (end - start) >> PAGE_SHIFT; +- unsigned long charged = 0; ++ unsigned long charged = 0, old_end = vma->vm_end; + pgoff_t pgoff; + int error; + int dirty_accountable = 0; +@@ -204,6 +209,9 @@ success: + dirty_accountable = 1; + } + ++ if (oldflags & VM_EXEC) ++ arch_remove_exec_range(current->mm, old_end); ++ + mmu_notifier_invalidate_range_start(mm, start, end); + if (is_vm_hugetlb_page(vma)) + hugetlb_change_protection(vma, start, end, vma->vm_page_prot); +--- a/mm/mremap.c ++++ b/mm/mremap.c +@@ -485,10 +485,10 @@ unsigned long do_mremap(unsigned long addr, + if (vma->vm_flags & VM_MAYSHARE) + map_flags |= MAP_SHARED; + +- new_addr = get_unmapped_area(vma->vm_file, 0, new_len, ++ new_addr = get_unmapped_area_prot(vma->vm_file, 0, new_len, + vma->vm_pgoff + + ((addr - vma->vm_start) >> PAGE_SHIFT), +- map_flags); ++ map_flags, vma->vm_flags & VM_EXEC); + if (new_addr & ~PAGE_MASK) { + ret = new_addr; + goto out; diff --git a/linux-2.6-firewire-git-pending.patch b/linux-2.6-firewire-git-pending.patch new file mode 100644 index 000000000..e05471f1b --- /dev/null +++ b/linux-2.6-firewire-git-pending.patch @@ -0,0 +1,4 @@ +# +# Patches under review and/or pending inclusion in the linux1394-git +# tree (and/or in by the time your read this), which we want... +# diff --git a/linux-2.6-firewire-git-update.patch b/linux-2.6-firewire-git-update.patch new file mode 100644 index 000000000..685808133 --- /dev/null +++ b/linux-2.6-firewire-git-update.patch @@ -0,0 +1,3682 @@ +linux1394-2.6.git tree vs. linus v2.6.29-rc3-git1 on 20090130 by jarod + +--- + firewire-git/drivers/firewire/fw-card.c | 68 - + firewire-git/drivers/firewire/fw-cdev.c | 1014 +++++++++++++++++-------- + firewire-git/drivers/firewire/fw-device.c | 43 - + firewire-git/drivers/firewire/fw-device.h | 7 + firewire-git/drivers/firewire/fw-iso.c | 225 ++++- + firewire-git/drivers/firewire/fw-ohci.c | 236 ++--- + firewire-git/drivers/firewire/fw-sbp2.c | 57 - + firewire-git/drivers/firewire/fw-topology.c | 28 + firewire-git/drivers/firewire/fw-topology.h | 19 + firewire-git/drivers/firewire/fw-transaction.c | 151 +-- + firewire-git/drivers/firewire/fw-transaction.h | 125 --- + include/linux/firewire-cdev.h | 170 +++- + 12 files changed, 1359 insertions(+), 784 deletions(-) + +diff -Naurp linux-2.6-git/drivers/firewire/fw-card.c firewire-git/drivers/firewire/fw-card.c +--- linux-2.6-git/drivers/firewire/fw-card.c 2009-01-30 13:39:02.989651512 -0500 ++++ firewire-git/drivers/firewire/fw-card.c 2009-01-30 13:35:51.859771884 -0500 +@@ -63,8 +63,7 @@ static int descriptor_count; + #define BIB_CMC ((1) << 30) + #define BIB_IMC ((1) << 31) + +-static u32 * +-generate_config_rom(struct fw_card *card, size_t *config_rom_length) ++static u32 *generate_config_rom(struct fw_card *card, size_t *config_rom_length) + { + struct fw_descriptor *desc; + static u32 config_rom[256]; +@@ -128,8 +127,7 @@ generate_config_rom(struct fw_card *card + return config_rom; + } + +-static void +-update_config_roms(void) ++static void update_config_roms(void) + { + struct fw_card *card; + u32 *config_rom; +@@ -141,8 +139,7 @@ update_config_roms(void) + } + } + +-int +-fw_core_add_descriptor(struct fw_descriptor *desc) ++int fw_core_add_descriptor(struct fw_descriptor *desc) + { + size_t i; + +@@ -171,8 +168,7 @@ fw_core_add_descriptor(struct fw_descrip + return 0; + } + +-void +-fw_core_remove_descriptor(struct fw_descriptor *desc) ++void fw_core_remove_descriptor(struct fw_descriptor *desc) + { + mutex_lock(&card_mutex); + +@@ -189,8 +185,7 @@ static const char gap_count_table[] = { + 63, 5, 7, 8, 10, 13, 16, 18, 21, 24, 26, 29, 32, 35, 37, 40 + }; + +-void +-fw_schedule_bm_work(struct fw_card *card, unsigned long delay) ++void fw_schedule_bm_work(struct fw_card *card, unsigned long delay) + { + int scheduled; + +@@ -200,8 +195,7 @@ fw_schedule_bm_work(struct fw_card *card + fw_card_put(card); + } + +-static void +-fw_card_bm_work(struct work_struct *work) ++static void fw_card_bm_work(struct work_struct *work) + { + struct fw_card *card = container_of(work, struct fw_card, work.work); + struct fw_device *root_device; +@@ -371,17 +365,16 @@ fw_card_bm_work(struct work_struct *work + fw_card_put(card); + } + +-static void +-flush_timer_callback(unsigned long data) ++static void flush_timer_callback(unsigned long data) + { + struct fw_card *card = (struct fw_card *)data; + + fw_flush_transactions(card); + } + +-void +-fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver, +- struct device *device) ++void fw_card_initialize(struct fw_card *card, ++ const struct fw_card_driver *driver, ++ struct device *device) + { + static atomic_t index = ATOMIC_INIT(-1); + +@@ -406,9 +399,8 @@ fw_card_initialize(struct fw_card *card, + } + EXPORT_SYMBOL(fw_card_initialize); + +-int +-fw_card_add(struct fw_card *card, +- u32 max_receive, u32 link_speed, u64 guid) ++int fw_card_add(struct fw_card *card, ++ u32 max_receive, u32 link_speed, u64 guid) + { + u32 *config_rom; + size_t length; +@@ -435,23 +427,20 @@ EXPORT_SYMBOL(fw_card_add); + * dummy driver just fails all IO. + */ + +-static int +-dummy_enable(struct fw_card *card, u32 *config_rom, size_t length) ++static int dummy_enable(struct fw_card *card, u32 *config_rom, size_t length) + { + BUG(); + return -1; + } + +-static int +-dummy_update_phy_reg(struct fw_card *card, int address, +- int clear_bits, int set_bits) ++static int dummy_update_phy_reg(struct fw_card *card, int address, ++ int clear_bits, int set_bits) + { + return -ENODEV; + } + +-static int +-dummy_set_config_rom(struct fw_card *card, +- u32 *config_rom, size_t length) ++static int dummy_set_config_rom(struct fw_card *card, ++ u32 *config_rom, size_t length) + { + /* + * We take the card out of card_list before setting the dummy +@@ -461,27 +450,23 @@ dummy_set_config_rom(struct fw_card *car + return -1; + } + +-static void +-dummy_send_request(struct fw_card *card, struct fw_packet *packet) ++static void dummy_send_request(struct fw_card *card, struct fw_packet *packet) + { + packet->callback(packet, card, -ENODEV); + } + +-static void +-dummy_send_response(struct fw_card *card, struct fw_packet *packet) ++static void dummy_send_response(struct fw_card *card, struct fw_packet *packet) + { + packet->callback(packet, card, -ENODEV); + } + +-static int +-dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet) ++static int dummy_cancel_packet(struct fw_card *card, struct fw_packet *packet) + { + return -ENOENT; + } + +-static int +-dummy_enable_phys_dma(struct fw_card *card, +- int node_id, int generation) ++static int dummy_enable_phys_dma(struct fw_card *card, ++ int node_id, int generation) + { + return -ENODEV; + } +@@ -496,16 +481,14 @@ static struct fw_card_driver dummy_drive + .enable_phys_dma = dummy_enable_phys_dma, + }; + +-void +-fw_card_release(struct kref *kref) ++void fw_card_release(struct kref *kref) + { + struct fw_card *card = container_of(kref, struct fw_card, kref); + + complete(&card->done); + } + +-void +-fw_core_remove_card(struct fw_card *card) ++void fw_core_remove_card(struct fw_card *card) + { + card->driver->update_phy_reg(card, 4, + PHY_LINK_ACTIVE | PHY_CONTENDER, 0); +@@ -529,8 +512,7 @@ fw_core_remove_card(struct fw_card *card + } + EXPORT_SYMBOL(fw_core_remove_card); + +-int +-fw_core_initiate_bus_reset(struct fw_card *card, int short_reset) ++int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset) + { + int reg = short_reset ? 5 : 1; + int bit = short_reset ? PHY_BUS_SHORT_RESET : PHY_BUS_RESET; +diff -Naurp linux-2.6-git/drivers/firewire/fw-cdev.c firewire-git/drivers/firewire/fw-cdev.c +--- linux-2.6-git/drivers/firewire/fw-cdev.c 2008-11-04 11:19:19.000000000 -0500 ++++ firewire-git/drivers/firewire/fw-cdev.c 2009-01-30 13:35:51.860646788 -0500 +@@ -18,87 +18,162 @@ + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +-#include +-#include +-#include +-#include ++#include ++#include + #include +-#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include + #include + #include ++#include + #include +-#include +-#include +-#include +-#include +-#include ++#include ++#include ++#include ++ + #include + #include +-#include "fw-transaction.h" +-#include "fw-topology.h" ++ + #include "fw-device.h" ++#include "fw-topology.h" ++#include "fw-transaction.h" ++ ++struct client { ++ u32 version; ++ struct fw_device *device; ++ ++ spinlock_t lock; ++ bool in_shutdown; ++ struct idr resource_idr; ++ struct list_head event_list; ++ wait_queue_head_t wait; ++ u64 bus_reset_closure; ++ ++ struct fw_iso_context *iso_context; ++ u64 iso_closure; ++ struct fw_iso_buffer buffer; ++ unsigned long vm_start; + +-struct client; +-struct client_resource { + struct list_head link; +- void (*release)(struct client *client, struct client_resource *r); +- u32 handle; ++ struct kref kref; ++}; ++ ++static inline void client_get(struct client *client) ++{ ++ kref_get(&client->kref); ++} ++ ++static void client_release(struct kref *kref) ++{ ++ struct client *client = container_of(kref, struct client, kref); ++ ++ fw_device_put(client->device); ++ kfree(client); ++} ++ ++static void client_put(struct client *client) ++{ ++ kref_put(&client->kref, client_release); ++} ++ ++struct client_resource; ++typedef void (*client_resource_release_fn_t)(struct client *, ++ struct client_resource *); ++struct client_resource { ++ client_resource_release_fn_t release; ++ int handle; ++}; ++ ++struct address_handler_resource { ++ struct client_resource resource; ++ struct fw_address_handler handler; ++ __u64 closure; ++ struct client *client; ++}; ++ ++struct outbound_transaction_resource { ++ struct client_resource resource; ++ struct fw_transaction transaction; ++}; ++ ++struct inbound_transaction_resource { ++ struct client_resource resource; ++ struct fw_request *request; ++ void *data; ++ size_t length; + }; + ++struct descriptor_resource { ++ struct client_resource resource; ++ struct fw_descriptor descriptor; ++ u32 data[0]; ++}; ++ ++struct iso_resource { ++ struct client_resource resource; ++ struct client *client; ++ /* Schedule work and access todo only with client->lock held. */ ++ struct delayed_work work; ++ enum {ISO_RES_ALLOC, ISO_RES_REALLOC, ISO_RES_DEALLOC, ++ ISO_RES_ALLOC_ONCE, ISO_RES_DEALLOC_ONCE,} todo; ++ int generation; ++ u64 channels; ++ s32 bandwidth; ++ struct iso_resource_event *e_alloc, *e_dealloc; ++}; ++ ++static void schedule_iso_resource(struct iso_resource *); ++static void release_iso_resource(struct client *, struct client_resource *); ++ + /* + * dequeue_event() just kfree()'s the event, so the event has to be +- * the first field in the struct. ++ * the first field in a struct XYZ_event. + */ +- + struct event { + struct { void *data; size_t size; } v[2]; + struct list_head link; + }; + +-struct bus_reset { ++struct bus_reset_event { + struct event event; + struct fw_cdev_event_bus_reset reset; + }; + +-struct response { ++struct outbound_transaction_event { + struct event event; +- struct fw_transaction transaction; + struct client *client; +- struct client_resource resource; ++ struct outbound_transaction_resource r; + struct fw_cdev_event_response response; + }; + +-struct iso_interrupt { ++struct inbound_transaction_event { + struct event event; +- struct fw_cdev_event_iso_interrupt interrupt; ++ struct fw_cdev_event_request request; + }; + +-struct client { +- u32 version; +- struct fw_device *device; +- spinlock_t lock; +- u32 resource_handle; +- struct list_head resource_list; +- struct list_head event_list; +- wait_queue_head_t wait; +- u64 bus_reset_closure; +- +- struct fw_iso_context *iso_context; +- u64 iso_closure; +- struct fw_iso_buffer buffer; +- unsigned long vm_start; ++struct iso_interrupt_event { ++ struct event event; ++ struct fw_cdev_event_iso_interrupt interrupt; ++}; + +- struct list_head link; ++struct iso_resource_event { ++ struct event event; ++ struct fw_cdev_event_iso_resource resource; + }; + +-static inline void __user * +-u64_to_uptr(__u64 value) ++static inline void __user *u64_to_uptr(__u64 value) + { + return (void __user *)(unsigned long)value; + } + +-static inline __u64 +-uptr_to_u64(void __user *ptr) ++static inline __u64 uptr_to_u64(void __user *ptr) + { + return (__u64)(unsigned long)ptr; + } +@@ -107,7 +182,6 @@ static int fw_device_op_open(struct inod + { + struct fw_device *device; + struct client *client; +- unsigned long flags; + + device = fw_device_get_by_devt(inode->i_rdev); + if (device == NULL) +@@ -125,16 +199,17 @@ static int fw_device_op_open(struct inod + } + + client->device = device; +- INIT_LIST_HEAD(&client->event_list); +- INIT_LIST_HEAD(&client->resource_list); + spin_lock_init(&client->lock); ++ idr_init(&client->resource_idr); ++ INIT_LIST_HEAD(&client->event_list); + init_waitqueue_head(&client->wait); ++ kref_init(&client->kref); + + file->private_data = client; + +- spin_lock_irqsave(&device->card->lock, flags); ++ mutex_lock(&device->client_list_mutex); + list_add_tail(&client->link, &device->client_list); +- spin_unlock_irqrestore(&device->card->lock, flags); ++ mutex_unlock(&device->client_list_mutex); + + return 0; + } +@@ -150,68 +225,69 @@ static void queue_event(struct client *c + event->v[1].size = size1; + + spin_lock_irqsave(&client->lock, flags); +- list_add_tail(&event->link, &client->event_list); ++ if (client->in_shutdown) ++ kfree(event); ++ else ++ list_add_tail(&event->link, &client->event_list); + spin_unlock_irqrestore(&client->lock, flags); + + wake_up_interruptible(&client->wait); + } + +-static int +-dequeue_event(struct client *client, char __user *buffer, size_t count) ++static int dequeue_event(struct client *client, ++ char __user *buffer, size_t count) + { +- unsigned long flags; + struct event *event; + size_t size, total; +- int i, retval; ++ int i, ret; + +- retval = wait_event_interruptible(client->wait, +- !list_empty(&client->event_list) || +- fw_device_is_shutdown(client->device)); +- if (retval < 0) +- return retval; ++ ret = wait_event_interruptible(client->wait, ++ !list_empty(&client->event_list) || ++ fw_device_is_shutdown(client->device)); ++ if (ret < 0) ++ return ret; + + if (list_empty(&client->event_list) && + fw_device_is_shutdown(client->device)) + return -ENODEV; + +- spin_lock_irqsave(&client->lock, flags); +- event = container_of(client->event_list.next, struct event, link); ++ spin_lock_irq(&client->lock); ++ event = list_first_entry(&client->event_list, struct event, link); + list_del(&event->link); +- spin_unlock_irqrestore(&client->lock, flags); ++ spin_unlock_irq(&client->lock); + + total = 0; + for (i = 0; i < ARRAY_SIZE(event->v) && total < count; i++) { + size = min(event->v[i].size, count - total); + if (copy_to_user(buffer + total, event->v[i].data, size)) { +- retval = -EFAULT; ++ ret = -EFAULT; + goto out; + } + total += size; + } +- retval = total; ++ ret = total; + + out: + kfree(event); + +- return retval; ++ return ret; + } + +-static ssize_t +-fw_device_op_read(struct file *file, +- char __user *buffer, size_t count, loff_t *offset) ++static ssize_t fw_device_op_read(struct file *file, char __user *buffer, ++ size_t count, loff_t *offset) + { + struct client *client = file->private_data; + + return dequeue_event(client, buffer, count); + } + +-/* caller must hold card->lock so that node pointers can be dereferenced here */ +-static void +-fill_bus_reset_event(struct fw_cdev_event_bus_reset *event, +- struct client *client) ++static void fill_bus_reset_event(struct fw_cdev_event_bus_reset *event, ++ struct client *client) + { + struct fw_card *card = client->device->card; + ++ spin_lock_irq(&card->lock); ++ + event->closure = client->bus_reset_closure; + event->type = FW_CDEV_EVENT_BUS_RESET; + event->generation = client->device->generation; +@@ -220,39 +296,49 @@ fill_bus_reset_event(struct fw_cdev_even + event->bm_node_id = 0; /* FIXME: We don't track the BM. */ + event->irm_node_id = card->irm_node->node_id; + event->root_node_id = card->root_node->node_id; ++ ++ spin_unlock_irq(&card->lock); + } + +-static void +-for_each_client(struct fw_device *device, +- void (*callback)(struct client *client)) ++static void for_each_client(struct fw_device *device, ++ void (*callback)(struct client *client)) + { +- struct fw_card *card = device->card; + struct client *c; +- unsigned long flags; +- +- spin_lock_irqsave(&card->lock, flags); + ++ mutex_lock(&device->client_list_mutex); + list_for_each_entry(c, &device->client_list, link) + callback(c); ++ mutex_unlock(&device->client_list_mutex); ++} ++ ++static int schedule_reallocations(int id, void *p, void *data) ++{ ++ struct client_resource *r = p; + +- spin_unlock_irqrestore(&card->lock, flags); ++ if (r->release == release_iso_resource) ++ schedule_iso_resource(container_of(r, ++ struct iso_resource, resource)); ++ return 0; + } + +-static void +-queue_bus_reset_event(struct client *client) ++static void queue_bus_reset_event(struct client *client) + { +- struct bus_reset *bus_reset; ++ struct bus_reset_event *e; + +- bus_reset = kzalloc(sizeof(*bus_reset), GFP_ATOMIC); +- if (bus_reset == NULL) { ++ e = kzalloc(sizeof(*e), GFP_KERNEL); ++ if (e == NULL) { + fw_notify("Out of memory when allocating bus reset event\n"); + return; + } + +- fill_bus_reset_event(&bus_reset->reset, client); ++ fill_bus_reset_event(&e->reset, client); ++ ++ queue_event(client, &e->event, ++ &e->reset, sizeof(e->reset), NULL, 0); + +- queue_event(client, &bus_reset->event, +- &bus_reset->reset, sizeof(bus_reset->reset), NULL, 0); ++ spin_lock_irq(&client->lock); ++ idr_for_each(&client->resource_idr, schedule_reallocations, client); ++ spin_unlock_irq(&client->lock); + } + + void fw_device_cdev_update(struct fw_device *device) +@@ -274,11 +360,11 @@ static int ioctl_get_info(struct client + { + struct fw_cdev_get_info *get_info = buffer; + struct fw_cdev_event_bus_reset bus_reset; +- struct fw_card *card = client->device->card; + unsigned long ret = 0; + + client->version = get_info->version; + get_info->version = FW_CDEV_VERSION; ++ get_info->card = client->device->card->index; + + down_read(&fw_device_rwsem); + +@@ -300,49 +386,61 @@ static int ioctl_get_info(struct client + client->bus_reset_closure = get_info->bus_reset_closure; + if (get_info->bus_reset != 0) { + void __user *uptr = u64_to_uptr(get_info->bus_reset); +- unsigned long flags; + +- spin_lock_irqsave(&card->lock, flags); + fill_bus_reset_event(&bus_reset, client); +- spin_unlock_irqrestore(&card->lock, flags); +- + if (copy_to_user(uptr, &bus_reset, sizeof(bus_reset))) + return -EFAULT; + } + +- get_info->card = card->index; +- + return 0; + } + +-static void +-add_client_resource(struct client *client, struct client_resource *resource) ++static int add_client_resource(struct client *client, ++ struct client_resource *resource, gfp_t gfp_mask) + { + unsigned long flags; ++ int ret; ++ ++ retry: ++ if (idr_pre_get(&client->resource_idr, gfp_mask | __GFP_ZERO) == 0) ++ return -ENOMEM; + + spin_lock_irqsave(&client->lock, flags); +- list_add_tail(&resource->link, &client->resource_list); +- resource->handle = client->resource_handle++; ++ if (client->in_shutdown) ++ ret = -ECANCELED; ++ else ++ ret = idr_get_new(&client->resource_idr, resource, ++ &resource->handle); ++ if (ret >= 0) { ++ client_get(client); ++ if (resource->release == release_iso_resource) ++ schedule_iso_resource(container_of(resource, ++ struct iso_resource, resource)); ++ } + spin_unlock_irqrestore(&client->lock, flags); ++ ++ if (ret == -EAGAIN) ++ goto retry; ++ ++ return ret < 0 ? ret : 0; + } + +-static int +-release_client_resource(struct client *client, u32 handle, +- struct client_resource **resource) ++static int release_client_resource(struct client *client, u32 handle, ++ client_resource_release_fn_t release, ++ struct client_resource **resource) + { + struct client_resource *r; +- unsigned long flags; + +- spin_lock_irqsave(&client->lock, flags); +- list_for_each_entry(r, &client->resource_list, link) { +- if (r->handle == handle) { +- list_del(&r->link); +- break; +- } +- } +- spin_unlock_irqrestore(&client->lock, flags); ++ spin_lock_irq(&client->lock); ++ if (client->in_shutdown) ++ r = NULL; ++ else ++ r = idr_find(&client->resource_idr, handle); ++ if (r && r->release == release) ++ idr_remove(&client->resource_idr, handle); ++ spin_unlock_irq(&client->lock); + +- if (&r->link == &client->resource_list) ++ if (!(r && r->release == release)) + return -EINVAL; + + if (resource) +@@ -350,203 +448,242 @@ release_client_resource(struct client *c + else + r->release(client, r); + ++ client_put(client); ++ + return 0; + } + +-static void +-release_transaction(struct client *client, struct client_resource *resource) ++static void release_transaction(struct client *client, ++ struct client_resource *resource) + { +- struct response *response = +- container_of(resource, struct response, resource); ++ struct outbound_transaction_resource *r = container_of(resource, ++ struct outbound_transaction_resource, resource); + +- fw_cancel_transaction(client->device->card, &response->transaction); ++ fw_cancel_transaction(client->device->card, &r->transaction); + } + +-static void +-complete_transaction(struct fw_card *card, int rcode, +- void *payload, size_t length, void *data) ++static void complete_transaction(struct fw_card *card, int rcode, ++ void *payload, size_t length, void *data) + { +- struct response *response = data; +- struct client *client = response->client; ++ struct outbound_transaction_event *e = data; ++ struct fw_cdev_event_response *rsp = &e->response; ++ struct client *client = e->client; + unsigned long flags; +- struct fw_cdev_event_response *r = &response->response; + +- if (length < r->length) +- r->length = length; ++ if (length < rsp->length) ++ rsp->length = length; + if (rcode == RCODE_COMPLETE) +- memcpy(r->data, payload, r->length); ++ memcpy(rsp->data, payload, rsp->length); + + spin_lock_irqsave(&client->lock, flags); +- list_del(&response->resource.link); ++ /* ++ * 1. If called while in shutdown, the idr tree must be left untouched. ++ * The idr handle will be removed and the client reference will be ++ * dropped later. ++ * 2. If the call chain was release_client_resource -> ++ * release_transaction -> complete_transaction (instead of a normal ++ * conclusion of the transaction), i.e. if this resource was already ++ * unregistered from the idr, the client reference will be dropped ++ * by release_client_resource and we must not drop it here. ++ */ ++ if (!client->in_shutdown && ++ idr_find(&client->resource_idr, e->r.resource.handle)) { ++ idr_remove(&client->resource_idr, e->r.resource.handle); ++ /* Drop the idr's reference */ ++ client_put(client); ++ } + spin_unlock_irqrestore(&client->lock, flags); + +- r->type = FW_CDEV_EVENT_RESPONSE; +- r->rcode = rcode; ++ rsp->type = FW_CDEV_EVENT_RESPONSE; ++ rsp->rcode = rcode; + + /* +- * In the case that sizeof(*r) doesn't align with the position of the ++ * In the case that sizeof(*rsp) doesn't align with the position of the + * data, and the read is short, preserve an extra copy of the data + * to stay compatible with a pre-2.6.27 bug. Since the bug is harmless + * for short reads and some apps depended on it, this is both safe + * and prudent for compatibility. + */ +- if (r->length <= sizeof(*r) - offsetof(typeof(*r), data)) +- queue_event(client, &response->event, r, sizeof(*r), +- r->data, r->length); ++ if (rsp->length <= sizeof(*rsp) - offsetof(typeof(*rsp), data)) ++ queue_event(client, &e->event, rsp, sizeof(*rsp), ++ rsp->data, rsp->length); + else +- queue_event(client, &response->event, r, sizeof(*r) + r->length, ++ queue_event(client, &e->event, rsp, sizeof(*rsp) + rsp->length, + NULL, 0); ++ ++ /* Drop the transaction callback's reference */ ++ client_put(client); + } + +-static int ioctl_send_request(struct client *client, void *buffer) ++static int init_request(struct client *client, ++ struct fw_cdev_send_request *request, ++ int destination_id, int speed) + { +- struct fw_device *device = client->device; +- struct fw_cdev_send_request *request = buffer; +- struct response *response; ++ struct outbound_transaction_event *e; ++ int ret; + +- /* What is the biggest size we'll accept, really? */ +- if (request->length > 4096) +- return -EINVAL; ++ if (request->length > 4096 || request->length > 512 << speed) ++ return -EIO; + +- response = kmalloc(sizeof(*response) + request->length, GFP_KERNEL); +- if (response == NULL) ++ e = kmalloc(sizeof(*e) + request->length, GFP_KERNEL); ++ if (e == NULL) + return -ENOMEM; + +- response->client = client; +- response->response.length = request->length; +- response->response.closure = request->closure; ++ e->client = client; ++ e->response.length = request->length; ++ e->response.closure = request->closure; + + if (request->data && +- copy_from_user(response->response.data, ++ copy_from_user(e->response.data, + u64_to_uptr(request->data), request->length)) { +- kfree(response); +- return -EFAULT; ++ ret = -EFAULT; ++ goto failed; + } + +- response->resource.release = release_transaction; +- add_client_resource(client, &response->resource); +- +- fw_send_request(device->card, &response->transaction, +- request->tcode & 0x1f, +- device->node->node_id, +- request->generation, +- device->max_speed, +- request->offset, +- response->response.data, request->length, +- complete_transaction, response); ++ e->r.resource.release = release_transaction; ++ ret = add_client_resource(client, &e->r.resource, GFP_KERNEL); ++ if (ret < 0) ++ goto failed; ++ ++ /* Get a reference for the transaction callback */ ++ client_get(client); ++ ++ fw_send_request(client->device->card, &e->r.transaction, ++ request->tcode & 0x1f, destination_id, ++ request->generation, speed, request->offset, ++ e->response.data, request->length, ++ complete_transaction, e); + + if (request->data) + return sizeof(request) + request->length; + else + return sizeof(request); ++ failed: ++ kfree(e); ++ ++ return ret; + } + +-struct address_handler { +- struct fw_address_handler handler; +- __u64 closure; +- struct client *client; +- struct client_resource resource; +-}; ++static int ioctl_send_request(struct client *client, void *buffer) ++{ ++ struct fw_cdev_send_request *request = buffer; + +-struct request { +- struct fw_request *request; +- void *data; +- size_t length; +- struct client_resource resource; +-}; ++ switch (request->tcode) { ++ case TCODE_WRITE_QUADLET_REQUEST: ++ case TCODE_WRITE_BLOCK_REQUEST: ++ case TCODE_READ_QUADLET_REQUEST: ++ case TCODE_READ_BLOCK_REQUEST: ++ case TCODE_LOCK_MASK_SWAP: ++ case TCODE_LOCK_COMPARE_SWAP: ++ case TCODE_LOCK_FETCH_ADD: ++ case TCODE_LOCK_LITTLE_ADD: ++ case TCODE_LOCK_BOUNDED_ADD: ++ case TCODE_LOCK_WRAP_ADD: ++ case TCODE_LOCK_VENDOR_DEPENDENT: ++ break; ++ default: ++ return -EINVAL; ++ } + +-struct request_event { +- struct event event; +- struct fw_cdev_event_request request; +-}; ++ return init_request(client, request, client->device->node->node_id, ++ client->device->max_speed); ++} + +-static void +-release_request(struct client *client, struct client_resource *resource) ++static void release_request(struct client *client, ++ struct client_resource *resource) + { +- struct request *request = +- container_of(resource, struct request, resource); ++ struct inbound_transaction_resource *r = container_of(resource, ++ struct inbound_transaction_resource, resource); + +- fw_send_response(client->device->card, request->request, ++ fw_send_response(client->device->card, r->request, + RCODE_CONFLICT_ERROR); +- kfree(request); ++ kfree(r); + } + +-static void +-handle_request(struct fw_card *card, struct fw_request *r, +- int tcode, int destination, int source, +- int generation, int speed, +- unsigned long long offset, +- void *payload, size_t length, void *callback_data) +-{ +- struct address_handler *handler = callback_data; +- struct request *request; +- struct request_event *e; +- struct client *client = handler->client; ++static void handle_request(struct fw_card *card, struct fw_request *request, ++ int tcode, int destination, int source, ++ int generation, int speed, ++ unsigned long long offset, ++ void *payload, size_t length, void *callback_data) ++{ ++ struct address_handler_resource *handler = callback_data; ++ struct inbound_transaction_resource *r; ++ struct inbound_transaction_event *e; ++ int ret; + +- request = kmalloc(sizeof(*request), GFP_ATOMIC); ++ r = kmalloc(sizeof(*r), GFP_ATOMIC); + e = kmalloc(sizeof(*e), GFP_ATOMIC); +- if (request == NULL || e == NULL) { +- kfree(request); +- kfree(e); +- fw_send_response(card, r, RCODE_CONFLICT_ERROR); +- return; +- } +- +- request->request = r; +- request->data = payload; +- request->length = length; ++ if (r == NULL || e == NULL) ++ goto failed; + +- request->resource.release = release_request; +- add_client_resource(client, &request->resource); ++ r->request = request; ++ r->data = payload; ++ r->length = length; ++ ++ r->resource.release = release_request; ++ ret = add_client_resource(handler->client, &r->resource, GFP_ATOMIC); ++ if (ret < 0) ++ goto failed; + + e->request.type = FW_CDEV_EVENT_REQUEST; + e->request.tcode = tcode; + e->request.offset = offset; + e->request.length = length; +- e->request.handle = request->resource.handle; ++ e->request.handle = r->resource.handle; + e->request.closure = handler->closure; + +- queue_event(client, &e->event, ++ queue_event(handler->client, &e->event, + &e->request, sizeof(e->request), payload, length); ++ return; ++ ++ failed: ++ kfree(r); ++ kfree(e); ++ fw_send_response(card, request, RCODE_CONFLICT_ERROR); + } + +-static void +-release_address_handler(struct client *client, +- struct client_resource *resource) ++static void release_address_handler(struct client *client, ++ struct client_resource *resource) + { +- struct address_handler *handler = +- container_of(resource, struct address_handler, resource); ++ struct address_handler_resource *r = ++ container_of(resource, struct address_handler_resource, resource); + +- fw_core_remove_address_handler(&handler->handler); +- kfree(handler); ++ fw_core_remove_address_handler(&r->handler); ++ kfree(r); + } + + static int ioctl_allocate(struct client *client, void *buffer) + { + struct fw_cdev_allocate *request = buffer; +- struct address_handler *handler; ++ struct address_handler_resource *r; + struct fw_address_region region; ++ int ret; + +- handler = kmalloc(sizeof(*handler), GFP_KERNEL); +- if (handler == NULL) ++ r = kmalloc(sizeof(*r), GFP_KERNEL); ++ if (r == NULL) + return -ENOMEM; + + region.start = request->offset; + region.end = request->offset + request->length; +- handler->handler.length = request->length; +- handler->handler.address_callback = handle_request; +- handler->handler.callback_data = handler; +- handler->closure = request->closure; +- handler->client = client; +- +- if (fw_core_add_address_handler(&handler->handler, ®ion) < 0) { +- kfree(handler); +- return -EBUSY; ++ r->handler.length = request->length; ++ r->handler.address_callback = handle_request; ++ r->handler.callback_data = r; ++ r->closure = request->closure; ++ r->client = client; ++ ++ ret = fw_core_add_address_handler(&r->handler, ®ion); ++ if (ret < 0) { ++ kfree(r); ++ return ret; + } + +- handler->resource.release = release_address_handler; +- add_client_resource(client, &handler->resource); +- request->handle = handler->resource.handle; ++ r->resource.release = release_address_handler; ++ ret = add_client_resource(client, &r->resource, GFP_KERNEL); ++ if (ret < 0) { ++ release_address_handler(client, &r->resource); ++ return ret; ++ } ++ request->handle = r->resource.handle; + + return 0; + } +@@ -555,18 +692,22 @@ static int ioctl_deallocate(struct clien + { + struct fw_cdev_deallocate *request = buffer; + +- return release_client_resource(client, request->handle, NULL); ++ return release_client_resource(client, request->handle, ++ release_address_handler, NULL); + } + + static int ioctl_send_response(struct client *client, void *buffer) + { + struct fw_cdev_send_response *request = buffer; + struct client_resource *resource; +- struct request *r; ++ struct inbound_transaction_resource *r; + +- if (release_client_resource(client, request->handle, &resource) < 0) ++ if (release_client_resource(client, request->handle, ++ release_request, &resource) < 0) + return -EINVAL; +- r = container_of(resource, struct request, resource); ++ ++ r = container_of(resource, struct inbound_transaction_resource, ++ resource); + if (request->length < r->length) + r->length = request->length; + if (copy_from_user(r->data, u64_to_uptr(request->data), r->length)) +@@ -588,85 +729,84 @@ static int ioctl_initiate_bus_reset(stru + return fw_core_initiate_bus_reset(client->device->card, short_reset); + } + +-struct descriptor { +- struct fw_descriptor d; +- struct client_resource resource; +- u32 data[0]; +-}; +- + static void release_descriptor(struct client *client, + struct client_resource *resource) + { +- struct descriptor *descriptor = +- container_of(resource, struct descriptor, resource); ++ struct descriptor_resource *r = ++ container_of(resource, struct descriptor_resource, resource); + +- fw_core_remove_descriptor(&descriptor->d); +- kfree(descriptor); ++ fw_core_remove_descriptor(&r->descriptor); ++ kfree(r); + } + + static int ioctl_add_descriptor(struct client *client, void *buffer) + { + struct fw_cdev_add_descriptor *request = buffer; +- struct descriptor *descriptor; +- int retval; ++ struct descriptor_resource *r; ++ int ret; + + if (request->length > 256) + return -EINVAL; + +- descriptor = +- kmalloc(sizeof(*descriptor) + request->length * 4, GFP_KERNEL); +- if (descriptor == NULL) ++ r = kmalloc(sizeof(*r) + request->length * 4, GFP_KERNEL); ++ if (r == NULL) + return -ENOMEM; + +- if (copy_from_user(descriptor->data, ++ if (copy_from_user(r->data, + u64_to_uptr(request->data), request->length * 4)) { +- kfree(descriptor); +- return -EFAULT; ++ ret = -EFAULT; ++ goto failed; + } + +- descriptor->d.length = request->length; +- descriptor->d.immediate = request->immediate; +- descriptor->d.key = request->key; +- descriptor->d.data = descriptor->data; +- +- retval = fw_core_add_descriptor(&descriptor->d); +- if (retval < 0) { +- kfree(descriptor); +- return retval; ++ r->descriptor.length = request->length; ++ r->descriptor.immediate = request->immediate; ++ r->descriptor.key = request->key; ++ r->descriptor.data = r->data; ++ ++ ret = fw_core_add_descriptor(&r->descriptor); ++ if (ret < 0) ++ goto failed; ++ ++ r->resource.release = release_descriptor; ++ ret = add_client_resource(client, &r->resource, GFP_KERNEL); ++ if (ret < 0) { ++ fw_core_remove_descriptor(&r->descriptor); ++ goto failed; + } +- +- descriptor->resource.release = release_descriptor; +- add_client_resource(client, &descriptor->resource); +- request->handle = descriptor->resource.handle; ++ request->handle = r->resource.handle; + + return 0; ++ failed: ++ kfree(r); ++ ++ return ret; + } + + static int ioctl_remove_descriptor(struct client *client, void *buffer) + { + struct fw_cdev_remove_descriptor *request = buffer; + +- return release_client_resource(client, request->handle, NULL); ++ return release_client_resource(client, request->handle, ++ release_descriptor, NULL); + } + +-static void +-iso_callback(struct fw_iso_context *context, u32 cycle, +- size_t header_length, void *header, void *data) ++static void iso_callback(struct fw_iso_context *context, u32 cycle, ++ size_t header_length, void *header, void *data) + { + struct client *client = data; +- struct iso_interrupt *irq; ++ struct iso_interrupt_event *e; + +- irq = kzalloc(sizeof(*irq) + header_length, GFP_ATOMIC); +- if (irq == NULL) ++ e = kzalloc(sizeof(*e) + header_length, GFP_ATOMIC); ++ if (e == NULL) + return; + +- irq->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT; +- irq->interrupt.closure = client->iso_closure; +- irq->interrupt.cycle = cycle; +- irq->interrupt.header_length = header_length; +- memcpy(irq->interrupt.header, header, header_length); +- queue_event(client, &irq->event, &irq->interrupt, +- sizeof(irq->interrupt) + header_length, NULL, 0); ++ e->interrupt.type = FW_CDEV_EVENT_ISO_INTERRUPT; ++ e->interrupt.closure = client->iso_closure; ++ e->interrupt.cycle = cycle; ++ e->interrupt.header_length = header_length; ++ memcpy(e->interrupt.header, header, header_length); ++ queue_event(client, &e->event, &e->interrupt, ++ sizeof(e->interrupt) + header_length, NULL, 0); + } + + static int ioctl_create_iso_context(struct client *client, void *buffer) +@@ -871,6 +1011,237 @@ static int ioctl_get_cycle_timer(struct + return 0; + } + ++static void iso_resource_work(struct work_struct *work) ++{ ++ struct iso_resource_event *e; ++ struct iso_resource *r = ++ container_of(work, struct iso_resource, work.work); ++ struct client *client = r->client; ++ int generation, channel, bandwidth, todo; ++ bool skip, free, success; ++ ++ spin_lock_irq(&client->lock); ++ generation = client->device->generation; ++ todo = r->todo; ++ /* Allow 1000ms grace period for other reallocations. */ ++ if (todo == ISO_RES_ALLOC && ++ time_is_after_jiffies(client->device->card->reset_jiffies + HZ)) { ++ if (schedule_delayed_work(&r->work, DIV_ROUND_UP(HZ, 3))) ++ client_get(client); ++ skip = true; ++ } else { ++ /* We could be called twice within the same generation. */ ++ skip = todo == ISO_RES_REALLOC && ++ r->generation == generation; ++ } ++ free = todo == ISO_RES_DEALLOC || ++ todo == ISO_RES_ALLOC_ONCE || ++ todo == ISO_RES_DEALLOC_ONCE; ++ r->generation = generation; ++ spin_unlock_irq(&client->lock); ++ ++ if (skip) ++ goto out; ++ ++ bandwidth = r->bandwidth; ++ ++ fw_iso_resource_manage(client->device->card, generation, ++ r->channels, &channel, &bandwidth, ++ todo == ISO_RES_ALLOC || ++ todo == ISO_RES_REALLOC || ++ todo == ISO_RES_ALLOC_ONCE); ++ /* ++ * Is this generation outdated already? As long as this resource sticks ++ * in the idr, it will be scheduled again for a newer generation or at ++ * shutdown. ++ */ ++ if (channel == -EAGAIN && ++ (todo == ISO_RES_ALLOC || todo == ISO_RES_REALLOC)) ++ goto out; ++ ++ success = channel >= 0 || bandwidth > 0; ++ ++ spin_lock_irq(&client->lock); ++ /* ++ * Transit from allocation to reallocation, except if the client ++ * requested deallocation in the meantime. ++ */ ++ if (r->todo == ISO_RES_ALLOC) ++ r->todo = ISO_RES_REALLOC; ++ /* ++ * Allocation or reallocation failure? Pull this resource out of the ++ * idr and prepare for deletion, unless the client is shutting down. ++ */ ++ if (r->todo == ISO_RES_REALLOC && !success && ++ !client->in_shutdown && ++ idr_find(&client->resource_idr, r->resource.handle)) { ++ idr_remove(&client->resource_idr, r->resource.handle); ++ client_put(client); ++ free = true; ++ } ++ spin_unlock_irq(&client->lock); ++ ++ if (todo == ISO_RES_ALLOC && channel >= 0) ++ r->channels = 1ULL << channel; ++ ++ if (todo == ISO_RES_REALLOC && success) ++ goto out; ++ ++ if (todo == ISO_RES_ALLOC || todo == ISO_RES_ALLOC_ONCE) { ++ e = r->e_alloc; ++ r->e_alloc = NULL; ++ } else { ++ e = r->e_dealloc; ++ r->e_dealloc = NULL; ++ } ++ e->resource.handle = r->resource.handle; ++ e->resource.channel = channel; ++ e->resource.bandwidth = bandwidth; ++ ++ queue_event(client, &e->event, ++ &e->resource, sizeof(e->resource), NULL, 0); ++ ++ if (free) { ++ cancel_delayed_work(&r->work); ++ kfree(r->e_alloc); ++ kfree(r->e_dealloc); ++ kfree(r); ++ } ++ out: ++ client_put(client); ++} ++ ++static void schedule_iso_resource(struct iso_resource *r) ++{ ++ client_get(r->client); ++ if (!schedule_delayed_work(&r->work, 0)) ++ client_put(r->client); ++} ++ ++static void release_iso_resource(struct client *client, ++ struct client_resource *resource) ++{ ++ struct iso_resource *r = ++ container_of(resource, struct iso_resource, resource); ++ ++ spin_lock_irq(&client->lock); ++ r->todo = ISO_RES_DEALLOC; ++ schedule_iso_resource(r); ++ spin_unlock_irq(&client->lock); ++} ++ ++static int init_iso_resource(struct client *client, ++ struct fw_cdev_allocate_iso_resource *request, int todo) ++{ ++ struct iso_resource_event *e1, *e2; ++ struct iso_resource *r; ++ int ret; ++ ++ if ((request->channels == 0 && request->bandwidth == 0) || ++ request->bandwidth > BANDWIDTH_AVAILABLE_INITIAL || ++ request->bandwidth < 0) ++ return -EINVAL; ++ ++ r = kmalloc(sizeof(*r), GFP_KERNEL); ++ e1 = kmalloc(sizeof(*e1), GFP_KERNEL); ++ e2 = kmalloc(sizeof(*e2), GFP_KERNEL); ++ if (r == NULL || e1 == NULL || e2 == NULL) { ++ ret = -ENOMEM; ++ goto fail; ++ } ++ ++ INIT_DELAYED_WORK(&r->work, iso_resource_work); ++ r->client = client; ++ r->todo = todo; ++ r->generation = -1; ++ r->channels = request->channels; ++ r->bandwidth = request->bandwidth; ++ r->e_alloc = e1; ++ r->e_dealloc = e2; ++ ++ e1->resource.closure = request->closure; ++ e1->resource.type = FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED; ++ e2->resource.closure = request->closure; ++ e2->resource.type = FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED; ++ ++ if (todo == ISO_RES_ALLOC) { ++ r->resource.release = release_iso_resource; ++ ret = add_client_resource(client, &r->resource, GFP_KERNEL); ++ if (ret < 0) ++ goto fail; ++ } else { ++ r->resource.release = NULL; ++ r->resource.handle = -1; ++ schedule_iso_resource(r); ++ } ++ request->handle = r->resource.handle; ++ ++ return 0; ++ fail: ++ kfree(r); ++ kfree(e1); ++ kfree(e2); ++ ++ return ret; ++} ++ ++static int ioctl_allocate_iso_resource(struct client *client, void *buffer) ++{ ++ struct fw_cdev_allocate_iso_resource *request = buffer; ++ ++ return init_iso_resource(client, request, ISO_RES_ALLOC); ++} ++ ++static int ioctl_deallocate_iso_resource(struct client *client, void *buffer) ++{ ++ struct fw_cdev_deallocate *request = buffer; ++ ++ return release_client_resource(client, request->handle, ++ release_iso_resource, NULL); ++} ++ ++static int ioctl_allocate_iso_resource_once(struct client *client, void *buffer) ++{ ++ struct fw_cdev_allocate_iso_resource *request = buffer; ++ ++ return init_iso_resource(client, request, ISO_RES_ALLOC_ONCE); ++} ++ ++static int ioctl_deallocate_iso_resource_once(struct client *client, void *buffer) ++{ ++ struct fw_cdev_allocate_iso_resource *request = buffer; ++ ++ return init_iso_resource(client, request, ISO_RES_DEALLOC_ONCE); ++} ++ ++static int ioctl_get_speed(struct client *client, void *buffer) ++{ ++ struct fw_cdev_get_speed *request = buffer; ++ ++ request->max_speed = client->device->max_speed; ++ ++ return 0; ++} ++ ++static int ioctl_send_broadcast_request(struct client *client, void *buffer) ++{ ++ struct fw_cdev_send_request *request = buffer; ++ ++ switch (request->tcode) { ++ case TCODE_WRITE_QUADLET_REQUEST: ++ case TCODE_WRITE_BLOCK_REQUEST: ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ /* Security policy: Only allow accesses to Units Space. */ ++ if (request->offset < CSR_REGISTER_BASE + CSR_CONFIG_ROM_END) ++ return -EACCES; ++ ++ return init_request(client, request, LOCAL_BUS | 0x3f, SCODE_100); ++} ++ + static int (* const ioctl_handlers[])(struct client *client, void *buffer) = { + ioctl_get_info, + ioctl_send_request, +@@ -885,13 +1256,19 @@ static int (* const ioctl_handlers[])(st + ioctl_start_iso, + ioctl_stop_iso, + ioctl_get_cycle_timer, ++ ioctl_allocate_iso_resource, ++ ioctl_deallocate_iso_resource, ++ ioctl_allocate_iso_resource_once, ++ ioctl_deallocate_iso_resource_once, ++ ioctl_get_speed, ++ ioctl_send_broadcast_request, + }; + +-static int +-dispatch_ioctl(struct client *client, unsigned int cmd, void __user *arg) ++static int dispatch_ioctl(struct client *client, ++ unsigned int cmd, void __user *arg) + { + char buffer[256]; +- int retval; ++ int ret; + + if (_IOC_TYPE(cmd) != '#' || + _IOC_NR(cmd) >= ARRAY_SIZE(ioctl_handlers)) +@@ -903,9 +1280,9 @@ dispatch_ioctl(struct client *client, un + return -EFAULT; + } + +- retval = ioctl_handlers[_IOC_NR(cmd)](client, buffer); +- if (retval < 0) +- return retval; ++ ret = ioctl_handlers[_IOC_NR(cmd)](client, buffer); ++ if (ret < 0) ++ return ret; + + if (_IOC_DIR(cmd) & _IOC_READ) { + if (_IOC_SIZE(cmd) > sizeof(buffer) || +@@ -913,12 +1290,11 @@ dispatch_ioctl(struct client *client, un + return -EFAULT; + } + +- return retval; ++ return ret; + } + +-static long +-fw_device_op_ioctl(struct file *file, +- unsigned int cmd, unsigned long arg) ++static long fw_device_op_ioctl(struct file *file, ++ unsigned int cmd, unsigned long arg) + { + struct client *client = file->private_data; + +@@ -929,9 +1305,8 @@ fw_device_op_ioctl(struct file *file, + } + + #ifdef CONFIG_COMPAT +-static long +-fw_device_op_compat_ioctl(struct file *file, +- unsigned int cmd, unsigned long arg) ++static long fw_device_op_compat_ioctl(struct file *file, ++ unsigned int cmd, unsigned long arg) + { + struct client *client = file->private_data; + +@@ -947,7 +1322,7 @@ static int fw_device_op_mmap(struct file + struct client *client = file->private_data; + enum dma_data_direction direction; + unsigned long size; +- int page_count, retval; ++ int page_count, ret; + + if (fw_device_is_shutdown(client->device)) + return -ENODEV; +@@ -973,48 +1348,57 @@ static int fw_device_op_mmap(struct file + else + direction = DMA_FROM_DEVICE; + +- retval = fw_iso_buffer_init(&client->buffer, client->device->card, +- page_count, direction); +- if (retval < 0) +- return retval; ++ ret = fw_iso_buffer_init(&client->buffer, client->device->card, ++ page_count, direction); ++ if (ret < 0) ++ return ret; + +- retval = fw_iso_buffer_map(&client->buffer, vma); +- if (retval < 0) ++ ret = fw_iso_buffer_map(&client->buffer, vma); ++ if (ret < 0) + fw_iso_buffer_destroy(&client->buffer, client->device->card); + +- return retval; ++ return ret; ++} ++ ++static int shutdown_resource(int id, void *p, void *data) ++{ ++ struct client_resource *r = p; ++ struct client *client = data; ++ ++ r->release(client, r); ++ client_put(client); ++ ++ return 0; + } + + static int fw_device_op_release(struct inode *inode, struct file *file) + { + struct client *client = file->private_data; + struct event *e, *next_e; +- struct client_resource *r, *next_r; +- unsigned long flags; + +- if (client->buffer.pages) +- fw_iso_buffer_destroy(&client->buffer, client->device->card); ++ mutex_lock(&client->device->client_list_mutex); ++ list_del(&client->link); ++ mutex_unlock(&client->device->client_list_mutex); + + if (client->iso_context) + fw_iso_context_destroy(client->iso_context); + +- list_for_each_entry_safe(r, next_r, &client->resource_list, link) +- r->release(client, r); ++ if (client->buffer.pages) ++ fw_iso_buffer_destroy(&client->buffer, client->device->card); + +- /* +- * FIXME: We should wait for the async tasklets to stop +- * running before freeing the memory. +- */ ++ /* Freeze client->resource_idr and client->event_list */ ++ spin_lock_irq(&client->lock); ++ client->in_shutdown = true; ++ spin_unlock_irq(&client->lock); ++ ++ idr_for_each(&client->resource_idr, shutdown_resource, client); ++ idr_remove_all(&client->resource_idr); ++ idr_destroy(&client->resource_idr); + + list_for_each_entry_safe(e, next_e, &client->event_list, link) + kfree(e); + +- spin_lock_irqsave(&client->device->card->lock, flags); +- list_del(&client->link); +- spin_unlock_irqrestore(&client->device->card->lock, flags); +- +- fw_device_put(client->device); +- kfree(client); ++ client_put(client); + + return 0; + } +diff -Naurp linux-2.6-git/drivers/firewire/fw-device.c firewire-git/drivers/firewire/fw-device.c +--- linux-2.6-git/drivers/firewire/fw-device.c 2009-01-30 13:39:02.989651512 -0500 ++++ firewire-git/drivers/firewire/fw-device.c 2009-01-30 13:35:51.860646788 -0500 +@@ -27,8 +27,10 @@ + #include + #include + #include ++#include + #include + #include ++#include + #include + #include + #include "fw-transaction.h" +@@ -132,8 +134,7 @@ static int get_modalias(struct fw_unit * + vendor, model, specifier_id, version); + } + +-static int +-fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env) ++static int fw_unit_uevent(struct device *dev, struct kobj_uevent_env *env) + { + struct fw_unit *unit = fw_unit(dev); + char modalias[64]; +@@ -191,8 +192,8 @@ struct config_rom_attribute { + u32 key; + }; + +-static ssize_t +-show_immediate(struct device *dev, struct device_attribute *dattr, char *buf) ++static ssize_t show_immediate(struct device *dev, ++ struct device_attribute *dattr, char *buf) + { + struct config_rom_attribute *attr = + container_of(dattr, struct config_rom_attribute, attr); +@@ -223,8 +224,8 @@ show_immediate(struct device *dev, struc + #define IMMEDIATE_ATTR(name, key) \ + { __ATTR(name, S_IRUGO, show_immediate, NULL), key } + +-static ssize_t +-show_text_leaf(struct device *dev, struct device_attribute *dattr, char *buf) ++static ssize_t show_text_leaf(struct device *dev, ++ struct device_attribute *dattr, char *buf) + { + struct config_rom_attribute *attr = + container_of(dattr, struct config_rom_attribute, attr); +@@ -293,10 +294,9 @@ static struct config_rom_attribute confi + TEXT_LEAF_ATTR(hardware_version_name, CSR_HARDWARE_VERSION), + }; + +-static void +-init_fw_attribute_group(struct device *dev, +- struct device_attribute *attrs, +- struct fw_attribute_group *group) ++static void init_fw_attribute_group(struct device *dev, ++ struct device_attribute *attrs, ++ struct fw_attribute_group *group) + { + struct device_attribute *attr; + int i, j; +@@ -319,9 +319,8 @@ init_fw_attribute_group(struct device *d + dev->groups = group->groups; + } + +-static ssize_t +-modalias_show(struct device *dev, +- struct device_attribute *attr, char *buf) ++static ssize_t modalias_show(struct device *dev, ++ struct device_attribute *attr, char *buf) + { + struct fw_unit *unit = fw_unit(dev); + int length; +@@ -332,9 +331,8 @@ modalias_show(struct device *dev, + return length + 1; + } + +-static ssize_t +-rom_index_show(struct device *dev, +- struct device_attribute *attr, char *buf) ++static ssize_t rom_index_show(struct device *dev, ++ struct device_attribute *attr, char *buf) + { + struct fw_device *device = fw_device(dev->parent); + struct fw_unit *unit = fw_unit(dev); +@@ -349,8 +347,8 @@ static struct device_attribute fw_unit_a + __ATTR_NULL, + }; + +-static ssize_t +-config_rom_show(struct device *dev, struct device_attribute *attr, char *buf) ++static ssize_t config_rom_show(struct device *dev, ++ struct device_attribute *attr, char *buf) + { + struct fw_device *device = fw_device(dev); + size_t length; +@@ -363,8 +361,8 @@ config_rom_show(struct device *dev, stru + return length; + } + +-static ssize_t +-guid_show(struct device *dev, struct device_attribute *attr, char *buf) ++static ssize_t guid_show(struct device *dev, ++ struct device_attribute *attr, char *buf) + { + struct fw_device *device = fw_device(dev); + int ret; +@@ -383,8 +381,8 @@ static struct device_attribute fw_device + __ATTR_NULL, + }; + +-static int +-read_rom(struct fw_device *device, int generation, int index, u32 *data) ++static int read_rom(struct fw_device *device, ++ int generation, int index, u32 *data) + { + int rcode; + +@@ -1004,6 +1002,7 @@ void fw_node_event(struct fw_card *card, + device->node = fw_node_get(node); + device->node_id = node->node_id; + device->generation = card->generation; ++ mutex_init(&device->client_list_mutex); + INIT_LIST_HEAD(&device->client_list); + + /* +diff -Naurp linux-2.6-git/drivers/firewire/fw-device.h firewire-git/drivers/firewire/fw-device.h +--- linux-2.6-git/drivers/firewire/fw-device.h 2009-01-30 13:39:02.989651512 -0500 ++++ firewire-git/drivers/firewire/fw-device.h 2009-01-30 13:35:51.860646788 -0500 +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + #include + + enum fw_device_state { +@@ -64,7 +65,10 @@ struct fw_device { + bool cmc; + struct fw_card *card; + struct device device; ++ ++ struct mutex client_list_mutex; + struct list_head client_list; ++ + u32 *config_rom; + size_t config_rom_length; + int config_rom_retries; +@@ -176,8 +180,7 @@ struct fw_driver { + const struct fw_device_id *id_table; + }; + +-static inline struct fw_driver * +-fw_driver(struct device_driver *drv) ++static inline struct fw_driver *fw_driver(struct device_driver *drv) + { + return container_of(drv, struct fw_driver, driver); + } +diff -Naurp linux-2.6-git/drivers/firewire/fw-iso.c firewire-git/drivers/firewire/fw-iso.c +--- linux-2.6-git/drivers/firewire/fw-iso.c 2008-11-04 11:18:33.000000000 -0500 ++++ firewire-git/drivers/firewire/fw-iso.c 2009-01-30 13:35:51.860646788 -0500 +@@ -1,5 +1,7 @@ + /* +- * Isochronous IO functionality ++ * Isochronous I/O functionality: ++ * - Isochronous DMA context management ++ * - Isochronous bus resource management (channels, bandwidth), client side + * + * Copyright (C) 2006 Kristian Hoegsberg + * +@@ -18,21 +20,25 @@ + * Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + +-#include +-#include + #include +-#include ++#include ++#include ++#include + #include ++#include ++#include + +-#include "fw-transaction.h" + #include "fw-topology.h" +-#include "fw-device.h" ++#include "fw-transaction.h" + +-int +-fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, +- int page_count, enum dma_data_direction direction) ++/* ++ * Isochronous DMA context management ++ */ ++ ++int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, ++ int page_count, enum dma_data_direction direction) + { +- int i, j, retval = -ENOMEM; ++ int i, j; + dma_addr_t address; + + buffer->page_count = page_count; +@@ -69,19 +75,19 @@ fw_iso_buffer_init(struct fw_iso_buffer + kfree(buffer->pages); + out: + buffer->pages = NULL; +- return retval; ++ return -ENOMEM; + } + + int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma) + { + unsigned long uaddr; +- int i, retval; ++ int i, ret; + + uaddr = vma->vm_start; + for (i = 0; i < buffer->page_count; i++) { +- retval = vm_insert_page(vma, uaddr, buffer->pages[i]); +- if (retval) +- return retval; ++ ret = vm_insert_page(vma, uaddr, buffer->pages[i]); ++ if (ret) ++ return ret; + uaddr += PAGE_SIZE; + } + +@@ -105,14 +111,14 @@ void fw_iso_buffer_destroy(struct fw_iso + buffer->pages = NULL; + } + +-struct fw_iso_context * +-fw_iso_context_create(struct fw_card *card, int type, +- int channel, int speed, size_t header_size, +- fw_iso_callback_t callback, void *callback_data) ++struct fw_iso_context *fw_iso_context_create(struct fw_card *card, ++ int type, int channel, int speed, size_t header_size, ++ fw_iso_callback_t callback, void *callback_data) + { + struct fw_iso_context *ctx; + +- ctx = card->driver->allocate_iso_context(card, type, header_size); ++ ctx = card->driver->allocate_iso_context(card, ++ type, channel, header_size); + if (IS_ERR(ctx)) + return ctx; + +@@ -134,25 +140,186 @@ void fw_iso_context_destroy(struct fw_is + card->driver->free_iso_context(ctx); + } + +-int +-fw_iso_context_start(struct fw_iso_context *ctx, int cycle, int sync, int tags) ++int fw_iso_context_start(struct fw_iso_context *ctx, ++ int cycle, int sync, int tags) + { + return ctx->card->driver->start_iso(ctx, cycle, sync, tags); + } + +-int +-fw_iso_context_queue(struct fw_iso_context *ctx, +- struct fw_iso_packet *packet, +- struct fw_iso_buffer *buffer, +- unsigned long payload) ++int fw_iso_context_queue(struct fw_iso_context *ctx, ++ struct fw_iso_packet *packet, ++ struct fw_iso_buffer *buffer, ++ unsigned long payload) + { + struct fw_card *card = ctx->card; + + return card->driver->queue_iso(ctx, packet, buffer, payload); + } + +-int +-fw_iso_context_stop(struct fw_iso_context *ctx) ++int fw_iso_context_stop(struct fw_iso_context *ctx) + { + return ctx->card->driver->stop_iso(ctx); + } ++ ++/* ++ * Isochronous bus resource management (channels, bandwidth), client side ++ */ ++ ++static int manage_bandwidth(struct fw_card *card, int irm_id, int generation, ++ int bandwidth, bool allocate) ++{ ++ __be32 data[2]; ++ int try, new, old = allocate ? BANDWIDTH_AVAILABLE_INITIAL : 0; ++ ++ /* ++ * On a 1394a IRM with low contention, try < 1 is enough. ++ * On a 1394-1995 IRM, we need at least try < 2. ++ * Let's just do try < 5. ++ */ ++ for (try = 0; try < 5; try++) { ++ new = allocate ? old - bandwidth : old + bandwidth; ++ if (new < 0 || new > BANDWIDTH_AVAILABLE_INITIAL) ++ break; ++ ++ data[0] = cpu_to_be32(old); ++ data[1] = cpu_to_be32(new); ++ switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, ++ irm_id, generation, SCODE_100, ++ CSR_REGISTER_BASE + CSR_BANDWIDTH_AVAILABLE, ++ data, sizeof(data))) { ++ case RCODE_GENERATION: ++ /* A generation change frees all bandwidth. */ ++ return allocate ? -EAGAIN : bandwidth; ++ ++ case RCODE_COMPLETE: ++ if (be32_to_cpup(data) == old) ++ return bandwidth; ++ ++ old = be32_to_cpup(data); ++ /* Fall through. */ ++ } ++ } ++ ++ return -EIO; ++} ++ ++static int manage_channel(struct fw_card *card, int irm_id, int generation, ++ u32 channels_mask, u64 offset, bool allocate) ++{ ++ __be32 data[2], c, all, old; ++ int i, retry = 5; ++ ++ old = all = allocate ? cpu_to_be32(~0) : 0; ++ ++ for (i = 0; i < 32; i++) { ++ if (!(channels_mask & 1 << i)) ++ continue; ++ ++ c = cpu_to_be32(1 << (31 - i)); ++ if ((old & c) != (all & c)) ++ continue; ++ ++ data[0] = old; ++ data[1] = old ^ c; ++ switch (fw_run_transaction(card, TCODE_LOCK_COMPARE_SWAP, ++ irm_id, generation, SCODE_100, ++ offset, data, sizeof(data))) { ++ case RCODE_GENERATION: ++ /* A generation change frees all channels. */ ++ return allocate ? -EAGAIN : i; ++ ++ case RCODE_COMPLETE: ++ if (data[0] == old) ++ return i; ++ ++ old = data[0]; ++ ++ /* Is the IRM 1394a-2000 compliant? */ ++ if ((data[0] & c) == (data[1] & c)) ++ continue; ++ ++ /* 1394-1995 IRM, fall through to retry. */ ++ default: ++ if (retry--) ++ i--; ++ } ++ } ++ ++ return -EIO; ++} ++ ++static void deallocate_channel(struct fw_card *card, int irm_id, ++ int generation, int channel) ++{ ++ u32 mask; ++ u64 offset; ++ ++ mask = channel < 32 ? 1 << channel : 1 << (channel - 32); ++ offset = channel < 32 ? CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI : ++ CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO; ++ ++ manage_channel(card, irm_id, generation, mask, offset, false); ++} ++ ++/** ++ * fw_iso_resource_manage - Allocate or deallocate a channel and/or bandwidth ++ * ++ * In parameters: card, generation, channels_mask, bandwidth, allocate ++ * Out parameters: channel, bandwidth ++ * This function blocks (sleeps) during communication with the IRM. ++ * ++ * Allocates or deallocates at most one channel out of channels_mask. ++ * channels_mask is a bitfield with MSB for channel 63 and LSB for channel 0. ++ * (Note, the IRM's CHANNELS_AVAILABLE is a big-endian bitfield with MSB for ++ * channel 0 and LSB for channel 63.) ++ * Allocates or deallocates as many bandwidth allocation units as specified. ++ * ++ * Returns channel < 0 if no channel was allocated or deallocated. ++ * Returns bandwidth = 0 if no bandwidth was allocated or deallocated. ++ * ++ * If generation is stale, deallocations succeed but allocations fail with ++ * channel = -EAGAIN. ++ * ++ * If channel allocation fails, no bandwidth will be allocated either. ++ * If bandwidth allocation fails, no channel will be allocated either. ++ * But deallocations of channel and bandwidth are tried independently ++ * of each other's success. ++ */ ++void fw_iso_resource_manage(struct fw_card *card, int generation, ++ u64 channels_mask, int *channel, int *bandwidth, ++ bool allocate) ++{ ++ u32 channels_hi = channels_mask; /* channels 31...0 */ ++ u32 channels_lo = channels_mask >> 32; /* channels 63...32 */ ++ int irm_id, ret, c = -EINVAL; ++ ++ spin_lock_irq(&card->lock); ++ irm_id = card->irm_node->node_id; ++ spin_unlock_irq(&card->lock); ++ ++ if (channels_hi) ++ c = manage_channel(card, irm_id, generation, channels_hi, ++ CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_HI, allocate); ++ if (channels_lo && c < 0) { ++ c = manage_channel(card, irm_id, generation, channels_lo, ++ CSR_REGISTER_BASE + CSR_CHANNELS_AVAILABLE_LO, allocate); ++ if (c >= 0) ++ c += 32; ++ } ++ *channel = c; ++ ++ if (allocate && channels_mask != 0 && c < 0) ++ *bandwidth = 0; ++ ++ if (*bandwidth == 0) ++ return; ++ ++ ret = manage_bandwidth(card, irm_id, generation, *bandwidth, allocate); ++ if (ret < 0) ++ *bandwidth = 0; ++ ++ if (allocate && ret < 0 && c >= 0) { ++ deallocate_channel(card, irm_id, generation, c); ++ *channel = ret; ++ } ++} +diff -Naurp linux-2.6-git/drivers/firewire/fw-ohci.c firewire-git/drivers/firewire/fw-ohci.c +--- linux-2.6-git/drivers/firewire/fw-ohci.c 2009-01-30 13:39:02.990772025 -0500 ++++ firewire-git/drivers/firewire/fw-ohci.c 2009-01-30 13:35:51.861646907 -0500 +@@ -205,6 +205,7 @@ struct fw_ohci { + + u32 it_context_mask; + struct iso_context *it_context_list; ++ u64 ir_context_channels; + u32 ir_context_mask; + struct iso_context *ir_context_list; + }; +@@ -441,9 +442,8 @@ static inline void flush_writes(const st + reg_read(ohci, OHCI1394_Version); + } + +-static int +-ohci_update_phy_reg(struct fw_card *card, int addr, +- int clear_bits, int set_bits) ++static int ohci_update_phy_reg(struct fw_card *card, int addr, ++ int clear_bits, int set_bits) + { + struct fw_ohci *ohci = fw_ohci(card); + u32 val, old; +@@ -658,8 +658,8 @@ static void ar_context_tasklet(unsigned + } + } + +-static int +-ar_context_init(struct ar_context *ctx, struct fw_ohci *ohci, u32 regs) ++static int ar_context_init(struct ar_context *ctx, ++ struct fw_ohci *ohci, u32 regs) + { + struct ar_buffer ab; + +@@ -690,8 +690,7 @@ static void ar_context_run(struct ar_con + flush_writes(ctx->ohci); + } + +-static struct descriptor * +-find_branch_descriptor(struct descriptor *d, int z) ++static struct descriptor *find_branch_descriptor(struct descriptor *d, int z) + { + int b, key; + +@@ -751,8 +750,7 @@ static void context_tasklet(unsigned lon + * Allocate a new buffer and add it to the list of free buffers for this + * context. Must be called with ohci->lock held. + */ +-static int +-context_add_buffer(struct context *ctx) ++static int context_add_buffer(struct context *ctx) + { + struct descriptor_buffer *desc; + dma_addr_t uninitialized_var(bus_addr); +@@ -781,9 +779,8 @@ context_add_buffer(struct context *ctx) + return 0; + } + +-static int +-context_init(struct context *ctx, struct fw_ohci *ohci, +- u32 regs, descriptor_callback_t callback) ++static int context_init(struct context *ctx, struct fw_ohci *ohci, ++ u32 regs, descriptor_callback_t callback) + { + ctx->ohci = ohci; + ctx->regs = regs; +@@ -814,8 +811,7 @@ context_init(struct context *ctx, struct + return 0; + } + +-static void +-context_release(struct context *ctx) ++static void context_release(struct context *ctx) + { + struct fw_card *card = &ctx->ohci->card; + struct descriptor_buffer *desc, *tmp; +@@ -827,8 +823,8 @@ context_release(struct context *ctx) + } + + /* Must be called with ohci->lock held */ +-static struct descriptor * +-context_get_descriptors(struct context *ctx, int z, dma_addr_t *d_bus) ++static struct descriptor *context_get_descriptors(struct context *ctx, ++ int z, dma_addr_t *d_bus) + { + struct descriptor *d = NULL; + struct descriptor_buffer *desc = ctx->buffer_tail; +@@ -912,8 +908,8 @@ struct driver_data { + * Must always be called with the ochi->lock held to ensure proper + * generation handling and locking around packet queue manipulation. + */ +-static int +-at_context_queue_packet(struct context *ctx, struct fw_packet *packet) ++static int at_context_queue_packet(struct context *ctx, ++ struct fw_packet *packet) + { + struct fw_ohci *ohci = ctx->ohci; + dma_addr_t d_bus, uninitialized_var(payload_bus); +@@ -1095,8 +1091,8 @@ static int handle_at_packet(struct conte + #define HEADER_GET_DATA_LENGTH(q) (((q) >> 16) & 0xffff) + #define HEADER_GET_EXTENDED_TCODE(q) (((q) >> 0) & 0xffff) + +-static void +-handle_local_rom(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr) ++static void handle_local_rom(struct fw_ohci *ohci, ++ struct fw_packet *packet, u32 csr) + { + struct fw_packet response; + int tcode, length, i; +@@ -1122,8 +1118,8 @@ handle_local_rom(struct fw_ohci *ohci, s + fw_core_handle_response(&ohci->card, &response); + } + +-static void +-handle_local_lock(struct fw_ohci *ohci, struct fw_packet *packet, u32 csr) ++static void handle_local_lock(struct fw_ohci *ohci, ++ struct fw_packet *packet, u32 csr) + { + struct fw_packet response; + int tcode, length, ext_tcode, sel; +@@ -1164,8 +1160,7 @@ handle_local_lock(struct fw_ohci *ohci, + fw_core_handle_response(&ohci->card, &response); + } + +-static void +-handle_local_request(struct context *ctx, struct fw_packet *packet) ++static void handle_local_request(struct context *ctx, struct fw_packet *packet) + { + u64 offset; + u32 csr; +@@ -1205,11 +1200,10 @@ handle_local_request(struct context *ctx + } + } + +-static void +-at_context_transmit(struct context *ctx, struct fw_packet *packet) ++static void at_context_transmit(struct context *ctx, struct fw_packet *packet) + { + unsigned long flags; +- int retval; ++ int ret; + + spin_lock_irqsave(&ctx->ohci->lock, flags); + +@@ -1220,10 +1214,10 @@ at_context_transmit(struct context *ctx, + return; + } + +- retval = at_context_queue_packet(ctx, packet); ++ ret = at_context_queue_packet(ctx, packet); + spin_unlock_irqrestore(&ctx->ohci->lock, flags); + +- if (retval < 0) ++ if (ret < 0) + packet->callback(packet, &ctx->ohci->card, packet->ack); + + } +@@ -1590,12 +1584,12 @@ static int ohci_enable(struct fw_card *c + return 0; + } + +-static int +-ohci_set_config_rom(struct fw_card *card, u32 *config_rom, size_t length) ++static int ohci_set_config_rom(struct fw_card *card, ++ u32 *config_rom, size_t length) + { + struct fw_ohci *ohci; + unsigned long flags; +- int retval = -EBUSY; ++ int ret = -EBUSY; + __be32 *next_config_rom; + dma_addr_t uninitialized_var(next_config_rom_bus); + +@@ -1649,7 +1643,7 @@ ohci_set_config_rom(struct fw_card *card + + reg_write(ohci, OHCI1394_ConfigROMmap, + ohci->next_config_rom_bus); +- retval = 0; ++ ret = 0; + } + + spin_unlock_irqrestore(&ohci->lock, flags); +@@ -1661,13 +1655,13 @@ ohci_set_config_rom(struct fw_card *card + * controller could need to access it before the bus reset + * takes effect. + */ +- if (retval == 0) ++ if (ret == 0) + fw_core_initiate_bus_reset(&ohci->card, 1); + else + dma_free_coherent(ohci->card.device, CONFIG_ROM_SIZE, + next_config_rom, next_config_rom_bus); + +- return retval; ++ return ret; + } + + static void ohci_send_request(struct fw_card *card, struct fw_packet *packet) +@@ -1689,7 +1683,7 @@ static int ohci_cancel_packet(struct fw_ + struct fw_ohci *ohci = fw_ohci(card); + struct context *ctx = &ohci->at_request_ctx; + struct driver_data *driver_data = packet->driver_data; +- int retval = -ENOENT; ++ int ret = -ENOENT; + + tasklet_disable(&ctx->tasklet); + +@@ -1704,23 +1698,22 @@ static int ohci_cancel_packet(struct fw_ + driver_data->packet = NULL; + packet->ack = RCODE_CANCELLED; + packet->callback(packet, &ohci->card, packet->ack); +- retval = 0; +- ++ ret = 0; + out: + tasklet_enable(&ctx->tasklet); + +- return retval; ++ return ret; + } + +-static int +-ohci_enable_phys_dma(struct fw_card *card, int node_id, int generation) ++static int ohci_enable_phys_dma(struct fw_card *card, ++ int node_id, int generation) + { + #ifdef CONFIG_FIREWIRE_OHCI_REMOTE_DMA + return 0; + #else + struct fw_ohci *ohci = fw_ohci(card); + unsigned long flags; +- int n, retval = 0; ++ int n, ret = 0; + + /* + * FIXME: Make sure this bitmask is cleared when we clear the busReset +@@ -1730,7 +1723,7 @@ ohci_enable_phys_dma(struct fw_card *car + spin_lock_irqsave(&ohci->lock, flags); + + if (ohci->generation != generation) { +- retval = -ESTALE; ++ ret = -ESTALE; + goto out; + } + +@@ -1748,12 +1741,12 @@ ohci_enable_phys_dma(struct fw_card *car + flush_writes(ohci); + out: + spin_unlock_irqrestore(&ohci->lock, flags); +- return retval; ++ ++ return ret; + #endif /* CONFIG_FIREWIRE_OHCI_REMOTE_DMA */ + } + +-static u64 +-ohci_get_bus_time(struct fw_card *card) ++static u64 ohci_get_bus_time(struct fw_card *card) + { + struct fw_ohci *ohci = fw_ohci(card); + u32 cycle_time; +@@ -1765,6 +1758,28 @@ ohci_get_bus_time(struct fw_card *card) + return bus_time; + } + ++static void copy_iso_headers(struct iso_context *ctx, void *p) ++{ ++ int i = ctx->header_length; ++ ++ if (i + ctx->base.header_size > PAGE_SIZE) ++ return; ++ ++ /* ++ * The iso header is byteswapped to little endian by ++ * the controller, but the remaining header quadlets ++ * are big endian. We want to present all the headers ++ * as big endian, so we have to swap the first quadlet. ++ */ ++ if (ctx->base.header_size > 0) ++ *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); ++ if (ctx->base.header_size > 4) ++ *(u32 *) (ctx->header + i + 4) = __swab32(*(u32 *) p); ++ if (ctx->base.header_size > 8) ++ memcpy(ctx->header + i + 8, p + 8, ctx->base.header_size - 8); ++ ctx->header_length += ctx->base.header_size; ++} ++ + static int handle_ir_dualbuffer_packet(struct context *context, + struct descriptor *d, + struct descriptor *last) +@@ -1775,7 +1790,6 @@ static int handle_ir_dualbuffer_packet(s + __le32 *ir_header; + size_t header_length; + void *p, *end; +- int i; + + if (db->first_res_count != 0 && db->second_res_count != 0) { + if (ctx->excess_bytes <= le16_to_cpu(db->second_req_count)) { +@@ -1788,25 +1802,14 @@ static int handle_ir_dualbuffer_packet(s + header_length = le16_to_cpu(db->first_req_count) - + le16_to_cpu(db->first_res_count); + +- i = ctx->header_length; + p = db + 1; + end = p + header_length; +- while (p < end && i + ctx->base.header_size <= PAGE_SIZE) { +- /* +- * The iso header is byteswapped to little endian by +- * the controller, but the remaining header quadlets +- * are big endian. We want to present all the headers +- * as big endian, so we have to swap the first +- * quadlet. +- */ +- *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); +- memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); +- i += ctx->base.header_size; ++ while (p < end) { ++ copy_iso_headers(ctx, p); + ctx->excess_bytes += + (le32_to_cpu(*(__le32 *)(p + 4)) >> 16) & 0xffff; +- p += ctx->base.header_size + 4; ++ p += max(ctx->base.header_size, (size_t)8); + } +- ctx->header_length = i; + + ctx->excess_bytes -= le16_to_cpu(db->second_req_count) - + le16_to_cpu(db->second_res_count); +@@ -1832,7 +1835,6 @@ static int handle_ir_packet_per_buffer(s + struct descriptor *pd; + __le32 *ir_header; + void *p; +- int i; + + for (pd = d; pd <= last; pd++) { + if (pd->transfer_status) +@@ -1842,21 +1844,8 @@ static int handle_ir_packet_per_buffer(s + /* Descriptor(s) not done yet, stop iteration */ + return 0; + +- i = ctx->header_length; +- p = last + 1; +- +- if (ctx->base.header_size > 0 && +- i + ctx->base.header_size <= PAGE_SIZE) { +- /* +- * The iso header is byteswapped to little endian by +- * the controller, but the remaining header quadlets +- * are big endian. We want to present all the headers +- * as big endian, so we have to swap the first quadlet. +- */ +- *(u32 *) (ctx->header + i) = __swab32(*(u32 *) (p + 4)); +- memcpy(ctx->header + i + 4, p + 8, ctx->base.header_size - 4); +- ctx->header_length += ctx->base.header_size; +- } ++ p = last + 1; ++ copy_iso_headers(ctx, p); + + if (le16_to_cpu(last->control) & DESCRIPTOR_IRQ_ALWAYS) { + ir_header = (__le32 *) p; +@@ -1888,21 +1877,24 @@ static int handle_it_packet(struct conte + return 1; + } + +-static struct fw_iso_context * +-ohci_allocate_iso_context(struct fw_card *card, int type, size_t header_size) ++static struct fw_iso_context *ohci_allocate_iso_context(struct fw_card *card, ++ int type, int channel, size_t header_size) + { + struct fw_ohci *ohci = fw_ohci(card); + struct iso_context *ctx, *list; + descriptor_callback_t callback; ++ u64 *channels, dont_care = ~0ULL; + u32 *mask, regs; + unsigned long flags; +- int index, retval = -ENOMEM; ++ int index, ret = -ENOMEM; + + if (type == FW_ISO_CONTEXT_TRANSMIT) { ++ channels = &dont_care; + mask = &ohci->it_context_mask; + list = ohci->it_context_list; + callback = handle_it_packet; + } else { ++ channels = &ohci->ir_context_channels; + mask = &ohci->ir_context_mask; + list = ohci->ir_context_list; + if (ohci->use_dualbuffer) +@@ -1912,9 +1904,11 @@ ohci_allocate_iso_context(struct fw_card + } + + spin_lock_irqsave(&ohci->lock, flags); +- index = ffs(*mask) - 1; +- if (index >= 0) ++ index = *channels & 1ULL << channel ? ffs(*mask) - 1 : -1; ++ if (index >= 0) { ++ *channels &= ~(1ULL << channel); + *mask &= ~(1 << index); ++ } + spin_unlock_irqrestore(&ohci->lock, flags); + + if (index < 0) +@@ -1932,8 +1926,8 @@ ohci_allocate_iso_context(struct fw_card + if (ctx->header == NULL) + goto out; + +- retval = context_init(&ctx->context, ohci, regs, callback); +- if (retval < 0) ++ ret = context_init(&ctx->context, ohci, regs, callback); ++ if (ret < 0) + goto out_with_header; + + return &ctx->base; +@@ -1945,7 +1939,7 @@ ohci_allocate_iso_context(struct fw_card + *mask |= 1 << index; + spin_unlock_irqrestore(&ohci->lock, flags); + +- return ERR_PTR(retval); ++ return ERR_PTR(ret); + } + + static int ohci_start_iso(struct fw_iso_context *base, +@@ -2024,16 +2018,16 @@ static void ohci_free_iso_context(struct + } else { + index = ctx - ohci->ir_context_list; + ohci->ir_context_mask |= 1 << index; ++ ohci->ir_context_channels |= 1ULL << base->channel; + } + + spin_unlock_irqrestore(&ohci->lock, flags); + } + +-static int +-ohci_queue_iso_transmit(struct fw_iso_context *base, +- struct fw_iso_packet *packet, +- struct fw_iso_buffer *buffer, +- unsigned long payload) ++static int ohci_queue_iso_transmit(struct fw_iso_context *base, ++ struct fw_iso_packet *packet, ++ struct fw_iso_buffer *buffer, ++ unsigned long payload) + { + struct iso_context *ctx = container_of(base, struct iso_context, base); + struct descriptor *d, *last, *pd; +@@ -2128,11 +2122,10 @@ ohci_queue_iso_transmit(struct fw_iso_co + return 0; + } + +-static int +-ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, +- struct fw_iso_packet *packet, +- struct fw_iso_buffer *buffer, +- unsigned long payload) ++static int ohci_queue_iso_receive_dualbuffer(struct fw_iso_context *base, ++ struct fw_iso_packet *packet, ++ struct fw_iso_buffer *buffer, ++ unsigned long payload) + { + struct iso_context *ctx = container_of(base, struct iso_context, base); + struct db_descriptor *db = NULL; +@@ -2151,11 +2144,11 @@ ohci_queue_iso_receive_dualbuffer(struct + z = 2; + + /* +- * The OHCI controller puts the status word in the header +- * buffer too, so we need 4 extra bytes per packet. ++ * The OHCI controller puts the isochronous header and trailer in the ++ * buffer, so we need at least 8 bytes. + */ + packet_count = p->header_length / ctx->base.header_size; +- header_size = packet_count * (ctx->base.header_size + 4); ++ header_size = packet_count * max(ctx->base.header_size, (size_t)8); + + /* Get header size in number of descriptors. */ + header_z = DIV_ROUND_UP(header_size, sizeof(*d)); +@@ -2173,7 +2166,8 @@ ohci_queue_iso_receive_dualbuffer(struct + db = (struct db_descriptor *) d; + db->control = cpu_to_le16(DESCRIPTOR_STATUS | + DESCRIPTOR_BRANCH_ALWAYS); +- db->first_size = cpu_to_le16(ctx->base.header_size + 4); ++ db->first_size = ++ cpu_to_le16(max(ctx->base.header_size, (size_t)8)); + if (p->skip && rest == p->payload_length) { + db->control |= cpu_to_le16(DESCRIPTOR_WAIT); + db->first_req_count = db->first_size; +@@ -2208,11 +2202,10 @@ ohci_queue_iso_receive_dualbuffer(struct + return 0; + } + +-static int +-ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, +- struct fw_iso_packet *packet, +- struct fw_iso_buffer *buffer, +- unsigned long payload) ++static int ohci_queue_iso_receive_packet_per_buffer(struct fw_iso_context *base, ++ struct fw_iso_packet *packet, ++ struct fw_iso_buffer *buffer, ++ unsigned long payload) + { + struct iso_context *ctx = container_of(base, struct iso_context, base); + struct descriptor *d = NULL, *pd = NULL; +@@ -2223,11 +2216,11 @@ ohci_queue_iso_receive_packet_per_buffer + int page, offset, packet_count, header_size, payload_per_buffer; + + /* +- * The OHCI controller puts the status word in the +- * buffer too, so we need 4 extra bytes per packet. ++ * The OHCI controller puts the isochronous header and trailer in the ++ * buffer, so we need at least 8 bytes. + */ + packet_count = p->header_length / ctx->base.header_size; +- header_size = ctx->base.header_size + 4; ++ header_size = max(ctx->base.header_size, (size_t)8); + + /* Get header size in number of descriptors. */ + header_z = DIV_ROUND_UP(header_size, sizeof(*d)); +@@ -2286,29 +2279,27 @@ ohci_queue_iso_receive_packet_per_buffer + return 0; + } + +-static int +-ohci_queue_iso(struct fw_iso_context *base, +- struct fw_iso_packet *packet, +- struct fw_iso_buffer *buffer, +- unsigned long payload) ++static int ohci_queue_iso(struct fw_iso_context *base, ++ struct fw_iso_packet *packet, ++ struct fw_iso_buffer *buffer, ++ unsigned long payload) + { + struct iso_context *ctx = container_of(base, struct iso_context, base); + unsigned long flags; +- int retval; ++ int ret; + + spin_lock_irqsave(&ctx->context.ohci->lock, flags); + if (base->type == FW_ISO_CONTEXT_TRANSMIT) +- retval = ohci_queue_iso_transmit(base, packet, buffer, payload); ++ ret = ohci_queue_iso_transmit(base, packet, buffer, payload); + else if (ctx->context.ohci->use_dualbuffer) +- retval = ohci_queue_iso_receive_dualbuffer(base, packet, +- buffer, payload); ++ ret = ohci_queue_iso_receive_dualbuffer(base, packet, ++ buffer, payload); + else +- retval = ohci_queue_iso_receive_packet_per_buffer(base, packet, +- buffer, +- payload); ++ ret = ohci_queue_iso_receive_packet_per_buffer(base, packet, ++ buffer, payload); + spin_unlock_irqrestore(&ctx->context.ohci->lock, flags); + +- return retval; ++ return ret; + } + + static const struct fw_card_driver ohci_driver = { +@@ -2357,8 +2348,8 @@ static void ohci_pmac_off(struct pci_dev + #define ohci_pmac_off(dev) + #endif /* CONFIG_PPC_PMAC */ + +-static int __devinit +-pci_probe(struct pci_dev *dev, const struct pci_device_id *ent) ++static int __devinit pci_probe(struct pci_dev *dev, ++ const struct pci_device_id *ent) + { + struct fw_ohci *ohci; + u32 bus_options, max_receive, link_speed, version; +@@ -2440,6 +2431,7 @@ pci_probe(struct pci_dev *dev, const str + ohci->it_context_list = kzalloc(size, GFP_KERNEL); + + reg_write(ohci, OHCI1394_IsoXmitIntMaskSet, ~0); ++ ohci->ir_context_channels = ~0ULL; + ohci->ir_context_mask = reg_read(ohci, OHCI1394_IsoXmitIntMaskSet); + reg_write(ohci, OHCI1394_IsoXmitIntMaskClear, ~0); + size = sizeof(struct iso_context) * hweight32(ohci->ir_context_mask); +diff -Naurp linux-2.6-git/drivers/firewire/fw-sbp2.c firewire-git/drivers/firewire/fw-sbp2.c +--- linux-2.6-git/drivers/firewire/fw-sbp2.c 2009-01-30 13:39:02.991771976 -0500 ++++ firewire-git/drivers/firewire/fw-sbp2.c 2009-01-30 13:35:51.861646907 -0500 +@@ -392,20 +392,18 @@ static const struct { + } + }; + +-static void +-free_orb(struct kref *kref) ++static void free_orb(struct kref *kref) + { + struct sbp2_orb *orb = container_of(kref, struct sbp2_orb, kref); + + kfree(orb); + } + +-static void +-sbp2_status_write(struct fw_card *card, struct fw_request *request, +- int tcode, int destination, int source, +- int generation, int speed, +- unsigned long long offset, +- void *payload, size_t length, void *callback_data) ++static void sbp2_status_write(struct fw_card *card, struct fw_request *request, ++ int tcode, int destination, int source, ++ int generation, int speed, ++ unsigned long long offset, ++ void *payload, size_t length, void *callback_data) + { + struct sbp2_logical_unit *lu = callback_data; + struct sbp2_orb *orb; +@@ -451,9 +449,8 @@ sbp2_status_write(struct fw_card *card, + fw_send_response(card, request, RCODE_COMPLETE); + } + +-static void +-complete_transaction(struct fw_card *card, int rcode, +- void *payload, size_t length, void *data) ++static void complete_transaction(struct fw_card *card, int rcode, ++ void *payload, size_t length, void *data) + { + struct sbp2_orb *orb = data; + unsigned long flags; +@@ -482,9 +479,8 @@ complete_transaction(struct fw_card *car + kref_put(&orb->kref, free_orb); + } + +-static void +-sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, +- int node_id, int generation, u64 offset) ++static void sbp2_send_orb(struct sbp2_orb *orb, struct sbp2_logical_unit *lu, ++ int node_id, int generation, u64 offset) + { + struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + unsigned long flags; +@@ -531,8 +527,8 @@ static int sbp2_cancel_orbs(struct sbp2_ + return retval; + } + +-static void +-complete_management_orb(struct sbp2_orb *base_orb, struct sbp2_status *status) ++static void complete_management_orb(struct sbp2_orb *base_orb, ++ struct sbp2_status *status) + { + struct sbp2_management_orb *orb = + container_of(base_orb, struct sbp2_management_orb, base); +@@ -542,10 +538,9 @@ complete_management_orb(struct sbp2_orb + complete(&orb->done); + } + +-static int +-sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, +- int generation, int function, int lun_or_login_id, +- void *response) ++static int sbp2_send_management_orb(struct sbp2_logical_unit *lu, int node_id, ++ int generation, int function, ++ int lun_or_login_id, void *response) + { + struct fw_device *device = fw_device(lu->tgt->unit->device.parent); + struct sbp2_management_orb *orb; +@@ -652,9 +647,8 @@ static void sbp2_agent_reset(struct sbp2 + &d, sizeof(d)); + } + +-static void +-complete_agent_reset_write_no_wait(struct fw_card *card, int rcode, +- void *payload, size_t length, void *data) ++static void complete_agent_reset_write_no_wait(struct fw_card *card, ++ int rcode, void *payload, size_t length, void *data) + { + kfree(data); + } +@@ -1299,8 +1293,7 @@ static void sbp2_unmap_scatterlist(struc + sizeof(orb->page_table), DMA_TO_DEVICE); + } + +-static unsigned int +-sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data) ++static unsigned int sbp2_status_to_sense_data(u8 *sbp2_status, u8 *sense_data) + { + int sam_status; + +@@ -1337,8 +1330,8 @@ sbp2_status_to_sense_data(u8 *sbp2_statu + } + } + +-static void +-complete_command_orb(struct sbp2_orb *base_orb, struct sbp2_status *status) ++static void complete_command_orb(struct sbp2_orb *base_orb, ++ struct sbp2_status *status) + { + struct sbp2_command_orb *orb = + container_of(base_orb, struct sbp2_command_orb, base); +@@ -1384,9 +1377,8 @@ complete_command_orb(struct sbp2_orb *ba + orb->done(orb->cmd); + } + +-static int +-sbp2_map_scatterlist(struct sbp2_command_orb *orb, struct fw_device *device, +- struct sbp2_logical_unit *lu) ++static int sbp2_map_scatterlist(struct sbp2_command_orb *orb, ++ struct fw_device *device, struct sbp2_logical_unit *lu) + { + struct scatterlist *sg = scsi_sglist(orb->cmd); + int i, n; +@@ -1584,9 +1576,8 @@ static int sbp2_scsi_abort(struct scsi_c + * This is the concatenation of target port identifier and logical unit + * identifier as per SAM-2...SAM-4 annex A. + */ +-static ssize_t +-sbp2_sysfs_ieee1394_id_show(struct device *dev, struct device_attribute *attr, +- char *buf) ++static ssize_t sbp2_sysfs_ieee1394_id_show(struct device *dev, ++ struct device_attribute *attr, char *buf) + { + struct scsi_device *sdev = to_scsi_device(dev); + struct sbp2_logical_unit *lu; +diff -Naurp linux-2.6-git/drivers/firewire/fw-topology.c firewire-git/drivers/firewire/fw-topology.c +--- linux-2.6-git/drivers/firewire/fw-topology.c 2009-01-30 13:39:02.991771976 -0500 ++++ firewire-git/drivers/firewire/fw-topology.c 2009-01-30 13:35:51.862647087 -0500 +@@ -314,9 +314,8 @@ typedef void (*fw_node_callback_t)(struc + struct fw_node * node, + struct fw_node * parent); + +-static void +-for_each_fw_node(struct fw_card *card, struct fw_node *root, +- fw_node_callback_t callback) ++static void for_each_fw_node(struct fw_card *card, struct fw_node *root, ++ fw_node_callback_t callback) + { + struct list_head list; + struct fw_node *node, *next, *child, *parent; +@@ -349,9 +348,8 @@ for_each_fw_node(struct fw_card *card, s + fw_node_put(node); + } + +-static void +-report_lost_node(struct fw_card *card, +- struct fw_node *node, struct fw_node *parent) ++static void report_lost_node(struct fw_card *card, ++ struct fw_node *node, struct fw_node *parent) + { + fw_node_event(card, node, FW_NODE_DESTROYED); + fw_node_put(node); +@@ -360,9 +358,8 @@ report_lost_node(struct fw_card *card, + card->bm_retries = 0; + } + +-static void +-report_found_node(struct fw_card *card, +- struct fw_node *node, struct fw_node *parent) ++static void report_found_node(struct fw_card *card, ++ struct fw_node *node, struct fw_node *parent) + { + int b_path = (node->phy_speed == SCODE_BETA); + +@@ -415,8 +412,7 @@ static void move_tree(struct fw_node *no + * found, lost or updated. Update the nodes in the card topology tree + * as we go. + */ +-static void +-update_tree(struct fw_card *card, struct fw_node *root) ++static void update_tree(struct fw_card *card, struct fw_node *root) + { + struct list_head list0, list1; + struct fw_node *node0, *node1, *next1; +@@ -497,8 +493,8 @@ update_tree(struct fw_card *card, struct + } + } + +-static void +-update_topology_map(struct fw_card *card, u32 *self_ids, int self_id_count) ++static void update_topology_map(struct fw_card *card, ++ u32 *self_ids, int self_id_count) + { + int node_count; + +@@ -510,10 +506,8 @@ update_topology_map(struct fw_card *card + fw_compute_block_crc(card->topology_map); + } + +-void +-fw_core_handle_bus_reset(struct fw_card *card, +- int node_id, int generation, +- int self_id_count, u32 * self_ids) ++void fw_core_handle_bus_reset(struct fw_card *card, int node_id, int generation, ++ int self_id_count, u32 *self_ids) + { + struct fw_node *local_node; + unsigned long flags; +diff -Naurp linux-2.6-git/drivers/firewire/fw-topology.h firewire-git/drivers/firewire/fw-topology.h +--- linux-2.6-git/drivers/firewire/fw-topology.h 2008-11-04 11:18:33.000000000 -0500 ++++ firewire-git/drivers/firewire/fw-topology.h 2009-01-30 13:35:51.862647087 -0500 +@@ -19,6 +19,11 @@ + #ifndef __fw_topology_h + #define __fw_topology_h + ++#include ++#include ++ ++#include ++ + enum { + FW_NODE_CREATED, + FW_NODE_UPDATED, +@@ -51,26 +56,22 @@ struct fw_node { + struct fw_node *ports[0]; + }; + +-static inline struct fw_node * +-fw_node_get(struct fw_node *node) ++static inline struct fw_node *fw_node_get(struct fw_node *node) + { + atomic_inc(&node->ref_count); + + return node; + } + +-static inline void +-fw_node_put(struct fw_node *node) ++static inline void fw_node_put(struct fw_node *node) + { + if (atomic_dec_and_test(&node->ref_count)) + kfree(node); + } + +-void +-fw_destroy_nodes(struct fw_card *card); +- +-int +-fw_compute_block_crc(u32 *block); ++struct fw_card; ++void fw_destroy_nodes(struct fw_card *card); + ++int fw_compute_block_crc(u32 *block); + + #endif /* __fw_topology_h */ +diff -Naurp linux-2.6-git/drivers/firewire/fw-transaction.c firewire-git/drivers/firewire/fw-transaction.c +--- linux-2.6-git/drivers/firewire/fw-transaction.c 2009-01-30 13:39:02.991771976 -0500 ++++ firewire-git/drivers/firewire/fw-transaction.c 2009-01-30 13:35:51.862647087 -0500 +@@ -64,10 +64,9 @@ + #define PHY_CONFIG_ROOT_ID(node_id) ((((node_id) & 0x3f) << 24) | (1 << 23)) + #define PHY_IDENTIFIER(id) ((id) << 30) + +-static int +-close_transaction(struct fw_transaction *transaction, +- struct fw_card *card, int rcode, +- u32 *payload, size_t length) ++static int close_transaction(struct fw_transaction *transaction, ++ struct fw_card *card, int rcode, ++ u32 *payload, size_t length) + { + struct fw_transaction *t; + unsigned long flags; +@@ -94,9 +93,8 @@ close_transaction(struct fw_transaction + * Only valid for transactions that are potentially pending (ie have + * been sent). + */ +-int +-fw_cancel_transaction(struct fw_card *card, +- struct fw_transaction *transaction) ++int fw_cancel_transaction(struct fw_card *card, ++ struct fw_transaction *transaction) + { + /* + * Cancel the packet transmission if it's still queued. That +@@ -116,9 +114,8 @@ fw_cancel_transaction(struct fw_card *ca + } + EXPORT_SYMBOL(fw_cancel_transaction); + +-static void +-transmit_complete_callback(struct fw_packet *packet, +- struct fw_card *card, int status) ++static void transmit_complete_callback(struct fw_packet *packet, ++ struct fw_card *card, int status) + { + struct fw_transaction *t = + container_of(packet, struct fw_transaction, packet); +@@ -151,8 +148,7 @@ transmit_complete_callback(struct fw_pac + } + } + +-static void +-fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, ++static void fw_fill_request(struct fw_packet *packet, int tcode, int tlabel, + int destination_id, int source_id, int generation, int speed, + unsigned long long offset, void *payload, size_t length) + { +@@ -247,12 +243,10 @@ fw_fill_request(struct fw_packet *packet + * @param callback_data pointer to arbitrary data, which will be + * passed to the callback + */ +-void +-fw_send_request(struct fw_card *card, struct fw_transaction *t, +- int tcode, int destination_id, int generation, int speed, +- unsigned long long offset, +- void *payload, size_t length, +- fw_transaction_callback_t callback, void *callback_data) ++void fw_send_request(struct fw_card *card, struct fw_transaction *t, int tcode, ++ int destination_id, int generation, int speed, ++ unsigned long long offset, void *payload, size_t length, ++ fw_transaction_callback_t callback, void *callback_data) + { + unsigned long flags; + int tlabel; +@@ -322,8 +316,8 @@ static void transaction_callback(struct + * Returns the RCODE. + */ + int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, +- int generation, int speed, unsigned long long offset, +- void *data, size_t length) ++ int generation, int speed, unsigned long long offset, ++ void *data, size_t length) + { + struct transaction_callback_data d; + struct fw_transaction t; +@@ -399,9 +393,8 @@ void fw_flush_transactions(struct fw_car + } + } + +-static struct fw_address_handler * +-lookup_overlapping_address_handler(struct list_head *list, +- unsigned long long offset, size_t length) ++static struct fw_address_handler *lookup_overlapping_address_handler( ++ struct list_head *list, unsigned long long offset, size_t length) + { + struct fw_address_handler *handler; + +@@ -414,9 +407,8 @@ lookup_overlapping_address_handler(struc + return NULL; + } + +-static struct fw_address_handler * +-lookup_enclosing_address_handler(struct list_head *list, +- unsigned long long offset, size_t length) ++static struct fw_address_handler *lookup_enclosing_address_handler( ++ struct list_head *list, unsigned long long offset, size_t length) + { + struct fw_address_handler *handler; + +@@ -449,36 +441,44 @@ const struct fw_address_region fw_unit_s + #endif /* 0 */ + + /** +- * Allocate a range of addresses in the node space of the OHCI +- * controller. When a request is received that falls within the +- * specified address range, the specified callback is invoked. The +- * parameters passed to the callback give the details of the +- * particular request. ++ * fw_core_add_address_handler - register for incoming requests ++ * @handler: callback ++ * @region: region in the IEEE 1212 node space address range ++ * ++ * region->start, ->end, and handler->length have to be quadlet-aligned. ++ * ++ * When a request is received that falls within the specified address range, ++ * the specified callback is invoked. The parameters passed to the callback ++ * give the details of the particular request. + * + * Return value: 0 on success, non-zero otherwise. + * The start offset of the handler's address region is determined by + * fw_core_add_address_handler() and is returned in handler->offset. +- * The offset is quadlet-aligned. + */ +-int +-fw_core_add_address_handler(struct fw_address_handler *handler, +- const struct fw_address_region *region) ++int fw_core_add_address_handler(struct fw_address_handler *handler, ++ const struct fw_address_region *region) + { + struct fw_address_handler *other; + unsigned long flags; + int ret = -EBUSY; + ++ if (region->start & 0xffff000000000003ULL || ++ region->end & 0xffff000000000003ULL || ++ region->start >= region->end || ++ handler->length & 3 || ++ handler->length == 0) ++ return -EINVAL; ++ + spin_lock_irqsave(&address_handler_lock, flags); + +- handler->offset = roundup(region->start, 4); ++ handler->offset = region->start; + while (handler->offset + handler->length <= region->end) { + other = + lookup_overlapping_address_handler(&address_handler_list, + handler->offset, + handler->length); + if (other != NULL) { +- handler->offset = +- roundup(other->offset + other->length, 4); ++ handler->offset += other->length; + } else { + list_add_tail(&handler->link, &address_handler_list); + ret = 0; +@@ -493,12 +493,7 @@ fw_core_add_address_handler(struct fw_ad + EXPORT_SYMBOL(fw_core_add_address_handler); + + /** +- * Deallocate a range of addresses allocated with fw_allocate. This +- * will call the associated callback one last time with a the special +- * tcode TCODE_DEALLOCATE, to let the client destroy the registered +- * callback data. For convenience, the callback parameters offset and +- * length are set to the start and the length respectively for the +- * deallocated region, payload is set to NULL. ++ * fw_core_remove_address_handler - unregister an address handler + */ + void fw_core_remove_address_handler(struct fw_address_handler *handler) + { +@@ -518,9 +513,8 @@ struct fw_request { + u32 data[0]; + }; + +-static void +-free_response_callback(struct fw_packet *packet, +- struct fw_card *card, int status) ++static void free_response_callback(struct fw_packet *packet, ++ struct fw_card *card, int status) + { + struct fw_request *request; + +@@ -528,9 +522,8 @@ free_response_callback(struct fw_packet + kfree(request); + } + +-void +-fw_fill_response(struct fw_packet *response, u32 *request_header, +- int rcode, void *payload, size_t length) ++void fw_fill_response(struct fw_packet *response, u32 *request_header, ++ int rcode, void *payload, size_t length) + { + int tcode, tlabel, extended_tcode, source, destination; + +@@ -588,8 +581,7 @@ fw_fill_response(struct fw_packet *respo + } + EXPORT_SYMBOL(fw_fill_response); + +-static struct fw_request * +-allocate_request(struct fw_packet *p) ++static struct fw_request *allocate_request(struct fw_packet *p) + { + struct fw_request *request; + u32 *data, length; +@@ -649,8 +641,8 @@ allocate_request(struct fw_packet *p) + return request; + } + +-void +-fw_send_response(struct fw_card *card, struct fw_request *request, int rcode) ++void fw_send_response(struct fw_card *card, ++ struct fw_request *request, int rcode) + { + /* unified transaction or broadcast transaction: don't respond */ + if (request->ack != ACK_PENDING || +@@ -670,8 +662,7 @@ fw_send_response(struct fw_card *card, s + } + EXPORT_SYMBOL(fw_send_response); + +-void +-fw_core_handle_request(struct fw_card *card, struct fw_packet *p) ++void fw_core_handle_request(struct fw_card *card, struct fw_packet *p) + { + struct fw_address_handler *handler; + struct fw_request *request; +@@ -719,8 +710,7 @@ fw_core_handle_request(struct fw_card *c + } + EXPORT_SYMBOL(fw_core_handle_request); + +-void +-fw_core_handle_response(struct fw_card *card, struct fw_packet *p) ++void fw_core_handle_response(struct fw_card *card, struct fw_packet *p) + { + struct fw_transaction *t; + unsigned long flags; +@@ -793,12 +783,10 @@ static const struct fw_address_region to + { .start = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP, + .end = CSR_REGISTER_BASE | CSR_TOPOLOGY_MAP_END, }; + +-static void +-handle_topology_map(struct fw_card *card, struct fw_request *request, +- int tcode, int destination, int source, +- int generation, int speed, +- unsigned long long offset, +- void *payload, size_t length, void *callback_data) ++static void handle_topology_map(struct fw_card *card, struct fw_request *request, ++ int tcode, int destination, int source, int generation, ++ int speed, unsigned long long offset, ++ void *payload, size_t length, void *callback_data) + { + int i, start, end; + __be32 *map; +@@ -832,12 +820,10 @@ static const struct fw_address_region re + { .start = CSR_REGISTER_BASE, + .end = CSR_REGISTER_BASE | CSR_CONFIG_ROM, }; + +-static void +-handle_registers(struct fw_card *card, struct fw_request *request, +- int tcode, int destination, int source, +- int generation, int speed, +- unsigned long long offset, +- void *payload, size_t length, void *callback_data) ++static void handle_registers(struct fw_card *card, struct fw_request *request, ++ int tcode, int destination, int source, int generation, ++ int speed, unsigned long long offset, ++ void *payload, size_t length, void *callback_data) + { + int reg = offset & ~CSR_REGISTER_BASE; + unsigned long long bus_time; +@@ -939,11 +925,11 @@ static struct fw_descriptor model_id_des + + static int __init fw_core_init(void) + { +- int retval; ++ int ret; + +- retval = bus_register(&fw_bus_type); +- if (retval < 0) +- return retval; ++ ret = bus_register(&fw_bus_type); ++ if (ret < 0) ++ return ret; + + fw_cdev_major = register_chrdev(0, "firewire", &fw_device_ops); + if (fw_cdev_major < 0) { +@@ -951,19 +937,10 @@ static int __init fw_core_init(void) + return fw_cdev_major; + } + +- retval = fw_core_add_address_handler(&topology_map, +- &topology_map_region); +- BUG_ON(retval < 0); +- +- retval = fw_core_add_address_handler(®isters, +- ®isters_region); +- BUG_ON(retval < 0); +- +- /* Add the vendor textual descriptor. */ +- retval = fw_core_add_descriptor(&vendor_id_descriptor); +- BUG_ON(retval < 0); +- retval = fw_core_add_descriptor(&model_id_descriptor); +- BUG_ON(retval < 0); ++ fw_core_add_address_handler(&topology_map, &topology_map_region); ++ fw_core_add_address_handler(®isters, ®isters_region); ++ fw_core_add_descriptor(&vendor_id_descriptor); ++ fw_core_add_descriptor(&model_id_descriptor); + + return 0; + } +diff -Naurp linux-2.6-git/drivers/firewire/fw-transaction.h firewire-git/drivers/firewire/fw-transaction.h +--- linux-2.6-git/drivers/firewire/fw-transaction.h 2009-01-30 13:39:02.992772636 -0500 ++++ firewire-git/drivers/firewire/fw-transaction.h 2009-01-30 13:35:51.862647087 -0500 +@@ -82,14 +82,14 @@ + #define CSR_SPEED_MAP 0x2000 + #define CSR_SPEED_MAP_END 0x3000 + ++#define BANDWIDTH_AVAILABLE_INITIAL 4915 + #define BROADCAST_CHANNEL_INITIAL (1 << 31 | 31) + #define BROADCAST_CHANNEL_VALID (1 << 30) + + #define fw_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, ## args) + #define fw_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) + +-static inline void +-fw_memcpy_from_be32(void *_dst, void *_src, size_t size) ++static inline void fw_memcpy_from_be32(void *_dst, void *_src, size_t size) + { + u32 *dst = _dst; + __be32 *src = _src; +@@ -99,8 +99,7 @@ fw_memcpy_from_be32(void *_dst, void *_s + dst[i] = be32_to_cpu(src[i]); + } + +-static inline void +-fw_memcpy_to_be32(void *_dst, void *_src, size_t size) ++static inline void fw_memcpy_to_be32(void *_dst, void *_src, size_t size) + { + fw_memcpy_from_be32(_dst, _src, size); + } +@@ -125,8 +124,7 @@ typedef void (*fw_packet_callback_t)(str + struct fw_card *card, int status); + + typedef void (*fw_transaction_callback_t)(struct fw_card *card, int rcode, +- void *data, +- size_t length, ++ void *data, size_t length, + void *callback_data); + + /* +@@ -141,12 +139,6 @@ typedef void (*fw_address_callback_t)(st + void *data, size_t length, + void *callback_data); + +-typedef void (*fw_bus_reset_callback_t)(struct fw_card *handle, +- int node_id, int generation, +- u32 *self_ids, +- int self_id_count, +- void *callback_data); +- + struct fw_packet { + int speed; + int generation; +@@ -187,12 +179,6 @@ struct fw_transaction { + void *callback_data; + }; + +-static inline struct fw_packet * +-fw_packet(struct list_head *l) +-{ +- return list_entry(l, struct fw_packet, link); +-} +- + struct fw_address_handler { + u64 offset; + size_t length; +@@ -201,7 +187,6 @@ struct fw_address_handler { + struct list_head link; + }; + +- + struct fw_address_region { + u64 start; + u64 end; +@@ -315,10 +300,8 @@ struct fw_iso_packet { + struct fw_iso_context; + + typedef void (*fw_iso_callback_t)(struct fw_iso_context *context, +- u32 cycle, +- size_t header_length, +- void *header, +- void *data); ++ u32 cycle, size_t header_length, ++ void *header, void *data); + + /* + * An iso buffer is just a set of pages mapped for DMA in the +@@ -344,36 +327,25 @@ struct fw_iso_context { + void *callback_data; + }; + +-int +-fw_iso_buffer_init(struct fw_iso_buffer *buffer, +- struct fw_card *card, +- int page_count, +- enum dma_data_direction direction); +-int +-fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma); +-void +-fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card); +- +-struct fw_iso_context * +-fw_iso_context_create(struct fw_card *card, int type, +- int channel, int speed, size_t header_size, +- fw_iso_callback_t callback, void *callback_data); +- +-void +-fw_iso_context_destroy(struct fw_iso_context *ctx); +- +-int +-fw_iso_context_queue(struct fw_iso_context *ctx, +- struct fw_iso_packet *packet, +- struct fw_iso_buffer *buffer, +- unsigned long payload); +- +-int +-fw_iso_context_start(struct fw_iso_context *ctx, +- int cycle, int sync, int tags); ++int fw_iso_buffer_init(struct fw_iso_buffer *buffer, struct fw_card *card, ++ int page_count, enum dma_data_direction direction); ++int fw_iso_buffer_map(struct fw_iso_buffer *buffer, struct vm_area_struct *vma); ++void fw_iso_buffer_destroy(struct fw_iso_buffer *buffer, struct fw_card *card); ++ ++struct fw_iso_context *fw_iso_context_create(struct fw_card *card, ++ int type, int channel, int speed, size_t header_size, ++ fw_iso_callback_t callback, void *callback_data); ++int fw_iso_context_queue(struct fw_iso_context *ctx, ++ struct fw_iso_packet *packet, ++ struct fw_iso_buffer *buffer, ++ unsigned long payload); ++int fw_iso_context_start(struct fw_iso_context *ctx, ++ int cycle, int sync, int tags); ++int fw_iso_context_stop(struct fw_iso_context *ctx); ++void fw_iso_context_destroy(struct fw_iso_context *ctx); + +-int +-fw_iso_context_stop(struct fw_iso_context *ctx); ++void fw_iso_resource_manage(struct fw_card *card, int generation, ++ u64 channels_mask, int *channel, int *bandwidth, bool allocate); + + struct fw_card_driver { + /* +@@ -415,7 +387,7 @@ struct fw_card_driver { + + struct fw_iso_context * + (*allocate_iso_context)(struct fw_card *card, +- int type, size_t header_size); ++ int type, int channel, size_t header_size); + void (*free_iso_context)(struct fw_iso_context *ctx); + + int (*start_iso)(struct fw_iso_context *ctx, +@@ -429,24 +401,18 @@ struct fw_card_driver { + int (*stop_iso)(struct fw_iso_context *ctx); + }; + +-int +-fw_core_initiate_bus_reset(struct fw_card *card, int short_reset); ++int fw_core_initiate_bus_reset(struct fw_card *card, int short_reset); + +-void +-fw_send_request(struct fw_card *card, struct fw_transaction *t, ++void fw_send_request(struct fw_card *card, struct fw_transaction *t, + int tcode, int destination_id, int generation, int speed, + unsigned long long offset, void *data, size_t length, + fw_transaction_callback_t callback, void *callback_data); +- +-int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, +- int generation, int speed, unsigned long long offset, +- void *data, size_t length); +- + int fw_cancel_transaction(struct fw_card *card, + struct fw_transaction *transaction); +- + void fw_flush_transactions(struct fw_card *card); +- ++int fw_run_transaction(struct fw_card *card, int tcode, int destination_id, ++ int generation, int speed, unsigned long long offset, ++ void *data, size_t length); + void fw_send_phy_config(struct fw_card *card, + int node_id, int generation, int gap_count); + +@@ -454,29 +420,18 @@ void fw_send_phy_config(struct fw_card * + * Called by the topology code to inform the device code of node + * activity; found, lost, or updated nodes. + */ +-void +-fw_node_event(struct fw_card *card, struct fw_node *node, int event); ++void fw_node_event(struct fw_card *card, struct fw_node *node, int event); + + /* API used by card level drivers */ + +-void +-fw_card_initialize(struct fw_card *card, const struct fw_card_driver *driver, +- struct device *device); +-int +-fw_card_add(struct fw_card *card, +- u32 max_receive, u32 link_speed, u64 guid); +- +-void +-fw_core_remove_card(struct fw_card *card); +- +-void +-fw_core_handle_bus_reset(struct fw_card *card, +- int node_id, int generation, +- int self_id_count, u32 *self_ids); +-void +-fw_core_handle_request(struct fw_card *card, struct fw_packet *request); +- +-void +-fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); ++void fw_card_initialize(struct fw_card *card, ++ const struct fw_card_driver *driver, struct device *device); ++int fw_card_add(struct fw_card *card, ++ u32 max_receive, u32 link_speed, u64 guid); ++void fw_core_remove_card(struct fw_card *card); ++void fw_core_handle_bus_reset(struct fw_card *card, int node_id, ++ int generation, int self_id_count, u32 *self_ids); ++void fw_core_handle_request(struct fw_card *card, struct fw_packet *request); ++void fw_core_handle_response(struct fw_card *card, struct fw_packet *packet); + + #endif /* __fw_transaction_h */ +--- linux-2.6-git/include/linux/firewire-cdev.h 2008-11-04 11:19:21.000000000 -0500 ++++ firewire-git/include/linux/firewire-cdev.h 2009-01-30 13:35:54.327647015 -0500 +@@ -25,10 +25,12 @@ + #include + #include + +-#define FW_CDEV_EVENT_BUS_RESET 0x00 +-#define FW_CDEV_EVENT_RESPONSE 0x01 +-#define FW_CDEV_EVENT_REQUEST 0x02 +-#define FW_CDEV_EVENT_ISO_INTERRUPT 0x03 ++#define FW_CDEV_EVENT_BUS_RESET 0x00 ++#define FW_CDEV_EVENT_RESPONSE 0x01 ++#define FW_CDEV_EVENT_REQUEST 0x02 ++#define FW_CDEV_EVENT_ISO_INTERRUPT 0x03 ++#define FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED 0x04 ++#define FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED 0x05 + + /** + * struct fw_cdev_event_common - Common part of all fw_cdev_event_ types +@@ -136,7 +138,24 @@ struct fw_cdev_event_request { + * This event is sent when the controller has completed an &fw_cdev_iso_packet + * with the %FW_CDEV_ISO_INTERRUPT bit set. In the receive case, the headers + * stripped of all packets up until and including the interrupt packet are +- * returned in the @header field. ++ * returned in the @header field. The amount of header data per packet is as ++ * specified at iso context creation by &fw_cdev_create_iso_context.header_size. ++ * ++ * In version 1 of this ABI, header data consisted of the 1394 isochronous ++ * packet header, followed by quadlets from the packet payload if ++ * &fw_cdev_create_iso_context.header_size > 4. ++ * ++ * In version 2 of this ABI, header data consist of the 1394 isochronous ++ * packet header, followed by a timestamp quadlet if ++ * &fw_cdev_create_iso_context.header_size > 4, followed by quadlets from the ++ * packet payload if &fw_cdev_create_iso_context.header_size > 8. ++ * ++ * Behaviour of ver. 1 of this ABI is no longer available since ABI ver. 2. ++ * ++ * Format of 1394 iso packet header: 16 bits len, 2 bits tag, 6 bits channel, ++ * 4 bits tcode, 4 bits sy, in big endian byte order. Format of timestamp: ++ * 16 bits invalid, 3 bits cycleSeconds, 13 bits cycleCount, in big endian byte ++ * order. + */ + struct fw_cdev_event_iso_interrupt { + __u64 closure; +@@ -147,12 +166,44 @@ struct fw_cdev_event_iso_interrupt { + }; + + /** ++ * struct fw_cdev_event_iso_resource - Iso resources were allocated or freed ++ * @closure: See &fw_cdev_event_common; ++ * set by %FW_CDEV_IOC_(DE)ALLOCATE_ISO_RESOURCE(_ONCE) ioctl ++ * @type: %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or ++ * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED ++ * @handle: Reference by which an allocated resource can be deallocated ++ * @channel: Isochronous channel which was (de)allocated, if any ++ * @bandwidth: Bandwidth allocation units which were (de)allocated, if any ++ * ++ * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event is sent after an isochronous ++ * resource was allocated at the IRM. The client has to check @channel and ++ * @bandwidth for whether the allocation actually succeeded. ++ * ++ * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event is sent after an isochronous ++ * resource was deallocated at the IRM. It is also sent when automatic ++ * reallocation after a bus reset failed. ++ * ++ * @channel is <0 if no channel was (de)allocated or if reallocation failed. ++ * @bandwidth is 0 if no bandwidth was (de)allocated or if reallocation failed. ++ */ ++struct fw_cdev_event_iso_resource { ++ __u64 closure; ++ __u32 type; ++ __u32 handle; ++ __s32 channel; ++ __s32 bandwidth; ++}; ++ ++/** + * union fw_cdev_event - Convenience union of fw_cdev_event_ types + * @common: Valid for all types + * @bus_reset: Valid if @common.type == %FW_CDEV_EVENT_BUS_RESET + * @response: Valid if @common.type == %FW_CDEV_EVENT_RESPONSE + * @request: Valid if @common.type == %FW_CDEV_EVENT_REQUEST + * @iso_interrupt: Valid if @common.type == %FW_CDEV_EVENT_ISO_INTERRUPT ++ * @iso_resource: Valid if @common.type == ++ * %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED or ++ * %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED + * + * Convenience union for userspace use. Events could be read(2) into an + * appropriately aligned char buffer and then cast to this union for further +@@ -163,13 +214,15 @@ struct fw_cdev_event_iso_interrupt { + * not fit will be discarded so that the next read(2) will return a new event. + */ + union fw_cdev_event { +- struct fw_cdev_event_common common; +- struct fw_cdev_event_bus_reset bus_reset; +- struct fw_cdev_event_response response; +- struct fw_cdev_event_request request; +- struct fw_cdev_event_iso_interrupt iso_interrupt; ++ struct fw_cdev_event_common common; ++ struct fw_cdev_event_bus_reset bus_reset; ++ struct fw_cdev_event_response response; ++ struct fw_cdev_event_request request; ++ struct fw_cdev_event_iso_interrupt iso_interrupt; ++ struct fw_cdev_event_iso_resource iso_resource; + }; + ++/* available since kernel version 2.6.22 */ + #define FW_CDEV_IOC_GET_INFO _IOWR('#', 0x00, struct fw_cdev_get_info) + #define FW_CDEV_IOC_SEND_REQUEST _IOW('#', 0x01, struct fw_cdev_send_request) + #define FW_CDEV_IOC_ALLOCATE _IOWR('#', 0x02, struct fw_cdev_allocate) +@@ -178,18 +231,29 @@ union fw_cdev_event { + #define FW_CDEV_IOC_INITIATE_BUS_RESET _IOW('#', 0x05, struct fw_cdev_initiate_bus_reset) + #define FW_CDEV_IOC_ADD_DESCRIPTOR _IOWR('#', 0x06, struct fw_cdev_add_descriptor) + #define FW_CDEV_IOC_REMOVE_DESCRIPTOR _IOW('#', 0x07, struct fw_cdev_remove_descriptor) +- + #define FW_CDEV_IOC_CREATE_ISO_CONTEXT _IOWR('#', 0x08, struct fw_cdev_create_iso_context) + #define FW_CDEV_IOC_QUEUE_ISO _IOWR('#', 0x09, struct fw_cdev_queue_iso) + #define FW_CDEV_IOC_START_ISO _IOW('#', 0x0a, struct fw_cdev_start_iso) + #define FW_CDEV_IOC_STOP_ISO _IOW('#', 0x0b, struct fw_cdev_stop_iso) ++ ++/* available since kernel version 2.6.24 */ + #define FW_CDEV_IOC_GET_CYCLE_TIMER _IOR('#', 0x0c, struct fw_cdev_get_cycle_timer) + +-/* FW_CDEV_VERSION History +- * +- * 1 Feb 18, 2007: Initial version. ++/* available since kernel version 2.6.30 */ ++#define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE _IOWR('#', 0x0d, struct fw_cdev_allocate_iso_resource) ++#define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE _IOW('#', 0x0e, struct fw_cdev_deallocate) ++#define FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x0f, struct fw_cdev_allocate_iso_resource) ++#define FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE _IOW('#', 0x10, struct fw_cdev_allocate_iso_resource) ++#define FW_CDEV_IOC_GET_SPEED _IOR('#', 0x11, struct fw_cdev_get_speed) ++#define FW_CDEV_IOC_SEND_BROADCAST_REQUEST _IOW('#', 0x12, struct fw_cdev_send_request) ++ ++/* ++ * FW_CDEV_VERSION History ++ * 1 (2.6.22) - initial version ++ * 2 (2.6.30) - changed &fw_cdev_event_iso_interrupt.header if ++ * &fw_cdev_create_iso_context.header_size is 8 or more + */ +-#define FW_CDEV_VERSION 1 ++#define FW_CDEV_VERSION 2 + + /** + * struct fw_cdev_get_info - General purpose information ioctl +@@ -201,7 +265,7 @@ union fw_cdev_event { + * case, @rom_length is updated with the actual length of the + * configuration ROM. + * @rom: If non-zero, address of a buffer to be filled by a copy of the +- * local node's configuration ROM ++ * device's configuration ROM + * @bus_reset: If non-zero, address of a buffer to be filled by a + * &struct fw_cdev_event_bus_reset with the current state + * of the bus. This does not cause a bus reset to happen. +@@ -229,7 +293,7 @@ struct fw_cdev_get_info { + * Send a request to the device. This ioctl implements all outgoing requests. + * Both quadlet and block request specify the payload as a pointer to the data + * in the @data field. Once the transaction completes, the kernel writes an +- * &fw_cdev_event_request event back. The @closure field is passed back to ++ * &fw_cdev_event_response event back. The @closure field is passed back to + * user space in the response event. + */ + struct fw_cdev_send_request { +@@ -284,9 +348,9 @@ struct fw_cdev_allocate { + }; + + /** +- * struct fw_cdev_deallocate - Free an address range allocation +- * @handle: Handle to the address range, as returned by the kernel when the +- * range was allocated ++ * struct fw_cdev_deallocate - Free a CSR address range or isochronous resource ++ * @handle: Handle to the address range or iso resource, as returned by the ++ * kernel when the range or resource was allocated + */ + struct fw_cdev_deallocate { + __u32 handle; +@@ -370,6 +434,9 @@ struct fw_cdev_remove_descriptor { + * + * If a context was successfully created, the kernel writes back a handle to the + * context, which must be passed in for subsequent operations on that context. ++ * ++ * Note that the effect of a @header_size > 4 depends on ++ * &fw_cdev_get_info.version, as documented at &fw_cdev_event_iso_interrupt. + */ + struct fw_cdev_create_iso_context { + __u32 type; +@@ -473,10 +540,73 @@ struct fw_cdev_stop_iso { + * The %FW_CDEV_IOC_GET_CYCLE_TIMER ioctl reads the isochronous cycle timer + * and also the system clock. This allows to express the receive time of an + * isochronous packet as a system time with microsecond accuracy. ++ * ++ * @cycle_timer consists of 7 bits cycleSeconds, 13 bits cycleCount, and ++ * 12 bits cycleOffset, in host byte order. + */ + struct fw_cdev_get_cycle_timer { + __u64 local_time; + __u32 cycle_timer; + }; + ++/** ++ * struct fw_cdev_allocate_iso_resource - (De)allocate a channel or bandwidth ++ * @closure: Passed back to userspace in correponding iso resource events ++ * @channels: Isochronous channels of which one is to be (de)allocated ++ * @bandwidth: Isochronous bandwidth units to be (de)allocated ++ * @handle: Handle to the allocation, written by the kernel (only valid in ++ * case of %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctls) ++ * ++ * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE ioctl initiates allocation of an ++ * isochronous channel and/or of isochronous bandwidth at the isochronous ++ * resource manager (IRM). Only one of the channels specified in @channels is ++ * allocated. An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED is sent after ++ * communication with the IRM, indicating success or failure in the event data. ++ * The kernel will automatically reallocate the resources after bus resets. ++ * Should a reallocation fail, an %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event ++ * will be sent. The kernel will also automatically deallocate the resources ++ * when the file descriptor is closed. ++ * ++ * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE ioctl can be used to initiate ++ * deallocation of resources which were allocated as described above. ++ * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation. ++ * ++ * The %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE ioctl is a variant of allocation ++ * without automatic re- or deallocation. ++ * An %FW_CDEV_EVENT_ISO_RESOURCE_ALLOCATED event concludes this operation, ++ * indicating success or failure in its data. ++ * ++ * The %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE_ONCE ioctl works like ++ * %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE except that resources are freed ++ * instead of allocated. ++ * An %FW_CDEV_EVENT_ISO_RESOURCE_DEALLOCATED event concludes this operation. ++ * ++ * To summarize, %FW_CDEV_IOC_DEALLOCATE_ISO_RESOURCE allocates iso resources ++ * for the lifetime of the fd or handle. ++ * In contrast, %FW_CDEV_IOC_ALLOCATE_ISO_RESOURCE_ONCE allocates iso resources ++ * for the duration of a bus generation. ++ * ++ * @channels is a host-endian bitfield with the least significant bit ++ * representing channel 0 and the most significant bit representing channel 63: ++ * 1ULL << c for each channel c that is a candidate for (de)allocation. ++ * ++ * @bandwidth is expressed in bandwidth allocation units, i.e. the time to send ++ * one quadlet of data (payload or header data) at speed S1600. ++ */ ++struct fw_cdev_allocate_iso_resource { ++ __u64 closure; ++ __u64 channels; ++ __u32 bandwidth; ++ __u32 handle; ++}; ++ ++/** ++ * struct fw_cdev_get_speed - Query maximum speed to or from this device ++ * @max_speed: Speed code; minimum of the device's link speed, the local node's ++ * link speed, and all PHY port speeds between the two links ++ */ ++struct fw_cdev_get_speed { ++ __u32 max_speed; ++}; ++ + #endif /* _LINUX_FIREWIRE_CDEV_H */ diff --git a/linux-2.6-fix-btusb-autosuspend.patch b/linux-2.6-fix-btusb-autosuspend.patch new file mode 100644 index 000000000..2dad6fe42 --- /dev/null +++ b/linux-2.6-fix-btusb-autosuspend.patch @@ -0,0 +1,18 @@ +commit ae69717118e1f14ed8737459f8c4baca1cb9c404 +Author: Matthew Garrett +Date: Wed Dec 16 14:31:30 2009 -0500 + + Fix btusb autosuspend + +diff --git a/drivers/bluetooth/btusb.c b/drivers/bluetooth/btusb.c +index 4c33417..ec54dd6 100644 +--- a/drivers/bluetooth/btusb.c ++++ b/drivers/bluetooth/btusb.c +@@ -307,6 +307,7 @@ static void btusb_bulk_complete(struct urb *urb) + return; + + usb_anchor_urb(urb, &data->bulk_anchor); ++ usb_mark_last_busy(data->udev); + + err = usb_submit_urb(urb, GFP_ATOMIC); + if (err < 0) { diff --git a/linux-2.6-fix-usb-serial-autosuspend.diff b/linux-2.6-fix-usb-serial-autosuspend.diff new file mode 100644 index 000000000..c58dfd681 --- /dev/null +++ b/linux-2.6-fix-usb-serial-autosuspend.diff @@ -0,0 +1,49 @@ +commit 3b8e1210f0a558145ba87eddb20f7b104676d6f6 +Author: Oliber Neukum +Date: Sat Jul 18 07:19:04 2009 +0200 + + usb: fix counter logic in opening serial converters + + the usage counter must be increased only after autoresumption + +diff --git a/drivers/usb/serial/usb-serial.c b/drivers/usb/serial/usb-serial.c +index 99188c9..3d1a756 100644 +--- a/drivers/usb/serial/usb-serial.c ++++ b/drivers/usb/serial/usb-serial.c +@@ -216,16 +216,15 @@ static int serial_open (struct tty_struct *tty, struct file *filp) + goto bailout_port_put; + } + +- ++port->port.count; +- + /* set up our port structure making the tty driver + * remember our port object, and us it */ + tty->driver_data = port; + tty_port_tty_set(&port->port, tty); + + /* If the console is attached, the device is already open */ +- if (port->port.count == 1 && !port->console) { ++ if (!port->port.count && !port->console) { + first = 1; ++ + /* lock this module before we call it + * this may fail, which means we must bail out, + * safe because we are called with BKL held */ +@@ -242,6 +241,8 @@ static int serial_open (struct tty_struct *tty, struct file *filp) + if (retval) + goto bailout_module_put; + ++ ++port->port.count; ++ + /* only call the device specific open if this + * is the first time the port is opened */ + retval = serial->type->open(tty, port, filp); +@@ -249,6 +250,8 @@ static int serial_open (struct tty_struct *tty, struct file *filp) + goto bailout_interface_put; + mutex_unlock(&serial->disc_mutex); + set_bit(ASYNCB_INITIALIZED, &port->port.flags); ++ } else { ++ ++port->port.count; + } + mutex_unlock(&port->mutex); + /* Now do the correct tty layer semantics */ diff --git a/linux-2.6-g5-therm-shutdown.patch b/linux-2.6-g5-therm-shutdown.patch new file mode 100644 index 000000000..1471ef1bb --- /dev/null +++ b/linux-2.6-g5-therm-shutdown.patch @@ -0,0 +1,70 @@ +--- linux-2.6.15/drivers/macintosh/therm_pm72.c.orig 2006-04-02 21:34:48.000000000 +0100 ++++ linux-2.6.15/drivers/macintosh/therm_pm72.c 2006-04-02 22:33:27.000000000 +0100 +@@ -924,10 +925,16 @@ static void do_monitor_cpu_combined(void + printk(KERN_WARNING "Warning ! Temperature way above maximum (%d) !\n", + temp_combi >> 16); + state0->overtemp += CPU_MAX_OVERTEMP / 4; +- } else if (temp_combi > (state0->mpu.tmax << 16)) ++ } else if (temp_combi > (state0->mpu.tmax << 16)) { + state0->overtemp++; +- else ++ printk(KERN_WARNING "Temperature %d above max %d. overtemp %d\n", ++ temp_combi >> 16, state0->mpu.tmax, state0->overtemp); ++ } else { ++ if (state0->overtemp) ++ printk(KERN_WARNING "Temperature back down to %d\n", ++ temp_combi >> 16); + state0->overtemp = 0; ++ } + if (state0->overtemp >= CPU_MAX_OVERTEMP) + critical_state = 1; + if (state0->overtemp > 0) { +@@ -999,10 +1015,16 @@ static void do_monitor_cpu_split(struct + " (%d) !\n", + state->index, temp >> 16); + state->overtemp += CPU_MAX_OVERTEMP / 4; +- } else if (temp > (state->mpu.tmax << 16)) ++ } else if (temp > (state->mpu.tmax << 16)) { + state->overtemp++; +- else ++ printk(KERN_WARNING "CPU %d temperature %d above max %d. overtemp %d\n", ++ state->index, temp >> 16, state->mpu.tmax, state->overtemp); ++ } else { ++ if (state->overtemp) ++ printk(KERN_WARNING "CPU %d temperature back down to %d\n", ++ state->index, temp >> 16); + state->overtemp = 0; ++ } + if (state->overtemp >= CPU_MAX_OVERTEMP) + critical_state = 1; + if (state->overtemp > 0) { +@@ -1061,10 +1097,16 @@ static void do_monitor_cpu_rack(struct c + " (%d) !\n", + state->index, temp >> 16); + state->overtemp = CPU_MAX_OVERTEMP / 4; +- } else if (temp > (state->mpu.tmax << 16)) ++ } else if (temp > (state->mpu.tmax << 16)) { + state->overtemp++; +- else ++ printk(KERN_WARNING "CPU %d temperature %d above max %d. overtemp %d\n", ++ state->index, temp >> 16, state->mpu.tmax, state->overtemp); ++ } else { ++ if (state->overtemp) ++ printk(KERN_WARNING "CPU %d temperature back down to %d\n", ++ state->index, temp >> 16); + state->overtemp = 0; ++ } + if (state->overtemp >= CPU_MAX_OVERTEMP) + critical_state = 1; + if (state->overtemp > 0) { +--- linux-2.6.15/drivers/macintosh/therm_pm72.h~ 2006-01-03 03:21:10.000000000 +0000 ++++ linux-2.6.15/drivers/macintosh/therm_pm72.h 2006-04-02 22:25:58.000000000 +0100 +@@ -243,7 +243,7 @@ struct dimm_pid_state + #define CPU_TEMP_HISTORY_SIZE 2 + #define CPU_POWER_HISTORY_SIZE 10 + #define CPU_PID_INTERVAL 1 +-#define CPU_MAX_OVERTEMP 30 ++#define CPU_MAX_OVERTEMP 90 + + #define CPUA_PUMP_RPM_INDEX 7 + #define CPUB_PUMP_RPM_INDEX 8 diff --git a/linux-2.6-hotfixes.patch b/linux-2.6-hotfixes.patch new file mode 100644 index 000000000..e69de29bb diff --git a/linux-2.6-input-clickpad-support.patch b/linux-2.6-input-clickpad-support.patch new file mode 100644 index 000000000..c61756e65 --- /dev/null +++ b/linux-2.6-input-clickpad-support.patch @@ -0,0 +1,137 @@ +From 5f57d67da87332a9a1ba8fa7a33bf0680e1c76e7 Mon Sep 17 00:00:00 2001 +From: Takashi Iwai +Date: Mon, 19 Apr 2010 10:37:21 -0700 +Subject: [PATCH] Input: Add support of Synaptics Clickpad device + +The new type of touchpads can be detected via a new query command +0x0c. The clickpad flags are in cap[0]:4 and cap[1]:0 bits. + +When the device is detected, the driver now reports only the left +button as the supported buttons so that X11 driver can detect that +the device is Clickpad. A Clickpad device gives the button events +only as the middle button. The kernel driver morphs to the left +button. The real handling of Clickpad is done rather in X driver +side. + +Signed-off-by: Takashi Iwai +Signed-off-by: Dmitry Torokhov +--- + drivers/input/mouse/synaptics.c | 35 ++++++++++++++++++++++++++++++----- + drivers/input/mouse/synaptics.h | 4 ++++ + 2 files changed, 34 insertions(+), 5 deletions(-) + +diff --git a/drivers/input/mouse/synaptics.c b/drivers/input/mouse/synaptics.c +index d3f5243..9ab9ff0 100644 +--- a/drivers/input/mouse/synaptics.c ++++ b/drivers/input/mouse/synaptics.c +@@ -136,7 +136,8 @@ static int synaptics_capability(struct psmouse *psmouse) + if (synaptics_send_cmd(psmouse, SYN_QUE_CAPABILITIES, cap)) + return -1; + priv->capabilities = (cap[0] << 16) | (cap[1] << 8) | cap[2]; +- priv->ext_cap = 0; ++ priv->ext_cap = priv->ext_cap_0c = 0; ++ + if (!SYN_CAP_VALID(priv->capabilities)) + return -1; + +@@ -149,7 +150,7 @@ static int synaptics_capability(struct psmouse *psmouse) + if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 1) { + if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB, cap)) { + printk(KERN_ERR "Synaptics claims to have extended capabilities," +- " but I'm not able to read them."); ++ " but I'm not able to read them.\n"); + } else { + priv->ext_cap = (cap[0] << 16) | (cap[1] << 8) | cap[2]; + +@@ -161,6 +162,16 @@ static int synaptics_capability(struct psmouse *psmouse) + priv->ext_cap &= 0xff0fff; + } + } ++ ++ if (SYN_EXT_CAP_REQUESTS(priv->capabilities) >= 4) { ++ if (synaptics_send_cmd(psmouse, SYN_QUE_EXT_CAPAB_0C, cap)) { ++ printk(KERN_ERR "Synaptics claims to have extended capability 0x0c," ++ " but I'm not able to read it.\n"); ++ } else { ++ priv->ext_cap_0c = (cap[0] << 16) | (cap[1] << 8) | cap[2]; ++ } ++ } ++ + return 0; + } + +@@ -347,7 +358,15 @@ static void synaptics_parse_hw_state(unsigned char buf[], struct synaptics_data + hw->left = (buf[0] & 0x01) ? 1 : 0; + hw->right = (buf[0] & 0x02) ? 1 : 0; + +- if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { ++ if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { ++ /* ++ * Clickpad's button is transmitted as middle button, ++ * however, since it is primary button, we will report ++ * it as BTN_LEFT. ++ */ ++ hw->left = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; ++ ++ } else if (SYN_CAP_MIDDLE_BUTTON(priv->capabilities)) { + hw->middle = ((buf[0] ^ buf[3]) & 0x01) ? 1 : 0; + if (hw->w == 2) + hw->scroll = (signed char)(buf[1]); +@@ -592,6 +611,12 @@ static void set_input_params(struct input_dev *dev, struct synaptics_data *priv) + + dev->absres[ABS_X] = priv->x_res; + dev->absres[ABS_Y] = priv->y_res; ++ ++ if (SYN_CAP_CLICKPAD(priv->ext_cap_0c)) { ++ /* Clickpads report only left button */ ++ __clear_bit(BTN_RIGHT, dev->keybit); ++ __clear_bit(BTN_MIDDLE, dev->keybit); ++ } + } + + static void synaptics_disconnect(struct psmouse *psmouse) +@@ -696,10 +721,10 @@ int synaptics_init(struct psmouse *psmouse) + + priv->pkt_type = SYN_MODEL_NEWABS(priv->model_id) ? SYN_NEWABS : SYN_OLDABS; + +- printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx\n", ++ printk(KERN_INFO "Synaptics Touchpad, model: %ld, fw: %ld.%ld, id: %#lx, caps: %#lx/%#lx/%#lx\n", + SYN_ID_MODEL(priv->identity), + SYN_ID_MAJOR(priv->identity), SYN_ID_MINOR(priv->identity), +- priv->model_id, priv->capabilities, priv->ext_cap); ++ priv->model_id, priv->capabilities, priv->ext_cap, priv->ext_cap_0c); + + set_input_params(psmouse->dev, priv); + +diff --git a/drivers/input/mouse/synaptics.h b/drivers/input/mouse/synaptics.h +index f0f40a3..ae37c5d 100644 +--- a/drivers/input/mouse/synaptics.h ++++ b/drivers/input/mouse/synaptics.h +@@ -18,6 +18,7 @@ + #define SYN_QUE_SERIAL_NUMBER_SUFFIX 0x07 + #define SYN_QUE_RESOLUTION 0x08 + #define SYN_QUE_EXT_CAPAB 0x09 ++#define SYN_QUE_EXT_CAPAB_0C 0x0c + + /* synatics modes */ + #define SYN_BIT_ABSOLUTE_MODE (1 << 7) +@@ -48,6 +49,8 @@ + #define SYN_CAP_VALID(c) ((((c) & 0x00ff00) >> 8) == 0x47) + #define SYN_EXT_CAP_REQUESTS(c) (((c) & 0x700000) >> 20) + #define SYN_CAP_MULTI_BUTTON_NO(ec) (((ec) & 0x00f000) >> 12) ++#define SYN_CAP_PRODUCT_ID(ec) (((ec) & 0xff0000) >> 16) ++#define SYN_CAP_CLICKPAD(ex0c) ((ex0c) & 0x100100) + + /* synaptics modes query bits */ + #define SYN_MODE_ABSOLUTE(m) ((m) & (1 << 7)) +@@ -96,6 +99,7 @@ struct synaptics_data { + unsigned long int model_id; /* Model-ID */ + unsigned long int capabilities; /* Capabilities */ + unsigned long int ext_cap; /* Extended Capabilities */ ++ unsigned long int ext_cap_0c; /* Ext Caps from 0x0c query */ + unsigned long int identity; /* Identification */ + int x_res; /* X resolution in units/mm */ + int y_res; /* Y resolution in units/mm */ +-- +1.7.0.1 + diff --git a/linux-2.6-input-fix-toshiba-hotkeys.patch b/linux-2.6-input-fix-toshiba-hotkeys.patch new file mode 100644 index 000000000..74558e69f --- /dev/null +++ b/linux-2.6-input-fix-toshiba-hotkeys.patch @@ -0,0 +1,278 @@ +commit 61a2aa30877a6e2be1d3fb3a71385e1f741819d7 +Author: Matthew Garrett +Date: Fri Mar 6 00:25:45 2009 +0000 + + toshiba-acpi: Add support for hotkey notifications + + Calling the ENAB method on Toshiba laptops results in notifications being + sent when laptop hotkeys are pressed. This patch simply calls that method + and sets up an input device if it's successful. + + Signed-off-by: Matthew Garrett + +diff --git a/drivers/platform/x86/toshiba_acpi.c b/drivers/platform/x86/toshiba_acpi.c +index 40e60fc..604f9fa 100644 +--- a/drivers/platform/x86/toshiba_acpi.c ++++ b/drivers/platform/x86/toshiba_acpi.c +@@ -46,6 +46,7 @@ + #include + #include + #include ++#include + + #include + +@@ -62,9 +63,10 @@ MODULE_LICENSE("GPL"); + + /* Toshiba ACPI method paths */ + #define METHOD_LCD_BRIGHTNESS "\\_SB_.PCI0.VGA_.LCD_._BCM" +-#define METHOD_HCI_1 "\\_SB_.VALD.GHCI" +-#define METHOD_HCI_2 "\\_SB_.VALZ.GHCI" ++#define TOSH_INTERFACE_1 "\\_SB_.VALD" ++#define TOSH_INTERFACE_2 "\\_SB_.VALZ" + #define METHOD_VIDEO_OUT "\\_SB_.VALX.DSSX" ++#define GHCI_METHOD ".GHCI" + + /* Toshiba HCI interface definitions + * +@@ -116,6 +118,36 @@ static const struct acpi_device_id toshiba_device_ids[] = { + }; + MODULE_DEVICE_TABLE(acpi, toshiba_device_ids); + ++struct key_entry { ++ char type; ++ u16 code; ++ u16 keycode; ++}; ++ ++enum {KE_KEY, KE_END}; ++ ++static struct key_entry toshiba_acpi_keymap[] = { ++ {KE_KEY, 0x101, KEY_MUTE}, ++ {KE_KEY, 0x13b, KEY_COFFEE}, ++ {KE_KEY, 0x13c, KEY_BATTERY}, ++ {KE_KEY, 0x13d, KEY_SLEEP}, ++ {KE_KEY, 0x13e, KEY_SUSPEND}, ++ {KE_KEY, 0x13f, KEY_SWITCHVIDEOMODE}, ++ {KE_KEY, 0x140, KEY_BRIGHTNESSDOWN}, ++ {KE_KEY, 0x141, KEY_BRIGHTNESSUP}, ++ {KE_KEY, 0x142, KEY_WLAN}, ++ {KE_KEY, 0x143, KEY_PROG1}, ++ {KE_KEY, 0xb05, KEY_PROG2}, ++ {KE_KEY, 0xb06, KEY_WWW}, ++ {KE_KEY, 0xb07, KEY_MAIL}, ++ {KE_KEY, 0xb30, KEY_STOP}, ++ {KE_KEY, 0xb31, KEY_PREVIOUSSONG}, ++ {KE_KEY, 0xb32, KEY_NEXTSONG}, ++ {KE_KEY, 0xb33, KEY_PLAYPAUSE}, ++ {KE_KEY, 0xb5a, KEY_MEDIA}, ++ {KE_END, 0, 0}, ++}; ++ + /* utility + */ + +@@ -252,6 +284,8 @@ struct toshiba_acpi_dev { + struct platform_device *p_dev; + struct rfkill *rfk_dev; + struct input_polled_dev *poll_dev; ++ struct input_dev *hotkey_dev; ++ acpi_handle handle; + + const char *bt_name; + const char *rfk_name; +@@ -702,6 +736,154 @@ static struct backlight_ops toshiba_backlight_data = { + .update_status = set_lcd_status, + }; + ++static struct key_entry *toshiba_acpi_get_entry_by_scancode(int code) ++{ ++ struct key_entry *key; ++ ++ for (key = toshiba_acpi_keymap; key->type != KE_END; key++) ++ if (code == key->code) ++ return key; ++ ++ return NULL; ++} ++ ++static struct key_entry *toshiba_acpi_get_entry_by_keycode(int code) ++{ ++ struct key_entry *key; ++ ++ for (key = toshiba_acpi_keymap; key->type != KE_END; key++) ++ if (code == key->keycode && key->type == KE_KEY) ++ return key; ++ ++ return NULL; ++} ++ ++static int toshiba_acpi_getkeycode(struct input_dev *dev, int scancode, ++ int *keycode) ++{ ++ struct key_entry *key = toshiba_acpi_get_entry_by_scancode(scancode); ++ ++ if (key && key->type == KE_KEY) { ++ *keycode = key->keycode; ++ return 0; ++ } ++ ++ return -EINVAL; ++} ++ ++static int toshiba_acpi_setkeycode(struct input_dev *dev, int scancode, ++ int keycode) ++{ ++ struct key_entry *key; ++ int old_keycode; ++ ++ if (keycode < 0 || keycode > KEY_MAX) ++ return -EINVAL; ++ ++ key = toshiba_acpi_get_entry_by_scancode(scancode); ++ if (key && key->type == KE_KEY) { ++ old_keycode = key->keycode; ++ key->keycode = keycode; ++ set_bit(keycode, dev->keybit); ++ if (!toshiba_acpi_get_entry_by_keycode(old_keycode)) ++ clear_bit(old_keycode, dev->keybit); ++ return 0; ++ } ++ ++ return -EINVAL; ++} ++ ++static void toshiba_acpi_notify(acpi_handle handle, u32 event, void *data) ++{ ++ u32 hci_result, value; ++ struct key_entry *key; ++ ++ if (event != 0x80) ++ return; ++ do { ++ hci_read1(HCI_SYSTEM_EVENT, &value, &hci_result); ++ if (hci_result == HCI_SUCCESS) { ++ if (value == 0x100) ++ continue; ++ else if (value & 0x80) { ++ key = toshiba_acpi_get_entry_by_scancode ++ (value & ~0x80); ++ if (!key) { ++ printk(MY_INFO "Unknown key %x\n", ++ value & ~0x80); ++ continue; ++ } ++ input_report_key(toshiba_acpi.hotkey_dev, ++ key->keycode, 1); ++ input_sync(toshiba_acpi.hotkey_dev); ++ input_report_key(toshiba_acpi.hotkey_dev, ++ key->keycode, 0); ++ input_sync(toshiba_acpi.hotkey_dev); ++ } ++ } else if (hci_result == HCI_NOT_SUPPORTED) { ++ /* This is a workaround for an unresolved issue on ++ * some machines where system events sporadically ++ * become disabled. */ ++ hci_write1(HCI_SYSTEM_EVENT, 1, &hci_result); ++ printk(MY_NOTICE "Re-enabled hotkeys\n"); ++ } ++ } while (hci_result != HCI_EMPTY); ++} ++ ++static int toshiba_acpi_setup_keyboard(char *device) ++{ ++ acpi_status status; ++ acpi_handle handle; ++ int result; ++ const struct key_entry *key; ++ ++ status = acpi_get_handle(NULL, device, &handle); ++ if (ACPI_FAILURE(status)) { ++ printk(MY_INFO "Unable to get notification device\n"); ++ return -ENODEV; ++ } ++ ++ toshiba_acpi.handle = handle; ++ ++ status = acpi_evaluate_object(handle, "ENAB", NULL, NULL); ++ if (ACPI_FAILURE(status)) { ++ printk(MY_INFO "Unable to enable hotkeys\n"); ++ return -ENODEV; ++ } ++ ++ status = acpi_install_notify_handler (handle, ACPI_DEVICE_NOTIFY, ++ toshiba_acpi_notify, NULL); ++ if (ACPI_FAILURE(status)) { ++ printk(MY_INFO "Unable to install hotkey notification\n"); ++ return -ENODEV; ++ } ++ ++ toshiba_acpi.hotkey_dev = input_allocate_device(); ++ if (!toshiba_acpi.hotkey_dev) { ++ printk(MY_INFO "Unable to register input device\n"); ++ return -ENOMEM; ++ } ++ ++ toshiba_acpi.hotkey_dev->name = "Toshiba input device"; ++ toshiba_acpi.hotkey_dev->phys = device; ++ toshiba_acpi.hotkey_dev->id.bustype = BUS_HOST; ++ toshiba_acpi.hotkey_dev->getkeycode = toshiba_acpi_getkeycode; ++ toshiba_acpi.hotkey_dev->setkeycode = toshiba_acpi_setkeycode; ++ ++ for (key = toshiba_acpi_keymap; key->type != KE_END; key++) { ++ set_bit(EV_KEY, toshiba_acpi.hotkey_dev->evbit); ++ set_bit(key->keycode, toshiba_acpi.hotkey_dev->keybit); ++ } ++ ++ result = input_register_device(toshiba_acpi.hotkey_dev); ++ if (result) { ++ printk(MY_INFO "Unable to register input device\n"); ++ return result; ++ } ++ ++ return 0; ++} ++ + static void toshiba_acpi_exit(void) + { + if (toshiba_acpi.poll_dev) { +@@ -709,12 +891,18 @@ static void toshiba_acpi_exit(void) + input_free_polled_device(toshiba_acpi.poll_dev); + } + ++ if (toshiba_acpi.hotkey_dev) ++ input_unregister_device(toshiba_acpi.hotkey_dev); ++ + if (toshiba_acpi.rfk_dev) + rfkill_unregister(toshiba_acpi.rfk_dev); + + if (toshiba_backlight_device) + backlight_device_unregister(toshiba_backlight_device); + ++ acpi_remove_notify_handler(toshiba_acpi.handle, ACPI_DEVICE_NOTIFY, ++ toshiba_acpi_notify); ++ + remove_device(); + + if (toshiba_proc_dir) +@@ -738,11 +926,15 @@ static int __init toshiba_acpi_init(void) + return -ENODEV; + + /* simple device detection: look for HCI method */ +- if (is_valid_acpi_path(METHOD_HCI_1)) +- method_hci = METHOD_HCI_1; +- else if (is_valid_acpi_path(METHOD_HCI_2)) +- method_hci = METHOD_HCI_2; +- else ++ if (is_valid_acpi_path(TOSH_INTERFACE_1 GHCI_METHOD)) { ++ method_hci = TOSH_INTERFACE_1 GHCI_METHOD; ++ if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_1)) ++ printk(MY_INFO "Unable to activate hotkeys\n"); ++ } else if (is_valid_acpi_path(TOSH_INTERFACE_2 GHCI_METHOD)) { ++ method_hci = TOSH_INTERFACE_2 GHCI_METHOD; ++ if (toshiba_acpi_setup_keyboard(TOSH_INTERFACE_2)) ++ printk(MY_INFO "Unable to activate hotkeys\n"); ++ } else + return -ENODEV; + + printk(MY_INFO "Toshiba Laptop ACPI Extras version %s\n", diff --git a/linux-2.6-input-hid-quirk-egalax.patch b/linux-2.6-input-hid-quirk-egalax.patch new file mode 100644 index 000000000..db38685f0 --- /dev/null +++ b/linux-2.6-input-hid-quirk-egalax.patch @@ -0,0 +1,41 @@ +Date: Mon, 1 Feb 2010 12:53:47 +1300 +From: Peter Hutterer +To: Dave Airlie +Subject: [PATCH] HID: add multi-input quirk for eGalax Touchcontroller + +Signed-off-by: Peter Hutterer +Tested-by: Alfred Broda +--- + drivers/hid/hid-ids.h | 3 +++ + drivers/hid/usbhid/hid-quirks.c | 1 + + 2 files changed, 4 insertions(+), 0 deletions(-) + +diff --git a/drivers/hid/hid-ids.h b/drivers/hid/hid-ids.h +index f5144b8..2e698a2 100644 +--- a/drivers/hid/hid-ids.h ++++ b/drivers/hid/hid-ids.h +@@ -158,6 +158,9 @@ + + #define USB_VENDOR_ID_DRAGONRISE 0x0079 + ++#define USB_VENDOR_ID_EGALAX 0x0EEF ++#define USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER 0x0001 ++ + #define USB_VENDOR_ID_ELO 0x04E7 + #define USB_DEVICE_ID_ELO_TS2700 0x0020 + +diff --git a/drivers/hid/usbhid/hid-quirks.c b/drivers/hid/usbhid/hid-quirks.c +index e987562..dc27d74 100644 +--- a/drivers/hid/usbhid/hid-quirks.c ++++ b/drivers/hid/usbhid/hid-quirks.c +@@ -32,6 +32,7 @@ static const struct hid_blacklist { + { USB_VENDOR_ID_AASHIMA, USB_DEVICE_ID_AASHIMA_PREDATOR, HID_QUIRK_BADPAD }, + { USB_VENDOR_ID_ALPS, USB_DEVICE_ID_IBM_GAMEPAD, HID_QUIRK_BADPAD }, + { USB_VENDOR_ID_CHIC, USB_DEVICE_ID_CHIC_GAMEPAD, HID_QUIRK_BADPAD }, ++ { USB_VENDOR_ID_EGALAX, USB_DEVICE_ID_EGALAX_TOUCHCONTROLLER, HID_QUIRK_MULTI_INPUT }, + { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_DRIVING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, + { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FLYING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, + { USB_VENDOR_ID_HAPP, USB_DEVICE_ID_UGCI_FIGHTING, HID_QUIRK_BADPAD | HID_QUIRK_MULTI_INPUT }, +-- +1.6.5.2 + diff --git a/linux-2.6-input-kill-stupid-messages.patch b/linux-2.6-input-kill-stupid-messages.patch new file mode 100644 index 000000000..2e6314694 --- /dev/null +++ b/linux-2.6-input-kill-stupid-messages.patch @@ -0,0 +1,17 @@ +--- linux-2.6.21.noarch/drivers/input/keyboard/atkbd.c~ 2007-07-06 10:51:04.000000000 -0400 ++++ linux-2.6.21.noarch/drivers/input/keyboard/atkbd.c 2007-07-06 10:51:33.000000000 -0400 +@@ -409,10 +409,14 @@ static irqreturn_t atkbd_interrupt(struc + goto out; + case ATKBD_RET_ACK: + case ATKBD_RET_NAK: ++#if 0 ++ /* Quite a few key switchers and other tools trigger this and it confuses ++ people who can do nothing about it */ + if (printk_ratelimit()) + printk(KERN_WARNING "atkbd.c: Spurious %s on %s. " + "Some program might be trying access hardware directly.\n", + data == ATKBD_RET_ACK ? "ACK" : "NAK", serio->phys); ++#endif + goto out; + case ATKBD_RET_ERR: + atkbd->err_count++; diff --git a/linux-2.6-intel-iommu-igfx.patch b/linux-2.6-intel-iommu-igfx.patch new file mode 100644 index 000000000..f5888d127 --- /dev/null +++ b/linux-2.6-intel-iommu-igfx.patch @@ -0,0 +1,78 @@ +Subject: [PATCH] [intel_iommu] Default to igfx_off +From: drago01 +To: fedora-kernel-list + +This option seems to causes way to many issues, it is +being investigated by Intel's chipset team for months now and +we still don't have any outcome. + +The results so far are "black screen when starting X", +"system hangs when using GL", "system does not resume". + +The patch adds an intel_iommu=igfx_on option, which makes it opt in, +rather than opt out. + +Signed-off-by: Adel Gadllah +Reviewed-by: Adam Jackson +--- + Documentation/kernel-parameters.txt | 11 +++++------ + drivers/pci/intel-iommu.c | 9 +++++---- + 2 files changed, 10 insertions(+), 10 deletions(-) + +diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt +index e7848a0..9914485 100644 +--- a/Documentation/kernel-parameters.txt ++++ b/Documentation/kernel-parameters.txt +@@ -992,12 +992,11 @@ and is between 256 and 4096 characters. It is defined in the file + Enable intel iommu driver. + off + Disable intel iommu driver. +- igfx_off [Default Off] +- By default, gfx is mapped as normal device. If a gfx +- device has a dedicated DMAR unit, the DMAR unit is +- bypassed by not enabling DMAR with this option. In +- this case, gfx device will use physical address for +- DMA. ++ igfx_on [Default Off] ++ By default, the gfx's DMAR unit is bypassed by not enabling ++ DMAR with this option. So the gfx device will use physical ++ address for DMA. When this option is enabled it the gfx is ++ mapped as normal device. + forcedac [x86_64] + With this option iommu will not optimize to look + for io virtual address below 32 bit forcing dual +diff --git a/drivers/pci/intel-iommu.c b/drivers/pci/intel-iommu.c +index 4173125..8f36786 100644 +--- a/drivers/pci/intel-iommu.c ++++ b/drivers/pci/intel-iommu.c +@@ -340,7 +340,8 @@ int dmar_disabled = 0; + int dmar_disabled = 1; + #endif /*CONFIG_DMAR_DEFAULT_ON*/ + +-static int __initdata dmar_map_gfx = 1; ++/* disabled by default; causes way too many issues */ ++static int dmar_map_gfx = 0; + static int dmar_forcedac; + static int intel_iommu_strict; + +@@ -361,10 +362,10 @@ static int __init intel_iommu_setup(char *str) + } else if (!strncmp(str, "off", 3)) { + dmar_disabled = 1; + printk(KERN_INFO "Intel-IOMMU: disabled\n"); +- } else if (!strncmp(str, "igfx_off", 8)) { +- dmar_map_gfx = 0; ++ } else if (!strncmp(str, "igfx_on", 7)) { ++ dmar_map_gfx = 1; + printk(KERN_INFO +- "Intel-IOMMU: disable GFX device mapping\n"); ++ "Intel-IOMMU: enabled GFX device mapping\n"); + } else if (!strncmp(str, "forcedac", 8)) { + printk(KERN_INFO + "Intel-IOMMU: Forcing DAC for PCI devices\n"); +-- +1.6.6.1 +_______________________________________________ +kernel mailing list +kernel@lists.fedoraproject.org +https://admin.fedoraproject.org/mailman/listinfo/kernel + diff --git a/linux-2.6-mac80211-age-scan-results-on-resume.patch b/linux-2.6-mac80211-age-scan-results-on-resume.patch new file mode 100644 index 000000000..d9e9631bd --- /dev/null +++ b/linux-2.6-mac80211-age-scan-results-on-resume.patch @@ -0,0 +1,181 @@ +Backport of "cfg80211: age scan results on resume" by Dan Williams. + +diff --git a/include/net/cfg80211.h b/include/net/cfg80211.h +index 23c0ab7..0432eb6 100644 +--- a/include/net/cfg80211.h ++++ b/include/net/cfg80211.h +@@ -450,6 +450,9 @@ struct ieee80211_channel; + * wireless extensions but this is subject to reevaluation as soon as this + * code is used more widely and we have a first user without wext. + * ++ * @suspend: wiphy device needs to be suspended ++ * @resume: wiphy device needs to be resumed ++ * + * @add_virtual_intf: create a new virtual interface with the given name, + * must set the struct wireless_dev's iftype. + * +@@ -499,6 +502,9 @@ struct ieee80211_channel; + * @set_channel: Set channel + */ + struct cfg80211_ops { ++ int (*suspend)(struct wiphy *wiphy); ++ int (*resume)(struct wiphy *wiphy); ++ + int (*add_virtual_intf)(struct wiphy *wiphy, char *name, + enum nl80211_iftype type, u32 *flags, + struct vif_params *params); +diff --git a/include/net/wireless.h b/include/net/wireless.h +index 21c5d96..ae2d34d 100644 +--- a/include/net/wireless.h ++++ b/include/net/wireless.h +@@ -220,6 +220,9 @@ struct wiphy { + /* dir in debugfs: ieee80211/ */ + struct dentry *debugfsdir; + ++ /* time spent in suspend, in seconds */ ++ unsigned long suspend_duration; ++ + char priv[0] __attribute__((__aligned__(NETDEV_ALIGN))); + }; + +diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c +index 9d4e4d8..691183e 100644 +--- a/net/mac80211/cfg.c ++++ b/net/mac80211/cfg.c +@@ -1141,6 +1141,32 @@ static int ieee80211_set_channel(struct wiphy *wiphy, + return ieee80211_hw_config(local, IEEE80211_CONF_CHANGE_CHANNEL); + } + ++#ifdef CONFIG_PM ++static int ieee80211_suspend(struct wiphy *wiphy) ++{ ++ return 0; ++} ++ ++static int ieee80211_resume(struct wiphy *wiphy) ++{ ++ struct ieee80211_local *local = wiphy_priv(wiphy); ++ unsigned long age_jiffies; ++ struct ieee80211_bss *bss; ++ ++ age_jiffies = msecs_to_jiffies(wiphy->suspend_duration * MSEC_PER_SEC); ++ spin_lock_bh(&local->bss_lock); ++ list_for_each_entry(bss, &local->bss_list, list) { ++ bss->last_update -= age_jiffies; ++ } ++ spin_unlock_bh(&local->bss_lock); ++ ++ return 0; ++} ++#else ++#define ieee80211_suspend NULL ++#define ieee80211_resume NULL ++#endif ++ + struct cfg80211_ops mac80211_config_ops = { + .add_virtual_intf = ieee80211_add_iface, + .del_virtual_intf = ieee80211_del_iface, +@@ -1169,4 +1195,6 @@ struct cfg80211_ops mac80211_config_ops = { + .change_bss = ieee80211_change_bss, + .set_txq_params = ieee80211_set_txq_params, + .set_channel = ieee80211_set_channel, ++ .suspend = ieee80211_suspend, ++ .resume = ieee80211_resume, + }; +diff --git a/net/mac80211/scan.c b/net/mac80211/scan.c +index f5c7c33..eb43ff5 100644 +--- a/net/mac80211/scan.c ++++ b/net/mac80211/scan.c +@@ -745,6 +745,15 @@ static void ieee80211_scan_add_ies(struct iw_request_info *info, + } + } + ++static inline unsigned int elapsed_jiffies_msecs(unsigned long start) ++{ ++ unsigned long end = jiffies; ++ ++ if (end >= start) ++ return jiffies_to_msecs(end - start); ++ ++ return jiffies_to_msecs(end + (MAX_JIFFY_OFFSET - start) + 1); ++} + + static char * + ieee80211_scan_result(struct ieee80211_local *local, +@@ -857,8 +866,8 @@ ieee80211_scan_result(struct ieee80211_local *local, + &iwe, buf); + memset(&iwe, 0, sizeof(iwe)); + iwe.cmd = IWEVCUSTOM; +- sprintf(buf, " Last beacon: %dms ago", +- jiffies_to_msecs(jiffies - bss->last_update)); ++ sprintf(buf, " Last beacon: %ums ago", ++ elapsed_jiffies_msecs(bss->last_update)); + iwe.u.data.length = strlen(buf); + current_ev = iwe_stream_add_point(info, current_ev, + end_buf, &iwe, buf); +diff --git a/net/wireless/core.h b/net/wireless/core.h +index f7fb9f4..a4031a9 100644 +--- a/net/wireless/core.h ++++ b/net/wireless/core.h +@@ -41,6 +41,8 @@ struct cfg80211_registered_device { + struct mutex devlist_mtx; + struct list_head netdev_list; + ++ unsigned long suspend_at; ++ + /* must be last because of the way we do wiphy_priv(), + * and it should at least be aligned to NETDEV_ALIGN */ + struct wiphy wiphy __attribute__((__aligned__(NETDEV_ALIGN))); +diff --git a/net/wireless/sysfs.c b/net/wireless/sysfs.c +index 79a3828..dc92564 100644 +--- a/net/wireless/sysfs.c ++++ b/net/wireless/sysfs.c +@@ -55,6 +55,39 @@ static int wiphy_uevent(struct device *dev, struct kobj_uevent_env *env) + } + #endif + ++static int wiphy_suspend(struct device *dev, pm_message_t state) ++{ ++ struct cfg80211_registered_device *rdev = dev_to_rdev(dev); ++ int ret = 0; ++ ++ rdev->wiphy.suspend_duration = 0; ++ rdev->suspend_at = get_seconds(); ++ ++ if (rdev->ops->suspend) { ++ rtnl_lock(); ++ ret = rdev->ops->suspend(&rdev->wiphy); ++ rtnl_unlock(); ++ } ++ ++ return ret; ++} ++ ++static int wiphy_resume(struct device *dev) ++{ ++ struct cfg80211_registered_device *rdev = dev_to_rdev(dev); ++ int ret = 0; ++ ++ rdev->wiphy.suspend_duration = get_seconds() - rdev->suspend_at; ++ ++ if (rdev->ops->resume) { ++ rtnl_lock(); ++ ret = rdev->ops->resume(&rdev->wiphy); ++ rtnl_unlock(); ++ } ++ ++ return ret; ++} ++ + struct class ieee80211_class = { + .name = "ieee80211", + .owner = THIS_MODULE, +@@ -63,6 +96,8 @@ struct class ieee80211_class = { + #ifdef CONFIG_HOTPLUG + .dev_uevent = wiphy_uevent, + #endif ++ .suspend = wiphy_suspend, ++ .resume = wiphy_resume, + }; + + int wiphy_sysfs_init(void) diff --git a/linux-2.6-makefile-after_link.patch b/linux-2.6-makefile-after_link.patch new file mode 100644 index 000000000..94b71f9b1 --- /dev/null +++ b/linux-2.6-makefile-after_link.patch @@ -0,0 +1,57 @@ +diff --git a/Makefile b/Makefile +index f908acc..960ff6f 100644 +--- a/Makefile ++++ b/Makefile +@@ -746,6 +746,10 @@ quiet_cmd_vmlinux__ ?= LD $@ + --start-group $(vmlinux-main) --end-group \ + $(filter-out $(vmlinux-lds) $(vmlinux-init) $(vmlinux-main) vmlinux.o FORCE ,$^) + ++ifdef AFTER_LINK ++cmd_vmlinux__ += ; $(AFTER_LINK) ++endif ++ + # Generate new vmlinux version + quiet_cmd_vmlinux_version = GEN .version + cmd_vmlinux_version = set -e; \ +diff --git a/arch/powerpc/kernel/vdso32/Makefile b/arch/powerpc/kernel/vdso32/Makefile +index 51ead52..ad21273 100644 +--- a/arch/powerpc/kernel/vdso32/Makefile ++++ b/arch/powerpc/kernel/vdso32/Makefile +@@ -41,7 +41,8 @@ $(obj-vdso32): %.o: %.S + + # actual build commands + quiet_cmd_vdso32ld = VDSO32L $@ +- cmd_vdso32ld = $(CROSS32CC) $(c_flags) -Wl,-T $^ -o $@ ++ cmd_vdso32ld = $(CROSS32CC) $(c_flags) -Wl,-T $^ -o $@ \ ++ $(if $(AFTER_LINK),; $(AFTER_LINK)) + quiet_cmd_vdso32as = VDSO32A $@ + cmd_vdso32as = $(CROSS32CC) $(a_flags) -c -o $@ $< + +diff --git a/arch/powerpc/kernel/vdso64/Makefile b/arch/powerpc/kernel/vdso64/Makefile +index 79da65d..f11c21b 100644 +--- a/arch/powerpc/kernel/vdso64/Makefile ++++ b/arch/powerpc/kernel/vdso64/Makefile +@@ -36,7 +36,8 @@ $(obj-vdso64): %.o: %.S + + # actual build commands + quiet_cmd_vdso64ld = VDSO64L $@ +- cmd_vdso64ld = $(CC) $(c_flags) -Wl,-T $^ -o $@ ++ cmd_vdso64ld = $(CC) $(c_flags) -Wl,-T $^ -o $@ \ ++ $(if $(AFTER_LINK),; $(AFTER_LINK)) + quiet_cmd_vdso64as = VDSO64A $@ + cmd_vdso64as = $(CC) $(a_flags) -c -o $@ $< + +diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile +index 6b4ffed..cbc3d05 100644 +--- a/arch/x86/vdso/Makefile ++++ b/arch/x86/vdso/Makefile +@@ -120,7 +120,8 @@ $(obj)/vdso32-syms.lds: $(vdso32.so-y:%=$(obj)/vdso32-%-syms.lds) FORCE + quiet_cmd_vdso = VDSO $@ + cmd_vdso = $(CC) -nostdlib -o $@ \ + $(VDSO_LDFLAGS) $(VDSO_LDFLAGS_$(filter %.lds,$(^F))) \ +- -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) ++ -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) \ ++ $(if $(AFTER_LINK),; $(AFTER_LINK)) + + VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv) + GCOV_PROFILE := n diff --git a/linux-2.6-nfs4-callback-hidden.patch b/linux-2.6-nfs4-callback-hidden.patch new file mode 100644 index 000000000..8fc236836 --- /dev/null +++ b/linux-2.6-nfs4-callback-hidden.patch @@ -0,0 +1,20 @@ +Author: Steve Dickson +Date: Tue Oct 13 15:59:57 EDT 2009 + +To avoid hangs in the svc_unregister(), on version 4 mounts +(and unmounts), when rpcbind is not running, make the nfs4 callback +program an 'hidden' service by setting the 'vs_hidden' flag in the +nfs4_callback_version structure. + +Signed-off-by: Steve Dickson + +diff -up linux-2.6.31.x86_64/fs/nfs/callback_xdr.c.orig linux-2.6.31.x86_64/fs/nfs/callback_xdr.c +--- linux-2.6.31.x86_64/fs/nfs/callback_xdr.c.orig 2009-09-09 18:13:59.000000000 -0400 ++++ linux-2.6.31.x86_64/fs/nfs/callback_xdr.c 2009-10-13 15:40:19.000000000 -0400 +@@ -716,5 +716,6 @@ struct svc_version nfs4_callback_version + .vs_proc = nfs4_callback_procedures1, + .vs_xdrsize = NFS4_CALLBACK_XDRSIZE, + .vs_dispatch = NULL, ++ .vs_hidden = 1, + }; + diff --git a/linux-2.6-p54pci.patch b/linux-2.6-p54pci.patch new file mode 100644 index 000000000..116cd6f25 --- /dev/null +++ b/linux-2.6-p54pci.patch @@ -0,0 +1,513 @@ +From: Christian Lamparter +Date: Sun, 17 Jan 2010 22:19:25 +0000 (+0100) +Subject: p54pci: move tx cleanup into tasklet +X-Git-Tag: master-2010-01-19~9 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Flinville%2Fwireless-next-2.6.git;a=commitdiff_plain;h=d713804c6032b95cd3035014e16fadebb9655c6f + +p54pci: move tx cleanup into tasklet + +This patch moves the tx cleanup routines out of the critical +interrupt context and into the (previously known as rx) tasklet. + +The main goal of this operation is to remove the extensive +usage of spin_lock_irqsaves in the generic p54common library. + +The next step would be to modify p54usb to do the +rx processing inside a tasklet (just like usbnet). + +Signed-off-by: Christian Lamparter +Signed-off-by: John W. Linville +--- + +diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c +index 4bf4c21..48cae48 100644 +--- a/drivers/net/wireless/p54/p54pci.c ++++ b/drivers/net/wireless/p54/p54pci.c +@@ -234,25 +234,26 @@ static void p54p_check_rx_ring(struct ieee80211_hw *dev, u32 *index, + p54p_refill_rx_ring(dev, ring_index, ring, ring_limit, rx_buf); + } + +-/* caller must hold priv->lock */ + static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index, + int ring_index, struct p54p_desc *ring, u32 ring_limit, +- void **tx_buf) ++ struct sk_buff **tx_buf) + { ++ unsigned long flags; + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; + struct p54p_desc *desc; ++ struct sk_buff *skb; + u32 idx, i; + + i = (*index) % ring_limit; + (*index) = idx = le32_to_cpu(ring_control->device_idx[ring_index]); + idx %= ring_limit; + ++ spin_lock_irqsave(&priv->lock, flags); + while (i != idx) { + desc = &ring[i]; +- if (tx_buf[i]) +- if (FREE_AFTER_TX((struct sk_buff *) tx_buf[i])) +- p54_free_skb(dev, tx_buf[i]); ++ ++ skb = tx_buf[i]; + tx_buf[i] = NULL; + + pci_unmap_single(priv->pdev, le32_to_cpu(desc->host_addr), +@@ -263,17 +264,32 @@ static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index, + desc->len = 0; + desc->flags = 0; + ++ if (skb && FREE_AFTER_TX(skb)) { ++ spin_unlock_irqrestore(&priv->lock, flags); ++ p54_free_skb(dev, skb); ++ spin_lock_irqsave(&priv->lock, flags); ++ } ++ + i++; + i %= ring_limit; + } ++ spin_unlock_irqrestore(&priv->lock, flags); + } + +-static void p54p_rx_tasklet(unsigned long dev_id) ++static void p54p_tasklet(unsigned long dev_id) + { + struct ieee80211_hw *dev = (struct ieee80211_hw *)dev_id; + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; + ++ p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, 3, ring_control->tx_mgmt, ++ ARRAY_SIZE(ring_control->tx_mgmt), ++ priv->tx_buf_mgmt); ++ ++ p54p_check_tx_ring(dev, &priv->tx_idx_data, 1, ring_control->tx_data, ++ ARRAY_SIZE(ring_control->tx_data), ++ priv->tx_buf_data); ++ + p54p_check_rx_ring(dev, &priv->rx_idx_mgmt, 2, ring_control->rx_mgmt, + ARRAY_SIZE(ring_control->rx_mgmt), priv->rx_buf_mgmt); + +@@ -288,38 +304,24 @@ static irqreturn_t p54p_interrupt(int irq, void *dev_id) + { + struct ieee80211_hw *dev = dev_id; + struct p54p_priv *priv = dev->priv; +- struct p54p_ring_control *ring_control = priv->ring_control; + __le32 reg; + + spin_lock(&priv->lock); + reg = P54P_READ(int_ident); + if (unlikely(reg == cpu_to_le32(0xFFFFFFFF))) { +- spin_unlock(&priv->lock); +- return IRQ_HANDLED; ++ goto out; + } +- + P54P_WRITE(int_ack, reg); + + reg &= P54P_READ(int_enable); + +- if (reg & cpu_to_le32(ISL38XX_INT_IDENT_UPDATE)) { +- p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, +- 3, ring_control->tx_mgmt, +- ARRAY_SIZE(ring_control->tx_mgmt), +- priv->tx_buf_mgmt); +- +- p54p_check_tx_ring(dev, &priv->tx_idx_data, +- 1, ring_control->tx_data, +- ARRAY_SIZE(ring_control->tx_data), +- priv->tx_buf_data); +- +- tasklet_schedule(&priv->rx_tasklet); +- +- } else if (reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT)) ++ if (reg & cpu_to_le32(ISL38XX_INT_IDENT_UPDATE)) ++ tasklet_schedule(&priv->tasklet); ++ else if (reg & cpu_to_le32(ISL38XX_INT_IDENT_INIT)) + complete(&priv->boot_comp); + ++out: + spin_unlock(&priv->lock); +- + return reg ? IRQ_HANDLED : IRQ_NONE; + } + +@@ -368,7 +370,7 @@ static void p54p_stop(struct ieee80211_hw *dev) + unsigned int i; + struct p54p_desc *desc; + +- tasklet_kill(&priv->rx_tasklet); ++ tasklet_kill(&priv->tasklet); + + P54P_WRITE(int_enable, cpu_to_le32(0)); + P54P_READ(int_enable); +@@ -559,7 +561,7 @@ static int __devinit p54p_probe(struct pci_dev *pdev, + priv->common.tx = p54p_tx; + + spin_lock_init(&priv->lock); +- tasklet_init(&priv->rx_tasklet, p54p_rx_tasklet, (unsigned long)dev); ++ tasklet_init(&priv->tasklet, p54p_tasklet, (unsigned long)dev); + + err = request_firmware(&priv->firmware, "isl3886pci", + &priv->pdev->dev); +diff --git a/drivers/net/wireless/p54/p54pci.h b/drivers/net/wireless/p54/p54pci.h +index fbb6839..2feead6 100644 +--- a/drivers/net/wireless/p54/p54pci.h ++++ b/drivers/net/wireless/p54/p54pci.h +@@ -92,7 +92,7 @@ struct p54p_priv { + struct p54_common common; + struct pci_dev *pdev; + struct p54p_csr __iomem *map; +- struct tasklet_struct rx_tasklet; ++ struct tasklet_struct tasklet; + const struct firmware *firmware; + spinlock_t lock; + struct p54p_ring_control *ring_control; +@@ -101,8 +101,8 @@ struct p54p_priv { + u32 rx_idx_mgmt, tx_idx_mgmt; + struct sk_buff *rx_buf_data[8]; + struct sk_buff *rx_buf_mgmt[4]; +- void *tx_buf_data[32]; +- void *tx_buf_mgmt[4]; ++ struct sk_buff *tx_buf_data[32]; ++ struct sk_buff *tx_buf_mgmt[4]; + struct completion boot_comp; + }; + +From: Christian Lamparter +Date: Fri, 22 Jan 2010 07:01:11 +0000 (+0100) +Subject: p54pci: revise tx locking +X-Git-Tag: master-2010-01-22~1 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Flinville%2Fwireless-next-2.6.git;a=commitdiff_plain;h=b92f7d30830a319148df2943b7565989494e5ad1 + +p54pci: revise tx locking + +This patch continues the effort which began with: +"[PATCH] p54pci: move tx cleanup into tasklet". + +Thanks to these changes, p54pci's interrupt & tx +cleanup routines can be made lock-less. + +Signed-off-by: Christian Lamparter +Signed-off-by: John W. Linville +--- + +diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c +index 48cae48..bda29c0 100644 +--- a/drivers/net/wireless/p54/p54pci.c ++++ b/drivers/net/wireless/p54/p54pci.c +@@ -238,7 +238,6 @@ static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index, + int ring_index, struct p54p_desc *ring, u32 ring_limit, + struct sk_buff **tx_buf) + { +- unsigned long flags; + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; + struct p54p_desc *desc; +@@ -249,7 +248,6 @@ static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index, + (*index) = idx = le32_to_cpu(ring_control->device_idx[ring_index]); + idx %= ring_limit; + +- spin_lock_irqsave(&priv->lock, flags); + while (i != idx) { + desc = &ring[i]; + +@@ -264,16 +262,12 @@ static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index, + desc->len = 0; + desc->flags = 0; + +- if (skb && FREE_AFTER_TX(skb)) { +- spin_unlock_irqrestore(&priv->lock, flags); ++ if (skb && FREE_AFTER_TX(skb)) + p54_free_skb(dev, skb); +- spin_lock_irqsave(&priv->lock, flags); +- } + + i++; + i %= ring_limit; + } +- spin_unlock_irqrestore(&priv->lock, flags); + } + + static void p54p_tasklet(unsigned long dev_id) +@@ -306,7 +300,6 @@ static irqreturn_t p54p_interrupt(int irq, void *dev_id) + struct p54p_priv *priv = dev->priv; + __le32 reg; + +- spin_lock(&priv->lock); + reg = P54P_READ(int_ident); + if (unlikely(reg == cpu_to_le32(0xFFFFFFFF))) { + goto out; +@@ -321,15 +314,14 @@ static irqreturn_t p54p_interrupt(int irq, void *dev_id) + complete(&priv->boot_comp); + + out: +- spin_unlock(&priv->lock); + return reg ? IRQ_HANDLED : IRQ_NONE; + } + + static void p54p_tx(struct ieee80211_hw *dev, struct sk_buff *skb) + { ++ unsigned long flags; + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; +- unsigned long flags; + struct p54p_desc *desc; + dma_addr_t mapping; + u32 device_idx, idx, i; +@@ -370,14 +362,14 @@ static void p54p_stop(struct ieee80211_hw *dev) + unsigned int i; + struct p54p_desc *desc; + +- tasklet_kill(&priv->tasklet); +- + P54P_WRITE(int_enable, cpu_to_le32(0)); + P54P_READ(int_enable); + udelay(10); + + free_irq(priv->pdev->irq, dev); + ++ tasklet_kill(&priv->tasklet); ++ + P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_RESET)); + + for (i = 0; i < ARRAY_SIZE(priv->rx_buf_data); i++) { +From: Quintin Pitts +Date: Fri, 9 Apr 2010 19:37:38 +0000 (+0200) +Subject: p54pci: prevent stuck rx-ring on slow system +X-Git-Tag: master-2010-04-12~9 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Flinville%2Fwireless-next-2.6.git;a=commitdiff_plain;h=5988f385b4cffa9ca72c5be0188e5f4c9ef46d82 + +p54pci: prevent stuck rx-ring on slow system + +This patch fixes an old problem, which - under certain +circumstances - could cause the device to become +unresponsive. + +most of p54pci's rx-ring management is implemented in just +two distinct standalone functions. p54p_check_rx_ring takes +care of processing incoming data, while p54p_refill_rx_ring +tries to replenish all depleted communication buffers. + +This has always worked fine on my fast machine, but +now I know there is a hidden race... + +The most likely candidate here is ring_control->device_idx. +Quintin Pitts had already analyzed the culprit and posted +a patch back in Oct 2009. But sadly, no one's picked up on this. +( https://patchwork.kernel.org/patch/53079/ [2 & 3] ). +This patch does the same way, except that it also prioritize +rx data processing, simply because tx routines *can* wait. + +Reported-by: Sean Young +Bugzilla: https://bugzilla.kernel.org/show_bug.cgi?id=11386 +Reported-by: Quintin Pitts +Signed-off-by: Quintin Pitts +Signed-off-by: Christian Lamparter +Signed-off-by: John W. Linville +--- + +diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c +index ed4bdff..aa29663 100644 +--- a/drivers/net/wireless/p54/p54pci.c ++++ b/drivers/net/wireless/p54/p54pci.c +@@ -131,7 +131,7 @@ static int p54p_upload_firmware(struct ieee80211_hw *dev) + + static void p54p_refill_rx_ring(struct ieee80211_hw *dev, + int ring_index, struct p54p_desc *ring, u32 ring_limit, +- struct sk_buff **rx_buf) ++ struct sk_buff **rx_buf, u32 index) + { + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; +@@ -139,7 +139,7 @@ static void p54p_refill_rx_ring(struct ieee80211_hw *dev, + + idx = le32_to_cpu(ring_control->host_idx[ring_index]); + limit = idx; +- limit -= le32_to_cpu(ring_control->device_idx[ring_index]); ++ limit -= le32_to_cpu(index); + limit = ring_limit - limit; + + i = idx % ring_limit; +@@ -231,7 +231,7 @@ static void p54p_check_rx_ring(struct ieee80211_hw *dev, u32 *index, + i %= ring_limit; + } + +- p54p_refill_rx_ring(dev, ring_index, ring, ring_limit, rx_buf); ++ p54p_refill_rx_ring(dev, ring_index, ring, ring_limit, rx_buf, *index); + } + + static void p54p_check_tx_ring(struct ieee80211_hw *dev, u32 *index, +@@ -276,14 +276,6 @@ static void p54p_tasklet(unsigned long dev_id) + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; + +- p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, 3, ring_control->tx_mgmt, +- ARRAY_SIZE(ring_control->tx_mgmt), +- priv->tx_buf_mgmt); +- +- p54p_check_tx_ring(dev, &priv->tx_idx_data, 1, ring_control->tx_data, +- ARRAY_SIZE(ring_control->tx_data), +- priv->tx_buf_data); +- + p54p_check_rx_ring(dev, &priv->rx_idx_mgmt, 2, ring_control->rx_mgmt, + ARRAY_SIZE(ring_control->rx_mgmt), priv->rx_buf_mgmt); + +@@ -292,6 +284,14 @@ static void p54p_tasklet(unsigned long dev_id) + + wmb(); + P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE)); ++ ++ p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, 3, ring_control->tx_mgmt, ++ ARRAY_SIZE(ring_control->tx_mgmt), ++ priv->tx_buf_mgmt); ++ ++ p54p_check_tx_ring(dev, &priv->tx_idx_data, 1, ring_control->tx_data, ++ ARRAY_SIZE(ring_control->tx_data), ++ priv->tx_buf_data); + } + + static irqreturn_t p54p_interrupt(int irq, void *dev_id) +@@ -444,10 +444,10 @@ static int p54p_open(struct ieee80211_hw *dev) + priv->rx_idx_mgmt = priv->tx_idx_mgmt = 0; + + p54p_refill_rx_ring(dev, 0, priv->ring_control->rx_data, +- ARRAY_SIZE(priv->ring_control->rx_data), priv->rx_buf_data); ++ ARRAY_SIZE(priv->ring_control->rx_data), priv->rx_buf_data, 0); + + p54p_refill_rx_ring(dev, 2, priv->ring_control->rx_mgmt, +- ARRAY_SIZE(priv->ring_control->rx_mgmt), priv->rx_buf_mgmt); ++ ARRAY_SIZE(priv->ring_control->rx_mgmt), priv->rx_buf_mgmt, 0); + + P54P_WRITE(ring_control_base, cpu_to_le32(priv->ring_control_dma)); + P54P_READ(ring_control_base); +From: Christian Lamparter +Date: Thu, 15 Apr 2010 12:17:07 +0000 (+0200) +Subject: p54pci: fix serious sparse warning +X-Git-Tag: master-2010-04-16~117 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Flinville%2Fwireless-next-2.6.git;a=commitdiff_plain;h=103823db62ffca028c7a214c80266519d2ea7d8d + +p54pci: fix serious sparse warning + +This patch fixes a bug which was just recently introduced by +("p54pci: prevent stuck rx-ring on slow system"). + +make M=drivers/net/wireless/p54 C=2 CF=-D__CHECK_ENDIAN__ + CHECK drivers/net/wireless/p54/p54pci.c +drivers/net/wireless/p54/p54pci.c:143:11: warning: cast to restricted __le32 + CC [M] drivers/net/wireless/p54/p54pci.o + +Reported-by: Johannes Berg +Signed-off-by: Christian Lamparter +Signed-off-by: John W. Linville +--- + +diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c +index aa29663..0a516c8 100644 +--- a/drivers/net/wireless/p54/p54pci.c ++++ b/drivers/net/wireless/p54/p54pci.c +@@ -139,7 +139,7 @@ static void p54p_refill_rx_ring(struct ieee80211_hw *dev, + + idx = le32_to_cpu(ring_control->host_idx[ring_index]); + limit = idx; +- limit -= le32_to_cpu(index); ++ limit -= index; + limit = ring_limit - limit; + + i = idx % ring_limit; +Subject: +[PATCH 2/2] p54pci: fix regression from prevent stuck rx-ring on slow system +From: +Christian Lamparter +Date: +Thu, 22 Apr 2010 19:52:43 +0200 +To: +linux-wireless@vger.kernel.org +CC: +linville@tuxdriver.com, hdegoede@redhat.com + +From: Hans de Goede + +This patch fixes a recently introduced use-after-free regression +from "p54pci: prevent stuck rx-ring on slow system". + +Hans de Goede reported a use-after-free regression: +> >BUG: unable to handle kernel paging request at 6b6b6b6b +> >IP: [] p54p_check_tx_ring+0x84/0xb1 [p54pci] +> >*pde = 00000000 +> >Oops: 0000 [#1] SMP +> >EIP: 0060:[] EFLAGS: 00010286 CPU: 0 +> >EIP is at p54p_check_tx_ring+0x84/0xb1 [p54pci] +> >EAX: 6b6b6b6b EBX: df10b170 ECX: 00000003 EDX: 00000001 +> >ESI: dc471500 EDI: d8acaeb0 EBP: c098be9c ESP: c098be84 +> > DS: 007b ES: 007b FS: 00d8 GS: 00e0 SS: 0068 +> >Process swapper (pid: 0, ti=c098a000 task=c09ccfe0 task.ti=c098a000) +> >Call Trace: +> > [] ? p54p_tasklet+0xaa/0xb5 [p54pci] +> > [] ? tasklet_action+0x78/0xcb +> > [] ? __do_softirq+0xbc/0x173 + +Quote from comment #17: +"The problem is the innocent looking moving of the tx processing to + after the rx processing in the tasklet. Quoting from the changelog: + This patch does it the same way, except that it also prioritize + rx data processing, simply because tx routines *can* wait. + + This is causing an issue with us referencing already freed memory, + because some skb's we transmit, we immediately receive back, such + as those for reading the eeprom (*) and getting stats. + + What can happen because of the moving of the tx processing to after + the rx processing is that when the tasklet first runs after doing a + special skb tx (such as eeprom) we've already received the answer + to it. + + Then the rx processing ends up calling p54_find_and_unlink_skb to + find the matching tx skb for the just received special rx skb and + frees the tx skb. + + Then after the processing of the rx skb answer, and thus freeing + the tx skb, we go process the completed tx ring entires, and then + dereference the free-ed skb, to see if it should free free-ed by + p54p_check_tx_ring()." + +Bugzilla: https://bugzilla.redhat.com/show_bug.cgi?id=583623 +Bug-Identified-by: Hans de Goede +Signed-off-by: Hans de Goede +Signed-off-by: Christian Lamparter +--- +diff --git a/drivers/net/wireless/p54/p54pci.c b/drivers/net/wireless/p54/p54pci.c +index ca42ccb..07c4528 100644 +--- a/drivers/net/wireless/p54/p54pci.c ++++ b/drivers/net/wireless/p54/p54pci.c +@@ -277,6 +277,14 @@ static void p54p_tasklet(unsigned long dev_id) + struct p54p_priv *priv = dev->priv; + struct p54p_ring_control *ring_control = priv->ring_control; + ++ p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, 3, ring_control->tx_mgmt, ++ ARRAY_SIZE(ring_control->tx_mgmt), ++ priv->tx_buf_mgmt); ++ ++ p54p_check_tx_ring(dev, &priv->tx_idx_data, 1, ring_control->tx_data, ++ ARRAY_SIZE(ring_control->tx_data), ++ priv->tx_buf_data); ++ + p54p_check_rx_ring(dev, &priv->rx_idx_mgmt, 2, ring_control->rx_mgmt, + ARRAY_SIZE(ring_control->rx_mgmt), priv->rx_buf_mgmt); + +@@ -285,14 +293,6 @@ static void p54p_tasklet(unsigned long dev_id) + + wmb(); + P54P_WRITE(dev_int, cpu_to_le32(ISL38XX_DEV_INT_UPDATE)); +- +- p54p_check_tx_ring(dev, &priv->tx_idx_mgmt, 3, ring_control->tx_mgmt, +- ARRAY_SIZE(ring_control->tx_mgmt), +- priv->tx_buf_mgmt); +- +- p54p_check_tx_ring(dev, &priv->tx_idx_data, 1, ring_control->tx_data, +- ARRAY_SIZE(ring_control->tx_data), +- priv->tx_buf_data); + } + + static irqreturn_t p54p_interrupt(int irq, void *dev_id) diff --git a/linux-2.6-pciehp-update.patch b/linux-2.6-pciehp-update.patch new file mode 100644 index 000000000..38ec79724 --- /dev/null +++ b/linux-2.6-pciehp-update.patch @@ -0,0 +1,147 @@ +diff --git a/drivers/pci/hotplug/pciehp.h b/drivers/pci/hotplug/pciehp.h +index b2801a7..c9f18f9 100644 +--- a/drivers/pci/hotplug/pciehp.h ++++ b/drivers/pci/hotplug/pciehp.h +@@ -224,6 +224,10 @@ static inline int pciehp_get_hp_hw_control_from_firmware(struct pci_dev *dev) + { + u32 flags = (OSC_PCI_EXPRESS_NATIVE_HP_CONTROL | + OSC_PCI_EXPRESS_CAP_STRUCTURE_CONTROL); ++ if (pciehp_force) { ++ dev_info(&dev->dev, "Bypassing BIOS check for pciehp\n"); ++ return 0; ++ } + return acpi_get_hp_hw_control_from_firmware(dev, flags); + } + +diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c +index 39cf248..ab6b016 100644 +--- a/drivers/pci/hotplug/pciehp_core.c ++++ b/drivers/pci/hotplug/pciehp_core.c +@@ -41,6 +41,7 @@ int pciehp_debug; + int pciehp_poll_mode; + int pciehp_poll_time; + int pciehp_force; ++int pciehp_passive; + struct workqueue_struct *pciehp_wq; + + #define DRIVER_VERSION "0.4" +@@ -50,15 +51,18 @@ struct workqueue_struct *pciehp_wq; + MODULE_AUTHOR(DRIVER_AUTHOR); + MODULE_DESCRIPTION(DRIVER_DESC); + MODULE_LICENSE("GPL"); ++MODULE_ALIAS("acpi*:PNP0A08:*"); + + module_param(pciehp_debug, bool, 0644); + module_param(pciehp_poll_mode, bool, 0644); + module_param(pciehp_poll_time, int, 0644); + module_param(pciehp_force, bool, 0644); ++module_param(pciehp_passive, bool, 0644); + MODULE_PARM_DESC(pciehp_debug, "Debugging mode enabled or not"); + MODULE_PARM_DESC(pciehp_poll_mode, "Using polling mechanism for hot-plug events or not"); + MODULE_PARM_DESC(pciehp_poll_time, "Polling mechanism frequency, in seconds"); + MODULE_PARM_DESC(pciehp_force, "Force pciehp, even if _OSC and OSHP are missing"); ++MODULE_PARM_DESC(pciehp_passive, "Listen for pciehp events, even if _OSC and OSHP are missing"); + + #define PCIE_MODULE_NAME "pciehp" + +@@ -85,6 +89,13 @@ static struct hotplug_slot_ops pciehp_hotplug_slot_ops = { + .get_cur_bus_speed = get_cur_bus_speed, + }; + ++static struct hotplug_slot_ops pciehp_passive_hotplug_slot_ops = { ++ .owner = THIS_MODULE, ++ .get_adapter_status = get_adapter_status, ++ .get_max_bus_speed = get_max_bus_speed, ++ .get_cur_bus_speed = get_cur_bus_speed, ++}; ++ + /* + * Check the status of the Electro Mechanical Interlock (EMI) + */ +@@ -212,7 +223,11 @@ static int init_slots(struct controller *ctrl) + hotplug_slot->info = info; + hotplug_slot->private = slot; + hotplug_slot->release = &release_slot; +- hotplug_slot->ops = &pciehp_hotplug_slot_ops; ++ if (pciehp_passive && ++ pciehp_get_hp_hw_control_from_firmware(ctrl->pci_dev)) ++ hotplug_slot->ops = &pciehp_passive_hotplug_slot_ops; ++ else ++ hotplug_slot->ops = &pciehp_hotplug_slot_ops; + slot->hotplug_slot = hotplug_slot; + snprintf(name, SLOT_NAME_SIZE, "%u", slot->number); + +@@ -407,11 +422,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_ + u8 value; + struct pci_dev *pdev = dev->port; + +- if (pciehp_force) +- dev_info(&dev->device, +- "Bypassing BIOS check for pciehp use on %s\n", +- pci_name(pdev)); +- else if (pciehp_get_hp_hw_control_from_firmware(pdev)) ++ if (!pciehp_passive && pciehp_get_hp_hw_control_from_firmware(pdev)) + goto err_out_none; + + ctrl = pcie_init(dev); +@@ -436,7 +447,7 @@ static int pciehp_probe(struct pcie_device *dev, const struct pcie_port_service_ + t_slot = pciehp_find_slot(ctrl, ctrl->slot_device_offset); + t_slot->hpc_ops->get_adapter_status(t_slot, &value); + if (value) { +- if (pciehp_force) ++ if (pciehp_force || pciehp_passive) + pciehp_enable_slot(t_slot); + } else { + /* Power off slot if not occupied */ +@@ -474,8 +485,11 @@ static int pciehp_suspend (struct pcie_device *dev, pm_message_t state) + + static int pciehp_resume (struct pcie_device *dev) + { ++ struct pci_dev *pdev = dev->port; + dev_info(&dev->device, "%s ENTRY\n", __func__); +- if (pciehp_force) { ++ ++ if (pciehp_force || (pciehp_passive && ++ pciehp_get_hp_hw_control_from_firmware(pdev))) { + struct controller *ctrl = get_service_data(dev); + struct slot *t_slot; + u8 status; +diff --git a/drivers/pci/hotplug/pciehp_ctrl.c b/drivers/pci/hotplug/pciehp_ctrl.c +index fead63c..12640bd 100644 +--- a/drivers/pci/hotplug/pciehp_ctrl.c ++++ b/drivers/pci/hotplug/pciehp_ctrl.c +@@ -185,7 +185,8 @@ static void set_slot_off(struct controller *ctrl, struct slot * pslot) + * before taking any action that relies on power having been + * removed from the slot/adapter. + */ +- msleep(1000); ++ if (PWR_LED(ctrl) || ATTN_LED(ctrl)) ++ msleep(1000); + + if (PWR_LED(ctrl)) + pslot->hpc_ops->green_led_off(pslot); +@@ -288,16 +289,16 @@ static int remove_board(struct slot *p_slot) + } + } + +- /* +- * After turning power off, we must wait for at least 1 second +- * before taking any action that relies on power having been +- * removed from the slot/adapter. +- */ +- msleep(1000); +- +- if (PWR_LED(ctrl)) ++ if (PWR_LED(ctrl)) { ++ /* ++ * After turning power off, we must wait for at least 1 second ++ * before taking any action that relies on power having been ++ * removed from the slot/adapter. ++ */ ++ msleep(1000); + /* turn off Green LED */ + p_slot->hpc_ops->green_led_off(p_slot); ++ } + + return 0; + } diff --git a/linux-2.6-phylib-autoload.patch b/linux-2.6-phylib-autoload.patch new file mode 100644 index 000000000..2b9122560 --- /dev/null +++ b/linux-2.6-phylib-autoload.patch @@ -0,0 +1,403 @@ +From c413dfa59bf979475a9647cc165f547021efeb27 Mon Sep 17 00:00:00 2001 +From: David Woodhouse +Date: Wed, 31 Mar 2010 02:10:20 +0100 +Subject: [PATCH 1/2] phylib: Support phy module autoloading + +We don't use the normal hotplug mechanism because it doesn't work. It will +load the module some time after the device appears, but that's not good +enough for us -- we need the driver loaded _immediately_ because otherwise +the NIC driver may just abort and then the phy 'device' goes away. + +[bwh: s/phy/mdio/ in module alias, kerneldoc for struct mdio_device_id] + +Signed-off-by: David Woodhouse +--- + drivers/net/phy/phy_device.c | 12 ++++++++++++ + include/linux/mod_devicetable.h | 26 ++++++++++++++++++++++++++ + include/linux/phy.h | 1 + + scripts/mod/file2alias.c | 26 ++++++++++++++++++++++++++ + 4 files changed, 65 insertions(+), 0 deletions(-) + +From 9ddd9886cc89827a4713e9a96614148272fdaa8e Mon Sep 17 00:00:00 2001 +From: David Woodhouse +Date: Wed, 31 Mar 2010 02:12:06 +0100 +Subject: [PATCH 2/2] phylib: Add module table to all existing phy drivers + +Signed-off-by: David Woodhouse +--- + drivers/net/phy/bcm63xx.c | 8 ++++++++ + drivers/net/phy/broadcom.c | 16 ++++++++++++++++ + drivers/net/phy/cicada.c | 8 ++++++++ + drivers/net/phy/davicom.c | 9 +++++++++ + drivers/net/phy/et1011c.c | 7 +++++++ + drivers/net/phy/icplus.c | 7 +++++++ + drivers/net/phy/lxt.c | 8 ++++++++ + drivers/net/phy/marvell.c | 13 +++++++++++++ + drivers/net/phy/national.c | 7 +++++++ + drivers/net/phy/qsemi.c | 7 +++++++ + drivers/net/phy/realtek.c | 7 +++++++ + drivers/net/phy/smsc.c | 11 +++++++++++ + drivers/net/phy/ste10Xp.c | 8 ++++++++ + drivers/net/phy/vitesse.c | 8 ++++++++ + 14 files changed, 124 insertions(+), 0 deletions(-) + +diff --git a/drivers/net/phy/bcm63xx.c b/drivers/net/phy/bcm63xx.c +index 4fed95e..ac5e498 100644 +--- a/drivers/net/phy/bcm63xx.c ++++ b/drivers/net/phy/bcm63xx.c +@@ -130,3 +130,11 @@ static void __exit bcm63xx_phy_exit(void) + + module_init(bcm63xx_phy_init); + module_exit(bcm63xx_phy_exit); ++ ++static struct mdio_device_id bcm63xx_tbl[] = { ++ { 0x00406000, 0xfffffc00 }, ++ { 0x002bdc00, 0xfffffc00 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, bcm64xx_tbl); +diff --git a/drivers/net/phy/broadcom.c b/drivers/net/phy/broadcom.c +index 33c4b12..f1939c3 100644 +--- a/drivers/net/phy/broadcom.c ++++ b/drivers/net/phy/broadcom.c +@@ -911,3 +911,19 @@ static void __exit broadcom_exit(void) + + module_init(broadcom_init); + module_exit(broadcom_exit); ++ ++static struct mdio_device_id broadcom_tbl[] = { ++ { 0x00206070, 0xfffffff0 }, ++ { 0x002060e0, 0xfffffff0 }, ++ { 0x002060c0, 0xfffffff0 }, ++ { 0x002060b0, 0xfffffff0 }, ++ { 0x0143bca0, 0xfffffff0 }, ++ { 0x0143bcb0, 0xfffffff0 }, ++ { PHY_ID_BCM50610, 0xfffffff0 }, ++ { PHY_ID_BCM50610M, 0xfffffff0 }, ++ { PHY_ID_BCM57780, 0xfffffff0 }, ++ { 0x0143bc70, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, broadcom_tbl); +diff --git a/drivers/net/phy/cicada.c b/drivers/net/phy/cicada.c +index a1bd599..efc608f 100644 +--- a/drivers/net/phy/cicada.c ++++ b/drivers/net/phy/cicada.c +@@ -159,3 +159,11 @@ static void __exit cicada_exit(void) + + module_init(cicada_init); + module_exit(cicada_exit); ++ ++static struct mdio_device_id cicada_tbl[] = { ++ { 0x000fc410, 0x000ffff0 }, ++ { 0x000fc440, 0x000fffc0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, cicada_tbl); +diff --git a/drivers/net/phy/davicom.c b/drivers/net/phy/davicom.c +index d926168..e02b18c 100644 +--- a/drivers/net/phy/davicom.c ++++ b/drivers/net/phy/davicom.c +@@ -219,3 +219,12 @@ static void __exit davicom_exit(void) + + module_init(davicom_init); + module_exit(davicom_exit); ++ ++static struct mdio_device_id davicom_tbl[] = { ++ { 0x0181b880, 0x0ffffff0 }, ++ { 0x0181b8a0, 0x0ffffff0 }, ++ { 0x00181b80, 0x0ffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, davicom_tbl); +diff --git a/drivers/net/phy/et1011c.c b/drivers/net/phy/et1011c.c +index b031fa2..500f0fd 100644 +--- a/drivers/net/phy/et1011c.c ++++ b/drivers/net/phy/et1011c.c +@@ -111,3 +111,10 @@ static void __exit et1011c_exit(void) + + module_init(et1011c_init); + module_exit(et1011c_exit); ++ ++static struct mdio_device_id et1011c_tbl[] = { ++ { 0x0282f014, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, et1011c_tbl); +diff --git a/drivers/net/phy/icplus.c b/drivers/net/phy/icplus.c +index af3f1f2..e661e90 100644 +--- a/drivers/net/phy/icplus.c ++++ b/drivers/net/phy/icplus.c +@@ -132,3 +132,10 @@ static void __exit ip175c_exit(void) + + module_init(ip175c_init); + module_exit(ip175c_exit); ++ ++static struct mdio_device_id icplus_tbl[] = { ++ { 0x02430d80, 0x0ffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, icplus_tbl); +diff --git a/drivers/net/phy/lxt.c b/drivers/net/phy/lxt.c +index 4cf3324..1d94f1d 100644 +--- a/drivers/net/phy/lxt.c ++++ b/drivers/net/phy/lxt.c +@@ -174,3 +174,11 @@ static void __exit lxt_exit(void) + + module_init(lxt_init); + module_exit(lxt_exit); ++ ++static struct mdio_device_id lxt_tbl[] = { ++ { 0x78100000, 0xfffffff0 }, ++ { 0x001378e0, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, lxt_tbl); +diff --git a/drivers/net/phy/marvell.c b/drivers/net/phy/marvell.c +index 6f69b9b..4e58b2c 100644 +--- a/drivers/net/phy/marvell.c ++++ b/drivers/net/phy/marvell.c +@@ -611,3 +611,16 @@ static void __exit marvell_exit(void) + + module_init(marvell_init); + module_exit(marvell_exit); ++ ++static struct mdio_device_id marvell_tbl[] = { ++ { 0x01410c60, 0xfffffff0 }, ++ { 0x01410c90, 0xfffffff0 }, ++ { 0x01410cc0, 0xfffffff0 }, ++ { 0x01410e10, 0xfffffff0 }, ++ { 0x01410cb0, 0xfffffff0 }, ++ { 0x01410cd0, 0xfffffff0 }, ++ { 0x01410e30, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, marvell_tbl); +diff --git a/drivers/net/phy/national.c b/drivers/net/phy/national.c +index 6c636eb..729ab29 100644 +--- a/drivers/net/phy/national.c ++++ b/drivers/net/phy/national.c +@@ -153,3 +153,10 @@ MODULE_LICENSE("GPL"); + + module_init(ns_init); + module_exit(ns_exit); ++ ++static struct mdio_device_id ns_tbl[] = { ++ { DP83865_PHY_ID, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, ns_tbl); +diff --git a/drivers/net/phy/phy_device.c b/drivers/net/phy/phy_device.c +index adbc0fd..16aa083 100644 +--- a/drivers/net/phy/phy_device.c ++++ b/drivers/net/phy/phy_device.c +@@ -149,6 +149,7 @@ EXPORT_SYMBOL(phy_scan_fixups); + struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) + { + struct phy_device *dev; ++ + /* We allocate the device, and initialize the + * default values */ + dev = kzalloc(sizeof(*dev), GFP_KERNEL); +@@ -179,6 +180,17 @@ struct phy_device* phy_device_create(struct mii_bus *bus, int addr, int phy_id) + mutex_init(&dev->lock); + INIT_DELAYED_WORK(&dev->state_queue, phy_state_machine); + ++ /* Request the appropriate module unconditionally; don't ++ bother trying to do so only if it isn't already loaded, ++ because that gets complicated. A hotplug event would have ++ done an unconditional modprobe anyway. ++ We don't do normal hotplug because it won't work for MDIO ++ -- because it relies on the device staying around for long ++ enough for the driver to get loaded. With MDIO, the NIC ++ driver will get bored and give up as soon as it finds that ++ there's no driver _already_ loaded. */ ++ request_module(MDIO_MODULE_PREFIX MDIO_ID_FMT, MDIO_ID_ARGS(phy_id)); ++ + return dev; + } + EXPORT_SYMBOL(phy_device_create); +diff --git a/drivers/net/phy/qsemi.c b/drivers/net/phy/qsemi.c +index 23062d0..3ec9610 100644 +--- a/drivers/net/phy/qsemi.c ++++ b/drivers/net/phy/qsemi.c +@@ -138,3 +138,10 @@ static void __exit qs6612_exit(void) + + module_init(qs6612_init); + module_exit(qs6612_exit); ++ ++static struct mdio_device_id qs6612_tbl[] = { ++ { 0x00181440, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, qs6612_tbl); +diff --git a/drivers/net/phy/realtek.c b/drivers/net/phy/realtek.c +index a052a67..f567c0e 100644 +--- a/drivers/net/phy/realtek.c ++++ b/drivers/net/phy/realtek.c +@@ -78,3 +78,10 @@ static void __exit realtek_exit(void) + + module_init(realtek_init); + module_exit(realtek_exit); ++ ++static struct mdio_device_id realtek_tbl[] = { ++ { 0x001cc912, 0x001fffff }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, realtek_tbl); +diff --git a/drivers/net/phy/smsc.c b/drivers/net/phy/smsc.c +index 5123bb9..9fb14b4 100644 +--- a/drivers/net/phy/smsc.c ++++ b/drivers/net/phy/smsc.c +@@ -236,3 +236,14 @@ MODULE_LICENSE("GPL"); + + module_init(smsc_init); + module_exit(smsc_exit); ++ ++static struct mdio_device_id smsc_tbl[] = { ++ { 0x0007c0a0, 0xfffffff0 }, ++ { 0x0007c0b0, 0xfffffff0 }, ++ { 0x0007c0c0, 0xfffffff0 }, ++ { 0x0007c0d0, 0xfffffff0 }, ++ { 0x0007c0f0, 0xfffffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, smsc_tbl); +diff --git a/drivers/net/phy/ste10Xp.c b/drivers/net/phy/ste10Xp.c +index 6bdb0d5..7229009 100644 +--- a/drivers/net/phy/ste10Xp.c ++++ b/drivers/net/phy/ste10Xp.c +@@ -132,6 +132,14 @@ static void __exit ste10Xp_exit(void) + module_init(ste10Xp_init); + module_exit(ste10Xp_exit); + ++static struct mdio_device_id ste10Xp_tbl[] = { ++ { STE101P_PHY_ID, 0xfffffff0 }, ++ { STE100P_PHY_ID, 0xffffffff }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, ste10Xp_tbl); ++ + MODULE_DESCRIPTION("STMicroelectronics STe10Xp PHY driver"); + MODULE_AUTHOR("Giuseppe Cavallaro "); + MODULE_LICENSE("GPL"); +diff --git a/drivers/net/phy/vitesse.c b/drivers/net/phy/vitesse.c +index dd3b244..45cce50 100644 +--- a/drivers/net/phy/vitesse.c ++++ b/drivers/net/phy/vitesse.c +@@ -191,3 +191,11 @@ static void __exit vsc82xx_exit(void) + + module_init(vsc82xx_init); + module_exit(vsc82xx_exit); ++ ++static struct mdio_device_id vitesse_tbl[] = { ++ { PHY_ID_VSC8244, 0x000fffc0 }, ++ { PHY_ID_VSC8221, 0x000ffff0 }, ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(mdio, vitesse_tbl); +diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h +index f58e9d8..55f1f9c 100644 +--- a/include/linux/mod_devicetable.h ++++ b/include/linux/mod_devicetable.h +@@ -474,4 +474,30 @@ struct platform_device_id { + __attribute__((aligned(sizeof(kernel_ulong_t)))); + }; + ++#define MDIO_MODULE_PREFIX "mdio:" ++ ++#define MDIO_ID_FMT "%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d%d" ++#define MDIO_ID_ARGS(_id) \ ++ (_id)>>31, ((_id)>>30) & 1, ((_id)>>29) & 1, ((_id)>>28) & 1, \ ++ ((_id)>>27) & 1, ((_id)>>26) & 1, ((_id)>>25) & 1, ((_id)>>24) & 1, \ ++ ((_id)>>23) & 1, ((_id)>>22) & 1, ((_id)>>21) & 1, ((_id)>>20) & 1, \ ++ ((_id)>>19) & 1, ((_id)>>18) & 1, ((_id)>>17) & 1, ((_id)>>16) & 1, \ ++ ((_id)>>15) & 1, ((_id)>>14) & 1, ((_id)>>13) & 1, ((_id)>>12) & 1, \ ++ ((_id)>>11) & 1, ((_id)>>10) & 1, ((_id)>>9) & 1, ((_id)>>8) & 1, \ ++ ((_id)>>7) & 1, ((_id)>>6) & 1, ((_id)>>5) & 1, ((_id)>>4) & 1, \ ++ ((_id)>>3) & 1, ((_id)>>2) & 1, ((_id)>>1) & 1, (_id) & 1 ++ ++/** ++ * struct mdio_device_id - identifies PHY devices on an MDIO/MII bus ++ * @phy_id: The result of ++ * (mdio_read(&MII_PHYSID1) << 16 | mdio_read(&PHYSID2)) & @phy_id_mask ++ * for this PHY type ++ * @phy_id_mask: Defines the significant bits of @phy_id. A value of 0 ++ * is used to terminate an array of struct mdio_device_id. ++ */ ++struct mdio_device_id { ++ __u32 phy_id; ++ __u32 phy_id_mask; ++}; ++ + #endif /* LINUX_MOD_DEVICETABLE_H */ +diff --git a/include/linux/phy.h b/include/linux/phy.h +index 6a7eb40..8d5715a 100644 +--- a/include/linux/phy.h ++++ b/include/linux/phy.h +@@ -24,6 +24,7 @@ + #include + #include + #include ++#include + + #include + +diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c +index 220213e..36a60a8 100644 +--- a/scripts/mod/file2alias.c ++++ b/scripts/mod/file2alias.c +@@ -796,6 +796,28 @@ static int do_platform_entry(const char *filename, + return 1; + } + ++static int do_mdio_entry(const char *filename, ++ struct mdio_device_id *id, char *alias) ++{ ++ int i; ++ ++ alias += sprintf(alias, MDIO_MODULE_PREFIX); ++ ++ for (i = 0; i < 32; i++) { ++ if (!((id->phy_id_mask >> (31-i)) & 1)) ++ *(alias++) = '?'; ++ else if ((id->phy_id >> (31-i)) & 1) ++ *(alias++) = '1'; ++ else ++ *(alias++) = '0'; ++ } ++ ++ /* Terminate the string */ ++ *alias = 0; ++ ++ return 1; ++} ++ + /* Ignore any prefix, eg. some architectures prepend _ */ + static inline int sym_is(const char *symbol, const char *name) + { +@@ -943,6 +965,10 @@ void handle_moddevtable(struct module *mod, struct elf_info *info, + do_table(symval, sym->st_size, + sizeof(struct platform_device_id), "platform", + do_platform_entry, mod); ++ else if (sym_is(symname, "__mod_mdio_device_table")) ++ do_table(symval, sym->st_size, ++ sizeof(struct mdio_device_id), "mdio", ++ do_mdio_entry, mod); + free(zeros); + } + diff --git a/linux-2.6-qcserial-autosuspend.diff b/linux-2.6-qcserial-autosuspend.diff new file mode 100644 index 000000000..566014522 --- /dev/null +++ b/linux-2.6-qcserial-autosuspend.diff @@ -0,0 +1,23 @@ +commit b2bcfa17349e5a6a01170b5269ee261dbd762a0c +Author: Matthew Garrett +Date: Sat Jul 18 14:43:36 2009 +0100 + + usb: enable autosuspend by default on qcserial + + All qcserial hardware supports autosuspend properly. Enable it by default. + + Signed-off-by: Matthew Garrett + +diff --git a/drivers/usb/serial/qcserial.c b/drivers/usb/serial/qcserial.c +index 7528b8d..959a176 100644 +--- a/drivers/usb/serial/qcserial.c ++++ b/drivers/usb/serial/qcserial.c +@@ -74,6 +74,8 @@ static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) + ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; + dbg("This Interface = %d", ifnum); + ++ usb_device_autosuspend_enable(serial->dev); ++ + switch (nintf) { + case 1: + /* QDL mode */ diff --git a/linux-2.6-rfkill-all.patch b/linux-2.6-rfkill-all.patch new file mode 100644 index 000000000..e353d2219 --- /dev/null +++ b/linux-2.6-rfkill-all.patch @@ -0,0 +1,52 @@ +From 06d4bc456d4a43fc79288b576a7ff8a15109a3fd Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Mon, 11 Jan 2010 08:47:44 -0500 +Subject: linux-2.6-rfkill-all.patch + +--- + include/linux/rfkill.h | 2 +- + net/rfkill/input.c | 8 ++++++++ + 3 files changed, 11 insertions(+), 1 deletions(-) + +diff --git a/include/linux/rfkill.h b/include/linux/rfkill.h +index 97059d0..4f82326 100644 +--- a/include/linux/rfkill.h ++++ b/include/linux/rfkill.h +@@ -29,7 +29,7 @@ + /** + * enum rfkill_type - type of rfkill switch. + * +- * @RFKILL_TYPE_ALL: toggles all switches (userspace only) ++ * @RFKILL_TYPE_ALL: toggles all switches (requests only - not a switch type) + * @RFKILL_TYPE_WLAN: switch is on a 802.11 wireless network device. + * @RFKILL_TYPE_BLUETOOTH: switch is on a bluetooth device. + * @RFKILL_TYPE_UWB: switch is on a ultra wideband device. +diff --git a/net/rfkill/input.c b/net/rfkill/input.c +index a7295ad..3713d7e 100644 +--- a/net/rfkill/input.c ++++ b/net/rfkill/input.c +@@ -212,6 +212,9 @@ static void rfkill_event(struct input_handle *handle, unsigned int type, + case KEY_WIMAX: + rfkill_schedule_toggle(RFKILL_TYPE_WIMAX); + break; ++ case KEY_RFKILL: ++ rfkill_schedule_toggle(RFKILL_TYPE_ALL); ++ break; + } + } else if (type == EV_SW && code == SW_RFKILL_ALL) + rfkill_schedule_evsw_rfkillall(data); +@@ -295,6 +298,11 @@ static const struct input_device_id rfkill_ids[] = { + .keybit = { [BIT_WORD(KEY_WIMAX)] = BIT_MASK(KEY_WIMAX) }, + }, + { ++ .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_KEYBIT, ++ .evbit = { BIT_MASK(EV_KEY) }, ++ .keybit = { [BIT_WORD(KEY_RFKILL)] = BIT_MASK(KEY_RFKILL) }, ++ }, ++ { + .flags = INPUT_DEVICE_ID_MATCH_EVBIT | INPUT_DEVICE_ID_MATCH_SWBIT, + .evbit = { BIT(EV_SW) }, + .swbit = { [BIT_WORD(SW_RFKILL_ALL)] = BIT_MASK(SW_RFKILL_ALL) }, +-- +1.6.5.2 + diff --git a/linux-2.6-selinux-avtab-size.patch b/linux-2.6-selinux-avtab-size.patch new file mode 100644 index 000000000..59d635f6d --- /dev/null +++ b/linux-2.6-selinux-avtab-size.patch @@ -0,0 +1,30 @@ +commit 6c9ff1013b7a21099da838eeef7c3f23ee347957 +Author: Stephen Smalley +Date: Mon Mar 15 10:42:11 2010 -0400 + + SELinux: Reduce max avtab size to avoid page allocation failures + + Reduce MAX_AVTAB_HASH_BITS so that the avtab allocation is an order 2 + allocation rather than an order 4 allocation on x86_64. This + addresses reports of page allocation failures: + http://marc.info/?l=selinux&m=126757230625867&w=2 + https://bugzilla.redhat.com/show_bug.cgi?id=570433 + + Reported-by: Russell Coker + Signed-off-by: Stephen D. Smalley + Acked-by: Eric Paris + Signed-off-by: James Morris + +diff --git a/security/selinux/ss/avtab.h b/security/selinux/ss/avtab.h +index 8da6a84..cd4f734 100644 +--- a/security/selinux/ss/avtab.h ++++ b/security/selinux/ss/avtab.h +@@ -82,7 +82,7 @@ struct avtab_node *avtab_search_node_next(struct avtab_node *node, int specified + void avtab_cache_init(void); + void avtab_cache_destroy(void); + +-#define MAX_AVTAB_HASH_BITS 13 ++#define MAX_AVTAB_HASH_BITS 11 + #define MAX_AVTAB_HASH_BUCKETS (1 << MAX_AVTAB_HASH_BITS) + #define MAX_AVTAB_HASH_MASK (MAX_AVTAB_HASH_BUCKETS-1) + #define MAX_AVTAB_SIZE MAX_AVTAB_HASH_BUCKETS diff --git a/linux-2.6-selinux-mprotect-checks.patch b/linux-2.6-selinux-mprotect-checks.patch new file mode 100644 index 000000000..175252537 --- /dev/null +++ b/linux-2.6-selinux-mprotect-checks.patch @@ -0,0 +1,41 @@ +This needs a fixed toolchain, and a userspace rebuild to work. +For these reasons, it's had difficulty getting upstream. + +ie, Fedora has a new enough toolchain, and has been rebuilt, so we don't need +the ifdefs. Other distros don't/haven't, and this patch would break them +if pushed upstream. + +--- linux-2.6.26.noarch/security/selinux/hooks.c~ 2008-09-25 14:11:17.000000000 -0400 ++++ linux-2.6.26.noarch/security/selinux/hooks.c 2008-09-25 14:12:17.000000000 -0400 +@@ -3018,7 +3018,6 @@ static int file_map_prot_check(struct fi + const struct cred *cred = current_cred(); + int rc = 0; + +-#ifndef CONFIG_PPC32 + if ((prot & PROT_EXEC) && (!file || (!shared && (prot & PROT_WRITE)))) { + /* + * We are making executable an anonymous mapping or a +@@ -3029,7 +3028,6 @@ static int file_map_prot_check(struct fi + if (rc) + goto error; + } +-#endif + + if (file) { + /* read access is always possible with a mapping */ +@@ -3024,7 +3022,6 @@ static int selinux_file_mprotect(struct + if (selinux_checkreqprot) + prot = reqprot; + +-#ifndef CONFIG_PPC32 + if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) { + rc = 0; + if (vma->vm_start >= vma->vm_mm->start_brk && +@@ -3049,7 +3046,6 @@ static int selinux_file_mprotect(struct + if (rc) + return rc; + } +-#endif + + return file_map_prot_check(vma->vm_file, prot, vma->vm_flags&VM_SHARED); + } diff --git a/linux-2.6-serial-460800.patch b/linux-2.6-serial-460800.patch new file mode 100644 index 000000000..17d67ef64 --- /dev/null +++ b/linux-2.6-serial-460800.patch @@ -0,0 +1,70 @@ +diff --git a/drivers/serial/8250.c b/drivers/serial/8250.c +index 2209620..659c1bb 100644 +--- a/drivers/serial/8250.c ++++ b/drivers/serial/8250.c +@@ -7,6 +7,9 @@ + * + * Copyright (C) 2001 Russell King. + * ++ * 2005/09/16: Enabled higher baud rates for 16C95x. ++ * (Mathias Adam ) ++ * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or +@@ -2227,6 +2230,14 @@ static unsigned int serial8250_get_divisor(struct uart_port *port, unsigned int + else if ((port->flags & UPF_MAGIC_MULTIPLIER) && + baud == (port->uartclk/8)) + quot = 0x8002; ++ /* ++ * For 16C950s UART_TCR is used in combination with divisor==1 ++ * to achieve baud rates up to baud_base*4. ++ */ ++ else if ((port->type == PORT_16C950) && ++ baud > (port->uartclk/16)) ++ quot = 1; ++ + else + quot = uart_get_divisor(port, baud); + +@@ -2240,7 +2251,7 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, + struct uart_8250_port *up = (struct uart_8250_port *)port; + unsigned char cval, fcr = 0; + unsigned long flags; +- unsigned int baud, quot; ++ unsigned int baud, quot, max_baud; + + switch (termios->c_cflag & CSIZE) { + case CS5: +@@ -2272,9 +2283,10 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, + /* + * Ask the core to calculate the divisor for us. + */ ++ max_baud = (up->port.type == PORT_16C950 ? port->uartclk/4 : port->uartclk/16); + baud = uart_get_baud_rate(port, termios, old, + port->uartclk / 16 / 0xffff, +- port->uartclk / 16); ++ max_baud); + quot = serial8250_get_divisor(port, baud); + + /* +@@ -2311,6 +2323,19 @@ serial8250_set_termios(struct uart_port *port, struct ktermios *termios, + spin_lock_irqsave(&up->port.lock, flags); + + /* ++ * 16C950 supports additional prescaler ratios between 1:16 and 1:4 ++ * thus increasing max baud rate to uartclk/4. ++ */ ++ if (up->port.type == PORT_16C950) { ++ if (baud == port->uartclk/4) ++ serial_icr_write(up, UART_TCR, 0x4); ++ else if (baud == port->uartclk/8) ++ serial_icr_write(up, UART_TCR, 0x8); ++ else ++ serial_icr_write(up, UART_TCR, 0); ++ } ++ ++ /* + * Update the per-port timeout. + */ + uart_update_timeout(port, termios->c_cflag, baud); diff --git a/linux-2.6-silence-acpi-blacklist.patch b/linux-2.6-silence-acpi-blacklist.patch new file mode 100644 index 000000000..c5997bb6e --- /dev/null +++ b/linux-2.6-silence-acpi-blacklist.patch @@ -0,0 +1,25 @@ +diff -up linux-2.6.26.noarch/drivers/acpi/blacklist.c.jx linux-2.6.26.noarch/drivers/acpi/blacklist.c +--- linux-2.6.26.noarch/drivers/acpi/blacklist.c.jx 2008-07-13 17:51:29.000000000 -0400 ++++ linux-2.6.26.noarch/drivers/acpi/blacklist.c 2008-08-12 14:21:39.000000000 -0400 +@@ -81,18 +81,18 @@ static int __init blacklist_by_year(void + + /* Doesn't exist? Likely an old system */ + if (!dmi_get_date(DMI_BIOS_DATE, &year, NULL, NULL)) { +- printk(KERN_ERR PREFIX "no DMI BIOS year, " ++ printk(KERN_INFO PREFIX "no DMI BIOS year, " + "acpi=force is required to enable ACPI\n" ); + return 1; + } + /* 0? Likely a buggy new BIOS */ + if (year == 0) { +- printk(KERN_ERR PREFIX "DMI BIOS year==0, " ++ printk(KERN_INFO PREFIX "DMI BIOS year==0, " + "assuming ACPI-capable machine\n" ); + return 0; + } + if (year < CONFIG_ACPI_BLACKLIST_YEAR) { +- printk(KERN_ERR PREFIX "BIOS age (%d) fails cutoff (%d), " ++ printk(KERN_INFO PREFIX "BIOS age (%d) fails cutoff (%d), " + "acpi=force is required to enable ACPI\n", + year, CONFIG_ACPI_BLACKLIST_YEAR); + return 1; diff --git a/linux-2.6-silence-fbcon-logo.patch b/linux-2.6-silence-fbcon-logo.patch new file mode 100644 index 000000000..45ab73331 --- /dev/null +++ b/linux-2.6-silence-fbcon-logo.patch @@ -0,0 +1,42 @@ +diff --git a/drivers/video/console/fbcon.c b/drivers/video/console/fbcon.c +index 1657b96..4c5c2be 100644 +--- a/drivers/video/console/fbcon.c ++++ b/drivers/video/console/fbcon.c +@@ -631,13 +631,15 @@ static void fbcon_prepare_logo(struct vc_data *vc, struct fb_info *info, + kfree(save); + } + +- if (logo_lines > vc->vc_bottom) { +- logo_shown = FBCON_LOGO_CANSHOW; +- printk(KERN_INFO +- "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n"); +- } else if (logo_shown != FBCON_LOGO_DONTSHOW) { +- logo_shown = FBCON_LOGO_DRAW; +- vc->vc_top = logo_lines; ++ if (logo_shown != FBCON_LOGO_DONTSHOW) { ++ if (logo_lines > vc->vc_bottom) { ++ logo_shown = FBCON_LOGO_CANSHOW; ++ printk(KERN_INFO ++ "fbcon_init: disable boot-logo (boot-logo bigger than screen).\n"); ++ } else { ++ logo_shown = FBCON_LOGO_DRAW; ++ vc->vc_top = logo_lines; ++ } + } + } + #endif /* MODULE */ +@@ -3489,6 +3491,14 @@ static int __init fb_console_init(void) + return 0; + } + ++static int __init quiet_logo(char *str) ++{ ++ logo_shown = FBCON_LOGO_DONTSHOW; ++ return 0; ++} ++ ++early_param("quiet", quiet_logo); ++ + module_init(fb_console_init); + + #ifdef MODULE diff --git a/linux-2.6-silence-noise.patch b/linux-2.6-silence-noise.patch new file mode 100644 index 000000000..119a97769 --- /dev/null +++ b/linux-2.6-silence-noise.patch @@ -0,0 +1,66 @@ +--- linux-2.6.26.noarch/drivers/base/power/main.c~ 2008-08-22 20:57:57.000000000 -0400 ++++ linux-2.6.26.noarch/drivers/base/power/main.c 2008-08-22 20:58:05.000000000 -0400 +@@ -69,9 +69,6 @@ void device_pm_unlock(void) + */ + void device_pm_add(struct device *dev) + { +- pr_debug("PM: Adding info for %s:%s\n", +- dev->bus ? dev->bus->name : "No Bus", +- kobject_name(&dev->kobj)); + mutex_lock(&dpm_list_mtx); + if (dev->parent) { + if (dev->parent->power.status >= DPM_SUSPENDING) +From b4e96f34c17e5a79cd28774cc722bb33e7e02c6e Mon Sep 17 00:00:00 2001 +From: Peter Jones +Date: Thu, 25 Sep 2008 16:23:33 -0400 +Subject: [PATCH] Don't print an error message just because there's no i8042 chip. + +Some systems, such as EFI-based Apple systems, won't necessarily have an +i8042 to initialize. We shouldn't be printing an error message in this +case, since not detecting the chip is the correct behavior. +--- + drivers/input/serio/i8042.c | 4 +--- + 1 files changed, 1 insertions(+), 3 deletions(-) + +diff --git a/drivers/input/serio/i8042.c b/drivers/input/serio/i8042.c +index 170f71e..4f3e632 100644 +--- a/drivers/input/serio/i8042.c ++++ b/drivers/input/serio/i8042.c +@@ -701,10 +701,8 @@ static int __devinit i8042_check_aux(void) + + static int i8042_controller_check(void) + { +- if (i8042_flush() == I8042_BUFFER_SIZE) { +- printk(KERN_ERR "i8042.c: No controller found.\n"); ++ if (i8042_flush() == I8042_BUFFER_SIZE) + return -ENODEV; +- } + + return 0; + } +-- +1.6.0.1 + +Socket fuzzers like sfuzz will trigger this printk a lot, even though it's +ratelimited. It isn't particularly useful, so just remove it. + +Signed-off-by: Dave Jones + +--- linux-2.6.27.noarch/net/can/af_can.c~ 2008-12-11 16:53:48.000000000 -0500 ++++ linux-2.6.27.noarch/net/can/af_can.c 2008-12-11 16:54:42.000000000 -0500 +@@ -134,13 +134,9 @@ static int can_create(struct net *net, s + err = request_module("can-proto-%d", protocol); + + /* +- * In case of error we only print a message but don't +- * return the error code immediately. Below we will +- * return -EPROTONOSUPPORT ++ * In case of error we don't return the error code immediately. ++ * Below we will return -EPROTONOSUPPORT + */ +- if (err && printk_ratelimit()) +- printk(KERN_ERR "can: request_module " +- "(can-proto-%d) failed.\n", protocol); + } + #endif + diff --git a/linux-2.6-sparc-selinux-mprotect-checks.patch b/linux-2.6-sparc-selinux-mprotect-checks.patch new file mode 100644 index 000000000..cc821e323 --- /dev/null +++ b/linux-2.6-sparc-selinux-mprotect-checks.patch @@ -0,0 +1,35 @@ +diff -up linux-2.6.24.sparc64/security/selinux/hooks.c.BAD linux-2.6.24.sparc64/security/selinux/hooks.c +--- linux-2.6.24.sparc64/security/selinux/hooks.c.BAD 2008-03-21 14:28:06.000000000 -0400 ++++ linux-2.6.24.sparc64/security/selinux/hooks.c 2008-03-21 14:29:10.000000000 -0400 +@@ -3018,6 +3018,7 @@ static int file_map_prot_check(struct fi + const struct cred *cred = current_cred(); + int rc = 0; + ++#ifndef CONFIG_SPARC + if ((prot & PROT_EXEC) && (!file || (!shared && (prot & PROT_WRITE)))) { + /* + * We are making executable an anonymous mapping or a +@@ -3028,6 +3029,7 @@ static int file_map_prot_check(struct fi + if (rc) + goto error; + } ++#endif + + if (file) { + /* read access is always possible with a mapping */ +@@ -3081,6 +3081,7 @@ static int selinux_file_mprotect(struct + if (selinux_checkreqprot) + prot = reqprot; + ++#ifndef CONFIG_SPARC + if ((prot & PROT_EXEC) && !(vma->vm_flags & VM_EXEC)) { + rc = 0; + if (vma->vm_start >= vma->vm_mm->start_brk && +@@ -3103,6 +3103,7 @@ static int selinux_file_mprotect(struct + if (rc) + return rc; + } ++#endif + + return file_map_prot_check(vma->vm_file, prot, vma->vm_flags&VM_SHARED); + } diff --git a/linux-2.6-tracehook.patch b/linux-2.6-tracehook.patch new file mode 100644 index 000000000..b8c54adcc --- /dev/null +++ b/linux-2.6-tracehook.patch @@ -0,0 +1,129 @@ +From: Oleg Nesterov + +[PATCH] signals: check ->group_stop_count after tracehook_get_signal() + +Move the call to do_signal_stop() down, after tracehook call. +This makes ->group_stop_count condition visible to tracers before +do_signal_stop() will participate in this group-stop. + +Currently the patch has no effect, tracehook_get_signal() always +returns 0. + +Signed-off-by: Oleg Nesterov +Signed-off-by: Roland McGrath +--- + include/linux/ptrace.h | 1 + + include/linux/sched.h | 1 + + include/linux/tracehook.h | 10 +++++----- + kernel/ptrace.c | 2 +- + kernel/signal.c | 4 ++-- + 5 files changed, 10 insertions(+), 8 deletions(-) + +diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h +index 56f2d63..4802e2a 100644 +--- a/include/linux/ptrace.h ++++ b/include/linux/ptrace.h +@@ -85,6 +85,7 @@ extern int ptrace_traceme(void); + extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len); + extern int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len); + extern int ptrace_attach(struct task_struct *tsk); ++extern bool __ptrace_detach(struct task_struct *tracer, struct task_struct *tracee); + extern int ptrace_detach(struct task_struct *, unsigned int); + extern void ptrace_disable(struct task_struct *); + extern int ptrace_check_attach(struct task_struct *task, int kill); +diff --git a/include/linux/sched.h b/include/linux/sched.h +index 78efe7c..9a2b557 100644 +--- a/include/linux/sched.h ++++ b/include/linux/sched.h +@@ -2095,6 +2095,7 @@ extern int kill_pgrp(struct pid *pid, in + extern int kill_pid(struct pid *pid, int sig, int priv); + extern int kill_proc_info(int, struct siginfo *, pid_t); + extern int do_notify_parent(struct task_struct *, int); ++extern void do_notify_parent_cldstop(struct task_struct *, int); + extern void __wake_up_parent(struct task_struct *p, struct task_struct *parent); + extern void force_sig(int, struct task_struct *); + extern int send_sig(int, struct task_struct *, int); +diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h +index 10db010..c78b2f4 100644 +--- a/include/linux/tracehook.h ++++ b/include/linux/tracehook.h +@@ -134,7 +134,7 @@ static inline __must_check int tracehook + */ + static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step) + { +- if (step) { ++ if (step && (task_ptrace(current) & PT_PTRACED)) { + siginfo_t info; + user_single_step_siginfo(current, regs, &info); + force_sig_info(SIGTRAP, &info, current); +@@ -156,7 +156,7 @@ static inline int tracehook_unsafe_exec( + { + int unsafe = 0; + int ptrace = task_ptrace(task); +- if (ptrace & PT_PTRACED) { ++ if (ptrace) { + if (ptrace & PT_PTRACE_CAP) + unsafe |= LSM_UNSAFE_PTRACE_CAP; + else +@@ -178,7 +178,7 @@ static inline int tracehook_unsafe_exec( + */ + static inline struct task_struct *tracehook_tracer_task(struct task_struct *tsk) + { +- if (task_ptrace(tsk) & PT_PTRACED) ++ if (task_ptrace(tsk)) + return rcu_dereference(tsk->parent); + return NULL; + } +@@ -386,7 +386,7 @@ static inline void tracehook_signal_hand + const struct k_sigaction *ka, + struct pt_regs *regs, int stepping) + { +- if (stepping) ++ if (stepping && (task_ptrace(current) & PT_PTRACED)) + ptrace_notify(SIGTRAP); + } + +@@ -492,7 +492,7 @@ static inline int tracehook_get_signal(s + */ + static inline int tracehook_notify_jctl(int notify, int why) + { +- return notify ?: (current->ptrace & PT_PTRACED) ? why : 0; ++ return notify ?: task_ptrace(current) ? why : 0; + } + + /** +diff --git a/kernel/ptrace.c b/kernel/ptrace.c +index 23bd09c..b7c1d32 100644 +--- a/kernel/ptrace.c ++++ b/kernel/ptrace.c +@@ -271,7 +271,7 @@ static int ignoring_children(struct sigh + * reap it now, in that case we must also wake up sub-threads sleeping in + * do_wait(). + */ +-static bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p) ++bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p) + { + __ptrace_unlink(p); + +diff --git a/kernel/signal.c b/kernel/signal.c +index 934ae5e..9551cec 100644 +--- a/kernel/signal.c ++++ b/kernel/signal.c +@@ -1498,7 +1498,7 @@ int do_notify_parent(struct task_struct + return ret; + } + +-static void do_notify_parent_cldstop(struct task_struct *tsk, int why) ++void do_notify_parent_cldstop(struct task_struct *tsk, int why) + { + struct siginfo info; + unsigned long flags; +@@ -1768,7 +1768,7 @@ static int do_signal_stop(int signr) + static int ptrace_signal(int signr, siginfo_t *info, + struct pt_regs *regs, void *cookie) + { +- if (!task_ptrace(current)) ++ if (!(task_ptrace(current) & PT_PTRACED)) + return signr; + + ptrace_signal_deliver(regs, cookie); diff --git a/linux-2.6-umh-refactor.patch b/linux-2.6-umh-refactor.patch new file mode 100644 index 000000000..1980761a9 --- /dev/null +++ b/linux-2.6-umh-refactor.patch @@ -0,0 +1,404 @@ +diff -up linux-2.6.32.noarch/fs/exec.c.orig linux-2.6.32.noarch/fs/exec.c +--- linux-2.6.32.noarch/fs/exec.c.orig 2010-02-05 06:57:45.000000000 -0500 ++++ linux-2.6.32.noarch/fs/exec.c 2010-02-05 06:57:31.000000000 -0500 +@@ -1762,6 +1762,50 @@ static void wait_for_dump_helpers(struct + } + + ++/* ++ * uhm_pipe_setup ++ * helper function to customize the process used ++ * to collect the core in userspace. Specifically ++ * it sets up a pipe and installs it as fd 0 (stdin) ++ * for the process. Returns 0 on success, or ++ * PTR_ERR on failure. ++ * Note that it also sets the core limit to 1. This ++ * is a special value that we use to trap recursive ++ * core dumps ++ */ ++static int umh_pipe_setup(struct subprocess_info *info) ++{ ++ struct file *rp, *wp; ++ struct fdtable *fdt; ++ struct coredump_params *cp = (struct coredump_params *)info->data; ++ struct files_struct *cf = current->files; ++ ++ wp = create_write_pipe(0); ++ if (IS_ERR(wp)) ++ return PTR_ERR(wp); ++ ++ rp = create_read_pipe(wp, 0); ++ if (IS_ERR(rp)) { ++ free_write_pipe(wp); ++ return PTR_ERR(rp); ++ } ++ ++ cp->file = wp; ++ ++ sys_close(0); ++ fd_install(0, rp); ++ spin_lock(&cf->file_lock); ++ fdt = files_fdtable(cf); ++ FD_SET(0, fdt->open_fds); ++ FD_CLR(0, fdt->close_on_exec); ++ spin_unlock(&cf->file_lock); ++ ++ /* and disallow core files too */ ++ current->signal->rlim[RLIMIT_CORE] = (struct rlimit){1, 1}; ++ ++ return 0; ++} ++ + void do_coredump(long signr, int exit_code, struct pt_regs *regs) + { + struct core_state core_state; +@@ -1842,15 +1886,15 @@ void do_coredump(long signr, int exit_co + goto fail_unlock; + + if (ispipe) { +- if (cprm.limit == 0) { ++ if (cprm.limit == 1) { + /* + * Normally core limits are irrelevant to pipes, since + * we're not writing to the file system, but we use +- * cprm.limit of 0 here as a speacial value. Any +- * non-zero limit gets set to RLIM_INFINITY below, but ++ * cprm.limit of 1 here as a speacial value. Any ++ * non-1 limit gets set to RLIM_INFINITY below, but + * a limit of 0 skips the dump. This is a consistent + * way to catch recursive crashes. We can still crash +- * if the core_pattern binary sets RLIM_CORE = !0 ++ * if the core_pattern binary sets RLIM_CORE = !1 + * but it runs as root, and can do lots of stupid things + * Note that we use task_tgid_vnr here to grab the pid + * of the process group leader. That way we get the +@@ -1858,7 +1902,7 @@ void do_coredump(long signr, int exit_co + * core_pattern process dies. + */ + printk(KERN_WARNING +- "Process %d(%s) has RLIMIT_CORE set to 0\n", ++ "Process %d(%s) has RLIMIT_CORE set to 1\n", + task_tgid_vnr(current), current->comm); + printk(KERN_WARNING "Aborting core\n"); + goto fail_unlock; +@@ -1882,8 +1926,13 @@ void do_coredump(long signr, int exit_co + cprm.limit = RLIM_INFINITY; + + /* SIGPIPE can happen, but it's just never processed */ +- if (call_usermodehelper_pipe(helper_argv[0], helper_argv, NULL, +- &cprm.file)) { ++ cprm.file = NULL; ++ if (call_usermodehelper_fns(helper_argv[0], helper_argv, NULL, ++ UMH_WAIT_EXEC, umh_pipe_setup, ++ NULL, &cprm)) { ++ if (cprm.file) ++ filp_close(cprm.file, NULL); ++ + printk(KERN_INFO "Core dump to %s pipe failed\n", + corename); + goto fail_dropcount; +diff -up linux-2.6.32.noarch/include/linux/kmod.h.orig linux-2.6.32.noarch/include/linux/kmod.h +--- linux-2.6.32.noarch/include/linux/kmod.h.orig 2010-02-05 06:57:45.000000000 -0500 ++++ linux-2.6.32.noarch/include/linux/kmod.h 2010-02-05 06:57:31.000000000 -0500 +@@ -23,6 +23,7 @@ + #include + #include + #include ++#include + + #define KMOD_PATH_LEN 256 + +@@ -44,7 +45,26 @@ static inline int request_module_nowait( + + struct key; + struct file; +-struct subprocess_info; ++ ++enum umh_wait { ++ UMH_NO_WAIT = -1, /* don't wait at all */ ++ UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */ ++ UMH_WAIT_PROC = 1, /* wait for the process to complete */ ++}; ++ ++struct subprocess_info { ++ struct work_struct work; ++ struct completion *complete; ++ struct cred *cred; ++ char *path; ++ char **argv; ++ char **envp; ++ enum umh_wait wait; ++ int retval; ++ int (*init)(struct subprocess_info *info); ++ void (*cleanup)(struct subprocess_info *info); ++ void *data; ++}; + + /* Allocate a subprocess_info structure */ + struct subprocess_info *call_usermodehelper_setup(char *path, char **argv, +@@ -55,14 +75,10 @@ void call_usermodehelper_setkeys(struct + struct key *session_keyring); + int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info, + struct file **filp); +-void call_usermodehelper_setcleanup(struct subprocess_info *info, +- void (*cleanup)(char **argv, char **envp)); +- +-enum umh_wait { +- UMH_NO_WAIT = -1, /* don't wait at all */ +- UMH_WAIT_EXEC = 0, /* wait for the exec, but not the process */ +- UMH_WAIT_PROC = 1, /* wait for the process to complete */ +-}; ++void call_usermodehelper_setfns(struct subprocess_info *info, ++ int (*init)(struct subprocess_info *info), ++ void (*cleanup)(struct subprocess_info *info), ++ void *data); + + /* Actually execute the sub-process */ + int call_usermodehelper_exec(struct subprocess_info *info, enum umh_wait wait); +@@ -72,7 +88,10 @@ int call_usermodehelper_exec(struct subp + void call_usermodehelper_freeinfo(struct subprocess_info *info); + + static inline int +-call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait) ++call_usermodehelper_fns(char *path, char **argv, char **envp, ++ enum umh_wait wait, ++ int (*init)(struct subprocess_info *info), ++ void (*cleanup)(struct subprocess_info *), void *data) + { + struct subprocess_info *info; + gfp_t gfp_mask = (wait == UMH_NO_WAIT) ? GFP_ATOMIC : GFP_KERNEL; +@@ -80,10 +99,18 @@ call_usermodehelper(char *path, char **a + info = call_usermodehelper_setup(path, argv, envp, gfp_mask); + if (info == NULL) + return -ENOMEM; ++ call_usermodehelper_setfns(info, init, cleanup, data); + return call_usermodehelper_exec(info, wait); + } + + static inline int ++call_usermodehelper(char *path, char **argv, char **envp, enum umh_wait wait) ++{ ++ return call_usermodehelper_fns(path, argv, envp, ++ wait, NULL, NULL, NULL); ++} ++ ++static inline int + call_usermodehelper_keys(char *path, char **argv, char **envp, + struct key *session_keyring, enum umh_wait wait) + { +@@ -100,10 +127,6 @@ call_usermodehelper_keys(char *path, cha + + extern void usermodehelper_init(void); + +-struct file; +-extern int call_usermodehelper_pipe(char *path, char *argv[], char *envp[], +- struct file **filp); +- + extern int usermodehelper_disable(void); + extern void usermodehelper_enable(void); + +diff -up linux-2.6.32.noarch/kernel/kmod.c.orig linux-2.6.32.noarch/kernel/kmod.c +--- linux-2.6.32.noarch/kernel/kmod.c.orig 2010-02-05 06:57:45.000000000 -0500 ++++ linux-2.6.32.noarch/kernel/kmod.c 2010-02-05 06:57:31.000000000 -0500 +@@ -124,19 +124,6 @@ int __request_module(bool wait, const ch + EXPORT_SYMBOL(__request_module); + #endif /* CONFIG_MODULES */ + +-struct subprocess_info { +- struct work_struct work; +- struct completion *complete; +- struct cred *cred; +- char *path; +- char **argv; +- char **envp; +- enum umh_wait wait; +- int retval; +- struct file *stdin; +- void (*cleanup)(char **argv, char **envp); +-}; +- + /* + * This is the task which runs the usermode application + */ +@@ -158,26 +145,15 @@ static int ____call_usermodehelper(void + commit_creds(sub_info->cred); + sub_info->cred = NULL; + +- /* Install input pipe when needed */ +- if (sub_info->stdin) { +- struct files_struct *f = current->files; +- struct fdtable *fdt; +- /* no races because files should be private here */ +- sys_close(0); +- fd_install(0, sub_info->stdin); +- spin_lock(&f->file_lock); +- fdt = files_fdtable(f); +- FD_SET(0, fdt->open_fds); +- FD_CLR(0, fdt->close_on_exec); +- spin_unlock(&f->file_lock); +- +- /* and disallow core files too */ +- current->signal->rlim[RLIMIT_CORE] = (struct rlimit){0, 0}; +- } +- + /* We can run anywhere, unlike our parent keventd(). */ + set_cpus_allowed_ptr(current, cpu_all_mask); + ++ if (sub_info->init) { ++ retval = sub_info->init(sub_info); ++ if (retval) ++ goto fail; ++ } ++ + /* + * Our parent is keventd, which runs with elevated scheduling priority. + * Avoid propagating that into the userspace child. +@@ -187,6 +163,7 @@ static int ____call_usermodehelper(void + retval = kernel_execve(sub_info->path, sub_info->argv, sub_info->envp); + + /* Exec failed? */ ++fail: + sub_info->retval = retval; + do_exit(0); + } +@@ -194,7 +171,7 @@ static int ____call_usermodehelper(void + void call_usermodehelper_freeinfo(struct subprocess_info *info) + { + if (info->cleanup) +- (*info->cleanup)(info->argv, info->envp); ++ (*info->cleanup)(info); + if (info->cred) + put_cred(info->cred); + kfree(info); +@@ -406,50 +383,31 @@ void call_usermodehelper_setkeys(struct + EXPORT_SYMBOL(call_usermodehelper_setkeys); + + /** +- * call_usermodehelper_setcleanup - set a cleanup function ++ * call_usermodehelper_setfns - set a cleanup/init function + * @info: a subprocess_info returned by call_usermodehelper_setup + * @cleanup: a cleanup function ++ * @init: an init function ++ * @data: arbitrary context sensitive data + * +- * The cleanup function is just befor ethe subprocess_info is about to ++ * The init function is used to customize the helper process prior to ++ * exec. A non-zero return code causes the process to error out, exit, ++ * and return the failure to the calling process ++ * ++ * The cleanup function is just before ethe subprocess_info is about to + * be freed. This can be used for freeing the argv and envp. The + * Function must be runnable in either a process context or the + * context in which call_usermodehelper_exec is called. + */ +-void call_usermodehelper_setcleanup(struct subprocess_info *info, +- void (*cleanup)(char **argv, char **envp)) ++void call_usermodehelper_setfns(struct subprocess_info *info, ++ int (*init)(struct subprocess_info *info), ++ void (*cleanup)(struct subprocess_info *info), ++ void *data) + { + info->cleanup = cleanup; ++ info->init = init; ++ info->data = data; + } +-EXPORT_SYMBOL(call_usermodehelper_setcleanup); +- +-/** +- * call_usermodehelper_stdinpipe - set up a pipe to be used for stdin +- * @sub_info: a subprocess_info returned by call_usermodehelper_setup +- * @filp: set to the write-end of a pipe +- * +- * This constructs a pipe, and sets the read end to be the stdin of the +- * subprocess, and returns the write-end in *@filp. +- */ +-int call_usermodehelper_stdinpipe(struct subprocess_info *sub_info, +- struct file **filp) +-{ +- struct file *f; +- +- f = create_write_pipe(0); +- if (IS_ERR(f)) +- return PTR_ERR(f); +- *filp = f; +- +- f = create_read_pipe(f, 0); +- if (IS_ERR(f)) { +- free_write_pipe(*filp); +- return PTR_ERR(f); +- } +- sub_info->stdin = f; +- +- return 0; +-} +-EXPORT_SYMBOL(call_usermodehelper_stdinpipe); ++EXPORT_SYMBOL(call_usermodehelper_setfns); + + /** + * call_usermodehelper_exec - start a usermode application +@@ -498,41 +456,6 @@ unlock: + } + EXPORT_SYMBOL(call_usermodehelper_exec); + +-/** +- * call_usermodehelper_pipe - call a usermode helper process with a pipe stdin +- * @path: path to usermode executable +- * @argv: arg vector for process +- * @envp: environment for process +- * @filp: set to the write-end of a pipe +- * +- * This is a simple wrapper which executes a usermode-helper function +- * with a pipe as stdin. It is implemented entirely in terms of +- * lower-level call_usermodehelper_* functions. +- */ +-int call_usermodehelper_pipe(char *path, char **argv, char **envp, +- struct file **filp) +-{ +- struct subprocess_info *sub_info; +- int ret; +- +- sub_info = call_usermodehelper_setup(path, argv, envp, GFP_KERNEL); +- if (sub_info == NULL) +- return -ENOMEM; +- +- ret = call_usermodehelper_stdinpipe(sub_info, filp); +- if (ret < 0) { +- call_usermodehelper_freeinfo(sub_info); +- return ret; +- } +- +- ret = call_usermodehelper_exec(sub_info, UMH_WAIT_EXEC); +- if (ret < 0) /* Failed to execute helper, close pipe */ +- filp_close(*filp, NULL); +- +- return ret; +-} +-EXPORT_SYMBOL(call_usermodehelper_pipe); +- + void __init usermodehelper_init(void) + { + khelper_wq = create_singlethread_workqueue("khelper"); +diff -up linux-2.6.32.noarch/kernel/sys.c.orig linux-2.6.32.noarch/kernel/sys.c +--- linux-2.6.32.noarch/kernel/sys.c.orig 2010-02-05 06:57:45.000000000 -0500 ++++ linux-2.6.32.noarch/kernel/sys.c 2010-02-05 06:48:30.000000000 -0500 +@@ -1599,9 +1599,9 @@ SYSCALL_DEFINE3(getcpu, unsigned __user + + char poweroff_cmd[POWEROFF_CMD_PATH_LEN] = "/sbin/poweroff"; + +-static void argv_cleanup(char **argv, char **envp) ++static void argv_cleanup(struct subprocess_info *info) + { +- argv_free(argv); ++ argv_free(info->argv); + } + + /** +@@ -1635,7 +1635,7 @@ int orderly_poweroff(bool force) + goto out; + } + +- call_usermodehelper_setcleanup(info, argv_cleanup); ++ call_usermodehelper_setfns(info, NULL, argv_cleanup, NULL); + + ret = call_usermodehelper_exec(info, UMH_NO_WAIT); + diff --git a/linux-2.6-upstream-reverts.patch b/linux-2.6-upstream-reverts.patch new file mode 100644 index 000000000..197189a05 --- /dev/null +++ b/linux-2.6-upstream-reverts.patch @@ -0,0 +1,1665 @@ +From 5ce8ba7c9279a63f99e1f131602580472b8af968 Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Thu, 15 Apr 2010 14:03:30 -0400 +Subject: drm/i915: Fix 82854 PCI ID, and treat it like other 85X + +From: Adam Jackson + +commit 5ce8ba7c9279a63f99e1f131602580472b8af968 upstream. + +pci.ids and the datasheet both say it's 358e, not 35e8. + +Signed-off-by: Adam Jackson +Signed-off-by: Eric Anholt +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_drv.c | 5 +++-- + drivers/gpu/drm/i915/i915_drv.h | 3 ++- + 2 files changed, 5 insertions(+), 3 deletions(-) + +--- a/drivers/gpu/drm/i915/i915_drv.c ++++ b/drivers/gpu/drm/i915/i915_drv.c +@@ -68,7 +68,8 @@ const static struct intel_device_info in + }; + + const static struct intel_device_info intel_i85x_info = { +- .is_i8xx = 1, .is_mobile = 1, .cursor_needs_physical = 1, ++ .is_i8xx = 1, .is_i85x = 1, .is_mobile = 1, ++ .cursor_needs_physical = 1, + }; + + const static struct intel_device_info intel_i865g_info = { +@@ -140,7 +141,7 @@ const static struct pci_device_id pciidl + INTEL_VGA_DEVICE(0x3577, &intel_i830_info), + INTEL_VGA_DEVICE(0x2562, &intel_845g_info), + INTEL_VGA_DEVICE(0x3582, &intel_i85x_info), +- INTEL_VGA_DEVICE(0x35e8, &intel_i85x_info), ++ INTEL_VGA_DEVICE(0x358e, &intel_i85x_info), + INTEL_VGA_DEVICE(0x2572, &intel_i865g_info), + INTEL_VGA_DEVICE(0x2582, &intel_i915g_info), + INTEL_VGA_DEVICE(0x258a, &intel_i915g_info), +--- a/drivers/gpu/drm/i915/i915_drv.h ++++ b/drivers/gpu/drm/i915/i915_drv.h +@@ -175,6 +175,7 @@ struct intel_overlay; + struct intel_device_info { + u8 is_mobile : 1; + u8 is_i8xx : 1; ++ u8 is_i85x : 1; + u8 is_i915g : 1; + u8 is_i9xx : 1; + u8 is_i945gm : 1; +@@ -1027,7 +1028,7 @@ extern int i915_wait_ring(struct drm_dev + + #define IS_I830(dev) ((dev)->pci_device == 0x3577) + #define IS_845G(dev) ((dev)->pci_device == 0x2562) +-#define IS_I85X(dev) ((dev)->pci_device == 0x3582) ++#define IS_I85X(dev) (INTEL_INFO(dev)->is_i85x) + #define IS_I865G(dev) ((dev)->pci_device == 0x2572) + #define IS_GEN2(dev) (INTEL_INFO(dev)->is_i8xx) + #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g) +From 61dd98fad58f945ed720ba132681acb58fcee015 Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Thu, 13 May 2010 14:55:28 -0400 +Subject: drm/edid: Fix 1024x768@85Hz + +From: Adam Jackson + +commit 61dd98fad58f945ed720ba132681acb58fcee015 upstream. + +Having hsync both start and end on pixel 1072 ain't gonna work very +well. Matches the X server's list. + +Signed-off-by: Adam Jackson +Tested-By: Michael Tokarev +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/drm_edid.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/gpu/drm/drm_edid.c ++++ b/drivers/gpu/drm/drm_edid.c +@@ -334,7 +334,7 @@ static struct drm_display_mode drm_dmt_m + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, + /* 1024x768@85Hz */ + { DRM_MODE("1024x768", DRM_MODE_TYPE_DRIVER, 94500, 1024, 1072, +- 1072, 1376, 0, 768, 769, 772, 808, 0, ++ 1168, 1376, 0, 768, 769, 772, 808, 0, + DRM_MODE_FLAG_PHSYNC | DRM_MODE_FLAG_PVSYNC) }, + /* 1152x864@75Hz */ + { DRM_MODE("1152x864", DRM_MODE_TYPE_DRIVER, 108000, 1152, 1216, +From 8d06a1e1e9c69244f08beb7d17146483f9dcd120 Mon Sep 17 00:00:00 2001 +From: Robert Hooker +Date: Fri, 19 Mar 2010 15:13:27 -0400 +Subject: drm/i915: Disable FBC on 915GM and 945GM. + +From: Robert Hooker + +commit 8d06a1e1e9c69244f08beb7d17146483f9dcd120 upstream. + +It is causing hangs after a suspend/resume cycle with the default +powersave=1 module option on these chipsets since 2.6.32-rc. + +BugLink: http://bugs.launchpad.net/bugs/492392 +Signed-off-by: Robert Hooker +Acked-by: Jesse Barnes +Signed-off-by: Eric Anholt +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_drv.c | 4 ++-- + drivers/gpu/drm/i915/intel_display.c | 2 +- + 2 files changed, 3 insertions(+), 3 deletions(-) + +--- a/drivers/gpu/drm/i915/i915_drv.c ++++ b/drivers/gpu/drm/i915/i915_drv.c +@@ -79,14 +79,14 @@ const static struct intel_device_info in + .is_i915g = 1, .is_i9xx = 1, .cursor_needs_physical = 1, + }; + const static struct intel_device_info intel_i915gm_info = { +- .is_i9xx = 1, .is_mobile = 1, .has_fbc = 1, ++ .is_i9xx = 1, .is_mobile = 1, + .cursor_needs_physical = 1, + }; + const static struct intel_device_info intel_i945g_info = { + .is_i9xx = 1, .has_hotplug = 1, .cursor_needs_physical = 1, + }; + const static struct intel_device_info intel_i945gm_info = { +- .is_i945gm = 1, .is_i9xx = 1, .is_mobile = 1, .has_fbc = 1, ++ .is_i945gm = 1, .is_i9xx = 1, .is_mobile = 1, + .has_hotplug = 1, .cursor_needs_physical = 1, + }; + +--- a/drivers/gpu/drm/i915/intel_display.c ++++ b/drivers/gpu/drm/i915/intel_display.c +@@ -4683,7 +4683,7 @@ static void intel_init_display(struct dr + dev_priv->display.fbc_enabled = g4x_fbc_enabled; + dev_priv->display.enable_fbc = g4x_enable_fbc; + dev_priv->display.disable_fbc = g4x_disable_fbc; +- } else if (IS_I965GM(dev) || IS_I945GM(dev) || IS_I915GM(dev)) { ++ } else if (IS_I965GM(dev)) { + dev_priv->display.fbc_enabled = i8xx_fbc_enabled; + dev_priv->display.enable_fbc = i8xx_enable_fbc; + dev_priv->display.disable_fbc = i8xx_disable_fbc; +From 1918ad77f7f908ed67cf37c505c6ad4ac52f1ecf Mon Sep 17 00:00:00 2001 +From: Jesse Barnes +Date: Fri, 23 Apr 2010 09:32:23 -0700 +Subject: drm/i915: fix non-Ironlake 965 class crashes +MIME-Version: 1.0 +Content-Type: text/plain; charset=UTF-8 +Content-Transfer-Encoding: 8bit + +From: Jesse Barnes + +commit 1918ad77f7f908ed67cf37c505c6ad4ac52f1ecf upstream. + +My PIPE_CONTROL fix (just sent via Eric's tree) was buggy; I was +testing a whole set of patches together and missed a conversion to the +new HAS_PIPE_CONTROL macro, which will cause breakage on non-Ironlake +965 class chips. Fortunately, the fix is trivial and has been tested. + +Be sure to use the HAS_PIPE_CONTROL macro in i915_get_gem_seqno, or +we'll end up reading the wrong graphics memory, likely causing hangs, +crashes, or worse. + +Reported-by: Zdenek Kabelac +Reported-by: Toralf Förster +Tested-by: Toralf Förster +Signed-off-by: Jesse Barnes +Signed-off-by: Linus Torvalds +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_gem.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -1785,7 +1785,7 @@ i915_get_gem_seqno(struct drm_device *de + { + drm_i915_private_t *dev_priv = dev->dev_private; + +- if (IS_I965G(dev)) ++ if (HAS_PIPE_CONTROL(dev)) + return ((volatile u32 *)(dev_priv->seqno_page))[0]; + else + return READ_HWSP(dev_priv, I915_GEM_HWS_INDEX); +From e552eb7038a36d9b18860f525aa02875e313fe16 Mon Sep 17 00:00:00 2001 +From: Jesse Barnes +Date: Wed, 21 Apr 2010 11:39:23 -0700 +Subject: drm/i915: use PIPE_CONTROL instruction on Ironlake and Sandy Bridge + +From: Jesse Barnes + +commit e552eb7038a36d9b18860f525aa02875e313fe16 upstream. + +Since 965, the hardware has supported the PIPE_CONTROL command, which +provides fine grained GPU cache flushing control. On recent chipsets, +this instruction is required for reliable interrupt and sequence number +reporting in the driver. + +So add support for this instruction, including workarounds, on Ironlake +and Sandy Bridge hardware. + +https://bugs.freedesktop.org/show_bug.cgi?id=27108 + +Signed-off-by: Jesse Barnes +Tested-by: Chris Wilson +Signed-off-by: Eric Anholt +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_drv.h | 4 + + drivers/gpu/drm/i915/i915_gem.c | 145 ++++++++++++++++++++++++++++++++++++---- + drivers/gpu/drm/i915/i915_irq.c | 8 +- + drivers/gpu/drm/i915/i915_reg.h | 11 +++ + 4 files changed, 152 insertions(+), 16 deletions(-) + +--- a/drivers/gpu/drm/i915/i915_drv.h ++++ b/drivers/gpu/drm/i915/i915_drv.h +@@ -206,11 +206,14 @@ typedef struct drm_i915_private { + + drm_dma_handle_t *status_page_dmah; + void *hw_status_page; ++ void *seqno_page; + dma_addr_t dma_status_page; + uint32_t counter; + unsigned int status_gfx_addr; ++ unsigned int seqno_gfx_addr; + drm_local_map_t hws_map; + struct drm_gem_object *hws_obj; ++ struct drm_gem_object *seqno_obj; + struct drm_gem_object *pwrctx; + + struct resource mch_res; +@@ -1090,6 +1093,7 @@ extern int i915_wait_ring(struct drm_dev + + #define HAS_PCH_SPLIT(dev) (IS_IRONLAKE(dev) || \ + IS_GEN6(dev)) ++#define HAS_PIPE_CONTROL(dev) (IS_IRONLAKE(dev) || IS_GEN6(dev)) + + #define PRIMARY_RINGBUFFER_SIZE (128*1024) + +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -1559,6 +1559,13 @@ i915_gem_object_move_to_inactive(struct + i915_verify_inactive(dev, __FILE__, __LINE__); + } + ++#define PIPE_CONTROL_FLUSH(addr) \ ++ OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | \ ++ PIPE_CONTROL_DEPTH_STALL); \ ++ OUT_RING(addr | PIPE_CONTROL_GLOBAL_GTT); \ ++ OUT_RING(0); \ ++ OUT_RING(0); \ ++ + /** + * Creates a new sequence number, emitting a write of it to the status page + * plus an interrupt, which will trigger i915_user_interrupt_handler. +@@ -1593,13 +1600,47 @@ i915_add_request(struct drm_device *dev, + if (dev_priv->mm.next_gem_seqno == 0) + dev_priv->mm.next_gem_seqno++; + +- BEGIN_LP_RING(4); +- OUT_RING(MI_STORE_DWORD_INDEX); +- OUT_RING(I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); +- OUT_RING(seqno); ++ if (HAS_PIPE_CONTROL(dev)) { ++ u32 scratch_addr = dev_priv->seqno_gfx_addr + 128; + +- OUT_RING(MI_USER_INTERRUPT); +- ADVANCE_LP_RING(); ++ /* ++ * Workaround qword write incoherence by flushing the ++ * PIPE_NOTIFY buffers out to memory before requesting ++ * an interrupt. ++ */ ++ BEGIN_LP_RING(32); ++ OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | ++ PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH); ++ OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT); ++ OUT_RING(seqno); ++ OUT_RING(0); ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; /* write to separate cachelines */ ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ scratch_addr += 128; ++ PIPE_CONTROL_FLUSH(scratch_addr); ++ OUT_RING(GFX_OP_PIPE_CONTROL | PIPE_CONTROL_QW_WRITE | ++ PIPE_CONTROL_WC_FLUSH | PIPE_CONTROL_TC_FLUSH | ++ PIPE_CONTROL_NOTIFY); ++ OUT_RING(dev_priv->seqno_gfx_addr | PIPE_CONTROL_GLOBAL_GTT); ++ OUT_RING(seqno); ++ OUT_RING(0); ++ ADVANCE_LP_RING(); ++ } else { ++ BEGIN_LP_RING(4); ++ OUT_RING(MI_STORE_DWORD_INDEX); ++ OUT_RING(I915_GEM_HWS_INDEX << MI_STORE_DWORD_INDEX_SHIFT); ++ OUT_RING(seqno); ++ ++ OUT_RING(MI_USER_INTERRUPT); ++ ADVANCE_LP_RING(); ++ } + + DRM_DEBUG_DRIVER("%d\n", seqno); + +@@ -1744,7 +1785,10 @@ i915_get_gem_seqno(struct drm_device *de + { + drm_i915_private_t *dev_priv = dev->dev_private; + +- return READ_HWSP(dev_priv, I915_GEM_HWS_INDEX); ++ if (IS_I965G(dev)) ++ return ((volatile u32 *)(dev_priv->seqno_page))[0]; ++ else ++ return READ_HWSP(dev_priv, I915_GEM_HWS_INDEX); + } + + /** +@@ -4576,6 +4620,49 @@ i915_gem_idle(struct drm_device *dev) + return 0; + } + ++/* ++ * 965+ support PIPE_CONTROL commands, which provide finer grained control ++ * over cache flushing. ++ */ ++static int ++i915_gem_init_pipe_control(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_gem_object *obj; ++ struct drm_i915_gem_object *obj_priv; ++ int ret; ++ ++ obj = drm_gem_object_alloc(dev, 4096); ++ if (obj == NULL) { ++ DRM_ERROR("Failed to allocate seqno page\n"); ++ ret = -ENOMEM; ++ goto err; ++ } ++ obj_priv = obj->driver_private; ++ obj_priv->agp_type = AGP_USER_CACHED_MEMORY; ++ ++ ret = i915_gem_object_pin(obj, 4096); ++ if (ret) ++ goto err_unref; ++ ++ dev_priv->seqno_gfx_addr = obj_priv->gtt_offset; ++ dev_priv->seqno_page = kmap(obj_priv->pages[0]); ++ if (dev_priv->seqno_page == NULL) ++ goto err_unpin; ++ ++ dev_priv->seqno_obj = obj; ++ memset(dev_priv->seqno_page, 0, PAGE_SIZE); ++ ++ return 0; ++ ++err_unpin: ++ i915_gem_object_unpin(obj); ++err_unref: ++ drm_gem_object_unreference(obj); ++err: ++ return ret; ++} ++ + static int + i915_gem_init_hws(struct drm_device *dev) + { +@@ -4593,7 +4680,8 @@ i915_gem_init_hws(struct drm_device *dev + obj = drm_gem_object_alloc(dev, 4096); + if (obj == NULL) { + DRM_ERROR("Failed to allocate status page\n"); +- return -ENOMEM; ++ ret = -ENOMEM; ++ goto err; + } + obj_priv = obj->driver_private; + obj_priv->agp_type = AGP_USER_CACHED_MEMORY; +@@ -4601,7 +4689,7 @@ i915_gem_init_hws(struct drm_device *dev + ret = i915_gem_object_pin(obj, 4096); + if (ret != 0) { + drm_gem_object_unreference(obj); +- return ret; ++ goto err_unref; + } + + dev_priv->status_gfx_addr = obj_priv->gtt_offset; +@@ -4610,10 +4698,16 @@ i915_gem_init_hws(struct drm_device *dev + if (dev_priv->hw_status_page == NULL) { + DRM_ERROR("Failed to map status page.\n"); + memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); +- i915_gem_object_unpin(obj); +- drm_gem_object_unreference(obj); +- return -EINVAL; ++ ret = -EINVAL; ++ goto err_unpin; + } ++ ++ if (HAS_PIPE_CONTROL(dev)) { ++ ret = i915_gem_init_pipe_control(dev); ++ if (ret) ++ goto err_unpin; ++ } ++ + dev_priv->hws_obj = obj; + memset(dev_priv->hw_status_page, 0, PAGE_SIZE); + I915_WRITE(HWS_PGA, dev_priv->status_gfx_addr); +@@ -4621,6 +4715,30 @@ i915_gem_init_hws(struct drm_device *dev + DRM_DEBUG_DRIVER("hws offset: 0x%08x\n", dev_priv->status_gfx_addr); + + return 0; ++ ++err_unpin: ++ i915_gem_object_unpin(obj); ++err_unref: ++ drm_gem_object_unreference(obj); ++err: ++ return 0; ++} ++ ++static void ++i915_gem_cleanup_pipe_control(struct drm_device *dev) ++{ ++ drm_i915_private_t *dev_priv = dev->dev_private; ++ struct drm_gem_object *obj; ++ struct drm_i915_gem_object *obj_priv; ++ ++ obj = dev_priv->seqno_obj; ++ obj_priv = obj->driver_private; ++ kunmap(obj_priv->pages[0]); ++ i915_gem_object_unpin(obj); ++ drm_gem_object_unreference(obj); ++ dev_priv->seqno_obj = NULL; ++ ++ dev_priv->seqno_page = NULL; + } + + static void +@@ -4644,6 +4762,9 @@ i915_gem_cleanup_hws(struct drm_device * + memset(&dev_priv->hws_map, 0, sizeof(dev_priv->hws_map)); + dev_priv->hw_status_page = NULL; + ++ if (HAS_PIPE_CONTROL(dev)) ++ i915_gem_cleanup_pipe_control(dev); ++ + /* Write high address into HWS_PGA when disabling. */ + I915_WRITE(HWS_PGA, 0x1ffff000); + } +--- a/drivers/gpu/drm/i915/i915_irq.c ++++ b/drivers/gpu/drm/i915/i915_irq.c +@@ -297,7 +297,7 @@ irqreturn_t ironlake_irq_handler(struct + READ_BREADCRUMB(dev_priv); + } + +- if (gt_iir & GT_USER_INTERRUPT) { ++ if (gt_iir & GT_PIPE_NOTIFY) { + u32 seqno = i915_get_gem_seqno(dev); + dev_priv->mm.irq_gem_seqno = seqno; + trace_i915_gem_request_complete(dev, seqno); +@@ -738,7 +738,7 @@ void i915_user_irq_get(struct drm_device + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); + if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { + if (HAS_PCH_SPLIT(dev)) +- ironlake_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); ++ ironlake_enable_graphics_irq(dev_priv, GT_PIPE_NOTIFY); + else + i915_enable_irq(dev_priv, I915_USER_INTERRUPT); + } +@@ -754,7 +754,7 @@ void i915_user_irq_put(struct drm_device + BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); + if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { + if (HAS_PCH_SPLIT(dev)) +- ironlake_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); ++ ironlake_disable_graphics_irq(dev_priv, GT_PIPE_NOTIFY); + else + i915_disable_irq(dev_priv, I915_USER_INTERRUPT); + } +@@ -1034,7 +1034,7 @@ static int ironlake_irq_postinstall(stru + /* enable kind of interrupts always enabled */ + u32 display_mask = DE_MASTER_IRQ_CONTROL | DE_GSE | DE_PCH_EVENT | + DE_PLANEA_FLIP_DONE | DE_PLANEB_FLIP_DONE; +- u32 render_mask = GT_USER_INTERRUPT; ++ u32 render_mask = GT_PIPE_NOTIFY; + u32 hotplug_mask = SDE_CRT_HOTPLUG | SDE_PORTB_HOTPLUG | + SDE_PORTC_HOTPLUG | SDE_PORTD_HOTPLUG; + +--- a/drivers/gpu/drm/i915/i915_reg.h ++++ b/drivers/gpu/drm/i915/i915_reg.h +@@ -210,6 +210,16 @@ + #define ASYNC_FLIP (1<<22) + #define DISPLAY_PLANE_A (0<<20) + #define DISPLAY_PLANE_B (1<<20) ++#define GFX_OP_PIPE_CONTROL ((0x3<<29)|(0x3<<27)|(0x2<<24)|2) ++#define PIPE_CONTROL_QW_WRITE (1<<14) ++#define PIPE_CONTROL_DEPTH_STALL (1<<13) ++#define PIPE_CONTROL_WC_FLUSH (1<<12) ++#define PIPE_CONTROL_IS_FLUSH (1<<11) /* MBZ on Ironlake */ ++#define PIPE_CONTROL_TC_FLUSH (1<<10) /* GM45+ only */ ++#define PIPE_CONTROL_ISP_DIS (1<<9) ++#define PIPE_CONTROL_NOTIFY (1<<8) ++#define PIPE_CONTROL_GLOBAL_GTT (1<<2) /* in addr dword */ ++#define PIPE_CONTROL_STALL_EN (1<<1) /* in addr word, Ironlake+ only */ + + /* + * Fence registers +@@ -2111,6 +2121,7 @@ + #define DEIER 0x4400c + + /* GT interrupt */ ++#define GT_PIPE_NOTIFY (1 << 4) + #define GT_SYNC_STATUS (1 << 2) + #define GT_USER_INTERRUPT (1 << 0) + +From c36a2a6de59e4a141a68b7575de837d3b0bd96b3 Mon Sep 17 00:00:00 2001 +From: Daniel Vetter +Date: Sat, 17 Apr 2010 15:12:03 +0200 +Subject: drm/i915: fix tiling limits for i915 class hw v2 + +From: Daniel Vetter + +commit c36a2a6de59e4a141a68b7575de837d3b0bd96b3 upstream. + +Current code is definitely crap: Largest pitch allowed spills into +the TILING_Y bit of the fence registers ... :( + +I've rewritten the limits check under the assumption that 3rd gen hw +has a 3d pitch limit of 8kb (like 2nd gen). This is supported by an +otherwise totally misleading XXX comment. + +This bug mostly resulted in tiling-corrupted pixmaps because the kernel +allowed too wide buffers to be tiled. Bug brought to the light by the +xf86-video-intel 2.11 release because that unconditionally enabled +tiling for pixmaps, relying on the kernel to check things. Tiling for +the framebuffer was not affected because the ddx does some additional +checks there ensure the buffer is within hw-limits. + +v2: Instead of computing the value that would be written into the +hw fence registers and then checking the limits simply check whether +the stride is above the 8kb limit. To better document the hw, add +some WARN_ONs in i915_write_fence_reg like I've done for the i830 +case (using the right limits). + +Signed-off-by: Daniel Vetter +Bugzilla: https://bugs.freedesktop.org/show_bug.cgi?id=27449 +Tested-by: Alexander Lam +Signed-off-by: Eric Anholt +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_gem.c | 6 ++++++ + drivers/gpu/drm/i915/i915_gem_tiling.c | 22 +++++++++------------- + drivers/gpu/drm/i915/i915_reg.h | 2 +- + 3 files changed, 16 insertions(+), 14 deletions(-) + +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -2316,6 +2316,12 @@ static void i915_write_fence_reg(struct + pitch_val = obj_priv->stride / tile_width; + pitch_val = ffs(pitch_val) - 1; + ++ if (obj_priv->tiling_mode == I915_TILING_Y && ++ HAS_128_BYTE_Y_TILING(dev)) ++ WARN_ON(pitch_val > I830_FENCE_MAX_PITCH_VAL); ++ else ++ WARN_ON(pitch_val > I915_FENCE_MAX_PITCH_VAL); ++ + val = obj_priv->gtt_offset; + if (obj_priv->tiling_mode == I915_TILING_Y) + val |= 1 << I830_FENCE_TILING_Y_SHIFT; +--- a/drivers/gpu/drm/i915/i915_gem_tiling.c ++++ b/drivers/gpu/drm/i915/i915_gem_tiling.c +@@ -357,21 +357,17 @@ i915_tiling_ok(struct drm_device *dev, i + * reg, so dont bother to check the size */ + if (stride / 128 > I965_FENCE_MAX_PITCH_VAL) + return false; +- } else if (IS_I9XX(dev)) { +- uint32_t pitch_val = ffs(stride / tile_width) - 1; +- +- /* XXX: For Y tiling, FENCE_MAX_PITCH_VAL is actually 6 (8KB) +- * instead of 4 (2KB) on 945s. +- */ +- if (pitch_val > I915_FENCE_MAX_PITCH_VAL || +- size > (I830_FENCE_MAX_SIZE_VAL << 20)) ++ } else if (IS_GEN3(dev) || IS_GEN2(dev)) { ++ if (stride > 8192) + return false; +- } else { +- uint32_t pitch_val = ffs(stride / tile_width) - 1; + +- if (pitch_val > I830_FENCE_MAX_PITCH_VAL || +- size > (I830_FENCE_MAX_SIZE_VAL << 19)) +- return false; ++ if (IS_GEN3(dev)) { ++ if (size > I830_FENCE_MAX_SIZE_VAL << 20) ++ return false; ++ } else { ++ if (size > I830_FENCE_MAX_SIZE_VAL << 19) ++ return false; ++ } + } + + /* 965+ just needs multiples of tile width */ +--- a/drivers/gpu/drm/i915/i915_reg.h ++++ b/drivers/gpu/drm/i915/i915_reg.h +@@ -221,7 +221,7 @@ + #define I830_FENCE_SIZE_BITS(size) ((ffs((size) >> 19) - 1) << 8) + #define I830_FENCE_PITCH_SHIFT 4 + #define I830_FENCE_REG_VALID (1<<0) +-#define I915_FENCE_MAX_PITCH_VAL 0x10 ++#define I915_FENCE_MAX_PITCH_VAL 4 + #define I830_FENCE_MAX_PITCH_VAL 6 + #define I830_FENCE_MAX_SIZE_VAL (1<<8) + +From bad720ff3e8e47a04bd88d9bbc8317e7d7e049d3 Mon Sep 17 00:00:00 2001 +From: Eric Anholt +Date: Thu, 22 Oct 2009 16:11:14 -0700 +Subject: drm/i915: Add initial bits for VGA modesetting bringup on Sandybridge. + +From: Eric Anholt + +commit bad720ff3e8e47a04bd88d9bbc8317e7d7e049d3 upstream. + +[needed for stable as it's just a bunch of macros that other drm patches +need, it changes no code functionality besides adding support for a new +device type. - gregkh] + +Signed-off-by: Eric Anholt +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/i915/i915_debugfs.c | 2 - + drivers/gpu/drm/i915/i915_dma.c | 16 ++++++--- + drivers/gpu/drm/i915/i915_drv.h | 26 ++++++++++++++- + drivers/gpu/drm/i915/i915_gem.c | 2 - + drivers/gpu/drm/i915/i915_gem_tiling.c | 2 - + drivers/gpu/drm/i915/i915_irq.c | 18 +++++----- + drivers/gpu/drm/i915/intel_bios.c | 3 + + drivers/gpu/drm/i915/intel_crt.c | 14 ++++---- + drivers/gpu/drm/i915/intel_display.c | 56 ++++++++++++++++----------------- + drivers/gpu/drm/i915/intel_lvds.c | 2 - + drivers/gpu/drm/i915/intel_overlay.c | 2 - + include/drm/drm_pciids.h | 1 + 12 files changed, 88 insertions(+), 56 deletions(-) + +--- a/drivers/gpu/drm/i915/i915_debugfs.c ++++ b/drivers/gpu/drm/i915/i915_debugfs.c +@@ -162,7 +162,7 @@ static int i915_interrupt_info(struct se + struct drm_device *dev = node->minor->dev; + drm_i915_private_t *dev_priv = dev->dev_private; + +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + seq_printf(m, "Interrupt enable: %08x\n", + I915_READ(IER)); + seq_printf(m, "Interrupt identity: %08x\n", +--- a/drivers/gpu/drm/i915/i915_dma.c ++++ b/drivers/gpu/drm/i915/i915_dma.c +@@ -978,15 +978,21 @@ static int i915_probe_agp(struct drm_dev + * Some of the preallocated space is taken by the GTT + * and popup. GTT is 1K per MB of aperture size, and popup is 4K. + */ +- if (IS_G4X(dev) || IS_PINEVIEW(dev) || IS_IRONLAKE(dev)) ++ if (IS_G4X(dev) || IS_PINEVIEW(dev) || IS_IRONLAKE(dev) || IS_GEN6(dev)) + overhead = 4096; + else + overhead = (*aperture_size / 1024) + 4096; + + switch (tmp & INTEL_GMCH_GMS_MASK) { + case INTEL_855_GMCH_GMS_DISABLED: +- DRM_ERROR("video memory is disabled\n"); +- return -1; ++ /* XXX: This is what my A1 silicon has. */ ++ if (IS_GEN6(dev)) { ++ stolen = 64 * 1024 * 1024; ++ } else { ++ DRM_ERROR("video memory is disabled\n"); ++ return -1; ++ } ++ break; + case INTEL_855_GMCH_GMS_STOLEN_1M: + stolen = 1 * 1024 * 1024; + break; +@@ -1064,7 +1070,7 @@ static unsigned long i915_gtt_to_phys(st + int gtt_offset, gtt_size; + + if (IS_I965G(dev)) { +- if (IS_G4X(dev) || IS_IRONLAKE(dev)) { ++ if (IS_G4X(dev) || IS_IRONLAKE(dev) || IS_GEN6(dev)) { + gtt_offset = 2*1024*1024; + gtt_size = 2*1024*1024; + } else { +@@ -1445,7 +1451,7 @@ int i915_driver_load(struct drm_device * + + dev->driver->get_vblank_counter = i915_get_vblank_counter; + dev->max_vblank_count = 0xffffff; /* only 24 bits of frame count */ +- if (IS_G4X(dev) || IS_IRONLAKE(dev)) { ++ if (IS_G4X(dev) || IS_IRONLAKE(dev) || IS_GEN6(dev)) { + dev->max_vblank_count = 0xffffffff; /* full 32 bit counter */ + dev->driver->get_vblank_counter = gm45_get_vblank_counter; + } +--- a/drivers/gpu/drm/i915/i915_drv.h ++++ b/drivers/gpu/drm/i915/i915_drv.h +@@ -1026,7 +1026,7 @@ extern int i915_wait_ring(struct drm_dev + #define IS_845G(dev) ((dev)->pci_device == 0x2562) + #define IS_I85X(dev) ((dev)->pci_device == 0x3582) + #define IS_I865G(dev) ((dev)->pci_device == 0x2572) +-#define IS_I8XX(dev) (INTEL_INFO(dev)->is_i8xx) ++#define IS_GEN2(dev) (INTEL_INFO(dev)->is_i8xx) + #define IS_I915G(dev) (INTEL_INFO(dev)->is_i915g) + #define IS_I915GM(dev) ((dev)->pci_device == 0x2592) + #define IS_I945G(dev) ((dev)->pci_device == 0x2772) +@@ -1045,8 +1045,29 @@ extern int i915_wait_ring(struct drm_dev + #define IS_I9XX(dev) (INTEL_INFO(dev)->is_i9xx) + #define IS_MOBILE(dev) (INTEL_INFO(dev)->is_mobile) + ++#define IS_GEN3(dev) (IS_I915G(dev) || \ ++ IS_I915GM(dev) || \ ++ IS_I945G(dev) || \ ++ IS_I945GM(dev) || \ ++ IS_G33(dev) || \ ++ IS_PINEVIEW(dev)) ++#define IS_GEN4(dev) ((dev)->pci_device == 0x2972 || \ ++ (dev)->pci_device == 0x2982 || \ ++ (dev)->pci_device == 0x2992 || \ ++ (dev)->pci_device == 0x29A2 || \ ++ (dev)->pci_device == 0x2A02 || \ ++ (dev)->pci_device == 0x2A12 || \ ++ (dev)->pci_device == 0x2E02 || \ ++ (dev)->pci_device == 0x2E12 || \ ++ (dev)->pci_device == 0x2E22 || \ ++ (dev)->pci_device == 0x2E32 || \ ++ (dev)->pci_device == 0x2A42 || \ ++ (dev)->pci_device == 0x2E42) ++ + #define I915_NEED_GFX_HWS(dev) (INTEL_INFO(dev)->need_gfx_hws) + ++#define IS_GEN6(dev) ((dev)->pci_device == 0x0102) ++ + /* With the 945 and later, Y tiling got adjusted so that it was 32 128-byte + * rows, which changed the alignment requirements and fence programming. + */ +@@ -1067,6 +1088,9 @@ extern int i915_wait_ring(struct drm_dev + #define I915_HAS_FBC(dev) (INTEL_INFO(dev)->has_fbc) + #define I915_HAS_RC6(dev) (INTEL_INFO(dev)->has_rc6) + ++#define HAS_PCH_SPLIT(dev) (IS_IRONLAKE(dev) || \ ++ IS_GEN6(dev)) ++ + #define PRIMARY_RINGBUFFER_SIZE (128*1024) + + #endif +--- a/drivers/gpu/drm/i915/i915_gem.c ++++ b/drivers/gpu/drm/i915/i915_gem.c +@@ -1819,7 +1819,7 @@ i915_do_wait_request(struct drm_device * + return -EIO; + + if (!i915_seqno_passed(i915_get_gem_seqno(dev), seqno)) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ier = I915_READ(DEIER) | I915_READ(GTIER); + else + ier = I915_READ(IER); +--- a/drivers/gpu/drm/i915/i915_gem_tiling.c ++++ b/drivers/gpu/drm/i915/i915_gem_tiling.c +@@ -209,7 +209,7 @@ i915_gem_detect_bit_6_swizzle(struct drm + uint32_t swizzle_y = I915_BIT_6_SWIZZLE_UNKNOWN; + bool need_disable; + +- if (IS_IRONLAKE(dev)) { ++ if (IS_IRONLAKE(dev) || IS_GEN6(dev)) { + /* On Ironlake whatever DRAM config, GPU always do + * same swizzling setup. + */ +--- a/drivers/gpu/drm/i915/i915_irq.c ++++ b/drivers/gpu/drm/i915/i915_irq.c +@@ -576,7 +576,7 @@ irqreturn_t i915_driver_irq_handler(DRM_ + + atomic_inc(&dev_priv->irq_received); + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return ironlake_irq_handler(dev); + + iir = I915_READ(IIR); +@@ -737,7 +737,7 @@ void i915_user_irq_get(struct drm_device + + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); + if (dev->irq_enabled && (++dev_priv->user_irq_refcount == 1)) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_enable_graphics_irq(dev_priv, GT_USER_INTERRUPT); + else + i915_enable_irq(dev_priv, I915_USER_INTERRUPT); +@@ -753,7 +753,7 @@ void i915_user_irq_put(struct drm_device + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); + BUG_ON(dev->irq_enabled && dev_priv->user_irq_refcount <= 0); + if (dev->irq_enabled && (--dev_priv->user_irq_refcount == 0)) { +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_disable_graphics_irq(dev_priv, GT_USER_INTERRUPT); + else + i915_disable_irq(dev_priv, I915_USER_INTERRUPT); +@@ -861,7 +861,7 @@ int i915_enable_vblank(struct drm_device + return -EINVAL; + + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_enable_display_irq(dev_priv, (pipe == 0) ? + DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); + else if (IS_I965G(dev)) +@@ -883,7 +883,7 @@ void i915_disable_vblank(struct drm_devi + unsigned long irqflags; + + spin_lock_irqsave(&dev_priv->user_irq_lock, irqflags); +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + ironlake_disable_display_irq(dev_priv, (pipe == 0) ? + DE_PIPEA_VBLANK: DE_PIPEB_VBLANK); + else +@@ -897,7 +897,7 @@ void i915_enable_interrupt (struct drm_d + { + struct drm_i915_private *dev_priv = dev->dev_private; + +- if (!IS_IRONLAKE(dev)) ++ if (!HAS_PCH_SPLIT(dev)) + opregion_enable_asle(dev); + dev_priv->irq_enabled = 1; + } +@@ -1076,7 +1076,7 @@ void i915_driver_irq_preinstall(struct d + INIT_WORK(&dev_priv->hotplug_work, i915_hotplug_work_func); + INIT_WORK(&dev_priv->error_work, i915_error_work_func); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + ironlake_irq_preinstall(dev); + return; + } +@@ -1108,7 +1108,7 @@ int i915_driver_irq_postinstall(struct d + + dev_priv->vblank_pipe = DRM_I915_VBLANK_PIPE_A | DRM_I915_VBLANK_PIPE_B; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return ironlake_irq_postinstall(dev); + + /* Unmask the interrupts that we always want on. */ +@@ -1196,7 +1196,7 @@ void i915_driver_irq_uninstall(struct dr + + dev_priv->vblank_pipe = 0; + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + ironlake_irq_uninstall(dev); + return; + } +--- a/drivers/gpu/drm/i915/intel_bios.c ++++ b/drivers/gpu/drm/i915/intel_bios.c +@@ -247,6 +247,7 @@ static void + parse_general_features(struct drm_i915_private *dev_priv, + struct bdb_header *bdb) + { ++ struct drm_device *dev = dev_priv->dev; + struct bdb_general_features *general; + + /* Set sensible defaults in case we can't find the general block */ +@@ -263,7 +264,7 @@ parse_general_features(struct drm_i915_p + if (IS_I85X(dev_priv->dev)) + dev_priv->lvds_ssc_freq = + general->ssc_freq ? 66 : 48; +- else if (IS_IRONLAKE(dev_priv->dev)) ++ else if (IS_IRONLAKE(dev_priv->dev) || IS_GEN6(dev)) + dev_priv->lvds_ssc_freq = + general->ssc_freq ? 100 : 120; + else +--- a/drivers/gpu/drm/i915/intel_crt.c ++++ b/drivers/gpu/drm/i915/intel_crt.c +@@ -39,7 +39,7 @@ static void intel_crt_dpms(struct drm_en + struct drm_i915_private *dev_priv = dev->dev_private; + u32 temp, reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + reg = PCH_ADPA; + else + reg = ADPA; +@@ -113,7 +113,7 @@ static void intel_crt_mode_set(struct dr + else + dpll_md_reg = DPLL_B_MD; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + adpa_reg = PCH_ADPA; + else + adpa_reg = ADPA; +@@ -122,7 +122,7 @@ static void intel_crt_mode_set(struct dr + * Disable separate mode multiplier used when cloning SDVO to CRT + * XXX this needs to be adjusted when we really are cloning + */ +- if (IS_I965G(dev) && !IS_IRONLAKE(dev)) { ++ if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) { + dpll_md = I915_READ(dpll_md_reg); + I915_WRITE(dpll_md_reg, + dpll_md & ~DPLL_MD_UDI_MULTIPLIER_MASK); +@@ -136,11 +136,11 @@ static void intel_crt_mode_set(struct dr + + if (intel_crtc->pipe == 0) { + adpa |= ADPA_PIPE_A_SELECT; +- if (!IS_IRONLAKE(dev)) ++ if (!HAS_PCH_SPLIT(dev)) + I915_WRITE(BCLRPAT_A, 0); + } else { + adpa |= ADPA_PIPE_B_SELECT; +- if (!IS_IRONLAKE(dev)) ++ if (!HAS_PCH_SPLIT(dev)) + I915_WRITE(BCLRPAT_B, 0); + } + +@@ -202,7 +202,7 @@ static bool intel_crt_detect_hotplug(str + u32 hotplug_en; + int i, tries = 0; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return intel_ironlake_crt_detect_hotplug(connector); + + /* +@@ -524,7 +524,7 @@ void intel_crt_init(struct drm_device *d + &intel_output->enc); + + /* Set up the DDC bus. */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + i2c_reg = PCH_GPIOA; + else { + i2c_reg = GPIOA; +--- a/drivers/gpu/drm/i915/intel_display.c ++++ b/drivers/gpu/drm/i915/intel_display.c +@@ -232,7 +232,7 @@ struct intel_limit { + #define G4X_P2_DISPLAY_PORT_FAST 10 + #define G4X_P2_DISPLAY_PORT_LIMIT 0 + +-/* Ironlake */ ++/* Ironlake / Sandybridge */ + /* as we calculate clock using (register_value + 2) for + N/M1/M2, so here the range value for them is (actual_value-2). + */ +@@ -690,7 +690,7 @@ static const intel_limit_t *intel_limit( + struct drm_device *dev = crtc->dev; + const intel_limit_t *limit; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + limit = intel_ironlake_limit(crtc); + else if (IS_G4X(dev)) { + limit = intel_g4x_limit(crtc); +@@ -1366,7 +1366,7 @@ intel_pipe_set_base(struct drm_crtc *crt + dspcntr &= ~DISPPLANE_TILED; + } + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + /* must disable */ + dspcntr |= DISPPLANE_TRICKLE_FEED_DISABLE; + +@@ -1427,7 +1427,7 @@ static void i915_disable_vga (struct drm + u8 sr1; + u32 vga_reg; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + vga_reg = CPU_VGACNTRL; + else + vga_reg = VGACNTRL; +@@ -2111,7 +2111,7 @@ static bool intel_crtc_mode_fixup(struct + struct drm_display_mode *adjusted_mode) + { + struct drm_device *dev = crtc->dev; +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + /* FDI link clock is fixed at 2.7G */ + if (mode->clock * 3 > 27000 * 4) + return MODE_CLOCK_HIGH; +@@ -2967,7 +2967,7 @@ static int intel_crtc_mode_set(struct dr + refclk / 1000); + } else if (IS_I9XX(dev)) { + refclk = 96000; +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + refclk = 120000; /* 120Mhz refclk */ + } else { + refclk = 48000; +@@ -3025,7 +3025,7 @@ static int intel_crtc_mode_set(struct dr + } + + /* FDI link */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + int lane, link_bw, bpp; + /* eDP doesn't require FDI link, so just set DP M/N + according to current link config */ +@@ -3102,7 +3102,7 @@ static int intel_crtc_mode_set(struct dr + * PCH B stepping, previous chipset stepping should be + * ignoring this setting. + */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + temp = I915_READ(PCH_DREF_CONTROL); + /* Always enable nonspread source */ + temp &= ~DREF_NONSPREAD_SOURCE_MASK; +@@ -3149,7 +3149,7 @@ static int intel_crtc_mode_set(struct dr + reduced_clock.m2; + } + +- if (!IS_IRONLAKE(dev)) ++ if (!HAS_PCH_SPLIT(dev)) + dpll = DPLL_VGA_MODE_DIS; + + if (IS_I9XX(dev)) { +@@ -3162,7 +3162,7 @@ static int intel_crtc_mode_set(struct dr + sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; + if (IS_I945G(dev) || IS_I945GM(dev) || IS_G33(dev)) + dpll |= (sdvo_pixel_multiply - 1) << SDVO_MULTIPLIER_SHIFT_HIRES; +- else if (IS_IRONLAKE(dev)) ++ else if (HAS_PCH_SPLIT(dev)) + dpll |= (sdvo_pixel_multiply - 1) << PLL_REF_SDVO_HDMI_MULTIPLIER_SHIFT; + } + if (is_dp) +@@ -3174,7 +3174,7 @@ static int intel_crtc_mode_set(struct dr + else { + dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA01_P1_POST_DIV_SHIFT; + /* also FPA1 */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + dpll |= (1 << (clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; + if (IS_G4X(dev) && has_reduced_clock) + dpll |= (1 << (reduced_clock.p1 - 1)) << DPLL_FPA1_P1_POST_DIV_SHIFT; +@@ -3193,7 +3193,7 @@ static int intel_crtc_mode_set(struct dr + dpll |= DPLLB_LVDS_P2_CLOCK_DIV_14; + break; + } +- if (IS_I965G(dev) && !IS_IRONLAKE(dev)) ++ if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) + dpll |= (6 << PLL_LOAD_PULSE_PHASE_SHIFT); + } else { + if (is_lvds) { +@@ -3227,7 +3227,7 @@ static int intel_crtc_mode_set(struct dr + + /* Ironlake's plane is forced to pipe, bit 24 is to + enable color space conversion */ +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + if (pipe == 0) + dspcntr &= ~DISPPLANE_SEL_PIPE_MASK; + else +@@ -3254,14 +3254,14 @@ static int intel_crtc_mode_set(struct dr + + + /* Disable the panel fitter if it was on our pipe */ +- if (!IS_IRONLAKE(dev) && intel_panel_fitter_pipe(dev) == pipe) ++ if (!HAS_PCH_SPLIT(dev) && intel_panel_fitter_pipe(dev) == pipe) + I915_WRITE(PFIT_CONTROL, 0); + + DRM_DEBUG_KMS("Mode for pipe %c:\n", pipe == 0 ? 'A' : 'B'); + drm_mode_debug_printmodeline(mode); + + /* assign to Ironlake registers */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + fp_reg = pch_fp_reg; + dpll_reg = pch_dpll_reg; + } +@@ -3282,7 +3282,7 @@ static int intel_crtc_mode_set(struct dr + if (is_lvds) { + u32 lvds; + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + lvds_reg = PCH_LVDS; + + lvds = I915_READ(lvds_reg); +@@ -3328,7 +3328,7 @@ static int intel_crtc_mode_set(struct dr + /* Wait for the clocks to stabilize. */ + udelay(150); + +- if (IS_I965G(dev) && !IS_IRONLAKE(dev)) { ++ if (IS_I965G(dev) && !HAS_PCH_SPLIT(dev)) { + if (is_sdvo) { + sdvo_pixel_multiply = adjusted_mode->clock / mode->clock; + I915_WRITE(dpll_md_reg, (0 << DPLL_MD_UDI_DIVIDER_SHIFT) | +@@ -3375,14 +3375,14 @@ static int intel_crtc_mode_set(struct dr + /* pipesrc and dspsize control the size that is scaled from, which should + * always be the user's requested size. + */ +- if (!IS_IRONLAKE(dev)) { ++ if (!HAS_PCH_SPLIT(dev)) { + I915_WRITE(dspsize_reg, ((mode->vdisplay - 1) << 16) | + (mode->hdisplay - 1)); + I915_WRITE(dsppos_reg, 0); + } + I915_WRITE(pipesrc_reg, ((mode->hdisplay - 1) << 16) | (mode->vdisplay - 1)); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + I915_WRITE(data_m1_reg, TU_SIZE(m_n.tu) | m_n.gmch_m); + I915_WRITE(data_n1_reg, TU_SIZE(m_n.tu) | m_n.gmch_n); + I915_WRITE(link_m1_reg, m_n.link_m); +@@ -3403,7 +3403,7 @@ static int intel_crtc_mode_set(struct dr + + intel_wait_for_vblank(dev); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + /* enable address swizzle for tiling buffer */ + temp = I915_READ(DISP_ARB_CTL); + I915_WRITE(DISP_ARB_CTL, temp | DISP_TILE_SURFACE_SWIZZLING); +@@ -3438,7 +3438,7 @@ void intel_crtc_load_lut(struct drm_crtc + return; + + /* use legacy palette for Ironlake */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + palreg = (intel_crtc->pipe == 0) ? LGC_PALETTE_A : + LGC_PALETTE_B; + +@@ -3922,7 +3922,7 @@ static void intel_increase_pllclock(stru + int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; + int dpll = I915_READ(dpll_reg); + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return; + + if (!dev_priv->lvds_downclock_avail) +@@ -3961,7 +3961,7 @@ static void intel_decrease_pllclock(stru + int dpll_reg = (pipe == 0) ? DPLL_A : DPLL_B; + int dpll = I915_READ(dpll_reg); + +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + return; + + if (!dev_priv->lvds_downclock_avail) +@@ -4382,7 +4382,7 @@ static void intel_setup_outputs(struct d + if (IS_MOBILE(dev) && !IS_I830(dev)) + intel_lvds_init(dev); + +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + int found; + + if (IS_MOBILE(dev) && (I915_READ(DP_A) & DP_DETECTED)) +@@ -4451,7 +4451,7 @@ static void intel_setup_outputs(struct d + DRM_DEBUG_KMS("probing DP_D\n"); + intel_dp_init(dev, DP_D); + } +- } else if (IS_I8XX(dev)) ++ } else if (IS_GEN2(dev)) + intel_dvo_init(dev); + + if (SUPPORTS_TV(dev)) +@@ -4599,7 +4599,7 @@ void intel_init_clock_gating(struct drm_ + * Disable clock gating reported to work incorrectly according to the + * specs, but enable as much else as we can. + */ +- if (IS_IRONLAKE(dev)) { ++ if (HAS_PCH_SPLIT(dev)) { + return; + } else if (IS_G4X(dev)) { + uint32_t dspclk_gate; +@@ -4672,7 +4672,7 @@ static void intel_init_display(struct dr + struct drm_i915_private *dev_priv = dev->dev_private; + + /* We always want a DPMS function */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + dev_priv->display.dpms = ironlake_crtc_dpms; + else + dev_priv->display.dpms = i9xx_crtc_dpms; +@@ -4715,7 +4715,7 @@ static void intel_init_display(struct dr + i830_get_display_clock_speed; + + /* For FIFO watermark updates */ +- if (IS_IRONLAKE(dev)) ++ if (HAS_PCH_SPLIT(dev)) + dev_priv->display.update_wm = NULL; + else if (IS_G4X(dev)) + dev_priv->display.update_wm = g4x_update_wm; +--- a/drivers/gpu/drm/i915/intel_lvds.c ++++ b/drivers/gpu/drm/i915/intel_lvds.c +@@ -661,7 +661,7 @@ static enum drm_connector_status intel_l + /* ACPI lid methods were generally unreliable in this generation, so + * don't even bother. + */ +- if (IS_I8XX(dev)) ++ if (IS_GEN2(dev)) + return connector_status_connected; + + if (!dmi_check_system(bad_lid_status) && !acpi_lid_open()) +--- a/drivers/gpu/drm/i915/intel_overlay.c ++++ b/drivers/gpu/drm/i915/intel_overlay.c +@@ -172,7 +172,7 @@ struct overlay_registers { + #define OFC_UPDATE 0x1 + + #define OVERLAY_NONPHYSICAL(dev) (IS_G33(dev) || IS_I965G(dev)) +-#define OVERLAY_EXISTS(dev) (!IS_G4X(dev) && !IS_IRONLAKE(dev)) ++#define OVERLAY_EXISTS(dev) (!IS_G4X(dev) && !IS_IRONLAKE(dev) && !IS_GEN6(dev)) + + + static struct overlay_registers *intel_overlay_map_regs_atomic(struct intel_overlay *overlay) +From 79b9517a33a283c5d9db875c263670ed1e055f7e Mon Sep 17 00:00:00 2001 +From: Dave Airlie +Date: Mon, 19 Apr 2010 17:54:31 +1000 +Subject: drm/radeon/kms: add FireMV 2400 PCI ID. + +From: Dave Airlie + +commit 79b9517a33a283c5d9db875c263670ed1e055f7e upstream. + +This is an M24/X600 chip. + +From RH# 581927 + +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + include/drm/drm_pciids.h | 1 + + 1 file changed, 1 insertion(+) + +--- a/include/drm/drm_pciids.h ++++ b/include/drm/drm_pciids.h +@@ -6,6 +6,7 @@ + {0x1002, 0x3150, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY}, \ + {0x1002, 0x3152, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x3154, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ ++ {0x1002, 0x3155, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_IS_MOBILITY|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x3E50, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x3E54, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RV380|RADEON_NEW_MEMMAP}, \ + {0x1002, 0x4136, PCI_ANY_ID, PCI_ANY_ID, 0, 0, CHIP_RS100|RADEON_IS_IGP}, \ +From 30f69f3fb20bd719b5e1bf879339914063d38f47 Mon Sep 17 00:00:00 2001 +From: Jerome Glisse +Date: Fri, 16 Apr 2010 18:46:35 +0200 +Subject: drm/radeon/kms: fix rs600 tlb flush + +From: Jerome Glisse + +commit 30f69f3fb20bd719b5e1bf879339914063d38f47 upstream. + +Typo in in flush leaded to no flush of the RS600 tlb which +ultimately leaded to massive system ram corruption, with +this patch everythings seems to work properly. + +Signed-off-by: Jerome Glisse +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/radeon/rs600.c | 2 +- + 1 file changed, 1 insertion(+), 1 deletion(-) + +--- a/drivers/gpu/drm/radeon/rs600.c ++++ b/drivers/gpu/drm/radeon/rs600.c +@@ -175,7 +175,7 @@ void rs600_gart_tlb_flush(struct radeon_ + WREG32_MC(R_000100_MC_PT0_CNTL, tmp); + + tmp = RREG32_MC(R_000100_MC_PT0_CNTL); +- tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) & S_000100_INVALIDATE_L2_CACHE(1); ++ tmp |= S_000100_INVALIDATE_ALL_L1_TLBS(1) | S_000100_INVALIDATE_L2_CACHE(1); + WREG32_MC(R_000100_MC_PT0_CNTL, tmp); + + tmp = RREG32_MC(R_000100_MC_PT0_CNTL); +From ba1163de2f74d624e7b0e530c4104c98ede0045a Mon Sep 17 00:00:00 2001 +From: Adam Jackson +Date: Tue, 6 Apr 2010 16:11:00 +0000 +Subject: drm/edid/quirks: Envision EN2028 + +From: Adam Jackson + +commit ba1163de2f74d624e7b0e530c4104c98ede0045a upstream. + +Claims 1280x1024 preferred, physically 1600x1200 + +cf. http://bugzilla.redhat.com/530399 + +Signed-off-by: Adam Jackson +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/drm_edid.c | 2 ++ + 1 file changed, 2 insertions(+) + +--- a/drivers/gpu/drm/drm_edid.c ++++ b/drivers/gpu/drm/drm_edid.c +@@ -85,6 +85,8 @@ static struct edid_quirk { + + /* Envision Peripherals, Inc. EN-7100e */ + { "EPI", 59264, EDID_QUIRK_135_CLOCK_TOO_HIGH }, ++ /* Envision EN2028 */ ++ { "EPI", 8232, EDID_QUIRK_PREFER_LARGE_60 }, + + /* Funai Electronics PM36B */ + { "FCM", 13600, EDID_QUIRK_PREFER_LARGE_75 | +From da58405860b992d2bb21ebae5d685fe3204dd3f0 Mon Sep 17 00:00:00 2001 +From: Chris Wilson +Date: Thu, 18 Mar 2010 11:56:54 +0000 +Subject: drm: Return ENODEV if the inode mapping changes + +From: Chris Wilson + +commit da58405860b992d2bb21ebae5d685fe3204dd3f0 upstream. + +Replace a BUG_ON with an error code in the event that the inode mapping +changes between calls to drm_open. This may happen for instance if udev +is loaded subsequent to the original opening of the device: + +[ 644.291870] kernel BUG at drivers/gpu/drm/drm_fops.c:146! +[ 644.291876] invalid opcode: 0000 [#1] SMP +[ 644.291882] last sysfs file: /sys/kernel/uevent_seqnum +[ 644.291888] +[ 644.291895] Pid: 7276, comm: lt-cairo-test-s Not tainted 2.6.34-rc1 #2 N150/N210/N220 /N150/N210/N220 +[ 644.291903] EIP: 0060:[] EFLAGS: 00210283 CPU: 0 +[ 644.291912] EIP is at drm_open+0x4b1/0x4e2 +[ 644.291918] EAX: f72d8d18 EBX: f790a400 ECX: f73176b8 EDX: 00000000 +[ 644.291923] ESI: f790a414 EDI: f790a414 EBP: f647ae20 ESP: f647adfc +[ 644.291929] DS: 007b ES: 007b FS: 00d8 GS: 0033 SS: 0068 +[ 644.291937] Process lt-cairo-test-s (pid: 7276, ti=f647a000 task=f73f5c80 task.ti=f647a000) +[ 644.291941] Stack: +[ 644.291945] 00000000 f7bb7400 00000080 f6451100 f73176b8 f6479214 f6451100 f73176b8 +[ 644.291957] <0> c1297ce0 f647ae34 c11c6c04 f73176b8 f7949800 00000000 f647ae54 c1080ac5 +[ 644.291969] <0> f7949800 f6451100 00000000 f6451100 f73176b8 f6452780 f647ae70 c107d1e6 +[ 644.291982] Call Trace: +[ 644.291991] [] ? drm_stub_open+0x8a/0xb8 +[ 644.292000] [] ? chrdev_open+0xef/0x106 +[ 644.292008] [] ? __dentry_open+0xd4/0x1a6 +[ 644.292015] [] ? nameidata_to_filp+0x31/0x45 +[ 644.292022] [] ? chrdev_open+0x0/0x106 +[ 644.292030] [] ? do_last+0x346/0x423 +[ 644.292037] [] ? do_filp_open+0x190/0x415 +[ 644.292046] [] ? handle_mm_fault+0x214/0x710 +[ 644.292053] [] ? do_sys_open+0x4d/0xe9 +[ 644.292061] [] ? do_page_fault+0x211/0x23f +[ 644.292068] [] ? sys_open+0x23/0x2b +[ 644.292075] [] ? sysenter_do_call+0x12/0x26 +[ 644.292079] Code: 89 f0 89 55 dc e8 8d 96 0a 00 8b 45 e0 8b 55 dc 83 78 04 01 75 28 8b 83 18 02 00 00 85 c0 74 0f 8b 4d ec 3b 81 ac 00 00 00 74 13 <0f> 0b eb fe 8b 4d ec 8b 81 ac 00 00 00 89 83 18 02 00 00 89 f0 +[ 644.292143] EIP: [] drm_open+0x4b1/0x4e2 SS:ESP 0068:f647adfc +[ 644.292175] ---[ end trace 2ddd476af89a60fa ]--- + +Signed-off-by: Chris Wilson +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/drm_fops.c | 16 +++++++++------- + 1 file changed, 9 insertions(+), 7 deletions(-) + +--- a/drivers/gpu/drm/drm_fops.c ++++ b/drivers/gpu/drm/drm_fops.c +@@ -140,14 +140,16 @@ int drm_open(struct inode *inode, struct + spin_unlock(&dev->count_lock); + } + out: +- mutex_lock(&dev->struct_mutex); +- if (minor->type == DRM_MINOR_LEGACY) { +- BUG_ON((dev->dev_mapping != NULL) && +- (dev->dev_mapping != inode->i_mapping)); +- if (dev->dev_mapping == NULL) +- dev->dev_mapping = inode->i_mapping; ++ if (!retcode) { ++ mutex_lock(&dev->struct_mutex); ++ if (minor->type == DRM_MINOR_LEGACY) { ++ if (dev->dev_mapping == NULL) ++ dev->dev_mapping = inode->i_mapping; ++ else if (dev->dev_mapping != inode->i_mapping) ++ retcode = -ENODEV; ++ } ++ mutex_unlock(&dev->struct_mutex); + } +- mutex_unlock(&dev->struct_mutex); + + return retcode; + } +From 725398322d05486109375fbb85c3404108881e17 Mon Sep 17 00:00:00 2001 +From: Zhao Yakui +Date: Thu, 4 Mar 2010 08:25:55 +0000 +Subject: drm: remove the EDID blob stored in the EDID property when it is disconnected + +From: Zhao Yakui + +commit 725398322d05486109375fbb85c3404108881e17 upstream. + +Now the EDID property will be updated when the corresponding EDID can be +obtained from the external display device. But after the external device +is plugged-out, the EDID property is not updated. In such case we still +get the corresponding EDID property although it is already detected as +disconnected. + +https://bugs.freedesktop.org/show_bug.cgi?id=26743 + +Signed-off-by: Zhao Yakui +Signed-off-by: Zhenyu Wang +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/drm_crtc_helper.c | 1 + + 1 file changed, 1 insertion(+) + +--- a/drivers/gpu/drm/drm_crtc_helper.c ++++ b/drivers/gpu/drm/drm_crtc_helper.c +@@ -104,6 +104,7 @@ int drm_helper_probe_single_connector_mo + if (connector->status == connector_status_disconnected) { + DRM_DEBUG_KMS("%s is disconnected\n", + drm_get_connector_name(connector)); ++ drm_mode_connector_update_edid_property(connector, NULL); + goto prune; + } + +From 44fef22416886a04d432043f741a6faf2c6ffefd Mon Sep 17 00:00:00 2001 +From: Ben Skeggs +Date: Thu, 18 Feb 2010 09:12:09 +1000 +Subject: drm/edid: allow certain bogus edids to hit a fixup path rather than fail + +From: Ben Skeggs + +commit 44fef22416886a04d432043f741a6faf2c6ffefd upstream. + +Signed-off-by: Ben Skeggs +Signed-off-by: Dave Airlie +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/gpu/drm/drm_edid.c | 9 --------- + 1 file changed, 9 deletions(-) + +--- a/drivers/gpu/drm/drm_edid.c ++++ b/drivers/gpu/drm/drm_edid.c +@@ -707,15 +707,6 @@ static struct drm_display_mode *drm_mode + mode->vsync_end = mode->vsync_start + vsync_pulse_width; + mode->vtotal = mode->vdisplay + vblank; + +- /* perform the basic check for the detailed timing */ +- if (mode->hsync_end > mode->htotal || +- mode->vsync_end > mode->vtotal) { +- drm_mode_destroy(dev, mode); +- DRM_DEBUG_KMS("Incorrect detailed timing. " +- "Sync is beyond the blank.\n"); +- return NULL; +- } +- + /* Some EDIDs have bogus h/vtotal values */ + if (mode->hsync_end > mode->htotal) + mode->htotal = mode->hsync_end + 1; +From 0725e95ea56698774e893edb7e7276b1d6890954 Mon Sep 17 00:00:00 2001 +From: Bernhard Rosenkraenzer +Date: Wed, 10 Mar 2010 12:36:43 +0100 +Subject: USB: qcserial: add new device ids + +From: Bernhard Rosenkraenzer + +commit 0725e95ea56698774e893edb7e7276b1d6890954 upstream. + +This patch adds various USB device IDs for Gobi 2000 devices, as found in the +drivers available at https://www.codeaurora.org/wiki/GOBI_Releases + +Signed-off-by: Bernhard Rosenkraenzer +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/usb/serial/qcserial.c | 29 +++++++++++++++++++++++++++++ + 1 file changed, 29 insertions(+) + +--- a/drivers/usb/serial/qcserial.c ++++ b/drivers/usb/serial/qcserial.c +@@ -47,6 +47,35 @@ static struct usb_device_id id_table[] = + {USB_DEVICE(0x05c6, 0x9221)}, /* Generic Gobi QDL device */ + {USB_DEVICE(0x05c6, 0x9231)}, /* Generic Gobi QDL device */ + {USB_DEVICE(0x1f45, 0x0001)}, /* Unknown Gobi QDL device */ ++ {USB_DEVICE(0x413c, 0x8185)}, /* Dell Gobi 2000 QDL device (N0218, VU936) */ ++ {USB_DEVICE(0x413c, 0x8186)}, /* Dell Gobi 2000 Modem device (N0218, VU936) */ ++ {USB_DEVICE(0x05c6, 0x9224)}, /* Sony Gobi 2000 QDL device (N0279, VU730) */ ++ {USB_DEVICE(0x05c6, 0x9225)}, /* Sony Gobi 2000 Modem device (N0279, VU730) */ ++ {USB_DEVICE(0x05c6, 0x9244)}, /* Samsung Gobi 2000 QDL device (VL176) */ ++ {USB_DEVICE(0x05c6, 0x9245)}, /* Samsung Gobi 2000 Modem device (VL176) */ ++ {USB_DEVICE(0x03f0, 0x241d)}, /* HP Gobi 2000 QDL device (VP412) */ ++ {USB_DEVICE(0x03f0, 0x251d)}, /* HP Gobi 2000 Modem device (VP412) */ ++ {USB_DEVICE(0x05c6, 0x9214)}, /* Acer Gobi 2000 QDL device (VP413) */ ++ {USB_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */ ++ {USB_DEVICE(0x05c6, 0x9264)}, /* Asus Gobi 2000 QDL device (VR305) */ ++ {USB_DEVICE(0x05c6, 0x9265)}, /* Asus Gobi 2000 Modem device (VR305) */ ++ {USB_DEVICE(0x05c6, 0x9234)}, /* Top Global Gobi 2000 QDL device (VR306) */ ++ {USB_DEVICE(0x05c6, 0x9235)}, /* Top Global Gobi 2000 Modem device (VR306) */ ++ {USB_DEVICE(0x05c6, 0x9274)}, /* iRex Technologies Gobi 2000 QDL device (VR307) */ ++ {USB_DEVICE(0x05c6, 0x9275)}, /* iRex Technologies Gobi 2000 Modem device (VR307) */ ++ {USB_DEVICE(0x1199, 0x9000)}, /* Sierra Wireless Gobi 2000 QDL device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9001)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9002)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9003)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9004)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9005)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9006)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9007)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9008)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9009)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x900a)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x16d8, 0x8001)}, /* CMDTech Gobi 2000 QDL device (VU922) */ ++ {USB_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */ + { } /* Terminating entry */ + }; + MODULE_DEVICE_TABLE(usb, id_table); +From 70136081fc67ea77d849f86fa323e5773c8e40ea Mon Sep 17 00:00:00 2001 +From: Theodore Kilgore +Date: Fri, 25 Dec 2009 05:15:10 -0300 +Subject: V4L/DVB (13991): gspca_mr973010a: Fix cif type 1 cameras not streaming on UHCI controllers + +From: Theodore Kilgore + +commit 70136081fc67ea77d849f86fa323e5773c8e40ea upstream. + +If you read the mail to Oliver Neukum on the linux-usb list, then you know +that I found a cure for the mysterious problem that the MR97310a CIF "type +1" cameras have been freezing up and refusing to stream if hooked up to a +machine with a UHCI controller. + +Namely, the cure is that if the camera is an mr97310a CIF type 1 camera, you +have to send it 0xa0, 0x00. Somehow, this is a timing reset command, or +such. It un-blocks whatever was previously stopping the CIF type 1 cameras +from working on the UHCI-based machines. + +Signed-off-by: Theodore Kilgore +Signed-off-by: Hans de Goede +Signed-off-by: Mauro Carvalho Chehab +Signed-off-by: Greg Kroah-Hartman + +--- + drivers/media/video/gspca/mr97310a.c | 6 ++++++ + 1 file changed, 6 insertions(+) + +--- a/drivers/media/video/gspca/mr97310a.c ++++ b/drivers/media/video/gspca/mr97310a.c +@@ -697,6 +697,12 @@ static int start_cif_cam(struct gspca_de + {0x13, 0x00, {0x01}, 1}, + {0, 0, {0}, 0} + }; ++ /* Without this command the cam won't work with USB-UHCI */ ++ gspca_dev->usb_buf[0] = 0x0a; ++ gspca_dev->usb_buf[1] = 0x00; ++ err_code = mr_write(gspca_dev, 2); ++ if (err_code < 0) ++ return err_code; + err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data, + ARRAY_SIZE(cif_sensor1_init_data)); + } +diff --git a/drivers/pci/pci.c b/drivers/pci/pci.c +index 315fea4..3245d33 100644 +--- a/drivers/pci/pci.c ++++ b/drivers/pci/pci.c +@@ -2421,18 +2421,17 @@ EXPORT_SYMBOL_GPL(pci_reset_function); + */ + int pcix_get_max_mmrbc(struct pci_dev *dev) + { +- int err, cap; ++ int cap; + u32 stat; + + cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); + if (!cap) + return -EINVAL; + +- err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat); +- if (err) ++ if (pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat)) + return -EINVAL; + +- return (stat & PCI_X_STATUS_MAX_READ) >> 12; ++ return 512 << ((stat & PCI_X_STATUS_MAX_READ) >> 21); + } + EXPORT_SYMBOL(pcix_get_max_mmrbc); + +@@ -2445,18 +2444,17 @@ EXPORT_SYMBOL(pcix_get_max_mmrbc); + */ + int pcix_get_mmrbc(struct pci_dev *dev) + { +- int ret, cap; +- u32 cmd; ++ int cap; ++ u16 cmd; + + cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); + if (!cap) + return -EINVAL; + +- ret = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd); +- if (!ret) +- ret = 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2); ++ if (pci_read_config_word(dev, cap + PCI_X_CMD, &cmd)) ++ return -EINVAL; + +- return ret; ++ return 512 << ((cmd & PCI_X_CMD_MAX_READ) >> 2); + } + EXPORT_SYMBOL(pcix_get_mmrbc); + +@@ -2471,28 +2469,27 @@ EXPORT_SYMBOL(pcix_get_mmrbc); + */ + int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc) + { +- int cap, err = -EINVAL; +- u32 stat, cmd, v, o; ++ int cap; ++ u32 stat, v, o; ++ u16 cmd; + + if (mmrbc < 512 || mmrbc > 4096 || !is_power_of_2(mmrbc)) +- goto out; ++ return -EINVAL; + + v = ffs(mmrbc) - 10; + + cap = pci_find_capability(dev, PCI_CAP_ID_PCIX); + if (!cap) +- goto out; ++ return -EINVAL; + +- err = pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat); +- if (err) +- goto out; ++ if (pci_read_config_dword(dev, cap + PCI_X_STATUS, &stat)) ++ return -EINVAL; + + if (v > (stat & PCI_X_STATUS_MAX_READ) >> 21) + return -E2BIG; + +- err = pci_read_config_dword(dev, cap + PCI_X_CMD, &cmd); +- if (err) +- goto out; ++ if (pci_read_config_word(dev, cap + PCI_X_CMD, &cmd)) ++ return -EINVAL; + + o = (cmd & PCI_X_CMD_MAX_READ) >> 2; + if (o != v) { +@@ -2502,10 +2499,10 @@ int pcix_set_mmrbc(struct pci_dev *dev, int mmrbc) + + cmd &= ~PCI_X_CMD_MAX_READ; + cmd |= v << 2; +- err = pci_write_config_dword(dev, cap + PCI_X_CMD, cmd); ++ if (pci_write_config_word(dev, cap + PCI_X_CMD, cmd)) ++ return -EIO; + } +-out: +- return err; ++ return 0; + } + EXPORT_SYMBOL(pcix_set_mmrbc); + + diff --git a/linux-2.6-usb-uvc-autosuspend.diff b/linux-2.6-usb-uvc-autosuspend.diff new file mode 100644 index 000000000..b7c7f6e0f --- /dev/null +++ b/linux-2.6-usb-uvc-autosuspend.diff @@ -0,0 +1,19 @@ +commit 9d4c919bcfa794c054cc33155c7e3c53ac2c5684 +Author: Matthew Garrett +Date: Sun Jul 19 02:24:49 2009 +0100 + + Enable autosuspend on UVC by default + +diff --git a/drivers/media/video/uvc/uvc_driver.c b/drivers/media/video/uvc/uvc_driver.c +index 89927b7..8de516b 100644 +--- a/drivers/media/video/uvc/uvc_driver.c ++++ b/drivers/media/video/uvc/uvc_driver.c +@@ -1647,6 +1647,8 @@ static int uvc_probe(struct usb_interface *intf, + "supported.\n", ret); + } + ++ usb_device_autosuspend_enable(udev); ++ + uvc_trace(UVC_TRACE_PROBE, "UVC device initialized.\n"); + return 0; + diff --git a/linux-2.6-usb-wwan-update.patch b/linux-2.6-usb-wwan-update.patch new file mode 100644 index 000000000..de53ca0db --- /dev/null +++ b/linux-2.6-usb-wwan-update.patch @@ -0,0 +1,1641 @@ +diff -up linux-2.6.33.noarch/drivers/usb/serial/Kconfig.orig linux-2.6.33.noarch/drivers/usb/serial/Kconfig +--- linux-2.6.33.noarch/drivers/usb/serial/Kconfig.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/usb/serial/Kconfig 2010-04-01 12:40:00.838027293 -0400 +@@ -565,8 +565,12 @@ config USB_SERIAL_XIRCOM + To compile this driver as a module, choose M here: the + module will be called keyspan_pda. + ++config USB_SERIAL_WWAN ++ tristate ++ + config USB_SERIAL_OPTION + tristate "USB driver for GSM and CDMA modems" ++ select USB_SERIAL_WWAN + help + Say Y here if you have a GSM or CDMA modem that's connected to USB. + +diff -up linux-2.6.33.noarch/drivers/usb/serial/Makefile.orig linux-2.6.33.noarch/drivers/usb/serial/Makefile +--- linux-2.6.33.noarch/drivers/usb/serial/Makefile.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/usb/serial/Makefile 2010-04-01 12:41:11.407997314 -0400 +@@ -51,6 +51,7 @@ obj-$(CONFIG_USB_SERIAL_SIEMENS_MPI) += + obj-$(CONFIG_USB_SERIAL_SIERRAWIRELESS) += sierra.o + obj-$(CONFIG_USB_SERIAL_SPCP8X5) += spcp8x5.o + obj-$(CONFIG_USB_SERIAL_SYMBOL) += symbolserial.o ++obj-$(CONFIG_USB_SERIAL_WWAN) += usb_wwan.o + obj-$(CONFIG_USB_SERIAL_TI) += ti_usb_3410_5052.o + obj-$(CONFIG_USB_SERIAL_VISOR) += visor.o + obj-$(CONFIG_USB_SERIAL_WHITEHEAT) += whiteheat.o +diff -up linux-2.6.33.noarch/drivers/usb/serial/option.c.orig linux-2.6.33.noarch/drivers/usb/serial/option.c +--- linux-2.6.33.noarch/drivers/usb/serial/option.c.orig 2010-02-24 13:52:17.000000000 -0500 ++++ linux-2.6.33.noarch/drivers/usb/serial/option.c 2010-04-01 12:42:37.072122049 -0400 +@@ -41,35 +41,14 @@ + #include + #include + #include ++#include "usb-wwan.h" + + /* Function prototypes */ + static int option_probe(struct usb_serial *serial, + const struct usb_device_id *id); +-static int option_open(struct tty_struct *tty, struct usb_serial_port *port); +-static void option_close(struct usb_serial_port *port); +-static void option_dtr_rts(struct usb_serial_port *port, int on); +- +-static int option_startup(struct usb_serial *serial); +-static void option_disconnect(struct usb_serial *serial); +-static void option_release(struct usb_serial *serial); +-static int option_write_room(struct tty_struct *tty); +- ++static int option_send_setup(struct usb_serial_port *port); + static void option_instat_callback(struct urb *urb); + +-static int option_write(struct tty_struct *tty, struct usb_serial_port *port, +- const unsigned char *buf, int count); +-static int option_chars_in_buffer(struct tty_struct *tty); +-static void option_set_termios(struct tty_struct *tty, +- struct usb_serial_port *port, struct ktermios *old); +-static int option_tiocmget(struct tty_struct *tty, struct file *file); +-static int option_tiocmset(struct tty_struct *tty, struct file *file, +- unsigned int set, unsigned int clear); +-static int option_send_setup(struct usb_serial_port *port); +-#ifdef CONFIG_PM +-static int option_suspend(struct usb_serial *serial, pm_message_t message); +-static int option_resume(struct usb_serial *serial); +-#endif +- + /* Vendor and product IDs */ + #define OPTION_VENDOR_ID 0x0AF0 + #define OPTION_PRODUCT_COLT 0x5000 +@@ -677,22 +656,22 @@ static struct usb_serial_driver option_1 + .id_table = option_ids, + .num_ports = 1, + .probe = option_probe, +- .open = option_open, +- .close = option_close, +- .dtr_rts = option_dtr_rts, +- .write = option_write, +- .write_room = option_write_room, +- .chars_in_buffer = option_chars_in_buffer, +- .set_termios = option_set_termios, +- .tiocmget = option_tiocmget, +- .tiocmset = option_tiocmset, +- .attach = option_startup, +- .disconnect = option_disconnect, +- .release = option_release, ++ .open = usb_wwan_open, ++ .close = usb_wwan_close, ++ .dtr_rts = usb_wwan_dtr_rts, ++ .write = usb_wwan_write, ++ .write_room = usb_wwan_write_room, ++ .chars_in_buffer = usb_wwan_chars_in_buffer, ++ .set_termios = usb_wwan_set_termios, ++ .tiocmget = usb_wwan_tiocmget, ++ .tiocmset = usb_wwan_tiocmset, ++ .attach = usb_wwan_startup, ++ .disconnect = usb_wwan_disconnect, ++ .release = usb_wwan_release, + .read_int_callback = option_instat_callback, + #ifdef CONFIG_PM +- .suspend = option_suspend, +- .resume = option_resume, ++ .suspend = usb_wwan_suspend, ++ .resume = usb_wwan_resume, + #endif + }; + +@@ -705,12 +684,6 @@ static int debug; + #define IN_BUFLEN 4096 + #define OUT_BUFLEN 4096 + +-struct option_intf_private { +- spinlock_t susp_lock; +- unsigned int suspended:1; +- int in_flight; +-}; +- + struct option_port_private { + /* Input endpoints and buffer for this port */ + struct urb *in_urbs[N_IN_URB]; +@@ -767,223 +740,35 @@ module_exit(option_exit); + static int option_probe(struct usb_serial *serial, + const struct usb_device_id *id) + { +- struct option_intf_private *data; ++ struct usb_wwan_intf_private *data; + + /* D-Link DWM 652 still exposes CD-Rom emulation interface in modem mode */ + if (serial->dev->descriptor.idVendor == DLINK_VENDOR_ID && + serial->dev->descriptor.idProduct == DLINK_PRODUCT_DWM_652 && + serial->interface->cur_altsetting->desc.bInterfaceClass == 0x8) + return -ENODEV; + + /* Bandrich modem and AT command interface is 0xff */ + if ((serial->dev->descriptor.idVendor == BANDRICH_VENDOR_ID || + serial->dev->descriptor.idVendor == PIRELLI_VENDOR_ID) && + serial->interface->cur_altsetting->desc.bInterfaceClass != 0xff) + return -ENODEV; + + /* Don't bind network interfaces on Huawei K3765 & K4505 */ + if (serial->dev->descriptor.idVendor == HUAWEI_VENDOR_ID && + (serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K3765 || + serial->dev->descriptor.idProduct == HUAWEI_PRODUCT_K4505) && + serial->interface->cur_altsetting->desc.bInterfaceNumber == 1) + return -ENODEV; + +- data = serial->private = kzalloc(sizeof(struct option_intf_private), GFP_KERNEL); ++ data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), GFP_KERNEL); + if (!data) + return -ENOMEM; ++ data->send_setup = option_send_setup; + spin_lock_init(&data->susp_lock); + return 0; + } + +-static void option_set_termios(struct tty_struct *tty, +- struct usb_serial_port *port, struct ktermios *old_termios) +-{ +- dbg("%s", __func__); +- /* Doesn't support option setting */ +- tty_termios_copy_hw(tty->termios, old_termios); +- option_send_setup(port); +-} +- +-static int option_tiocmget(struct tty_struct *tty, struct file *file) +-{ +- struct usb_serial_port *port = tty->driver_data; +- unsigned int value; +- struct option_port_private *portdata; +- +- portdata = usb_get_serial_port_data(port); +- +- value = ((portdata->rts_state) ? TIOCM_RTS : 0) | +- ((portdata->dtr_state) ? TIOCM_DTR : 0) | +- ((portdata->cts_state) ? TIOCM_CTS : 0) | +- ((portdata->dsr_state) ? TIOCM_DSR : 0) | +- ((portdata->dcd_state) ? TIOCM_CAR : 0) | +- ((portdata->ri_state) ? TIOCM_RNG : 0); +- +- return value; +-} +- +-static int option_tiocmset(struct tty_struct *tty, struct file *file, +- unsigned int set, unsigned int clear) +-{ +- struct usb_serial_port *port = tty->driver_data; +- struct option_port_private *portdata; +- +- portdata = usb_get_serial_port_data(port); +- +- /* FIXME: what locks portdata fields ? */ +- if (set & TIOCM_RTS) +- portdata->rts_state = 1; +- if (set & TIOCM_DTR) +- portdata->dtr_state = 1; +- +- if (clear & TIOCM_RTS) +- portdata->rts_state = 0; +- if (clear & TIOCM_DTR) +- portdata->dtr_state = 0; +- return option_send_setup(port); +-} +- +-/* Write */ +-static int option_write(struct tty_struct *tty, struct usb_serial_port *port, +- const unsigned char *buf, int count) +-{ +- struct option_port_private *portdata; +- struct option_intf_private *intfdata; +- int i; +- int left, todo; +- struct urb *this_urb = NULL; /* spurious */ +- int err; +- unsigned long flags; +- +- portdata = usb_get_serial_port_data(port); +- intfdata = port->serial->private; +- +- dbg("%s: write (%d chars)", __func__, count); +- +- i = 0; +- left = count; +- for (i = 0; left > 0 && i < N_OUT_URB; i++) { +- todo = left; +- if (todo > OUT_BUFLEN) +- todo = OUT_BUFLEN; +- +- this_urb = portdata->out_urbs[i]; +- if (test_and_set_bit(i, &portdata->out_busy)) { +- if (time_before(jiffies, +- portdata->tx_start_time[i] + 10 * HZ)) +- continue; +- usb_unlink_urb(this_urb); +- continue; +- } +- dbg("%s: endpoint %d buf %d", __func__, +- usb_pipeendpoint(this_urb->pipe), i); +- +- err = usb_autopm_get_interface_async(port->serial->interface); +- if (err < 0) +- break; +- +- /* send the data */ +- memcpy(this_urb->transfer_buffer, buf, todo); +- this_urb->transfer_buffer_length = todo; +- +- spin_lock_irqsave(&intfdata->susp_lock, flags); +- if (intfdata->suspended) { +- usb_anchor_urb(this_urb, &portdata->delayed); +- spin_unlock_irqrestore(&intfdata->susp_lock, flags); +- } else { +- intfdata->in_flight++; +- spin_unlock_irqrestore(&intfdata->susp_lock, flags); +- err = usb_submit_urb(this_urb, GFP_ATOMIC); +- if (err) { +- dbg("usb_submit_urb %p (write bulk) failed " +- "(%d)", this_urb, err); +- clear_bit(i, &portdata->out_busy); +- spin_lock_irqsave(&intfdata->susp_lock, flags); +- intfdata->in_flight--; +- spin_unlock_irqrestore(&intfdata->susp_lock, flags); +- continue; +- } +- } +- +- portdata->tx_start_time[i] = jiffies; +- buf += todo; +- left -= todo; +- } +- +- count -= left; +- dbg("%s: wrote (did %d)", __func__, count); +- return count; +-} +- +-static void option_indat_callback(struct urb *urb) +-{ +- int err; +- int endpoint; +- struct usb_serial_port *port; +- struct tty_struct *tty; +- unsigned char *data = urb->transfer_buffer; +- int status = urb->status; +- +- dbg("%s: %p", __func__, urb); +- +- endpoint = usb_pipeendpoint(urb->pipe); +- port = urb->context; +- +- if (status) { +- dbg("%s: nonzero status: %d on endpoint %02x.", +- __func__, status, endpoint); +- } else { +- tty = tty_port_tty_get(&port->port); +- if (urb->actual_length) { +- tty_buffer_request_room(tty, urb->actual_length); +- tty_insert_flip_string(tty, data, urb->actual_length); +- tty_flip_buffer_push(tty); +- } else +- dbg("%s: empty read urb received", __func__); +- tty_kref_put(tty); +- +- /* Resubmit urb so we continue receiving */ +- if (port->port.count && status != -ESHUTDOWN) { +- err = usb_submit_urb(urb, GFP_ATOMIC); +- if (err) +- printk(KERN_ERR "%s: resubmit read urb failed. " +- "(%d)", __func__, err); +- else +- usb_mark_last_busy(port->serial->dev); +- } +- +- } +- return; +-} +- +-static void option_outdat_callback(struct urb *urb) +-{ +- struct usb_serial_port *port; +- struct option_port_private *portdata; +- struct option_intf_private *intfdata; +- int i; +- +- dbg("%s", __func__); +- +- port = urb->context; +- intfdata = port->serial->private; +- +- usb_serial_port_softint(port); +- usb_autopm_put_interface_async(port->serial->interface); +- portdata = usb_get_serial_port_data(port); +- spin_lock(&intfdata->susp_lock); +- intfdata->in_flight--; +- spin_unlock(&intfdata->susp_lock); +- +- for (i = 0; i < N_OUT_URB; ++i) { +- if (portdata->out_urbs[i] == urb) { +- smp_mb__before_clear_bit(); +- clear_bit(i, &portdata->out_busy); +- break; +- } +- } +-} +- + static void option_instat_callback(struct urb *urb) + { + int err; +@@ -1026,183 +811,6 @@ static void option_instat_callback(struc + } + } + +-static int option_write_room(struct tty_struct *tty) +-{ +- struct usb_serial_port *port = tty->driver_data; +- struct option_port_private *portdata; +- int i; +- int data_len = 0; +- struct urb *this_urb; +- +- portdata = usb_get_serial_port_data(port); +- +- for (i = 0; i < N_OUT_URB; i++) { +- this_urb = portdata->out_urbs[i]; +- if (this_urb && !test_bit(i, &portdata->out_busy)) +- data_len += OUT_BUFLEN; +- } +- +- dbg("%s: %d", __func__, data_len); +- return data_len; +-} +- +-static int option_chars_in_buffer(struct tty_struct *tty) +-{ +- struct usb_serial_port *port = tty->driver_data; +- struct option_port_private *portdata; +- int i; +- int data_len = 0; +- struct urb *this_urb; +- +- portdata = usb_get_serial_port_data(port); +- +- for (i = 0; i < N_OUT_URB; i++) { +- this_urb = portdata->out_urbs[i]; +- /* FIXME: This locking is insufficient as this_urb may +- go unused during the test */ +- if (this_urb && test_bit(i, &portdata->out_busy)) +- data_len += this_urb->transfer_buffer_length; +- } +- dbg("%s: %d", __func__, data_len); +- return data_len; +-} +- +-static int option_open(struct tty_struct *tty, struct usb_serial_port *port) +-{ +- struct option_port_private *portdata; +- struct option_intf_private *intfdata; +- struct usb_serial *serial = port->serial; +- int i, err; +- struct urb *urb; +- +- portdata = usb_get_serial_port_data(port); +- intfdata = serial->private; +- +- dbg("%s", __func__); +- +- /* Start reading from the IN endpoint */ +- for (i = 0; i < N_IN_URB; i++) { +- urb = portdata->in_urbs[i]; +- if (!urb) +- continue; +- err = usb_submit_urb(urb, GFP_KERNEL); +- if (err) { +- dbg("%s: submit urb %d failed (%d) %d", +- __func__, i, err, +- urb->transfer_buffer_length); +- } +- } +- +- option_send_setup(port); +- +- serial->interface->needs_remote_wakeup = 1; +- spin_lock_irq(&intfdata->susp_lock); +- portdata->opened = 1; +- spin_unlock_irq(&intfdata->susp_lock); +- usb_autopm_put_interface(serial->interface); +- +- return 0; +-} +- +-static void option_dtr_rts(struct usb_serial_port *port, int on) +-{ +- struct usb_serial *serial = port->serial; +- struct option_port_private *portdata; +- +- dbg("%s", __func__); +- portdata = usb_get_serial_port_data(port); +- mutex_lock(&serial->disc_mutex); +- portdata->rts_state = on; +- portdata->dtr_state = on; +- if (serial->dev) +- option_send_setup(port); +- mutex_unlock(&serial->disc_mutex); +-} +- +- +-static void option_close(struct usb_serial_port *port) +-{ +- int i; +- struct usb_serial *serial = port->serial; +- struct option_port_private *portdata; +- struct option_intf_private *intfdata = port->serial->private; +- +- dbg("%s", __func__); +- portdata = usb_get_serial_port_data(port); +- +- if (serial->dev) { +- /* Stop reading/writing urbs */ +- spin_lock_irq(&intfdata->susp_lock); +- portdata->opened = 0; +- spin_unlock_irq(&intfdata->susp_lock); +- +- for (i = 0; i < N_IN_URB; i++) +- usb_kill_urb(portdata->in_urbs[i]); +- for (i = 0; i < N_OUT_URB; i++) +- usb_kill_urb(portdata->out_urbs[i]); +- usb_autopm_get_interface(serial->interface); +- serial->interface->needs_remote_wakeup = 0; +- } +-} +- +-/* Helper functions used by option_setup_urbs */ +-static struct urb *option_setup_urb(struct usb_serial *serial, int endpoint, +- int dir, void *ctx, char *buf, int len, +- void (*callback)(struct urb *)) +-{ +- struct urb *urb; +- +- if (endpoint == -1) +- return NULL; /* endpoint not needed */ +- +- urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ +- if (urb == NULL) { +- dbg("%s: alloc for endpoint %d failed.", __func__, endpoint); +- return NULL; +- } +- +- /* Fill URB using supplied data. */ +- usb_fill_bulk_urb(urb, serial->dev, +- usb_sndbulkpipe(serial->dev, endpoint) | dir, +- buf, len, callback, ctx); +- +- return urb; +-} +- +-/* Setup urbs */ +-static void option_setup_urbs(struct usb_serial *serial) +-{ +- int i, j; +- struct usb_serial_port *port; +- struct option_port_private *portdata; +- +- dbg("%s", __func__); +- +- for (i = 0; i < serial->num_ports; i++) { +- port = serial->port[i]; +- portdata = usb_get_serial_port_data(port); +- +- /* Do indat endpoints first */ +- for (j = 0; j < N_IN_URB; ++j) { +- portdata->in_urbs[j] = option_setup_urb(serial, +- port->bulk_in_endpointAddress, +- USB_DIR_IN, port, +- portdata->in_buffer[j], +- IN_BUFLEN, option_indat_callback); +- } +- +- /* outdat endpoints */ +- for (j = 0; j < N_OUT_URB; ++j) { +- portdata->out_urbs[j] = option_setup_urb(serial, +- port->bulk_out_endpointAddress, +- USB_DIR_OUT, port, +- portdata->out_buffer[j], +- OUT_BUFLEN, option_outdat_callback); +- } +- } +-} +- +- + /** send RTS/DTR state to the port. + * + * This is exactly the same as SET_CONTROL_LINE_STATE from the PSTN +@@ -1228,224 +836,6 @@ static int option_send_setup(struct usb_ + 0x22, 0x21, val, ifNum, NULL, 0, USB_CTRL_SET_TIMEOUT); + } + +-static int option_startup(struct usb_serial *serial) +-{ +- int i, j, err; +- struct usb_serial_port *port; +- struct option_port_private *portdata; +- u8 *buffer; +- +- dbg("%s", __func__); +- +- /* Now setup per port private data */ +- for (i = 0; i < serial->num_ports; i++) { +- port = serial->port[i]; +- portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); +- if (!portdata) { +- dbg("%s: kmalloc for option_port_private (%d) failed!.", +- __func__, i); +- return 1; +- } +- init_usb_anchor(&portdata->delayed); +- +- for (j = 0; j < N_IN_URB; j++) { +- buffer = (u8 *)__get_free_page(GFP_KERNEL); +- if (!buffer) +- goto bail_out_error; +- portdata->in_buffer[j] = buffer; +- } +- +- for (j = 0; j < N_OUT_URB; j++) { +- buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL); +- if (!buffer) +- goto bail_out_error2; +- portdata->out_buffer[j] = buffer; +- } +- +- usb_set_serial_port_data(port, portdata); +- +- if (!port->interrupt_in_urb) +- continue; +- err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); +- if (err) +- dbg("%s: submit irq_in urb failed %d", +- __func__, err); +- } +- option_setup_urbs(serial); +- return 0; +- +-bail_out_error2: +- for (j = 0; j < N_OUT_URB; j++) +- kfree(portdata->out_buffer[j]); +-bail_out_error: +- for (j = 0; j < N_IN_URB; j++) +- if (portdata->in_buffer[j]) +- free_page((unsigned long)portdata->in_buffer[j]); +- kfree(portdata); +- return 1; +-} +- +-static void stop_read_write_urbs(struct usb_serial *serial) +-{ +- int i, j; +- struct usb_serial_port *port; +- struct option_port_private *portdata; +- +- /* Stop reading/writing urbs */ +- for (i = 0; i < serial->num_ports; ++i) { +- port = serial->port[i]; +- portdata = usb_get_serial_port_data(port); +- for (j = 0; j < N_IN_URB; j++) +- usb_kill_urb(portdata->in_urbs[j]); +- for (j = 0; j < N_OUT_URB; j++) +- usb_kill_urb(portdata->out_urbs[j]); +- } +-} +- +-static void option_disconnect(struct usb_serial *serial) +-{ +- dbg("%s", __func__); +- +- stop_read_write_urbs(serial); +-} +- +-static void option_release(struct usb_serial *serial) +-{ +- int i, j; +- struct usb_serial_port *port; +- struct option_port_private *portdata; +- +- dbg("%s", __func__); +- +- /* Now free them */ +- for (i = 0; i < serial->num_ports; ++i) { +- port = serial->port[i]; +- portdata = usb_get_serial_port_data(port); +- +- for (j = 0; j < N_IN_URB; j++) { +- if (portdata->in_urbs[j]) { +- usb_free_urb(portdata->in_urbs[j]); +- free_page((unsigned long) +- portdata->in_buffer[j]); +- portdata->in_urbs[j] = NULL; +- } +- } +- for (j = 0; j < N_OUT_URB; j++) { +- if (portdata->out_urbs[j]) { +- usb_free_urb(portdata->out_urbs[j]); +- kfree(portdata->out_buffer[j]); +- portdata->out_urbs[j] = NULL; +- } +- } +- } +- +- /* Now free per port private data */ +- for (i = 0; i < serial->num_ports; i++) { +- port = serial->port[i]; +- kfree(usb_get_serial_port_data(port)); +- } +-} +- +-#ifdef CONFIG_PM +-static int option_suspend(struct usb_serial *serial, pm_message_t message) +-{ +- struct option_intf_private *intfdata = serial->private; +- int b; +- +- dbg("%s entered", __func__); +- +- if (message.event & PM_EVENT_AUTO) { +- spin_lock_irq(&intfdata->susp_lock); +- b = intfdata->in_flight; +- spin_unlock_irq(&intfdata->susp_lock); +- +- if (b) +- return -EBUSY; +- } +- +- spin_lock_irq(&intfdata->susp_lock); +- intfdata->suspended = 1; +- spin_unlock_irq(&intfdata->susp_lock); +- stop_read_write_urbs(serial); +- +- return 0; +-} +- +-static void play_delayed(struct usb_serial_port *port) +-{ +- struct option_intf_private *data; +- struct option_port_private *portdata; +- struct urb *urb; +- int err; +- +- portdata = usb_get_serial_port_data(port); +- data = port->serial->private; +- while ((urb = usb_get_from_anchor(&portdata->delayed))) { +- err = usb_submit_urb(urb, GFP_ATOMIC); +- if (!err) +- data->in_flight++; +- } +-} +- +-static int option_resume(struct usb_serial *serial) +-{ +- int i, j; +- struct usb_serial_port *port; +- struct option_intf_private *intfdata = serial->private; +- struct option_port_private *portdata; +- struct urb *urb; +- int err = 0; +- +- dbg("%s entered", __func__); +- /* get the interrupt URBs resubmitted unconditionally */ +- for (i = 0; i < serial->num_ports; i++) { +- port = serial->port[i]; +- if (!port->interrupt_in_urb) { +- dbg("%s: No interrupt URB for port %d\n", __func__, i); +- continue; +- } +- err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO); +- dbg("Submitted interrupt URB for port %d (result %d)", i, err); +- if (err < 0) { +- err("%s: Error %d for interrupt URB of port%d", +- __func__, err, i); +- goto err_out; +- } +- } +- +- for (i = 0; i < serial->num_ports; i++) { +- /* walk all ports */ +- port = serial->port[i]; +- portdata = usb_get_serial_port_data(port); +- +- /* skip closed ports */ +- spin_lock_irq(&intfdata->susp_lock); +- if (!portdata->opened) { +- spin_unlock_irq(&intfdata->susp_lock); +- continue; +- } +- +- for (j = 0; j < N_IN_URB; j++) { +- urb = portdata->in_urbs[j]; +- err = usb_submit_urb(urb, GFP_ATOMIC); +- if (err < 0) { +- err("%s: Error %d for bulk URB %d", +- __func__, err, i); +- spin_unlock_irq(&intfdata->susp_lock); +- goto err_out; +- } +- } +- play_delayed(port); +- spin_unlock_irq(&intfdata->susp_lock); +- } +- spin_lock_irq(&intfdata->susp_lock); +- intfdata->suspended = 0; +- spin_unlock_irq(&intfdata->susp_lock); +-err_out: +- return err; +-} +-#endif +- + MODULE_AUTHOR(DRIVER_AUTHOR); + MODULE_DESCRIPTION(DRIVER_DESC); + MODULE_VERSION(DRIVER_VERSION); +diff -up linux-2.6.33.noarch/drivers/usb/serial/qcserial.c.orig linux-2.6.33.noarch/drivers/usb/serial/qcserial.c +--- linux-2.6.33.noarch/drivers/usb/serial/qcserial.c.orig 2010-04-01 12:38:39.954019769 -0400 ++++ linux-2.6.33.noarch/drivers/usb/serial/qcserial.c 2010-04-01 12:41:29.346996823 -0400 +@@ -15,13 +15,14 @@ + #include + #include + #include ++#include "usb-wwan.h" + + #define DRIVER_AUTHOR "Qualcomm Inc" + #define DRIVER_DESC "Qualcomm USB Serial driver" + + static int debug; + +-static struct usb_device_id id_table[] = { ++static const struct usb_device_id id_table[] = { + {USB_DEVICE(0x05c6, 0x9211)}, /* Acer Gobi QDL device */ + {USB_DEVICE(0x05c6, 0x9212)}, /* Acer Gobi Modem Device */ + {USB_DEVICE(0x03f0, 0x1f1d)}, /* HP un2400 Gobi Modem Device */ +@@ -47,6 +48,37 @@ static struct usb_device_id id_table[] = + {USB_DEVICE(0x05c6, 0x9221)}, /* Generic Gobi QDL device */ + {USB_DEVICE(0x05c6, 0x9231)}, /* Generic Gobi QDL device */ + {USB_DEVICE(0x1f45, 0x0001)}, /* Unknown Gobi QDL device */ ++ {USB_DEVICE(0x413c, 0x8185)}, /* Dell Gobi 2000 QDL device (N0218, VU936) */ ++ {USB_DEVICE(0x413c, 0x8186)}, /* Dell Gobi 2000 Modem device (N0218, VU936) */ ++ {USB_DEVICE(0x05c6, 0x9224)}, /* Sony Gobi 2000 QDL device (N0279, VU730) */ ++ {USB_DEVICE(0x05c6, 0x9225)}, /* Sony Gobi 2000 Modem device (N0279, VU730) */ ++ {USB_DEVICE(0x05c6, 0x9244)}, /* Samsung Gobi 2000 QDL device (VL176) */ ++ {USB_DEVICE(0x05c6, 0x9245)}, /* Samsung Gobi 2000 Modem device (VL176) */ ++ {USB_DEVICE(0x03f0, 0x241d)}, /* HP Gobi 2000 QDL device (VP412) */ ++ {USB_DEVICE(0x03f0, 0x251d)}, /* HP Gobi 2000 Modem device (VP412) */ ++ {USB_DEVICE(0x05c6, 0x9214)}, /* Acer Gobi 2000 QDL device (VP413) */ ++ {USB_DEVICE(0x05c6, 0x9215)}, /* Acer Gobi 2000 Modem device (VP413) */ ++ {USB_DEVICE(0x05c6, 0x9264)}, /* Asus Gobi 2000 QDL device (VR305) */ ++ {USB_DEVICE(0x05c6, 0x9265)}, /* Asus Gobi 2000 Modem device (VR305) */ ++ {USB_DEVICE(0x05c6, 0x9234)}, /* Top Global Gobi 2000 QDL device (VR306) */ ++ {USB_DEVICE(0x05c6, 0x9235)}, /* Top Global Gobi 2000 Modem device (VR306) */ ++ {USB_DEVICE(0x05c6, 0x9274)}, /* iRex Technologies Gobi 2000 QDL device (VR307) */ ++ {USB_DEVICE(0x05c6, 0x9275)}, /* iRex Technologies Gobi 2000 Modem device (VR307) */ ++ {USB_DEVICE(0x1199, 0x9000)}, /* Sierra Wireless Gobi 2000 QDL device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9001)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9002)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9003)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9004)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9005)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9006)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9007)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9008)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x9009)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x1199, 0x900a)}, /* Sierra Wireless Gobi 2000 Modem device (VT773) */ ++ {USB_DEVICE(0x16d8, 0x8001)}, /* CMDTech Gobi 2000 QDL device (VU922) */ ++ {USB_DEVICE(0x16d8, 0x8002)}, /* CMDTech Gobi 2000 Modem device (VU922) */ ++ {USB_DEVICE(0x05c6, 0x9204)}, /* Gobi 2000 QDL device */ ++ {USB_DEVICE(0x05c6, 0x9205)}, /* Gobi 2000 Modem device */ + { } /* Terminating entry */ + }; + MODULE_DEVICE_TABLE(usb, id_table); +@@ -63,6 +95,8 @@ static struct usb_driver qcdriver = { + + static int qcprobe(struct usb_serial *serial, const struct usb_device_id *id) + { ++ struct usb_wwan_intf_private *data; ++ struct usb_host_interface *intf = serial->interface->cur_altsetting; + int retval = -ENODEV; + __u8 nintf; + __u8 ifnum; +@@ -71,33 +105,45 @@ static int qcprobe(struct usb_serial *se + + nintf = serial->dev->actconfig->desc.bNumInterfaces; + dbg("Num Interfaces = %d", nintf); +- ifnum = serial->interface->cur_altsetting->desc.bInterfaceNumber; ++ ifnum = intf->desc.bInterfaceNumber; + dbg("This Interface = %d", ifnum); + ++ data = serial->private = kzalloc(sizeof(struct usb_wwan_intf_private), ++ GFP_KERNEL); ++ if (!data) ++ return -ENOMEM; ++ ++ spin_lock_init(&data->susp_lock); ++ + switch (nintf) { + case 1: + /* QDL mode */ +- if (serial->interface->num_altsetting == 2) { +- struct usb_host_interface *intf; +- ++ /* Gobi 2000 has a single altsetting, older ones have two */ ++ if (serial->interface->num_altsetting == 2) + intf = &serial->interface->altsetting[1]; +- if (intf->desc.bNumEndpoints == 2) { +- if (usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) && +- usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) { +- dbg("QDL port found"); +- retval = usb_set_interface(serial->dev, ifnum, 1); +- if (retval < 0) { +- dev_err(&serial->dev->dev, +- "Could not set interface, error %d\n", +- retval); +- retval = -ENODEV; +- } +- return retval; +- } ++ else if (serial->interface->num_altsetting > 2) ++ break; ++ ++ if (intf->desc.bNumEndpoints == 2 && ++ usb_endpoint_is_bulk_in(&intf->endpoint[0].desc) && ++ usb_endpoint_is_bulk_out(&intf->endpoint[1].desc)) { ++ dbg("QDL port found"); ++ ++ if (serial->interface->num_altsetting == 1) ++ return 0; ++ ++ retval = usb_set_interface(serial->dev, ifnum, 1); ++ if (retval < 0) { ++ dev_err(&serial->dev->dev, ++ "Could not set interface, error %d\n", ++ retval); ++ retval = -ENODEV; + } ++ return retval; + } + break; + ++ case 3: + case 4: + /* Composite mode */ + if (ifnum == 2) { +@@ -132,6 +178,18 @@ static struct usb_serial_driver qcdevice + .usb_driver = &qcdriver, + .num_ports = 1, + .probe = qcprobe, ++ .open = usb_wwan_open, ++ .close = usb_wwan_close, ++ .write = usb_wwan_write, ++ .write_room = usb_wwan_write_room, ++ .chars_in_buffer = usb_wwan_chars_in_buffer, ++ .attach = usb_wwan_startup, ++ .disconnect = usb_wwan_disconnect, ++ .release = usb_wwan_release, ++#ifdef CONFIG_PM ++ .suspend = usb_wwan_suspend, ++ .resume = usb_wwan_resume, ++#endif + }; + + static int __init qcinit(void) +diff -up linux-2.6.33.noarch/drivers/usb/serial/usb_wwan.c.orig linux-2.6.33.noarch/drivers/usb/serial/usb_wwan.c +--- linux-2.6.33.noarch/drivers/usb/serial/usb_wwan.c.orig 2010-04-01 12:39:41.531121118 -0400 ++++ linux-2.6.33.noarch/drivers/usb/serial/usb_wwan.c 2010-04-01 12:39:41.531121118 -0400 +@@ -0,0 +1,665 @@ ++/* ++ USB Driver layer for GSM modems ++ ++ Copyright (C) 2005 Matthias Urlichs ++ ++ This driver is free software; you can redistribute it and/or modify ++ it under the terms of Version 2 of the GNU General Public License as ++ published by the Free Software Foundation. ++ ++ Portions copied from the Keyspan driver by Hugh Blemings ++ ++ History: see the git log. ++ ++ Work sponsored by: Sigos GmbH, Germany ++ ++ This driver exists because the "normal" serial driver doesn't work too well ++ with GSM modems. Issues: ++ - data loss -- one single Receive URB is not nearly enough ++ - controlling the baud rate doesn't make sense ++*/ ++ ++#define DRIVER_VERSION "v0.7.2" ++#define DRIVER_AUTHOR "Matthias Urlichs " ++#define DRIVER_DESC "USB Driver for GSM modems" ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include "usb-wwan.h" ++ ++static int debug; ++ ++void usb_wwan_dtr_rts(struct usb_serial_port *port, int on) ++{ ++ struct usb_serial *serial = port->serial; ++ struct usb_wwan_port_private *portdata; ++ ++ struct usb_wwan_intf_private *intfdata; ++ ++ dbg("%s", __func__); ++ ++ intfdata = port->serial->private; ++ ++ if (!intfdata->send_setup) ++ return; ++ ++ portdata = usb_get_serial_port_data(port); ++ mutex_lock(&serial->disc_mutex); ++ portdata->rts_state = on; ++ portdata->dtr_state = on; ++ if (serial->dev) ++ intfdata->send_setup(port); ++ mutex_unlock(&serial->disc_mutex); ++} ++EXPORT_SYMBOL(usb_wwan_dtr_rts); ++ ++void usb_wwan_set_termios(struct tty_struct *tty, ++ struct usb_serial_port *port, ++ struct ktermios *old_termios) ++{ ++ struct usb_wwan_intf_private *intfdata = port->serial->private; ++ ++ dbg("%s", __func__); ++ ++ /* Doesn't support option setting */ ++ tty_termios_copy_hw(tty->termios, old_termios); ++ ++ if (intfdata->send_setup) ++ intfdata->send_setup(port); ++} ++EXPORT_SYMBOL(usb_wwan_set_termios); ++ ++int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file) ++{ ++ struct usb_serial_port *port = tty->driver_data; ++ unsigned int value; ++ struct usb_wwan_port_private *portdata; ++ ++ portdata = usb_get_serial_port_data(port); ++ ++ value = ((portdata->rts_state) ? TIOCM_RTS : 0) | ++ ((portdata->dtr_state) ? TIOCM_DTR : 0) | ++ ((portdata->cts_state) ? TIOCM_CTS : 0) | ++ ((portdata->dsr_state) ? TIOCM_DSR : 0) | ++ ((portdata->dcd_state) ? TIOCM_CAR : 0) | ++ ((portdata->ri_state) ? TIOCM_RNG : 0); ++ ++ return value; ++} ++EXPORT_SYMBOL(usb_wwan_tiocmget); ++ ++int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file, ++ unsigned int set, unsigned int clear) ++{ ++ struct usb_serial_port *port = tty->driver_data; ++ struct usb_wwan_port_private *portdata; ++ struct usb_wwan_intf_private *intfdata; ++ ++ portdata = usb_get_serial_port_data(port); ++ intfdata = port->serial->private; ++ ++ if (!intfdata->send_setup) ++ return -EINVAL; ++ ++ /* FIXME: what locks portdata fields ? */ ++ if (set & TIOCM_RTS) ++ portdata->rts_state = 1; ++ if (set & TIOCM_DTR) ++ portdata->dtr_state = 1; ++ ++ if (clear & TIOCM_RTS) ++ portdata->rts_state = 0; ++ if (clear & TIOCM_DTR) ++ portdata->dtr_state = 0; ++ return intfdata->send_setup(port); ++} ++EXPORT_SYMBOL(usb_wwan_tiocmset); ++ ++/* Write */ ++int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, ++ const unsigned char *buf, int count) ++{ ++ struct usb_wwan_port_private *portdata; ++ struct usb_wwan_intf_private *intfdata; ++ int i; ++ int left, todo; ++ struct urb *this_urb = NULL; /* spurious */ ++ int err; ++ unsigned long flags; ++ ++ portdata = usb_get_serial_port_data(port); ++ intfdata = port->serial->private; ++ ++ dbg("%s: write (%d chars)", __func__, count); ++ ++ i = 0; ++ left = count; ++ for (i = 0; left > 0 && i < N_OUT_URB; i++) { ++ todo = left; ++ if (todo > OUT_BUFLEN) ++ todo = OUT_BUFLEN; ++ ++ this_urb = portdata->out_urbs[i]; ++ if (test_and_set_bit(i, &portdata->out_busy)) { ++ if (time_before(jiffies, ++ portdata->tx_start_time[i] + 10 * HZ)) ++ continue; ++ usb_unlink_urb(this_urb); ++ continue; ++ } ++ dbg("%s: endpoint %d buf %d", __func__, ++ usb_pipeendpoint(this_urb->pipe), i); ++ ++ err = usb_autopm_get_interface_async(port->serial->interface); ++ if (err < 0) ++ break; ++ ++ /* send the data */ ++ memcpy(this_urb->transfer_buffer, buf, todo); ++ this_urb->transfer_buffer_length = todo; ++ ++ spin_lock_irqsave(&intfdata->susp_lock, flags); ++ if (intfdata->suspended) { ++ usb_anchor_urb(this_urb, &portdata->delayed); ++ spin_unlock_irqrestore(&intfdata->susp_lock, flags); ++ } else { ++ intfdata->in_flight++; ++ spin_unlock_irqrestore(&intfdata->susp_lock, flags); ++ err = usb_submit_urb(this_urb, GFP_ATOMIC); ++ if (err) { ++ dbg("usb_submit_urb %p (write bulk) failed " ++ "(%d)", this_urb, err); ++ clear_bit(i, &portdata->out_busy); ++ spin_lock_irqsave(&intfdata->susp_lock, flags); ++ intfdata->in_flight--; ++ spin_unlock_irqrestore(&intfdata->susp_lock, ++ flags); ++ continue; ++ } ++ } ++ ++ portdata->tx_start_time[i] = jiffies; ++ buf += todo; ++ left -= todo; ++ } ++ ++ count -= left; ++ dbg("%s: wrote (did %d)", __func__, count); ++ return count; ++} ++EXPORT_SYMBOL(usb_wwan_write); ++ ++static void usb_wwan_indat_callback(struct urb *urb) ++{ ++ int err; ++ int endpoint; ++ struct usb_serial_port *port; ++ struct tty_struct *tty; ++ unsigned char *data = urb->transfer_buffer; ++ int status = urb->status; ++ ++ dbg("%s: %p", __func__, urb); ++ ++ endpoint = usb_pipeendpoint(urb->pipe); ++ port = urb->context; ++ ++ if (status) { ++ dbg("%s: nonzero status: %d on endpoint %02x.", ++ __func__, status, endpoint); ++ } else { ++ tty = tty_port_tty_get(&port->port); ++ if (urb->actual_length) { ++ tty_buffer_request_room(tty, urb->actual_length); ++ tty_insert_flip_string(tty, data, urb->actual_length); ++ tty_flip_buffer_push(tty); ++ } else ++ dbg("%s: empty read urb received", __func__); ++ tty_kref_put(tty); ++ ++ /* Resubmit urb so we continue receiving */ ++ if (port->port.count && status != -ESHUTDOWN) { ++ err = usb_submit_urb(urb, GFP_ATOMIC); ++ if (err) ++ printk(KERN_ERR "%s: resubmit read urb failed. " ++ "(%d)", __func__, err); ++ else ++ usb_mark_last_busy(port->serial->dev); ++ } ++ ++ } ++ return; ++} ++ ++static void usb_wwan_outdat_callback(struct urb *urb) ++{ ++ struct usb_serial_port *port; ++ struct usb_wwan_port_private *portdata; ++ struct usb_wwan_intf_private *intfdata; ++ int i; ++ ++ dbg("%s", __func__); ++ ++ port = urb->context; ++ intfdata = port->serial->private; ++ ++ usb_serial_port_softint(port); ++ usb_autopm_put_interface_async(port->serial->interface); ++ portdata = usb_get_serial_port_data(port); ++ spin_lock(&intfdata->susp_lock); ++ intfdata->in_flight--; ++ spin_unlock(&intfdata->susp_lock); ++ ++ for (i = 0; i < N_OUT_URB; ++i) { ++ if (portdata->out_urbs[i] == urb) { ++ smp_mb__before_clear_bit(); ++ clear_bit(i, &portdata->out_busy); ++ break; ++ } ++ } ++} ++ ++int usb_wwan_write_room(struct tty_struct *tty) ++{ ++ struct usb_serial_port *port = tty->driver_data; ++ struct usb_wwan_port_private *portdata; ++ int i; ++ int data_len = 0; ++ struct urb *this_urb; ++ ++ portdata = usb_get_serial_port_data(port); ++ ++ for (i = 0; i < N_OUT_URB; i++) { ++ this_urb = portdata->out_urbs[i]; ++ if (this_urb && !test_bit(i, &portdata->out_busy)) ++ data_len += OUT_BUFLEN; ++ } ++ ++ dbg("%s: %d", __func__, data_len); ++ return data_len; ++} ++EXPORT_SYMBOL(usb_wwan_write_room); ++ ++int usb_wwan_chars_in_buffer(struct tty_struct *tty) ++{ ++ struct usb_serial_port *port = tty->driver_data; ++ struct usb_wwan_port_private *portdata; ++ int i; ++ int data_len = 0; ++ struct urb *this_urb; ++ ++ portdata = usb_get_serial_port_data(port); ++ ++ for (i = 0; i < N_OUT_URB; i++) { ++ this_urb = portdata->out_urbs[i]; ++ /* FIXME: This locking is insufficient as this_urb may ++ go unused during the test */ ++ if (this_urb && test_bit(i, &portdata->out_busy)) ++ data_len += this_urb->transfer_buffer_length; ++ } ++ dbg("%s: %d", __func__, data_len); ++ return data_len; ++} ++EXPORT_SYMBOL(usb_wwan_chars_in_buffer); ++ ++int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port) ++{ ++ struct usb_wwan_port_private *portdata; ++ struct usb_wwan_intf_private *intfdata; ++ struct usb_serial *serial = port->serial; ++ int i, err; ++ struct urb *urb; ++ ++ portdata = usb_get_serial_port_data(port); ++ intfdata = serial->private; ++ ++ dbg("%s", __func__); ++ ++ /* Start reading from the IN endpoint */ ++ for (i = 0; i < N_IN_URB; i++) { ++ urb = portdata->in_urbs[i]; ++ if (!urb) ++ continue; ++ err = usb_submit_urb(urb, GFP_KERNEL); ++ if (err) { ++ dbg("%s: submit urb %d failed (%d) %d", ++ __func__, i, err, urb->transfer_buffer_length); ++ } ++ } ++ ++ if (intfdata->send_setup) ++ intfdata->send_setup(port); ++ ++ serial->interface->needs_remote_wakeup = 1; ++ spin_lock_irq(&intfdata->susp_lock); ++ portdata->opened = 1; ++ spin_unlock_irq(&intfdata->susp_lock); ++ usb_autopm_put_interface(serial->interface); ++ ++ return 0; ++} ++EXPORT_SYMBOL(usb_wwan_open); ++ ++void usb_wwan_close(struct usb_serial_port *port) ++{ ++ int i; ++ struct usb_serial *serial = port->serial; ++ struct usb_wwan_port_private *portdata; ++ struct usb_wwan_intf_private *intfdata = port->serial->private; ++ ++ dbg("%s", __func__); ++ portdata = usb_get_serial_port_data(port); ++ ++ if (serial->dev) { ++ /* Stop reading/writing urbs */ ++ spin_lock_irq(&intfdata->susp_lock); ++ portdata->opened = 0; ++ spin_unlock_irq(&intfdata->susp_lock); ++ ++ for (i = 0; i < N_IN_URB; i++) ++ usb_kill_urb(portdata->in_urbs[i]); ++ for (i = 0; i < N_OUT_URB; i++) ++ usb_kill_urb(portdata->out_urbs[i]); ++ usb_autopm_get_interface(serial->interface); ++ serial->interface->needs_remote_wakeup = 0; ++ } ++} ++EXPORT_SYMBOL(usb_wwan_close); ++ ++/* Helper functions used by usb_wwan_setup_urbs */ ++static struct urb *usb_wwan_setup_urb(struct usb_serial *serial, int endpoint, ++ int dir, void *ctx, char *buf, int len, ++ void (*callback) (struct urb *)) ++{ ++ struct urb *urb; ++ ++ if (endpoint == -1) ++ return NULL; /* endpoint not needed */ ++ ++ urb = usb_alloc_urb(0, GFP_KERNEL); /* No ISO */ ++ if (urb == NULL) { ++ dbg("%s: alloc for endpoint %d failed.", __func__, endpoint); ++ return NULL; ++ } ++ ++ /* Fill URB using supplied data. */ ++ usb_fill_bulk_urb(urb, serial->dev, ++ usb_sndbulkpipe(serial->dev, endpoint) | dir, ++ buf, len, callback, ctx); ++ ++ return urb; ++} ++ ++/* Setup urbs */ ++static void usb_wwan_setup_urbs(struct usb_serial *serial) ++{ ++ int i, j; ++ struct usb_serial_port *port; ++ struct usb_wwan_port_private *portdata; ++ ++ dbg("%s", __func__); ++ ++ for (i = 0; i < serial->num_ports; i++) { ++ port = serial->port[i]; ++ portdata = usb_get_serial_port_data(port); ++ ++ /* Do indat endpoints first */ ++ for (j = 0; j < N_IN_URB; ++j) { ++ portdata->in_urbs[j] = usb_wwan_setup_urb(serial, ++ port-> ++ bulk_in_endpointAddress, ++ USB_DIR_IN, ++ port, ++ portdata-> ++ in_buffer[j], ++ IN_BUFLEN, ++ usb_wwan_indat_callback); ++ } ++ ++ /* outdat endpoints */ ++ for (j = 0; j < N_OUT_URB; ++j) { ++ portdata->out_urbs[j] = usb_wwan_setup_urb(serial, ++ port-> ++ bulk_out_endpointAddress, ++ USB_DIR_OUT, ++ port, ++ portdata-> ++ out_buffer ++ [j], ++ OUT_BUFLEN, ++ usb_wwan_outdat_callback); ++ } ++ } ++} ++ ++int usb_wwan_startup(struct usb_serial *serial) ++{ ++ int i, j, err; ++ struct usb_serial_port *port; ++ struct usb_wwan_port_private *portdata; ++ u8 *buffer; ++ ++ dbg("%s", __func__); ++ ++ /* Now setup per port private data */ ++ for (i = 0; i < serial->num_ports; i++) { ++ port = serial->port[i]; ++ portdata = kzalloc(sizeof(*portdata), GFP_KERNEL); ++ if (!portdata) { ++ dbg("%s: kmalloc for usb_wwan_port_private (%d) failed!.", ++ __func__, i); ++ return 1; ++ } ++ init_usb_anchor(&portdata->delayed); ++ ++ for (j = 0; j < N_IN_URB; j++) { ++ buffer = (u8 *) __get_free_page(GFP_KERNEL); ++ if (!buffer) ++ goto bail_out_error; ++ portdata->in_buffer[j] = buffer; ++ } ++ ++ for (j = 0; j < N_OUT_URB; j++) { ++ buffer = kmalloc(OUT_BUFLEN, GFP_KERNEL); ++ if (!buffer) ++ goto bail_out_error2; ++ portdata->out_buffer[j] = buffer; ++ } ++ ++ usb_set_serial_port_data(port, portdata); ++ ++ if (!port->interrupt_in_urb) ++ continue; ++ err = usb_submit_urb(port->interrupt_in_urb, GFP_KERNEL); ++ if (err) ++ dbg("%s: submit irq_in urb failed %d", __func__, err); ++ } ++ usb_wwan_setup_urbs(serial); ++ return 0; ++ ++bail_out_error2: ++ for (j = 0; j < N_OUT_URB; j++) ++ kfree(portdata->out_buffer[j]); ++bail_out_error: ++ for (j = 0; j < N_IN_URB; j++) ++ if (portdata->in_buffer[j]) ++ free_page((unsigned long)portdata->in_buffer[j]); ++ kfree(portdata); ++ return 1; ++} ++EXPORT_SYMBOL(usb_wwan_startup); ++ ++static void stop_read_write_urbs(struct usb_serial *serial) ++{ ++ int i, j; ++ struct usb_serial_port *port; ++ struct usb_wwan_port_private *portdata; ++ ++ /* Stop reading/writing urbs */ ++ for (i = 0; i < serial->num_ports; ++i) { ++ port = serial->port[i]; ++ portdata = usb_get_serial_port_data(port); ++ for (j = 0; j < N_IN_URB; j++) ++ usb_kill_urb(portdata->in_urbs[j]); ++ for (j = 0; j < N_OUT_URB; j++) ++ usb_kill_urb(portdata->out_urbs[j]); ++ } ++} ++ ++void usb_wwan_disconnect(struct usb_serial *serial) ++{ ++ dbg("%s", __func__); ++ ++ stop_read_write_urbs(serial); ++} ++EXPORT_SYMBOL(usb_wwan_disconnect); ++ ++void usb_wwan_release(struct usb_serial *serial) ++{ ++ int i, j; ++ struct usb_serial_port *port; ++ struct usb_wwan_port_private *portdata; ++ ++ dbg("%s", __func__); ++ ++ /* Now free them */ ++ for (i = 0; i < serial->num_ports; ++i) { ++ port = serial->port[i]; ++ portdata = usb_get_serial_port_data(port); ++ ++ for (j = 0; j < N_IN_URB; j++) { ++ usb_free_urb(portdata->in_urbs[j]); ++ free_page((unsigned long) ++ portdata->in_buffer[j]); ++ portdata->in_urbs[j] = NULL; ++ } ++ for (j = 0; j < N_OUT_URB; j++) { ++ usb_free_urb(portdata->out_urbs[j]); ++ kfree(portdata->out_buffer[j]); ++ portdata->out_urbs[j] = NULL; ++ } ++ } ++ ++ /* Now free per port private data */ ++ for (i = 0; i < serial->num_ports; i++) { ++ port = serial->port[i]; ++ kfree(usb_get_serial_port_data(port)); ++ } ++} ++EXPORT_SYMBOL(usb_wwan_release); ++ ++#ifdef CONFIG_PM ++int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message) ++{ ++ struct usb_wwan_intf_private *intfdata = serial->private; ++ int b; ++ ++ dbg("%s entered", __func__); ++ ++ if (message.event & PM_EVENT_AUTO) { ++ spin_lock_irq(&intfdata->susp_lock); ++ b = intfdata->in_flight; ++ spin_unlock_irq(&intfdata->susp_lock); ++ ++ if (b) ++ return -EBUSY; ++ } ++ ++ spin_lock_irq(&intfdata->susp_lock); ++ intfdata->suspended = 1; ++ spin_unlock_irq(&intfdata->susp_lock); ++ stop_read_write_urbs(serial); ++ ++ return 0; ++} ++EXPORT_SYMBOL(usb_wwan_suspend); ++ ++static void play_delayed(struct usb_serial_port *port) ++{ ++ struct usb_wwan_intf_private *data; ++ struct usb_wwan_port_private *portdata; ++ struct urb *urb; ++ int err; ++ ++ portdata = usb_get_serial_port_data(port); ++ data = port->serial->private; ++ while ((urb = usb_get_from_anchor(&portdata->delayed))) { ++ err = usb_submit_urb(urb, GFP_ATOMIC); ++ if (!err) ++ data->in_flight++; ++ } ++} ++ ++int usb_wwan_resume(struct usb_serial *serial) ++{ ++ int i, j; ++ struct usb_serial_port *port; ++ struct usb_wwan_intf_private *intfdata = serial->private; ++ struct usb_wwan_port_private *portdata; ++ struct urb *urb; ++ int err = 0; ++ ++ dbg("%s entered", __func__); ++ /* get the interrupt URBs resubmitted unconditionally */ ++ for (i = 0; i < serial->num_ports; i++) { ++ port = serial->port[i]; ++ if (!port->interrupt_in_urb) { ++ dbg("%s: No interrupt URB for port %d\n", __func__, i); ++ continue; ++ } ++ err = usb_submit_urb(port->interrupt_in_urb, GFP_NOIO); ++ dbg("Submitted interrupt URB for port %d (result %d)", i, err); ++ if (err < 0) { ++ err("%s: Error %d for interrupt URB of port%d", ++ __func__, err, i); ++ goto err_out; ++ } ++ } ++ ++ for (i = 0; i < serial->num_ports; i++) { ++ /* walk all ports */ ++ port = serial->port[i]; ++ portdata = usb_get_serial_port_data(port); ++ ++ /* skip closed ports */ ++ spin_lock_irq(&intfdata->susp_lock); ++ if (!portdata->opened) { ++ spin_unlock_irq(&intfdata->susp_lock); ++ continue; ++ } ++ ++ for (j = 0; j < N_IN_URB; j++) { ++ urb = portdata->in_urbs[j]; ++ err = usb_submit_urb(urb, GFP_ATOMIC); ++ if (err < 0) { ++ err("%s: Error %d for bulk URB %d", ++ __func__, err, i); ++ spin_unlock_irq(&intfdata->susp_lock); ++ goto err_out; ++ } ++ } ++ play_delayed(port); ++ spin_unlock_irq(&intfdata->susp_lock); ++ } ++ spin_lock_irq(&intfdata->susp_lock); ++ intfdata->suspended = 0; ++ spin_unlock_irq(&intfdata->susp_lock); ++err_out: ++ return err; ++} ++EXPORT_SYMBOL(usb_wwan_resume); ++#endif ++ ++MODULE_AUTHOR(DRIVER_AUTHOR); ++MODULE_DESCRIPTION(DRIVER_DESC); ++MODULE_VERSION(DRIVER_VERSION); ++MODULE_LICENSE("GPL"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Debug messages"); +diff -up linux-2.6.33.noarch/drivers/usb/serial/usb-wwan.h.orig linux-2.6.33.noarch/drivers/usb/serial/usb-wwan.h +--- linux-2.6.33.noarch/drivers/usb/serial/usb-wwan.h.orig 2010-04-01 12:42:23.050997135 -0400 ++++ linux-2.6.33.noarch/drivers/usb/serial/usb-wwan.h 2010-04-01 12:42:19.341996684 -0400 +@@ -0,0 +1,66 @@ ++/* ++ * Definitions for USB serial mobile broadband cards ++ */ ++ ++#ifndef __LINUX_USB_USB_WWAN ++#define __LINUX_USB_USB_WWAN ++ ++extern void usb_wwan_dtr_rts(struct usb_serial_port *port, int on); ++extern int usb_wwan_open(struct tty_struct *tty, struct usb_serial_port *port); ++extern void usb_wwan_close(struct usb_serial_port *port); ++extern int usb_wwan_startup(struct usb_serial *serial); ++extern void usb_wwan_disconnect(struct usb_serial *serial); ++extern void usb_wwan_release(struct usb_serial *serial); ++extern int usb_wwan_write_room(struct tty_struct *tty); ++extern void usb_wwan_set_termios(struct tty_struct *tty, ++ struct usb_serial_port *port, ++ struct ktermios *old); ++extern int usb_wwan_tiocmget(struct tty_struct *tty, struct file *file); ++extern int usb_wwan_tiocmset(struct tty_struct *tty, struct file *file, ++ unsigned int set, unsigned int clear); ++extern int usb_wwan_send_setup(struct usb_serial_port *port); ++extern int usb_wwan_write(struct tty_struct *tty, struct usb_serial_port *port, ++ const unsigned char *buf, int count); ++extern int usb_wwan_chars_in_buffer(struct tty_struct *tty); ++#ifdef CONFIG_PM ++extern int usb_wwan_suspend(struct usb_serial *serial, pm_message_t message); ++extern int usb_wwan_resume(struct usb_serial *serial); ++#endif ++ ++/* per port private data */ ++ ++#define N_IN_URB 4 ++#define N_OUT_URB 4 ++#define IN_BUFLEN 4096 ++#define OUT_BUFLEN 4096 ++ ++struct usb_wwan_intf_private { ++ spinlock_t susp_lock; ++ unsigned int suspended:1; ++ int in_flight; ++ int (*send_setup) (struct usb_serial_port *port); ++}; ++ ++struct usb_wwan_port_private { ++ /* Input endpoints and buffer for this port */ ++ struct urb *in_urbs[N_IN_URB]; ++ u8 *in_buffer[N_IN_URB]; ++ /* Output endpoints and buffer for this port */ ++ struct urb *out_urbs[N_OUT_URB]; ++ u8 *out_buffer[N_OUT_URB]; ++ unsigned long out_busy; /* Bit vector of URBs in use */ ++ int opened; ++ struct usb_anchor delayed; ++ ++ /* Settings for the port */ ++ int rts_state; /* Handshaking pins (outputs) */ ++ int dtr_state; ++ int cts_state; /* Handshaking pins (inputs) */ ++ int dsr_state; ++ int dcd_state; ++ int ri_state; ++ ++ unsigned long tx_start_time[N_OUT_URB]; ++}; ++ ++#endif /* __LINUX_USB_USB_WWAN */ diff --git a/linux-2.6-utrace-ptrace.patch b/linux-2.6-utrace-ptrace.patch new file mode 100644 index 000000000..3771682d6 --- /dev/null +++ b/linux-2.6-utrace-ptrace.patch @@ -0,0 +1,1825 @@ +implement utrace-ptrace + +The patch adds the new file, kernel/ptrace-utrace.c, which contains +the new implementation of ptrace over utrace. + +This file is not compiled until we have CONFIG_UTRACE option, will be +added by the next "utrace core" patch. + +It's supposed to be an invisible implementation change, nothing should +change to userland when CONFIG_UTRACE is enabled. + +Signed-off-by: Roland McGrath +Signed-off-by: Oleg Nesterov +--- + include/linux/ptrace.h | 2 +- + kernel/Makefile | 1 + + kernel/ptrace-utrace.c | 1080 ++++++++++++++++++++++++++++++++++++++++++++++++ + kernel/ptrace.c | 572 +++++++++++++------------- + kernel/utrace.c | 16 + + 5 files changed, 1378 insertions(+), 293 deletions(-) + +diff --git a/include/linux/ptrace.h b/include/linux/ptrace.h +index 4802e2a..03f8fc7 100644 +--- a/include/linux/ptrace.h ++++ b/include/linux/ptrace.h +@@ -79,7 +79,7 @@ + #include /* For unlikely. */ + #include /* For struct task_struct. */ + +- ++extern void ptrace_notify_stop(struct task_struct *tracee); + extern long arch_ptrace(struct task_struct *child, long request, long addr, long data); + extern int ptrace_traceme(void); + extern int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len); +diff --git a/kernel/Makefile b/kernel/Makefile +index 8a0185e..30a118d 100644 +--- a/kernel/Makefile ++++ b/kernel/Makefile +@@ -70,6 +70,7 @@ obj-$(CONFIG_RESOURCE_COUNTERS) += res_c + obj-$(CONFIG_STOP_MACHINE) += stop_machine.o + obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o + obj-$(CONFIG_UTRACE) += utrace.o ++obj-$(CONFIG_UTRACE) += ptrace-utrace.o + obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o + obj-$(CONFIG_AUDITSYSCALL) += auditsc.o + obj-$(CONFIG_GCOV_KERNEL) += gcov/ +diff --git a/kernel/ptrace-utrace.c b/kernel/ptrace-utrace.c +new file mode 100644 +index ...ea419ee 100644 +--- /dev/null ++++ b/kernel/ptrace-utrace.c +@@ -0,0 +1,1080 @@ ++/* ++ * linux/kernel/ptrace.c ++ * ++ * (C) Copyright 1999 Linus Torvalds ++ * ++ * Common interfaces for "ptrace()" which we do not want ++ * to continually duplicate across every architecture. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++/* ++ * ptrace a task: make the debugger its new parent and ++ * move it to the ptrace list. ++ * ++ * Must be called with the tasklist lock write-held. ++ */ ++void __ptrace_link(struct task_struct *child, struct task_struct *new_parent) ++{ ++ BUG_ON(!list_empty(&child->ptrace_entry)); ++ list_add(&child->ptrace_entry, &new_parent->ptraced); ++ child->parent = new_parent; ++} ++ ++/* ++ * unptrace a task: move it back to its original parent and ++ * remove it from the ptrace list. ++ * ++ * Must be called with the tasklist lock write-held. ++ */ ++void __ptrace_unlink(struct task_struct *child) ++{ ++ BUG_ON(!child->ptrace); ++ ++ child->ptrace = 0; ++ child->parent = child->real_parent; ++ list_del_init(&child->ptrace_entry); ++ ++ arch_ptrace_untrace(child); ++} ++ ++struct ptrace_context { ++ int options; ++ ++ int signr; ++ siginfo_t *siginfo; ++ ++ int stop_code; ++ unsigned long eventmsg; ++ ++ enum utrace_resume_action resume; ++}; ++ ++#define PT_UTRACED 0x00001000 ++ ++#define PTRACE_O_SYSEMU 0x100 ++ ++#define PTRACE_EVENT_SYSCALL (1 << 16) ++#define PTRACE_EVENT_SIGTRAP (2 << 16) ++#define PTRACE_EVENT_SIGNAL (3 << 16) ++/* events visible to user-space */ ++#define PTRACE_EVENT_MASK 0xFFFF ++ ++static inline bool ptrace_event_pending(struct ptrace_context *ctx) ++{ ++ return ctx->stop_code != 0; ++} ++ ++static inline int get_stop_event(struct ptrace_context *ctx) ++{ ++ return ctx->stop_code >> 8; ++} ++ ++static inline void set_stop_code(struct ptrace_context *ctx, int event) ++{ ++ ctx->stop_code = (event << 8) | SIGTRAP; ++} ++ ++static inline struct ptrace_context * ++ptrace_context(struct utrace_engine *engine) ++{ ++ return engine->data; ++} ++ ++static const struct utrace_engine_ops ptrace_utrace_ops; /* forward decl */ ++ ++static struct utrace_engine *ptrace_lookup_engine(struct task_struct *tracee) ++{ ++ return utrace_attach_task(tracee, UTRACE_ATTACH_MATCH_OPS, ++ &ptrace_utrace_ops, NULL); ++} ++ ++static struct utrace_engine * ++ptrace_reuse_engine(struct task_struct *tracee) ++{ ++ struct utrace_engine *engine; ++ struct ptrace_context *ctx; ++ int err = -EPERM; ++ ++ engine = ptrace_lookup_engine(tracee); ++ if (IS_ERR(engine)) ++ return engine; ++ ++ ctx = ptrace_context(engine); ++ if (unlikely(ctx->resume == UTRACE_DETACH)) { ++ /* ++ * Try to reuse this self-detaching engine. ++ * The only caller which can hit this case is ptrace_attach(), ++ * it holds ->cred_guard_mutex. ++ */ ++ ctx->options = 0; ++ ctx->eventmsg = 0; ++ ++ /* make sure we don't get unwanted reports */ ++ err = utrace_set_events(tracee, engine, UTRACE_EVENT(QUIESCE)); ++ if (!err || err == -EINPROGRESS) { ++ ctx->resume = UTRACE_RESUME; ++ /* synchronize with ptrace_report_signal() */ ++ err = utrace_barrier(tracee, engine); ++ } ++ WARN_ON(!err != (engine->ops == &ptrace_utrace_ops)); ++ ++ if (!err) ++ return engine; ++ } ++ ++ utrace_engine_put(engine); ++ return ERR_PTR(err); ++} ++ ++static struct utrace_engine * ++ptrace_attach_engine(struct task_struct *tracee) ++{ ++ struct utrace_engine *engine; ++ struct ptrace_context *ctx; ++ ++ if (unlikely(task_utrace_flags(tracee))) { ++ engine = ptrace_reuse_engine(tracee); ++ if (!IS_ERR(engine) || IS_ERR(engine) == -EPERM) ++ return engine; ++ } ++ ++ ctx = kzalloc(sizeof(*ctx), GFP_KERNEL); ++ if (unlikely(!ctx)) ++ return ERR_PTR(-ENOMEM); ++ ++ ctx->resume = UTRACE_RESUME; ++ ++ engine = utrace_attach_task(tracee, UTRACE_ATTACH_CREATE | ++ UTRACE_ATTACH_EXCLUSIVE | ++ UTRACE_ATTACH_MATCH_OPS, ++ &ptrace_utrace_ops, ctx); ++ if (unlikely(IS_ERR(engine))) { ++ if (engine != ERR_PTR(-ESRCH) && ++ engine != ERR_PTR(-ERESTARTNOINTR)) ++ engine = ERR_PTR(-EPERM); ++ kfree(ctx); ++ } ++ ++ return engine; ++} ++ ++static inline int ptrace_set_events(struct task_struct *target, ++ struct utrace_engine *engine, ++ unsigned long options) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ /* ++ * We need QUIESCE for resume handling, CLONE to check ++ * for CLONE_PTRACE, other events are always reported. ++ */ ++ unsigned long events = UTRACE_EVENT(QUIESCE) | UTRACE_EVENT(CLONE) | ++ UTRACE_EVENT(EXEC) | UTRACE_EVENT_SIGNAL_ALL; ++ ++ ctx->options = options; ++ if (options & PTRACE_O_TRACEEXIT) ++ events |= UTRACE_EVENT(EXIT); ++ ++ return utrace_set_events(target, engine, events); ++} ++ ++/* ++ * Attach a utrace engine for ptrace and set up its event mask. ++ * Returns error code or 0 on success. ++ */ ++static int ptrace_attach_task(struct task_struct *tracee, int options) ++{ ++ struct utrace_engine *engine; ++ int err; ++ ++ engine = ptrace_attach_engine(tracee); ++ if (IS_ERR(engine)) ++ return PTR_ERR(engine); ++ /* ++ * It can fail only if the tracee is dead, the caller ++ * must notice this before setting PT_UTRACED. ++ */ ++ err = ptrace_set_events(tracee, engine, options); ++ WARN_ON(err && !tracee->exit_state); ++ utrace_engine_put(engine); ++ return 0; ++} ++ ++static int ptrace_wake_up(struct task_struct *tracee, ++ struct utrace_engine *engine, ++ enum utrace_resume_action action, ++ bool force_wakeup) ++{ ++ if (force_wakeup) { ++ unsigned long flags; ++ /* ++ * Preserve the compatibility bug. Historically ptrace ++ * wakes up the tracee even if it should not. Clear ++ * SIGNAL_STOP_STOPPED for utrace_wakeup(). ++ */ ++ if (lock_task_sighand(tracee, &flags)) { ++ tracee->signal->flags &= ~SIGNAL_STOP_STOPPED; ++ unlock_task_sighand(tracee, &flags); ++ } ++ } ++ ++ if (action != UTRACE_REPORT) ++ ptrace_context(engine)->stop_code = 0; ++ ++ return utrace_control(tracee, engine, action); ++} ++ ++static void ptrace_detach_task(struct task_struct *tracee, int sig) ++{ ++ /* ++ * If true, the caller is PTRACE_DETACH, otherwise ++ * the tracer detaches implicitly during exit. ++ */ ++ bool voluntary = (sig >= 0); ++ struct utrace_engine *engine = ptrace_lookup_engine(tracee); ++ enum utrace_resume_action action = UTRACE_DETACH; ++ ++ if (unlikely(IS_ERR(engine))) ++ return; ++ ++ if (sig) { ++ struct ptrace_context *ctx = ptrace_context(engine); ++ ++ switch (get_stop_event(ctx)) { ++ case PTRACE_EVENT_SYSCALL: ++ if (voluntary) ++ send_sig_info(sig, SEND_SIG_PRIV, tracee); ++ break; ++ ++ case PTRACE_EVENT_SIGNAL: ++ if (voluntary) ++ ctx->signr = sig; ++ ctx->resume = UTRACE_DETACH; ++ action = UTRACE_RESUME; ++ break; ++ } ++ } ++ ++ ptrace_wake_up(tracee, engine, action, voluntary); ++ utrace_engine_put(engine); ++} ++ ++static void ptrace_abort_attach(struct task_struct *tracee) ++{ ++ ptrace_detach_task(tracee, 0); ++} ++ ++static u32 ptrace_report_exit(u32 action, struct utrace_engine *engine, ++ long orig_code, long *code) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ ++ WARN_ON(ptrace_event_pending(ctx) && ++ !signal_group_exit(current->signal)); ++ ++ set_stop_code(ctx, PTRACE_EVENT_EXIT); ++ ctx->eventmsg = *code; ++ ++ return UTRACE_STOP; ++} ++ ++static void ptrace_clone_attach(struct task_struct *child, ++ int options) ++{ ++ struct task_struct *parent = current; ++ struct task_struct *tracer; ++ bool abort = true; ++ ++ if (unlikely(ptrace_attach_task(child, options))) { ++ WARN_ON(1); ++ return; ++ } ++ ++ write_lock_irq(&tasklist_lock); ++ tracer = parent->parent; ++ if (!(tracer->flags & PF_EXITING) && parent->ptrace) { ++ child->ptrace = parent->ptrace; ++ __ptrace_link(child, tracer); ++ abort = false; ++ } ++ write_unlock_irq(&tasklist_lock); ++ if (unlikely(abort)) { ++ ptrace_abort_attach(child); ++ return; ++ } ++ ++ sigaddset(&child->pending.signal, SIGSTOP); ++ set_tsk_thread_flag(child, TIF_SIGPENDING); ++} ++ ++static u32 ptrace_report_clone(u32 action, struct utrace_engine *engine, ++ unsigned long clone_flags, ++ struct task_struct *child) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ int event = 0; ++ ++ WARN_ON(ptrace_event_pending(ctx)); ++ ++ if (clone_flags & CLONE_UNTRACED) { ++ /* no events reported */ ++ } else if (clone_flags & CLONE_VFORK) { ++ if (ctx->options & PTRACE_O_TRACEVFORK) ++ event = PTRACE_EVENT_VFORK; ++ else if (ctx->options & PTRACE_O_TRACEVFORKDONE) ++ event = PTRACE_EVENT_VFORK_DONE; ++ } else if ((clone_flags & CSIGNAL) != SIGCHLD) { ++ if (ctx->options & PTRACE_O_TRACECLONE) ++ event = PTRACE_EVENT_CLONE; ++ } else if (ctx->options & PTRACE_O_TRACEFORK) { ++ event = PTRACE_EVENT_FORK; ++ } ++ /* ++ * Any of these reports implies auto-attaching the new child. ++ * So does CLONE_PTRACE, even with no event to report. ++ */ ++ if ((event && event != PTRACE_EVENT_VFORK_DONE) || ++ (clone_flags & CLONE_PTRACE)) ++ ptrace_clone_attach(child, ctx->options); ++ ++ if (!event) ++ return UTRACE_RESUME; ++ ++ set_stop_code(ctx, event); ++ ctx->eventmsg = child->pid; ++ /* ++ * We shouldn't stop now, inside the do_fork() path. ++ * We will stop later, before return to user-mode. ++ */ ++ if (event == PTRACE_EVENT_VFORK_DONE) ++ return UTRACE_REPORT; ++ else ++ return UTRACE_STOP; ++} ++ ++static inline void set_syscall_code(struct ptrace_context *ctx) ++{ ++ set_stop_code(ctx, PTRACE_EVENT_SYSCALL); ++ if (ctx->options & PTRACE_O_TRACESYSGOOD) ++ ctx->stop_code |= 0x80; ++} ++ ++static u32 ptrace_report_syscall_entry(u32 action, struct utrace_engine *engine, ++ struct pt_regs *regs) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ ++ if (action & UTRACE_SYSCALL_RESUMED) { ++ /* ++ * We already reported the first time. ++ * Nothing more to do now. ++ */ ++ if (unlikely(ctx->options & PTRACE_O_SYSEMU)) ++ return UTRACE_SYSCALL_ABORT | UTRACE_REPORT; ++ return utrace_syscall_action(action) | UTRACE_RESUME; ++ } ++ ++ WARN_ON(ptrace_event_pending(ctx)); ++ ++ set_syscall_code(ctx); ++ ++ if (unlikely(ctx->options & PTRACE_O_SYSEMU)) ++ return UTRACE_SYSCALL_ABORT | UTRACE_REPORT; ++ /* ++ * Stop now to report. We will get another callback after ++ * we resume, with the UTRACE_SYSCALL_RESUMED flag set. ++ */ ++ return UTRACE_SYSCALL_RUN | UTRACE_STOP; ++} ++ ++static u32 ptrace_report_syscall_exit(u32 action, struct utrace_engine *engine, ++ struct pt_regs *regs) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ ++ if (ptrace_event_pending(ctx)) ++ return UTRACE_STOP; ++ ++ if (ctx->resume != UTRACE_RESUME) { ++ WARN_ON(ctx->resume != UTRACE_BLOCKSTEP && ++ ctx->resume != UTRACE_SINGLESTEP); ++ ctx->resume = UTRACE_RESUME; ++ ++ ctx->signr = SIGTRAP; ++ return UTRACE_INTERRUPT; ++ } ++ ++ set_syscall_code(ctx); ++ return UTRACE_STOP; ++} ++ ++static u32 ptrace_report_exec(u32 action, struct utrace_engine *engine, ++ const struct linux_binfmt *fmt, ++ const struct linux_binprm *bprm, ++ struct pt_regs *regs) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ ++ WARN_ON(ptrace_event_pending(ctx)); ++ ++ if (!(ctx->options & PTRACE_O_TRACEEXEC)) { ++ /* ++ * Old-fashioned ptrace'd exec just posts a plain signal. ++ */ ++ send_sig(SIGTRAP, current, 0); ++ return UTRACE_RESUME; ++ } ++ ++ set_stop_code(ctx, PTRACE_EVENT_EXEC); ++ return UTRACE_STOP; ++} ++ ++static enum utrace_signal_action resume_signal(struct ptrace_context *ctx, ++ struct k_sigaction *return_ka) ++{ ++ siginfo_t *info = ctx->siginfo; ++ int signr = ctx->signr; ++ ++ ctx->siginfo = NULL; ++ ctx->signr = 0; ++ ++ /* Did the debugger cancel the sig? */ ++ if (!signr) ++ return UTRACE_SIGNAL_IGN; ++ /* ++ * Update the siginfo structure if the signal has changed. ++ * If the debugger wanted something specific in the siginfo ++ * then it should have updated *info via PTRACE_SETSIGINFO. ++ */ ++ if (info->si_signo != signr) { ++ info->si_signo = signr; ++ info->si_errno = 0; ++ info->si_code = SI_USER; ++ info->si_pid = task_pid_vnr(current->parent); ++ info->si_uid = task_uid(current->parent); ++ } ++ ++ /* If the (new) signal is now blocked, requeue it. */ ++ if (sigismember(¤t->blocked, signr)) { ++ send_sig_info(signr, info, current); ++ return UTRACE_SIGNAL_IGN; ++ } ++ ++ spin_lock_irq(¤t->sighand->siglock); ++ *return_ka = current->sighand->action[signr - 1]; ++ spin_unlock_irq(¤t->sighand->siglock); ++ ++ return UTRACE_SIGNAL_DELIVER; ++} ++ ++static u32 ptrace_report_signal(u32 action, struct utrace_engine *engine, ++ struct pt_regs *regs, ++ siginfo_t *info, ++ const struct k_sigaction *orig_ka, ++ struct k_sigaction *return_ka) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ enum utrace_resume_action resume = ctx->resume; ++ ++ if (ptrace_event_pending(ctx)) { ++ action = utrace_signal_action(action); ++ WARN_ON(action != UTRACE_SIGNAL_REPORT); ++ return action | UTRACE_STOP; ++ } ++ ++ switch (utrace_signal_action(action)) { ++ case UTRACE_SIGNAL_HANDLER: ++ if (WARN_ON(ctx->siginfo)) ++ ctx->siginfo = NULL; ++ ++ if (resume != UTRACE_RESUME) { ++ WARN_ON(resume != UTRACE_BLOCKSTEP && ++ resume != UTRACE_SINGLESTEP); ++ ++ set_stop_code(ctx, PTRACE_EVENT_SIGTRAP); ++ return UTRACE_STOP | UTRACE_SIGNAL_IGN; ++ } ++ ++ case UTRACE_SIGNAL_REPORT: ++ if (!ctx->siginfo) { ++ if (ctx->signr) { ++ /* set by ptrace_resume(SYSCALL_EXIT) */ ++ WARN_ON(ctx->signr != SIGTRAP); ++ user_single_step_siginfo(current, regs, info); ++ force_sig_info(SIGTRAP, info, current); ++ } ++ ++ return resume | UTRACE_SIGNAL_IGN; ++ } ++ ++ if (WARN_ON(ctx->siginfo != info)) ++ return resume | UTRACE_SIGNAL_IGN; ++ ++ return resume | resume_signal(ctx, return_ka); ++ ++ default: ++ break; ++ } ++ ++ WARN_ON(ctx->siginfo); ++ ctx->siginfo = info; ++ /* ++ * ctx->siginfo points to the caller's stack. ++ * Make sure the subsequent UTRACE_SIGNAL_REPORT clears ++ * ->siginfo before return from get_signal_to_deliver(). ++ */ ++ if (utrace_control(current, engine, UTRACE_INTERRUPT)) ++ WARN_ON(1); ++ ++ ctx->signr = info->si_signo; ++ ctx->stop_code = (PTRACE_EVENT_SIGNAL << 8) | ctx->signr; ++ ++ return UTRACE_STOP | UTRACE_SIGNAL_IGN; ++} ++ ++static u32 ptrace_report_quiesce(u32 action, struct utrace_engine *engine, ++ unsigned long event) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ ++ if (ptrace_event_pending(ctx)) ++ return UTRACE_STOP; ++ ++ return event ? UTRACE_RESUME : ctx->resume; ++} ++ ++static void ptrace_release(void *data) ++{ ++ kfree(data); ++} ++ ++static const struct utrace_engine_ops ptrace_utrace_ops = { ++ .report_signal = ptrace_report_signal, ++ .report_quiesce = ptrace_report_quiesce, ++ .report_exec = ptrace_report_exec, ++ .report_exit = ptrace_report_exit, ++ .report_clone = ptrace_report_clone, ++ .report_syscall_entry = ptrace_report_syscall_entry, ++ .report_syscall_exit = ptrace_report_syscall_exit, ++ .release = ptrace_release, ++}; ++ ++int ptrace_check_attach(struct task_struct *child, int kill) ++{ ++ struct utrace_engine *engine; ++ struct utrace_examiner exam; ++ int ret = -ESRCH; ++ ++ engine = ptrace_lookup_engine(child); ++ if (IS_ERR(engine)) ++ return ret; ++ ++ if (child->parent != current) ++ goto out; ++ ++ if (unlikely(kill)) ++ ret = 0; ++ ++ if (!task_is_stopped_or_traced(child)) ++ goto out; ++ /* ++ * Make sure our engine has already stopped the child. ++ * Then wait for it to be off the CPU. ++ */ ++ if (!utrace_control(child, engine, UTRACE_STOP) && ++ !utrace_prepare_examine(child, engine, &exam)) ++ ret = 0; ++out: ++ utrace_engine_put(engine); ++ return ret; ++} ++ ++int ptrace_attach(struct task_struct *task) ++{ ++ int retval; ++ ++ audit_ptrace(task); ++ ++ retval = -EPERM; ++ if (unlikely(task->flags & PF_KTHREAD)) ++ goto out; ++ if (same_thread_group(task, current)) ++ goto out; ++ ++ /* ++ * Protect exec's credential calculations against our interference; ++ * interference; SUID, SGID and LSM creds get determined differently ++ * under ptrace. ++ */ ++ retval = -ERESTARTNOINTR; ++ if (mutex_lock_interruptible(&task->cred_guard_mutex)) ++ goto out; ++ ++ task_lock(task); ++ retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH); ++ task_unlock(task); ++ if (retval) ++ goto unlock_creds; ++ ++ retval = ptrace_attach_task(task, 0); ++ if (unlikely(retval)) ++ goto unlock_creds; ++ ++ write_lock_irq(&tasklist_lock); ++ retval = -EPERM; ++ if (unlikely(task->exit_state)) ++ goto unlock_tasklist; ++ ++ BUG_ON(task->ptrace); ++ task->ptrace = PT_UTRACED; ++ if (capable(CAP_SYS_PTRACE)) ++ task->ptrace |= PT_PTRACE_CAP; ++ ++ __ptrace_link(task, current); ++ send_sig_info(SIGSTOP, SEND_SIG_FORCED, task); ++ ++ retval = 0; ++unlock_tasklist: ++ write_unlock_irq(&tasklist_lock); ++unlock_creds: ++ mutex_unlock(&task->cred_guard_mutex); ++out: ++ return retval; ++} ++ ++/* ++ * Performs checks and sets PT_UTRACED. ++ * Should be used by all ptrace implementations for PTRACE_TRACEME. ++ */ ++int ptrace_traceme(void) ++{ ++ bool detach = true; ++ int ret = ptrace_attach_task(current, 0); ++ ++ if (unlikely(ret)) ++ return ret; ++ ++ ret = -EPERM; ++ write_lock_irq(&tasklist_lock); ++ BUG_ON(current->ptrace); ++ ret = security_ptrace_traceme(current->parent); ++ /* ++ * Check PF_EXITING to ensure ->real_parent has not passed ++ * exit_ptrace(). Otherwise we don't report the error but ++ * pretend ->real_parent untraces us right after return. ++ */ ++ if (!ret && !(current->real_parent->flags & PF_EXITING)) { ++ current->ptrace = PT_UTRACED; ++ __ptrace_link(current, current->real_parent); ++ detach = false; ++ } ++ write_unlock_irq(&tasklist_lock); ++ ++ if (detach) ++ ptrace_abort_attach(current); ++ return ret; ++} ++ ++static void ptrace_do_detach(struct task_struct *tracee, unsigned int data) ++{ ++ bool detach, release; ++ ++ write_lock_irq(&tasklist_lock); ++ /* ++ * This tracee can be already killed. Make sure de_thread() or ++ * our sub-thread doing do_wait() didn't do release_task() yet. ++ */ ++ detach = tracee->ptrace != 0; ++ release = false; ++ if (likely(detach)) ++ release = __ptrace_detach(current, tracee); ++ write_unlock_irq(&tasklist_lock); ++ ++ if (unlikely(release)) ++ release_task(tracee); ++ else if (likely(detach)) ++ ptrace_detach_task(tracee, data); ++} ++ ++int ptrace_detach(struct task_struct *child, unsigned int data) ++{ ++ if (!valid_signal(data)) ++ return -EIO; ++ ++ ptrace_do_detach(child, data); ++ ++ return 0; ++} ++ ++/* ++ * Detach all tasks we were using ptrace on. ++ */ ++void exit_ptrace(struct task_struct *tracer) ++{ ++ for (;;) { ++ struct task_struct *tracee = NULL; ++ ++ read_lock(&tasklist_lock); ++ if (!list_empty(&tracer->ptraced)) { ++ tracee = list_first_entry(&tracer->ptraced, ++ struct task_struct, ptrace_entry); ++ get_task_struct(tracee); ++ } ++ read_unlock(&tasklist_lock); ++ if (!tracee) ++ break; ++ ++ ptrace_do_detach(tracee, -1); ++ put_task_struct(tracee); ++ } ++} ++ ++static int ptrace_set_options(struct task_struct *tracee, ++ struct utrace_engine *engine, long data) ++{ ++ BUILD_BUG_ON(PTRACE_O_MASK & PTRACE_O_SYSEMU); ++ ++ ptrace_set_events(tracee, engine, data & PTRACE_O_MASK); ++ return (data & ~PTRACE_O_MASK) ? -EINVAL : 0; ++} ++ ++static int ptrace_rw_siginfo(struct task_struct *tracee, ++ struct ptrace_context *ctx, ++ siginfo_t *info, bool write) ++{ ++ unsigned long flags; ++ int err; ++ ++ switch (get_stop_event(ctx)) { ++ case 0: /* jctl stop */ ++ return -EINVAL; ++ ++ case PTRACE_EVENT_SIGNAL: ++ err = -ESRCH; ++ if (lock_task_sighand(tracee, &flags)) { ++ if (likely(task_is_traced(tracee))) { ++ if (write) ++ *ctx->siginfo = *info; ++ else ++ *info = *ctx->siginfo; ++ err = 0; ++ } ++ unlock_task_sighand(tracee, &flags); ++ } ++ ++ return err; ++ ++ default: ++ if (!write) { ++ memset(info, 0, sizeof(*info)); ++ info->si_signo = SIGTRAP; ++ info->si_code = ctx->stop_code & PTRACE_EVENT_MASK; ++ info->si_pid = task_pid_vnr(tracee); ++ info->si_uid = task_uid(tracee); ++ } ++ ++ return 0; ++ } ++} ++ ++static void do_ptrace_notify_stop(struct ptrace_context *ctx, ++ struct task_struct *tracee) ++{ ++ /* ++ * This can race with SIGKILL, but we borrow this race from ++ * the old ptrace implementation. ->exit_code is only needed ++ * for wait_task_stopped()->task_stopped_code(), we should ++ * change it to use ptrace_context. ++ */ ++ tracee->exit_code = ctx->stop_code & PTRACE_EVENT_MASK; ++ WARN_ON(!tracee->exit_code); ++ ++ read_lock(&tasklist_lock); ++ /* ++ * Don't want to allow preemption here, because ++ * sys_ptrace() needs this task to be inactive. ++ */ ++ preempt_disable(); ++ /* ++ * It can be killed and then released by our subthread, ++ * or ptrace_attach() has not completed yet. ++ */ ++ if (task_ptrace(tracee)) ++ do_notify_parent_cldstop(tracee, CLD_TRAPPED); ++ read_unlock(&tasklist_lock); ++ preempt_enable_no_resched(); ++} ++ ++void ptrace_notify_stop(struct task_struct *tracee) ++{ ++ struct utrace_engine *engine = ptrace_lookup_engine(tracee); ++ ++ if (IS_ERR(engine)) ++ return; ++ ++ do_ptrace_notify_stop(ptrace_context(engine), tracee); ++ utrace_engine_put(engine); ++} ++ ++static int ptrace_resume_action(struct task_struct *tracee, ++ struct utrace_engine *engine, long request) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ unsigned long events; ++ int action; ++ ++ ctx->options &= ~PTRACE_O_SYSEMU; ++ events = engine->flags & ~UTRACE_EVENT_SYSCALL; ++ action = UTRACE_RESUME; ++ ++ switch (request) { ++#ifdef PTRACE_SINGLEBLOCK ++ case PTRACE_SINGLEBLOCK: ++ if (unlikely(!arch_has_block_step())) ++ return -EIO; ++ action = UTRACE_BLOCKSTEP; ++ events |= UTRACE_EVENT(SYSCALL_EXIT); ++ break; ++#endif ++ ++#ifdef PTRACE_SINGLESTEP ++ case PTRACE_SINGLESTEP: ++ if (unlikely(!arch_has_single_step())) ++ return -EIO; ++ action = UTRACE_SINGLESTEP; ++ events |= UTRACE_EVENT(SYSCALL_EXIT); ++ break; ++#endif ++ ++#ifdef PTRACE_SYSEMU ++ case PTRACE_SYSEMU_SINGLESTEP: ++ if (unlikely(!arch_has_single_step())) ++ return -EIO; ++ action = UTRACE_SINGLESTEP; ++ case PTRACE_SYSEMU: ++ ctx->options |= PTRACE_O_SYSEMU; ++ events |= UTRACE_EVENT(SYSCALL_ENTRY); ++ break; ++#endif ++ ++ case PTRACE_SYSCALL: ++ events |= UTRACE_EVENT_SYSCALL; ++ break; ++ ++ case PTRACE_CONT: ++ break; ++ default: ++ return -EIO; ++ } ++ ++ if (events != engine->flags && ++ utrace_set_events(tracee, engine, events)) ++ return -ESRCH; ++ ++ return action; ++} ++ ++static int ptrace_resume(struct task_struct *tracee, ++ struct utrace_engine *engine, ++ long request, long data) ++{ ++ struct ptrace_context *ctx = ptrace_context(engine); ++ int action; ++ ++ if (!valid_signal(data)) ++ return -EIO; ++ ++ action = ptrace_resume_action(tracee, engine, request); ++ if (action < 0) ++ return action; ++ ++ switch (get_stop_event(ctx)) { ++ case PTRACE_EVENT_VFORK: ++ if (ctx->options & PTRACE_O_TRACEVFORKDONE) { ++ set_stop_code(ctx, PTRACE_EVENT_VFORK_DONE); ++ action = UTRACE_REPORT; ++ } ++ break; ++ ++ case PTRACE_EVENT_EXEC: ++ case PTRACE_EVENT_FORK: ++ case PTRACE_EVENT_CLONE: ++ case PTRACE_EVENT_VFORK_DONE: ++ if (request == PTRACE_SYSCALL) { ++ set_syscall_code(ctx); ++ do_ptrace_notify_stop(ctx, tracee); ++ return 0; ++ } ++ ++ if (action != UTRACE_RESUME) { ++ /* ++ * single-stepping. UTRACE_SIGNAL_REPORT will ++ * synthesize a trap to follow the syscall insn. ++ */ ++ ctx->signr = SIGTRAP; ++ action = UTRACE_INTERRUPT; ++ } ++ break; ++ ++ case PTRACE_EVENT_SYSCALL: ++ if (data) ++ send_sig_info(data, SEND_SIG_PRIV, tracee); ++ break; ++ ++ case PTRACE_EVENT_SIGNAL: ++ ctx->signr = data; ++ break; ++ } ++ ++ ctx->resume = action; ++ ptrace_wake_up(tracee, engine, action, true); ++ return 0; ++} ++ ++int ptrace_request(struct task_struct *child, long request, ++ long addr, long data) ++{ ++ struct utrace_engine *engine = ptrace_lookup_engine(child); ++ siginfo_t siginfo; ++ int ret; ++ ++ if (unlikely(IS_ERR(engine))) ++ return -ESRCH; ++ ++ switch (request) { ++ case PTRACE_PEEKTEXT: ++ case PTRACE_PEEKDATA: ++ ret = generic_ptrace_peekdata(child, addr, data); ++ break; ++ case PTRACE_POKETEXT: ++ case PTRACE_POKEDATA: ++ ret = generic_ptrace_pokedata(child, addr, data); ++ break; ++ ++#ifdef PTRACE_OLDSETOPTIONS ++ case PTRACE_OLDSETOPTIONS: ++#endif ++ case PTRACE_SETOPTIONS: ++ ret = ptrace_set_options(child, engine, data); ++ break; ++ case PTRACE_GETEVENTMSG: ++ ret = put_user(ptrace_context(engine)->eventmsg, ++ (unsigned long __user *) data); ++ break; ++ ++ case PTRACE_GETSIGINFO: ++ ret = ptrace_rw_siginfo(child, ptrace_context(engine), ++ &siginfo, false); ++ if (!ret) ++ ret = copy_siginfo_to_user((siginfo_t __user *) data, ++ &siginfo); ++ break; ++ ++ case PTRACE_SETSIGINFO: ++ if (copy_from_user(&siginfo, (siginfo_t __user *) data, ++ sizeof siginfo)) ++ ret = -EFAULT; ++ else ++ ret = ptrace_rw_siginfo(child, ptrace_context(engine), ++ &siginfo, true); ++ break; ++ ++ case PTRACE_DETACH: /* detach a process that was attached. */ ++ ret = ptrace_detach(child, data); ++ break; ++ ++ case PTRACE_KILL: ++ /* Ugly historical behaviour. */ ++ if (task_is_traced(child)) ++ ptrace_resume(child, engine, PTRACE_CONT, SIGKILL); ++ ret = 0; ++ break; ++ ++ default: ++ ret = ptrace_resume(child, engine, request, data); ++ break; ++ } ++ ++ utrace_engine_put(engine); ++ return ret; ++} ++ ++#if defined CONFIG_COMPAT ++#include ++ ++int compat_ptrace_request(struct task_struct *child, compat_long_t request, ++ compat_ulong_t addr, compat_ulong_t data) ++{ ++ struct utrace_engine *engine = ptrace_lookup_engine(child); ++ compat_ulong_t __user *datap = compat_ptr(data); ++ compat_ulong_t word; ++ siginfo_t siginfo; ++ int ret; ++ ++ if (unlikely(IS_ERR(engine))) ++ return -ESRCH; ++ ++ switch (request) { ++ case PTRACE_PEEKTEXT: ++ case PTRACE_PEEKDATA: ++ ret = access_process_vm(child, addr, &word, sizeof(word), 0); ++ if (ret != sizeof(word)) ++ ret = -EIO; ++ else ++ ret = put_user(word, datap); ++ break; ++ ++ case PTRACE_POKETEXT: ++ case PTRACE_POKEDATA: ++ ret = access_process_vm(child, addr, &data, sizeof(data), 1); ++ ret = (ret != sizeof(data) ? -EIO : 0); ++ break; ++ ++ case PTRACE_GETEVENTMSG: ++ ret = put_user((compat_ulong_t)ptrace_context(engine)->eventmsg, ++ datap); ++ break; ++ ++ case PTRACE_GETSIGINFO: ++ ret = ptrace_rw_siginfo(child, ptrace_context(engine), ++ &siginfo, false); ++ if (!ret) ++ ret = copy_siginfo_to_user32( ++ (struct compat_siginfo __user *) datap, ++ &siginfo); ++ break; ++ ++ case PTRACE_SETSIGINFO: ++ memset(&siginfo, 0, sizeof siginfo); ++ if (copy_siginfo_from_user32( ++ &siginfo, (struct compat_siginfo __user *) datap)) ++ ret = -EFAULT; ++ else ++ ret = ptrace_rw_siginfo(child, ptrace_context(engine), ++ &siginfo, true); ++ break; ++ ++ default: ++ ret = ptrace_request(child, request, addr, data); ++ } ++ ++ utrace_engine_put(engine); ++ return ret; ++} ++#endif /* CONFIG_COMPAT */ +diff --git a/kernel/ptrace.c b/kernel/ptrace.c +index a408bf7..4e87441 100644 +--- a/kernel/ptrace.c ++++ b/kernel/ptrace.c +@@ -16,7 +16,6 @@ + #include + #include + #include +-#include + #include + #include + #include +@@ -24,7 +23,286 @@ + #include + #include + ++int __ptrace_may_access(struct task_struct *task, unsigned int mode) ++{ ++ const struct cred *cred = current_cred(), *tcred; ++ ++ /* May we inspect the given task? ++ * This check is used both for attaching with ptrace ++ * and for allowing access to sensitive information in /proc. ++ * ++ * ptrace_attach denies several cases that /proc allows ++ * because setting up the necessary parent/child relationship ++ * or halting the specified task is impossible. ++ */ ++ int dumpable = 0; ++ /* Don't let security modules deny introspection */ ++ if (task == current) ++ return 0; ++ rcu_read_lock(); ++ tcred = __task_cred(task); ++ if ((cred->uid != tcred->euid || ++ cred->uid != tcred->suid || ++ cred->uid != tcred->uid || ++ cred->gid != tcred->egid || ++ cred->gid != tcred->sgid || ++ cred->gid != tcred->gid) && ++ !capable(CAP_SYS_PTRACE)) { ++ rcu_read_unlock(); ++ return -EPERM; ++ } ++ rcu_read_unlock(); ++ smp_rmb(); ++ if (task->mm) ++ dumpable = get_dumpable(task->mm); ++ if (!dumpable && !capable(CAP_SYS_PTRACE)) ++ return -EPERM; ++ ++ return security_ptrace_access_check(task, mode); ++} ++ ++bool ptrace_may_access(struct task_struct *task, unsigned int mode) ++{ ++ int err; ++ task_lock(task); ++ err = __ptrace_may_access(task, mode); ++ task_unlock(task); ++ return !err; ++} ++ ++/* ++ * Called with irqs disabled, returns true if childs should reap themselves. ++ */ ++static int ignoring_children(struct sighand_struct *sigh) ++{ ++ int ret; ++ spin_lock(&sigh->siglock); ++ ret = (sigh->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) || ++ (sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT); ++ spin_unlock(&sigh->siglock); ++ return ret; ++} ++ ++/* ++ * Called with tasklist_lock held for writing. ++ * Unlink a traced task, and clean it up if it was a traced zombie. ++ * Return true if it needs to be reaped with release_task(). ++ * (We can't call release_task() here because we already hold tasklist_lock.) ++ * ++ * If it's a zombie, our attachedness prevented normal parent notification ++ * or self-reaping. Do notification now if it would have happened earlier. ++ * If it should reap itself, return true. ++ * ++ * If it's our own child, there is no notification to do. But if our normal ++ * children self-reap, then this child was prevented by ptrace and we must ++ * reap it now, in that case we must also wake up sub-threads sleeping in ++ * do_wait(). ++ */ ++bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p) ++{ ++ __ptrace_unlink(p); ++ ++ if (p->exit_state == EXIT_ZOMBIE) { ++ if (!task_detached(p) && thread_group_empty(p)) { ++ if (!same_thread_group(p->real_parent, tracer)) ++ do_notify_parent(p, p->exit_signal); ++ else if (ignoring_children(tracer->sighand)) { ++ __wake_up_parent(p, tracer); ++ p->exit_signal = -1; ++ } ++ } ++ if (task_detached(p)) { ++ /* Mark it as in the process of being reaped. */ ++ p->exit_state = EXIT_DEAD; ++ return true; ++ } ++ } ++ ++ return false; ++} ++ ++int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len) ++{ ++ int copied = 0; ++ ++ while (len > 0) { ++ char buf[128]; ++ int this_len, retval; ++ ++ this_len = (len > sizeof(buf)) ? sizeof(buf) : len; ++ retval = access_process_vm(tsk, src, buf, this_len, 0); ++ if (!retval) { ++ if (copied) ++ break; ++ return -EIO; ++ } ++ if (copy_to_user(dst, buf, retval)) ++ return -EFAULT; ++ copied += retval; ++ src += retval; ++ dst += retval; ++ len -= retval; ++ } ++ return copied; ++} ++ ++int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len) ++{ ++ int copied = 0; ++ ++ while (len > 0) { ++ char buf[128]; ++ int this_len, retval; ++ ++ this_len = (len > sizeof(buf)) ? sizeof(buf) : len; ++ if (copy_from_user(buf, src, this_len)) ++ return -EFAULT; ++ retval = access_process_vm(tsk, dst, buf, this_len, 1); ++ if (!retval) { ++ if (copied) ++ break; ++ return -EIO; ++ } ++ copied += retval; ++ src += retval; ++ dst += retval; ++ len -= retval; ++ } ++ return copied; ++} ++ ++static struct task_struct *ptrace_get_task_struct(pid_t pid) ++{ ++ struct task_struct *child; ++ ++ rcu_read_lock(); ++ child = find_task_by_vpid(pid); ++ if (child) ++ get_task_struct(child); ++ rcu_read_unlock(); ++ ++ if (!child) ++ return ERR_PTR(-ESRCH); ++ return child; ++} ++ ++#ifndef arch_ptrace_attach ++#define arch_ptrace_attach(child) do { } while (0) ++#endif + ++SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) ++{ ++ struct task_struct *child; ++ long ret; ++ ++ /* ++ * This lock_kernel fixes a subtle race with suid exec ++ */ ++ lock_kernel(); ++ if (request == PTRACE_TRACEME) { ++ ret = ptrace_traceme(); ++ if (!ret) ++ arch_ptrace_attach(current); ++ goto out; ++ } ++ ++ child = ptrace_get_task_struct(pid); ++ if (IS_ERR(child)) { ++ ret = PTR_ERR(child); ++ goto out; ++ } ++ ++ if (request == PTRACE_ATTACH) { ++ ret = ptrace_attach(child); ++ /* ++ * Some architectures need to do book-keeping after ++ * a ptrace attach. ++ */ ++ if (!ret) ++ arch_ptrace_attach(child); ++ goto out_put_task_struct; ++ } ++ ++ ret = ptrace_check_attach(child, request == PTRACE_KILL); ++ if (ret < 0) ++ goto out_put_task_struct; ++ ++ ret = arch_ptrace(child, request, addr, data); ++ ++ out_put_task_struct: ++ put_task_struct(child); ++ out: ++ unlock_kernel(); ++ return ret; ++} ++ ++int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data) ++{ ++ unsigned long tmp; ++ int copied; ++ ++ copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0); ++ if (copied != sizeof(tmp)) ++ return -EIO; ++ return put_user(tmp, (unsigned long __user *)data); ++} ++ ++int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data) ++{ ++ int copied; ++ ++ copied = access_process_vm(tsk, addr, &data, sizeof(data), 1); ++ return (copied == sizeof(data)) ? 0 : -EIO; ++} ++ ++#if defined CONFIG_COMPAT ++#include ++ ++asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, ++ compat_long_t addr, compat_long_t data) ++{ ++ struct task_struct *child; ++ long ret; ++ ++ /* ++ * This lock_kernel fixes a subtle race with suid exec ++ */ ++ lock_kernel(); ++ if (request == PTRACE_TRACEME) { ++ ret = ptrace_traceme(); ++ goto out; ++ } ++ ++ child = ptrace_get_task_struct(pid); ++ if (IS_ERR(child)) { ++ ret = PTR_ERR(child); ++ goto out; ++ } ++ ++ if (request == PTRACE_ATTACH) { ++ ret = ptrace_attach(child); ++ /* ++ * Some architectures need to do book-keeping after ++ * a ptrace attach. ++ */ ++ if (!ret) ++ arch_ptrace_attach(child); ++ goto out_put_task_struct; ++ } ++ ++ ret = ptrace_check_attach(child, request == PTRACE_KILL); ++ if (!ret) ++ ret = compat_arch_ptrace(child, request, addr, data); ++ ++ out_put_task_struct: ++ put_task_struct(child); ++ out: ++ unlock_kernel(); ++ return ret; ++} ++#endif /* CONFIG_COMPAT */ ++ ++#ifndef CONFIG_UTRACE + /* + * ptrace a task: make the debugger its new parent and + * move it to the ptrace list. +@@ -101,76 +379,21 @@ int ptrace_check_attach(struct task_stru + /* + * child->sighand can't be NULL, release_task() + * does ptrace_unlink() before __exit_signal(). +- */ +- spin_lock_irq(&child->sighand->siglock); +- if (task_is_stopped(child)) +- child->state = TASK_TRACED; +- else if (!task_is_traced(child) && !kill) +- ret = -ESRCH; +- spin_unlock_irq(&child->sighand->siglock); +- } +- read_unlock(&tasklist_lock); +- +- if (!ret && !kill) +- ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH; +- +- /* All systems go.. */ +- return ret; +-} +- +-int __ptrace_may_access(struct task_struct *task, unsigned int mode) +-{ +- const struct cred *cred = current_cred(), *tcred; +- +- /* May we inspect the given task? +- * This check is used both for attaching with ptrace +- * and for allowing access to sensitive information in /proc. +- * +- * ptrace_attach denies several cases that /proc allows +- * because setting up the necessary parent/child relationship +- * or halting the specified task is impossible. +- */ +- int dumpable = 0; +- /* Don't let security modules deny introspection */ +- if (task == current) +- return 0; +- rcu_read_lock(); +- tcred = __task_cred(task); +- if ((cred->uid != tcred->euid || +- cred->uid != tcred->suid || +- cred->uid != tcred->uid || +- cred->gid != tcred->egid || +- cred->gid != tcred->sgid || +- cred->gid != tcred->gid) && +- !capable(CAP_SYS_PTRACE)) { +- rcu_read_unlock(); +- return -EPERM; +- } +- rcu_read_unlock(); +- smp_rmb(); +- if (task->mm) +- dumpable = get_dumpable(task->mm); +- if (!dumpable && !capable(CAP_SYS_PTRACE)) +- return -EPERM; +- +- return security_ptrace_access_check(task, mode); +-} ++ */ ++ spin_lock_irq(&child->sighand->siglock); ++ if (task_is_stopped(child)) ++ child->state = TASK_TRACED; ++ else if (!task_is_traced(child) && !kill) ++ ret = -ESRCH; ++ spin_unlock_irq(&child->sighand->siglock); ++ } ++ read_unlock(&tasklist_lock); + +-bool ptrace_may_access(struct task_struct *task, unsigned int mode) +-{ +- int err; +- task_lock(task); +- err = __ptrace_may_access(task, mode); +- task_unlock(task); +- return !err; +-} ++ if (!ret && !kill) ++ ret = wait_task_inactive(child, TASK_TRACED) ? 0 : -ESRCH; + +-/* +- * For experimental use of utrace, exclude ptrace on the same task. +- */ +-static inline bool exclude_ptrace(struct task_struct *task) +-{ +- return unlikely(!!task_utrace_flags(task)); ++ /* All systems go.. */ ++ return ret; + } + + int ptrace_attach(struct task_struct *task) +@@ -196,8 +419,6 @@ int ptrace_attach(struct task_struct *ta + + task_lock(task); + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH); +- if (!retval && exclude_ptrace(task)) +- retval = -EBUSY; + task_unlock(task); + if (retval) + goto unlock_creds; +@@ -235,9 +456,6 @@ int ptrace_traceme(void) + { + int ret = -EPERM; + +- if (exclude_ptrace(current)) /* XXX locking */ +- return -EBUSY; +- + write_lock_irq(&tasklist_lock); + /* Are we already being traced? */ + if (!current->ptrace) { +@@ -257,57 +475,6 @@ int ptrace_traceme(void) + return ret; + } + +-/* +- * Called with irqs disabled, returns true if childs should reap themselves. +- */ +-static int ignoring_children(struct sighand_struct *sigh) +-{ +- int ret; +- spin_lock(&sigh->siglock); +- ret = (sigh->action[SIGCHLD-1].sa.sa_handler == SIG_IGN) || +- (sigh->action[SIGCHLD-1].sa.sa_flags & SA_NOCLDWAIT); +- spin_unlock(&sigh->siglock); +- return ret; +-} +- +-/* +- * Called with tasklist_lock held for writing. +- * Unlink a traced task, and clean it up if it was a traced zombie. +- * Return true if it needs to be reaped with release_task(). +- * (We can't call release_task() here because we already hold tasklist_lock.) +- * +- * If it's a zombie, our attachedness prevented normal parent notification +- * or self-reaping. Do notification now if it would have happened earlier. +- * If it should reap itself, return true. +- * +- * If it's our own child, there is no notification to do. But if our normal +- * children self-reap, then this child was prevented by ptrace and we must +- * reap it now, in that case we must also wake up sub-threads sleeping in +- * do_wait(). +- */ +-bool __ptrace_detach(struct task_struct *tracer, struct task_struct *p) +-{ +- __ptrace_unlink(p); +- +- if (p->exit_state == EXIT_ZOMBIE) { +- if (!task_detached(p) && thread_group_empty(p)) { +- if (!same_thread_group(p->real_parent, tracer)) +- do_notify_parent(p, p->exit_signal); +- else if (ignoring_children(tracer->sighand)) { +- __wake_up_parent(p, tracer); +- p->exit_signal = -1; +- } +- } +- if (task_detached(p)) { +- /* Mark it as in the process of being reaped. */ +- p->exit_state = EXIT_DEAD; +- return true; +- } +- } +- +- return false; +-} +- + int ptrace_detach(struct task_struct *child, unsigned int data) + { + bool dead = false; +@@ -361,56 +528,6 @@ void exit_ptrace(struct task_struct *tra + } + } + +-int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst, int len) +-{ +- int copied = 0; +- +- while (len > 0) { +- char buf[128]; +- int this_len, retval; +- +- this_len = (len > sizeof(buf)) ? sizeof(buf) : len; +- retval = access_process_vm(tsk, src, buf, this_len, 0); +- if (!retval) { +- if (copied) +- break; +- return -EIO; +- } +- if (copy_to_user(dst, buf, retval)) +- return -EFAULT; +- copied += retval; +- src += retval; +- dst += retval; +- len -= retval; +- } +- return copied; +-} +- +-int ptrace_writedata(struct task_struct *tsk, char __user *src, unsigned long dst, int len) +-{ +- int copied = 0; +- +- while (len > 0) { +- char buf[128]; +- int this_len, retval; +- +- this_len = (len > sizeof(buf)) ? sizeof(buf) : len; +- if (copy_from_user(buf, src, this_len)) +- return -EFAULT; +- retval = access_process_vm(tsk, dst, buf, this_len, 1); +- if (!retval) { +- if (copied) +- break; +- return -EIO; +- } +- copied += retval; +- src += retval; +- dst += retval; +- len -= retval; +- } +- return copied; +-} +- + static int ptrace_setoptions(struct task_struct *child, long data) + { + child->ptrace &= ~PT_TRACE_MASK; +@@ -594,93 +710,7 @@ int ptrace_request(struct task_struct *c + return ret; + } + +-static struct task_struct *ptrace_get_task_struct(pid_t pid) +-{ +- struct task_struct *child; +- +- rcu_read_lock(); +- child = find_task_by_vpid(pid); +- if (child) +- get_task_struct(child); +- rcu_read_unlock(); +- +- if (!child) +- return ERR_PTR(-ESRCH); +- return child; +-} +- +-#ifndef arch_ptrace_attach +-#define arch_ptrace_attach(child) do { } while (0) +-#endif +- +-SYSCALL_DEFINE4(ptrace, long, request, long, pid, long, addr, long, data) +-{ +- struct task_struct *child; +- long ret; +- +- /* +- * This lock_kernel fixes a subtle race with suid exec +- */ +- lock_kernel(); +- if (request == PTRACE_TRACEME) { +- ret = ptrace_traceme(); +- if (!ret) +- arch_ptrace_attach(current); +- goto out; +- } +- +- child = ptrace_get_task_struct(pid); +- if (IS_ERR(child)) { +- ret = PTR_ERR(child); +- goto out; +- } +- +- if (request == PTRACE_ATTACH) { +- ret = ptrace_attach(child); +- /* +- * Some architectures need to do book-keeping after +- * a ptrace attach. +- */ +- if (!ret) +- arch_ptrace_attach(child); +- goto out_put_task_struct; +- } +- +- ret = ptrace_check_attach(child, request == PTRACE_KILL); +- if (ret < 0) +- goto out_put_task_struct; +- +- ret = arch_ptrace(child, request, addr, data); +- +- out_put_task_struct: +- put_task_struct(child); +- out: +- unlock_kernel(); +- return ret; +-} +- +-int generic_ptrace_peekdata(struct task_struct *tsk, long addr, long data) +-{ +- unsigned long tmp; +- int copied; +- +- copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0); +- if (copied != sizeof(tmp)) +- return -EIO; +- return put_user(tmp, (unsigned long __user *)data); +-} +- +-int generic_ptrace_pokedata(struct task_struct *tsk, long addr, long data) +-{ +- int copied; +- +- copied = access_process_vm(tsk, addr, &data, sizeof(data), 1); +- return (copied == sizeof(data)) ? 0 : -EIO; +-} +- + #if defined CONFIG_COMPAT +-#include +- + int compat_ptrace_request(struct task_struct *child, compat_long_t request, + compat_ulong_t addr, compat_ulong_t data) + { +@@ -732,47 +762,5 @@ int compat_ptrace_request(struct task_st + + return ret; + } +- +-asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid, +- compat_long_t addr, compat_long_t data) +-{ +- struct task_struct *child; +- long ret; +- +- /* +- * This lock_kernel fixes a subtle race with suid exec +- */ +- lock_kernel(); +- if (request == PTRACE_TRACEME) { +- ret = ptrace_traceme(); +- goto out; +- } +- +- child = ptrace_get_task_struct(pid); +- if (IS_ERR(child)) { +- ret = PTR_ERR(child); +- goto out; +- } +- +- if (request == PTRACE_ATTACH) { +- ret = ptrace_attach(child); +- /* +- * Some architectures need to do book-keeping after +- * a ptrace attach. +- */ +- if (!ret) +- arch_ptrace_attach(child); +- goto out_put_task_struct; +- } +- +- ret = ptrace_check_attach(child, request == PTRACE_KILL); +- if (!ret) +- ret = compat_arch_ptrace(child, request, addr, data); +- +- out_put_task_struct: +- put_task_struct(child); +- out: +- unlock_kernel(); +- return ret; +-} + #endif /* CONFIG_COMPAT */ ++#endif /* CONFIG_UTRACE */ +diff --git a/kernel/utrace.c b/kernel/utrace.c +index f003e34..f5a9e2c 100644 +--- a/kernel/utrace.c ++++ b/kernel/utrace.c +@@ -811,6 +811,22 @@ relock: + spin_unlock_irq(&task->sighand->siglock); + spin_unlock(&utrace->lock); + ++ /* ++ * If ptrace is among the reasons for this stop, do its ++ * notification now. This could not just be done in ++ * ptrace's own event report callbacks because it has to ++ * be done after we are in TASK_TRACED. This makes the ++ * synchronization with ptrace_do_wait() work right. ++ * ++ * It's only because of the bad old overloading of the do_wait() ++ * logic for handling ptrace stops that we need this special case ++ * here. One day we will clean up ptrace so it does not need to ++ * work this way. New things that are designed sensibly don't need ++ * a wakeup that synchronizes with tasklist_lock and ->state, so ++ * the proper utrace API does not try to support this weirdness. ++ */ ++ ptrace_notify_stop(task); ++ + schedule(); + + utrace_finish_stop(); diff --git a/linux-2.6-utrace.patch b/linux-2.6-utrace.patch new file mode 100644 index 000000000..a7d0adcd8 --- /dev/null +++ b/linux-2.6-utrace.patch @@ -0,0 +1,4163 @@ +utrace core + +This adds the utrace facility, a new modular interface in the kernel for +implementing user thread tracing and debugging. This fits on top of the +tracehook_* layer, so the new code is well-isolated. + +The new interface is in and the DocBook utrace book +describes it. It allows for multiple separate tracing engines to work in +parallel without interfering with each other. Higher-level tracing +facilities can be implemented as loadable kernel modules using this layer. + +The new facility is made optional under CONFIG_UTRACE. +When this is not enabled, no new code is added. +It can only be enabled on machines that have all the +prerequisites and select CONFIG_HAVE_ARCH_TRACEHOOK. + +In this initial version, utrace and ptrace do not play together at all. +If ptrace is attached to a thread, the attach calls in the utrace kernel +API return -EBUSY. If utrace is attached to a thread, the PTRACE_ATTACH +or PTRACE_TRACEME request will return EBUSY to userland. The old ptrace +code is otherwise unchanged and nothing using ptrace should be affected +by this patch as long as utrace is not used at the same time. In the +future we can clean up the ptrace implementation and rework it to use +the utrace API. + +Signed-off-by: Roland McGrath +--- + Documentation/DocBook/Makefile | 2 +- + Documentation/DocBook/utrace.tmpl | 590 +++++++++ + fs/proc/array.c | 3 + + include/linux/sched.h | 5 + + include/linux/tracehook.h | 87 ++- + include/linux/utrace.h | 692 +++++++++++ + init/Kconfig | 9 + + kernel/Makefile | 1 + + kernel/fork.c | 3 + + kernel/ptrace.c | 14 + + kernel/utrace.c | 2436 +++++++++++++++++++++++++++++++++++++ + 11 files changed, 3840 insertions(+), 2 deletions(-) + +diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile +index 325cfd1..a45e4e6 100644 +--- a/Documentation/DocBook/Makefile ++++ b/Documentation/DocBook/Makefile +@@ -14,7 +14,7 @@ DOCBOOKS := z8530book.xml mcabook.xml de + genericirq.xml s390-drivers.xml uio-howto.xml scsi.xml \ + mac80211.xml debugobjects.xml sh.xml regulator.xml \ + alsa-driver-api.xml writing-an-alsa-driver.xml \ +- tracepoint.xml media.xml ++ tracepoint.xml utrace.xml media.xml + + ### + # The build process is as follows (targets): +diff --git a/Documentation/DocBook/utrace.tmpl b/Documentation/DocBook/utrace.tmpl +new file mode 100644 +index ...e149f49 100644 +--- /dev/null ++++ b/Documentation/DocBook/utrace.tmpl +@@ -0,0 +1,590 @@ ++ ++ ++ ++ ++ ++ The utrace User Debugging Infrastructure ++ ++ ++ ++ ++ utrace concepts ++ ++ Introduction ++ ++ ++ utrace is infrastructure code for tracing ++ and controlling user threads. This is the foundation for writing ++ tracing engines, which can be loadable kernel modules. ++ ++ ++ ++ The basic actors in utrace are the thread ++ and the tracing engine. A tracing engine is some body of code that ++ calls into the <linux/utrace.h> ++ interfaces, represented by a struct ++ utrace_engine_ops. (Usually it's a kernel module, ++ though the legacy ptrace support is a tracing ++ engine that is not in a kernel module.) The interface operates on ++ individual threads (struct task_struct). ++ If an engine wants to treat several threads as a group, that is up ++ to its higher-level code. ++ ++ ++ ++ Tracing begins by attaching an engine to a thread, using ++ utrace_attach_task or ++ utrace_attach_pid. If successful, it returns a ++ pointer that is the handle used in all other calls. ++ ++ ++ ++ ++ Events and Callbacks ++ ++ ++ An attached engine does nothing by default. An engine makes something ++ happen by requesting callbacks via utrace_set_events ++ and poking the thread with utrace_control. ++ The synchronization issues related to these two calls ++ are discussed further below in . ++ ++ ++ ++ Events are specified using the macro ++ UTRACE_EVENT(type). ++ Each event type is associated with a callback in struct ++ utrace_engine_ops. A tracing engine can leave unused ++ callbacks NULL. The only callbacks required ++ are those used by the event flags it sets. ++ ++ ++ ++ Many engines can be attached to each thread. When a thread has an ++ event, each engine gets a callback if it has set the event flag for ++ that event type. For most events, engines are called in the order they ++ attached. Engines that attach after the event has occurred do not get ++ callbacks for that event. This includes any new engines just attached ++ by an existing engine's callback function. Once the sequence of ++ callbacks for that one event has completed, such new engines are then ++ eligible in the next sequence that starts when there is another event. ++ ++ ++ ++ Event reporting callbacks have details particular to the event type, ++ but are all called in similar environments and have the same ++ constraints. Callbacks are made from safe points, where no locks ++ are held, no special resources are pinned (usually), and the ++ user-mode state of the thread is accessible. So, callback code has ++ a pretty free hand. But to be a good citizen, callback code should ++ never block for long periods. It is fine to block in ++ kmalloc and the like, but never wait for i/o or ++ for user mode to do something. If you need the thread to wait, use ++ UTRACE_STOP and return from the callback ++ quickly. When your i/o finishes or whatever, you can use ++ utrace_control to resume the thread. ++ ++ ++ ++ The UTRACE_EVENT(SYSCALL_ENTRY) event is a special ++ case. While other events happen in the kernel when it will return to ++ user mode soon, this event happens when entering the kernel before it ++ will proceed with the work requested from user mode. Because of this ++ difference, the report_syscall_entry callback is ++ special in two ways. For this event, engines are called in reverse of ++ the normal order (this includes the report_quiesce ++ call that precedes a report_syscall_entry call). ++ This preserves the semantics that the last engine to attach is called ++ "closest to user mode"--the engine that is first to see a thread's user ++ state when it enters the kernel is also the last to see that state when ++ the thread returns to user mode. For the same reason, if these ++ callbacks use UTRACE_STOP (see the next section), ++ the thread stops immediately after callbacks rather than only when it's ++ ready to return to user mode; when allowed to resume, it will actually ++ attempt the system call indicated by the register values at that time. ++ ++ ++ ++ ++ Stopping Safely ++ ++ Writing well-behaved callbacks ++ ++ ++ Well-behaved callbacks are important to maintain two essential ++ properties of the interface. The first of these is that unrelated ++ tracing engines should not interfere with each other. If your engine's ++ event callback does not return quickly, then another engine won't get ++ the event notification in a timely manner. The second important ++ property is that tracing should be as noninvasive as possible to the ++ normal operation of the system overall and of the traced thread in ++ particular. That is, attached tracing engines should not perturb a ++ thread's behavior, except to the extent that changing its user-visible ++ state is explicitly what you want to do. (Obviously some perturbation ++ is unavoidable, primarily timing changes, ranging from small delays due ++ to the overhead of tracing, to arbitrary pauses in user code execution ++ when a user stops a thread with a debugger for examination.) Even when ++ you explicitly want the perturbation of making the traced thread block, ++ just blocking directly in your callback has more unwanted effects. For ++ example, the CLONE event callbacks are called when ++ the new child thread has been created but not yet started running; the ++ child can never be scheduled until the CLONE ++ tracing callbacks return. (This allows engines tracing the parent to ++ attach to the child.) If a CLONE event callback ++ blocks the parent thread, it also prevents the child thread from ++ running (even to process a SIGKILL). If what you ++ want is to make both the parent and child block, then use ++ utrace_attach_task on the child and then use ++ UTRACE_STOP on both threads. A more crucial ++ problem with blocking in callbacks is that it can prevent ++ SIGKILL from working. A thread that is blocking ++ due to UTRACE_STOP will still wake up and die ++ immediately when sent a SIGKILL, as all threads ++ should. Relying on the utrace ++ infrastructure rather than on private synchronization calls in event ++ callbacks is an important way to help keep tracing robustly ++ noninvasive. ++ ++ ++ ++ ++ Using <constant>UTRACE_STOP</constant> ++ ++ ++ To control another thread and access its state, it must be stopped ++ with UTRACE_STOP. This means that it is ++ stopped and won't start running again while we access it. When a ++ thread is not already stopped, utrace_control ++ returns -EINPROGRESS and an engine must wait ++ for an event callback when the thread is ready to stop. The thread ++ may be running on another CPU or may be blocked. When it is ready ++ to be examined, it will make callbacks to engines that set the ++ UTRACE_EVENT(QUIESCE) event bit. To wake up an ++ interruptible wait, use UTRACE_INTERRUPT. ++ ++ ++ ++ As long as some engine has used UTRACE_STOP and ++ not called utrace_control to resume the thread, ++ then the thread will remain stopped. SIGKILL ++ will wake it up, but it will not run user code. When the stop is ++ cleared with utrace_control or a callback ++ return value, the thread starts running again. ++ (See also .) ++ ++ ++ ++ ++ ++ ++ Tear-down Races ++ ++ Primacy of <constant>SIGKILL</constant> ++ ++ Ordinarily synchronization issues for tracing engines are kept fairly ++ straightforward by using UTRACE_STOP. You ask a ++ thread to stop, and then once it makes the ++ report_quiesce callback it cannot do anything else ++ that would result in another callback, until you let it with a ++ utrace_control call. This simple arrangement ++ avoids complex and error-prone code in each one of a tracing engine's ++ event callbacks to keep them serialized with the engine's other ++ operations done on that thread from another thread of control. ++ However, giving tracing engines complete power to keep a traced thread ++ stuck in place runs afoul of a more important kind of simplicity that ++ the kernel overall guarantees: nothing can prevent or delay ++ SIGKILL from making a thread die and release its ++ resources. To preserve this important property of ++ SIGKILL, it as a special case can break ++ UTRACE_STOP like nothing else normally can. This ++ includes both explicit SIGKILL signals and the ++ implicit SIGKILL sent to each other thread in the ++ same thread group by a thread doing an exec, or processing a fatal ++ signal, or making an exit_group system call. A ++ tracing engine can prevent a thread from beginning the exit or exec or ++ dying by signal (other than SIGKILL) if it is ++ attached to that thread, but once the operation begins, no tracing ++ engine can prevent or delay all other threads in the same thread group ++ dying. ++ ++ ++ ++ Final callbacks ++ ++ The report_reap callback is always the final event ++ in the life cycle of a traced thread. Tracing engines can use this as ++ the trigger to clean up their own data structures. The ++ report_death callback is always the penultimate ++ event a tracing engine might see; it's seen unless the thread was ++ already in the midst of dying when the engine attached. Many tracing ++ engines will have no interest in when a parent reaps a dead process, ++ and nothing they want to do with a zombie thread once it dies; for ++ them, the report_death callback is the natural ++ place to clean up data structures and detach. To facilitate writing ++ such engines robustly, given the asynchrony of ++ SIGKILL, and without error-prone manual ++ implementation of synchronization schemes, the ++ utrace infrastructure provides some special ++ guarantees about the report_death and ++ report_reap callbacks. It still takes some care ++ to be sure your tracing engine is robust to tear-down races, but these ++ rules make it reasonably straightforward and concise to handle a lot of ++ corner cases correctly. ++ ++ ++ ++ Engine and task pointers ++ ++ The first sort of guarantee concerns the core data structures ++ themselves. struct utrace_engine is ++ a reference-counted data structure. While you hold a reference, an ++ engine pointer will always stay valid so that you can safely pass it to ++ any utrace call. Each call to ++ utrace_attach_task or ++ utrace_attach_pid returns an engine pointer with a ++ reference belonging to the caller. You own that reference until you ++ drop it using utrace_engine_put. There is an ++ implicit reference on the engine while it is attached. So if you drop ++ your only reference, and then use ++ utrace_attach_task without ++ UTRACE_ATTACH_CREATE to look up that same engine, ++ you will get the same pointer with a new reference to replace the one ++ you dropped, just like calling utrace_engine_get. ++ When an engine has been detached, either explicitly with ++ UTRACE_DETACH or implicitly after ++ report_reap, then any references you hold are all ++ that keep the old engine pointer alive. ++ ++ ++ ++ There is nothing a kernel module can do to keep a struct ++ task_struct alive outside of ++ rcu_read_lock. When the task dies and is reaped ++ by its parent (or itself), that structure can be freed so that any ++ dangling pointers you have stored become invalid. ++ utrace will not prevent this, but it can ++ help you detect it safely. By definition, a task that has been reaped ++ has had all its engines detached. All ++ utrace calls can be safely called on a ++ detached engine if the caller holds a reference on that engine pointer, ++ even if the task pointer passed in the call is invalid. All calls ++ return -ESRCH for a detached engine, which tells ++ you that the task pointer you passed could be invalid now. Since ++ utrace_control and ++ utrace_set_events do not block, you can call those ++ inside a rcu_read_lock section and be sure after ++ they don't return -ESRCH that the task pointer is ++ still valid until rcu_read_unlock. The ++ infrastructure never holds task references of its own. Though neither ++ rcu_read_lock nor any other lock is held while ++ making a callback, it's always guaranteed that the struct ++ task_struct and the struct ++ utrace_engine passed as arguments remain valid ++ until the callback function returns. ++ ++ ++ ++ The common means for safely holding task pointers that is available to ++ kernel modules is to use struct pid, which ++ permits put_pid from kernel modules. When using ++ that, the calls utrace_attach_pid, ++ utrace_control_pid, ++ utrace_set_events_pid, and ++ utrace_barrier_pid are available. ++ ++ ++ ++ ++ ++ Serialization of <constant>DEATH</constant> and <constant>REAP</constant> ++ ++ ++ The second guarantee is the serialization of ++ DEATH and REAP event ++ callbacks for a given thread. The actual reaping by the parent ++ (release_task call) can occur simultaneously ++ while the thread is still doing the final steps of dying, including ++ the report_death callback. If a tracing engine ++ has requested both DEATH and ++ REAP event reports, it's guaranteed that the ++ report_reap callback will not be made until ++ after the report_death callback has returned. ++ If the report_death callback itself detaches ++ from the thread, then the report_reap callback ++ will never be made. Thus it is safe for a ++ report_death callback to clean up data ++ structures and detach. ++ ++ ++ ++ Interlock with final callbacks ++ ++ The final sort of guarantee is that a tracing engine will know for sure ++ whether or not the report_death and/or ++ report_reap callbacks will be made for a certain ++ thread. These tear-down races are disambiguated by the error return ++ values of utrace_set_events and ++ utrace_control. Normally ++ utrace_control called with ++ UTRACE_DETACH returns zero, and this means that no ++ more callbacks will be made. If the thread is in the midst of dying, ++ it returns -EALREADY to indicate that the ++ report_death callback may already be in progress; ++ when you get this error, you know that any cleanup your ++ report_death callback does is about to happen or ++ has just happened--note that if the report_death ++ callback does not detach, the engine remains attached until the thread ++ gets reaped. If the thread is in the midst of being reaped, ++ utrace_control returns -ESRCH ++ to indicate that the report_reap callback may ++ already be in progress; this means the engine is implicitly detached ++ when the callback completes. This makes it possible for a tracing ++ engine that has decided asynchronously to detach from a thread to ++ safely clean up its data structures, knowing that no ++ report_death or report_reap ++ callback will try to do the same. utrace_detach ++ returns -ESRCH when the struct ++ utrace_engine has already been detached, but is ++ still a valid pointer because of its reference count. A tracing engine ++ can use this to safely synchronize its own independent multiple threads ++ of control with each other and with its event callbacks that detach. ++ ++ ++ ++ In the same vein, utrace_set_events normally ++ returns zero; if the target thread was stopped before the call, then ++ after a successful call, no event callbacks not requested in the new ++ flags will be made. It fails with -EALREADY if ++ you try to clear UTRACE_EVENT(DEATH) when the ++ report_death callback may already have begun, if ++ you try to clear UTRACE_EVENT(REAP) when the ++ report_reap callback may already have begun, or if ++ you try to newly set UTRACE_EVENT(DEATH) or ++ UTRACE_EVENT(QUIESCE) when the target is already ++ dead or dying. Like utrace_control, it returns ++ -ESRCH when the thread has already been detached ++ (including forcible detach on reaping). This lets the tracing engine ++ know for sure which event callbacks it will or won't see after ++ utrace_set_events has returned. By checking for ++ errors, it can know whether to clean up its data structures immediately ++ or to let its callbacks do the work. ++ ++ ++ ++ Using <function>utrace_barrier</function> ++ ++ When a thread is safely stopped, calling ++ utrace_control with UTRACE_DETACH ++ or calling utrace_set_events to disable some events ++ ensures synchronously that your engine won't get any more of the callbacks ++ that have been disabled (none at all when detaching). But these can also ++ be used while the thread is not stopped, when it might be simultaneously ++ making a callback to your engine. For this situation, these calls return ++ -EINPROGRESS when it's possible a callback is in ++ progress. If you are not prepared to have your old callbacks still run, ++ then you can synchronize to be sure all the old callbacks are finished, ++ using utrace_barrier. This is necessary if the ++ kernel module containing your callback code is going to be unloaded. ++ ++ ++ After using UTRACE_DETACH once, further calls to ++ utrace_control with the same engine pointer will ++ return -ESRCH. In contrast, after getting ++ -EINPROGRESS from ++ utrace_set_events, you can call ++ utrace_set_events again later and if it returns zero ++ then know the old callbacks have finished. ++ ++ ++ Unlike all other calls, utrace_barrier (and ++ utrace_barrier_pid) will accept any engine pointer you ++ hold a reference on, even if UTRACE_DETACH has already ++ been used. After any utrace_control or ++ utrace_set_events call (these do not block), you can ++ call utrace_barrier to block until callbacks have ++ finished. This returns -ESRCH only if the engine is ++ completely detached (finished all callbacks). Otherwise it waits ++ until the thread is definitely not in the midst of a callback to this ++ engine and then returns zero, but can return ++ -ERESTARTSYS if its wait is interrupted. ++ ++ ++ ++ ++ ++ ++ ++utrace core API ++ ++ ++ The utrace API is declared in <linux/utrace.h>. ++ ++ ++!Iinclude/linux/utrace.h ++!Ekernel/utrace.c ++ ++ ++ ++Machine State ++ ++ ++ The task_current_syscall function can be used on any ++ valid struct task_struct at any time, and does ++ not even require that utrace_attach_task was used at all. ++ ++ ++ ++ The other ways to access the registers and other machine-dependent state of ++ a task can only be used on a task that is at a known safe point. The safe ++ points are all the places where utrace_set_events can ++ request callbacks (except for the DEATH and ++ REAP events). So at any event callback, it is safe to ++ examine current. ++ ++ ++ ++ One task can examine another only after a callback in the target task that ++ returns UTRACE_STOP so that task will not return to user ++ mode after the safe point. This guarantees that the task will not resume ++ until the same engine uses utrace_control, unless the ++ task dies suddenly. To examine safely, one must use a pair of calls to ++ utrace_prepare_examine and ++ utrace_finish_examine surrounding the calls to ++ struct user_regset functions or direct examination ++ of task data structures. utrace_prepare_examine returns ++ an error if the task is not properly stopped, or is dead. After a ++ successful examination, the paired utrace_finish_examine ++ call returns an error if the task ever woke up during the examination. If ++ so, any data gathered may be scrambled and should be discarded. This means ++ there was a spurious wake-up (which should not happen), or a sudden death. ++ ++ ++<structname>struct user_regset</structname> ++ ++ ++ The struct user_regset API ++ is declared in <linux/regset.h>. ++ ++ ++!Finclude/linux/regset.h ++ ++ ++ ++ ++ <filename>System Call Information</filename> ++ ++ ++ This function is declared in <linux/ptrace.h>. ++ ++ ++!Elib/syscall.c ++ ++ ++ ++<filename>System Call Tracing</filename> ++ ++ ++ The arch API for system call information is declared in ++ <asm/syscall.h>. ++ Each of these calls can be used only at system call entry tracing, ++ or can be used only at system call exit and the subsequent safe points ++ before returning to user mode. ++ At system call entry tracing means either during a ++ report_syscall_entry callback, ++ or any time after that callback has returned UTRACE_STOP. ++ ++ ++!Finclude/asm-generic/syscall.h ++ ++ ++ ++ ++ ++Kernel Internals ++ ++ ++ This chapter covers the interface to the tracing infrastructure ++ from the core of the kernel and the architecture-specific code. ++ This is for maintainers of the kernel and arch code, and not relevant ++ to using the tracing facilities described in preceding chapters. ++ ++ ++Core Calls In ++ ++ ++ These calls are declared in <linux/tracehook.h>. ++ The core kernel calls these functions at various important places. ++ ++ ++!Finclude/linux/tracehook.h ++ ++ ++ ++Architecture Calls Out ++ ++ ++ An arch that has done all these things sets ++ CONFIG_HAVE_ARCH_TRACEHOOK. ++ This is required to enable the utrace code. ++ ++ ++<filename><asm/ptrace.h></filename> ++ ++ ++ An arch defines these in <asm/ptrace.h> ++ if it supports hardware single-step or block-step features. ++ ++ ++!Finclude/linux/ptrace.h arch_has_single_step arch_has_block_step ++!Finclude/linux/ptrace.h user_enable_single_step user_enable_block_step ++!Finclude/linux/ptrace.h user_disable_single_step ++ ++ ++ ++ ++ <filename><asm/syscall.h></filename> ++ ++ ++ An arch provides <asm/syscall.h> that ++ defines these as inlines, or declares them as exported functions. ++ These interfaces are described in . ++ ++ ++ ++ ++ ++ <filename><linux/tracehook.h></filename> ++ ++ ++ An arch must define TIF_NOTIFY_RESUME ++ and TIF_SYSCALL_TRACE ++ in its <asm/thread_info.h>. ++ The arch code must call the following functions, all declared ++ in <linux/tracehook.h> and ++ described in : ++ ++ ++ ++ tracehook_notify_resume ++ ++ ++ tracehook_report_syscall_entry ++ ++ ++ tracehook_report_syscall_exit ++ ++ ++ tracehook_signal_handler ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ ++ +diff --git a/fs/proc/array.c b/fs/proc/array.c +index 13b5d07..cda9489 100644 +--- a/fs/proc/array.c ++++ b/fs/proc/array.c +@@ -82,6 +82,7 @@ + #include + #include + #include ++#include + + #include + #include +@@ -194,6 +195,8 @@ static inline void task_state(struct seq + cred->uid, cred->euid, cred->suid, cred->fsuid, + cred->gid, cred->egid, cred->sgid, cred->fsgid); + ++ task_utrace_proc_status(m, p); ++ + task_lock(p); + if (p->files) + fdt = files_fdtable(p->files); +diff --git a/include/linux/sched.h b/include/linux/sched.h +index 9a2b557..47379c1 100644 +--- a/include/linux/sched.h ++++ b/include/linux/sched.h +@@ -1412,6 +1412,11 @@ struct task_struct { + #endif + seccomp_t seccomp; + ++#ifdef CONFIG_UTRACE ++ struct utrace *utrace; ++ unsigned long utrace_flags; ++#endif ++ + /* Thread group tracking */ + u32 parent_exec_id; + u32 self_exec_id; +diff --git a/include/linux/tracehook.h b/include/linux/tracehook.h +index c78b2f4..71fa250 100644 +--- a/include/linux/tracehook.h ++++ b/include/linux/tracehook.h +@@ -49,6 +49,7 @@ + #include + #include + #include ++#include + struct linux_binprm; + + /** +@@ -63,6 +64,8 @@ struct linux_binprm; + */ + static inline int tracehook_expect_breakpoints(struct task_struct *task) + { ++ if (unlikely(task_utrace_flags(task) & UTRACE_EVENT(SIGNAL_CORE))) ++ return 1; + return (task_ptrace(task) & PT_PTRACED) != 0; + } + +@@ -111,6 +114,9 @@ static inline void ptrace_report_syscall + static inline __must_check int tracehook_report_syscall_entry( + struct pt_regs *regs) + { ++ if ((task_utrace_flags(current) & UTRACE_EVENT(SYSCALL_ENTRY)) && ++ utrace_report_syscall_entry(regs)) ++ return 1; + ptrace_report_syscall(regs); + return 0; + } +@@ -134,6 +140,9 @@ static inline __must_check int tracehook + */ + static inline void tracehook_report_syscall_exit(struct pt_regs *regs, int step) + { ++ if (task_utrace_flags(current) & UTRACE_EVENT(SYSCALL_EXIT)) ++ utrace_report_syscall_exit(regs); ++ + if (step && (task_ptrace(current) & PT_PTRACED)) { + siginfo_t info; + user_single_step_siginfo(current, regs, &info); +@@ -201,6 +210,8 @@ static inline void tracehook_report_exec + struct linux_binprm *bprm, + struct pt_regs *regs) + { ++ if (unlikely(task_utrace_flags(current) & UTRACE_EVENT(EXEC))) ++ utrace_report_exec(fmt, bprm, regs); + if (!ptrace_event(PT_TRACE_EXEC, PTRACE_EVENT_EXEC, 0) && + unlikely(task_ptrace(current) & PT_PTRACED)) + send_sig(SIGTRAP, current, 0); +@@ -218,10 +229,37 @@ static inline void tracehook_report_exec + */ + static inline void tracehook_report_exit(long *exit_code) + { ++ if (unlikely(task_utrace_flags(current) & UTRACE_EVENT(EXIT))) ++ utrace_report_exit(exit_code); + ptrace_event(PT_TRACE_EXIT, PTRACE_EVENT_EXIT, *exit_code); + } + + /** ++ * tracehook_init_task - task_struct has just been copied ++ * @task: new &struct task_struct just copied from parent ++ * ++ * Called from do_fork() when @task has just been duplicated. ++ * After this, @task will be passed to tracehook_free_task() ++ * even if the rest of its setup fails before it is fully created. ++ */ ++static inline void tracehook_init_task(struct task_struct *task) ++{ ++ utrace_init_task(task); ++} ++ ++/** ++ * tracehook_free_task - task_struct is being freed ++ * @task: dead &struct task_struct being freed ++ * ++ * Called from free_task() when @task is no longer in use. ++ */ ++static inline void tracehook_free_task(struct task_struct *task) ++{ ++ if (task_utrace_struct(task)) ++ utrace_free_task(task); ++} ++ ++/** + * tracehook_prepare_clone - prepare for new child to be cloned + * @clone_flags: %CLONE_* flags from clone/fork/vfork system call + * +@@ -285,6 +323,8 @@ static inline void tracehook_report_clon + unsigned long clone_flags, + pid_t pid, struct task_struct *child) + { ++ if (unlikely(task_utrace_flags(current) & UTRACE_EVENT(CLONE))) ++ utrace_report_clone(clone_flags, child); + if (unlikely(task_ptrace(child))) { + /* + * It doesn't matter who attached/attaching to this +@@ -317,6 +357,9 @@ static inline void tracehook_report_clon + pid_t pid, + struct task_struct *child) + { ++ if (unlikely(task_utrace_flags(current) & UTRACE_EVENT(CLONE)) && ++ (clone_flags & CLONE_VFORK)) ++ utrace_finish_vfork(current); + if (unlikely(trace)) + ptrace_event(0, trace, pid); + } +@@ -351,6 +394,10 @@ static inline void tracehook_report_vfor + */ + static inline void tracehook_prepare_release_task(struct task_struct *task) + { ++ /* see utrace_add_engine() about this barrier */ ++ smp_mb(); ++ if (task_utrace_flags(task)) ++ utrace_maybe_reap(task, task_utrace_struct(task), true); + } + + /** +@@ -365,6 +412,7 @@ static inline void tracehook_prepare_rel + static inline void tracehook_finish_release_task(struct task_struct *task) + { + ptrace_release_task(task); ++ BUG_ON(task->exit_state != EXIT_DEAD); + } + + /** +@@ -386,6 +434,8 @@ static inline void tracehook_signal_hand + const struct k_sigaction *ka, + struct pt_regs *regs, int stepping) + { ++ if (task_utrace_flags(current)) ++ utrace_signal_handler(current, stepping); + if (stepping && (task_ptrace(current) & PT_PTRACED)) + ptrace_notify(SIGTRAP); + } +@@ -403,6 +453,8 @@ static inline void tracehook_signal_hand + static inline int tracehook_consider_ignored_signal(struct task_struct *task, + int sig) + { ++ if (unlikely(task_utrace_flags(task) & UTRACE_EVENT(SIGNAL_IGN))) ++ return 1; + return (task_ptrace(task) & PT_PTRACED) != 0; + } + +@@ -422,6 +474,9 @@ static inline int tracehook_consider_ign + static inline int tracehook_consider_fatal_signal(struct task_struct *task, + int sig) + { ++ if (unlikely(task_utrace_flags(task) & (UTRACE_EVENT(SIGNAL_TERM) | ++ UTRACE_EVENT(SIGNAL_CORE)))) ++ return 1; + return (task_ptrace(task) & PT_PTRACED) != 0; + } + +@@ -436,6 +491,8 @@ static inline int tracehook_consider_fat + */ + static inline int tracehook_force_sigpending(void) + { ++ if (unlikely(task_utrace_flags(current))) ++ return utrace_interrupt_pending(); + return 0; + } + +@@ -465,6 +522,8 @@ static inline int tracehook_get_signal(s + siginfo_t *info, + struct k_sigaction *return_ka) + { ++ if (unlikely(task_utrace_flags(task))) ++ return utrace_get_signal(task, regs, info, return_ka); + return 0; + } + +@@ -492,6 +551,8 @@ static inline int tracehook_get_signal(s + */ + static inline int tracehook_notify_jctl(int notify, int why) + { ++ if (task_utrace_flags(current) & UTRACE_EVENT(JCTL)) ++ utrace_report_jctl(notify, why); + return notify ?: task_ptrace(current) ? why : 0; + } + +@@ -502,6 +563,8 @@ static inline int tracehook_notify_jctl( + */ + static inline void tracehook_finish_jctl(void) + { ++ if (task_utrace_flags(current)) ++ utrace_finish_stop(); + } + + #define DEATH_REAP -1 +@@ -524,6 +587,8 @@ static inline void tracehook_finish_jctl + static inline int tracehook_notify_death(struct task_struct *task, + void **death_cookie, int group_dead) + { ++ *death_cookie = task_utrace_struct(task); ++ + if (task_detached(task)) + return task->ptrace ? SIGCHLD : DEATH_REAP; + +@@ -560,6 +625,15 @@ static inline void tracehook_report_deat + int signal, void *death_cookie, + int group_dead) + { ++ /* ++ * If utrace_set_events() was just called to enable ++ * UTRACE_EVENT(DEATH), then we are obliged to call ++ * utrace_report_death() and not miss it. utrace_set_events() ++ * checks @task->exit_state under tasklist_lock to synchronize ++ * with exit_notify(), the caller. ++ */ ++ if (task_utrace_flags(task) & _UTRACE_DEATH_EVENTS) ++ utrace_report_death(task, death_cookie, group_dead, signal); + } + + #ifdef TIF_NOTIFY_RESUME +@@ -589,10 +663,21 @@ static inline void set_notify_resume(str + * asynchronously, this will be called again before we return to + * user mode. + * +- * Called without locks. ++ * Called without locks. However, on some machines this may be ++ * called with interrupts disabled. + */ + static inline void tracehook_notify_resume(struct pt_regs *regs) + { ++ struct task_struct *task = current; ++ /* ++ * Prevent the following store/load from getting ahead of the ++ * caller which clears TIF_NOTIFY_RESUME. This pairs with the ++ * implicit mb() before setting TIF_NOTIFY_RESUME in ++ * set_notify_resume(). ++ */ ++ smp_mb(); ++ if (task_utrace_flags(task)) ++ utrace_resume(task, regs); + } + #endif /* TIF_NOTIFY_RESUME */ + +diff --git a/include/linux/utrace.h b/include/linux/utrace.h +new file mode 100644 +index ...f251efe 100644 +--- /dev/null ++++ b/include/linux/utrace.h +@@ -0,0 +1,692 @@ ++/* ++ * utrace infrastructure interface for debugging user processes ++ * ++ * Copyright (C) 2006-2009 Red Hat, Inc. All rights reserved. ++ * ++ * This copyrighted material is made available to anyone wishing to use, ++ * modify, copy, or redistribute it subject to the terms and conditions ++ * of the GNU General Public License v.2. ++ * ++ * Red Hat Author: Roland McGrath. ++ * ++ * This interface allows for notification of interesting events in a ++ * thread. It also mediates access to thread state such as registers. ++ * Multiple unrelated users can be associated with a single thread. ++ * We call each of these a tracing engine. ++ * ++ * A tracing engine starts by calling utrace_attach_task() or ++ * utrace_attach_pid() on the chosen thread, passing in a set of hooks ++ * (&struct utrace_engine_ops), and some associated data. This produces a ++ * &struct utrace_engine, which is the handle used for all other ++ * operations. An attached engine has its ops vector, its data, and an ++ * event mask controlled by utrace_set_events(). ++ * ++ * For each event bit that is set, that engine will get the ++ * appropriate ops->report_*() callback when the event occurs. The ++ * &struct utrace_engine_ops need not provide callbacks for an event ++ * unless the engine sets one of the associated event bits. ++ */ ++ ++#ifndef _LINUX_UTRACE_H ++#define _LINUX_UTRACE_H 1 ++ ++#include ++#include ++#include ++#include ++ ++struct linux_binprm; ++struct pt_regs; ++struct utrace; ++struct user_regset; ++struct user_regset_view; ++ ++/* ++ * Event bits passed to utrace_set_events(). ++ * These appear in &struct task_struct.@utrace_flags ++ * and &struct utrace_engine.@flags. ++ */ ++enum utrace_events { ++ _UTRACE_EVENT_QUIESCE, /* Thread is available for examination. */ ++ _UTRACE_EVENT_REAP, /* Zombie reaped, no more tracing possible. */ ++ _UTRACE_EVENT_CLONE, /* Successful clone/fork/vfork just done. */ ++ _UTRACE_EVENT_EXEC, /* Successful execve just completed. */ ++ _UTRACE_EVENT_EXIT, /* Thread exit in progress. */ ++ _UTRACE_EVENT_DEATH, /* Thread has died. */ ++ _UTRACE_EVENT_SYSCALL_ENTRY, /* User entered kernel for system call. */ ++ _UTRACE_EVENT_SYSCALL_EXIT, /* Returning to user after system call. */ ++ _UTRACE_EVENT_SIGNAL, /* Signal delivery will run a user handler. */ ++ _UTRACE_EVENT_SIGNAL_IGN, /* No-op signal to be delivered. */ ++ _UTRACE_EVENT_SIGNAL_STOP, /* Signal delivery will suspend. */ ++ _UTRACE_EVENT_SIGNAL_TERM, /* Signal delivery will terminate. */ ++ _UTRACE_EVENT_SIGNAL_CORE, /* Signal delivery will dump core. */ ++ _UTRACE_EVENT_JCTL, /* Job control stop or continue completed. */ ++ _UTRACE_NEVENTS ++}; ++#define UTRACE_EVENT(type) (1UL << _UTRACE_EVENT_##type) ++ ++/* ++ * All the kinds of signal events. ++ * These all use the @report_signal() callback. ++ */ ++#define UTRACE_EVENT_SIGNAL_ALL (UTRACE_EVENT(SIGNAL) \ ++ | UTRACE_EVENT(SIGNAL_IGN) \ ++ | UTRACE_EVENT(SIGNAL_STOP) \ ++ | UTRACE_EVENT(SIGNAL_TERM) \ ++ | UTRACE_EVENT(SIGNAL_CORE)) ++/* ++ * Both kinds of syscall events; these call the @report_syscall_entry() ++ * and @report_syscall_exit() callbacks, respectively. ++ */ ++#define UTRACE_EVENT_SYSCALL \ ++ (UTRACE_EVENT(SYSCALL_ENTRY) | UTRACE_EVENT(SYSCALL_EXIT)) ++ ++/* ++ * The event reports triggered synchronously by task death. ++ */ ++#define _UTRACE_DEATH_EVENTS (UTRACE_EVENT(DEATH) | UTRACE_EVENT(QUIESCE)) ++ ++/* ++ * Hooks in call these entry points to the utrace dispatch. ++ */ ++void utrace_free_task(struct task_struct *); ++bool utrace_interrupt_pending(void); ++void utrace_resume(struct task_struct *, struct pt_regs *); ++void utrace_finish_stop(void); ++void utrace_maybe_reap(struct task_struct *, struct utrace *, bool); ++int utrace_get_signal(struct task_struct *, struct pt_regs *, ++ siginfo_t *, struct k_sigaction *); ++void utrace_report_clone(unsigned long, struct task_struct *); ++void utrace_finish_vfork(struct task_struct *); ++void utrace_report_exit(long *exit_code); ++void utrace_report_death(struct task_struct *, struct utrace *, bool, int); ++void utrace_report_jctl(int notify, int type); ++void utrace_report_exec(struct linux_binfmt *, struct linux_binprm *, ++ struct pt_regs *regs); ++bool utrace_report_syscall_entry(struct pt_regs *); ++void utrace_report_syscall_exit(struct pt_regs *); ++void utrace_signal_handler(struct task_struct *, int); ++ ++#ifndef CONFIG_UTRACE ++ ++/* ++ * uses these accessors to avoid #ifdef CONFIG_UTRACE. ++ */ ++static inline unsigned long task_utrace_flags(struct task_struct *task) ++{ ++ return 0; ++} ++static inline struct utrace *task_utrace_struct(struct task_struct *task) ++{ ++ return NULL; ++} ++static inline void utrace_init_task(struct task_struct *child) ++{ ++} ++ ++static inline void task_utrace_proc_status(struct seq_file *m, ++ struct task_struct *p) ++{ ++} ++ ++#else /* CONFIG_UTRACE */ ++ ++static inline unsigned long task_utrace_flags(struct task_struct *task) ++{ ++ return task->utrace_flags; ++} ++ ++static inline struct utrace *task_utrace_struct(struct task_struct *task) ++{ ++ struct utrace *utrace; ++ ++ /* ++ * This barrier ensures that any prior load of task->utrace_flags ++ * is ordered before this load of task->utrace. We use those ++ * utrace_flags checks in the hot path to decide to call into ++ * the utrace code. The first attach installs task->utrace before ++ * setting task->utrace_flags nonzero with implicit barrier in ++ * between, see utrace_add_engine(). ++ */ ++ smp_rmb(); ++ utrace = task->utrace; ++ ++ smp_read_barrier_depends(); /* See utrace_task_alloc(). */ ++ return utrace; ++} ++ ++static inline void utrace_init_task(struct task_struct *task) ++{ ++ task->utrace_flags = 0; ++ task->utrace = NULL; ++} ++ ++void task_utrace_proc_status(struct seq_file *m, struct task_struct *p); ++ ++ ++/* ++ * Version number of the API defined in this file. This will change ++ * whenever a tracing engine's code would need some updates to keep ++ * working. We maintain this here for the benefit of tracing engine code ++ * that is developed concurrently with utrace API improvements before they ++ * are merged into the kernel, making LINUX_VERSION_CODE checks unwieldy. ++ */ ++#define UTRACE_API_VERSION 20091216 ++ ++/** ++ * enum utrace_resume_action - engine's choice of action for a traced task ++ * @UTRACE_STOP: Stay quiescent after callbacks. ++ * @UTRACE_INTERRUPT: Make @report_signal() callback soon. ++ * @UTRACE_REPORT: Make some callback soon. ++ * @UTRACE_SINGLESTEP: Resume in user mode for one instruction. ++ * @UTRACE_BLOCKSTEP: Resume in user mode until next branch. ++ * @UTRACE_RESUME: Resume normally in user mode. ++ * @UTRACE_DETACH: Detach my engine (implies %UTRACE_RESUME). ++ * ++ * See utrace_control() for detailed descriptions of each action. This is ++ * encoded in the @action argument and the return value for every callback ++ * with a &u32 return value. ++ * ++ * The order of these is important. When there is more than one engine, ++ * each supplies its choice and the smallest value prevails. ++ */ ++enum utrace_resume_action { ++ UTRACE_STOP, ++ UTRACE_INTERRUPT, ++ UTRACE_REPORT, ++ UTRACE_SINGLESTEP, ++ UTRACE_BLOCKSTEP, ++ UTRACE_RESUME, ++ UTRACE_DETACH, ++ UTRACE_RESUME_MAX ++}; ++#define UTRACE_RESUME_BITS (ilog2(UTRACE_RESUME_MAX) + 1) ++#define UTRACE_RESUME_MASK ((1 << UTRACE_RESUME_BITS) - 1) ++ ++/** ++ * utrace_resume_action - &enum utrace_resume_action from callback action ++ * @action: &u32 callback @action argument or return value ++ * ++ * This extracts the &enum utrace_resume_action from @action, ++ * which is the @action argument to a &struct utrace_engine_ops ++ * callback or the return value from one. ++ */ ++static inline enum utrace_resume_action utrace_resume_action(u32 action) ++{ ++ return action & UTRACE_RESUME_MASK; ++} ++ ++/** ++ * enum utrace_signal_action - disposition of signal ++ * @UTRACE_SIGNAL_DELIVER: Deliver according to sigaction. ++ * @UTRACE_SIGNAL_IGN: Ignore the signal. ++ * @UTRACE_SIGNAL_TERM: Terminate the process. ++ * @UTRACE_SIGNAL_CORE: Terminate with core dump. ++ * @UTRACE_SIGNAL_STOP: Deliver as absolute stop. ++ * @UTRACE_SIGNAL_TSTP: Deliver as job control stop. ++ * @UTRACE_SIGNAL_REPORT: Reporting before pending signals. ++ * @UTRACE_SIGNAL_HANDLER: Reporting after signal handler setup. ++ * ++ * This is encoded in the @action argument and the return value for ++ * a @report_signal() callback. It says what will happen to the ++ * signal described by the &siginfo_t parameter to the callback. ++ * ++ * The %UTRACE_SIGNAL_REPORT value is used in an @action argument when ++ * a tracing report is being made before dequeuing any pending signal. ++ * If this is immediately after a signal handler has been set up, then ++ * %UTRACE_SIGNAL_HANDLER is used instead. A @report_signal callback ++ * that uses %UTRACE_SIGNAL_DELIVER|%UTRACE_SINGLESTEP will ensure ++ * it sees a %UTRACE_SIGNAL_HANDLER report. ++ */ ++enum utrace_signal_action { ++ UTRACE_SIGNAL_DELIVER = 0x00, ++ UTRACE_SIGNAL_IGN = 0x10, ++ UTRACE_SIGNAL_TERM = 0x20, ++ UTRACE_SIGNAL_CORE = 0x30, ++ UTRACE_SIGNAL_STOP = 0x40, ++ UTRACE_SIGNAL_TSTP = 0x50, ++ UTRACE_SIGNAL_REPORT = 0x60, ++ UTRACE_SIGNAL_HANDLER = 0x70 ++}; ++#define UTRACE_SIGNAL_MASK 0xf0 ++#define UTRACE_SIGNAL_HOLD 0x100 /* Flag, push signal back on queue. */ ++ ++/** ++ * utrace_signal_action - &enum utrace_signal_action from callback action ++ * @action: @report_signal callback @action argument or return value ++ * ++ * This extracts the &enum utrace_signal_action from @action, which ++ * is the @action argument to a @report_signal callback or the ++ * return value from one. ++ */ ++static inline enum utrace_signal_action utrace_signal_action(u32 action) ++{ ++ return action & UTRACE_SIGNAL_MASK; ++} ++ ++/** ++ * enum utrace_syscall_action - disposition of system call attempt ++ * @UTRACE_SYSCALL_RUN: Run the system call. ++ * @UTRACE_SYSCALL_ABORT: Don't run the system call. ++ * ++ * This is encoded in the @action argument and the return value for ++ * a @report_syscall_entry callback. ++ */ ++enum utrace_syscall_action { ++ UTRACE_SYSCALL_RUN = 0x00, ++ UTRACE_SYSCALL_ABORT = 0x10 ++}; ++#define UTRACE_SYSCALL_MASK 0xf0 ++#define UTRACE_SYSCALL_RESUMED 0x100 /* Flag, report_syscall_entry() repeats */ ++ ++/** ++ * utrace_syscall_action - &enum utrace_syscall_action from callback action ++ * @action: @report_syscall_entry callback @action or return value ++ * ++ * This extracts the &enum utrace_syscall_action from @action, which ++ * is the @action argument to a @report_syscall_entry callback or the ++ * return value from one. ++ */ ++static inline enum utrace_syscall_action utrace_syscall_action(u32 action) ++{ ++ return action & UTRACE_SYSCALL_MASK; ++} ++ ++/* ++ * Flags for utrace_attach_task() and utrace_attach_pid(). ++ */ ++#define UTRACE_ATTACH_MATCH_OPS 0x0001 /* Match engines on ops. */ ++#define UTRACE_ATTACH_MATCH_DATA 0x0002 /* Match engines on data. */ ++#define UTRACE_ATTACH_MATCH_MASK 0x000f ++#define UTRACE_ATTACH_CREATE 0x0010 /* Attach a new engine. */ ++#define UTRACE_ATTACH_EXCLUSIVE 0x0020 /* Refuse if existing match. */ ++ ++/** ++ * struct utrace_engine - per-engine structure ++ * @ops: &struct utrace_engine_ops pointer passed to utrace_attach_task() ++ * @data: engine-private &void * passed to utrace_attach_task() ++ * @flags: event mask set by utrace_set_events() plus internal flag bits ++ * ++ * The task itself never has to worry about engines detaching while ++ * it's doing event callbacks. These structures are removed from the ++ * task's active list only when it's stopped, or by the task itself. ++ * ++ * utrace_engine_get() and utrace_engine_put() maintain a reference count. ++ * When it drops to zero, the structure is freed. One reference is held ++ * implicitly while the engine is attached to its task. ++ */ ++struct utrace_engine { ++/* private: */ ++ struct kref kref; ++ void (*release)(void *); ++ struct list_head entry; ++ ++/* public: */ ++ const struct utrace_engine_ops *ops; ++ void *data; ++ ++ unsigned long flags; ++}; ++ ++/** ++ * utrace_engine_get - acquire a reference on a &struct utrace_engine ++ * @engine: &struct utrace_engine pointer ++ * ++ * You must hold a reference on @engine, and you get another. ++ */ ++static inline void utrace_engine_get(struct utrace_engine *engine) ++{ ++ kref_get(&engine->kref); ++} ++ ++void __utrace_engine_release(struct kref *); ++ ++/** ++ * utrace_engine_put - release a reference on a &struct utrace_engine ++ * @engine: &struct utrace_engine pointer ++ * ++ * You must hold a reference on @engine, and you lose that reference. ++ * If it was the last one, @engine becomes an invalid pointer. ++ */ ++static inline void utrace_engine_put(struct utrace_engine *engine) ++{ ++ kref_put(&engine->kref, __utrace_engine_release); ++} ++ ++/** ++ * struct utrace_engine_ops - tracing engine callbacks ++ * ++ * Each @report_*() callback corresponds to an %UTRACE_EVENT(*) bit. ++ * utrace_set_events() calls on @engine choose which callbacks will ++ * be made to @engine from @task. ++ * ++ * Most callbacks take an @action argument, giving the resume action ++ * chosen by other tracing engines. All callbacks take an @engine ++ * argument. The @report_reap callback takes a @task argument that ++ * might or might not be @current. All other @report_* callbacks ++ * report an event in the @current task. ++ * ++ * For some calls, @action also includes bits specific to that event ++ * and utrace_resume_action() is used to extract the resume action. ++ * This shows what would happen if @engine wasn't there, or will if ++ * the callback's return value uses %UTRACE_RESUME. This always ++ * starts as %UTRACE_RESUME when no other tracing is being done on ++ * this task. ++ * ++ * All return values contain &enum utrace_resume_action bits. For ++ * some calls, other bits specific to that kind of event are added to ++ * the resume action bits with OR. These are the same bits used in ++ * the @action argument. The resume action returned by a callback ++ * does not override previous engines' choices, it only says what ++ * @engine wants done. What @current actually does is the action that's ++ * most constrained among the choices made by all attached engines. ++ * See utrace_control() for more information on the actions. ++ * ++ * When %UTRACE_STOP is used in @report_syscall_entry, then @current ++ * stops before attempting the system call. In this case, another ++ * @report_syscall_entry callback will follow after @current resumes if ++ * %UTRACE_REPORT or %UTRACE_INTERRUPT was returned by some callback ++ * or passed to utrace_control(). In a second or later callback, ++ * %UTRACE_SYSCALL_RESUMED is set in the @action argument to indicate ++ * a repeat callback still waiting to attempt the same system call ++ * invocation. This repeat callback gives each engine an opportunity ++ * to reexamine registers another engine might have changed while ++ * @current was held in %UTRACE_STOP. ++ * ++ * In other cases, the resume action does not take effect until @current ++ * is ready to check for signals and return to user mode. If there ++ * are more callbacks to be made, the last round of calls determines ++ * the final action. A @report_quiesce callback with @event zero, or ++ * a @report_signal callback, will always be the last one made before ++ * @current resumes. Only %UTRACE_STOP is "sticky"--if @engine returned ++ * %UTRACE_STOP then @current stays stopped unless @engine returns ++ * different from a following callback. ++ * ++ * The report_death() and report_reap() callbacks do not take @action ++ * arguments, and only %UTRACE_DETACH is meaningful in the return value ++ * from a report_death() callback. None of the resume actions applies ++ * to a dead thread. ++ * ++ * All @report_*() hooks are called with no locks held, in a generally ++ * safe environment when we will be returning to user mode soon (or just ++ * entered the kernel). It is fine to block for memory allocation and ++ * the like, but all hooks are asynchronous and must not block on ++ * external events! If you want the thread to block, use %UTRACE_STOP ++ * in your hook's return value; then later wake it up with utrace_control(). ++ * ++ * @report_quiesce: ++ * Requested by %UTRACE_EVENT(%QUIESCE). ++ * This does not indicate any event, but just that @current is in a ++ * safe place for examination. This call is made before each specific ++ * event callback, except for @report_reap. The @event argument gives ++ * the %UTRACE_EVENT(@which) value for the event occurring. This ++ * callback might be made for events @engine has not requested, if ++ * some other engine is tracing the event; calling utrace_set_events() ++ * call here can request the immediate callback for this occurrence of ++ * @event. @event is zero when there is no other event, @current is ++ * now ready to check for signals and return to user mode, and some ++ * engine has used %UTRACE_REPORT or %UTRACE_INTERRUPT to request this ++ * callback. For this case, if @report_signal is not %NULL, the ++ * @report_quiesce callback may be replaced with a @report_signal ++ * callback passing %UTRACE_SIGNAL_REPORT in its @action argument, ++ * whenever @current is entering the signal-check path anyway. ++ * ++ * @report_signal: ++ * Requested by %UTRACE_EVENT(%SIGNAL_*) or %UTRACE_EVENT(%QUIESCE). ++ * Use utrace_signal_action() and utrace_resume_action() on @action. ++ * The signal action is %UTRACE_SIGNAL_REPORT when some engine has ++ * used %UTRACE_REPORT or %UTRACE_INTERRUPT; the callback can choose ++ * to stop or to deliver an artificial signal, before pending signals. ++ * It's %UTRACE_SIGNAL_HANDLER instead when signal handler setup just ++ * finished (after a previous %UTRACE_SIGNAL_DELIVER return); this ++ * serves in lieu of any %UTRACE_SIGNAL_REPORT callback requested by ++ * %UTRACE_REPORT or %UTRACE_INTERRUPT, and is also implicitly ++ * requested by %UTRACE_SINGLESTEP or %UTRACE_BLOCKSTEP into the ++ * signal delivery. The other signal actions indicate a signal about ++ * to be delivered; the previous engine's return value sets the signal ++ * action seen by the the following engine's callback. The @info data ++ * can be changed at will, including @info->si_signo. The settings in ++ * @return_ka determines what %UTRACE_SIGNAL_DELIVER does. @orig_ka ++ * is what was in force before other tracing engines intervened, and ++ * it's %NULL when this report began as %UTRACE_SIGNAL_REPORT or ++ * %UTRACE_SIGNAL_HANDLER. For a report without a new signal, @info ++ * is left uninitialized and must be set completely by an engine that ++ * chooses to deliver a signal; if there was a previous @report_signal ++ * callback ending in %UTRACE_STOP and it was just resumed using ++ * %UTRACE_REPORT or %UTRACE_INTERRUPT, then @info is left unchanged ++ * from the previous callback. In this way, the original signal can ++ * be left in @info while returning %UTRACE_STOP|%UTRACE_SIGNAL_IGN ++ * and then found again when resuming with %UTRACE_INTERRUPT. ++ * The %UTRACE_SIGNAL_HOLD flag bit can be OR'd into the return value, ++ * and might be in @action if the previous engine returned it. This ++ * flag asks that the signal in @info be pushed back on @current's queue ++ * so that it will be seen again after whatever action is taken now. ++ * ++ * @report_clone: ++ * Requested by %UTRACE_EVENT(%CLONE). ++ * Event reported for parent, before the new task @child might run. ++ * @clone_flags gives the flags used in the clone system call, or ++ * equivalent flags for a fork() or vfork() system call. This ++ * function can use utrace_attach_task() on @child. Then passing ++ * %UTRACE_STOP to utrace_control() on @child here keeps the child ++ * stopped before it ever runs in user mode, %UTRACE_REPORT or ++ * %UTRACE_INTERRUPT ensures a callback from @child before it ++ * starts in user mode. ++ * ++ * @report_jctl: ++ * Requested by %UTRACE_EVENT(%JCTL). ++ * Job control event; @type is %CLD_STOPPED or %CLD_CONTINUED, ++ * indicating whether we are stopping or resuming now. If @notify ++ * is nonzero, @current is the last thread to stop and so will send ++ * %SIGCHLD to its parent after this callback; @notify reflects ++ * what the parent's %SIGCHLD has in @si_code, which can sometimes ++ * be %CLD_STOPPED even when @type is %CLD_CONTINUED. ++ * ++ * @report_exec: ++ * Requested by %UTRACE_EVENT(%EXEC). ++ * An execve system call has succeeded and the new program is about to ++ * start running. The initial user register state is handy to be tweaked ++ * directly in @regs. @fmt and @bprm gives the details of this exec. ++ * ++ * @report_syscall_entry: ++ * Requested by %UTRACE_EVENT(%SYSCALL_ENTRY). ++ * Thread has entered the kernel to request a system call. ++ * The user register state is handy to be tweaked directly in @regs. ++ * The @action argument contains an &enum utrace_syscall_action, ++ * use utrace_syscall_action() to extract it. The return value ++ * overrides the last engine's action for the system call. ++ * If the final action is %UTRACE_SYSCALL_ABORT, no system call ++ * is made. The details of the system call being attempted can ++ * be fetched here with syscall_get_nr() and syscall_get_arguments(). ++ * The parameter registers can be changed with syscall_set_arguments(). ++ * See above about the %UTRACE_SYSCALL_RESUMED flag in @action. ++ * Use %UTRACE_REPORT in the return value to guarantee you get ++ * another callback (with %UTRACE_SYSCALL_RESUMED flag) in case ++ * @current stops with %UTRACE_STOP before attempting the system call. ++ * ++ * @report_syscall_exit: ++ * Requested by %UTRACE_EVENT(%SYSCALL_EXIT). ++ * Thread is about to leave the kernel after a system call request. ++ * The user register state is handy to be tweaked directly in @regs. ++ * The results of the system call attempt can be examined here using ++ * syscall_get_error() and syscall_get_return_value(). It is safe ++ * here to call syscall_set_return_value() or syscall_rollback(). ++ * ++ * @report_exit: ++ * Requested by %UTRACE_EVENT(%EXIT). ++ * Thread is exiting and cannot be prevented from doing so, ++ * but all its state is still live. The @code value will be ++ * the wait result seen by the parent, and can be changed by ++ * this engine or others. The @orig_code value is the real ++ * status, not changed by any tracing engine. Returning %UTRACE_STOP ++ * here keeps @current stopped before it cleans up its state and dies, ++ * so it can be examined by other processes. When @current is allowed ++ * to run, it will die and get to the @report_death callback. ++ * ++ * @report_death: ++ * Requested by %UTRACE_EVENT(%DEATH). ++ * Thread is really dead now. It might be reaped by its parent at ++ * any time, or self-reap immediately. Though the actual reaping ++ * may happen in parallel, a report_reap() callback will always be ++ * ordered after a report_death() callback. ++ * ++ * @report_reap: ++ * Requested by %UTRACE_EVENT(%REAP). ++ * Called when someone reaps the dead task (parent, init, or self). ++ * This means the parent called wait, or else this was a detached ++ * thread or a process whose parent ignores SIGCHLD. ++ * No more callbacks are made after this one. ++ * The engine is always detached. ++ * There is nothing more a tracing engine can do about this thread. ++ * After this callback, the @engine pointer will become invalid. ++ * The @task pointer may become invalid if get_task_struct() hasn't ++ * been used to keep it alive. ++ * An engine should always request this callback if it stores the ++ * @engine pointer or stores any pointer in @engine->data, so it ++ * can clean up its data structures. ++ * Unlike other callbacks, this can be called from the parent's context ++ * rather than from the traced thread itself--it must not delay the ++ * parent by blocking. ++ * ++ * @release: ++ * If not %NULL, this is called after the last utrace_engine_put() ++ * call for a &struct utrace_engine, which could be implicit after ++ * a %UTRACE_DETACH return from another callback. Its argument is ++ * the engine's @data member. ++ */ ++struct utrace_engine_ops { ++ u32 (*report_quiesce)(u32 action, struct utrace_engine *engine, ++ unsigned long event); ++ u32 (*report_signal)(u32 action, struct utrace_engine *engine, ++ struct pt_regs *regs, ++ siginfo_t *info, ++ const struct k_sigaction *orig_ka, ++ struct k_sigaction *return_ka); ++ u32 (*report_clone)(u32 action, struct utrace_engine *engine, ++ unsigned long clone_flags, ++ struct task_struct *child); ++ u32 (*report_jctl)(u32 action, struct utrace_engine *engine, ++ int type, int notify); ++ u32 (*report_exec)(u32 action, struct utrace_engine *engine, ++ const struct linux_binfmt *fmt, ++ const struct linux_binprm *bprm, ++ struct pt_regs *regs); ++ u32 (*report_syscall_entry)(u32 action, struct utrace_engine *engine, ++ struct pt_regs *regs); ++ u32 (*report_syscall_exit)(u32 action, struct utrace_engine *engine, ++ struct pt_regs *regs); ++ u32 (*report_exit)(u32 action, struct utrace_engine *engine, ++ long orig_code, long *code); ++ u32 (*report_death)(struct utrace_engine *engine, ++ bool group_dead, int signal); ++ void (*report_reap)(struct utrace_engine *engine, ++ struct task_struct *task); ++ void (*release)(void *data); ++}; ++ ++/** ++ * struct utrace_examiner - private state for using utrace_prepare_examine() ++ * ++ * The members of &struct utrace_examiner are private to the implementation. ++ * This data type holds the state from a call to utrace_prepare_examine() ++ * to be used by a call to utrace_finish_examine(). ++ */ ++struct utrace_examiner { ++/* private: */ ++ long state; ++ unsigned long ncsw; ++}; ++ ++/* ++ * These are the exported entry points for tracing engines to use. ++ * See kernel/utrace.c for their kerneldoc comments with interface details. ++ */ ++struct utrace_engine *utrace_attach_task(struct task_struct *, int, ++ const struct utrace_engine_ops *, ++ void *); ++struct utrace_engine *utrace_attach_pid(struct pid *, int, ++ const struct utrace_engine_ops *, ++ void *); ++int __must_check utrace_control(struct task_struct *, ++ struct utrace_engine *, ++ enum utrace_resume_action); ++int __must_check utrace_set_events(struct task_struct *, ++ struct utrace_engine *, ++ unsigned long eventmask); ++int __must_check utrace_barrier(struct task_struct *, ++ struct utrace_engine *); ++int __must_check utrace_prepare_examine(struct task_struct *, ++ struct utrace_engine *, ++ struct utrace_examiner *); ++int __must_check utrace_finish_examine(struct task_struct *, ++ struct utrace_engine *, ++ struct utrace_examiner *); ++ ++/** ++ * utrace_control_pid - control a thread being traced by a tracing engine ++ * @pid: thread to affect ++ * @engine: attached engine to affect ++ * @action: &enum utrace_resume_action for thread to do ++ * ++ * This is the same as utrace_control(), but takes a &struct pid ++ * pointer rather than a &struct task_struct pointer. The caller must ++ * hold a ref on @pid, but does not need to worry about the task ++ * staying valid. If it's been reaped so that @pid points nowhere, ++ * then this call returns -%ESRCH. ++ */ ++static inline __must_check int utrace_control_pid( ++ struct pid *pid, struct utrace_engine *engine, ++ enum utrace_resume_action action) ++{ ++ /* ++ * We don't bother with rcu_read_lock() here to protect the ++ * task_struct pointer, because utrace_control will return ++ * -ESRCH without looking at that pointer if the engine is ++ * already detached. A task_struct pointer can't die before ++ * all the engines are detached in release_task() first. ++ */ ++ struct task_struct *task = pid_task(pid, PIDTYPE_PID); ++ return unlikely(!task) ? -ESRCH : utrace_control(task, engine, action); ++} ++ ++/** ++ * utrace_set_events_pid - choose which event reports a tracing engine gets ++ * @pid: thread to affect ++ * @engine: attached engine to affect ++ * @eventmask: new event mask ++ * ++ * This is the same as utrace_set_events(), but takes a &struct pid ++ * pointer rather than a &struct task_struct pointer. The caller must ++ * hold a ref on @pid, but does not need to worry about the task ++ * staying valid. If it's been reaped so that @pid points nowhere, ++ * then this call returns -%ESRCH. ++ */ ++static inline __must_check int utrace_set_events_pid( ++ struct pid *pid, struct utrace_engine *engine, unsigned long eventmask) ++{ ++ struct task_struct *task = pid_task(pid, PIDTYPE_PID); ++ return unlikely(!task) ? -ESRCH : ++ utrace_set_events(task, engine, eventmask); ++} ++ ++/** ++ * utrace_barrier_pid - synchronize with simultaneous tracing callbacks ++ * @pid: thread to affect ++ * @engine: engine to affect (can be detached) ++ * ++ * This is the same as utrace_barrier(), but takes a &struct pid ++ * pointer rather than a &struct task_struct pointer. The caller must ++ * hold a ref on @pid, but does not need to worry about the task ++ * staying valid. If it's been reaped so that @pid points nowhere, ++ * then this call returns -%ESRCH. ++ */ ++static inline __must_check int utrace_barrier_pid(struct pid *pid, ++ struct utrace_engine *engine) ++{ ++ struct task_struct *task = pid_task(pid, PIDTYPE_PID); ++ return unlikely(!task) ? -ESRCH : utrace_barrier(task, engine); ++} ++ ++#endif /* CONFIG_UTRACE */ ++ ++#endif /* linux/utrace.h */ +diff --git a/init/Kconfig b/init/Kconfig +index d95ca7c..6d52a08 100644 +--- a/init/Kconfig ++++ b/init/Kconfig +@@ -320,6 +320,15 @@ config AUDIT_TREE + depends on AUDITSYSCALL + select INOTIFY + ++config UTRACE ++ bool "Infrastructure for tracing and debugging user processes" ++ depends on EXPERIMENTAL ++ depends on HAVE_ARCH_TRACEHOOK ++ help ++ Enable the utrace process tracing interface. This is an internal ++ kernel interface exported to kernel modules, to track events in ++ user threads, extract and change user thread state. ++ + menu "RCU Subsystem" + + choice +diff --git a/kernel/Makefile b/kernel/Makefile +index 864ff75..8a0185e 100644 +--- a/kernel/Makefile ++++ b/kernel/Makefile +@@ -69,6 +69,7 @@ obj-$(CONFIG_IKCONFIG) += configs.o + obj-$(CONFIG_RESOURCE_COUNTERS) += res_counter.o + obj-$(CONFIG_STOP_MACHINE) += stop_machine.o + obj-$(CONFIG_KPROBES_SANITY_TEST) += test_kprobes.o ++obj-$(CONFIG_UTRACE) += utrace.o + obj-$(CONFIG_AUDIT) += audit.o auditfilter.o audit_watch.o + obj-$(CONFIG_AUDITSYSCALL) += auditsc.o + obj-$(CONFIG_GCOV_KERNEL) += gcov/ +diff --git a/kernel/fork.c b/kernel/fork.c +index f88bd98..2b6820c 100644 +--- a/kernel/fork.c ++++ b/kernel/fork.c +@@ -153,6 +153,7 @@ void free_task(struct task_struct *tsk) + free_thread_info(tsk->stack); + rt_mutex_debug_task_free(tsk); + ftrace_graph_exit_task(tsk); ++ tracehook_free_task(tsk); + free_task_struct(tsk); + } + EXPORT_SYMBOL(free_task); +@@ -1023,6 +1024,8 @@ static struct task_struct *copy_process( + if (!p) + goto fork_out; + ++ tracehook_init_task(p); ++ + ftrace_graph_init_task(p); + + rt_mutex_init_task(p); +diff --git a/kernel/ptrace.c b/kernel/ptrace.c +index b7c1d32..a408bf7 100644 +--- a/kernel/ptrace.c ++++ b/kernel/ptrace.c +@@ -16,6 +16,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -164,6 +165,14 @@ bool ptrace_may_access(struct task_struc + return !err; + } + ++/* ++ * For experimental use of utrace, exclude ptrace on the same task. ++ */ ++static inline bool exclude_ptrace(struct task_struct *task) ++{ ++ return unlikely(!!task_utrace_flags(task)); ++} ++ + int ptrace_attach(struct task_struct *task) + { + int retval; +@@ -187,6 +196,8 @@ int ptrace_attach(struct task_struct *ta + + task_lock(task); + retval = __ptrace_may_access(task, PTRACE_MODE_ATTACH); ++ if (!retval && exclude_ptrace(task)) ++ retval = -EBUSY; + task_unlock(task); + if (retval) + goto unlock_creds; +@@ -224,6 +235,9 @@ int ptrace_traceme(void) + { + int ret = -EPERM; + ++ if (exclude_ptrace(current)) /* XXX locking */ ++ return -EBUSY; ++ + write_lock_irq(&tasklist_lock); + /* Are we already being traced? */ + if (!current->ptrace) { +diff --git a/kernel/utrace.c b/kernel/utrace.c +new file mode 100644 +index ...f003e34 100644 +--- /dev/null ++++ b/kernel/utrace.c +@@ -0,0 +1,2436 @@ ++/* ++ * utrace infrastructure interface for debugging user processes ++ * ++ * Copyright (C) 2006-2010 Red Hat, Inc. All rights reserved. ++ * ++ * This copyrighted material is made available to anyone wishing to use, ++ * modify, copy, or redistribute it subject to the terms and conditions ++ * of the GNU General Public License v.2. ++ * ++ * Red Hat Author: Roland McGrath. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++ ++/* ++ * Per-thread structure private to utrace implementation. ++ * If task_struct.utrace_flags is nonzero, task_struct.utrace ++ * has always been allocated first. Once allocated, it is ++ * never freed until free_task(). ++ * ++ * The common event reporting loops are done by the task making the ++ * report without ever taking any locks. To facilitate this, the two ++ * lists @attached and @attaching work together for smooth asynchronous ++ * attaching with low overhead. Modifying either list requires @lock. ++ * The @attaching list can be modified any time while holding @lock. ++ * New engines being attached always go on this list. ++ * ++ * The @attached list is what the task itself uses for its reporting ++ * loops. When the task itself is not quiescent, it can use the ++ * @attached list without taking any lock. Nobody may modify the list ++ * when the task is not quiescent. When it is quiescent, that means ++ * that it won't run again without taking @lock itself before using ++ * the list. ++ * ++ * At each place where we know the task is quiescent (or it's current), ++ * while holding @lock, we call splice_attaching(), below. This moves ++ * the @attaching list members on to the end of the @attached list. ++ * Since this happens at the start of any reporting pass, any new ++ * engines attached asynchronously go on the stable @attached list ++ * in time to have their callbacks seen. ++ */ ++struct utrace { ++ spinlock_t lock; ++ struct list_head attached, attaching; ++ ++ struct task_struct *cloning; ++ ++ struct utrace_engine *reporting; ++ ++ enum utrace_resume_action resume:UTRACE_RESUME_BITS; ++ unsigned int signal_handler:1; ++ unsigned int vfork_stop:1; /* need utrace_stop() before vfork wait */ ++ unsigned int death:1; /* in utrace_report_death() now */ ++ unsigned int reap:1; /* release_task() has run */ ++ unsigned int pending_attach:1; /* need splice_attaching() */ ++}; ++ ++static struct kmem_cache *utrace_cachep; ++static struct kmem_cache *utrace_engine_cachep; ++static const struct utrace_engine_ops utrace_detached_ops; /* forward decl */ ++ ++static int __init utrace_init(void) ++{ ++ utrace_cachep = KMEM_CACHE(utrace, SLAB_PANIC); ++ utrace_engine_cachep = KMEM_CACHE(utrace_engine, SLAB_PANIC); ++ return 0; ++} ++module_init(utrace_init); ++ ++/* ++ * Set up @task.utrace for the first time. We can have races ++ * between two utrace_attach_task() calls here. The task_lock() ++ * governs installing the new pointer. If another one got in first, ++ * we just punt the new one we allocated. ++ * ++ * This returns false only in case of a memory allocation failure. ++ */ ++static bool utrace_task_alloc(struct task_struct *task) ++{ ++ struct utrace *utrace = kmem_cache_zalloc(utrace_cachep, GFP_KERNEL); ++ if (unlikely(!utrace)) ++ return false; ++ spin_lock_init(&utrace->lock); ++ INIT_LIST_HEAD(&utrace->attached); ++ INIT_LIST_HEAD(&utrace->attaching); ++ utrace->resume = UTRACE_RESUME; ++ task_lock(task); ++ if (likely(!task->utrace)) { ++ /* ++ * This barrier makes sure the initialization of the struct ++ * precedes the installation of the pointer. This pairs ++ * with smp_read_barrier_depends() in task_utrace_struct(). ++ */ ++ smp_wmb(); ++ task->utrace = utrace; ++ } ++ task_unlock(task); ++ ++ if (unlikely(task->utrace != utrace)) ++ kmem_cache_free(utrace_cachep, utrace); ++ return true; ++} ++ ++/* ++ * This is called via tracehook_free_task() from free_task() ++ * when @task is being deallocated. ++ */ ++void utrace_free_task(struct task_struct *task) ++{ ++ kmem_cache_free(utrace_cachep, task->utrace); ++} ++ ++/* ++ * This is calledwhen the task is safely quiescent, i.e. it won't consult ++ * utrace->attached without the lock. Move any engines attached ++ * asynchronously from @utrace->attaching onto the @utrace->attached list. ++ */ ++static void splice_attaching(struct utrace *utrace) ++{ ++ lockdep_assert_held(&utrace->lock); ++ list_splice_tail_init(&utrace->attaching, &utrace->attached); ++ utrace->pending_attach = 0; ++} ++ ++/* ++ * This is the exported function used by the utrace_engine_put() inline. ++ */ ++void __utrace_engine_release(struct kref *kref) ++{ ++ struct utrace_engine *engine = container_of(kref, struct utrace_engine, ++ kref); ++ BUG_ON(!list_empty(&engine->entry)); ++ if (engine->release) ++ (*engine->release)(engine->data); ++ kmem_cache_free(utrace_engine_cachep, engine); ++} ++EXPORT_SYMBOL_GPL(__utrace_engine_release); ++ ++static bool engine_matches(struct utrace_engine *engine, int flags, ++ const struct utrace_engine_ops *ops, void *data) ++{ ++ if ((flags & UTRACE_ATTACH_MATCH_OPS) && engine->ops != ops) ++ return false; ++ if ((flags & UTRACE_ATTACH_MATCH_DATA) && engine->data != data) ++ return false; ++ return engine->ops && engine->ops != &utrace_detached_ops; ++} ++ ++static struct utrace_engine *find_matching_engine( ++ struct utrace *utrace, int flags, ++ const struct utrace_engine_ops *ops, void *data) ++{ ++ struct utrace_engine *engine; ++ list_for_each_entry(engine, &utrace->attached, entry) ++ if (engine_matches(engine, flags, ops, data)) ++ return engine; ++ list_for_each_entry(engine, &utrace->attaching, entry) ++ if (engine_matches(engine, flags, ops, data)) ++ return engine; ++ return NULL; ++} ++ ++/* ++ * Enqueue @engine, or maybe don't if UTRACE_ATTACH_EXCLUSIVE. ++ */ ++static int utrace_add_engine(struct task_struct *target, ++ struct utrace *utrace, ++ struct utrace_engine *engine, ++ int flags, ++ const struct utrace_engine_ops *ops, ++ void *data) ++{ ++ int ret; ++ ++ spin_lock(&utrace->lock); ++ ++ ret = -EEXIST; ++ if ((flags & UTRACE_ATTACH_EXCLUSIVE) && ++ unlikely(find_matching_engine(utrace, flags, ops, data))) ++ goto unlock; ++ ++ /* ++ * In case we had no engines before, make sure that ++ * utrace_flags is not zero. Since we did unlock+lock ++ * at least once after utrace_task_alloc() installed ++ * ->utrace, we have the necessary barrier which pairs ++ * with rmb() in task_utrace_struct(). ++ */ ++ ret = -ESRCH; ++ if (!target->utrace_flags) { ++ target->utrace_flags = UTRACE_EVENT(REAP); ++ /* ++ * If we race with tracehook_prepare_release_task() ++ * make sure that either it sees utrace_flags != 0 ++ * or we see exit_state == EXIT_DEAD. ++ */ ++ smp_mb(); ++ if (unlikely(target->exit_state == EXIT_DEAD)) { ++ target->utrace_flags = 0; ++ goto unlock; ++ } ++ } ++ ++ /* ++ * Put the new engine on the pending ->attaching list. ++ * Make sure it gets onto the ->attached list by the next ++ * time it's examined. Setting ->pending_attach ensures ++ * that start_report() takes the lock and splices the lists ++ * before the next new reporting pass. ++ * ++ * When target == current, it would be safe just to call ++ * splice_attaching() right here. But if we're inside a ++ * callback, that would mean the new engine also gets ++ * notified about the event that precipitated its own ++ * creation. This is not what the user wants. ++ */ ++ list_add_tail(&engine->entry, &utrace->attaching); ++ utrace->pending_attach = 1; ++ ret = 0; ++unlock: ++ spin_unlock(&utrace->lock); ++ ++ return ret; ++} ++ ++/** ++ * utrace_attach_task - attach new engine, or look up an attached engine ++ * @target: thread to attach to ++ * @flags: flag bits combined with OR, see below ++ * @ops: callback table for new engine ++ * @data: engine private data pointer ++ * ++ * The caller must ensure that the @target thread does not get freed, ++ * i.e. hold a ref or be its parent. It is always safe to call this ++ * on @current, or on the @child pointer in a @report_clone callback. ++ * For most other cases, it's easier to use utrace_attach_pid() instead. ++ * ++ * UTRACE_ATTACH_CREATE: ++ * Create a new engine. If %UTRACE_ATTACH_CREATE is not specified, you ++ * only look up an existing engine already attached to the thread. ++ * ++ * UTRACE_ATTACH_EXCLUSIVE: ++ * Attempting to attach a second (matching) engine fails with -%EEXIST. ++ * ++ * UTRACE_ATTACH_MATCH_OPS: Only consider engines matching @ops. ++ * UTRACE_ATTACH_MATCH_DATA: Only consider engines matching @data. ++ * ++ * Calls with neither %UTRACE_ATTACH_MATCH_OPS nor %UTRACE_ATTACH_MATCH_DATA ++ * match the first among any engines attached to @target. That means that ++ * %UTRACE_ATTACH_EXCLUSIVE in such a call fails with -%EEXIST if there ++ * are any engines on @target at all. ++ */ ++struct utrace_engine *utrace_attach_task( ++ struct task_struct *target, int flags, ++ const struct utrace_engine_ops *ops, void *data) ++{ ++ struct utrace *utrace = task_utrace_struct(target); ++ struct utrace_engine *engine; ++ int ret; ++ ++ if (!(flags & UTRACE_ATTACH_CREATE)) { ++ if (unlikely(!utrace)) ++ return ERR_PTR(-ENOENT); ++ spin_lock(&utrace->lock); ++ engine = find_matching_engine(utrace, flags, ops, data); ++ if (engine) ++ utrace_engine_get(engine); ++ spin_unlock(&utrace->lock); ++ return engine ?: ERR_PTR(-ENOENT); ++ } ++ ++ if (unlikely(!ops) || unlikely(ops == &utrace_detached_ops)) ++ return ERR_PTR(-EINVAL); ++ ++ if (unlikely(target->flags & PF_KTHREAD)) ++ /* ++ * Silly kernel, utrace is for users! ++ */ ++ return ERR_PTR(-EPERM); ++ ++ if (!utrace) { ++ if (unlikely(!utrace_task_alloc(target))) ++ return ERR_PTR(-ENOMEM); ++ utrace = task_utrace_struct(target); ++ } ++ ++ engine = kmem_cache_alloc(utrace_engine_cachep, GFP_KERNEL); ++ if (unlikely(!engine)) ++ return ERR_PTR(-ENOMEM); ++ ++ /* ++ * Initialize the new engine structure. It starts out with two ++ * refs: one ref to return, and one ref for being attached. ++ */ ++ kref_set(&engine->kref, 2); ++ engine->flags = 0; ++ engine->ops = ops; ++ engine->data = data; ++ engine->release = ops->release; ++ ++ ret = utrace_add_engine(target, utrace, engine, flags, ops, data); ++ ++ if (unlikely(ret)) { ++ kmem_cache_free(utrace_engine_cachep, engine); ++ engine = ERR_PTR(ret); ++ } ++ ++ return engine; ++} ++EXPORT_SYMBOL_GPL(utrace_attach_task); ++ ++/** ++ * utrace_attach_pid - attach new engine, or look up an attached engine ++ * @pid: &struct pid pointer representing thread to attach to ++ * @flags: flag bits combined with OR, see utrace_attach_task() ++ * @ops: callback table for new engine ++ * @data: engine private data pointer ++ * ++ * This is the same as utrace_attach_task(), but takes a &struct pid ++ * pointer rather than a &struct task_struct pointer. The caller must ++ * hold a ref on @pid, but does not need to worry about the task ++ * staying valid. If it's been reaped so that @pid points nowhere, ++ * then this call returns -%ESRCH. ++ */ ++struct utrace_engine *utrace_attach_pid( ++ struct pid *pid, int flags, ++ const struct utrace_engine_ops *ops, void *data) ++{ ++ struct utrace_engine *engine = ERR_PTR(-ESRCH); ++ struct task_struct *task = get_pid_task(pid, PIDTYPE_PID); ++ if (task) { ++ engine = utrace_attach_task(task, flags, ops, data); ++ put_task_struct(task); ++ } ++ return engine; ++} ++EXPORT_SYMBOL_GPL(utrace_attach_pid); ++ ++/* ++ * When an engine is detached, the target thread may still see it and ++ * make callbacks until it quiesces. We install a special ops vector ++ * with these two callbacks. When the target thread quiesces, it can ++ * safely free the engine itself. For any event we will always get ++ * the report_quiesce() callback first, so we only need this one ++ * pointer to be set. The only exception is report_reap(), so we ++ * supply that callback too. ++ */ ++static u32 utrace_detached_quiesce(u32 action, struct utrace_engine *engine, ++ unsigned long event) ++{ ++ return UTRACE_DETACH; ++} ++ ++static void utrace_detached_reap(struct utrace_engine *engine, ++ struct task_struct *task) ++{ ++} ++ ++static const struct utrace_engine_ops utrace_detached_ops = { ++ .report_quiesce = &utrace_detached_quiesce, ++ .report_reap = &utrace_detached_reap ++}; ++ ++/* ++ * The caller has to hold a ref on the engine. If the attached flag is ++ * true (all but utrace_barrier() calls), the engine is supposed to be ++ * attached. If the attached flag is false (utrace_barrier() only), ++ * then return -ERESTARTSYS for an engine marked for detach but not yet ++ * fully detached. The task pointer can be invalid if the engine is ++ * detached. ++ * ++ * Get the utrace lock for the target task. ++ * Returns the struct if locked, or ERR_PTR(-errno). ++ * ++ * This has to be robust against races with: ++ * utrace_control(target, UTRACE_DETACH) calls ++ * UTRACE_DETACH after reports ++ * utrace_report_death ++ * utrace_release_task ++ */ ++static struct utrace *get_utrace_lock(struct task_struct *target, ++ struct utrace_engine *engine, ++ bool attached) ++ __acquires(utrace->lock) ++{ ++ struct utrace *utrace; ++ ++ rcu_read_lock(); ++ ++ /* ++ * If this engine was already detached, bail out before we look at ++ * the task_struct pointer at all. If it's detached after this ++ * check, then RCU is still keeping this task_struct pointer valid. ++ * ++ * The ops pointer is NULL when the engine is fully detached. ++ * It's &utrace_detached_ops when it's marked detached but still ++ * on the list. In the latter case, utrace_barrier() still works, ++ * since the target might be in the middle of an old callback. ++ */ ++ if (unlikely(!engine->ops)) { ++ rcu_read_unlock(); ++ return ERR_PTR(-ESRCH); ++ } ++ ++ if (unlikely(engine->ops == &utrace_detached_ops)) { ++ rcu_read_unlock(); ++ return attached ? ERR_PTR(-ESRCH) : ERR_PTR(-ERESTARTSYS); ++ } ++ ++ utrace = task_utrace_struct(target); ++ spin_lock(&utrace->lock); ++ if (unlikely(!engine->ops) || ++ unlikely(engine->ops == &utrace_detached_ops)) { ++ /* ++ * By the time we got the utrace lock, ++ * it had been reaped or detached already. ++ */ ++ spin_unlock(&utrace->lock); ++ utrace = ERR_PTR(-ESRCH); ++ if (!attached && engine->ops == &utrace_detached_ops) ++ utrace = ERR_PTR(-ERESTARTSYS); ++ } ++ rcu_read_unlock(); ++ ++ return utrace; ++} ++ ++/* ++ * Now that we don't hold any locks, run through any ++ * detached engines and free their references. Each ++ * engine had one implicit ref while it was attached. ++ */ ++static void put_detached_list(struct list_head *list) ++{ ++ struct utrace_engine *engine, *next; ++ list_for_each_entry_safe(engine, next, list, entry) { ++ list_del_init(&engine->entry); ++ utrace_engine_put(engine); ++ } ++} ++ ++/* ++ * We use an extra bit in utrace_engine.flags past the event bits, ++ * to record whether the engine is keeping the target thread stopped. ++ * ++ * This bit is set in task_struct.utrace_flags whenever it is set in any ++ * engine's flags. Only utrace_reset() resets it in utrace_flags. ++ */ ++#define ENGINE_STOP (1UL << _UTRACE_NEVENTS) ++ ++static void mark_engine_wants_stop(struct task_struct *task, ++ struct utrace_engine *engine) ++{ ++ engine->flags |= ENGINE_STOP; ++ task->utrace_flags |= ENGINE_STOP; ++} ++ ++static void clear_engine_wants_stop(struct utrace_engine *engine) ++{ ++ engine->flags &= ~ENGINE_STOP; ++} ++ ++static bool engine_wants_stop(struct utrace_engine *engine) ++{ ++ return (engine->flags & ENGINE_STOP) != 0; ++} ++ ++/** ++ * utrace_set_events - choose which event reports a tracing engine gets ++ * @target: thread to affect ++ * @engine: attached engine to affect ++ * @events: new event mask ++ * ++ * This changes the set of events for which @engine wants callbacks made. ++ * ++ * This fails with -%EALREADY and does nothing if you try to clear ++ * %UTRACE_EVENT(%DEATH) when the @report_death callback may already have ++ * begun, if you try to clear %UTRACE_EVENT(%REAP) when the @report_reap ++ * callback may already have begun, or if you try to newly set ++ * %UTRACE_EVENT(%DEATH) or %UTRACE_EVENT(%QUIESCE) when @target is ++ * already dead or dying. ++ * ++ * This can fail with -%ESRCH when @target has already been detached, ++ * including forcible detach on reaping. ++ * ++ * If @target was stopped before the call, then after a successful call, ++ * no event callbacks not requested in @events will be made; if ++ * %UTRACE_EVENT(%QUIESCE) is included in @events, then a ++ * @report_quiesce callback will be made when @target resumes. ++ * ++ * If @target was not stopped and @events excludes some bits that were ++ * set before, this can return -%EINPROGRESS to indicate that @target ++ * may have been making some callback to @engine. When this returns ++ * zero, you can be sure that no event callbacks you've disabled in ++ * @events can be made. If @events only sets new bits that were not set ++ * before on @engine, then -%EINPROGRESS will never be returned. ++ * ++ * To synchronize after an -%EINPROGRESS return, see utrace_barrier(). ++ * ++ * When @target is @current, -%EINPROGRESS is not returned. But note ++ * that a newly-created engine will not receive any callbacks related to ++ * an event notification already in progress. This call enables @events ++ * callbacks to be made as soon as @engine becomes eligible for any ++ * callbacks, see utrace_attach_task(). ++ * ++ * These rules provide for coherent synchronization based on %UTRACE_STOP, ++ * even when %SIGKILL is breaking its normal simple rules. ++ */ ++int utrace_set_events(struct task_struct *target, ++ struct utrace_engine *engine, ++ unsigned long events) ++{ ++ struct utrace *utrace; ++ unsigned long old_flags, old_utrace_flags; ++ int ret; ++ ++ /* ++ * We just ignore the internal bit, so callers can use ++ * engine->flags to seed bitwise ops for our argument. ++ */ ++ events &= ~ENGINE_STOP; ++ ++ utrace = get_utrace_lock(target, engine, true); ++ if (unlikely(IS_ERR(utrace))) ++ return PTR_ERR(utrace); ++ ++ old_utrace_flags = target->utrace_flags; ++ old_flags = engine->flags & ~ENGINE_STOP; ++ ++ if (target->exit_state && ++ (((events & ~old_flags) & _UTRACE_DEATH_EVENTS) || ++ (utrace->death && ++ ((old_flags & ~events) & _UTRACE_DEATH_EVENTS)) || ++ (utrace->reap && ((old_flags & ~events) & UTRACE_EVENT(REAP))))) { ++ spin_unlock(&utrace->lock); ++ return -EALREADY; ++ } ++ ++ /* ++ * When setting these flags, it's essential that we really ++ * synchronize with exit_notify(). They cannot be set after ++ * exit_notify() takes the tasklist_lock. By holding the read ++ * lock here while setting the flags, we ensure that the calls ++ * to tracehook_notify_death() and tracehook_report_death() will ++ * see the new flags. This ensures that utrace_release_task() ++ * knows positively that utrace_report_death() will be called or ++ * that it won't. ++ */ ++ if ((events & ~old_utrace_flags) & _UTRACE_DEATH_EVENTS) { ++ read_lock(&tasklist_lock); ++ if (unlikely(target->exit_state)) { ++ read_unlock(&tasklist_lock); ++ spin_unlock(&utrace->lock); ++ return -EALREADY; ++ } ++ target->utrace_flags |= events; ++ read_unlock(&tasklist_lock); ++ } ++ ++ engine->flags = events | (engine->flags & ENGINE_STOP); ++ target->utrace_flags |= events; ++ ++ if ((events & UTRACE_EVENT_SYSCALL) && ++ !(old_utrace_flags & UTRACE_EVENT_SYSCALL)) ++ set_tsk_thread_flag(target, TIF_SYSCALL_TRACE); ++ ++ ret = 0; ++ if ((old_flags & ~events) && target != current && ++ !task_is_stopped_or_traced(target) && !target->exit_state) { ++ /* ++ * This barrier ensures that our engine->flags changes ++ * have hit before we examine utrace->reporting, ++ * pairing with the barrier in start_callback(). If ++ * @target has not yet hit finish_callback() to clear ++ * utrace->reporting, we might be in the middle of a ++ * callback to @engine. ++ */ ++ smp_mb(); ++ if (utrace->reporting == engine) ++ ret = -EINPROGRESS; ++ } ++ ++ spin_unlock(&utrace->lock); ++ ++ return ret; ++} ++EXPORT_SYMBOL_GPL(utrace_set_events); ++ ++/* ++ * Asynchronously mark an engine as being detached. ++ * ++ * This must work while the target thread races with us doing ++ * start_callback(), defined below. It uses smp_rmb() between checking ++ * @engine->flags and using @engine->ops. Here we change @engine->ops ++ * first, then use smp_wmb() before changing @engine->flags. This ensures ++ * it can check the old flags before using the old ops, or check the old ++ * flags before using the new ops, or check the new flags before using the ++ * new ops, but can never check the new flags before using the old ops. ++ * Hence, utrace_detached_ops might be used with any old flags in place. ++ * It has report_quiesce() and report_reap() callbacks to handle all cases. ++ */ ++static void mark_engine_detached(struct utrace_engine *engine) ++{ ++ engine->ops = &utrace_detached_ops; ++ smp_wmb(); ++ engine->flags = UTRACE_EVENT(QUIESCE); ++} ++ ++/* ++ * Get @target to stop and return true if it is already stopped now. ++ * If we return false, it will make some event callback soonish. ++ * Called with @utrace locked. ++ */ ++static bool utrace_do_stop(struct task_struct *target, struct utrace *utrace) ++{ ++ if (task_is_stopped(target)) { ++ /* ++ * Stopped is considered quiescent; when it wakes up, it will ++ * go through utrace_finish_stop() before doing anything else. ++ */ ++ spin_lock_irq(&target->sighand->siglock); ++ if (likely(task_is_stopped(target))) ++ __set_task_state(target, TASK_TRACED); ++ spin_unlock_irq(&target->sighand->siglock); ++ } else if (utrace->resume > UTRACE_REPORT) { ++ utrace->resume = UTRACE_REPORT; ++ set_notify_resume(target); ++ } ++ ++ return task_is_traced(target); ++} ++ ++/* ++ * If the target is not dead it should not be in tracing ++ * stop any more. Wake it unless it's in job control stop. ++ */ ++static void utrace_wakeup(struct task_struct *target, struct utrace *utrace) ++{ ++ lockdep_assert_held(&utrace->lock); ++ spin_lock_irq(&target->sighand->siglock); ++ if (target->signal->flags & SIGNAL_STOP_STOPPED || ++ target->signal->group_stop_count) ++ target->state = TASK_STOPPED; ++ else ++ wake_up_state(target, __TASK_TRACED); ++ spin_unlock_irq(&target->sighand->siglock); ++} ++ ++/* ++ * This is called when there might be some detached engines on the list or ++ * some stale bits in @task->utrace_flags. Clean them up and recompute the ++ * flags. Returns true if we're now fully detached. ++ * ++ * Called with @utrace->lock held, returns with it released. ++ * After this returns, @utrace might be freed if everything detached. ++ */ ++static bool utrace_reset(struct task_struct *task, struct utrace *utrace) ++ __releases(utrace->lock) ++{ ++ struct utrace_engine *engine, *next; ++ unsigned long flags = 0; ++ LIST_HEAD(detached); ++ ++ splice_attaching(utrace); ++ ++ /* ++ * Update the set of events of interest from the union ++ * of the interests of the remaining tracing engines. ++ * For any engine marked detached, remove it from the list. ++ * We'll collect them on the detached list. ++ */ ++ list_for_each_entry_safe(engine, next, &utrace->attached, entry) { ++ if (engine->ops == &utrace_detached_ops) { ++ engine->ops = NULL; ++ list_move(&engine->entry, &detached); ++ } else { ++ flags |= engine->flags | UTRACE_EVENT(REAP); ++ } ++ } ++ ++ if (task->exit_state) { ++ /* ++ * Once it's already dead, we never install any flags ++ * except REAP. When ->exit_state is set and events ++ * like DEATH are not set, then they never can be set. ++ * This ensures that utrace_release_task() knows ++ * positively that utrace_report_death() can never run. ++ */ ++ BUG_ON(utrace->death); ++ flags &= UTRACE_EVENT(REAP); ++ } else if (!(flags & UTRACE_EVENT_SYSCALL) && ++ test_tsk_thread_flag(task, TIF_SYSCALL_TRACE)) { ++ clear_tsk_thread_flag(task, TIF_SYSCALL_TRACE); ++ } ++ ++ if (!flags) { ++ /* ++ * No more engines, cleared out the utrace. ++ */ ++ utrace->resume = UTRACE_RESUME; ++ utrace->signal_handler = 0; ++ } ++ ++ /* ++ * If no more engines want it stopped, wake it up. ++ */ ++ if (task_is_traced(task) && !(flags & ENGINE_STOP)) ++ utrace_wakeup(task, utrace); ++ ++ /* ++ * In theory spin_lock() doesn't imply rcu_read_lock(). ++ * Once we clear ->utrace_flags this task_struct can go away ++ * because tracehook_prepare_release_task() path does not take ++ * utrace->lock when ->utrace_flags == 0. ++ */ ++ rcu_read_lock(); ++ task->utrace_flags = flags; ++ spin_unlock(&utrace->lock); ++ rcu_read_unlock(); ++ ++ put_detached_list(&detached); ++ ++ return !flags; ++} ++ ++void utrace_finish_stop(void) ++{ ++ /* ++ * If we were task_is_traced() and then SIGKILL'ed, make ++ * sure we do nothing until the tracer drops utrace->lock. ++ */ ++ if (unlikely(__fatal_signal_pending(current))) { ++ struct utrace *utrace = task_utrace_struct(current); ++ spin_unlock_wait(&utrace->lock); ++ } ++} ++ ++/* ++ * Perform %UTRACE_STOP, i.e. block in TASK_TRACED until woken up. ++ * @task == current, @utrace == current->utrace, which is not locked. ++ * Return true if we were woken up by SIGKILL even though some utrace ++ * engine may still want us to stay stopped. ++ */ ++static void utrace_stop(struct task_struct *task, struct utrace *utrace, ++ enum utrace_resume_action action) ++{ ++relock: ++ spin_lock(&utrace->lock); ++ ++ if (action < utrace->resume) { ++ /* ++ * Ensure a reporting pass when we're resumed. ++ */ ++ utrace->resume = action; ++ if (action == UTRACE_INTERRUPT) ++ set_thread_flag(TIF_SIGPENDING); ++ else ++ set_thread_flag(TIF_NOTIFY_RESUME); ++ } ++ ++ /* ++ * If the ENGINE_STOP bit is clear in utrace_flags, that means ++ * utrace_reset() ran after we processed some UTRACE_STOP return ++ * values from callbacks to get here. If all engines have detached ++ * or resumed us, we don't stop. This check doesn't require ++ * siglock, but it should follow the interrupt/report bookkeeping ++ * steps (this can matter for UTRACE_RESUME but not UTRACE_DETACH). ++ */ ++ if (unlikely(!(task->utrace_flags & ENGINE_STOP))) { ++ utrace_reset(task, utrace); ++ if (task->utrace_flags & ENGINE_STOP) ++ goto relock; ++ return; ++ } ++ ++ /* ++ * The siglock protects us against signals. As well as SIGKILL ++ * waking us up, we must synchronize with the signal bookkeeping ++ * for stop signals and SIGCONT. ++ */ ++ spin_lock_irq(&task->sighand->siglock); ++ ++ if (unlikely(__fatal_signal_pending(task))) { ++ spin_unlock_irq(&task->sighand->siglock); ++ spin_unlock(&utrace->lock); ++ return; ++ } ++ ++ __set_current_state(TASK_TRACED); ++ ++ /* ++ * If there is a group stop in progress, ++ * we must participate in the bookkeeping. ++ */ ++ if (unlikely(task->signal->group_stop_count) && ++ !--task->signal->group_stop_count) ++ task->signal->flags = SIGNAL_STOP_STOPPED; ++ ++ spin_unlock_irq(&task->sighand->siglock); ++ spin_unlock(&utrace->lock); ++ ++ schedule(); ++ ++ utrace_finish_stop(); ++ ++ /* ++ * While in TASK_TRACED, we were considered "frozen enough". ++ * Now that we woke up, it's crucial if we're supposed to be ++ * frozen that we freeze now before running anything substantial. ++ */ ++ try_to_freeze(); ++ ++ /* ++ * While we were in TASK_TRACED, complete_signal() considered ++ * us "uninterested" in signal wakeups. Now make sure our ++ * TIF_SIGPENDING state is correct for normal running. ++ */ ++ spin_lock_irq(&task->sighand->siglock); ++ recalc_sigpending(); ++ spin_unlock_irq(&task->sighand->siglock); ++} ++ ++/* ++ * Called by release_task() with @reap set to true. ++ * Called by utrace_report_death() with @reap set to false. ++ * On reap, make report_reap callbacks and clean out @utrace ++ * unless still making callbacks. On death, update bookkeeping ++ * and handle the reap work if release_task() came in first. ++ */ ++void utrace_maybe_reap(struct task_struct *target, struct utrace *utrace, ++ bool reap) ++{ ++ struct utrace_engine *engine, *next; ++ struct list_head attached; ++ ++ spin_lock(&utrace->lock); ++ ++ if (reap) { ++ /* ++ * If the target will do some final callbacks but hasn't ++ * finished them yet, we know because it clears these event ++ * bits after it's done. Instead of cleaning up here and ++ * requiring utrace_report_death() to cope with it, we ++ * delay the REAP report and the teardown until after the ++ * target finishes its death reports. ++ */ ++ utrace->reap = 1; ++ ++ if (target->utrace_flags & _UTRACE_DEATH_EVENTS) { ++ spin_unlock(&utrace->lock); ++ return; ++ } ++ } else { ++ /* ++ * After we unlock with this flag clear, any competing ++ * utrace_control/utrace_set_events calls know that we've ++ * finished our callbacks and any detach bookkeeping. ++ */ ++ utrace->death = 0; ++ ++ if (!utrace->reap) { ++ /* ++ * We're just dead, not reaped yet. This will ++ * reset @target->utrace_flags so the later call ++ * with @reap set won't hit the check above. ++ */ ++ utrace_reset(target, utrace); ++ return; ++ } ++ } ++ ++ /* ++ * utrace_add_engine() checks ->utrace_flags != 0. Since ++ * @utrace->reap is set, nobody can set or clear UTRACE_EVENT(REAP) ++ * in @engine->flags or change @engine->ops and nobody can change ++ * @utrace->attached after we drop the lock. ++ */ ++ target->utrace_flags = 0; ++ ++ /* ++ * We clear out @utrace->attached before we drop the lock so ++ * that find_matching_engine() can't come across any old engine ++ * while we are busy tearing it down. ++ */ ++ list_replace_init(&utrace->attached, &attached); ++ list_splice_tail_init(&utrace->attaching, &attached); ++ ++ spin_unlock(&utrace->lock); ++ ++ list_for_each_entry_safe(engine, next, &attached, entry) { ++ if (engine->flags & UTRACE_EVENT(REAP)) ++ engine->ops->report_reap(engine, target); ++ ++ engine->ops = NULL; ++ engine->flags = 0; ++ list_del_init(&engine->entry); ++ ++ utrace_engine_put(engine); ++ } ++} ++ ++/* ++ * You can't do anything to a dead task but detach it. ++ * If release_task() has been called, you can't do that. ++ * ++ * On the exit path, DEATH and QUIESCE event bits are set only ++ * before utrace_report_death() has taken the lock. At that point, ++ * the death report will come soon, so disallow detach until it's ++ * done. This prevents us from racing with it detaching itself. ++ * ++ * Called only when @target->exit_state is nonzero. ++ */ ++static inline int utrace_control_dead(struct task_struct *target, ++ struct utrace *utrace, ++ enum utrace_resume_action action) ++{ ++ lockdep_assert_held(&utrace->lock); ++ ++ if (action != UTRACE_DETACH || unlikely(utrace->reap)) ++ return -ESRCH; ++ ++ if (unlikely(utrace->death)) ++ /* ++ * We have already started the death report. We can't ++ * prevent the report_death and report_reap callbacks, ++ * so tell the caller they will happen. ++ */ ++ return -EALREADY; ++ ++ return 0; ++} ++ ++/** ++ * utrace_control - control a thread being traced by a tracing engine ++ * @target: thread to affect ++ * @engine: attached engine to affect ++ * @action: &enum utrace_resume_action for thread to do ++ * ++ * This is how a tracing engine asks a traced thread to do something. ++ * This call is controlled by the @action argument, which has the ++ * same meaning as the &enum utrace_resume_action value returned by ++ * event reporting callbacks. ++ * ++ * If @target is already dead (@target->exit_state nonzero), ++ * all actions except %UTRACE_DETACH fail with -%ESRCH. ++ * ++ * The following sections describe each option for the @action argument. ++ * ++ * UTRACE_DETACH: ++ * ++ * After this, the @engine data structure is no longer accessible, ++ * and the thread might be reaped. The thread will start running ++ * again if it was stopped and no longer has any attached engines ++ * that want it stopped. ++ * ++ * If the @report_reap callback may already have begun, this fails ++ * with -%ESRCH. If the @report_death callback may already have ++ * begun, this fails with -%EALREADY. ++ * ++ * If @target is not already stopped, then a callback to this engine ++ * might be in progress or about to start on another CPU. If so, ++ * then this returns -%EINPROGRESS; the detach happens as soon as ++ * the pending callback is finished. To synchronize after an ++ * -%EINPROGRESS return, see utrace_barrier(). ++ * ++ * If @target is properly stopped before utrace_control() is called, ++ * then after successful return it's guaranteed that no more callbacks ++ * to the @engine->ops vector will be made. ++ * ++ * The only exception is %SIGKILL (and exec or group-exit by another ++ * thread in the group), which can cause asynchronous @report_death ++ * and/or @report_reap callbacks even when %UTRACE_STOP was used. ++ * (In that event, this fails with -%ESRCH or -%EALREADY, see above.) ++ * ++ * UTRACE_STOP: ++ * ++ * This asks that @target stop running. This returns 0 only if ++ * @target is already stopped, either for tracing or for job ++ * control. Then @target will remain stopped until another ++ * utrace_control() call is made on @engine; @target can be woken ++ * only by %SIGKILL (or equivalent, such as exec or termination by ++ * another thread in the same thread group). ++ * ++ * This returns -%EINPROGRESS if @target is not already stopped. ++ * Then the effect is like %UTRACE_REPORT. A @report_quiesce or ++ * @report_signal callback will be made soon. Your callback can ++ * then return %UTRACE_STOP to keep @target stopped. ++ * ++ * This does not interrupt system calls in progress, including ones ++ * that sleep for a long time. For that, use %UTRACE_INTERRUPT. ++ * To interrupt system calls and then keep @target stopped, your ++ * @report_signal callback can return %UTRACE_STOP. ++ * ++ * UTRACE_RESUME: ++ * ++ * Just let @target continue running normally, reversing the effect ++ * of a previous %UTRACE_STOP. If another engine is keeping @target ++ * stopped, then it remains stopped until all engines let it resume. ++ * If @target was not stopped, this has no effect. ++ * ++ * UTRACE_REPORT: ++ * ++ * This is like %UTRACE_RESUME, but also ensures that there will be ++ * a @report_quiesce or @report_signal callback made soon. If ++ * @target had been stopped, then there will be a callback before it ++ * resumes running normally. If another engine is keeping @target ++ * stopped, then there might be no callbacks until all engines let ++ * it resume. ++ * ++ * Since this is meaningless unless @report_quiesce callbacks will ++ * be made, it returns -%EINVAL if @engine lacks %UTRACE_EVENT(%QUIESCE). ++ * ++ * UTRACE_INTERRUPT: ++ * ++ * This is like %UTRACE_REPORT, but ensures that @target will make a ++ * @report_signal callback before it resumes or delivers signals. ++ * If @target was in a system call or about to enter one, work in ++ * progress will be interrupted as if by %SIGSTOP. If another ++ * engine is keeping @target stopped, then there might be no ++ * callbacks until all engines let it resume. ++ * ++ * This gives @engine an opportunity to introduce a forced signal ++ * disposition via its @report_signal callback. ++ * ++ * UTRACE_SINGLESTEP: ++ * ++ * It's invalid to use this unless arch_has_single_step() returned true. ++ * This is like %UTRACE_RESUME, but resumes for one user instruction only. ++ * ++ * Note that passing %UTRACE_SINGLESTEP or %UTRACE_BLOCKSTEP to ++ * utrace_control() or returning it from an event callback alone does ++ * not necessarily ensure that stepping will be enabled. If there are ++ * more callbacks made to any engine before returning to user mode, ++ * then the resume action is chosen only by the last set of callbacks. ++ * To be sure, enable %UTRACE_EVENT(%QUIESCE) and look for the ++ * @report_quiesce callback with a zero event mask, or the ++ * @report_signal callback with %UTRACE_SIGNAL_REPORT. ++ * ++ * Since this is not robust unless @report_quiesce callbacks will ++ * be made, it returns -%EINVAL if @engine lacks %UTRACE_EVENT(%QUIESCE). ++ * ++ * UTRACE_BLOCKSTEP: ++ * ++ * It's invalid to use this unless arch_has_block_step() returned true. ++ * This is like %UTRACE_SINGLESTEP, but resumes for one whole basic ++ * block of user instructions. ++ * ++ * Since this is not robust unless @report_quiesce callbacks will ++ * be made, it returns -%EINVAL if @engine lacks %UTRACE_EVENT(%QUIESCE). ++ * ++ * %UTRACE_BLOCKSTEP devolves to %UTRACE_SINGLESTEP when another ++ * tracing engine is using %UTRACE_SINGLESTEP at the same time. ++ */ ++int utrace_control(struct task_struct *target, ++ struct utrace_engine *engine, ++ enum utrace_resume_action action) ++{ ++ struct utrace *utrace; ++ bool reset; ++ int ret; ++ ++ if (unlikely(action >= UTRACE_RESUME_MAX)) { ++ WARN(1, "invalid action argument to utrace_control()!"); ++ return -EINVAL; ++ } ++ ++ /* ++ * This is a sanity check for a programming error in the caller. ++ * Their request can only work properly in all cases by relying on ++ * a follow-up callback, but they didn't set one up! This check ++ * doesn't do locking, but it shouldn't matter. The caller has to ++ * be synchronously sure the callback is set up to be operating the ++ * interface properly. ++ */ ++ if (action >= UTRACE_REPORT && action < UTRACE_RESUME && ++ unlikely(!(engine->flags & UTRACE_EVENT(QUIESCE)))) { ++ WARN(1, "utrace_control() with no QUIESCE callback in place!"); ++ return -EINVAL; ++ } ++ ++ utrace = get_utrace_lock(target, engine, true); ++ if (unlikely(IS_ERR(utrace))) ++ return PTR_ERR(utrace); ++ ++ reset = task_is_traced(target); ++ ret = 0; ++ ++ /* ++ * ->exit_state can change under us, this doesn't matter. ++ * We do not care about ->exit_state in fact, but we do ++ * care about ->reap and ->death. If either flag is set, ++ * we must also see ->exit_state != 0. ++ */ ++ if (unlikely(target->exit_state)) { ++ ret = utrace_control_dead(target, utrace, action); ++ if (ret) { ++ spin_unlock(&utrace->lock); ++ return ret; ++ } ++ reset = true; ++ } ++ ++ switch (action) { ++ case UTRACE_STOP: ++ mark_engine_wants_stop(target, engine); ++ if (!reset && !utrace_do_stop(target, utrace)) ++ ret = -EINPROGRESS; ++ reset = false; ++ break; ++ ++ case UTRACE_DETACH: ++ if (engine_wants_stop(engine)) ++ target->utrace_flags &= ~ENGINE_STOP; ++ mark_engine_detached(engine); ++ reset = reset || utrace_do_stop(target, utrace); ++ if (!reset) { ++ /* ++ * As in utrace_set_events(), this barrier ensures ++ * that our engine->flags changes have hit before we ++ * examine utrace->reporting, pairing with the barrier ++ * in start_callback(). If @target has not yet hit ++ * finish_callback() to clear utrace->reporting, we ++ * might be in the middle of a callback to @engine. ++ */ ++ smp_mb(); ++ if (utrace->reporting == engine) ++ ret = -EINPROGRESS; ++ } ++ break; ++ ++ case UTRACE_RESUME: ++ /* ++ * This and all other cases imply resuming if stopped. ++ * There might not be another report before it just ++ * resumes, so make sure single-step is not left set. ++ */ ++ clear_engine_wants_stop(engine); ++ if (likely(reset)) ++ user_disable_single_step(target); ++ break; ++ ++ case UTRACE_BLOCKSTEP: ++ /* ++ * Resume from stopped, step one block. ++ * We fall through to treat it like UTRACE_SINGLESTEP. ++ */ ++ if (unlikely(!arch_has_block_step())) { ++ WARN(1, "UTRACE_BLOCKSTEP when !arch_has_block_step()"); ++ action = UTRACE_SINGLESTEP; ++ } ++ ++ case UTRACE_SINGLESTEP: ++ /* ++ * Resume from stopped, step one instruction. ++ * We fall through to the UTRACE_REPORT case. ++ */ ++ if (unlikely(!arch_has_single_step())) { ++ WARN(1, ++ "UTRACE_SINGLESTEP when !arch_has_single_step()"); ++ reset = false; ++ ret = -EOPNOTSUPP; ++ break; ++ } ++ ++ case UTRACE_REPORT: ++ /* ++ * Make the thread call tracehook_notify_resume() soon. ++ * But don't bother if it's already been interrupted. ++ * In that case, utrace_get_signal() will be reporting soon. ++ */ ++ clear_engine_wants_stop(engine); ++ if (action < utrace->resume) { ++ utrace->resume = action; ++ set_notify_resume(target); ++ } ++ break; ++ ++ case UTRACE_INTERRUPT: ++ /* ++ * Make the thread call tracehook_get_signal() soon. ++ */ ++ clear_engine_wants_stop(engine); ++ if (utrace->resume == UTRACE_INTERRUPT) ++ break; ++ utrace->resume = UTRACE_INTERRUPT; ++ ++ /* ++ * If it's not already stopped, interrupt it now. We need ++ * the siglock here in case it calls recalc_sigpending() ++ * and clears its own TIF_SIGPENDING. By taking the lock, ++ * we've serialized any later recalc_sigpending() after our ++ * setting of utrace->resume to force it on. ++ */ ++ if (reset) { ++ /* ++ * This is really just to keep the invariant that ++ * TIF_SIGPENDING is set with UTRACE_INTERRUPT. ++ * When it's stopped, we know it's always going ++ * through utrace_get_signal() and will recalculate. ++ */ ++ set_tsk_thread_flag(target, TIF_SIGPENDING); ++ } else { ++ struct sighand_struct *sighand; ++ unsigned long irqflags; ++ sighand = lock_task_sighand(target, &irqflags); ++ if (likely(sighand)) { ++ signal_wake_up(target, 0); ++ unlock_task_sighand(target, &irqflags); ++ } ++ } ++ break; ++ ++ default: ++ BUG(); /* We checked it on entry. */ ++ } ++ ++ /* ++ * Let the thread resume running. If it's not stopped now, ++ * there is nothing more we need to do. ++ */ ++ if (reset) ++ utrace_reset(target, utrace); ++ else ++ spin_unlock(&utrace->lock); ++ ++ return ret; ++} ++EXPORT_SYMBOL_GPL(utrace_control); ++ ++/** ++ * utrace_barrier - synchronize with simultaneous tracing callbacks ++ * @target: thread to affect ++ * @engine: engine to affect (can be detached) ++ * ++ * This blocks while @target might be in the midst of making a callback to ++ * @engine. It can be interrupted by signals and will return -%ERESTARTSYS. ++ * A return value of zero means no callback from @target to @engine was ++ * in progress. Any effect of its return value (such as %UTRACE_STOP) has ++ * already been applied to @engine. ++ * ++ * It's not necessary to keep the @target pointer alive for this call. ++ * It's only necessary to hold a ref on @engine. This will return ++ * safely even if @target has been reaped and has no task refs. ++ * ++ * A successful return from utrace_barrier() guarantees its ordering ++ * with respect to utrace_set_events() and utrace_control() calls. If ++ * @target was not properly stopped, event callbacks just disabled might ++ * still be in progress; utrace_barrier() waits until there is no chance ++ * an unwanted callback can be in progress. ++ */ ++int utrace_barrier(struct task_struct *target, struct utrace_engine *engine) ++{ ++ struct utrace *utrace; ++ int ret = -ERESTARTSYS; ++ ++ if (unlikely(target == current)) ++ return 0; ++ ++ do { ++ utrace = get_utrace_lock(target, engine, false); ++ if (unlikely(IS_ERR(utrace))) { ++ ret = PTR_ERR(utrace); ++ if (ret != -ERESTARTSYS) ++ break; ++ } else { ++ /* ++ * All engine state changes are done while ++ * holding the lock, i.e. before we get here. ++ * Since we have the lock, we only need to ++ * worry about @target making a callback. ++ * When it has entered start_callback() but ++ * not yet gotten to finish_callback(), we ++ * will see utrace->reporting == @engine. ++ * When @target doesn't take the lock, it uses ++ * barriers to order setting utrace->reporting ++ * before it examines the engine state. ++ */ ++ if (utrace->reporting != engine) ++ ret = 0; ++ spin_unlock(&utrace->lock); ++ if (!ret) ++ break; ++ } ++ schedule_timeout_interruptible(1); ++ } while (!signal_pending(current)); ++ ++ return ret; ++} ++EXPORT_SYMBOL_GPL(utrace_barrier); ++ ++/* ++ * This is local state used for reporting loops, perhaps optimized away. ++ */ ++struct utrace_report { ++ u32 result; ++ enum utrace_resume_action action; ++ enum utrace_resume_action resume_action; ++ bool detaches; ++ bool spurious; ++}; ++ ++#define INIT_REPORT(var) \ ++ struct utrace_report var = { \ ++ .action = UTRACE_RESUME, \ ++ .resume_action = UTRACE_RESUME, \ ++ .spurious = true \ ++ } ++ ++/* ++ * We are now making the report, so clear the flag saying we need one. ++ * When there is a new attach, ->pending_attach is set just so we will ++ * know to do splice_attaching() here before the callback loop. ++ */ ++static enum utrace_resume_action start_report(struct utrace *utrace) ++{ ++ enum utrace_resume_action resume = utrace->resume; ++ if (utrace->pending_attach || ++ (resume > UTRACE_INTERRUPT && resume < UTRACE_RESUME)) { ++ spin_lock(&utrace->lock); ++ splice_attaching(utrace); ++ resume = utrace->resume; ++ if (resume > UTRACE_INTERRUPT) ++ utrace->resume = UTRACE_RESUME; ++ spin_unlock(&utrace->lock); ++ } ++ return resume; ++} ++ ++static inline void finish_report_reset(struct task_struct *task, ++ struct utrace *utrace, ++ struct utrace_report *report) ++{ ++ if (unlikely(report->spurious || report->detaches)) { ++ spin_lock(&utrace->lock); ++ if (utrace_reset(task, utrace)) ++ report->action = UTRACE_RESUME; ++ } ++} ++ ++/* ++ * Complete a normal reporting pass, pairing with a start_report() call. ++ * This handles any UTRACE_DETACH or UTRACE_REPORT or UTRACE_INTERRUPT ++ * returns from engine callbacks. If @will_not_stop is true and any ++ * engine's last callback used UTRACE_STOP, we do UTRACE_REPORT here to ++ * ensure we stop before user mode. If there were no callbacks made, it ++ * will recompute @task->utrace_flags to avoid another false-positive. ++ */ ++static void finish_report(struct task_struct *task, struct utrace *utrace, ++ struct utrace_report *report, bool will_not_stop) ++{ ++ enum utrace_resume_action resume = report->action; ++ ++ if (resume == UTRACE_STOP) ++ resume = will_not_stop ? UTRACE_REPORT : UTRACE_RESUME; ++ ++ if (resume < utrace->resume) { ++ spin_lock(&utrace->lock); ++ utrace->resume = resume; ++ if (resume == UTRACE_INTERRUPT) ++ set_tsk_thread_flag(task, TIF_SIGPENDING); ++ else ++ set_tsk_thread_flag(task, TIF_NOTIFY_RESUME); ++ spin_unlock(&utrace->lock); ++ } ++ ++ finish_report_reset(task, utrace, report); ++} ++ ++static void finish_callback_report(struct task_struct *task, ++ struct utrace *utrace, ++ struct utrace_report *report, ++ struct utrace_engine *engine, ++ enum utrace_resume_action action) ++{ ++ if (action == UTRACE_DETACH) { ++ /* ++ * By holding the lock here, we make sure that ++ * utrace_barrier() (really get_utrace_lock()) sees the ++ * effect of this detach. Otherwise utrace_barrier() could ++ * return 0 after this callback had returned UTRACE_DETACH. ++ * This way, a 0 return is an unambiguous indicator that any ++ * callback returning UTRACE_DETACH has indeed caused detach. ++ */ ++ spin_lock(&utrace->lock); ++ engine->ops = &utrace_detached_ops; ++ spin_unlock(&utrace->lock); ++ } ++ ++ /* ++ * If utrace_control() was used, treat that like UTRACE_DETACH here. ++ */ ++ if (engine->ops == &utrace_detached_ops) { ++ report->detaches = true; ++ return; ++ } ++ ++ if (action < report->action) ++ report->action = action; ++ ++ if (action != UTRACE_STOP) { ++ if (action < report->resume_action) ++ report->resume_action = action; ++ ++ if (engine_wants_stop(engine)) { ++ spin_lock(&utrace->lock); ++ clear_engine_wants_stop(engine); ++ spin_unlock(&utrace->lock); ++ } ++ ++ return; ++ } ++ ++ if (!engine_wants_stop(engine)) { ++ spin_lock(&utrace->lock); ++ /* ++ * If utrace_control() came in and detached us ++ * before we got the lock, we must not stop now. ++ */ ++ if (unlikely(engine->ops == &utrace_detached_ops)) ++ report->detaches = true; ++ else ++ mark_engine_wants_stop(task, engine); ++ spin_unlock(&utrace->lock); ++ } ++} ++ ++/* ++ * Apply the return value of one engine callback to @report. ++ * Returns true if @engine detached and should not get any more callbacks. ++ */ ++static bool finish_callback(struct task_struct *task, struct utrace *utrace, ++ struct utrace_report *report, ++ struct utrace_engine *engine, ++ u32 ret) ++{ ++ report->result = ret & ~UTRACE_RESUME_MASK; ++ finish_callback_report(task, utrace, report, engine, ++ utrace_resume_action(ret)); ++ ++ /* ++ * Now that we have applied the effect of the return value, ++ * clear this so that utrace_barrier() can stop waiting. ++ * A subsequent utrace_control() can stop or resume @engine ++ * and know this was ordered after its callback's action. ++ * ++ * We don't need any barriers here because utrace_barrier() ++ * takes utrace->lock. If we touched engine->flags above, ++ * the lock guaranteed this change was before utrace_barrier() ++ * examined utrace->reporting. ++ */ ++ utrace->reporting = NULL; ++ ++ /* ++ * We've just done an engine callback. These are allowed to sleep, ++ * though all well-behaved ones restrict that to blocking kalloc() ++ * or quickly-acquired mutex_lock() and the like. This is a good ++ * place to make sure tracing engines don't introduce too much ++ * latency under voluntary preemption. ++ */ ++ might_sleep(); ++ ++ return engine->ops == &utrace_detached_ops; ++} ++ ++/* ++ * Start the callbacks for @engine to consider @event (a bit mask). ++ * This makes the report_quiesce() callback first. If @engine wants ++ * a specific callback for @event, we return the ops vector to use. ++ * If not, we return NULL. The return value from the ops->callback ++ * function called should be passed to finish_callback(). ++ */ ++static const struct utrace_engine_ops *start_callback( ++ struct utrace *utrace, struct utrace_report *report, ++ struct utrace_engine *engine, struct task_struct *task, ++ unsigned long event) ++{ ++ const struct utrace_engine_ops *ops; ++ unsigned long want; ++ ++ /* ++ * This barrier ensures that we've set utrace->reporting before ++ * we examine engine->flags or engine->ops. utrace_barrier() ++ * relies on this ordering to indicate that the effect of any ++ * utrace_control() and utrace_set_events() calls is in place ++ * by the time utrace->reporting can be seen to be NULL. ++ */ ++ utrace->reporting = engine; ++ smp_mb(); ++ ++ /* ++ * This pairs with the barrier in mark_engine_detached(). ++ * It makes sure that we never see the old ops vector with ++ * the new flags, in case the original vector had no report_quiesce. ++ */ ++ want = engine->flags; ++ smp_rmb(); ++ ops = engine->ops; ++ ++ if (want & UTRACE_EVENT(QUIESCE)) { ++ if (finish_callback(task, utrace, report, engine, ++ (*ops->report_quiesce)(report->action, ++ engine, event))) ++ return NULL; ++ ++ /* ++ * finish_callback() reset utrace->reporting after the ++ * quiesce callback. Now we set it again (as above) ++ * before re-examining engine->flags, which could have ++ * been changed synchronously by ->report_quiesce or ++ * asynchronously by utrace_control() or utrace_set_events(). ++ */ ++ utrace->reporting = engine; ++ smp_mb(); ++ want = engine->flags; ++ } ++ ++ if (want & ENGINE_STOP) ++ report->action = UTRACE_STOP; ++ ++ if (want & event) { ++ report->spurious = false; ++ return ops; ++ } ++ ++ utrace->reporting = NULL; ++ return NULL; ++} ++ ++/* ++ * Do a normal reporting pass for engines interested in @event. ++ * @callback is the name of the member in the ops vector, and remaining ++ * args are the extras it takes after the standard three args. ++ */ ++#define REPORT_CALLBACKS(rev, task, utrace, report, event, callback, ...) \ ++ do { \ ++ struct utrace_engine *engine; \ ++ const struct utrace_engine_ops *ops; \ ++ list_for_each_entry##rev(engine, &utrace->attached, entry) { \ ++ ops = start_callback(utrace, report, engine, task, \ ++ event); \ ++ if (!ops) \ ++ continue; \ ++ finish_callback(task, utrace, report, engine, \ ++ (*ops->callback)(__VA_ARGS__)); \ ++ } \ ++ } while (0) ++#define REPORT(task, utrace, report, event, callback, ...) \ ++ do { \ ++ start_report(utrace); \ ++ REPORT_CALLBACKS(, task, utrace, report, event, callback, \ ++ (report)->action, engine, ## __VA_ARGS__); \ ++ finish_report(task, utrace, report, true); \ ++ } while (0) ++ ++/* ++ * Called iff UTRACE_EVENT(EXEC) flag is set. ++ */ ++void utrace_report_exec(struct linux_binfmt *fmt, struct linux_binprm *bprm, ++ struct pt_regs *regs) ++{ ++ struct task_struct *task = current; ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ ++ REPORT(task, utrace, &report, UTRACE_EVENT(EXEC), ++ report_exec, fmt, bprm, regs); ++} ++ ++static u32 do_report_syscall_entry(struct pt_regs *regs, ++ struct task_struct *task, ++ struct utrace *utrace, ++ struct utrace_report *report, ++ u32 resume_report) ++{ ++ start_report(utrace); ++ REPORT_CALLBACKS(_reverse, task, utrace, report, ++ UTRACE_EVENT(SYSCALL_ENTRY), report_syscall_entry, ++ resume_report | report->result | report->action, ++ engine, regs); ++ finish_report(task, utrace, report, false); ++ ++ if (report->action != UTRACE_STOP) ++ return 0; ++ ++ utrace_stop(task, utrace, report->resume_action); ++ ++ if (fatal_signal_pending(task)) { ++ /* ++ * We are continuing despite UTRACE_STOP because of a ++ * SIGKILL. Don't let the system call actually proceed. ++ */ ++ report->result = UTRACE_SYSCALL_ABORT; ++ } else if (utrace->resume <= UTRACE_REPORT) { ++ /* ++ * If we've been asked for another report after our stop, ++ * go back to report (and maybe stop) again before we run ++ * the system call. The second (and later) reports are ++ * marked with the UTRACE_SYSCALL_RESUMED flag so that ++ * engines know this is a second report at the same ++ * entry. This gives them the chance to examine the ++ * registers anew after they might have been changed ++ * while we were stopped. ++ */ ++ report->detaches = false; ++ report->spurious = true; ++ report->action = report->resume_action = UTRACE_RESUME; ++ return UTRACE_SYSCALL_RESUMED; ++ } ++ ++ return 0; ++} ++ ++/* ++ * Called iff UTRACE_EVENT(SYSCALL_ENTRY) flag is set. ++ * Return true to prevent the system call. ++ */ ++bool utrace_report_syscall_entry(struct pt_regs *regs) ++{ ++ struct task_struct *task = current; ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ u32 resume_report = 0; ++ ++ do { ++ resume_report = do_report_syscall_entry(regs, task, utrace, ++ &report, resume_report); ++ } while (resume_report); ++ ++ return utrace_syscall_action(report.result) == UTRACE_SYSCALL_ABORT; ++} ++ ++/* ++ * Called iff UTRACE_EVENT(SYSCALL_EXIT) flag is set. ++ */ ++void utrace_report_syscall_exit(struct pt_regs *regs) ++{ ++ struct task_struct *task = current; ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ ++ REPORT(task, utrace, &report, UTRACE_EVENT(SYSCALL_EXIT), ++ report_syscall_exit, regs); ++} ++ ++/* ++ * Called iff UTRACE_EVENT(CLONE) flag is set. ++ * This notification call blocks the wake_up_new_task call on the child. ++ * So we must not quiesce here. tracehook_report_clone_complete will do ++ * a quiescence check momentarily. ++ */ ++void utrace_report_clone(unsigned long clone_flags, struct task_struct *child) ++{ ++ struct task_struct *task = current; ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ ++ /* ++ * We don't use the REPORT() macro here, because we need ++ * to clear utrace->cloning before finish_report(). ++ * After finish_report(), utrace can be a stale pointer ++ * in cases when report.action is still UTRACE_RESUME. ++ */ ++ start_report(utrace); ++ utrace->cloning = child; ++ ++ REPORT_CALLBACKS(, task, utrace, &report, ++ UTRACE_EVENT(CLONE), report_clone, ++ report.action, engine, clone_flags, child); ++ ++ utrace->cloning = NULL; ++ finish_report(task, utrace, &report, !(clone_flags & CLONE_VFORK)); ++ ++ /* ++ * For a vfork, we will go into an uninterruptible block waiting ++ * for the child. We need UTRACE_STOP to happen before this, not ++ * after. For CLONE_VFORK, utrace_finish_vfork() will be called. ++ */ ++ if (report.action == UTRACE_STOP && (clone_flags & CLONE_VFORK)) { ++ spin_lock(&utrace->lock); ++ utrace->vfork_stop = 1; ++ spin_unlock(&utrace->lock); ++ } ++} ++ ++/* ++ * We're called after utrace_report_clone() for a CLONE_VFORK. ++ * If UTRACE_STOP was left from the clone report, we stop here. ++ * After this, we'll enter the uninterruptible wait_for_completion() ++ * waiting for the child. ++ */ ++void utrace_finish_vfork(struct task_struct *task) ++{ ++ struct utrace *utrace = task_utrace_struct(task); ++ ++ if (utrace->vfork_stop) { ++ spin_lock(&utrace->lock); ++ utrace->vfork_stop = 0; ++ spin_unlock(&utrace->lock); ++ utrace_stop(task, utrace, UTRACE_RESUME); /* XXX */ ++ } ++} ++ ++/* ++ * Called iff UTRACE_EVENT(JCTL) flag is set. ++ * ++ * Called with siglock held. ++ */ ++void utrace_report_jctl(int notify, int what) ++{ ++ struct task_struct *task = current; ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ ++ spin_unlock_irq(&task->sighand->siglock); ++ ++ REPORT(task, utrace, &report, UTRACE_EVENT(JCTL), ++ report_jctl, what, notify); ++ ++ spin_lock_irq(&task->sighand->siglock); ++} ++ ++/* ++ * Called iff UTRACE_EVENT(EXIT) flag is set. ++ */ ++void utrace_report_exit(long *exit_code) ++{ ++ struct task_struct *task = current; ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ long orig_code = *exit_code; ++ ++ REPORT(task, utrace, &report, UTRACE_EVENT(EXIT), ++ report_exit, orig_code, exit_code); ++ ++ if (report.action == UTRACE_STOP) ++ utrace_stop(task, utrace, report.resume_action); ++} ++ ++/* ++ * Called iff UTRACE_EVENT(DEATH) or UTRACE_EVENT(QUIESCE) flag is set. ++ * ++ * It is always possible that we are racing with utrace_release_task here. ++ * For this reason, utrace_release_task checks for the event bits that get ++ * us here, and delays its cleanup for us to do. ++ */ ++void utrace_report_death(struct task_struct *task, struct utrace *utrace, ++ bool group_dead, int signal) ++{ ++ INIT_REPORT(report); ++ ++ BUG_ON(!task->exit_state); ++ ++ /* ++ * We are presently considered "quiescent"--which is accurate ++ * inasmuch as we won't run any more user instructions ever again. ++ * But for utrace_control and utrace_set_events to be robust, they ++ * must be sure whether or not we will run any more callbacks. If ++ * a call comes in before we do, taking the lock here synchronizes ++ * us so we don't run any callbacks just disabled. Calls that come ++ * in while we're running the callbacks will see the exit.death ++ * flag and know that we are not yet fully quiescent for purposes ++ * of detach bookkeeping. ++ */ ++ spin_lock(&utrace->lock); ++ BUG_ON(utrace->death); ++ utrace->death = 1; ++ utrace->resume = UTRACE_RESUME; ++ splice_attaching(utrace); ++ spin_unlock(&utrace->lock); ++ ++ REPORT_CALLBACKS(, task, utrace, &report, UTRACE_EVENT(DEATH), ++ report_death, engine, group_dead, signal); ++ ++ utrace_maybe_reap(task, utrace, false); ++} ++ ++/* ++ * Finish the last reporting pass before returning to user mode. ++ */ ++static void finish_resume_report(struct task_struct *task, ++ struct utrace *utrace, ++ struct utrace_report *report) ++{ ++ finish_report_reset(task, utrace, report); ++ ++ switch (report->action) { ++ case UTRACE_STOP: ++ utrace_stop(task, utrace, report->resume_action); ++ break; ++ ++ case UTRACE_INTERRUPT: ++ if (!signal_pending(task)) ++ set_tsk_thread_flag(task, TIF_SIGPENDING); ++ break; ++ ++ case UTRACE_BLOCKSTEP: ++ if (likely(arch_has_block_step())) { ++ user_enable_block_step(task); ++ break; ++ } ++ ++ /* ++ * This means some callback is to blame for failing ++ * to check arch_has_block_step() itself. Warn and ++ * then fall through to treat it as SINGLESTEP. ++ */ ++ WARN(1, "UTRACE_BLOCKSTEP when !arch_has_block_step()"); ++ ++ case UTRACE_SINGLESTEP: ++ if (likely(arch_has_single_step())) { ++ user_enable_single_step(task); ++ } else { ++ /* ++ * This means some callback is to blame for failing ++ * to check arch_has_single_step() itself. Spew ++ * about it so the loser will fix his module. ++ */ ++ WARN(1, ++ "UTRACE_SINGLESTEP when !arch_has_single_step()"); ++ } ++ break; ++ ++ case UTRACE_REPORT: ++ case UTRACE_RESUME: ++ default: ++ user_disable_single_step(task); ++ break; ++ } ++} ++ ++/* ++ * This is called when TIF_NOTIFY_RESUME had been set (and is now clear). ++ * We are close to user mode, and this is the place to report or stop. ++ * When we return, we're going to user mode or into the signals code. ++ */ ++void utrace_resume(struct task_struct *task, struct pt_regs *regs) ++{ ++ struct utrace *utrace = task_utrace_struct(task); ++ INIT_REPORT(report); ++ struct utrace_engine *engine; ++ ++ /* ++ * Some machines get here with interrupts disabled. The same arch ++ * code path leads to calling into get_signal_to_deliver(), which ++ * implicitly reenables them by virtue of spin_unlock_irq. ++ */ ++ local_irq_enable(); ++ ++ /* ++ * If this flag is still set it's because there was a signal ++ * handler setup done but no report_signal following it. Clear ++ * the flag before we get to user so it doesn't confuse us later. ++ */ ++ if (unlikely(utrace->signal_handler)) { ++ spin_lock(&utrace->lock); ++ utrace->signal_handler = 0; ++ spin_unlock(&utrace->lock); ++ } ++ ++ /* ++ * Update our bookkeeping even if there are no callbacks made here. ++ */ ++ report.action = start_report(utrace); ++ ++ switch (report.action) { ++ case UTRACE_RESUME: ++ /* ++ * Anything we might have done was already handled by ++ * utrace_get_signal(), or this is an entirely spurious ++ * call. (The arch might use TIF_NOTIFY_RESUME for other ++ * purposes as well as calling us.) ++ */ ++ return; ++ case UTRACE_REPORT: ++ if (unlikely(!(task->utrace_flags & UTRACE_EVENT(QUIESCE)))) ++ break; ++ /* ++ * Do a simple reporting pass, with no specific ++ * callback after report_quiesce. ++ */ ++ report.action = UTRACE_RESUME; ++ list_for_each_entry(engine, &utrace->attached, entry) ++ start_callback(utrace, &report, engine, task, 0); ++ break; ++ default: ++ /* ++ * Even if this report was truly spurious, there is no need ++ * for utrace_reset() now. TIF_NOTIFY_RESUME was already ++ * cleared--it doesn't stay spuriously set. ++ */ ++ report.spurious = false; ++ break; ++ } ++ ++ /* ++ * Finish the report and either stop or get ready to resume. ++ * If utrace->resume was not UTRACE_REPORT, this applies its ++ * effect now (i.e. step or interrupt). ++ */ ++ finish_resume_report(task, utrace, &report); ++} ++ ++/* ++ * Return true if current has forced signal_pending(). ++ * ++ * This is called only when current->utrace_flags is nonzero, so we know ++ * that current->utrace must be set. It's not inlined in tracehook.h ++ * just so that struct utrace can stay opaque outside this file. ++ */ ++bool utrace_interrupt_pending(void) ++{ ++ return task_utrace_struct(current)->resume == UTRACE_INTERRUPT; ++} ++ ++/* ++ * Take the siglock and push @info back on our queue. ++ * Returns with @task->sighand->siglock held. ++ */ ++static void push_back_signal(struct task_struct *task, siginfo_t *info) ++ __acquires(task->sighand->siglock) ++{ ++ struct sigqueue *q; ++ ++ if (unlikely(!info->si_signo)) { /* Oh, a wise guy! */ ++ spin_lock_irq(&task->sighand->siglock); ++ return; ++ } ++ ++ q = sigqueue_alloc(); ++ if (likely(q)) { ++ q->flags = 0; ++ copy_siginfo(&q->info, info); ++ } ++ ++ spin_lock_irq(&task->sighand->siglock); ++ ++ sigaddset(&task->pending.signal, info->si_signo); ++ if (likely(q)) ++ list_add(&q->list, &task->pending.list); ++ ++ set_tsk_thread_flag(task, TIF_SIGPENDING); ++} ++ ++/* ++ * This is the hook from the signals code, called with the siglock held. ++ * Here is the ideal place to stop. We also dequeue and intercept signals. ++ */ ++int utrace_get_signal(struct task_struct *task, struct pt_regs *regs, ++ siginfo_t *info, struct k_sigaction *return_ka) ++ __releases(task->sighand->siglock) ++ __acquires(task->sighand->siglock) ++{ ++ struct utrace *utrace; ++ struct k_sigaction *ka; ++ INIT_REPORT(report); ++ struct utrace_engine *engine; ++ const struct utrace_engine_ops *ops; ++ unsigned long event, want; ++ u32 ret; ++ int signr; ++ ++ utrace = task_utrace_struct(task); ++ if (utrace->resume < UTRACE_RESUME || ++ utrace->pending_attach || utrace->signal_handler) { ++ enum utrace_resume_action resume; ++ ++ /* ++ * We've been asked for an explicit report before we ++ * even check for pending signals. ++ */ ++ ++ spin_unlock_irq(&task->sighand->siglock); ++ ++ spin_lock(&utrace->lock); ++ ++ splice_attaching(utrace); ++ ++ report.result = utrace->signal_handler ? ++ UTRACE_SIGNAL_HANDLER : UTRACE_SIGNAL_REPORT; ++ utrace->signal_handler = 0; ++ ++ resume = utrace->resume; ++ utrace->resume = UTRACE_RESUME; ++ ++ spin_unlock(&utrace->lock); ++ ++ /* ++ * Make sure signal_pending() only returns true ++ * if there are real signals pending. ++ */ ++ if (signal_pending(task)) { ++ spin_lock_irq(&task->sighand->siglock); ++ recalc_sigpending(); ++ spin_unlock_irq(&task->sighand->siglock); ++ } ++ ++ if (resume > UTRACE_REPORT) { ++ /* ++ * We only got here to process utrace->resume. ++ * Despite no callbacks, this report is not spurious. ++ */ ++ report.action = resume; ++ report.spurious = false; ++ finish_resume_report(task, utrace, &report); ++ return -1; ++ } else if (!(task->utrace_flags & UTRACE_EVENT(QUIESCE))) { ++ /* ++ * We only got here to clear utrace->signal_handler. ++ */ ++ return -1; ++ } ++ ++ /* ++ * Do a reporting pass for no signal, just for EVENT(QUIESCE). ++ * The engine callbacks can fill in *info and *return_ka. ++ * We'll pass NULL for the @orig_ka argument to indicate ++ * that there was no original signal. ++ */ ++ event = 0; ++ ka = NULL; ++ memset(return_ka, 0, sizeof *return_ka); ++ } else if (!(task->utrace_flags & UTRACE_EVENT_SIGNAL_ALL) || ++ unlikely(task->signal->group_stop_count)) { ++ /* ++ * If no engine is interested in intercepting signals or ++ * we must stop, let the caller just dequeue them normally ++ * or participate in group-stop. ++ */ ++ return 0; ++ } else { ++ /* ++ * Steal the next signal so we can let tracing engines ++ * examine it. From the signal number and sigaction, ++ * determine what normal delivery would do. If no ++ * engine perturbs it, we'll do that by returning the ++ * signal number after setting *return_ka. ++ */ ++ signr = dequeue_signal(task, &task->blocked, info); ++ if (signr == 0) ++ return signr; ++ BUG_ON(signr != info->si_signo); ++ ++ ka = &task->sighand->action[signr - 1]; ++ *return_ka = *ka; ++ ++ /* ++ * We are never allowed to interfere with SIGKILL. ++ * Just punt after filling in *return_ka for our caller. ++ */ ++ if (signr == SIGKILL) ++ return signr; ++ ++ if (ka->sa.sa_handler == SIG_IGN) { ++ event = UTRACE_EVENT(SIGNAL_IGN); ++ report.result = UTRACE_SIGNAL_IGN; ++ } else if (ka->sa.sa_handler != SIG_DFL) { ++ event = UTRACE_EVENT(SIGNAL); ++ report.result = UTRACE_SIGNAL_DELIVER; ++ } else if (sig_kernel_coredump(signr)) { ++ event = UTRACE_EVENT(SIGNAL_CORE); ++ report.result = UTRACE_SIGNAL_CORE; ++ } else if (sig_kernel_ignore(signr)) { ++ event = UTRACE_EVENT(SIGNAL_IGN); ++ report.result = UTRACE_SIGNAL_IGN; ++ } else if (signr == SIGSTOP) { ++ event = UTRACE_EVENT(SIGNAL_STOP); ++ report.result = UTRACE_SIGNAL_STOP; ++ } else if (sig_kernel_stop(signr)) { ++ event = UTRACE_EVENT(SIGNAL_STOP); ++ report.result = UTRACE_SIGNAL_TSTP; ++ } else { ++ event = UTRACE_EVENT(SIGNAL_TERM); ++ report.result = UTRACE_SIGNAL_TERM; ++ } ++ ++ /* ++ * Now that we know what event type this signal is, we ++ * can short-circuit if no engines care about those. ++ */ ++ if ((task->utrace_flags & (event | UTRACE_EVENT(QUIESCE))) == 0) ++ return signr; ++ ++ /* ++ * We have some interested engines, so tell them about ++ * the signal and let them change its disposition. ++ */ ++ spin_unlock_irq(&task->sighand->siglock); ++ } ++ ++ /* ++ * This reporting pass chooses what signal disposition we'll act on. ++ */ ++ list_for_each_entry(engine, &utrace->attached, entry) { ++ /* ++ * See start_callback() comment about this barrier. ++ */ ++ utrace->reporting = engine; ++ smp_mb(); ++ ++ /* ++ * This pairs with the barrier in mark_engine_detached(), ++ * see start_callback() comments. ++ */ ++ want = engine->flags; ++ smp_rmb(); ++ ops = engine->ops; ++ ++ if ((want & (event | UTRACE_EVENT(QUIESCE))) == 0) { ++ utrace->reporting = NULL; ++ continue; ++ } ++ ++ if (ops->report_signal) ++ ret = (*ops->report_signal)( ++ report.result | report.action, engine, ++ regs, info, ka, return_ka); ++ else ++ ret = (report.result | (*ops->report_quiesce)( ++ report.action, engine, event)); ++ ++ /* ++ * Avoid a tight loop reporting again and again if some ++ * engine is too stupid. ++ */ ++ switch (utrace_resume_action(ret)) { ++ default: ++ break; ++ case UTRACE_INTERRUPT: ++ case UTRACE_REPORT: ++ ret = (ret & ~UTRACE_RESUME_MASK) | UTRACE_RESUME; ++ break; ++ } ++ ++ finish_callback(task, utrace, &report, engine, ret); ++ } ++ ++ /* ++ * We express the chosen action to the signals code in terms ++ * of a representative signal whose default action does it. ++ * Our caller uses our return value (signr) to decide what to ++ * do, but uses info->si_signo as the signal number to report. ++ */ ++ switch (utrace_signal_action(report.result)) { ++ case UTRACE_SIGNAL_TERM: ++ signr = SIGTERM; ++ break; ++ ++ case UTRACE_SIGNAL_CORE: ++ signr = SIGQUIT; ++ break; ++ ++ case UTRACE_SIGNAL_STOP: ++ signr = SIGSTOP; ++ break; ++ ++ case UTRACE_SIGNAL_TSTP: ++ signr = SIGTSTP; ++ break; ++ ++ case UTRACE_SIGNAL_DELIVER: ++ signr = info->si_signo; ++ ++ if (return_ka->sa.sa_handler == SIG_DFL) { ++ /* ++ * We'll do signr's normal default action. ++ * For ignore, we'll fall through below. ++ * For stop/death, break locks and returns it. ++ */ ++ if (likely(signr) && !sig_kernel_ignore(signr)) ++ break; ++ } else if (return_ka->sa.sa_handler != SIG_IGN && ++ likely(signr)) { ++ /* ++ * Complete the bookkeeping after the report. ++ * The handler will run. If an engine wanted to ++ * stop or step, then make sure we do another ++ * report after signal handler setup. ++ */ ++ if (report.action != UTRACE_RESUME) ++ report.action = UTRACE_INTERRUPT; ++ finish_report(task, utrace, &report, true); ++ ++ if (unlikely(report.result & UTRACE_SIGNAL_HOLD)) ++ push_back_signal(task, info); ++ else ++ spin_lock_irq(&task->sighand->siglock); ++ ++ /* ++ * We do the SA_ONESHOT work here since the ++ * normal path will only touch *return_ka now. ++ */ ++ if (unlikely(return_ka->sa.sa_flags & SA_ONESHOT)) { ++ return_ka->sa.sa_flags &= ~SA_ONESHOT; ++ if (likely(valid_signal(signr))) { ++ ka = &task->sighand->action[signr - 1]; ++ ka->sa.sa_handler = SIG_DFL; ++ } ++ } ++ ++ return signr; ++ } ++ ++ /* Fall through for an ignored signal. */ ++ ++ case UTRACE_SIGNAL_IGN: ++ case UTRACE_SIGNAL_REPORT: ++ default: ++ /* ++ * If the signal is being ignored, then we are on the way ++ * directly back to user mode. We can stop here, or step, ++ * as in utrace_resume(), above. After we've dealt with that, ++ * our caller will relock and come back through here. ++ */ ++ finish_resume_report(task, utrace, &report); ++ ++ if (unlikely(fatal_signal_pending(task))) { ++ /* ++ * The only reason we woke up now was because of a ++ * SIGKILL. Don't do normal dequeuing in case it ++ * might get a signal other than SIGKILL. That would ++ * perturb the death state so it might differ from ++ * what the debugger would have allowed to happen. ++ * Instead, pluck out just the SIGKILL to be sure ++ * we'll die immediately with nothing else different ++ * from the quiescent state the debugger wanted us in. ++ */ ++ sigset_t sigkill_only; ++ siginitsetinv(&sigkill_only, sigmask(SIGKILL)); ++ spin_lock_irq(&task->sighand->siglock); ++ signr = dequeue_signal(task, &sigkill_only, info); ++ BUG_ON(signr != SIGKILL); ++ *return_ka = task->sighand->action[SIGKILL - 1]; ++ return signr; ++ } ++ ++ if (unlikely(report.result & UTRACE_SIGNAL_HOLD)) { ++ push_back_signal(task, info); ++ spin_unlock_irq(&task->sighand->siglock); ++ } ++ ++ return -1; ++ } ++ ++ /* ++ * Complete the bookkeeping after the report. ++ * This sets utrace->resume if UTRACE_STOP was used. ++ */ ++ finish_report(task, utrace, &report, true); ++ ++ return_ka->sa.sa_handler = SIG_DFL; ++ ++ /* ++ * If this signal is fatal, si_signo gets through as exit_code. ++ * We can't allow a completely bogus value there or else core ++ * kernel code can freak out. (If an engine wants to control ++ * the exit_code value exactly, it can do so in report_exit.) ++ * We'll produce a big complaint in dmesg, but won't crash. ++ * That's nicer for debugging your utrace engine. ++ */ ++ if (unlikely(info->si_signo & 0x80)) { ++ WARN(1, "utrace engine left bogus si_signo value!"); ++ info->si_signo = SIGTRAP; ++ } ++ ++ if (unlikely(report.result & UTRACE_SIGNAL_HOLD)) ++ push_back_signal(task, info); ++ else ++ spin_lock_irq(&task->sighand->siglock); ++ ++ if (sig_kernel_stop(signr)) ++ task->signal->flags |= SIGNAL_STOP_DEQUEUED; ++ ++ return signr; ++} ++ ++/* ++ * This gets called after a signal handler has been set up. ++ * We set a flag so the next report knows it happened. ++ * If we're already stepping, make sure we do a report_signal. ++ * If not, make sure we get into utrace_resume() where we can ++ * clear the signal_handler flag before resuming. ++ */ ++void utrace_signal_handler(struct task_struct *task, int stepping) ++{ ++ struct utrace *utrace = task_utrace_struct(task); ++ ++ spin_lock(&utrace->lock); ++ ++ utrace->signal_handler = 1; ++ if (utrace->resume > UTRACE_INTERRUPT) { ++ if (stepping) { ++ utrace->resume = UTRACE_INTERRUPT; ++ set_tsk_thread_flag(task, TIF_SIGPENDING); ++ } else if (utrace->resume == UTRACE_RESUME) { ++ set_tsk_thread_flag(task, TIF_NOTIFY_RESUME); ++ } ++ } ++ ++ spin_unlock(&utrace->lock); ++} ++ ++/** ++ * utrace_prepare_examine - prepare to examine thread state ++ * @target: thread of interest, a &struct task_struct pointer ++ * @engine: engine pointer returned by utrace_attach_task() ++ * @exam: temporary state, a &struct utrace_examiner pointer ++ * ++ * This call prepares to safely examine the thread @target using ++ * &struct user_regset calls, or direct access to thread-synchronous fields. ++ * ++ * When @target is current, this call is superfluous. When @target is ++ * another thread, it must be held stopped via %UTRACE_STOP by @engine. ++ * ++ * This call may block the caller until @target stays stopped, so it must ++ * be called only after the caller is sure @target is about to unschedule. ++ * This means a zero return from a utrace_control() call on @engine giving ++ * %UTRACE_STOP, or a report_quiesce() or report_signal() callback to ++ * @engine that used %UTRACE_STOP in its return value. ++ * ++ * Returns -%ESRCH if @target is dead or -%EINVAL if %UTRACE_STOP was ++ * not used. If @target has started running again despite %UTRACE_STOP ++ * (for %SIGKILL or a spurious wakeup), this call returns -%EAGAIN. ++ * ++ * When this call returns zero, it's safe to use &struct user_regset ++ * calls and task_user_regset_view() on @target and to examine some of ++ * its fields directly. When the examination is complete, a ++ * utrace_finish_examine() call must follow to check whether it was ++ * completed safely. ++ */ ++int utrace_prepare_examine(struct task_struct *target, ++ struct utrace_engine *engine, ++ struct utrace_examiner *exam) ++{ ++ int ret = 0; ++ ++ if (unlikely(target == current)) ++ return 0; ++ ++ rcu_read_lock(); ++ if (unlikely(!engine_wants_stop(engine))) ++ ret = -EINVAL; ++ else if (unlikely(target->exit_state)) ++ ret = -ESRCH; ++ else { ++ exam->state = target->state; ++ if (unlikely(exam->state == TASK_RUNNING)) ++ ret = -EAGAIN; ++ else ++ get_task_struct(target); ++ } ++ rcu_read_unlock(); ++ ++ if (likely(!ret)) { ++ exam->ncsw = wait_task_inactive(target, exam->state); ++ put_task_struct(target); ++ if (unlikely(!exam->ncsw)) ++ ret = -EAGAIN; ++ } ++ ++ return ret; ++} ++EXPORT_SYMBOL_GPL(utrace_prepare_examine); ++ ++/** ++ * utrace_finish_examine - complete an examination of thread state ++ * @target: thread of interest, a &struct task_struct pointer ++ * @engine: engine pointer returned by utrace_attach_task() ++ * @exam: pointer passed to utrace_prepare_examine() call ++ * ++ * This call completes an examination on the thread @target begun by a ++ * paired utrace_prepare_examine() call with the same arguments that ++ * returned success (zero). ++ * ++ * When @target is current, this call is superfluous. When @target is ++ * another thread, this returns zero if @target has remained unscheduled ++ * since the paired utrace_prepare_examine() call returned zero. ++ * ++ * When this returns an error, any examination done since the paired ++ * utrace_prepare_examine() call is unreliable and the data extracted ++ * should be discarded. The error is -%EINVAL if @engine is not ++ * keeping @target stopped, or -%EAGAIN if @target woke up unexpectedly. ++ */ ++int utrace_finish_examine(struct task_struct *target, ++ struct utrace_engine *engine, ++ struct utrace_examiner *exam) ++{ ++ int ret = 0; ++ ++ if (unlikely(target == current)) ++ return 0; ++ ++ rcu_read_lock(); ++ if (unlikely(!engine_wants_stop(engine))) ++ ret = -EINVAL; ++ else if (unlikely(target->state != exam->state)) ++ ret = -EAGAIN; ++ else ++ get_task_struct(target); ++ rcu_read_unlock(); ++ ++ if (likely(!ret)) { ++ unsigned long ncsw = wait_task_inactive(target, exam->state); ++ if (unlikely(ncsw != exam->ncsw)) ++ ret = -EAGAIN; ++ put_task_struct(target); ++ } ++ ++ return ret; ++} ++EXPORT_SYMBOL_GPL(utrace_finish_examine); ++ ++/* ++ * This is declared in linux/regset.h and defined in machine-dependent ++ * code. We put the export here to ensure no machine forgets it. ++ */ ++EXPORT_SYMBOL_GPL(task_user_regset_view); ++ ++/* ++ * Called with rcu_read_lock() held. ++ */ ++void task_utrace_proc_status(struct seq_file *m, struct task_struct *p) ++{ ++ seq_printf(m, "Utrace:\t%lx\n", p->utrace_flags); ++} diff --git a/linux-2.6-v4l-dvb-add-kworld-a340-support.patch b/linux-2.6-v4l-dvb-add-kworld-a340-support.patch new file mode 100644 index 000000000..95c912abd --- /dev/null +++ b/linux-2.6-v4l-dvb-add-kworld-a340-support.patch @@ -0,0 +1,148 @@ +[PATCH] dvb: add support for kworld 340u and ub435-q to em28xx-dvb + +This adds support for the KWorld PlusTV 340U and KWorld UB345-Q ATSC +sticks, which are really the same device. The sticks have an eMPIA +em2870 usb bridge chipset, an LG Electronics LGDT3304 ATSC/QAM +demodulator and an NXP TDA18271HD tuner -- early versions of the 340U +have a a TDA18271HD/C1, later models and the UB435-Q have a C2. + +The stick has been tested succesfully with both VSB_8 and QAM_256 signals. +Its using lgdt3304 support added to the lgdt3305 driver by a prior patch, +rather than the current lgdt3304 driver, as its severely lacking in +functionality by comparison (see said patch for details). + +Signed-off-by: Jarod Wilson + +--- +diff -r 14021dfc00f3 drivers/media/video/em28xx/em28xx-cards.c +--- a/drivers/media/video/em28xx/em28xx-cards.c Thu Feb 11 23:11:30 2010 -0200 ++++ b/drivers/media/video/em28xx/em28xx-cards.c Thu Feb 18 16:47:17 2010 -0500 +@@ -170,6 +170,22 @@ + { -1, -1, -1, -1}, + }; + ++/* ++ * KWorld PlusTV 340U and UB435-Q (ATSC) GPIOs map: ++ * EM_GPIO_0 - currently unknown ++ * EM_GPIO_1 - LED disable/enable (1 = off, 0 = on) ++ * EM_GPIO_2 - currently unknown ++ * EM_GPIO_3 - currently unknown ++ * EM_GPIO_4 - TDA18271HD/C1 tuner (1 = active, 0 = in reset) ++ * EM_GPIO_5 - LGDT3304 ATSC/QAM demod (1 = active, 0 = in reset) ++ * EM_GPIO_6 - currently unknown ++ * EM_GPIO_7 - currently unknown ++ */ ++static struct em28xx_reg_seq kworld_a340_digital[] = { ++ {EM28XX_R08_GPIO, 0x6d, ~EM_GPIO_4, 10}, ++ { -1, -1, -1, -1}, ++}; ++ + /* Pinnacle Hybrid Pro eb1a:2881 */ + static struct em28xx_reg_seq pinnacle_hybrid_pro_analog[] = { + {EM28XX_R08_GPIO, 0xfd, ~EM_GPIO_4, 10}, +@@ -1703,6 +1719,16 @@ + .tuner_gpio = reddo_dvb_c_usb_box, + .has_dvb = 1, + }, ++ /* 1b80:a340 - Empia EM2870, NXP TDA18271HD and LG DT3304, sold ++ * initially as the KWorld PlusTV 340U, then as the UB435-Q. ++ * Early variants have a TDA18271HD/C1, later ones a TDA18271HD/C2 */ ++ [EM2870_BOARD_KWORLD_A340] = { ++ .name = "KWorld PlusTV 340U or UB435-Q (ATSC)", ++ .tuner_type = TUNER_ABSENT, /* Digital-only TDA18271HD */ ++ .has_dvb = 1, ++ .dvb_gpio = kworld_a340_digital, ++ .tuner_gpio = default_tuner_gpio, ++ }, + }; + const unsigned int em28xx_bcount = ARRAY_SIZE(em28xx_boards); + +@@ -1826,6 +1852,8 @@ + .driver_info = EM2820_BOARD_IODATA_GVMVP_SZ }, + { USB_DEVICE(0xeb1a, 0x50a6), + .driver_info = EM2860_BOARD_GADMEI_UTV330 }, ++ { USB_DEVICE(0x1b80, 0xa340), ++ .driver_info = EM2870_BOARD_KWORLD_A340 }, + { }, + }; + MODULE_DEVICE_TABLE(usb, em28xx_id_table); +diff -r 14021dfc00f3 drivers/media/video/em28xx/em28xx-dvb.c +--- a/drivers/media/video/em28xx/em28xx-dvb.c Thu Feb 11 23:11:30 2010 -0200 ++++ b/drivers/media/video/em28xx/em28xx-dvb.c Thu Feb 18 16:47:17 2010 -0500 +@@ -30,11 +30,13 @@ + #include "tuner-simple.h" + + #include "lgdt330x.h" ++#include "lgdt3305.h" + #include "zl10353.h" + #include "s5h1409.h" + #include "mt352.h" + #include "mt352_priv.h" /* FIXME */ + #include "tda1002x.h" ++#include "tda18271.h" + + MODULE_DESCRIPTION("driver for em28xx based DVB cards"); + MODULE_AUTHOR("Mauro Carvalho Chehab "); +@@ -231,6 +233,18 @@ + .demod_chip = LGDT3303, + }; + ++static struct lgdt3305_config em2870_lgdt3304_dev = { ++ .i2c_addr = 0x0e, ++ .demod_chip = LGDT3304, ++ .spectral_inversion = 1, ++ .deny_i2c_rptr = 1, ++ .mpeg_mode = LGDT3305_MPEG_PARALLEL, ++ .tpclk_edge = LGDT3305_TPCLK_FALLING_EDGE, ++ .tpvalid_polarity = LGDT3305_TP_VALID_HIGH, ++ .vsb_if_khz = 3250, ++ .qam_if_khz = 4000, ++}; ++ + static struct zl10353_config em28xx_zl10353_with_xc3028 = { + .demod_address = (0x1e >> 1), + .no_tuner = 1, +@@ -247,6 +261,17 @@ + .mpeg_timing = S5H1409_MPEGTIMING_CONTINOUS_NONINVERTING_CLOCK + }; + ++static struct tda18271_std_map kworld_a340_std_map = { ++ .atsc_6 = { .if_freq = 3250, .agc_mode = 3, .std = 0, ++ .if_lvl = 1, .rfagc_top = 0x37, }, ++ .qam_6 = { .if_freq = 4000, .agc_mode = 3, .std = 1, ++ .if_lvl = 1, .rfagc_top = 0x37, }, ++}; ++ ++static struct tda18271_config kworld_a340_config = { ++ .std_map = &kworld_a340_std_map, ++}; ++ + static struct zl10353_config em28xx_zl10353_xc3028_no_i2c_gate = { + .demod_address = (0x1e >> 1), + .no_tuner = 1, +@@ -569,6 +594,14 @@ + } + } + break; ++ case EM2870_BOARD_KWORLD_A340: ++ dvb->frontend = dvb_attach(lgdt3305_attach, ++ &em2870_lgdt3304_dev, ++ &dev->i2c_adap); ++ if (dvb->frontend != NULL) ++ dvb_attach(tda18271_attach, dvb->frontend, 0x60, ++ &dev->i2c_adap, &kworld_a340_config); ++ break; + default: + em28xx_errdev("/2: The frontend of your DVB/ATSC card" + " isn't supported yet\n"); +diff -r 14021dfc00f3 drivers/media/video/em28xx/em28xx.h +--- a/drivers/media/video/em28xx/em28xx.h Thu Feb 11 23:11:30 2010 -0200 ++++ b/drivers/media/video/em28xx/em28xx.h Thu Feb 18 16:47:17 2010 -0500 +@@ -112,6 +112,7 @@ + #define EM2861_BOARD_GADMEI_UTV330PLUS 72 + #define EM2870_BOARD_REDDO_DVB_C_USB_BOX 73 + #define EM2800_BOARD_VC211A 74 ++#define EM2870_BOARD_KWORLD_A340 76 + + /* Limits minimum and default number of buffers */ + #define EM28XX_MIN_BUF 4 diff --git a/linux-2.6-v4l-dvb-add-lgdt3304-support.patch b/linux-2.6-v4l-dvb-add-lgdt3304-support.patch new file mode 100644 index 000000000..30c50434f --- /dev/null +++ b/linux-2.6-v4l-dvb-add-lgdt3304-support.patch @@ -0,0 +1,350 @@ +From b71e18093e2e7f240797875c50c49552722f8825 Mon Sep 17 00:00:00 2001 +From: Jarod Wilson +Date: Mon, 15 Feb 2010 17:13:25 -0500 +Subject: [PATCH 1/2] dvb: add lgdt3304 support to lgdt3305 driver + +There's a currently-unused lgdt3304 demod driver, which leaves a lot to +be desired as far as functionality. The 3304 is unsurprisingly quite +similar to the 3305, and empirical testing yeilds far better results +and more complete functionality by merging 3304 support into the 3305 +driver. (For example, the current lgdt3304 driver lacks support for +signal strength, snr, ucblocks, etc., which we get w/the lgdt3305). + +For the moment, not dropping the lgdt3304 driver, and its still up to +a given device's config setup to choose which demod driver to use, but +I'd suggest dropping the 3304 driver entirely. + +As a follow-up to this patch, I've got another patch that adds support +for the KWorld PlusTV 340U (ATSC) em2870-based tuner stick, driving +its lgdt3304 demod via this lgdt3305 driver, which is what I used to +successfully test this patch with both VSB_8 and QAM_256 signals. + +A few pieces are still a touch crude, but I think its a solid start, +as well as much cleaner and more feature-complete than the existing +lgdt3304 driver. + +Signed-off-by: Jarod Wilson +--- + drivers/media/dvb/frontends/lgdt3305.c | 206 ++++++++++++++++++++++++++++++-- + drivers/media/dvb/frontends/lgdt3305.h | 6 + + 2 files changed, 203 insertions(+), 9 deletions(-) + +diff --git a/drivers/media/dvb/frontends/lgdt3305.c b/drivers/media/dvb/frontends/lgdt3305.c +index fde8c59..40695e6 100644 +--- a/drivers/media/dvb/frontends/lgdt3305.c ++++ b/drivers/media/dvb/frontends/lgdt3305.c +@@ -1,5 +1,5 @@ + /* +- * Support for LGDT3305 - VSB/QAM ++ * Support for LG Electronics LGDT3304 and LGDT3305 - VSB/QAM + * + * Copyright (C) 2008, 2009 Michael Krufky + * +@@ -357,7 +357,10 @@ static int lgdt3305_rfagc_loop(struct lgdt3305_state *state, + case QAM_256: + agcdelay = 0x046b; + rfbw = 0x8889; +- ifbw = 0x8888; ++ if (state->cfg->demod_chip == LGDT3305) ++ ifbw = 0x8888; ++ else ++ ifbw = 0x6666; + break; + default: + return -EINVAL; +@@ -409,8 +412,18 @@ static int lgdt3305_agc_setup(struct lgdt3305_state *state, + lg_dbg("lockdten = %d, acqen = %d\n", lockdten, acqen); + + /* control agc function */ +- lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1); +- lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen); ++ switch (state->cfg->demod_chip) { ++ case LGDT3304: ++ lgdt3305_write_reg(state, 0x0314, 0xe1 | lockdten << 1); ++ lgdt3305_set_reg_bit(state, 0x030e, 2, acqen); ++ break; ++ case LGDT3305: ++ lgdt3305_write_reg(state, LGDT3305_AGC_CTRL_4, 0xe1 | lockdten << 1); ++ lgdt3305_set_reg_bit(state, LGDT3305_AGC_CTRL_1, 2, acqen); ++ break; ++ default: ++ return -EINVAL; ++ } + + return lgdt3305_rfagc_loop(state, param); + } +@@ -543,6 +556,11 @@ static int lgdt3305_i2c_gate_ctrl(struct dvb_frontend *fe, int enable) + enable ? 0 : 1); + } + ++static int lgdt3304_sleep(struct dvb_frontend *fe) ++{ ++ return 0; ++} ++ + static int lgdt3305_sleep(struct dvb_frontend *fe) + { + struct lgdt3305_state *state = fe->demodulator_priv; +@@ -571,6 +589,55 @@ static int lgdt3305_sleep(struct dvb_frontend *fe) + return 0; + } + ++static int lgdt3304_init(struct dvb_frontend *fe) ++{ ++ struct lgdt3305_state *state = fe->demodulator_priv; ++ int ret; ++ ++ static struct lgdt3305_reg lgdt3304_init_data[] = { ++ { .reg = LGDT3305_GEN_CTRL_1, .val = 0x03, }, ++ { .reg = 0x000d, .val = 0x02, }, ++ { .reg = 0x000e, .val = 0x02, }, ++ { .reg = LGDT3305_DGTL_AGC_REF_1, .val = 0x32, }, ++ { .reg = LGDT3305_DGTL_AGC_REF_2, .val = 0xc4, }, ++ { .reg = LGDT3305_CR_CTR_FREQ_1, .val = 0x00, }, ++ { .reg = LGDT3305_CR_CTR_FREQ_2, .val = 0x00, }, ++ { .reg = LGDT3305_CR_CTR_FREQ_3, .val = 0x00, }, ++ { .reg = LGDT3305_CR_CTR_FREQ_4, .val = 0x00, }, ++ { .reg = LGDT3305_CR_CTRL_7, .val = 0xf9, }, ++ { .reg = 0x0112, .val = 0x17, }, ++ { .reg = 0x0113, .val = 0x15, }, ++ { .reg = 0x0114, .val = 0x18, }, ++ { .reg = 0x0115, .val = 0xff, }, ++ { .reg = 0x0116, .val = 0x3c, }, ++ { .reg = 0x0214, .val = 0x67, }, ++ { .reg = 0x0424, .val = 0x8d, }, ++ { .reg = 0x0427, .val = 0x12, }, ++ { .reg = 0x0428, .val = 0x4f, }, ++ { .reg = LGDT3305_IFBW_1, .val = 0x80, }, ++ { .reg = LGDT3305_IFBW_2, .val = 0x00, }, ++ { .reg = 0x030a, .val = 0x08, }, ++ { .reg = 0x030b, .val = 0x9b, }, ++ { .reg = 0x030d, .val = 0x00, }, ++ { .reg = 0x030e, .val = 0x1c, }, ++ { .reg = 0x0314, .val = 0xe1, }, ++ { .reg = 0x000d, .val = 0x82, }, ++ { .reg = LGDT3305_TP_CTRL_1, .val = 0x5b, }, ++ { .reg = LGDT3305_TP_CTRL_1, .val = 0x5b, }, ++ }; ++ ++ lg_dbg("\n"); ++ ++ ret = lgdt3305_write_regs(state, lgdt3304_init_data, ++ ARRAY_SIZE(lgdt3304_init_data)); ++ if (lg_fail(ret)) ++ goto fail; ++ ++ ret = lgdt3305_soft_reset(state); ++fail: ++ return ret; ++} ++ + static int lgdt3305_init(struct dvb_frontend *fe) + { + struct lgdt3305_state *state = fe->demodulator_priv; +@@ -639,6 +706,88 @@ fail: + return ret; + } + ++static int lgdt3304_set_parameters(struct dvb_frontend *fe, ++ struct dvb_frontend_parameters *param) ++{ ++ struct lgdt3305_state *state = fe->demodulator_priv; ++ int ret; ++ ++ lg_dbg("(%d, %d)\n", param->frequency, param->u.vsb.modulation); ++ ++ if (fe->ops.tuner_ops.set_params) { ++ ret = fe->ops.tuner_ops.set_params(fe, param); ++ if (fe->ops.i2c_gate_ctrl) ++ fe->ops.i2c_gate_ctrl(fe, 0); ++ if (lg_fail(ret)) ++ goto fail; ++ state->current_frequency = param->frequency; ++ } ++ ++ ret = lgdt3305_set_modulation(state, param); ++ if (lg_fail(ret)) ++ goto fail; ++ ++ ret = lgdt3305_passband_digital_agc(state, param); ++ if (lg_fail(ret)) ++ goto fail; ++ ++ ret = lgdt3305_agc_setup(state, param); ++ if (lg_fail(ret)) ++ goto fail; ++ ++ /* reg 0x030d is 3304-only... seen in vsb and qam usbsnoops... */ ++ switch (param->u.vsb.modulation) { ++ case VSB_8: ++ lgdt3305_write_reg(state, 0x030d, 0x00); ++#if 1 ++ lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_1, 0x4f); ++ lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_2, 0x0c); ++ lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_3, 0xac); ++ lgdt3305_write_reg(state, LGDT3305_CR_CTR_FREQ_4, 0xba); ++#endif ++ break; ++ case QAM_64: ++ case QAM_256: ++ lgdt3305_write_reg(state, 0x030d, 0x14); ++#if 1 ++ ret = lgdt3305_set_if(state, param); ++ if (lg_fail(ret)) ++ goto fail; ++#endif ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++#if 0 ++ /* the set_if vsb formula doesn't work for the 3304, we end up sending ++ * 0x40851e07 instead of 0x4f0cacba (which works back to 94050, rather ++ * than 3250, in the case of the kworld 340u) */ ++ ret = lgdt3305_set_if(state, param); ++ if (lg_fail(ret)) ++ goto fail; ++#endif ++ ++ ret = lgdt3305_spectral_inversion(state, param, ++ state->cfg->spectral_inversion ++ ? 1 : 0); ++ if (lg_fail(ret)) ++ goto fail; ++ ++ state->current_modulation = param->u.vsb.modulation; ++ ++ ret = lgdt3305_mpeg_mode(state, state->cfg->mpeg_mode); ++ if (lg_fail(ret)) ++ goto fail; ++ ++ /* lgdt3305_mpeg_mode_polarity calls lgdt3305_soft_reset */ ++ ret = lgdt3305_mpeg_mode_polarity(state, ++ state->cfg->tpclk_edge, ++ state->cfg->tpvalid_polarity); ++fail: ++ return ret; ++} ++ + static int lgdt3305_set_parameters(struct dvb_frontend *fe, + struct dvb_frontend_parameters *param) + { +@@ -847,6 +996,10 @@ static int lgdt3305_read_status(struct dvb_frontend *fe, fe_status_t *status) + switch (state->current_modulation) { + case QAM_256: + case QAM_64: ++#if 0 /* needed w/3304 to set FE_HAS_SIGNAL */ ++ if (cr_lock) ++ *status |= FE_HAS_SIGNAL; ++#endif + ret = lgdt3305_read_fec_lock_status(state, &fec_lock); + if (lg_fail(ret)) + goto fail; +@@ -992,6 +1145,7 @@ static void lgdt3305_release(struct dvb_frontend *fe) + kfree(state); + } + ++static struct dvb_frontend_ops lgdt3304_ops; + static struct dvb_frontend_ops lgdt3305_ops; + + struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, +@@ -1012,11 +1166,21 @@ struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, + state->cfg = config; + state->i2c_adap = i2c_adap; + +- memcpy(&state->frontend.ops, &lgdt3305_ops, +- sizeof(struct dvb_frontend_ops)); ++ switch (config->demod_chip) { ++ case LGDT3304: ++ memcpy(&state->frontend.ops, &lgdt3304_ops, ++ sizeof(struct dvb_frontend_ops)); ++ break; ++ case LGDT3305: ++ memcpy(&state->frontend.ops, &lgdt3305_ops, ++ sizeof(struct dvb_frontend_ops)); ++ break; ++ default: ++ goto fail; ++ } + state->frontend.demodulator_priv = state; + +- /* verify that we're talking to a lg dt3305 */ ++ /* verify that we're talking to a lg dt3304/5 */ + ret = lgdt3305_read_reg(state, LGDT3305_GEN_CTRL_2, &val); + if ((lg_fail(ret)) | (val == 0)) + goto fail; +@@ -1035,12 +1199,36 @@ struct dvb_frontend *lgdt3305_attach(const struct lgdt3305_config *config, + + return &state->frontend; + fail: +- lg_warn("unable to detect LGDT3305 hardware\n"); ++ lg_warn("unable to detect %s hardware\n", ++ config->demod_chip ? "LGDT3304" : "LGDT3305"); + kfree(state); + return NULL; + } + EXPORT_SYMBOL(lgdt3305_attach); + ++static struct dvb_frontend_ops lgdt3304_ops = { ++ .info = { ++ .name = "LG Electronics LGDT3304 VSB/QAM Frontend", ++ .type = FE_ATSC, ++ .frequency_min = 54000000, ++ .frequency_max = 858000000, ++ .frequency_stepsize = 62500, ++ .caps = FE_CAN_QAM_64 | FE_CAN_QAM_256 | FE_CAN_8VSB ++ }, ++ .i2c_gate_ctrl = lgdt3305_i2c_gate_ctrl, ++ .init = lgdt3304_init, ++ .sleep = lgdt3304_sleep, ++ .set_frontend = lgdt3304_set_parameters, ++ .get_frontend = lgdt3305_get_frontend, ++ .get_tune_settings = lgdt3305_get_tune_settings, ++ .read_status = lgdt3305_read_status, ++ .read_ber = lgdt3305_read_ber, ++ .read_signal_strength = lgdt3305_read_signal_strength, ++ .read_snr = lgdt3305_read_snr, ++ .read_ucblocks = lgdt3305_read_ucblocks, ++ .release = lgdt3305_release, ++}; ++ + static struct dvb_frontend_ops lgdt3305_ops = { + .info = { + .name = "LG Electronics LGDT3305 VSB/QAM Frontend", +@@ -1064,7 +1252,7 @@ static struct dvb_frontend_ops lgdt3305_ops = { + .release = lgdt3305_release, + }; + +-MODULE_DESCRIPTION("LG Electronics LGDT3305 ATSC/QAM-B Demodulator Driver"); ++MODULE_DESCRIPTION("LG Electronics LGDT3304/5 ATSC/QAM-B Demodulator Driver"); + MODULE_AUTHOR("Michael Krufky "); + MODULE_LICENSE("GPL"); + MODULE_VERSION("0.1"); +diff --git a/drivers/media/dvb/frontends/lgdt3305.h b/drivers/media/dvb/frontends/lgdt3305.h +index 9cb11c9..a7f30c2 100644 +--- a/drivers/media/dvb/frontends/lgdt3305.h ++++ b/drivers/media/dvb/frontends/lgdt3305.h +@@ -41,6 +41,11 @@ enum lgdt3305_tp_valid_polarity { + LGDT3305_TP_VALID_HIGH = 1, + }; + ++enum lgdt_demod_chip_type { ++ LGDT3305 = 0, ++ LGDT3304 = 1, ++}; ++ + struct lgdt3305_config { + u8 i2c_addr; + +@@ -65,6 +70,7 @@ struct lgdt3305_config { + enum lgdt3305_mpeg_mode mpeg_mode; + enum lgdt3305_tp_clock_edge tpclk_edge; + enum lgdt3305_tp_valid_polarity tpvalid_polarity; ++ enum lgdt_demod_chip_type demod_chip; + }; + + #if defined(CONFIG_DVB_LGDT3305) || (defined(CONFIG_DVB_LGDT3305_MODULE) && \ +-- +1.6.6 + diff --git a/linux-2.6-v4l-dvb-experimental.patch b/linux-2.6-v4l-dvb-experimental.patch new file mode 100644 index 000000000..e69de29bb diff --git a/linux-2.6-v4l-dvb-fixes.patch b/linux-2.6-v4l-dvb-fixes.patch new file mode 100644 index 000000000..e69de29bb diff --git a/linux-2.6-v4l-dvb-gspca-fixes.patch b/linux-2.6-v4l-dvb-gspca-fixes.patch new file mode 100644 index 000000000..2677c0239 --- /dev/null +++ b/linux-2.6-v4l-dvb-gspca-fixes.patch @@ -0,0 +1,3982 @@ +From: German Galkin +Date: Sun, 7 Mar 2010 09:19:02 +0000 (-0300) +Subject: V4L/DVB: gspca - sn9c20x: Fix exposure control for HV7131R sensor +X-Git-Url: http://git.linuxtv.org/v4l-dvb.git?a=commitdiff_plain;h=0c05cee69fbef74a08f4f9804f0a3ca7ba39a3e2 + +V4L/DVB: gspca - sn9c20x: Fix exposure control for HV7131R sensor + +Make the range of exposure values (0-0x1770) distribute evenly through +HV7131R's exposure control bytes. + +Signed-off-by: German Galkin +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index 4a1bc08..dce5ef8 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -1654,9 +1654,9 @@ static int set_exposure(struct gspca_dev *gspca_dev) + case SENSOR_HV7131R: + exp[0] |= (4 << 4); + exp[2] = 0x25; +- exp[3] = ((sd->exposure * 0xffffff) / 0xffff) >> 16; +- exp[4] = ((sd->exposure * 0xffffff) / 0xffff) >> 8; +- exp[5] = ((sd->exposure * 0xffffff) / 0xffff) & 0xff; ++ exp[3] = (sd->exposure >> 5) & 0xff; ++ exp[4] = (sd->exposure << 3) & 0xff; ++ exp[5] = 0; + break; + default: + return 0; +From 1f6d33db111022345a85d8f441a22a5a46fc8ca2 Mon Sep 17 00:00:00 2001 +From: Brian Johnson +Date: Tue, 9 Mar 2010 19:53:05 -0500 +Subject: [PATCH] gspca - sn9c20x: use gspca's input device handling + +Drop custom code for handling the input button in +favor of using gspca's input hanlding mechinism. +--- + drivers/media/video/gspca/Kconfig | 6 -- + drivers/media/video/gspca/sn9c20x.c | 145 ++++++++--------------------------- + 2 files changed, 33 insertions(+), 118 deletions(-) + +diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig +index e0060c1..5d920e5 100644 +--- a/drivers/media/video/gspca/Kconfig ++++ b/drivers/media/video/gspca/Kconfig +@@ -172,12 +172,6 @@ config USB_GSPCA_SN9C20X + To compile this driver as a module, choose M here: the + module will be called gspca_sn9c20x. + +-config USB_GSPCA_SN9C20X_EVDEV +- bool "Enable evdev support" +- depends on USB_GSPCA_SN9C20X && INPUT +- ---help--- +- Say Y here in order to enable evdev support for sn9c20x webcam button. +- + config USB_GSPCA_SONIXB + tristate "SONIX Bayer USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index dce5ef8..d2a4902 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -18,10 +18,7 @@ + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ + +-#ifdef CONFIG_USB_GSPCA_SN9C20X_EVDEV +-#include +-#include +-#include ++#ifdef CONFIG_INPUT + #include + #endif + +@@ -54,6 +51,9 @@ MODULE_LICENSE("GPL"); + #define SENSOR_HV7131R 10 + #define SENSOR_MT9VPRB 20 + ++/* camera flags */ ++#define HAS_BUTTON 0x1 ++ + /* specific webcam descriptor */ + struct sd { + struct gspca_dev gspca_dev; +@@ -87,11 +87,7 @@ struct sd { + u8 *jpeg_hdr; + u8 quality; + +-#ifdef CONFIG_USB_GSPCA_SN9C20X_EVDEV +- struct input_dev *input_dev; +- u8 input_gpio; +- struct task_struct *input_task; +-#endif ++ u8 flags; + }; + + struct i2c_reg_u8 { +@@ -1420,87 +1416,6 @@ static int hv7131r_init_sensor(struct gspca_dev *gspca_dev) + return 0; + } + +-#ifdef CONFIG_USB_GSPCA_SN9C20X_EVDEV +-static int input_kthread(void *data) +-{ +- struct gspca_dev *gspca_dev = (struct gspca_dev *)data; +- struct sd *sd = (struct sd *) gspca_dev; +- +- DECLARE_WAIT_QUEUE_HEAD(wait); +- set_freezable(); +- for (;;) { +- if (kthread_should_stop()) +- break; +- +- if (reg_r(gspca_dev, 0x1005, 1) < 0) +- continue; +- +- input_report_key(sd->input_dev, +- KEY_CAMERA, +- gspca_dev->usb_buf[0] & sd->input_gpio); +- input_sync(sd->input_dev); +- +- wait_event_freezable_timeout(wait, +- kthread_should_stop(), +- msecs_to_jiffies(100)); +- } +- return 0; +-} +- +- +-static int sn9c20x_input_init(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- if (sd->input_gpio == 0) +- return 0; +- +- sd->input_dev = input_allocate_device(); +- if (!sd->input_dev) +- return -ENOMEM; +- +- sd->input_dev->name = "SN9C20X Webcam"; +- +- sd->input_dev->phys = kasprintf(GFP_KERNEL, "usb-%s-%s", +- gspca_dev->dev->bus->bus_name, +- gspca_dev->dev->devpath); +- +- if (!sd->input_dev->phys) +- return -ENOMEM; +- +- usb_to_input_id(gspca_dev->dev, &sd->input_dev->id); +- sd->input_dev->dev.parent = &gspca_dev->dev->dev; +- +- set_bit(EV_KEY, sd->input_dev->evbit); +- set_bit(KEY_CAMERA, sd->input_dev->keybit); +- +- if (input_register_device(sd->input_dev)) +- return -EINVAL; +- +- sd->input_task = kthread_run(input_kthread, gspca_dev, "sn9c20x/%s-%s", +- gspca_dev->dev->bus->bus_name, +- gspca_dev->dev->devpath); +- +- if (IS_ERR(sd->input_task)) +- return -EINVAL; +- +- return 0; +-} +- +-static void sn9c20x_input_cleanup(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- if (sd->input_task != NULL && !IS_ERR(sd->input_task)) +- kthread_stop(sd->input_task); +- +- if (sd->input_dev != NULL) { +- input_unregister_device(sd->input_dev); +- kfree(sd->input_dev->phys); +- input_free_device(sd->input_dev); +- sd->input_dev = NULL; +- } +-} +-#endif +- + static int set_cmatrix(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -2004,6 +1919,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + + sd->sensor = (id->driver_info >> 8) & 0xff; + sd->i2c_addr = id->driver_info & 0xff; ++ sd->flags = (id->driver_info >> 16) & 0xff; + + switch (sd->sensor) { + case SENSOR_MT9M111: +@@ -2038,11 +1954,6 @@ static int sd_config(struct gspca_dev *gspca_dev, + + sd->quality = 95; + +-#ifdef CONFIG_USB_GSPCA_SN9C20X_EVDEV +- sd->input_gpio = (id->driver_info >> 16) & 0xff; +- if (sn9c20x_input_init(gspca_dev) < 0) +- return -ENODEV; +-#endif + return 0; + } + +@@ -2342,6 +2253,24 @@ static void sd_dqcallback(struct gspca_dev *gspca_dev) + do_autoexposure(gspca_dev, avg_lum); + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet */ ++ int len) /* interrupt packet length */ ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret = -EINVAL; ++ if (sd->flags & HAS_BUTTON && len == 1) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ return ret; ++} ++#endif ++ + static void sd_pkt_scan(struct gspca_dev *gspca_dev, + u8 *data, /* isoc packet */ + int len) /* iso packet length */ +@@ -2408,6 +2337,9 @@ static const struct sd_desc sd_desc = { + .stopN = sd_stopN, + .stop0 = sd_stop0, + .pkt_scan = sd_pkt_scan, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + .dq_callback = sd_dqcallback, + #ifdef CONFIG_VIDEO_ADV_DEBUG + .set_register = sd_dbg_s_register, +@@ -2416,8 +2348,8 @@ static const struct sd_desc sd_desc = { + .get_chip_ident = sd_chip_ident, + }; + +-#define SN9C20X(sensor, i2c_addr, button_mask) \ +- .driver_info = (button_mask << 16) \ ++#define SN9C20X(sensor, i2c_addr, flags) \ ++ .driver_info = (flags << 16) \ + | (SENSOR_ ## sensor << 8) \ + | (i2c_addr) + +@@ -2425,7 +2357,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0c45, 0x6240), SN9C20X(MT9M001, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6242), SN9C20X(MT9M111, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)}, +- {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, 0x10)}, ++ {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, HAS_BUTTON)}, + {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)}, +@@ -2436,13 +2368,13 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0c45, 0x627f), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6280), SN9C20X(MT9M001, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6282), SN9C20X(MT9M111, 0x5d, 0)}, +- {USB_DEVICE(0x0c45, 0x6288), SN9C20X(OV9655, 0x30, 0)}, ++ {USB_DEVICE(0x0c45, 0x6288), SN9C20X(OV9655, 0x30, HAS_BUTTON)}, + {USB_DEVICE(0x0c45, 0x628e), SN9C20X(SOI968, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x628f), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x62a0), SN9C20X(OV7670, 0x21, 0)}, + {USB_DEVICE(0x0c45, 0x62b0), SN9C20X(MT9VPRB, 0x00, 0)}, + {USB_DEVICE(0x0c45, 0x62b3), SN9C20X(OV9655, 0x30, 0)}, +- {USB_DEVICE(0x0c45, 0x62bb), SN9C20X(OV7660, 0x21, 0)}, ++ {USB_DEVICE(0x0c45, 0x62bb), SN9C20X(OV7660, 0x21, HAS_BUTTON)}, + {USB_DEVICE(0x0c45, 0x62bc), SN9C20X(HV7131R, 0x11, 0)}, + {USB_DEVICE(0x045e, 0x00f4), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x145f, 0x013d), SN9C20X(OV7660, 0x21, 0)}, +@@ -2451,7 +2383,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0xa168, 0x0611), SN9C20X(HV7131R, 0x11, 0)}, + {USB_DEVICE(0xa168, 0x0613), SN9C20X(HV7131R, 0x11, 0)}, + {USB_DEVICE(0xa168, 0x0618), SN9C20X(HV7131R, 0x11, 0)}, +- {USB_DEVICE(0xa168, 0x0614), SN9C20X(MT9M111, 0x5d, 0)}, ++ {USB_DEVICE(0xa168, 0x0614), SN9C20X(MT9M111, 0x5d, HAS_BUTTON)}, + {USB_DEVICE(0xa168, 0x0615), SN9C20X(MT9M111, 0x5d, 0)}, + {USB_DEVICE(0xa168, 0x0617), SN9C20X(MT9M111, 0x5d, 0)}, + {} +@@ -2466,22 +2398,11 @@ static int sd_probe(struct usb_interface *intf, + THIS_MODULE); + } + +-static void sd_disconnect(struct usb_interface *intf) +-{ +-#ifdef CONFIG_USB_GSPCA_SN9C20X_EVDEV +- struct gspca_dev *gspca_dev = usb_get_intfdata(intf); +- +- sn9c20x_input_cleanup(gspca_dev); +-#endif +- +- gspca_disconnect(intf); +-} +- + static struct usb_driver sd_driver = { + .name = MODULE_NAME, + .id_table = device_table, + .probe = sd_probe, +- .disconnect = sd_disconnect, ++ .disconnect = gspca_disconnect, + #ifdef CONFIG_PM + .suspend = gspca_suspend, + .resume = gspca_resume, +-- +1.6.1 + +From ed53494aab1eadefa6b6c1413d59805839fb6fcf Mon Sep 17 00:00:00 2001 +From: Brian Johnson +Date: Tue, 9 Mar 2010 19:53:12 -0500 +Subject: [PATCH] gspca - sn9c20x: Add support for camera LEDs + +--- + drivers/media/video/gspca/sn9c20x.c | 18 +++++++++++++++--- + 1 files changed, 15 insertions(+), 3 deletions(-) + +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index d2a4902..0e8a64d 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -53,6 +53,7 @@ MODULE_LICENSE("GPL"); + + /* camera flags */ + #define HAS_BUTTON 0x1 ++#define LED_REVERSE 0x2 /* some cameras unset gpio to turn on leds */ + + /* specific webcam descriptor */ + struct sd { +@@ -730,7 +731,8 @@ static u16 bridge_init[][2] = { + {0x11be, 0xf0}, {0x11bf, 0x00}, {0x118c, 0x1f}, + {0x118d, 0x1f}, {0x118e, 0x1f}, {0x118f, 0x1f}, + {0x1180, 0x01}, {0x1181, 0x00}, {0x1182, 0x01}, +- {0x1183, 0x00}, {0x1184, 0x50}, {0x1185, 0x80} ++ {0x1183, 0x00}, {0x1184, 0x50}, {0x1185, 0x80}, ++ {0x1007, 0x00} + }; + + /* Gain = (bit[3:0] / 16 + 1) * (bit[4] + 1) * (bit[5] + 1) * (bit[6] + 1) */ +@@ -1973,6 +1975,11 @@ static int sd_init(struct gspca_dev *gspca_dev) + } + } + ++ if (sd->flags & LED_REVERSE) ++ reg_w1(gspca_dev, 0x1006, 0x00); ++ else ++ reg_w1(gspca_dev, 0x1006, 0x20); ++ + if (reg_w(gspca_dev, 0x10c0, i2c_init, 9) < 0) { + err("Device initialization failed"); + return -ENODEV; +@@ -2153,6 +2160,8 @@ static int sd_start(struct gspca_dev *gspca_dev) + set_exposure(gspca_dev); + set_hvflip(gspca_dev); + ++ reg_w1(gspca_dev, 0x1007, 0x20); ++ + reg_r(gspca_dev, 0x1061, 1); + reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] | 0x02); + return 0; +@@ -2160,6 +2169,8 @@ static int sd_start(struct gspca_dev *gspca_dev) + + static void sd_stopN(struct gspca_dev *gspca_dev) + { ++ reg_w1(gspca_dev, 0x1007, 0x00); ++ + reg_r(gspca_dev, 0x1061, 1); + reg_w1(gspca_dev, 0x1061, gspca_dev->usb_buf[0] & ~0x02); + } +@@ -2349,7 +2360,7 @@ static const struct sd_desc sd_desc = { + }; + + #define SN9C20X(sensor, i2c_addr, flags) \ +- .driver_info = (flags << 16) \ ++ .driver_info = ((flags & 0xff) << 16) \ + | (SENSOR_ ## sensor << 8) \ + | (i2c_addr) + +@@ -2357,7 +2368,8 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0c45, 0x6240), SN9C20X(MT9M001, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6242), SN9C20X(MT9M111, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)}, +- {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, HAS_BUTTON)}, ++ {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, ++ (HAS_BUTTON | LED_REVERSE))}, + {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)}, +-- +1.6.1 + +From c1dfdd5443097d4fbd773858a1c38d7b6b7dfcc1 Mon Sep 17 00:00:00 2001 +From: Brian Johnson +Date: Tue, 9 Mar 2010 19:55:51 -0500 +Subject: [PATCH] gspca - sn9c20x: Add upside down detection + +Add support for detecting webcams that are mounted +upside down in laptops. Currently the only two known +are two MSI modesl using the 0c45:624f. +--- + drivers/media/video/gspca/sn9c20x.c | 50 ++++++++++++++++++++++++++++------- + 1 files changed, 40 insertions(+), 10 deletions(-) + +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index 0e8a64d..41c8916 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -26,6 +26,7 @@ + #include "jpeg.h" + + #include ++#include + + MODULE_AUTHOR("Brian Johnson , " + "microdia project "); +@@ -54,6 +55,7 @@ MODULE_LICENSE("GPL"); + /* camera flags */ + #define HAS_BUTTON 0x1 + #define LED_REVERSE 0x2 /* some cameras unset gpio to turn on leds */ ++#define FLIP_DETECT 0x4 + + /* specific webcam descriptor */ + struct sd { +@@ -126,6 +128,25 @@ static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val); + static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val); + static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val); + ++static const struct dmi_system_id flip_dmi_table[] = { ++ { ++ .ident = "MSI MS-1034", ++ .matches = { ++ DMI_MATCH(DMI_SYS_VENDOR, "MICRO-STAR INT'L CO.,LTD."), ++ DMI_MATCH(DMI_PRODUCT_NAME, "MS-1034"), ++ DMI_MATCH(DMI_PRODUCT_VERSION, "0341") ++ } ++ }, ++ { ++ .ident = "MSI MS-1632", ++ .matches = { ++ DMI_MATCH(DMI_BOARD_VENDOR, "MSI"), ++ DMI_MATCH(DMI_BOARD_NAME, "MS-1632") ++ } ++ }, ++ {} ++}; ++ + static const struct ctrl sd_ctrls[] = { + { + #define BRIGHTNESS_IDX 0 +@@ -1495,17 +1516,26 @@ static int set_redblue(struct gspca_dev *gspca_dev) + + static int set_hvflip(struct gspca_dev *gspca_dev) + { +- u8 value, tslb; ++ u8 value, tslb, hflip, vflip; + u16 value2; + struct sd *sd = (struct sd *) gspca_dev; ++ ++ if ((sd->flags & FLIP_DETECT) && dmi_check_system(flip_dmi_table)) { ++ hflip = !sd->hflip; ++ vflip = !sd->vflip; ++ } else { ++ hflip = sd->hflip; ++ vflip = sd->vflip; ++ } ++ + switch (sd->sensor) { + case SENSOR_OV9650: + i2c_r1(gspca_dev, 0x1e, &value); + value &= ~0x30; + tslb = 0x01; +- if (sd->hflip) ++ if (hflip) + value |= 0x20; +- if (sd->vflip) { ++ if (vflip) { + value |= 0x10; + tslb = 0x49; + } +@@ -1516,9 +1546,9 @@ static int set_hvflip(struct gspca_dev *gspca_dev) + case SENSOR_MT9V011: + i2c_r2(gspca_dev, 0x20, &value2); + value2 &= ~0xc0a0; +- if (sd->hflip) ++ if (hflip) + value2 |= 0x8080; +- if (sd->vflip) ++ if (vflip) + value2 |= 0x4020; + i2c_w2(gspca_dev, 0x20, value2); + break; +@@ -1526,18 +1556,18 @@ static int set_hvflip(struct gspca_dev *gspca_dev) + case SENSOR_MT9V112: + i2c_r2(gspca_dev, 0x20, &value2); + value2 &= ~0x0003; +- if (sd->hflip) ++ if (hflip) + value2 |= 0x0002; +- if (sd->vflip) ++ if (vflip) + value2 |= 0x0001; + i2c_w2(gspca_dev, 0x20, value2); + break; + case SENSOR_HV7131R: + i2c_r1(gspca_dev, 0x01, &value); + value &= ~0x03; +- if (sd->vflip) ++ if (vflip) + value |= 0x01; +- if (sd->hflip) ++ if (hflip) + value |= 0x02; + i2c_w1(gspca_dev, 0x01, value); + break; +@@ -2370,7 +2400,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, + (HAS_BUTTON | LED_REVERSE))}, +- {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30, 0)}, ++ {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30, FLIP_DETECT)}, + {USB_DEVICE(0x0c45, 0x6251), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6253), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x6260), SN9C20X(OV7670, 0x21, 0)}, +-- +1.6.1 + +From 2e25ca5a85c702d2d49df7f5b1e3ecd61e01bf3e Mon Sep 17 00:00:00 2001 +From: Brian Johnson +Date: Tue, 9 Mar 2010 19:55:59 -0500 +Subject: [PATCH] gspca - sn9c20x: Add support for cameras using the MT9M112 sensor + +Adds the following models: + - 0c45:624c + - 0c45:628c + - 0458:704a + - 0458:704c +--- + Documentation/video4linux/gspca.txt | 4 +++ + drivers/media/video/gspca/sn9c20x.c | 44 ++++++++++++++++++++++++++++++++-- + 2 files changed, 45 insertions(+), 3 deletions(-) + +diff --git a/Documentation/video4linux/gspca.txt b/Documentation/video4linux/gspca.txt +index 181b9e6..3bfab2e 100644 +--- a/Documentation/video4linux/gspca.txt ++++ b/Documentation/video4linux/gspca.txt +@@ -50,6 +50,8 @@ zc3xx 0458:700f Genius VideoCam Web V2 + sonixj 0458:7025 Genius Eye 311Q + sn9c20x 0458:7029 Genius Look 320s + sonixj 0458:702e Genius Slim 310 NB ++sn9c20x 0458:704a Genius Slim 1320 ++sn9c20x 0458:704c Genius i-Look 1321 + sn9c20x 045e:00f4 LifeCam VX-6000 (SN9C20x + OV9650) + sonixj 045e:00f5 MicroSoft VX3000 + sonixj 045e:00f7 MicroSoft VX1000 +@@ -311,6 +313,7 @@ sonixj 0c45:614a Frontech E-Ccam (JIL-2225) + sn9c20x 0c45:6240 PC Camera (SN9C201 + MT9M001) + sn9c20x 0c45:6242 PC Camera (SN9C201 + MT9M111) + sn9c20x 0c45:6248 PC Camera (SN9C201 + OV9655) ++sn9c20x 0c45:624c PC Camera (SN9C201 + MT9M112) + sn9c20x 0c45:624e PC Camera (SN9C201 + SOI968) + sn9c20x 0c45:624f PC Camera (SN9C201 + OV9650) + sn9c20x 0c45:6251 PC Camera (SN9C201 + OV9650) +@@ -323,6 +326,7 @@ sn9c20x 0c45:627f PC Camera (SN9C201 + OV9650) + sn9c20x 0c45:6280 PC Camera (SN9C202 + MT9M001) + sn9c20x 0c45:6282 PC Camera (SN9C202 + MT9M111) + sn9c20x 0c45:6288 PC Camera (SN9C202 + OV9655) ++sn9c20x 0c45:628c PC Camera (SN9C201 + MT9M112) + sn9c20x 0c45:628e PC Camera (SN9C202 + SOI968) + sn9c20x 0c45:628f PC Camera (SN9C202 + OV9650) + sn9c20x 0c45:62a0 PC Camera (SN9C202 + OV7670) +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index 41c8916..8684596 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -49,7 +49,8 @@ MODULE_LICENSE("GPL"); + #define SENSOR_MT9V112 7 + #define SENSOR_MT9M001 8 + #define SENSOR_MT9M111 9 +-#define SENSOR_HV7131R 10 ++#define SENSOR_MT9M112 10 ++#define SENSOR_HV7131R 11 + #define SENSOR_MT9VPRB 20 + + /* camera flags */ +@@ -730,6 +731,7 @@ static u16 i2c_ident[] = { + V4L2_IDENT_MT9V112, + V4L2_IDENT_MT9M001C12ST, + V4L2_IDENT_MT9M111, ++ V4L2_IDENT_MT9M112, + V4L2_IDENT_HV7131R, + }; + +@@ -1061,6 +1063,13 @@ static struct i2c_reg_u16 mt9m111_init[] = { + {0xf0, 0x0000}, + }; + ++static struct i2c_reg_u16 mt9m112_init[] = { ++ {0xf0, 0x0000}, {0x0d, 0x0021}, {0x0d, 0x0008}, ++ {0xf0, 0x0001}, {0x3a, 0x4300}, {0x9b, 0x4300}, ++ {0x06, 0x708e}, {0xf0, 0x0002}, {0x2e, 0x0a1e}, ++ {0xf0, 0x0000}, ++}; ++ + static struct i2c_reg_u8 hv7131r_init[] = { + {0x02, 0x08}, {0x02, 0x00}, {0x01, 0x08}, + {0x02, 0x00}, {0x20, 0x00}, {0x21, 0xd0}, +@@ -1387,6 +1396,23 @@ static int mt9v_init_sensor(struct gspca_dev *gspca_dev) + return -ENODEV; + } + ++static int mt9m112_init_sensor(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int i; ++ for (i = 0; i < ARRAY_SIZE(mt9m112_init); i++) { ++ if (i2c_w2(gspca_dev, mt9m112_init[i].reg, ++ mt9m112_init[i].val) < 0) { ++ err("MT9M112 sensor initialization failed"); ++ return -ENODEV; ++ } ++ } ++ gspca_dev->ctrl_dis = (1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX) | (1 << GAIN_IDX); ++ sd->hstart = 0; ++ sd->vstart = 2; ++ return 0; ++} ++ + static int mt9m111_init_sensor(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -1552,6 +1578,7 @@ static int set_hvflip(struct gspca_dev *gspca_dev) + value2 |= 0x4020; + i2c_w2(gspca_dev, 0x20, value2); + break; ++ case SENSOR_MT9M112: + case SENSOR_MT9M111: + case SENSOR_MT9V112: + i2c_r2(gspca_dev, 0x20, &value2); +@@ -1877,7 +1904,7 @@ static int sd_dbg_g_register(struct gspca_dev *gspca_dev, + if (reg->match.addr != sd->i2c_addr) + return -EINVAL; + if (sd->sensor >= SENSOR_MT9V011 && +- sd->sensor <= SENSOR_MT9M111) { ++ sd->sensor <= SENSOR_MT9M112) { + if (i2c_r2(gspca_dev, reg->reg, (u16 *)®->val) < 0) + return -EINVAL; + } else { +@@ -1906,7 +1933,7 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev, + if (reg->match.addr != sd->i2c_addr) + return -EINVAL; + if (sd->sensor >= SENSOR_MT9V011 && +- sd->sensor <= SENSOR_MT9M111) { ++ sd->sensor <= SENSOR_MT9M112) { + if (i2c_w2(gspca_dev, reg->reg, reg->val) < 0) + return -EINVAL; + } else { +@@ -1954,6 +1981,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->flags = (id->driver_info >> 16) & 0xff; + + switch (sd->sensor) { ++ case SENSOR_MT9M112: + case SENSOR_MT9M111: + case SENSOR_OV9650: + case SENSOR_SOI968: +@@ -2050,6 +2078,11 @@ static int sd_init(struct gspca_dev *gspca_dev) + return -ENODEV; + info("MT9M111 sensor detected"); + break; ++ case SENSOR_MT9M112: ++ if (mt9m112_init_sensor(gspca_dev) < 0) ++ return -ENODEV; ++ info("MT9M112 sensor detected"); ++ break; + case SENSOR_MT9M001: + if (mt9m001_init_sensor(gspca_dev) < 0) + return -ENODEV; +@@ -2109,6 +2142,7 @@ static void configure_sensor_output(struct gspca_dev *gspca_dev, int mode) + i2c_w1(gspca_dev, 0x12, (value & 0x7) | 0x40); + } + break; ++ case SENSOR_MT9M112: + case SENSOR_MT9M111: + if (mode & MODE_SXGA) { + i2c_w2(gspca_dev, 0xf0, 0x0002); +@@ -2398,6 +2432,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0c45, 0x6240), SN9C20X(MT9M001, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6242), SN9C20X(MT9M111, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6248), SN9C20X(OV9655, 0x30, 0)}, ++ {USB_DEVICE(0x0c45, 0x624c), SN9C20X(MT9M112, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x624e), SN9C20X(SOI968, 0x30, + (HAS_BUTTON | LED_REVERSE))}, + {USB_DEVICE(0x0c45, 0x624f), SN9C20X(OV9650, 0x30, FLIP_DETECT)}, +@@ -2411,6 +2446,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0c45, 0x6280), SN9C20X(MT9M001, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6282), SN9C20X(MT9M111, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x6288), SN9C20X(OV9655, 0x30, HAS_BUTTON)}, ++ {USB_DEVICE(0x0c45, 0x628c), SN9C20X(MT9M112, 0x5d, 0)}, + {USB_DEVICE(0x0c45, 0x628e), SN9C20X(SOI968, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x628f), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x0c45, 0x62a0), SN9C20X(OV7670, 0x21, 0)}, +@@ -2421,6 +2457,8 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x045e, 0x00f4), SN9C20X(OV9650, 0x30, 0)}, + {USB_DEVICE(0x145f, 0x013d), SN9C20X(OV7660, 0x21, 0)}, + {USB_DEVICE(0x0458, 0x7029), SN9C20X(HV7131R, 0x11, 0)}, ++ {USB_DEVICE(0x0458, 0x704a), SN9C20X(MT9M112, 0x5d, 0)}, ++ {USB_DEVICE(0x0458, 0x704c), SN9C20X(MT9M112, 0x5d, 0)}, + {USB_DEVICE(0xa168, 0x0610), SN9C20X(HV7131R, 0x11, 0)}, + {USB_DEVICE(0xa168, 0x0611), SN9C20X(HV7131R, 0x11, 0)}, + {USB_DEVICE(0xa168, 0x0613), SN9C20X(HV7131R, 0x11, 0)}, +-- +1.6.1 + +From 9a4ef004b953572b479c643f2314ea352b74d732 Mon Sep 17 00:00:00 2001 +From: Brian Johnson +Date: Tue, 9 Mar 2010 19:57:55 -0500 +Subject: [PATCH] gspca - sn9c20x: Fix bug with OV9655 code + +Fixed buggy init sequence for the OV9655 sensor. +Tested with a 0c45:6288 and 0c45:62b3. +--- + drivers/media/video/gspca/sn9c20x.c | 58 ++++++++++++++-------------------- + 1 files changed, 24 insertions(+), 34 deletions(-) + +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index 8684596..69a3aa3 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -934,40 +934,30 @@ static struct i2c_reg_u8 ov9650_init[] = { + }; + + static struct i2c_reg_u8 ov9655_init[] = { +- {0x12, 0x80}, {0x12, 0x01}, {0x0d, 0x00}, {0x0e, 0x61}, +- {0x11, 0x80}, {0x13, 0xba}, {0x14, 0x2e}, {0x16, 0x24}, +- {0x1e, 0x04}, {0x1e, 0x04}, {0x1e, 0x04}, {0x27, 0x08}, +- {0x28, 0x08}, {0x29, 0x15}, {0x2c, 0x08}, {0x32, 0xbf}, +- {0x34, 0x3d}, {0x35, 0x00}, {0x36, 0xf8}, {0x38, 0x12}, +- {0x39, 0x57}, {0x3a, 0x00}, {0x3b, 0xcc}, {0x3c, 0x0c}, +- {0x3d, 0x19}, {0x3e, 0x0c}, {0x3f, 0x01}, {0x41, 0x40}, +- {0x42, 0x80}, {0x45, 0x46}, {0x46, 0x62}, {0x47, 0x2a}, +- {0x48, 0x3c}, {0x4a, 0xf0}, {0x4b, 0xdc}, {0x4c, 0xdc}, +- {0x4d, 0xdc}, {0x4e, 0xdc}, {0x69, 0x02}, {0x6c, 0x04}, +- {0x6f, 0x9e}, {0x70, 0x05}, {0x71, 0x78}, {0x77, 0x02}, +- {0x8a, 0x23}, {0x8c, 0x0d}, {0x90, 0x7e}, {0x91, 0x7c}, +- {0x9f, 0x6e}, {0xa0, 0x6e}, {0xa5, 0x68}, {0xa6, 0x60}, +- {0xa8, 0xc1}, {0xa9, 0xfa}, {0xaa, 0x92}, {0xab, 0x04}, +- {0xac, 0x80}, {0xad, 0x80}, {0xae, 0x80}, {0xaf, 0x80}, +- {0xb2, 0xf2}, {0xb3, 0x20}, {0xb5, 0x00}, {0xb6, 0xaf}, +- {0xbb, 0xae}, {0xbc, 0x44}, {0xbd, 0x44}, {0xbe, 0x3b}, +- {0xbf, 0x3a}, {0xc0, 0xe2}, {0xc1, 0xc8}, {0xc2, 0x01}, ++ {0x12, 0x80}, {0x0e, 0x61}, {0x11, 0x80}, {0x13, 0xba}, ++ {0x14, 0x2e}, {0x16, 0x24}, {0x1e, 0x04}, {0x27, 0x08}, ++ {0x28, 0x08}, {0x29, 0x15}, {0x2c, 0x08}, {0x34, 0x3d}, ++ {0x35, 0x00}, {0x38, 0x12}, {0x0f, 0x42}, {0x39, 0x57}, ++ {0x3a, 0x00}, {0x3b, 0xcc}, {0x3c, 0x0c}, {0x3d, 0x19}, ++ {0x3e, 0x0c}, {0x3f, 0x01}, {0x41, 0x40}, {0x42, 0x80}, ++ {0x45, 0x46}, {0x46, 0x62}, {0x47, 0x2a}, {0x48, 0x3c}, ++ {0x4a, 0xf0}, {0x4b, 0xdc}, {0x4c, 0xdc}, {0x4d, 0xdc}, ++ {0x4e, 0xdc}, {0x6c, 0x04}, {0x6f, 0x9e}, {0x70, 0x05}, ++ {0x71, 0x78}, {0x77, 0x02}, {0x8a, 0x23}, {0x90, 0x7e}, ++ {0x91, 0x7c}, {0x9f, 0x6e}, {0xa0, 0x6e}, {0xa5, 0x68}, ++ {0xa6, 0x60}, {0xa8, 0xc1}, {0xa9, 0xfa}, {0xaa, 0x92}, ++ {0xab, 0x04}, {0xac, 0x80}, {0xad, 0x80}, {0xae, 0x80}, ++ {0xaf, 0x80}, {0xb2, 0xf2}, {0xb3, 0x20}, {0xb5, 0x00}, ++ {0xb6, 0xaf}, {0xbb, 0xae}, {0xbc, 0x44}, {0xbd, 0x44}, ++ {0xbe, 0x3b}, {0xbf, 0x3a}, {0xc1, 0xc8}, {0xc2, 0x01}, + {0xc4, 0x00}, {0xc6, 0x85}, {0xc7, 0x81}, {0xc9, 0xe0}, +- {0xca, 0xe8}, {0xcc, 0xd8}, {0xcd, 0x93}, {0x12, 0x61}, ++ {0xca, 0xe8}, {0xcc, 0xd8}, {0xcd, 0x93}, {0x2d, 0x00}, ++ {0x2e, 0x00}, {0x01, 0x80}, {0x02, 0x80}, {0x12, 0x61}, + {0x36, 0xfa}, {0x8c, 0x8d}, {0xc0, 0xaa}, {0x69, 0x0a}, +- {0x03, 0x12}, {0x17, 0x14}, {0x18, 0x00}, {0x19, 0x01}, +- {0x1a, 0x3d}, {0x32, 0xbf}, {0x11, 0x80}, {0x2a, 0x10}, +- {0x2b, 0x0a}, {0x92, 0x00}, {0x93, 0x00}, {0x1e, 0x04}, +- {0x1e, 0x04}, {0x10, 0x7c}, {0x04, 0x03}, {0xa1, 0x00}, +- {0x2d, 0x00}, {0x2e, 0x00}, {0x00, 0x00}, {0x01, 0x80}, +- {0x02, 0x80}, {0x12, 0x61}, {0x36, 0xfa}, {0x8c, 0x8d}, +- {0xc0, 0xaa}, {0x69, 0x0a}, {0x03, 0x12}, {0x17, 0x14}, +- {0x18, 0x00}, {0x19, 0x01}, {0x1a, 0x3d}, {0x32, 0xbf}, +- {0x11, 0x80}, {0x2a, 0x10}, {0x2b, 0x0a}, {0x92, 0x00}, +- {0x93, 0x00}, {0x04, 0x01}, {0x10, 0x1f}, {0xa1, 0x00}, +- {0x00, 0x0a}, {0xa1, 0x00}, {0x10, 0x5d}, {0x04, 0x03}, +- {0x00, 0x01}, {0xa1, 0x00}, {0x10, 0x7c}, {0x04, 0x03}, +- {0x00, 0x03}, {0x00, 0x0a}, {0x00, 0x10}, {0x00, 0x13}, ++ {0x03, 0x09}, {0x17, 0x16}, {0x18, 0x6e}, {0x19, 0x01}, ++ {0x1a, 0x3e}, {0x32, 0x09}, {0x2a, 0x10}, {0x2b, 0x0a}, ++ {0x92, 0x00}, {0x93, 0x00}, {0xa1, 0x00}, {0x10, 0x7c}, ++ {0x04, 0x03}, {0x00, 0x13}, + }; + + static struct i2c_reg_u16 mt9v112_init[] = { +@@ -1267,8 +1257,8 @@ static int ov9655_init_sensor(struct gspca_dev *gspca_dev) + } + /* disable hflip and vflip */ + gspca_dev->ctrl_dis = (1 << HFLIP_IDX) | (1 << VFLIP_IDX); +- sd->hstart = 0; +- sd->vstart = 7; ++ sd->hstart = 1; ++ sd->vstart = 2; + return 0; + } + +-- +1.6.1 + +From: Max Thrun +Date: Sat, 27 Feb 2010 20:20:18 +0000 (-0300) +Subject: V4L/DVB: gspca- ov534: Remove ambiguous controls +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=c8e6b4f9f77d44edef3ef9ffd25957a204beb444 + +V4L/DVB: gspca- ov534: Remove ambiguous controls + +Remove Blue/Red Channel Target Value, they are meant for Black Level +Calibration but it is not completely clear how to use them. + +Signed-off-by: Max Thrun +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 957e05e..2a0e8a3 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -60,8 +60,6 @@ struct sd { + u8 contrast; + u8 gain; + u8 exposure; +- u8 redblc; +- u8 blueblc; + u8 hue; + u8 autogain; + u8 awb; +@@ -76,10 +74,6 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); +-static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val); +-static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val); +-static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val); +-static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); +@@ -156,34 +150,6 @@ static const struct ctrl sd_ctrls[] = { + }, + { /* 4 */ + { +- .id = V4L2_CID_RED_BALANCE, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Red Balance", +- .minimum = 0, +- .maximum = 255, +- .step = 1, +-#define RED_BALANCE_DEF 128 +- .default_value = RED_BALANCE_DEF, +- }, +- .set = sd_setredblc, +- .get = sd_getredblc, +- }, +- { /* 5 */ +- { +- .id = V4L2_CID_BLUE_BALANCE, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Blue Balance", +- .minimum = 0, +- .maximum = 255, +- .step = 1, +-#define BLUE_BALANCE_DEF 128 +- .default_value = BLUE_BALANCE_DEF, +- }, +- .set = sd_setblueblc, +- .get = sd_getblueblc, +- }, +- { /* 6 */ +- { + .id = V4L2_CID_HUE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Hue", +@@ -196,7 +162,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_sethue, + .get = sd_gethue, + }, +- { /* 7 */ ++ { /* 5 */ + { + .id = V4L2_CID_AUTOGAIN, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -210,8 +176,8 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setautogain, + .get = sd_getautogain, + }, +-#define AWB_IDX 8 +- { /* 8 */ ++#define AWB_IDX 6 ++ { /* 6 */ + { + .id = V4L2_CID_AUTO_WHITE_BALANCE, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -225,7 +191,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setawb, + .get = sd_getawb, + }, +- { /* 9 */ ++ { /* 7 */ + { + .id = V4L2_CID_SHARPNESS, + .type = V4L2_CTRL_TYPE_INTEGER, +@@ -239,7 +205,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setsharpness, + .get = sd_getsharpness, + }, +- { /* 10 */ ++ { /* 8 */ + { + .id = V4L2_CID_HFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -253,7 +219,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_sethflip, + .get = sd_gethflip, + }, +- { /* 11 */ ++ { /* 9 */ + { + .id = V4L2_CID_VFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -722,20 +688,6 @@ static void setexposure(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x10, val << 1); + } + +-static void setredblc(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sccb_reg_write(gspca_dev, 0x43, sd->redblc); +-} +- +-static void setblueblc(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sccb_reg_write(gspca_dev, 0x42, sd->blueblc); +-} +- + static void sethue(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -825,8 +777,6 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->contrast = CONTRAST_DEF; + sd->gain = GAIN_DEF; + sd->exposure = EXPO_DEF; +- sd->redblc = RED_BALANCE_DEF; +- sd->blueblc = BLUE_BALANCE_DEF; + sd->hue = HUE_DEF; + #if AUTOGAIN_DEF != 0 + sd->autogain = AUTOGAIN_DEF; +@@ -907,8 +857,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + setautogain(gspca_dev); + setawb(gspca_dev); + setgain(gspca_dev); +- setredblc(gspca_dev); +- setblueblc(gspca_dev); + sethue(gspca_dev); + setexposure(gspca_dev); + setbrightness(gspca_dev); +@@ -1092,42 +1040,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + +-static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sd->redblc = val; +- if (gspca_dev->streaming) +- setredblc(gspca_dev); +- return 0; +-} +- +-static int sd_getredblc(struct gspca_dev *gspca_dev, __s32 *val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- *val = sd->redblc; +- return 0; +-} +- +-static int sd_setblueblc(struct gspca_dev *gspca_dev, __s32 val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sd->blueblc = val; +- if (gspca_dev->streaming) +- setblueblc(gspca_dev); +- return 0; +-} +- +-static int sd_getblueblc(struct gspca_dev *gspca_dev, __s32 *val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- *val = sd->blueblc; +- return 0; +-} +- + static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +From: Antonio Ospite +Date: Sat, 27 Feb 2010 20:20:19 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Remove hue control +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=6acd5f4ec11256cc11f8068f17121087765b5c7f + +V4L/DVB: gspca - ov534: Remove hue control + +Hue control doesn't work and the sensor datasheet is not clear about how +to set hue properly. + +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 2a0e8a3..186827a 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -60,7 +60,6 @@ struct sd { + u8 contrast; + u8 gain; + u8 exposure; +- u8 hue; + u8 autogain; + u8 awb; + s8 sharpness; +@@ -82,8 +81,6 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); + static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); +-static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val); +-static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); +@@ -150,20 +147,6 @@ static const struct ctrl sd_ctrls[] = { + }, + { /* 4 */ + { +- .id = V4L2_CID_HUE, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Hue", +- .minimum = 0, +- .maximum = 255, +- .step = 1, +-#define HUE_DEF 143 +- .default_value = HUE_DEF, +- }, +- .set = sd_sethue, +- .get = sd_gethue, +- }, +- { /* 5 */ +- { + .id = V4L2_CID_AUTOGAIN, + .type = V4L2_CTRL_TYPE_BOOLEAN, + .name = "Autogain", +@@ -176,8 +159,8 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setautogain, + .get = sd_getautogain, + }, +-#define AWB_IDX 6 +- { /* 6 */ ++#define AWB_IDX 5 ++ { /* 5 */ + { + .id = V4L2_CID_AUTO_WHITE_BALANCE, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -191,7 +174,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setawb, + .get = sd_getawb, + }, +- { /* 7 */ ++ { /* 6 */ + { + .id = V4L2_CID_SHARPNESS, + .type = V4L2_CTRL_TYPE_INTEGER, +@@ -205,7 +188,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setsharpness, + .get = sd_getsharpness, + }, +- { /* 8 */ ++ { /* 7 */ + { + .id = V4L2_CID_HFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -219,7 +202,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_sethflip, + .get = sd_gethflip, + }, +- { /* 9 */ ++ { /* 8 */ + { + .id = V4L2_CID_VFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -688,13 +671,6 @@ static void setexposure(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x10, val << 1); + } + +-static void sethue(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sccb_reg_write(gspca_dev, 0x01, sd->hue); +-} +- + static void setautogain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -777,7 +753,6 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->contrast = CONTRAST_DEF; + sd->gain = GAIN_DEF; + sd->exposure = EXPO_DEF; +- sd->hue = HUE_DEF; + #if AUTOGAIN_DEF != 0 + sd->autogain = AUTOGAIN_DEF; + #else +@@ -857,7 +832,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + setautogain(gspca_dev); + setawb(gspca_dev); + setgain(gspca_dev); +- sethue(gspca_dev); + setexposure(gspca_dev); + setbrightness(gspca_dev); + setcontrast(gspca_dev); +@@ -1040,24 +1014,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + +-static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sd->hue = val; +- if (gspca_dev->streaming) +- sethue(gspca_dev); +- return 0; +-} +- +-static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- *val = sd->hue; +- return 0; +-} +- + static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +From: Max Thrun +Date: Sat, 27 Feb 2010 20:20:20 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Fix autogain control, enable it by default +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=0de1d89b747863562f1fdf7501b8e1fb5d54b33e + +V4L/DVB: gspca - ov534: Fix autogain control, enable it by default + +* Use 'agc' instead of 'autogain' in the code so to align the naming + as in AEC/AWB. + * Tweak brightness and contrast default values. + * Fix setting/resetting registers values for AGC. + * Set actual gain back when disabling AGC. + * Skip setting GAIN register when AGC is enabled. + * Enable AGC by default. + +Note that as Auto Gain Control is now enabled by default, if you are +using the driver for visual computing applications you might need to +disable it explicitly in your software. + +Signed-off-by: Max Thrun +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 186827a..4058e22 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -60,7 +60,7 @@ struct sd { + u8 contrast; + u8 gain; + u8 exposure; +- u8 autogain; ++ u8 agc; + u8 awb; + s8 sharpness; + u8 hflip; +@@ -73,8 +73,8 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); +-static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); +-static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); +@@ -97,7 +97,7 @@ static const struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 255, + .step = 1, +-#define BRIGHTNESS_DEF 20 ++#define BRIGHTNESS_DEF 0 + .default_value = BRIGHTNESS_DEF, + }, + .set = sd_setbrightness, +@@ -111,7 +111,7 @@ static const struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 255, + .step = 1, +-#define CONTRAST_DEF 37 ++#define CONTRAST_DEF 32 + .default_value = CONTRAST_DEF, + }, + .set = sd_setcontrast, +@@ -149,15 +149,15 @@ static const struct ctrl sd_ctrls[] = { + { + .id = V4L2_CID_AUTOGAIN, + .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "Autogain", ++ .name = "Auto Gain", + .minimum = 0, + .maximum = 1, + .step = 1, +-#define AUTOGAIN_DEF 0 +- .default_value = AUTOGAIN_DEF, ++#define AGC_DEF 1 ++ .default_value = AGC_DEF, + }, +- .set = sd_setautogain, +- .get = sd_getautogain, ++ .set = sd_setagc, ++ .get = sd_getagc, + }, + #define AWB_IDX 5 + { /* 5 */ +@@ -639,6 +639,9 @@ static void setgain(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + u8 val; + ++ if (sd->agc) ++ return; ++ + val = sd->gain; + switch (val & 0x30) { + case 0x00: +@@ -671,18 +674,22 @@ static void setexposure(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x10, val << 1); + } + +-static void setautogain(struct gspca_dev *gspca_dev) ++static void setagc(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + +- if (sd->autogain) { +- sccb_reg_write(gspca_dev, 0x13, 0xf7); /* AGC,AEC,AWB ON */ ++ if (sd->agc) { ++ sccb_reg_write(gspca_dev, 0x13, ++ sccb_reg_read(gspca_dev, 0x13) | 0x04); + sccb_reg_write(gspca_dev, 0x64, + sccb_reg_read(gspca_dev, 0x64) | 0x03); + } else { +- sccb_reg_write(gspca_dev, 0x13, 0xf0); /* AGC,AEC,AWB OFF */ ++ sccb_reg_write(gspca_dev, 0x13, ++ sccb_reg_read(gspca_dev, 0x13) & ~0x04); + sccb_reg_write(gspca_dev, 0x64, +- sccb_reg_read(gspca_dev, 0x64) & 0xfc); ++ sccb_reg_read(gspca_dev, 0x64) & ~0x03); ++ ++ setgain(gspca_dev); + } + } + +@@ -753,8 +760,8 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->contrast = CONTRAST_DEF; + sd->gain = GAIN_DEF; + sd->exposure = EXPO_DEF; +-#if AUTOGAIN_DEF != 0 +- sd->autogain = AUTOGAIN_DEF; ++#if AGC_DEF != 0 ++ sd->agc = AGC_DEF; + #else + gspca_dev->ctrl_inac |= (1 << AWB_IDX); + #endif +@@ -829,7 +836,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + } + set_frame_rate(gspca_dev); + +- setautogain(gspca_dev); ++ setagc(gspca_dev); + setawb(gspca_dev); + setgain(gspca_dev); + setexposure(gspca_dev); +@@ -1014,11 +1021,11 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + +-static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) ++static int sd_setagc(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; + +- sd->autogain = val; ++ sd->agc = val; + + if (gspca_dev->streaming) { + +@@ -1028,16 +1035,16 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) + gspca_dev->ctrl_inac &= ~(1 << AWB_IDX); + else + gspca_dev->ctrl_inac |= (1 << AWB_IDX); +- setautogain(gspca_dev); ++ setagc(gspca_dev); + } + return 0; + } + +-static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) ++static int sd_getagc(struct gspca_dev *gspca_dev, __s32 *val) + { + struct sd *sd = (struct sd *) gspca_dev; + +- *val = sd->autogain; ++ *val = sd->agc; + return 0; + } + +From: Max Thrun +Date: Sat, 27 Feb 2010 20:20:21 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Add Auto Exposure +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=9f886b52dd32c4eac5d5be13f74824856ff32baf + +V4L/DVB: gspca - ov534: Add Auto Exposure + +This also makes manual exposure actually work: it never worked before +because AEC was always enabled. + +Signed-off-by: Max Thrun +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 4058e22..2d89650 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -62,6 +62,7 @@ struct sd { + u8 exposure; + u8 agc; + u8 awb; ++ u8 aec; + s8 sharpness; + u8 hflip; + u8 vflip; +@@ -83,6 +84,8 @@ static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setawb(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); +@@ -176,6 +179,20 @@ static const struct ctrl sd_ctrls[] = { + }, + { /* 6 */ + { ++ .id = V4L2_CID_EXPOSURE_AUTO, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "Auto Exposure", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, ++#define AEC_DEF 1 ++ .default_value = AEC_DEF, ++ }, ++ .set = sd_setaec, ++ .get = sd_getaec, ++ }, ++ { /* 7 */ ++ { + .id = V4L2_CID_SHARPNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Sharpness", +@@ -188,7 +205,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setsharpness, + .get = sd_getsharpness, + }, +- { /* 7 */ ++ { /* 8 */ + { + .id = V4L2_CID_HFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -202,7 +219,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_sethflip, + .get = sd_gethflip, + }, +- { /* 8 */ ++ { /* 9 */ + { + .id = V4L2_CID_VFLIP, + .type = V4L2_CTRL_TYPE_BOOLEAN, +@@ -703,6 +720,20 @@ static void setawb(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */ + } + ++static void setaec(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (sd->aec) ++ sccb_reg_write(gspca_dev, 0x13, ++ sccb_reg_read(gspca_dev, 0x13) | 0x01); ++ else { ++ sccb_reg_write(gspca_dev, 0x13, ++ sccb_reg_read(gspca_dev, 0x13) & ~0x01); ++ setexposure(gspca_dev); ++ } ++} ++ + static void setsharpness(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -768,6 +799,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + #if AWB_DEF != 0 + sd->awb = AWB_DEF + #endif ++ sd->aec = AEC_DEF; + #if SHARPNESS_DEF != 0 + sd->sharpness = SHARPNESS_DEF; + #endif +@@ -838,6 +870,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + + setagc(gspca_dev); + setawb(gspca_dev); ++ setaec(gspca_dev); + setgain(gspca_dev); + setexposure(gspca_dev); + setbrightness(gspca_dev); +@@ -1066,6 +1099,24 @@ static int sd_getawb(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + ++static int sd_setaec(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->aec = val; ++ if (gspca_dev->streaming) ++ setaec(gspca_dev); ++ return 0; ++} ++ ++static int sd_getaec(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->aec; ++ return 0; ++} ++ + static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +From: Antonio Ospite +Date: Mon, 1 Mar 2010 11:53:34 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Fix and document setting manual exposure +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=c8b4264e60b378aa73dc59d434c930bc9345c890 + +V4L/DVB: gspca - ov534: Fix and document setting manual exposure + +Document that even if the state is a u8 value, both MSB and LSB are set +as sd->exposure represents half of the value we are going to set into +registers. + +Skip setting exposure when AEC is enabled. + +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 2d89650..4fda098 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -686,6 +686,15 @@ static void setexposure(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + u8 val; + ++ if (sd->aec) ++ return; ++ ++ /* 'val' is one byte and represents half of the exposure value we are ++ * going to set into registers, a two bytes value: ++ * ++ * MSB: ((u16) val << 1) >> 8 == val >> 7 ++ * LSB: ((u16) val << 1) & 0xff == val << 1 ++ */ + val = sd->exposure; + sccb_reg_write(gspca_dev, 0x08, val >> 7); + sccb_reg_write(gspca_dev, 0x10, val << 1); +From: Max Thrun +Date: Sat, 27 Feb 2010 20:20:23 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Fix Auto White Balance control +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=6a7410900b54e9af7f9282917a8bcbc9835ffaa1 + +V4L/DVB: gspca - ov534: Fix Auto White Balance control + +Set only the needed bits for AWB, and enable it by default. + +Signed-off-by: Max Thrun +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 4fda098..3b538d7 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -171,7 +171,7 @@ static const struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 1, + .step = 1, +-#define AWB_DEF 0 ++#define AWB_DEF 1 + .default_value = AWB_DEF, + }, + .set = sd_setawb, +@@ -723,10 +723,17 @@ static void setawb(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + +- if (sd->awb) +- sccb_reg_write(gspca_dev, 0x63, 0xe0); /* AWB on */ +- else +- sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */ ++ if (sd->awb) { ++ sccb_reg_write(gspca_dev, 0x13, ++ sccb_reg_read(gspca_dev, 0x13) | 0x02); ++ sccb_reg_write(gspca_dev, 0x63, ++ sccb_reg_read(gspca_dev, 0x63) | 0xc0); ++ } else { ++ sccb_reg_write(gspca_dev, 0x13, ++ sccb_reg_read(gspca_dev, 0x13) & ~0x02); ++ sccb_reg_write(gspca_dev, 0x63, ++ sccb_reg_read(gspca_dev, 0x63) & ~0xc0); ++ } + } + + static void setaec(struct gspca_dev *gspca_dev) +@@ -805,9 +812,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + #else + gspca_dev->ctrl_inac |= (1 << AWB_IDX); + #endif +-#if AWB_DEF != 0 +- sd->awb = AWB_DEF +-#endif ++ sd->awb = AWB_DEF; + sd->aec = AEC_DEF; + #if SHARPNESS_DEF != 0 + sd->sharpness = SHARPNESS_DEF; +From: Max Thrun +Date: Sat, 27 Feb 2010 20:20:24 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Fixes for sharpness control +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=2bd647c5a4f8236b035f9db620930731ac77c957 + +V4L/DVB: gspca - ov534: Fixes for sharpness control + +* Adjust comments for sharpness control + * Set default value unconditionally, for readability + +Signed-off-by: Max Thrun +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 3b538d7..f2077ea 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -756,8 +756,8 @@ static void setsharpness(struct gspca_dev *gspca_dev) + u8 val; + + val = sd->sharpness; +- sccb_reg_write(gspca_dev, 0x91, val); /* vga noise */ +- sccb_reg_write(gspca_dev, 0x8e, val); /* qvga noise */ ++ sccb_reg_write(gspca_dev, 0x91, val); /* Auto de-noise threshold */ ++ sccb_reg_write(gspca_dev, 0x8e, val); /* De-noise threshold */ + } + + static void sethflip(struct gspca_dev *gspca_dev) +@@ -814,9 +814,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + #endif + sd->awb = AWB_DEF; + sd->aec = AEC_DEF; +-#if SHARPNESS_DEF != 0 + sd->sharpness = SHARPNESS_DEF; +-#endif + #if HFLIP_DEF != 0 + sd->hflip = HFLIP_DEF; + #endif +From: Max Thrun +Date: Sat, 27 Feb 2010 20:20:25 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Fix unsetting hflip and vflip bits +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=9398cf3859a02fcc3a310393857d5cfca61647f3 + +V4L/DVB: gspca - ov534: Fix unsetting hflip and vflip bits + +Also set default values unconditionally, for readability. + +Signed-off-by: Max Thrun +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index f2077ea..8f01201 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -769,7 +769,7 @@ static void sethflip(struct gspca_dev *gspca_dev) + sccb_reg_read(gspca_dev, 0x0c) | 0x40); + else + sccb_reg_write(gspca_dev, 0x0c, +- sccb_reg_read(gspca_dev, 0x0c) & 0xbf); ++ sccb_reg_read(gspca_dev, 0x0c) & ~0x40); + } + + static void setvflip(struct gspca_dev *gspca_dev) +@@ -781,7 +781,7 @@ static void setvflip(struct gspca_dev *gspca_dev) + sccb_reg_read(gspca_dev, 0x0c) | 0x80); + else + sccb_reg_write(gspca_dev, 0x0c, +- sccb_reg_read(gspca_dev, 0x0c) & 0x7f); ++ sccb_reg_read(gspca_dev, 0x0c) & ~0x80); + } + + /* this function is called at probe time */ +@@ -815,12 +815,8 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->awb = AWB_DEF; + sd->aec = AEC_DEF; + sd->sharpness = SHARPNESS_DEF; +-#if HFLIP_DEF != 0 + sd->hflip = HFLIP_DEF; +-#endif +-#if VFLIP_DEF != 0 + sd->vflip = VFLIP_DEF; +-#endif + + return 0; + } +From: Antonio Ospite +Date: Mon, 1 Mar 2010 11:54:33 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Cosmetics: fix indentation and hex digits +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=521acb59f1fa8d6a2bd37f8262da2b789014ac71 + +V4L/DVB: gspca - ov534: Cosmetics: fix indentation and hex digits + +* Indent with tabs, not with spaces, nor with mixed style. + * Less indentation for controls index comments. + * Use lowercase hex digits. + +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 8f01201..8783844 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -92,147 +92,147 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); + + static const struct ctrl sd_ctrls[] = { +- { /* 0 */ +- { +- .id = V4L2_CID_BRIGHTNESS, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Brightness", +- .minimum = 0, +- .maximum = 255, +- .step = 1, ++ { /* 0 */ ++ { ++ .id = V4L2_CID_BRIGHTNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Brightness", ++ .minimum = 0, ++ .maximum = 255, ++ .step = 1, + #define BRIGHTNESS_DEF 0 +- .default_value = BRIGHTNESS_DEF, ++ .default_value = BRIGHTNESS_DEF, ++ }, ++ .set = sd_setbrightness, ++ .get = sd_getbrightness, + }, +- .set = sd_setbrightness, +- .get = sd_getbrightness, +- }, +- { /* 1 */ +- { +- .id = V4L2_CID_CONTRAST, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Contrast", +- .minimum = 0, +- .maximum = 255, +- .step = 1, ++ { /* 1 */ ++ { ++ .id = V4L2_CID_CONTRAST, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Contrast", ++ .minimum = 0, ++ .maximum = 255, ++ .step = 1, + #define CONTRAST_DEF 32 +- .default_value = CONTRAST_DEF, ++ .default_value = CONTRAST_DEF, ++ }, ++ .set = sd_setcontrast, ++ .get = sd_getcontrast, + }, +- .set = sd_setcontrast, +- .get = sd_getcontrast, +- }, +- { /* 2 */ +- { +- .id = V4L2_CID_GAIN, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Main Gain", +- .minimum = 0, +- .maximum = 63, +- .step = 1, ++ { /* 2 */ ++ { ++ .id = V4L2_CID_GAIN, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Main Gain", ++ .minimum = 0, ++ .maximum = 63, ++ .step = 1, + #define GAIN_DEF 20 +- .default_value = GAIN_DEF, ++ .default_value = GAIN_DEF, ++ }, ++ .set = sd_setgain, ++ .get = sd_getgain, + }, +- .set = sd_setgain, +- .get = sd_getgain, +- }, +- { /* 3 */ +- { +- .id = V4L2_CID_EXPOSURE, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Exposure", +- .minimum = 0, +- .maximum = 255, +- .step = 1, ++ { /* 3 */ ++ { ++ .id = V4L2_CID_EXPOSURE, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Exposure", ++ .minimum = 0, ++ .maximum = 255, ++ .step = 1, + #define EXPO_DEF 120 +- .default_value = EXPO_DEF, ++ .default_value = EXPO_DEF, ++ }, ++ .set = sd_setexposure, ++ .get = sd_getexposure, + }, +- .set = sd_setexposure, +- .get = sd_getexposure, +- }, +- { /* 4 */ +- { +- .id = V4L2_CID_AUTOGAIN, +- .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "Auto Gain", +- .minimum = 0, +- .maximum = 1, +- .step = 1, ++ { /* 4 */ ++ { ++ .id = V4L2_CID_AUTOGAIN, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "Auto Gain", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, + #define AGC_DEF 1 +- .default_value = AGC_DEF, ++ .default_value = AGC_DEF, ++ }, ++ .set = sd_setagc, ++ .get = sd_getagc, + }, +- .set = sd_setagc, +- .get = sd_getagc, +- }, + #define AWB_IDX 5 +- { /* 5 */ +- { +- .id = V4L2_CID_AUTO_WHITE_BALANCE, +- .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "Auto White Balance", +- .minimum = 0, +- .maximum = 1, +- .step = 1, ++ { /* 5 */ ++ { ++ .id = V4L2_CID_AUTO_WHITE_BALANCE, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "Auto White Balance", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, + #define AWB_DEF 1 +- .default_value = AWB_DEF, ++ .default_value = AWB_DEF, ++ }, ++ .set = sd_setawb, ++ .get = sd_getawb, + }, +- .set = sd_setawb, +- .get = sd_getawb, +- }, +- { /* 6 */ +- { +- .id = V4L2_CID_EXPOSURE_AUTO, +- .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "Auto Exposure", +- .minimum = 0, +- .maximum = 1, +- .step = 1, ++ { /* 6 */ ++ { ++ .id = V4L2_CID_EXPOSURE_AUTO, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "Auto Exposure", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, + #define AEC_DEF 1 +- .default_value = AEC_DEF, ++ .default_value = AEC_DEF, ++ }, ++ .set = sd_setaec, ++ .get = sd_getaec, + }, +- .set = sd_setaec, +- .get = sd_getaec, +- }, +- { /* 7 */ +- { +- .id = V4L2_CID_SHARPNESS, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Sharpness", +- .minimum = 0, +- .maximum = 63, +- .step = 1, ++ { /* 7 */ ++ { ++ .id = V4L2_CID_SHARPNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Sharpness", ++ .minimum = 0, ++ .maximum = 63, ++ .step = 1, + #define SHARPNESS_DEF 0 +- .default_value = SHARPNESS_DEF, ++ .default_value = SHARPNESS_DEF, ++ }, ++ .set = sd_setsharpness, ++ .get = sd_getsharpness, + }, +- .set = sd_setsharpness, +- .get = sd_getsharpness, +- }, +- { /* 8 */ +- { +- .id = V4L2_CID_HFLIP, +- .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "HFlip", +- .minimum = 0, +- .maximum = 1, +- .step = 1, ++ { /* 8 */ ++ { ++ .id = V4L2_CID_HFLIP, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "HFlip", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, + #define HFLIP_DEF 0 +- .default_value = HFLIP_DEF, ++ .default_value = HFLIP_DEF, ++ }, ++ .set = sd_sethflip, ++ .get = sd_gethflip, + }, +- .set = sd_sethflip, +- .get = sd_gethflip, +- }, +- { /* 9 */ +- { +- .id = V4L2_CID_VFLIP, +- .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "VFlip", +- .minimum = 0, +- .maximum = 1, +- .step = 1, ++ { /* 9 */ ++ { ++ .id = V4L2_CID_VFLIP, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "VFlip", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, + #define VFLIP_DEF 0 +- .default_value = VFLIP_DEF, ++ .default_value = VFLIP_DEF, ++ }, ++ .set = sd_setvflip, ++ .get = sd_getvflip, + }, +- .set = sd_setvflip, +- .get = sd_getvflip, +- }, + }; + + static const struct v4l2_pix_format ov772x_mode[] = { +@@ -641,14 +641,14 @@ static void setbrightness(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + +- sccb_reg_write(gspca_dev, 0x9B, sd->brightness); ++ sccb_reg_write(gspca_dev, 0x9b, sd->brightness); + } + + static void setcontrast(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + +- sccb_reg_write(gspca_dev, 0x9C, sd->contrast); ++ sccb_reg_write(gspca_dev, 0x9c, sd->contrast); + } + + static void setgain(struct gspca_dev *gspca_dev) +From: Mosalam Ebrahimi +Date: Mon, 8 Mar 2010 16:52:17 +0000 (-0300) +Subject: V4L/DVB: gspca - ov534: Add Powerline Frequency control +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=9bc3ac54da6a52969088caca9f6acdf682fa8ace + +V4L/DVB: gspca - ov534: Add Powerline Frequency control + +Note that setting this options to 50Hz can reduce the framerate, so it is +still disabled (60Hz) by default. + +Signed-off-by: Mosalam Ebrahimi +Signed-off-by: Antonio Ospite +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 8783844..29af17e 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -66,7 +66,7 @@ struct sd { + s8 sharpness; + u8 hflip; + u8 vflip; +- ++ u8 freqfltr; + }; + + /* V4L2 controls supported by the driver */ +@@ -90,6 +90,10 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_querymenu(struct gspca_dev *gspca_dev, ++ struct v4l2_querymenu *menu); + + static const struct ctrl sd_ctrls[] = { + { /* 0 */ +@@ -233,6 +237,20 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setvflip, + .get = sd_getvflip, + }, ++ { /* 10 */ ++ { ++ .id = V4L2_CID_POWER_LINE_FREQUENCY, ++ .type = V4L2_CTRL_TYPE_MENU, ++ .name = "Light Frequency Filter", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, ++#define FREQFLTR_DEF 0 ++ .default_value = FREQFLTR_DEF, ++ }, ++ .set = sd_setfreqfltr, ++ .get = sd_getfreqfltr, ++ }, + }; + + static const struct v4l2_pix_format ov772x_mode[] = { +@@ -784,6 +802,17 @@ static void setvflip(struct gspca_dev *gspca_dev) + sccb_reg_read(gspca_dev, 0x0c) & ~0x80); + } + ++static void setfreqfltr(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (sd->freqfltr == 0) ++ sccb_reg_write(gspca_dev, 0x2b, 0x00); ++ else ++ sccb_reg_write(gspca_dev, 0x2b, 0x9e); ++} ++ ++ + /* this function is called at probe time */ + static int sd_config(struct gspca_dev *gspca_dev, + const struct usb_device_id *id) +@@ -817,6 +846,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->sharpness = SHARPNESS_DEF; + sd->hflip = HFLIP_DEF; + sd->vflip = VFLIP_DEF; ++ sd->freqfltr = FREQFLTR_DEF; + + return 0; + } +@@ -886,6 +916,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + setsharpness(gspca_dev); + setvflip(gspca_dev); + sethflip(gspca_dev); ++ setfreqfltr(gspca_dev); + + ov534_set_led(gspca_dev, 1); + ov534_reg_write(gspca_dev, 0xe0, 0x00); +@@ -1179,6 +1210,43 @@ static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + ++static int sd_setfreqfltr(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->freqfltr = val; ++ if (gspca_dev->streaming) ++ setfreqfltr(gspca_dev); ++ return 0; ++} ++ ++static int sd_getfreqfltr(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->freqfltr; ++ return 0; ++} ++ ++static int sd_querymenu(struct gspca_dev *gspca_dev, ++ struct v4l2_querymenu *menu) ++{ ++ switch (menu->id) { ++ case V4L2_CID_POWER_LINE_FREQUENCY: ++ switch (menu->index) { ++ case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ ++ strcpy((char *) menu->name, "Disabled"); ++ return 0; ++ case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ ++ strcpy((char *) menu->name, "50 Hz"); ++ return 0; ++ } ++ break; ++ } ++ ++ return -EINVAL; ++} ++ + /* get stream parameters (framerate) */ + static int sd_get_streamparm(struct gspca_dev *gspca_dev, + struct v4l2_streamparm *parm) +@@ -1230,6 +1298,7 @@ static const struct sd_desc sd_desc = { + .start = sd_start, + .stopN = sd_stopN, + .pkt_scan = sd_pkt_scan, ++ .querymenu = sd_querymenu, + .get_streamparm = sd_get_streamparm, + .set_streamparm = sd_set_streamparm, + }; +gspca_spca561: Fix LED on rev12a cameras + +From: Hans de Goede + +Fix LED control on rev12a cameras and remove the unneeded +sd_stop0 callback function. + +Priority: normal + +Signed-off-by: Hans de Goede + +--- a/drivers/media/video/gspca/spca561.c Sat Feb 20 15:26:07 2010 +0100 ++++ b/drivers/media/video/gspca/spca561.c Sat Feb 27 11:18:14 2010 +0100 +@@ -280,9 +280,9 @@ + }; + + static const __u16 spca561_161rev12A_data1[][2] = { +- {0x29, 0x8118}, /* white balance - was 21 */ +- {0x08, 0x8114}, /* white balance - was 01 */ +- {0x0e, 0x8112}, /* white balance - was 00 */ ++ {0x29, 0x8118}, /* Control register (various enable bits) */ ++ {0x08, 0x8114}, /* GPIO: Led off */ ++ {0x0e, 0x8112}, /* 0x0e stream off 0x3e stream on */ + {0x00, 0x8102}, /* white balance - new */ + {0x92, 0x8804}, + {0x04, 0x8802}, /* windows uses 08 */ +@@ -294,15 +294,11 @@ + {0x07, 0x8601}, + {0x07, 0x8602}, + {0x04, 0x8501}, +- {0x21, 0x8118}, + + {0x07, 0x8201}, /* windows uses 02 */ + {0x08, 0x8200}, + {0x01, 0x8200}, + +- {0x00, 0x8114}, +- {0x01, 0x8114}, /* windows uses 00 */ +- + {0x90, 0x8604}, + {0x00, 0x8605}, + {0xb0, 0x8603}, +@@ -333,6 +329,9 @@ + {0xf0, 0x8505}, + {0x32, 0x850a}, + /* {0x99, 0x8700}, * - white balance - new (removed) */ ++ /* HDG we used to do this in stop0, making the init state and the state ++ after a start / stop different, so do this here instead. */ ++ {0x29, 0x8118}, + {} + }; + +@@ -676,6 +675,9 @@ + setwhite(gspca_dev); + setgain(gspca_dev); + setexposure(gspca_dev); ++ ++ /* Led ON (bit 3 -> 0 */ ++ reg_w_val(gspca_dev->dev, 0x8114, 0x00); + return 0; + } + static int sd_start_72a(struct gspca_dev *gspca_dev) +@@ -722,26 +724,14 @@ + + if (sd->chip_revision == Rev012A) { + reg_w_val(gspca_dev->dev, 0x8112, 0x0e); ++ /* Led Off (bit 3 -> 1 */ ++ reg_w_val(gspca_dev->dev, 0x8114, 0x08); + } else { + reg_w_val(gspca_dev->dev, 0x8112, 0x20); + /* reg_w_val(gspca_dev->dev, 0x8102, 0x00); ?? */ + } + } + +-/* called on streamoff with alt 0 and on disconnect */ +-static void sd_stop0(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- if (!gspca_dev->present) +- return; +- if (sd->chip_revision == Rev012A) { +- reg_w_val(gspca_dev->dev, 0x8118, 0x29); +- reg_w_val(gspca_dev->dev, 0x8114, 0x08); +- } +-/* reg_w_val(gspca_dev->dev, 0x8114, 0); */ +-} +- + static void do_autogain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -1059,7 +1049,6 @@ + .init = sd_init_12a, + .start = sd_start_12a, + .stopN = sd_stopN, +- .stop0 = sd_stop0, + .pkt_scan = sd_pkt_scan, + }; + static const struct sd_desc sd_desc_72a = { +@@ -1070,7 +1059,6 @@ + .init = sd_init_72a, + .start = sd_start_72a, + .stopN = sd_stopN, +- .stop0 = sd_stop0, + .pkt_scan = sd_pkt_scan, + .dq_callback = do_autogain, + }; + +gspca_spca561: Add support for camera button + +From: Hans de Goede + +gspca_spca561: Add support for camera button + +Priority: normal + +Signed-off-by: Hans de Goede + +--- a/drivers/media/video/gspca/spca561.c Sat Feb 27 11:18:14 2010 +0100 ++++ b/drivers/media/video/gspca/spca561.c Sun Feb 28 13:41:04 2010 +0100 +@@ -22,6 +22,7 @@ + + #define MODULE_NAME "spca561" + ++#include + #include "gspca.h" + + MODULE_AUTHOR("Michel Xhaard "); +@@ -809,6 +810,23 @@ + switch (*data++) { /* sequence number */ + case 0: /* start of frame */ + gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); ++ ++ /* This should never happen */ ++ if (len < 2) { ++ PDEBUG(D_ERR, "Short SOF packet, ignoring"); ++ gspca_dev->last_packet_type = DISCARD_PACKET; ++ return; ++ } ++ ++#ifdef CONFIG_INPUT ++ if (data[0] & 0x20) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ } ++#endif ++ + if (data[1] & 0x10) { + /* compressed bayer */ + gspca_frame_add(gspca_dev, FIRST_PACKET, data, len); +@@ -1050,6 +1068,9 @@ + .start = sd_start_12a, + .stopN = sd_stopN, + .pkt_scan = sd_pkt_scan, ++#ifdef CONFIG_INPUT ++ .other_input = 1, ++#endif + }; + static const struct sd_desc sd_desc_72a = { + .name = MODULE_NAME, +@@ -1061,6 +1082,9 @@ + .stopN = sd_stopN, + .pkt_scan = sd_pkt_scan, + .dq_callback = do_autogain, ++#ifdef CONFIG_INPUT ++ .other_input = 1, ++#endif + }; + static const struct sd_desc *sd_desc[2] = { + &sd_desc_12a, + +gspca: make usb id 0461:0815 get handled by the right driver + +From: John Ellson + +The 0461:0815 camera is spca561 based not spca508 + +Priority: high + +Signed-off-by: John Ellson +Signed-off-by: Hans de Goede + +diff -r 6687077521f7 -r 649d692c7bc1 linux/drivers/media/video/gspca/spca508.c +--- a/drivers/media/video/gspca/spca508.c Thu Mar 11 10:12:39 2010 +0100 ++++ b/drivers/media/video/gspca/spca508.c Wed Mar 17 14:22:58 2010 +0100 +@@ -1559,7 +1559,6 @@ + static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x0130, 0x0130), .driver_info = HamaUSBSightcam}, + {USB_DEVICE(0x041e, 0x4018), .driver_info = CreativeVista}, +- {USB_DEVICE(0x0461, 0x0815), .driver_info = MicroInnovationIC200}, + {USB_DEVICE(0x0733, 0x0110), .driver_info = ViewQuestVQ110}, + {USB_DEVICE(0x0af9, 0x0010), .driver_info = HamaUSBSightcam}, + {USB_DEVICE(0x0af9, 0x0011), .driver_info = HamaUSBSightcam2}, +diff -r 6687077521f7 -r 649d692c7bc1 linux/drivers/media/video/gspca/spca561.c +--- a/drivers/media/video/gspca/spca561.c Thu Mar 11 10:12:39 2010 +0100 ++++ b/drivers/media/video/gspca/spca561.c Wed Mar 17 14:22:58 2010 +0100 +@@ -1096,6 +1096,7 @@ + {USB_DEVICE(0x041e, 0x401a), .driver_info = Rev072A}, + {USB_DEVICE(0x041e, 0x403b), .driver_info = Rev012A}, + {USB_DEVICE(0x0458, 0x7004), .driver_info = Rev072A}, ++ {USB_DEVICE(0x0461, 0x0815), .driver_info = Rev072A}, + {USB_DEVICE(0x046d, 0x0928), .driver_info = Rev012A}, + {USB_DEVICE(0x046d, 0x0929), .driver_info = Rev012A}, + {USB_DEVICE(0x046d, 0x092a), .driver_info = Rev012A}, +From: Jean-François Moine +Date: Thu, 18 Feb 2010 07:12:06 +0000 (-0300) +Subject: V4L/DVB: gspca - sonixj: Add vertical flip control for sensor hv7131r +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=f344792e0c1dd7e0029b7dd92612ff002646634e + +V4L/DVB: gspca - sonixj: Add vertical flip control for sensor hv7131r + +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c +index 4ece110..fea8075 100644 +--- a/drivers/media/video/gspca/sonixj.c ++++ b/drivers/media/video/gspca/sonixj.c +@@ -282,7 +282,7 @@ static const struct ctrl sd_ctrls[] = { + static __u32 ctrl_dis[] = { + (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX) | + (1 << AUTOGAIN_IDX), /* SENSOR_ADCM1700 0 */ +- (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), ++ (1 << INFRARED_IDX) | (1 << FREQ_IDX), + /* SENSOR_HV7131R 1 */ + (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), + /* SENSOR_MI0360 2 */ +@@ -1780,23 +1780,34 @@ static void setautogain(struct gspca_dev *gspca_dev) + sd->ag_cnt = -1; + } + +-/* ov7630/ov7648 only */ ++/* hv7131r/ov7630/ov7648 only */ + static void setvflip(struct sd *sd) + { + u8 comn; + + if (sd->gspca_dev.ctrl_dis & (1 << VFLIP_IDX)) + return; +- if (sd->sensor == SENSOR_OV7630) { ++ switch (sd->sensor) { ++ case SENSOR_HV7131R: ++ comn = 0x18; /* clkdiv = 1, ablcen = 1 */ ++ if (sd->vflip) ++ comn |= 0x01; ++ i2c_w1(&sd->gspca_dev, 0x01, comn); /* sctra */ ++ break; ++ case SENSOR_OV7630: + comn = 0x02; + if (!sd->vflip) + comn |= 0x80; +- } else { ++ i2c_w1(&sd->gspca_dev, 0x75, comn); ++ break; ++ default: ++/* case SENSOR_OV7648: */ + comn = 0x06; + if (sd->vflip) + comn |= 0x80; ++ i2c_w1(&sd->gspca_dev, 0x75, comn); ++ break; + } +- i2c_w1(&sd->gspca_dev, 0x75, comn); + } + + static void setsharpness(struct sd *sd) +From: Jean-François Moine +Date: Thu, 18 Feb 2010 17:56:33 +0000 (-0300) +Subject: V4L/DVB: gspca - sonixj: Set the vertical flip at capture start for all sensors +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=648399060d0e1dea17e6450e1cfa7629c5aa704b + +V4L/DVB: gspca - sonixj: Set the vertical flip at capture start for all sensors + +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c +index fea8075..2ccddcd 100644 +--- a/drivers/media/video/gspca/sonixj.c ++++ b/drivers/media/video/gspca/sonixj.c +@@ -2082,7 +2082,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg17 = 0x64; /* 640 MCKSIZE */ + break; + case SENSOR_OV7630: +- setvflip(sd); + reg17 = 0xe2; + reg1 = 0x44; + break; +@@ -2154,11 +2153,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg_w1(gspca_dev, 0x17, reg17); + reg_w1(gspca_dev, 0x01, reg1); + +- switch (sd->sensor) { +- case SENSOR_OV7630: +- setvflip(sd); +- break; +- } ++ setvflip(sd); + setbrightness(gspca_dev); + setcontrast(gspca_dev); + setautogain(gspca_dev); +From: Jean-François Moine +Date: Wed, 17 Mar 2010 18:25:32 +0000 (-0300) +Subject: V4L/DVB: gspca - sonixj: More static const and better array initialization +X-Git-Url: http://git.linuxtv.org/v4l-dvb.git?a=commitdiff_plain;h=5bcd8657cca97ad5a9c159659f6ba857e35960b8 + +V4L/DVB: gspca - sonixj: More static const and better array initialization + +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c +index 83d5773..eb43f22 100644 +--- a/drivers/media/video/gspca/sonixj.c ++++ b/drivers/media/video/gspca/sonixj.c +@@ -66,17 +66,19 @@ struct sd { + #define BRIDGE_SN9C110 2 + #define BRIDGE_SN9C120 3 + u8 sensor; /* Type of image sensor chip */ +-#define SENSOR_ADCM1700 0 +-#define SENSOR_HV7131R 1 +-#define SENSOR_MI0360 2 +-#define SENSOR_MO4000 3 +-#define SENSOR_MT9V111 4 +-#define SENSOR_OM6802 5 +-#define SENSOR_OV7630 6 +-#define SENSOR_OV7648 7 +-#define SENSOR_OV7660 8 +-#define SENSOR_PO1030 9 +-#define SENSOR_SP80708 10 ++enum { ++ SENSOR_ADCM1700, ++ SENSOR_HV7131R, ++ SENSOR_MI0360, ++ SENSOR_MO4000, ++ SENSOR_MT9V111, ++ SENSOR_OM6802, ++ SENSOR_OV7630, ++ SENSOR_OV7648, ++ SENSOR_OV7660, ++ SENSOR_PO1030, ++ SENSOR_SP80708, ++} sensors; + u8 i2c_addr; + + u8 *jpeg_hdr; +@@ -280,29 +282,47 @@ static const struct ctrl sd_ctrls[] = { + }; + + /* table of the disabled controls */ +-static __u32 ctrl_dis[] = { +- (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX) | +- (1 << AUTOGAIN_IDX), /* SENSOR_ADCM1700 0 */ +- (1 << INFRARED_IDX) | (1 << FREQ_IDX), +- /* SENSOR_HV7131R 1 */ +- (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_MI0360 2 */ +- (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_MO4000 3 */ +- (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_MT9V111 4 */ +- (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_OM6802 5 */ +- (1 << INFRARED_IDX), +- /* SENSOR_OV7630 6 */ +- (1 << INFRARED_IDX), +- /* SENSOR_OV7648 7 */ +- (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX), +- /* SENSOR_OV7660 8 */ +- (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | +- (1 << FREQ_IDX), /* SENSOR_PO1030 9 */ +- (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | +- (1 << FREQ_IDX), /* SENSOR_SP80708 10 */ ++static const __u32 ctrl_dis[] = { ++[SENSOR_ADCM1700] = (1 << AUTOGAIN_IDX) | ++ (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_HV7131R] = (1 << INFRARED_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_MI0360] = (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_MO4000] = (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_MT9V111] = (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_OM6802] = (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_OV7630] = (1 << INFRARED_IDX), ++ ++[SENSOR_OV7648] = (1 << INFRARED_IDX), ++ ++[SENSOR_OV7660] = (1 << AUTOGAIN_IDX) | ++ (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX), ++ ++[SENSOR_PO1030] = (1 << AUTOGAIN_IDX) | ++ (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ ++[SENSOR_SP80708] = (1 << AUTOGAIN_IDX) | ++ (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), + }; + + static const struct v4l2_pix_format cif_mode[] = { +@@ -455,17 +475,17 @@ static const u8 sn_sp80708[0x1c] = { + + /* sequence specific to the sensors - !! index = SENSOR_xxx */ + static const u8 *sn_tb[] = { +- sn_adcm1700, +- sn_hv7131, +- sn_mi0360, +- sn_mo4000, +- sn_mt9v111, +- sn_om6802, +- sn_ov7630, +- sn_ov7648, +- sn_ov7660, +- sn_po1030, +- sn_sp80708 ++[SENSOR_ADCM1700] = sn_adcm1700, ++[SENSOR_HV7131R] = sn_hv7131, ++[SENSOR_MI0360] = sn_mi0360, ++[SENSOR_MO4000] = sn_mo4000, ++[SENSOR_MT9V111] = sn_mt9v111, ++[SENSOR_OM6802] = sn_om6802, ++[SENSOR_OV7630] = sn_ov7630, ++[SENSOR_OV7648] = sn_ov7648, ++[SENSOR_OV7660] = sn_ov7660, ++[SENSOR_PO1030] = sn_po1030, ++[SENSOR_SP80708] = sn_sp80708 + }; + + /* default gamma table */ +@@ -1068,18 +1088,18 @@ static const u8 sp80708_sensor_param1[][8] = { + {} + }; + +-static const u8 (*sensor_init[11])[8] = { +- adcm1700_sensor_init, /* ADCM1700 0 */ +- hv7131r_sensor_init, /* HV7131R 1 */ +- mi0360_sensor_init, /* MI0360 2 */ +- mo4000_sensor_init, /* MO4000 3 */ +- mt9v111_sensor_init, /* MT9V111 4 */ +- om6802_sensor_init, /* OM6802 5 */ +- ov7630_sensor_init, /* OV7630 6 */ +- ov7648_sensor_init, /* OV7648 7 */ +- ov7660_sensor_init, /* OV7660 8 */ +- po1030_sensor_init, /* PO1030 9 */ +- sp80708_sensor_init, /* SP80708 10 */ ++static const u8 (*sensor_init[])[8] = { ++[SENSOR_ADCM1700] = adcm1700_sensor_init, ++[SENSOR_HV7131R] = hv7131r_sensor_init, ++[SENSOR_MI0360] = mi0360_sensor_init, ++[SENSOR_MO4000] = mo4000_sensor_init, ++[SENSOR_MT9V111] = mt9v111_sensor_init, ++[SENSOR_OM6802] = om6802_sensor_init, ++[SENSOR_OV7630] = ov7630_sensor_init, ++[SENSOR_OV7648] = ov7648_sensor_init, ++[SENSOR_OV7660] = ov7660_sensor_init, ++[SENSOR_PO1030] = po1030_sensor_init, ++[SENSOR_SP80708] = sp80708_sensor_init, + }; + + /* read bytes to gspca_dev->usb_buf */ +@@ -1702,7 +1722,7 @@ static void setcolors(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + int i, v; + u8 reg8a[12]; /* U & V gains */ +- static s16 uv[6] = { /* same as reg84 in signed decimal */ ++ static const s16 uv[6] = { /* same as reg84 in signed decimal */ + -24, -38, 64, /* UR UG UB */ + 62, -51, -9 /* VR VG VB */ + }; +From: Jean-François Moine +Date: Thu, 18 Mar 2010 08:15:30 +0000 (-0300) +Subject: V4L/DVB: gspca - sonixj: Add webcam 0c45:6142 with sensors gc0307 and po2030n +X-Git-Url: http://git.linuxtv.org/v4l-dvb.git?a=commitdiff_plain;h=7ece2ad1a65a3c92c2573ee5c79d45159cbd6183 + +V4L/DVB: gspca - sonixj: Add webcam 0c45:6142 with sensors gc0307 and po2030n + +Signed-off-by: Jean-François Moine +Signed-off-by: Mauro Carvalho Chehab +--- + +diff --git a/Documentation/video4linux/gspca.txt b/Documentation/video4linux/gspca.txt +index 181b9e6..9475e1e 100644 +--- a/Documentation/video4linux/gspca.txt ++++ b/Documentation/video4linux/gspca.txt +@@ -305,6 +305,7 @@ sonixj 0c45:6138 Sn9c120 Mo4000 + sonixj 0c45:613a Microdia Sonix PC Camera + sonixj 0c45:613b Surfer SN-206 + sonixj 0c45:613c Sonix Pccam168 ++sonixj 0c45:6142 Hama PC-Webcam AC-150 + sonixj 0c45:6143 Sonix Pccam168 + sonixj 0c45:6148 Digitus DA-70811/ZSMC USB PC Camera ZS211/Microdia + sonixj 0c45:614a Frontech E-Ccam (JIL-2225) +diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c +index eb43f22..5e727aa 100644 +--- a/drivers/media/video/gspca/sonixj.c ++++ b/drivers/media/video/gspca/sonixj.c +@@ -68,6 +68,7 @@ struct sd { + u8 sensor; /* Type of image sensor chip */ + enum { + SENSOR_ADCM1700, ++ SENSOR_GC0307, + SENSOR_HV7131R, + SENSOR_MI0360, + SENSOR_MO4000, +@@ -77,6 +78,7 @@ enum { + SENSOR_OV7648, + SENSOR_OV7660, + SENSOR_PO1030, ++ SENSOR_PO2030N, + SENSOR_SP80708, + } sensors; + u8 i2c_addr; +@@ -288,6 +290,11 @@ static const __u32 ctrl_dis[] = { + (1 << VFLIP_IDX) | + (1 << FREQ_IDX), + ++[SENSOR_GC0307] = (1 << AUTOGAIN_IDX) | ++ (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ + [SENSOR_HV7131R] = (1 << INFRARED_IDX) | + (1 << FREQ_IDX), + +@@ -319,6 +326,11 @@ static const __u32 ctrl_dis[] = { + (1 << VFLIP_IDX) | + (1 << FREQ_IDX), + ++[SENSOR_PO2030N] = (1 << AUTOGAIN_IDX) | ++ (1 << INFRARED_IDX) | ++ (1 << VFLIP_IDX) | ++ (1 << FREQ_IDX), ++ + [SENSOR_SP80708] = (1 << AUTOGAIN_IDX) | + (1 << INFRARED_IDX) | + (1 << VFLIP_IDX) | +@@ -362,7 +374,17 @@ static const u8 sn_adcm1700[0x1c] = { + 0x06, 0x00, 0x00, 0x00 + }; + +-/*Data from sn9c102p+hv7131r */ ++static const u8 sn_gc0307[0x1c] = { ++/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ ++ 0x00, 0x61, 0x62, 0x00, 0x1a, 0x00, 0x00, 0x00, ++/* reg8 reg9 rega regb regc regd rege regf */ ++ 0x80, 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ ++ 0x03, 0x00, 0x03, 0x01, 0x08, 0x28, 0x1e, 0x02, ++/* reg18 reg19 reg1a reg1b */ ++ 0x06, 0x00, 0x00, 0x00 ++}; ++ + static const u8 sn_hv7131[0x1c] = { + /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ + 0x00, 0x03, 0x64, 0x00, 0x1a, 0x20, 0x20, 0x20, +@@ -462,6 +484,17 @@ static const u8 sn_po1030[0x1c] = { + 0x07, 0x00, 0x00, 0x00 + }; + ++static const u8 sn_po2030n[0x1c] = { ++/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ ++ 0x00, 0x63, 0x40, 0x00, 0x1a, 0x00, 0x00, 0x00, ++/* reg8 reg9 rega regb regc regd rege regf */ ++ 0x81, 0x6e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ ++ 0x03, 0x00, 0x00, 0x01, 0x14, 0x28, 0x1e, 0x00, ++/* reg18 reg19 reg1a reg1b */ ++ 0x07, 0x00, 0x00, 0x00 ++}; ++ + static const u8 sn_sp80708[0x1c] = { + /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ + 0x00, 0x63, 0x60, 0x00, 0x1a, 0x20, 0x20, 0x20, +@@ -476,6 +509,7 @@ static const u8 sn_sp80708[0x1c] = { + /* sequence specific to the sensors - !! index = SENSOR_xxx */ + static const u8 *sn_tb[] = { + [SENSOR_ADCM1700] = sn_adcm1700, ++[SENSOR_GC0307] = sn_gc0307, + [SENSOR_HV7131R] = sn_hv7131, + [SENSOR_MI0360] = sn_mi0360, + [SENSOR_MO4000] = sn_mo4000, +@@ -485,6 +519,7 @@ static const u8 *sn_tb[] = { + [SENSOR_OV7648] = sn_ov7648, + [SENSOR_OV7660] = sn_ov7660, + [SENSOR_PO1030] = sn_po1030, ++[SENSOR_PO2030N] = sn_po2030n, + [SENSOR_SP80708] = sn_sp80708 + }; + +@@ -503,8 +538,13 @@ static const u8 gamma_spec_1[17] = { + 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d, + 0xa9, 0xb4, 0xbe, 0xc8, 0xd2, 0xdb, 0xe4, 0xed, 0xf5 + }; +-/* gamma for sensor SP80708 */ ++/* gamma for sensor GC0307 */ + static const u8 gamma_spec_2[17] = { ++ 0x14, 0x37, 0x50, 0x6a, 0x7c, 0x8d, 0x9d, 0xab, ++ 0xb5, 0xbf, 0xc2, 0xcb, 0xd1, 0xd6, 0xdb, 0xe1, 0xeb ++}; ++/* gamma for sensor SP80708 */ ++static const u8 gamma_spec_3[17] = { + 0x0a, 0x2d, 0x4e, 0x68, 0x7d, 0x8f, 0x9f, 0xab, + 0xb7, 0xc2, 0xcc, 0xd3, 0xd8, 0xde, 0xe2, 0xe5, 0xe6 + }; +@@ -552,6 +592,64 @@ static const u8 adcm1700_sensor_param1[][8] = { + {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10}, + {} + }; ++static const u8 gc0307_sensor_init[][8] = { ++ {0xa0, 0x21, 0x43, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x44, 0xa2, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x01, 0x6a, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x02, 0x70, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x10, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x1c, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x11, 0x05, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x05, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x06, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x07, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x08, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x09, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x0a, 0xe8, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x0b, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x0c, 0x80, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x0d, 0x22, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x0e, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x0f, 0xb2, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x12, 0x70, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /*delay 10ms*/ ++ {0xa0, 0x21, 0x13, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x15, 0xb8, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x16, 0x13, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x17, 0x52, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x18, 0x50, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x1e, 0x0d, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x1f, 0x32, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x61, 0x90, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x63, 0x70, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x65, 0x98, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x67, 0x90, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x03, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x04, 0x96, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x45, 0x27, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x47, 0x2c, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x43, 0x47, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x44, 0xd8, 0x00, 0x00, 0x00, 0x10}, ++ {} ++}; ++static const u8 gc0307_sensor_param1[][8] = { ++ {0xa0, 0x21, 0x68, 0x13, 0x00, 0x00, 0x00, 0x10}, ++ {0xd0, 0x21, 0x61, 0x80, 0x00, 0x80, 0x00, 0x10}, ++ {0xc0, 0x21, 0x65, 0x80, 0x00, 0x80, 0x00, 0x10}, ++ {0xc0, 0x21, 0x63, 0xa0, 0x00, 0xa6, 0x00, 0x10}, ++/*param3*/ ++ {0xa0, 0x21, 0x01, 0x6e, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x21, 0x02, 0x88, 0x00, 0x00, 0x00, 0x10}, ++ ++ {0xa0, 0x21, 0x68, 0x22, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, ++ {0xa0, 0x21, 0x03, 0x07, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, ++ {0xa0, 0x21, 0x04, 0x91, 0x00, 0x00, 0x00, 0x10}, ++ {} ++}; ++ + static const u8 hv7131r_sensor_init[][8] = { + {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10}, + {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10}, +@@ -1003,6 +1101,82 @@ static const u8 po1030_sensor_param1[][8] = { + {} + }; + ++static const u8 po2030n_sensor_init[][8] = { ++ {0xa1, 0x6e, 0x1e, 0x1a, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x1f, 0x99, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */ ++ {0xa1, 0x6e, 0x1e, 0x0a, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x1f, 0x19, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x0a, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 10ms */ ++ {0xa1, 0x6e, 0x20, 0x44, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x05, 0x70, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x08, 0x00, 0xd0, 0x00, 0x08, 0x10}, ++ {0xd1, 0x6e, 0x0c, 0x03, 0x50, 0x01, 0xe8, 0x10}, ++ {0xd1, 0x6e, 0x1d, 0x20, 0x0a, 0x19, 0x44, 0x10}, ++ {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x29, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x2d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x31, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x35, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x3d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x41, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x45, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x49, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x4d, 0x00, 0x00, 0x00, 0xed, 0x10}, ++ {0xd1, 0x6e, 0x51, 0x17, 0x4a, 0x2f, 0xc0, 0x10}, ++ {0xd1, 0x6e, 0x55, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x59, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x5d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x61, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x65, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x69, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x6d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x71, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x75, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x79, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x7d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x81, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x85, 0x00, 0x00, 0x00, 0x08, 0x10}, ++ {0xd1, 0x6e, 0x89, 0x01, 0xe8, 0x00, 0x01, 0x10}, ++ {0xa1, 0x6e, 0x8d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x21, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x25, 0x00, 0x00, 0x00, 0x01, 0x10}, ++ {0xd1, 0x6e, 0x29, 0xe6, 0x00, 0xbd, 0x03, 0x10}, ++ {0xd1, 0x6e, 0x2d, 0x41, 0x38, 0x68, 0x40, 0x10}, ++ {0xd1, 0x6e, 0x31, 0x2b, 0x00, 0x36, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x35, 0x30, 0x30, 0x08, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x39, 0x00, 0x00, 0x33, 0x06, 0x10}, ++ {0xb1, 0x6e, 0x3d, 0x06, 0x02, 0x00, 0x00, 0x10}, ++ {} ++}; ++static const u8 po2030n_sensor_param1[][8] = { ++ {0xa1, 0x6e, 0x1a, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 8ms */ ++ {0xa1, 0x6e, 0x1b, 0xf4, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, ++ {0xd1, 0x6e, 0x16, 0x50, 0x40, 0x49, 0x40, 0x10}, ++/*param2*/ ++ {0xa1, 0x6e, 0x1d, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x04, 0x03, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x05, 0x6f, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x06, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x07, 0x25, 0x00, 0x00, 0x00, 0x10}, ++ {0xa1, 0x6e, 0x15, 0x04, 0x00, 0x00, 0x00, 0x10}, ++ {0xc1, 0x6e, 0x16, 0x52, 0x40, 0x48, 0x00, 0x10}, ++/*after start*/ ++ {0xa1, 0x6e, 0x15, 0x0f, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */ ++ {0xa1, 0x6e, 0x1a, 0x05, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, /* delay 5ms */ ++ {0xa1, 0x6e, 0x1b, 0x53, 0x00, 0x00, 0x00, 0x10}, ++ {} ++}; ++ + static const u8 sp80708_sensor_init[][8] = { + {0xa1, 0x18, 0x06, 0xf9, 0x00, 0x00, 0x00, 0x10}, + {0xa1, 0x18, 0x09, 0x1f, 0x00, 0x00, 0x00, 0x10}, +@@ -1090,6 +1264,7 @@ static const u8 sp80708_sensor_param1[][8] = { + + static const u8 (*sensor_init[])[8] = { + [SENSOR_ADCM1700] = adcm1700_sensor_init, ++[SENSOR_GC0307] = gc0307_sensor_init, + [SENSOR_HV7131R] = hv7131r_sensor_init, + [SENSOR_MI0360] = mi0360_sensor_init, + [SENSOR_MO4000] = mo4000_sensor_init, +@@ -1099,6 +1274,7 @@ static const u8 (*sensor_init[])[8] = { + [SENSOR_OV7648] = ov7648_sensor_init, + [SENSOR_OV7660] = ov7660_sensor_init, + [SENSOR_PO1030] = po1030_sensor_init, ++[SENSOR_PO2030N] = po2030n_sensor_init, + [SENSOR_SP80708] = sp80708_sensor_init, + }; + +@@ -1168,7 +1344,8 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val) + PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val); + switch (sd->sensor) { + case SENSOR_ADCM1700: +- case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */ ++ case SENSOR_OM6802: ++ case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */ + gspca_dev->usb_buf[0] = 0x80 | (2 << 4); + break; + default: /* i2c command = a1 (400 kHz) */ +@@ -1215,7 +1392,8 @@ static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len) + + switch (sd->sensor) { + case SENSOR_ADCM1700: +- case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */ ++ case SENSOR_OM6802: ++ case SENSOR_GC0307: /* i2c command = a0 (100 kHz) */ + mode[0] = 0x80 | 0x10; + break; + default: /* i2c command = 91 (400 kHz) */ +@@ -1354,6 +1532,46 @@ static void ov7648_probe(struct gspca_dev *gspca_dev) + gspca_dev->usb_buf[3], gspca_dev->usb_buf[4]); + } + ++/* 0c45:6142 sensor may be po2030n, gc0305 or gc0307 */ ++static void po2030n_probe(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ /* check gc0307 */ ++ reg_w1(gspca_dev, 0x17, 0x62); ++ reg_w1(gspca_dev, 0x01, 0x08); ++ reg_w1(gspca_dev, 0x02, 0x22); ++ sd->i2c_addr = 0x21; ++ i2c_r(gspca_dev, 0x00, 1); ++ ++ reg_w1(gspca_dev, 0x01, 0x29); /* reset */ ++ reg_w1(gspca_dev, 0x17, 0x42); ++ ++ if (gspca_dev->usb_buf[4] == 0x99) { /* gc0307 (?) */ ++ PDEBUG(D_PROBE, "Sensor gc0307"); ++ sd->sensor = SENSOR_GC0307; ++ return; ++ } ++ ++ /* check po2030n */ ++ reg_w1(gspca_dev, 0x17, 0x62); ++ reg_w1(gspca_dev, 0x01, 0x0a); ++ sd->i2c_addr = 0x6e; ++ i2c_r(gspca_dev, 0x00, 2); ++ ++ reg_w1(gspca_dev, 0x01, 0x29); ++ reg_w1(gspca_dev, 0x17, 0x42); ++ ++ if (gspca_dev->usb_buf[3] == 0x20 ++ && gspca_dev->usb_buf[4] == 0x30) ++ PDEBUG(D_PROBE, "Sensor po2030n"); ++/* sd->sensor = SENSOR_PO2030N; */ ++ else ++ PDEBUG(D_PROBE, "Unknown sensor ID %02x%02x", ++ gspca_dev->usb_buf[3], ++ gspca_dev->usb_buf[4]); ++} ++ + static void bridge_init(struct gspca_dev *gspca_dev, + const u8 *sn9c1xx) + { +@@ -1374,8 +1592,10 @@ static void bridge_init(struct gspca_dev *gspca_dev, + reg_w(gspca_dev, 0x08, &sn9c1xx[8], 2); + reg_w(gspca_dev, 0x17, &sn9c1xx[0x17], 5); + switch (sd->sensor) { ++ case SENSOR_GC0307: + case SENSOR_OV7660: + case SENSOR_PO1030: ++ case SENSOR_PO2030N: + case SENSOR_SP80708: + reg9a = reg9a_spec; + break; +@@ -1396,6 +1616,14 @@ static void bridge_init(struct gspca_dev *gspca_dev, + reg_w1(gspca_dev, 0x01, 0x42); + reg_w1(gspca_dev, 0x01, 0x42); + break; ++ case SENSOR_GC0307: ++ msleep(50); ++ reg_w1(gspca_dev, 0x01, 0x61); ++ reg_w1(gspca_dev, 0x17, 0x22); ++ reg_w1(gspca_dev, 0x01, 0x60); ++ reg_w1(gspca_dev, 0x01, 0x40); ++ msleep(50); ++ break; + case SENSOR_MT9V111: + reg_w1(gspca_dev, 0x01, 0x61); + reg_w1(gspca_dev, 0x17, 0x61); +@@ -1438,6 +1666,12 @@ static void bridge_init(struct gspca_dev *gspca_dev, + reg_w1(gspca_dev, 0x01, 0x60); + reg_w1(gspca_dev, 0x01, 0x40); + break; ++ case SENSOR_PO2030N: ++ reg_w1(gspca_dev, 0x01, 0x63); ++ reg_w1(gspca_dev, 0x17, 0x20); ++ reg_w1(gspca_dev, 0x01, 0x62); ++ reg_w1(gspca_dev, 0x01, 0x42); ++ break; + case SENSOR_OV7660: + /* fall thru */ + case SENSOR_SP80708: +@@ -1545,6 +1779,9 @@ static int sd_init(struct gspca_dev *gspca_dev) + case SENSOR_OV7648: + ov7648_probe(gspca_dev); + break; ++ case SENSOR_PO2030N: ++ po2030n_probe(gspca_dev); ++ break; + } + regGpio[1] = 0x70; + reg_w(gspca_dev, 0x01, regGpio, 2); +@@ -1763,9 +2000,12 @@ static void setgamma(struct gspca_dev *gspca_dev) + case SENSOR_MT9V111: + gamma_base = gamma_spec_1; + break; +- case SENSOR_SP80708: ++ case SENSOR_GC0307: + gamma_base = gamma_spec_2; + break; ++ case SENSOR_SP80708: ++ gamma_base = gamma_spec_3; ++ break; + default: + gamma_base = gamma_def; + break; +@@ -1956,9 +2196,15 @@ static int sd_start(struct gspca_dev *gspca_dev) + static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; + static const u8 CA_adcm1700[] = + { 0x14, 0xec, 0x0a, 0xf6 }; ++ static const u8 CA_po2030n[] = ++ { 0x1e, 0xe2, 0x14, 0xec }; + static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */ ++ static const u8 CE_gc0307[] = ++ { 0x32, 0xce, 0x2d, 0xd3 }; + static const u8 CE_ov76xx[] = + { 0x32, 0xdd, 0x32, 0xdd }; ++ static const u8 CE_po2030n[] = ++ { 0x14, 0xe7, 0x1e, 0xdd }; + + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); +@@ -2015,6 +2261,9 @@ static int sd_start(struct gspca_dev *gspca_dev) + } + reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); + switch (sd->sensor) { ++ case SENSOR_GC0307: ++ reg17 = 0xa2; ++ break; + case SENSOR_MT9V111: + reg17 = 0xe0; + break; +@@ -2029,6 +2278,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg17 = 0xa0; + break; + case SENSOR_PO1030: ++ case SENSOR_PO2030N: + reg17 = 0xa0; + break; + default: +@@ -2053,12 +2303,16 @@ static int sd_start(struct gspca_dev *gspca_dev) + case SENSOR_SP80708: + reg_w1(gspca_dev, 0x9a, 0x05); + break; ++ case SENSOR_GC0307: + case SENSOR_MT9V111: + reg_w1(gspca_dev, 0x9a, 0x07); + break; + case SENSOR_OV7648: + reg_w1(gspca_dev, 0x9a, 0x0a); + break; ++ case SENSOR_PO2030N: ++ reg_w1(gspca_dev, 0x9a, 0x06); ++ break; + default: + reg_w1(gspca_dev, 0x9a, 0x08); + break; +@@ -2083,6 +2337,11 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg1 = 0x46; + reg17 = 0xe2; + break; ++ case SENSOR_GC0307: ++ init = gc0307_sensor_param1; ++ reg17 = 0xa2; ++ reg1 = 0x44; ++ break; + case SENSOR_MO4000: + if (mode) { + /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ +@@ -2132,6 +2391,11 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg17 = 0xa2; + reg1 = 0x44; + break; ++ case SENSOR_PO2030N: ++ init = po2030n_sensor_param1; ++ reg1 = 0x46; ++ reg17 = 0xa2; ++ break; + default: + /* case SENSOR_SP80708: */ + init = sp80708_sensor_param1; +@@ -2151,10 +2415,18 @@ static int sd_start(struct gspca_dev *gspca_dev) + } + + reg_w(gspca_dev, 0xc0, C0, 6); +- if (sd->sensor == SENSOR_ADCM1700) ++ switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ case SENSOR_GC0307: + reg_w(gspca_dev, 0xca, CA_adcm1700, 4); +- else ++ break; ++ case SENSOR_PO2030N: ++ reg_w(gspca_dev, 0xca, CA_po2030n, 4); ++ break; ++ default: + reg_w(gspca_dev, 0xca, CA, 4); ++ break; ++ } + switch (sd->sensor) { + case SENSOR_ADCM1700: + case SENSOR_OV7630: +@@ -2162,6 +2434,12 @@ static int sd_start(struct gspca_dev *gspca_dev) + case SENSOR_OV7660: + reg_w(gspca_dev, 0xce, CE_ov76xx, 4); + break; ++ case SENSOR_GC0307: ++ reg_w(gspca_dev, 0xce, CE_gc0307, 4); ++ break; ++ case SENSOR_PO2030N: ++ reg_w(gspca_dev, 0xce, CE_po2030n, 4); ++ break; + default: + reg_w(gspca_dev, 0xce, CE, 4); + /* ?? {0x1e, 0xdd, 0x2d, 0xe7} */ +@@ -2199,6 +2477,9 @@ static void sd_stopN(struct gspca_dev *gspca_dev) + + data = 0x0b; + switch (sd->sensor) { ++ case SENSOR_GC0307: ++ data = 0x29; ++ break; + case SENSOR_HV7131R: + i2c_w8(gspca_dev, stophv7131); + data = 0x2b; +@@ -2675,7 +2956,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + #endif + {USB_DEVICE(0x0c45, 0x613c), BS(SN9C120, HV7131R)}, + {USB_DEVICE(0x0c45, 0x613e), BS(SN9C120, OV7630)}, +-/* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/ ++ {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, /*sn9c120b*/ + {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/ + {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/ + {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/ +From: Jean-François Moine +Date: Fri, 2 Apr 2010 10:12:42 +0000 (+0200) +Subject: gspca - vc032x: Change the ov7670 format to YUYV. +X-Git-Url: http://git.linuxtv.org/jfrancois/gspca.git?a=commitdiff_plain;h=510d87cf78323250749ee9b95631f28f1d942020 + +gspca - vc032x: Change the ov7670 format to YUYV. + +Signed-off-by: Jean-François Moine +--- + +diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c +index 7fde145..732c3df 100644 +--- a/drivers/media/video/gspca/vc032x.c ++++ b/drivers/media/video/gspca/vc032x.c +@@ -1971,268 +1971,489 @@ static const u8 ov7660_NoFliker[][4] = { + {} + }; + +-static const u8 ov7670_initVGA_JPG[][4] = { ++static const u8 ov7670_InitVGA[][4] = { + {0xb3, 0x01, 0x05, 0xcc}, +- {0x00, 0x00, 0x30, 0xdd}, {0xb0, 0x03, 0x19, 0xcc}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xb0, 0x03, 0x19, 0xcc}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xb0, 0x04, 0x02, 0xcc}, + {0x00, 0x00, 0x10, 0xdd}, +- {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, +- {0xb3, 0x00, 0x66, 0xcc}, {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb3, 0x00, 0x66, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb0, 0x16, 0x01, 0xcc}, + {0xb3, 0x35, 0xa1, 0xcc}, /* i2c add: 21 */ + {0xb3, 0x34, 0x01, 0xcc}, +- {0xb3, 0x05, 0x01, 0xcc}, {0xb3, 0x06, 0x01, 0xcc}, +- {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc}, +- {0xb3, 0x02, 0x02, 0xcc}, {0xb3, 0x03, 0x1f, 0xcc}, +- {0xb3, 0x14, 0x00, 0xcc}, {0xb3, 0x15, 0x00, 0xcc}, +- {0xb3, 0x16, 0x02, 0xcc}, {0xb3, 0x17, 0x7f, 0xcc}, +- {0xb3, 0x04, 0x05, 0xcc}, {0xb3, 0x20, 0x00, 0xcc}, +- {0xb3, 0x21, 0x00, 0xcc}, {0xb3, 0x22, 0x01, 0xcc}, +- {0xb3, 0x23, 0xe0, 0xcc}, {0xbc, 0x00, 0x41, 0xcc}, +- {0xbc, 0x01, 0x01, 0xcc}, {0x00, 0x12, 0x80, 0xaa}, +- {0x00, 0x00, 0x20, 0xdd}, {0x00, 0x12, 0x00, 0xaa}, +- {0x00, 0x11, 0x40, 0xaa}, {0x00, 0x6b, 0x0a, 0xaa}, +- {0x00, 0x3a, 0x04, 0xaa}, {0x00, 0x40, 0xc0, 0xaa}, +- {0x00, 0x8c, 0x00, 0xaa}, {0x00, 0x7a, 0x29, 0xaa}, +- {0x00, 0x7b, 0x0e, 0xaa}, {0x00, 0x7c, 0x1a, 0xaa}, +- {0x00, 0x7d, 0x31, 0xaa}, {0x00, 0x7e, 0x53, 0xaa}, +- {0x00, 0x7f, 0x60, 0xaa}, {0x00, 0x80, 0x6b, 0xaa}, +- {0x00, 0x81, 0x73, 0xaa}, {0x00, 0x82, 0x7b, 0xaa}, +- {0x00, 0x83, 0x82, 0xaa}, {0x00, 0x84, 0x89, 0xaa}, +- {0x00, 0x85, 0x96, 0xaa}, {0x00, 0x86, 0xa1, 0xaa}, +- {0x00, 0x87, 0xb7, 0xaa}, {0x00, 0x88, 0xcc, 0xaa}, +- {0x00, 0x89, 0xe1, 0xaa}, {0x00, 0x13, 0xe0, 0xaa}, +- {0x00, 0x00, 0x00, 0xaa}, {0x00, 0x10, 0x00, 0xaa}, +- {0x00, 0x0d, 0x40, 0xaa}, {0x00, 0x14, 0x28, 0xaa}, +- {0x00, 0xa5, 0x05, 0xaa}, {0x00, 0xab, 0x07, 0xaa}, +- {0x00, 0x24, 0x95, 0xaa}, {0x00, 0x25, 0x33, 0xaa}, +- {0x00, 0x26, 0xe3, 0xaa}, {0x00, 0x9f, 0x88, 0xaa}, +- {0x00, 0xa0, 0x78, 0xaa}, {0x00, 0x55, 0x90, 0xaa}, +- {0x00, 0xa1, 0x03, 0xaa}, {0x00, 0xa6, 0xe0, 0xaa}, +- {0x00, 0xa7, 0xd8, 0xaa}, {0x00, 0xa8, 0xf0, 0xaa}, +- {0x00, 0xa9, 0x90, 0xaa}, {0x00, 0xaa, 0x14, 0xaa}, +- {0x00, 0x13, 0xe5, 0xaa}, {0x00, 0x0e, 0x61, 0xaa}, +- {0x00, 0x0f, 0x4b, 0xaa}, {0x00, 0x16, 0x02, 0xaa}, ++ {0xb3, 0x05, 0x01, 0xcc}, ++ {0xb3, 0x06, 0x01, 0xcc}, ++ {0xb3, 0x08, 0x01, 0xcc}, ++ {0xb3, 0x09, 0x0c, 0xcc}, ++ {0xb3, 0x02, 0x02, 0xcc}, ++ {0xb3, 0x03, 0x1f, 0xcc}, ++ {0xb3, 0x14, 0x00, 0xcc}, ++ {0xb3, 0x15, 0x00, 0xcc}, ++ {0xb3, 0x16, 0x02, 0xcc}, ++ {0xb3, 0x17, 0x7f, 0xcc}, ++ {0xb3, 0x04, 0x05, 0xcc}, ++ {0xb3, 0x20, 0x00, 0xcc}, ++ {0xb3, 0x21, 0x00, 0xcc}, ++ {0xb3, 0x22, 0x01, 0xcc}, ++ {0xb3, 0x23, 0xe0, 0xcc}, ++ {0xbc, 0x00, 0x41, 0xcc}, ++ {0xbc, 0x01, 0x01, 0xcc}, ++ {0x00, 0x12, 0x80, 0xaa}, ++ {0x00, 0x00, 0x20, 0xdd}, ++ {0x00, 0x12, 0x00, 0xaa}, ++ {0x00, 0x11, 0x40, 0xaa}, ++ {0x00, 0x6b, 0x0a, 0xaa}, ++ {0x00, 0x3a, 0x04, 0xaa}, ++ {0x00, 0x40, 0xc0, 0xaa}, ++ {0x00, 0x8c, 0x00, 0xaa}, ++ {0x00, 0x7a, 0x29, 0xaa}, ++ {0x00, 0x7b, 0x0e, 0xaa}, ++ {0x00, 0x7c, 0x1a, 0xaa}, ++ {0x00, 0x7d, 0x31, 0xaa}, ++ {0x00, 0x7e, 0x53, 0xaa}, ++ {0x00, 0x7f, 0x60, 0xaa}, ++ {0x00, 0x80, 0x6b, 0xaa}, ++ {0x00, 0x81, 0x73, 0xaa}, ++ {0x00, 0x82, 0x7b, 0xaa}, ++ {0x00, 0x83, 0x82, 0xaa}, ++ {0x00, 0x84, 0x89, 0xaa}, ++ {0x00, 0x85, 0x96, 0xaa}, ++ {0x00, 0x86, 0xa1, 0xaa}, ++ {0x00, 0x87, 0xb7, 0xaa}, ++ {0x00, 0x88, 0xcc, 0xaa}, ++ {0x00, 0x89, 0xe1, 0xaa}, ++ {0x00, 0x13, 0xe0, 0xaa}, ++ {0x00, 0x00, 0x00, 0xaa}, ++ {0x00, 0x10, 0x00, 0xaa}, ++ {0x00, 0x0d, 0x40, 0xaa}, ++ {0x00, 0x14, 0x28, 0xaa}, ++ {0x00, 0xa5, 0x05, 0xaa}, ++ {0x00, 0xab, 0x07, 0xaa}, ++ {0x00, 0x24, 0x95, 0xaa}, ++ {0x00, 0x25, 0x33, 0xaa}, ++ {0x00, 0x26, 0xe3, 0xaa}, ++ {0x00, 0x9f, 0x88, 0xaa}, ++ {0x00, 0xa0, 0x78, 0xaa}, ++ {0x00, 0x55, 0x90, 0xaa}, ++ {0x00, 0xa1, 0x03, 0xaa}, ++ {0x00, 0xa6, 0xe0, 0xaa}, ++ {0x00, 0xa7, 0xd8, 0xaa}, ++ {0x00, 0xa8, 0xf0, 0xaa}, ++ {0x00, 0xa9, 0x90, 0xaa}, ++ {0x00, 0xaa, 0x14, 0xaa}, ++ {0x00, 0x13, 0xe5, 0xaa}, ++ {0x00, 0x0e, 0x61, 0xaa}, ++ {0x00, 0x0f, 0x4b, 0xaa}, ++ {0x00, 0x16, 0x02, 0xaa}, + {0x00, 0x1e, 0x07, 0xaa}, /* MVFP */ + {0x00, 0x21, 0x02, 0xaa}, +- {0x00, 0x22, 0x91, 0xaa}, {0x00, 0x29, 0x07, 0xaa}, +- {0x00, 0x33, 0x0b, 0xaa}, {0x00, 0x35, 0x0b, 0xaa}, +- {0x00, 0x37, 0x1d, 0xaa}, {0x00, 0x38, 0x71, 0xaa}, +- {0x00, 0x39, 0x2a, 0xaa}, {0x00, 0x3c, 0x78, 0xaa}, +- {0x00, 0x4d, 0x40, 0xaa}, {0x00, 0x4e, 0x20, 0xaa}, +- {0x00, 0x74, 0x19, 0xaa}, {0x00, 0x8d, 0x4f, 0xaa}, +- {0x00, 0x8e, 0x00, 0xaa}, {0x00, 0x8f, 0x00, 0xaa}, +- {0x00, 0x90, 0x00, 0xaa}, {0x00, 0x91, 0x00, 0xaa}, +- {0x00, 0x96, 0x00, 0xaa}, {0x00, 0x9a, 0x80, 0xaa}, +- {0x00, 0xb0, 0x84, 0xaa}, {0x00, 0xb1, 0x0c, 0xaa}, +- {0x00, 0xb2, 0x0e, 0xaa}, {0x00, 0xb3, 0x82, 0xaa}, +- {0x00, 0xb8, 0x0a, 0xaa}, {0x00, 0x43, 0x14, 0xaa}, +- {0x00, 0x44, 0xf0, 0xaa}, {0x00, 0x45, 0x45, 0xaa}, +- {0x00, 0x46, 0x63, 0xaa}, {0x00, 0x47, 0x2d, 0xaa}, +- {0x00, 0x48, 0x46, 0xaa}, {0x00, 0x59, 0x88, 0xaa}, +- {0x00, 0x5a, 0xa0, 0xaa}, {0x00, 0x5b, 0xc6, 0xaa}, +- {0x00, 0x5c, 0x7d, 0xaa}, {0x00, 0x5d, 0x5f, 0xaa}, +- {0x00, 0x5e, 0x19, 0xaa}, {0x00, 0x6c, 0x0a, 0xaa}, +- {0x00, 0x6d, 0x55, 0xaa}, {0x00, 0x6e, 0x11, 0xaa}, +- {0x00, 0x6f, 0x9e, 0xaa}, {0x00, 0x69, 0x00, 0xaa}, +- {0x00, 0x6a, 0x40, 0xaa}, {0x00, 0x01, 0x40, 0xaa}, +- {0x00, 0x02, 0x40, 0xaa}, {0x00, 0x13, 0xe7, 0xaa}, +- {0x00, 0x5f, 0xf0, 0xaa}, {0x00, 0x60, 0xf0, 0xaa}, +- {0x00, 0x61, 0xf0, 0xaa}, {0x00, 0x27, 0xa0, 0xaa}, +- {0x00, 0x28, 0x80, 0xaa}, {0x00, 0x2c, 0x90, 0xaa}, +- {0x00, 0x4f, 0x66, 0xaa}, {0x00, 0x50, 0x66, 0xaa}, +- {0x00, 0x51, 0x00, 0xaa}, {0x00, 0x52, 0x22, 0xaa}, +- {0x00, 0x53, 0x5e, 0xaa}, {0x00, 0x54, 0x80, 0xaa}, +- {0x00, 0x58, 0x9e, 0xaa}, {0x00, 0x41, 0x08, 0xaa}, +- {0x00, 0x3f, 0x00, 0xaa}, {0x00, 0x75, 0x85, 0xaa}, +- {0x00, 0x76, 0xe1, 0xaa}, {0x00, 0x4c, 0x00, 0xaa}, +- {0x00, 0x77, 0x0a, 0xaa}, {0x00, 0x3d, 0x88, 0xaa}, +- {0x00, 0x4b, 0x09, 0xaa}, {0x00, 0xc9, 0x60, 0xaa}, +- {0x00, 0x41, 0x38, 0xaa}, {0x00, 0x62, 0x30, 0xaa}, +- {0x00, 0x63, 0x30, 0xaa}, {0x00, 0x64, 0x08, 0xaa}, +- {0x00, 0x94, 0x07, 0xaa}, {0x00, 0x95, 0x0b, 0xaa}, +- {0x00, 0x65, 0x00, 0xaa}, {0x00, 0x66, 0x05, 0xaa}, +- {0x00, 0x56, 0x50, 0xaa}, {0x00, 0x34, 0x11, 0xaa}, +- {0x00, 0xa4, 0x88, 0xaa}, {0x00, 0x96, 0x00, 0xaa}, +- {0x00, 0x97, 0x30, 0xaa}, {0x00, 0x98, 0x20, 0xaa}, +- {0x00, 0x99, 0x30, 0xaa}, {0x00, 0x9a, 0x84, 0xaa}, +- {0x00, 0x9b, 0x29, 0xaa}, {0x00, 0x9c, 0x03, 0xaa}, +- {0x00, 0x78, 0x04, 0xaa}, {0x00, 0x79, 0x01, 0xaa}, +- {0x00, 0xc8, 0xf0, 0xaa}, {0x00, 0x79, 0x0f, 0xaa}, +- {0x00, 0xc8, 0x00, 0xaa}, {0x00, 0x79, 0x10, 0xaa}, +- {0x00, 0xc8, 0x7e, 0xaa}, {0x00, 0x79, 0x0a, 0xaa}, +- {0x00, 0xc8, 0x80, 0xaa}, {0x00, 0x79, 0x0b, 0xaa}, +- {0x00, 0xc8, 0x01, 0xaa}, {0x00, 0x79, 0x0c, 0xaa}, +- {0x00, 0xc8, 0x0f, 0xaa}, {0x00, 0x79, 0x0d, 0xaa}, +- {0x00, 0xc8, 0x20, 0xaa}, {0x00, 0x79, 0x09, 0xaa}, +- {0x00, 0xc8, 0x80, 0xaa}, {0x00, 0x79, 0x02, 0xaa}, +- {0x00, 0xc8, 0xc0, 0xaa}, {0x00, 0x79, 0x03, 0xaa}, +- {0x00, 0xc8, 0x40, 0xaa}, {0x00, 0x79, 0x05, 0xaa}, +- {0x00, 0xc8, 0x30, 0xaa}, {0x00, 0x79, 0x26, 0xaa}, +- {0x00, 0x11, 0x40, 0xaa}, {0x00, 0x3a, 0x04, 0xaa}, +- {0x00, 0x12, 0x00, 0xaa}, {0x00, 0x40, 0xc0, 0xaa}, +- {0x00, 0x8c, 0x00, 0xaa}, {0x00, 0x17, 0x14, 0xaa}, +- {0x00, 0x18, 0x02, 0xaa}, {0x00, 0x32, 0x92, 0xaa}, +- {0x00, 0x19, 0x02, 0xaa}, {0x00, 0x1a, 0x7a, 0xaa}, +- {0x00, 0x03, 0x0a, 0xaa}, {0x00, 0x0c, 0x00, 0xaa}, +- {0x00, 0x3e, 0x00, 0xaa}, {0x00, 0x70, 0x3a, 0xaa}, +- {0x00, 0x71, 0x35, 0xaa}, {0x00, 0x72, 0x11, 0xaa}, +- {0x00, 0x73, 0xf0, 0xaa}, {0x00, 0xa2, 0x02, 0xaa}, +- {0x00, 0xb1, 0x00, 0xaa}, {0x00, 0xb1, 0x0c, 0xaa}, ++ {0x00, 0x22, 0x91, 0xaa}, ++ {0x00, 0x29, 0x07, 0xaa}, ++ {0x00, 0x33, 0x0b, 0xaa}, ++ {0x00, 0x35, 0x0b, 0xaa}, ++ {0x00, 0x37, 0x1d, 0xaa}, ++ {0x00, 0x38, 0x71, 0xaa}, ++ {0x00, 0x39, 0x2a, 0xaa}, ++ {0x00, 0x3c, 0x78, 0xaa}, ++ {0x00, 0x4d, 0x40, 0xaa}, ++ {0x00, 0x4e, 0x20, 0xaa}, ++ {0x00, 0x74, 0x19, 0xaa}, ++ {0x00, 0x8d, 0x4f, 0xaa}, ++ {0x00, 0x8e, 0x00, 0xaa}, ++ {0x00, 0x8f, 0x00, 0xaa}, ++ {0x00, 0x90, 0x00, 0xaa}, ++ {0x00, 0x91, 0x00, 0xaa}, ++ {0x00, 0x96, 0x00, 0xaa}, ++ {0x00, 0x9a, 0x80, 0xaa}, ++ {0x00, 0xb0, 0x84, 0xaa}, ++ {0x00, 0xb1, 0x0c, 0xaa}, ++ {0x00, 0xb2, 0x0e, 0xaa}, ++ {0x00, 0xb3, 0x82, 0xaa}, ++ {0x00, 0xb8, 0x0a, 0xaa}, ++ {0x00, 0x43, 0x14, 0xaa}, ++ {0x00, 0x44, 0xf0, 0xaa}, ++ {0x00, 0x45, 0x45, 0xaa}, ++ {0x00, 0x46, 0x63, 0xaa}, ++ {0x00, 0x47, 0x2d, 0xaa}, ++ {0x00, 0x48, 0x46, 0xaa}, ++ {0x00, 0x59, 0x88, 0xaa}, ++ {0x00, 0x5a, 0xa0, 0xaa}, ++ {0x00, 0x5b, 0xc6, 0xaa}, ++ {0x00, 0x5c, 0x7d, 0xaa}, ++ {0x00, 0x5d, 0x5f, 0xaa}, ++ {0x00, 0x5e, 0x19, 0xaa}, ++ {0x00, 0x6c, 0x0a, 0xaa}, ++ {0x00, 0x6d, 0x55, 0xaa}, ++ {0x00, 0x6e, 0x11, 0xaa}, ++ {0x00, 0x6f, 0x9e, 0xaa}, ++ {0x00, 0x69, 0x00, 0xaa}, ++ {0x00, 0x6a, 0x40, 0xaa}, ++ {0x00, 0x01, 0x40, 0xaa}, ++ {0x00, 0x02, 0x40, 0xaa}, ++ {0x00, 0x13, 0xe7, 0xaa}, ++ {0x00, 0x5f, 0xf0, 0xaa}, ++ {0x00, 0x60, 0xf0, 0xaa}, ++ {0x00, 0x61, 0xf0, 0xaa}, ++ {0x00, 0x27, 0xa0, 0xaa}, ++ {0x00, 0x28, 0x80, 0xaa}, ++ {0x00, 0x2c, 0x90, 0xaa}, ++ {0x00, 0x4f, 0x66, 0xaa}, ++ {0x00, 0x50, 0x66, 0xaa}, ++ {0x00, 0x51, 0x00, 0xaa}, ++ {0x00, 0x52, 0x22, 0xaa}, ++ {0x00, 0x53, 0x5e, 0xaa}, ++ {0x00, 0x54, 0x80, 0xaa}, ++ {0x00, 0x58, 0x9e, 0xaa}, ++ {0x00, 0x41, 0x08, 0xaa}, ++ {0x00, 0x3f, 0x00, 0xaa}, ++ {0x00, 0x75, 0x85, 0xaa}, ++ {0x00, 0x76, 0xe1, 0xaa}, ++ {0x00, 0x4c, 0x00, 0xaa}, ++ {0x00, 0x77, 0x0a, 0xaa}, ++ {0x00, 0x3d, 0x88, 0xaa}, ++ {0x00, 0x4b, 0x09, 0xaa}, ++ {0x00, 0xc9, 0x60, 0xaa}, ++ {0x00, 0x41, 0x38, 0xaa}, ++ {0x00, 0x62, 0x30, 0xaa}, ++ {0x00, 0x63, 0x30, 0xaa}, ++ {0x00, 0x64, 0x08, 0xaa}, ++ {0x00, 0x94, 0x07, 0xaa}, ++ {0x00, 0x95, 0x0b, 0xaa}, ++ {0x00, 0x65, 0x00, 0xaa}, ++ {0x00, 0x66, 0x05, 0xaa}, ++ {0x00, 0x56, 0x50, 0xaa}, ++ {0x00, 0x34, 0x11, 0xaa}, ++ {0x00, 0xa4, 0x88, 0xaa}, ++ {0x00, 0x96, 0x00, 0xaa}, ++ {0x00, 0x97, 0x30, 0xaa}, ++ {0x00, 0x98, 0x20, 0xaa}, ++ {0x00, 0x99, 0x30, 0xaa}, ++ {0x00, 0x9a, 0x84, 0xaa}, ++ {0x00, 0x9b, 0x29, 0xaa}, ++ {0x00, 0x9c, 0x03, 0xaa}, ++ {0x00, 0x78, 0x04, 0xaa}, ++ {0x00, 0x79, 0x01, 0xaa}, ++ {0x00, 0xc8, 0xf0, 0xaa}, ++ {0x00, 0x79, 0x0f, 0xaa}, ++ {0x00, 0xc8, 0x00, 0xaa}, ++ {0x00, 0x79, 0x10, 0xaa}, ++ {0x00, 0xc8, 0x7e, 0xaa}, ++ {0x00, 0x79, 0x0a, 0xaa}, ++ {0x00, 0xc8, 0x80, 0xaa}, ++ {0x00, 0x79, 0x0b, 0xaa}, ++ {0x00, 0xc8, 0x01, 0xaa}, ++ {0x00, 0x79, 0x0c, 0xaa}, ++ {0x00, 0xc8, 0x0f, 0xaa}, ++ {0x00, 0x79, 0x0d, 0xaa}, ++ {0x00, 0xc8, 0x20, 0xaa}, ++ {0x00, 0x79, 0x09, 0xaa}, ++ {0x00, 0xc8, 0x80, 0xaa}, ++ {0x00, 0x79, 0x02, 0xaa}, ++ {0x00, 0xc8, 0xc0, 0xaa}, ++ {0x00, 0x79, 0x03, 0xaa}, ++ {0x00, 0xc8, 0x40, 0xaa}, ++ {0x00, 0x79, 0x05, 0xaa}, ++ {0x00, 0xc8, 0x30, 0xaa}, ++ {0x00, 0x79, 0x26, 0xaa}, ++ {0x00, 0x11, 0x40, 0xaa}, ++ {0x00, 0x3a, 0x04, 0xaa}, ++ {0x00, 0x12, 0x00, 0xaa}, ++ {0x00, 0x40, 0xc0, 0xaa}, ++ {0x00, 0x8c, 0x00, 0xaa}, ++ {0x00, 0x17, 0x14, 0xaa}, ++ {0x00, 0x18, 0x02, 0xaa}, ++ {0x00, 0x32, 0x92, 0xaa}, ++ {0x00, 0x19, 0x02, 0xaa}, ++ {0x00, 0x1a, 0x7a, 0xaa}, ++ {0x00, 0x03, 0x0a, 0xaa}, ++ {0x00, 0x0c, 0x00, 0xaa}, ++ {0x00, 0x3e, 0x00, 0xaa}, ++ {0x00, 0x70, 0x3a, 0xaa}, ++ {0x00, 0x71, 0x35, 0xaa}, ++ {0x00, 0x72, 0x11, 0xaa}, ++ {0x00, 0x73, 0xf0, 0xaa}, ++ {0x00, 0xa2, 0x02, 0xaa}, ++ {0x00, 0xb1, 0x00, 0xaa}, ++ {0x00, 0xb1, 0x0c, 0xaa}, + {0x00, 0x1e, 0x37, 0xaa}, /* MVFP */ + {0x00, 0xaa, 0x14, 0xaa}, +- {0x00, 0x24, 0x80, 0xaa}, {0x00, 0x25, 0x74, 0xaa}, +- {0x00, 0x26, 0xd3, 0xaa}, {0x00, 0x0d, 0x00, 0xaa}, +- {0x00, 0x14, 0x18, 0xaa}, {0x00, 0x9d, 0x99, 0xaa}, +- {0x00, 0x9e, 0x7f, 0xaa}, {0x00, 0x64, 0x08, 0xaa}, +- {0x00, 0x94, 0x07, 0xaa}, {0x00, 0x95, 0x06, 0xaa}, +- {0x00, 0x66, 0x05, 0xaa}, {0x00, 0x41, 0x08, 0xaa}, +- {0x00, 0x3f, 0x00, 0xaa}, {0x00, 0x75, 0x07, 0xaa}, +- {0x00, 0x76, 0xe1, 0xaa}, {0x00, 0x4c, 0x00, 0xaa}, +- {0x00, 0x77, 0x00, 0xaa}, {0x00, 0x3d, 0xc2, 0xaa}, +- {0x00, 0x4b, 0x09, 0xaa}, {0x00, 0xc9, 0x60, 0xaa}, +- {0x00, 0x41, 0x38, 0xaa}, {0xb6, 0x00, 0x00, 0xcc}, +- {0xb6, 0x03, 0x02, 0xcc}, {0xb6, 0x02, 0x80, 0xcc}, +- {0xb6, 0x05, 0x01, 0xcc}, {0xb6, 0x04, 0xe0, 0xcc}, +- {0xb6, 0x12, 0xf8, 0xcc}, {0xb6, 0x13, 0x13, 0xcc}, +- {0xb6, 0x18, 0x02, 0xcc}, {0xb6, 0x17, 0x58, 0xcc}, +- {0xb6, 0x16, 0x00, 0xcc}, {0xb6, 0x22, 0x12, 0xcc}, +- {0xb6, 0x23, 0x0b, 0xcc}, {0xbf, 0xc0, 0x39, 0xcc}, +- {0xbf, 0xc1, 0x04, 0xcc}, {0xbf, 0xcc, 0x00, 0xcc}, +- {0xb3, 0x5c, 0x01, 0xcc}, {0xb3, 0x01, 0x45, 0xcc}, ++ {0x00, 0x24, 0x80, 0xaa}, ++ {0x00, 0x25, 0x74, 0xaa}, ++ {0x00, 0x26, 0xd3, 0xaa}, ++ {0x00, 0x0d, 0x00, 0xaa}, ++ {0x00, 0x14, 0x18, 0xaa}, ++ {0x00, 0x9d, 0x99, 0xaa}, ++ {0x00, 0x9e, 0x7f, 0xaa}, ++ {0x00, 0x64, 0x08, 0xaa}, ++ {0x00, 0x94, 0x07, 0xaa}, ++ {0x00, 0x95, 0x06, 0xaa}, ++ {0x00, 0x66, 0x05, 0xaa}, ++ {0x00, 0x41, 0x08, 0xaa}, ++ {0x00, 0x3f, 0x00, 0xaa}, ++ {0x00, 0x75, 0x07, 0xaa}, ++ {0x00, 0x76, 0xe1, 0xaa}, ++ {0x00, 0x4c, 0x00, 0xaa}, ++ {0x00, 0x77, 0x00, 0xaa}, ++ {0x00, 0x3d, 0xc2, 0xaa}, ++ {0x00, 0x4b, 0x09, 0xaa}, ++ {0x00, 0xc9, 0x60, 0xaa}, ++ {0x00, 0x41, 0x38, 0xaa}, ++ {0xbf, 0xc0, 0x26, 0xcc}, ++ {0xbf, 0xc1, 0x02, 0xcc}, ++ {0xbf, 0xcc, 0x04, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xb3, 0x01, 0x45, 0xcc}, + {0x00, 0x77, 0x05, 0xaa}, + {}, + }; + +-static const u8 ov7670_initQVGA_JPG[][4] = { +- {0xb3, 0x01, 0x05, 0xcc}, {0x00, 0x00, 0x30, 0xdd}, +- {0xb0, 0x03, 0x19, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, +- {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, +- {0xb3, 0x00, 0x66, 0xcc}, {0xb3, 0x00, 0x67, 0xcc}, +- {0xb3, 0x35, 0xa1, 0xcc}, {0xb3, 0x34, 0x01, 0xcc}, +- {0xb3, 0x05, 0x01, 0xcc}, {0xb3, 0x06, 0x01, 0xcc}, +- {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc}, +- {0xb3, 0x02, 0x02, 0xcc}, {0xb3, 0x03, 0x1f, 0xcc}, +- {0xb3, 0x14, 0x00, 0xcc}, {0xb3, 0x15, 0x00, 0xcc}, +- {0xb3, 0x16, 0x02, 0xcc}, {0xb3, 0x17, 0x7f, 0xcc}, +- {0xb3, 0x04, 0x05, 0xcc}, {0xb3, 0x20, 0x00, 0xcc}, +- {0xb3, 0x21, 0x00, 0xcc}, {0xb3, 0x22, 0x01, 0xcc}, +- {0xb3, 0x23, 0xe0, 0xcc}, {0xbc, 0x00, 0xd1, 0xcc}, +- {0xbc, 0x01, 0x01, 0xcc}, {0x00, 0x12, 0x80, 0xaa}, +- {0x00, 0x00, 0x20, 0xdd}, {0x00, 0x12, 0x00, 0xaa}, +- {0x00, 0x11, 0x40, 0xaa}, {0x00, 0x6b, 0x0a, 0xaa}, +- {0x00, 0x3a, 0x04, 0xaa}, {0x00, 0x40, 0xc0, 0xaa}, +- {0x00, 0x8c, 0x00, 0xaa}, {0x00, 0x7a, 0x29, 0xaa}, +- {0x00, 0x7b, 0x0e, 0xaa}, {0x00, 0x7c, 0x1a, 0xaa}, +- {0x00, 0x7d, 0x31, 0xaa}, {0x00, 0x7e, 0x53, 0xaa}, +- {0x00, 0x7f, 0x60, 0xaa}, {0x00, 0x80, 0x6b, 0xaa}, +- {0x00, 0x81, 0x73, 0xaa}, {0x00, 0x82, 0x7b, 0xaa}, +- {0x00, 0x83, 0x82, 0xaa}, {0x00, 0x84, 0x89, 0xaa}, +- {0x00, 0x85, 0x96, 0xaa}, {0x00, 0x86, 0xa1, 0xaa}, +- {0x00, 0x87, 0xb7, 0xaa}, {0x00, 0x88, 0xcc, 0xaa}, +- {0x00, 0x89, 0xe1, 0xaa}, {0x00, 0x13, 0xe0, 0xaa}, +- {0x00, 0x00, 0x00, 0xaa}, {0x00, 0x10, 0x00, 0xaa}, +- {0x00, 0x0d, 0x40, 0xaa}, {0x00, 0x14, 0x28, 0xaa}, +- {0x00, 0xa5, 0x05, 0xaa}, {0x00, 0xab, 0x07, 0xaa}, +- {0x00, 0x24, 0x95, 0xaa}, {0x00, 0x25, 0x33, 0xaa}, +- {0x00, 0x26, 0xe3, 0xaa}, {0x00, 0x9f, 0x88, 0xaa}, +- {0x00, 0xa0, 0x78, 0xaa}, {0x00, 0x55, 0x90, 0xaa}, +- {0x00, 0xa1, 0x03, 0xaa}, {0x00, 0xa6, 0xe0, 0xaa}, +- {0x00, 0xa7, 0xd8, 0xaa}, {0x00, 0xa8, 0xf0, 0xaa}, +- {0x00, 0xa9, 0x90, 0xaa}, {0x00, 0xaa, 0x14, 0xaa}, +- {0x00, 0x13, 0xe5, 0xaa}, {0x00, 0x0e, 0x61, 0xaa}, +- {0x00, 0x0f, 0x4b, 0xaa}, {0x00, 0x16, 0x02, 0xaa}, ++static const u8 ov7670_InitQVGA[][4] = { ++ {0xb3, 0x01, 0x05, 0xcc}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xb0, 0x03, 0x19, 0xcc}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xb0, 0x04, 0x02, 0xcc}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xb3, 0x00, 0x66, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb0, 0x16, 0x01, 0xcc}, ++ {0xb3, 0x35, 0xa1, 0xcc}, /* i2c add: 21 */ ++ {0xb3, 0x34, 0x01, 0xcc}, ++ {0xb3, 0x05, 0x01, 0xcc}, ++ {0xb3, 0x06, 0x01, 0xcc}, ++ {0xb3, 0x08, 0x01, 0xcc}, ++ {0xb3, 0x09, 0x0c, 0xcc}, ++ {0xb3, 0x02, 0x02, 0xcc}, ++ {0xb3, 0x03, 0x1f, 0xcc}, ++ {0xb3, 0x14, 0x00, 0xcc}, ++ {0xb3, 0x15, 0x00, 0xcc}, ++ {0xb3, 0x16, 0x02, 0xcc}, ++ {0xb3, 0x17, 0x7f, 0xcc}, ++ {0xb3, 0x04, 0x05, 0xcc}, ++ {0xb3, 0x20, 0x00, 0xcc}, ++ {0xb3, 0x21, 0x00, 0xcc}, ++ {0xb3, 0x22, 0x01, 0xcc}, ++ {0xb3, 0x23, 0xe0, 0xcc}, ++ {0xbc, 0x00, 0xd1, 0xcc}, ++ {0xbc, 0x01, 0x01, 0xcc}, ++ {0x00, 0x12, 0x80, 0xaa}, ++ {0x00, 0x00, 0x20, 0xdd}, ++ {0x00, 0x12, 0x00, 0xaa}, ++ {0x00, 0x11, 0x40, 0xaa}, ++ {0x00, 0x6b, 0x0a, 0xaa}, ++ {0x00, 0x3a, 0x04, 0xaa}, ++ {0x00, 0x40, 0xc0, 0xaa}, ++ {0x00, 0x8c, 0x00, 0xaa}, ++ {0x00, 0x7a, 0x29, 0xaa}, ++ {0x00, 0x7b, 0x0e, 0xaa}, ++ {0x00, 0x7c, 0x1a, 0xaa}, ++ {0x00, 0x7d, 0x31, 0xaa}, ++ {0x00, 0x7e, 0x53, 0xaa}, ++ {0x00, 0x7f, 0x60, 0xaa}, ++ {0x00, 0x80, 0x6b, 0xaa}, ++ {0x00, 0x81, 0x73, 0xaa}, ++ {0x00, 0x82, 0x7b, 0xaa}, ++ {0x00, 0x83, 0x82, 0xaa}, ++ {0x00, 0x84, 0x89, 0xaa}, ++ {0x00, 0x85, 0x96, 0xaa}, ++ {0x00, 0x86, 0xa1, 0xaa}, ++ {0x00, 0x87, 0xb7, 0xaa}, ++ {0x00, 0x88, 0xcc, 0xaa}, ++ {0x00, 0x89, 0xe1, 0xaa}, ++ {0x00, 0x13, 0xe0, 0xaa}, ++ {0x00, 0x00, 0x00, 0xaa}, ++ {0x00, 0x10, 0x00, 0xaa}, ++ {0x00, 0x0d, 0x40, 0xaa}, ++ {0x00, 0x14, 0x28, 0xaa}, ++ {0x00, 0xa5, 0x05, 0xaa}, ++ {0x00, 0xab, 0x07, 0xaa}, ++ {0x00, 0x24, 0x95, 0xaa}, ++ {0x00, 0x25, 0x33, 0xaa}, ++ {0x00, 0x26, 0xe3, 0xaa}, ++ {0x00, 0x9f, 0x88, 0xaa}, ++ {0x00, 0xa0, 0x78, 0xaa}, ++ {0x00, 0x55, 0x90, 0xaa}, ++ {0x00, 0xa1, 0x03, 0xaa}, ++ {0x00, 0xa6, 0xe0, 0xaa}, ++ {0x00, 0xa7, 0xd8, 0xaa}, ++ {0x00, 0xa8, 0xf0, 0xaa}, ++ {0x00, 0xa9, 0x90, 0xaa}, ++ {0x00, 0xaa, 0x14, 0xaa}, ++ {0x00, 0x13, 0xe5, 0xaa}, ++ {0x00, 0x0e, 0x61, 0xaa}, ++ {0x00, 0x0f, 0x4b, 0xaa}, ++ {0x00, 0x16, 0x02, 0xaa}, + {0x00, 0x1e, 0x07, 0xaa}, /* MVFP */ + {0x00, 0x21, 0x02, 0xaa}, +- {0x00, 0x22, 0x91, 0xaa}, {0x00, 0x29, 0x07, 0xaa}, +- {0x00, 0x33, 0x0b, 0xaa}, {0x00, 0x35, 0x0b, 0xaa}, +- {0x00, 0x37, 0x1d, 0xaa}, {0x00, 0x38, 0x71, 0xaa}, +- {0x00, 0x39, 0x2a, 0xaa}, {0x00, 0x3c, 0x78, 0xaa}, +- {0x00, 0x4d, 0x40, 0xaa}, {0x00, 0x4e, 0x20, 0xaa}, +- {0x00, 0x74, 0x19, 0xaa}, {0x00, 0x8d, 0x4f, 0xaa}, +- {0x00, 0x8e, 0x00, 0xaa}, {0x00, 0x8f, 0x00, 0xaa}, +- {0x00, 0x90, 0x00, 0xaa}, {0x00, 0x91, 0x00, 0xaa}, +- {0x00, 0x96, 0x00, 0xaa}, {0x00, 0x9a, 0x80, 0xaa}, +- {0x00, 0xb0, 0x84, 0xaa}, {0x00, 0xb1, 0x0c, 0xaa}, +- {0x00, 0xb2, 0x0e, 0xaa}, {0x00, 0xb3, 0x82, 0xaa}, +- {0x00, 0xb8, 0x0a, 0xaa}, {0x00, 0x43, 0x14, 0xaa}, +- {0x00, 0x44, 0xf0, 0xaa}, {0x00, 0x45, 0x45, 0xaa}, +- {0x00, 0x46, 0x63, 0xaa}, {0x00, 0x47, 0x2d, 0xaa}, +- {0x00, 0x48, 0x46, 0xaa}, {0x00, 0x59, 0x88, 0xaa}, +- {0x00, 0x5a, 0xa0, 0xaa}, {0x00, 0x5b, 0xc6, 0xaa}, +- {0x00, 0x5c, 0x7d, 0xaa}, {0x00, 0x5d, 0x5f, 0xaa}, +- {0x00, 0x5e, 0x19, 0xaa}, {0x00, 0x6c, 0x0a, 0xaa}, +- {0x00, 0x6d, 0x55, 0xaa}, {0x00, 0x6e, 0x11, 0xaa}, +- {0x00, 0x6f, 0x9e, 0xaa}, {0x00, 0x69, 0x00, 0xaa}, +- {0x00, 0x6a, 0x40, 0xaa}, {0x00, 0x01, 0x40, 0xaa}, +- {0x00, 0x02, 0x40, 0xaa}, {0x00, 0x13, 0xe7, 0xaa}, +- {0x00, 0x5f, 0xf0, 0xaa}, {0x00, 0x60, 0xf0, 0xaa}, +- {0x00, 0x61, 0xf0, 0xaa}, {0x00, 0x27, 0xa0, 0xaa}, +- {0x00, 0x28, 0x80, 0xaa}, {0x00, 0x2c, 0x90, 0xaa}, +- {0x00, 0x4f, 0x66, 0xaa}, {0x00, 0x50, 0x66, 0xaa}, +- {0x00, 0x51, 0x00, 0xaa}, {0x00, 0x52, 0x22, 0xaa}, +- {0x00, 0x53, 0x5e, 0xaa}, {0x00, 0x54, 0x80, 0xaa}, +- {0x00, 0x58, 0x9e, 0xaa}, {0x00, 0x41, 0x08, 0xaa}, +- {0x00, 0x3f, 0x00, 0xaa}, {0x00, 0x75, 0x85, 0xaa}, +- {0x00, 0x76, 0xe1, 0xaa}, {0x00, 0x4c, 0x00, 0xaa}, +- {0x00, 0x77, 0x0a, 0xaa}, {0x00, 0x3d, 0x88, 0xaa}, +- {0x00, 0x4b, 0x09, 0xaa}, {0x00, 0xc9, 0x60, 0xaa}, +- {0x00, 0x41, 0x38, 0xaa}, {0x00, 0x62, 0x30, 0xaa}, +- {0x00, 0x63, 0x30, 0xaa}, {0x00, 0x64, 0x08, 0xaa}, +- {0x00, 0x94, 0x07, 0xaa}, {0x00, 0x95, 0x0b, 0xaa}, +- {0x00, 0x65, 0x00, 0xaa}, {0x00, 0x66, 0x05, 0xaa}, +- {0x00, 0x56, 0x50, 0xaa}, {0x00, 0x34, 0x11, 0xaa}, +- {0x00, 0xa4, 0x88, 0xaa}, {0x00, 0x96, 0x00, 0xaa}, +- {0x00, 0x97, 0x30, 0xaa}, {0x00, 0x98, 0x20, 0xaa}, +- {0x00, 0x99, 0x30, 0xaa}, {0x00, 0x9a, 0x84, 0xaa}, +- {0x00, 0x9b, 0x29, 0xaa}, {0x00, 0x9c, 0x03, 0xaa}, +- {0x00, 0x78, 0x04, 0xaa}, {0x00, 0x79, 0x01, 0xaa}, +- {0x00, 0xc8, 0xf0, 0xaa}, {0x00, 0x79, 0x0f, 0xaa}, +- {0x00, 0xc8, 0x00, 0xaa}, {0x00, 0x79, 0x10, 0xaa}, +- {0x00, 0xc8, 0x7e, 0xaa}, {0x00, 0x79, 0x0a, 0xaa}, +- {0x00, 0xc8, 0x80, 0xaa}, {0x00, 0x79, 0x0b, 0xaa}, +- {0x00, 0xc8, 0x01, 0xaa}, {0x00, 0x79, 0x0c, 0xaa}, +- {0x00, 0xc8, 0x0f, 0xaa}, {0x00, 0x79, 0x0d, 0xaa}, +- {0x00, 0xc8, 0x20, 0xaa}, {0x00, 0x79, 0x09, 0xaa}, +- {0x00, 0xc8, 0x80, 0xaa}, {0x00, 0x79, 0x02, 0xaa}, +- {0x00, 0xc8, 0xc0, 0xaa}, {0x00, 0x79, 0x03, 0xaa}, +- {0x00, 0xc8, 0x40, 0xaa}, {0x00, 0x79, 0x05, 0xaa}, +- {0x00, 0xc8, 0x30, 0xaa}, {0x00, 0x79, 0x26, 0xaa}, +- {0x00, 0x11, 0x40, 0xaa}, {0x00, 0x3a, 0x04, 0xaa}, +- {0x00, 0x12, 0x00, 0xaa}, {0x00, 0x40, 0xc0, 0xaa}, +- {0x00, 0x8c, 0x00, 0xaa}, {0x00, 0x17, 0x14, 0xaa}, +- {0x00, 0x18, 0x02, 0xaa}, {0x00, 0x32, 0x92, 0xaa}, +- {0x00, 0x19, 0x02, 0xaa}, {0x00, 0x1a, 0x7a, 0xaa}, +- {0x00, 0x03, 0x0a, 0xaa}, {0x00, 0x0c, 0x00, 0xaa}, +- {0x00, 0x3e, 0x00, 0xaa}, {0x00, 0x70, 0x3a, 0xaa}, +- {0x00, 0x71, 0x35, 0xaa}, {0x00, 0x72, 0x11, 0xaa}, +- {0x00, 0x73, 0xf0, 0xaa}, {0x00, 0xa2, 0x02, 0xaa}, +- {0x00, 0xb1, 0x00, 0xaa}, {0x00, 0xb1, 0x0c, 0xaa}, ++ {0x00, 0x22, 0x91, 0xaa}, ++ {0x00, 0x29, 0x07, 0xaa}, ++ {0x00, 0x33, 0x0b, 0xaa}, ++ {0x00, 0x35, 0x0b, 0xaa}, ++ {0x00, 0x37, 0x1d, 0xaa}, ++ {0x00, 0x38, 0x71, 0xaa}, ++ {0x00, 0x39, 0x2a, 0xaa}, ++ {0x00, 0x3c, 0x78, 0xaa}, ++ {0x00, 0x4d, 0x40, 0xaa}, ++ {0x00, 0x4e, 0x20, 0xaa}, ++ {0x00, 0x74, 0x19, 0xaa}, ++ {0x00, 0x8d, 0x4f, 0xaa}, ++ {0x00, 0x8e, 0x00, 0xaa}, ++ {0x00, 0x8f, 0x00, 0xaa}, ++ {0x00, 0x90, 0x00, 0xaa}, ++ {0x00, 0x91, 0x00, 0xaa}, ++ {0x00, 0x96, 0x00, 0xaa}, ++ {0x00, 0x9a, 0x80, 0xaa}, ++ {0x00, 0xb0, 0x84, 0xaa}, ++ {0x00, 0xb1, 0x0c, 0xaa}, ++ {0x00, 0xb2, 0x0e, 0xaa}, ++ {0x00, 0xb3, 0x82, 0xaa}, ++ {0x00, 0xb8, 0x0a, 0xaa}, ++ {0x00, 0x43, 0x14, 0xaa}, ++ {0x00, 0x44, 0xf0, 0xaa}, ++ {0x00, 0x45, 0x45, 0xaa}, ++ {0x00, 0x46, 0x63, 0xaa}, ++ {0x00, 0x47, 0x2d, 0xaa}, ++ {0x00, 0x48, 0x46, 0xaa}, ++ {0x00, 0x59, 0x88, 0xaa}, ++ {0x00, 0x5a, 0xa0, 0xaa}, ++ {0x00, 0x5b, 0xc6, 0xaa}, ++ {0x00, 0x5c, 0x7d, 0xaa}, ++ {0x00, 0x5d, 0x5f, 0xaa}, ++ {0x00, 0x5e, 0x19, 0xaa}, ++ {0x00, 0x6c, 0x0a, 0xaa}, ++ {0x00, 0x6d, 0x55, 0xaa}, ++ {0x00, 0x6e, 0x11, 0xaa}, ++ {0x00, 0x6f, 0x9e, 0xaa}, ++ {0x00, 0x69, 0x00, 0xaa}, ++ {0x00, 0x6a, 0x40, 0xaa}, ++ {0x00, 0x01, 0x40, 0xaa}, ++ {0x00, 0x02, 0x40, 0xaa}, ++ {0x00, 0x13, 0xe7, 0xaa}, ++ {0x00, 0x5f, 0xf0, 0xaa}, ++ {0x00, 0x60, 0xf0, 0xaa}, ++ {0x00, 0x61, 0xf0, 0xaa}, ++ {0x00, 0x27, 0xa0, 0xaa}, ++ {0x00, 0x28, 0x80, 0xaa}, ++ {0x00, 0x2c, 0x90, 0xaa}, ++ {0x00, 0x4f, 0x66, 0xaa}, ++ {0x00, 0x50, 0x66, 0xaa}, ++ {0x00, 0x51, 0x00, 0xaa}, ++ {0x00, 0x52, 0x22, 0xaa}, ++ {0x00, 0x53, 0x5e, 0xaa}, ++ {0x00, 0x54, 0x80, 0xaa}, ++ {0x00, 0x58, 0x9e, 0xaa}, ++ {0x00, 0x41, 0x08, 0xaa}, ++ {0x00, 0x3f, 0x00, 0xaa}, ++ {0x00, 0x75, 0x85, 0xaa}, ++ {0x00, 0x76, 0xe1, 0xaa}, ++ {0x00, 0x4c, 0x00, 0xaa}, ++ {0x00, 0x77, 0x0a, 0xaa}, ++ {0x00, 0x3d, 0x88, 0xaa}, ++ {0x00, 0x4b, 0x09, 0xaa}, ++ {0x00, 0xc9, 0x60, 0xaa}, ++ {0x00, 0x41, 0x38, 0xaa}, ++ {0x00, 0x62, 0x30, 0xaa}, ++ {0x00, 0x63, 0x30, 0xaa}, ++ {0x00, 0x64, 0x08, 0xaa}, ++ {0x00, 0x94, 0x07, 0xaa}, ++ {0x00, 0x95, 0x0b, 0xaa}, ++ {0x00, 0x65, 0x00, 0xaa}, ++ {0x00, 0x66, 0x05, 0xaa}, ++ {0x00, 0x56, 0x50, 0xaa}, ++ {0x00, 0x34, 0x11, 0xaa}, ++ {0x00, 0xa4, 0x88, 0xaa}, ++ {0x00, 0x96, 0x00, 0xaa}, ++ {0x00, 0x97, 0x30, 0xaa}, ++ {0x00, 0x98, 0x20, 0xaa}, ++ {0x00, 0x99, 0x30, 0xaa}, ++ {0x00, 0x9a, 0x84, 0xaa}, ++ {0x00, 0x9b, 0x29, 0xaa}, ++ {0x00, 0x9c, 0x03, 0xaa}, ++ {0x00, 0x78, 0x04, 0xaa}, ++ {0x00, 0x79, 0x01, 0xaa}, ++ {0x00, 0xc8, 0xf0, 0xaa}, ++ {0x00, 0x79, 0x0f, 0xaa}, ++ {0x00, 0xc8, 0x00, 0xaa}, ++ {0x00, 0x79, 0x10, 0xaa}, ++ {0x00, 0xc8, 0x7e, 0xaa}, ++ {0x00, 0x79, 0x0a, 0xaa}, ++ {0x00, 0xc8, 0x80, 0xaa}, ++ {0x00, 0x79, 0x0b, 0xaa}, ++ {0x00, 0xc8, 0x01, 0xaa}, ++ {0x00, 0x79, 0x0c, 0xaa}, ++ {0x00, 0xc8, 0x0f, 0xaa}, ++ {0x00, 0x79, 0x0d, 0xaa}, ++ {0x00, 0xc8, 0x20, 0xaa}, ++ {0x00, 0x79, 0x09, 0xaa}, ++ {0x00, 0xc8, 0x80, 0xaa}, ++ {0x00, 0x79, 0x02, 0xaa}, ++ {0x00, 0xc8, 0xc0, 0xaa}, ++ {0x00, 0x79, 0x03, 0xaa}, ++ {0x00, 0xc8, 0x40, 0xaa}, ++ {0x00, 0x79, 0x05, 0xaa}, ++ {0x00, 0xc8, 0x30, 0xaa}, ++ {0x00, 0x79, 0x26, 0xaa}, ++ {0x00, 0x11, 0x40, 0xaa}, ++ {0x00, 0x3a, 0x04, 0xaa}, ++ {0x00, 0x12, 0x00, 0xaa}, ++ {0x00, 0x40, 0xc0, 0xaa}, ++ {0x00, 0x8c, 0x00, 0xaa}, ++ {0x00, 0x17, 0x14, 0xaa}, ++ {0x00, 0x18, 0x02, 0xaa}, ++ {0x00, 0x32, 0x92, 0xaa}, ++ {0x00, 0x19, 0x02, 0xaa}, ++ {0x00, 0x1a, 0x7a, 0xaa}, ++ {0x00, 0x03, 0x0a, 0xaa}, ++ {0x00, 0x0c, 0x00, 0xaa}, ++ {0x00, 0x3e, 0x00, 0xaa}, ++ {0x00, 0x70, 0x3a, 0xaa}, ++ {0x00, 0x71, 0x35, 0xaa}, ++ {0x00, 0x72, 0x11, 0xaa}, ++ {0x00, 0x73, 0xf0, 0xaa}, ++ {0x00, 0xa2, 0x02, 0xaa}, ++ {0x00, 0xb1, 0x00, 0xaa}, ++ {0x00, 0xb1, 0x0c, 0xaa}, + {0x00, 0x1e, 0x37, 0xaa}, /* MVFP */ + {0x00, 0xaa, 0x14, 0xaa}, +- {0x00, 0x24, 0x80, 0xaa}, {0x00, 0x25, 0x74, 0xaa}, +- {0x00, 0x26, 0xd3, 0xaa}, {0x00, 0x0d, 0x00, 0xaa}, +- {0x00, 0x14, 0x18, 0xaa}, {0x00, 0x9d, 0x99, 0xaa}, +- {0x00, 0x9e, 0x7f, 0xaa}, {0x00, 0x64, 0x08, 0xaa}, +- {0x00, 0x94, 0x07, 0xaa}, {0x00, 0x95, 0x06, 0xaa}, +- {0x00, 0x66, 0x05, 0xaa}, {0x00, 0x41, 0x08, 0xaa}, +- {0x00, 0x3f, 0x00, 0xaa}, {0x00, 0x75, 0x07, 0xaa}, +- {0x00, 0x76, 0xe1, 0xaa}, {0x00, 0x4c, 0x00, 0xaa}, +- {0x00, 0x77, 0x00, 0xaa}, {0x00, 0x3d, 0xc2, 0xaa}, +- {0x00, 0x4b, 0x09, 0xaa}, {0x00, 0xc9, 0x60, 0xaa}, +- {0x00, 0x41, 0x38, 0xaa}, {0xb6, 0x00, 0x00, 0xcc}, +- {0xb6, 0x03, 0x01, 0xcc}, {0xb6, 0x02, 0x40, 0xcc}, +- {0xb6, 0x05, 0x00, 0xcc}, {0xb6, 0x04, 0xf0, 0xcc}, +- {0xb6, 0x12, 0xf8, 0xcc}, {0xb6, 0x13, 0x21, 0xcc}, +- {0xb6, 0x18, 0x00, 0xcc}, {0xb6, 0x17, 0x96, 0xcc}, +- {0xb6, 0x16, 0x00, 0xcc}, {0xb6, 0x22, 0x12, 0xcc}, +- {0xb6, 0x23, 0x0b, 0xcc}, {0xbf, 0xc0, 0x39, 0xcc}, +- {0xbf, 0xc1, 0x04, 0xcc}, {0xbf, 0xcc, 0x00, 0xcc}, +- {0xbc, 0x02, 0x18, 0xcc}, {0xbc, 0x03, 0x50, 0xcc}, +- {0xbc, 0x04, 0x18, 0xcc}, {0xbc, 0x05, 0x00, 0xcc}, +- {0xbc, 0x06, 0x00, 0xcc}, {0xbc, 0x08, 0x30, 0xcc}, +- {0xbc, 0x09, 0x40, 0xcc}, {0xbc, 0x0a, 0x10, 0xcc}, +- {0xbc, 0x0b, 0x00, 0xcc}, {0xbc, 0x0c, 0x00, 0xcc}, +- {0xb3, 0x5c, 0x01, 0xcc}, {0xb3, 0x01, 0x45, 0xcc}, +- {0x00, 0x77, 0x05, 0xaa }, ++ {0x00, 0x24, 0x80, 0xaa}, ++ {0x00, 0x25, 0x74, 0xaa}, ++ {0x00, 0x26, 0xd3, 0xaa}, ++ {0x00, 0x0d, 0x00, 0xaa}, ++ {0x00, 0x14, 0x18, 0xaa}, ++ {0x00, 0x9d, 0x99, 0xaa}, ++ {0x00, 0x9e, 0x7f, 0xaa}, ++ {0x00, 0x64, 0x08, 0xaa}, ++ {0x00, 0x94, 0x07, 0xaa}, ++ {0x00, 0x95, 0x06, 0xaa}, ++ {0x00, 0x66, 0x05, 0xaa}, ++ {0x00, 0x41, 0x08, 0xaa}, ++ {0x00, 0x3f, 0x00, 0xaa}, ++ {0x00, 0x75, 0x07, 0xaa}, ++ {0x00, 0x76, 0xe1, 0xaa}, ++ {0x00, 0x4c, 0x00, 0xaa}, ++ {0x00, 0x77, 0x00, 0xaa}, ++ {0x00, 0x3d, 0xc2, 0xaa}, ++ {0x00, 0x4b, 0x09, 0xaa}, ++ {0x00, 0xc9, 0x60, 0xaa}, ++ {0x00, 0x41, 0x38, 0xaa}, ++ {0xbc, 0x02, 0x18, 0xcc}, ++ {0xbc, 0x03, 0x50, 0xcc}, ++ {0xbc, 0x04, 0x18, 0xcc}, ++ {0xbc, 0x05, 0x00, 0xcc}, ++ {0xbc, 0x06, 0x00, 0xcc}, ++ {0xbc, 0x08, 0x30, 0xcc}, ++ {0xbc, 0x09, 0x40, 0xcc}, ++ {0xbc, 0x0a, 0x10, 0xcc}, ++ {0xbc, 0x0b, 0x00, 0xcc}, ++ {0xbc, 0x0c, 0x00, 0xcc}, ++ {0xbf, 0xc0, 0x26, 0xcc}, ++ {0xbf, 0xc1, 0x02, 0xcc}, ++ {0xbf, 0xcc, 0x04, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xb3, 0x01, 0x45, 0xcc}, ++ {0x00, 0x77, 0x05, 0xaa}, + {}, + }; + +@@ -3117,6 +3338,10 @@ static int sd_config(struct gspca_dev *gspca_dev, + cam->cam_mode = bi_mode; + cam->nmodes = ARRAY_SIZE(bi_mode); + break; ++ case SENSOR_OV7670: ++ cam->cam_mode = bi_mode; ++ cam->nmodes = ARRAY_SIZE(bi_mode) - 1; ++ break; + default: + cam->cam_mode = vc0323_mode; + cam->nmodes = ARRAY_SIZE(vc0323_mode) - 1; +@@ -3329,14 +3554,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + else + init = ov7660_initVGA_data; /* 640x480 */ + break; +- case SENSOR_OV7670: +- /*GammaT = ov7660_gamma; */ +- /*MatrixT = ov7660_matrix; */ +- if (mode) +- init = ov7670_initQVGA_JPG; /* 320x240 */ +- else +- init = ov7670_initVGA_JPG; /* 640x480 */ +- break; + case SENSOR_MI0360: + GammaT = mi1320_gamma; + MatrixT = mi0360_matrix; +@@ -3373,6 +3590,9 @@ static int sd_start(struct gspca_dev *gspca_dev) + MatrixT = mi1320_matrix; + init = mi1320_soc_init[mode]; + break; ++ case SENSOR_OV7670: ++ init = mode == 1 ? ov7670_InitVGA : ov7670_InitQVGA; ++ break; + case SENSOR_PO3130NC: + GammaT = po3130_gamma; + MatrixT = po3130_matrix; +@@ -3426,7 +3646,13 @@ static int sd_start(struct gspca_dev *gspca_dev) + sethvflip(gspca_dev); + setlightfreq(gspca_dev); + } +- if (sd->sensor == SENSOR_POxxxx) { ++ switch (sd->sensor) { ++ case SENSOR_OV7670: ++ reg_w(gspca_dev->dev, 0x87, 0xffff, 0xffff); ++ reg_w(gspca_dev->dev, 0x88, 0xff00, 0xf0f1); ++ reg_w(gspca_dev->dev, 0xa0, 0x0000, 0xbfff); ++ break; ++ case SENSOR_POxxxx: + setcolors(gspca_dev); + setbrightness(gspca_dev); + setcontrast(gspca_dev); +@@ -3435,6 +3661,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + msleep(80); + reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); + usb_exchange(gspca_dev, poxxxx_init_end_2); ++ break; + } + return 0; + } diff --git a/linux-2.6-v4l-dvb-rebase-gspca-to-latest.patch b/linux-2.6-v4l-dvb-rebase-gspca-to-latest.patch new file mode 100644 index 000000000..aed3aecb3 --- /dev/null +++ b/linux-2.6-v4l-dvb-rebase-gspca-to-latest.patch @@ -0,0 +1,15766 @@ +From 1adf4b1e78d961522e4d598dd82456630458e617 Mon Sep 17 00:00:00 2001 +From: Hans de Goede +Date: Sat, 20 Feb 2010 21:40:38 +0100 +Subject: [PATCH] Rebase gspca webcamdrivers to latest upstream + +This adds drivers for benq, cpia1 and sn9c2028 bridges + support for +more devices and many bugfixes in other drivers. + +This also adds support for the button found on most cameras in most +gspca sub drivers. +--- + drivers/media/video/gspca/Kconfig | 46 +- + drivers/media/video/gspca/Makefile | 8 + + drivers/media/video/gspca/benq.c | 322 ++++ + drivers/media/video/gspca/coarse_expo_autogain.h | 116 ++ + drivers/media/video/gspca/conex.c | 4 +- + drivers/media/video/gspca/cpia1.c | 2022 ++++++++++++++++++++ + drivers/media/video/gspca/etoms.c | 10 +- + drivers/media/video/gspca/gl860/gl860.c | 10 +- + drivers/media/video/gspca/gspca.c | 252 +++- + drivers/media/video/gspca/gspca.h | 30 +- + drivers/media/video/gspca/m5602/m5602_mt9m111.c | 16 +- + drivers/media/video/gspca/m5602/m5602_ov7660.c | 102 +- + drivers/media/video/gspca/m5602/m5602_ov7660.h | 2 +- + drivers/media/video/gspca/m5602/m5602_ov9650.c | 2 +- + drivers/media/video/gspca/m5602/m5602_po1030.c | 14 +- + drivers/media/video/gspca/m5602/m5602_s5k4aa.c | 2 +- + drivers/media/video/gspca/m5602/m5602_s5k83a.c | 2 +- + drivers/media/video/gspca/mars.c | 40 +- + drivers/media/video/gspca/mr97310a.c | 226 ++- + drivers/media/video/gspca/ov519.c | 170 ++- + drivers/media/video/gspca/ov534.c | 1253 ++----------- + drivers/media/video/gspca/ov534_9.c | 1477 ++++++++++++++ + drivers/media/video/gspca/pac207.c | 25 +- + drivers/media/video/gspca/pac7302.c | 432 ++--- + drivers/media/video/gspca/pac7311.c | 272 ++-- + drivers/media/video/gspca/pac_common.h | 9 +- + drivers/media/video/gspca/sn9c2028.c | 757 ++++++++ + drivers/media/video/gspca/sn9c2028.h | 51 + + drivers/media/video/gspca/sn9c20x.c | 33 +- + drivers/media/video/gspca/sonixb.c | 481 ++++-- + drivers/media/video/gspca/sonixj.c | 423 ++++- + drivers/media/video/gspca/spca500.c | 21 +- + drivers/media/video/gspca/spca501.c | 27 +- + drivers/media/video/gspca/spca505.c | 2 +- + drivers/media/video/gspca/spca506.c | 4 +- + drivers/media/video/gspca/spca508.c | 48 +- + drivers/media/video/gspca/spca561.c | 35 +- + drivers/media/video/gspca/sq905c.c | 45 +- + drivers/media/video/gspca/stk014.c | 2 +- + drivers/media/video/gspca/stv0680.c | 36 +- + drivers/media/video/gspca/stv06xx/stv06xx.c | 32 +- + drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c | 22 + + drivers/media/video/gspca/sunplus.c | 71 +- + drivers/media/video/gspca/t613.c | 102 +- + drivers/media/video/gspca/tv8532.c | 8 +- + drivers/media/video/gspca/vc032x.c | 1163 +++++++++++- + drivers/media/video/gspca/zc3xx.c | 712 ++++---- + include/linux/videodev2.h | 2 + + 48 files changed, 8692 insertions(+), 2249 deletions(-) + create mode 100644 drivers/media/video/gspca/benq.c + create mode 100644 drivers/media/video/gspca/coarse_expo_autogain.h + create mode 100644 drivers/media/video/gspca/cpia1.c + create mode 100644 drivers/media/video/gspca/ov534_9.c + create mode 100644 drivers/media/video/gspca/sn9c2028.c + create mode 100644 drivers/media/video/gspca/sn9c2028.h + +diff --git a/drivers/media/video/gspca/Kconfig b/drivers/media/video/gspca/Kconfig +index 609d65b..e0060c1 100644 +--- a/drivers/media/video/gspca/Kconfig ++++ b/drivers/media/video/gspca/Kconfig +@@ -21,6 +21,15 @@ source "drivers/media/video/gspca/m5602/Kconfig" + source "drivers/media/video/gspca/stv06xx/Kconfig" + source "drivers/media/video/gspca/gl860/Kconfig" + ++config USB_GSPCA_BENQ ++ tristate "Benq USB Camera Driver" ++ depends on VIDEO_V4L2 && USB_GSPCA ++ help ++ Say Y here if you want support for the Benq DC E300 camera. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called gspca_benq. ++ + config USB_GSPCA_CONEX + tristate "Conexant Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA +@@ -30,6 +39,17 @@ config USB_GSPCA_CONEX + To compile this driver as a module, choose M here: the + module will be called gspca_conex. + ++config USB_GSPCA_CPIA1 ++ tristate "cpia CPiA (version 1) Camera Driver" ++ depends on VIDEO_V4L2 && USB_GSPCA ++ help ++ Say Y here if you want support for USB cameras based on the cpia ++ CPiA chip. Note that you need atleast version 0.6.4 of libv4l for ++ applications to understand the videoformat generated by this driver. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called gspca_cpia1. ++ + config USB_GSPCA_ETOMS + tristate "Etoms USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA +@@ -86,15 +106,25 @@ config USB_GSPCA_OV519 + module will be called gspca_ov519. + + config USB_GSPCA_OV534 +- tristate "OV534 USB Camera Driver" ++ tristate "OV534 OV772x USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA + help +- Say Y here if you want support for cameras based on the OV534 chip. +- (e.g. Sony Playstation EYE) ++ Say Y here if you want support for cameras based on the OV534 chip ++ and sensor OV772x (e.g. Sony Playstation EYE) + + To compile this driver as a module, choose M here: the + module will be called gspca_ov534. + ++config USB_GSPCA_OV534_9 ++ tristate "OV534 OV965x USB Camera Driver" ++ depends on VIDEO_V4L2 && USB_GSPCA ++ help ++ Say Y here if you want support for cameras based on the OV534 chip ++ and sensor OV965x (e.g. Hercules Dualpix) ++ ++ To compile this driver as a module, choose M here: the ++ module will be called gspca_ov534_9. ++ + config USB_GSPCA_PAC207 + tristate "Pixart PAC207 USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA +@@ -122,6 +152,16 @@ config USB_GSPCA_PAC7311 + To compile this driver as a module, choose M here: the + module will be called gspca_pac7311. + ++config USB_GSPCA_SN9C2028 ++ tristate "SONIX Dual-Mode USB Camera Driver" ++ depends on VIDEO_V4L2 && USB_GSPCA ++ help ++ Say Y here if you want streaming support for Sonix SN9C2028 cameras. ++ These are supported as stillcams in libgphoto2/camlibs/sonix. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called gspca_sn9c2028. ++ + config USB_GSPCA_SN9C20X + tristate "SN9C20X USB Camera Driver" + depends on VIDEO_V4L2 && USB_GSPCA +diff --git a/drivers/media/video/gspca/Makefile b/drivers/media/video/gspca/Makefile +index ff2c727..6e4cf1c 100644 +--- a/drivers/media/video/gspca/Makefile ++++ b/drivers/media/video/gspca/Makefile +@@ -1,5 +1,7 @@ + obj-$(CONFIG_USB_GSPCA) += gspca_main.o ++obj-$(CONFIG_USB_GSPCA_BENQ) += gspca_benq.o + obj-$(CONFIG_USB_GSPCA_CONEX) += gspca_conex.o ++obj-$(CONFIG_USB_GSPCA_CPIA1) += gspca_cpia1.o + obj-$(CONFIG_USB_GSPCA_ETOMS) += gspca_etoms.o + obj-$(CONFIG_USB_GSPCA_FINEPIX) += gspca_finepix.o + obj-$(CONFIG_USB_GSPCA_JEILINJ) += gspca_jeilinj.o +@@ -7,9 +9,11 @@ obj-$(CONFIG_USB_GSPCA_MARS) += gspca_mars.o + obj-$(CONFIG_USB_GSPCA_MR97310A) += gspca_mr97310a.o + obj-$(CONFIG_USB_GSPCA_OV519) += gspca_ov519.o + obj-$(CONFIG_USB_GSPCA_OV534) += gspca_ov534.o ++obj-$(CONFIG_USB_GSPCA_OV534_9) += gspca_ov534_9.o + obj-$(CONFIG_USB_GSPCA_PAC207) += gspca_pac207.o + obj-$(CONFIG_USB_GSPCA_PAC7302) += gspca_pac7302.o + obj-$(CONFIG_USB_GSPCA_PAC7311) += gspca_pac7311.o ++obj-$(CONFIG_USB_GSPCA_SN9C2028) += gspca_sn9c2028.o + obj-$(CONFIG_USB_GSPCA_SN9C20X) += gspca_sn9c20x.o + obj-$(CONFIG_USB_GSPCA_SONIXB) += gspca_sonixb.o + obj-$(CONFIG_USB_GSPCA_SONIXJ) += gspca_sonixj.o +@@ -30,7 +34,9 @@ obj-$(CONFIG_USB_GSPCA_VC032X) += gspca_vc032x.o + obj-$(CONFIG_USB_GSPCA_ZC3XX) += gspca_zc3xx.o + + gspca_main-objs := gspca.o ++gspca_benq-objs := benq.o + gspca_conex-objs := conex.o ++gspca_cpia1-objs := cpia1.o + gspca_etoms-objs := etoms.o + gspca_finepix-objs := finepix.o + gspca_jeilinj-objs := jeilinj.o +@@ -38,9 +44,11 @@ gspca_mars-objs := mars.o + gspca_mr97310a-objs := mr97310a.o + gspca_ov519-objs := ov519.o + gspca_ov534-objs := ov534.o ++gspca_ov534_9-objs := ov534_9.o + gspca_pac207-objs := pac207.o + gspca_pac7302-objs := pac7302.o + gspca_pac7311-objs := pac7311.o ++gspca_sn9c2028-objs := sn9c2028.o + gspca_sn9c20x-objs := sn9c20x.o + gspca_sonixb-objs := sonixb.o + gspca_sonixj-objs := sonixj.o +diff --git a/drivers/media/video/gspca/benq.c b/drivers/media/video/gspca/benq.c +new file mode 100644 +index 0000000..43ac4af +--- /dev/null ++++ b/drivers/media/video/gspca/benq.c +@@ -0,0 +1,322 @@ ++/* ++ * Benq DC E300 subdriver ++ * ++ * Copyright (C) 2009 Jean-Francois Moine (http://moinejf.free.fr) ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#define MODULE_NAME "benq" ++ ++#include "gspca.h" ++ ++MODULE_AUTHOR("Jean-Francois Moine "); ++MODULE_DESCRIPTION("Benq DC E300 USB Camera Driver"); ++MODULE_LICENSE("GPL"); ++ ++/* specific webcam descriptor */ ++struct sd { ++ struct gspca_dev gspca_dev; /* !! must be the first item */ ++}; ++ ++/* V4L2 controls supported by the driver */ ++static const struct ctrl sd_ctrls[] = { ++}; ++ ++static const struct v4l2_pix_format vga_mode[] = { ++ {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 320, ++ .sizeimage = 320 * 240 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG}, ++}; ++ ++static void sd_isoc_irq(struct urb *urb); ++ ++/* -- write a register -- */ ++static void reg_w(struct gspca_dev *gspca_dev, ++ u16 value, u16 index) ++{ ++ struct usb_device *dev = gspca_dev->dev; ++ int ret; ++ ++ if (gspca_dev->usb_err < 0) ++ return; ++ ret = usb_control_msg(dev, usb_sndctrlpipe(dev, 0), ++ 0x02, ++ USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ value, ++ index, ++ NULL, ++ 0, ++ 500); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "reg_w err %d", ret); ++ gspca_dev->usb_err = ret; ++ } ++} ++ ++/* this function is called at probe time */ ++static int sd_config(struct gspca_dev *gspca_dev, ++ const struct usb_device_id *id) ++{ ++ gspca_dev->cam.cam_mode = vga_mode; ++ gspca_dev->cam.nmodes = ARRAY_SIZE(vga_mode); ++ gspca_dev->cam.no_urb_create = 1; ++ gspca_dev->cam.reverse_alts = 1; ++ return 0; ++} ++ ++/* this function is called at probe and resume time */ ++static int sd_init(struct gspca_dev *gspca_dev) ++{ ++ return 0; ++} ++ ++static int sd_isoc_init(struct gspca_dev *gspca_dev) ++{ ++ int ret; ++ ++ ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, ++ gspca_dev->nbalt - 1); ++ if (ret < 0) { ++ err("usb_set_interface failed"); ++ return ret; ++ } ++/* reg_w(gspca_dev, 0x0003, 0x0002); */ ++ return 0; ++} ++ ++/* -- start the camera -- */ ++static int sd_start(struct gspca_dev *gspca_dev) ++{ ++ struct urb *urb; ++ int i, n; ++ ++ /* create 4 URBs - 2 on endpoint 0x83 and 2 on 0x082 */ ++#if MAX_NURBS < 4 ++#error "Not enough URBs in the gspca table" ++#endif ++#define SD_PKT_SZ 64 ++#define SD_NPKT 32 ++ for (n = 0; n < 4; n++) { ++ urb = usb_alloc_urb(SD_NPKT, GFP_KERNEL); ++ if (!urb) { ++ err("usb_alloc_urb failed"); ++ return -ENOMEM; ++ } ++ gspca_dev->urb[n] = urb; ++ urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, ++ SD_PKT_SZ * SD_NPKT, ++ GFP_KERNEL, ++ &urb->transfer_dma); ++ ++ if (urb->transfer_buffer == NULL) { ++ err("usb_buffer_alloc failed"); ++ return -ENOMEM; ++ } ++ urb->dev = gspca_dev->dev; ++ urb->context = gspca_dev; ++ urb->transfer_buffer_length = SD_PKT_SZ * SD_NPKT; ++ urb->pipe = usb_rcvisocpipe(gspca_dev->dev, ++ n & 1 ? 0x82 : 0x83); ++ urb->transfer_flags = URB_ISO_ASAP ++ | URB_NO_TRANSFER_DMA_MAP; ++ urb->interval = 1; ++ urb->complete = sd_isoc_irq; ++ urb->number_of_packets = SD_NPKT; ++ for (i = 0; i < SD_NPKT; i++) { ++ urb->iso_frame_desc[i].length = SD_PKT_SZ; ++ urb->iso_frame_desc[i].offset = SD_PKT_SZ * i; ++ } ++ } ++ ++ return gspca_dev->usb_err; ++} ++ ++static void sd_stopN(struct gspca_dev *gspca_dev) ++{ ++ reg_w(gspca_dev, 0x003c, 0x0003); ++ reg_w(gspca_dev, 0x003c, 0x0004); ++ reg_w(gspca_dev, 0x003c, 0x0005); ++ reg_w(gspca_dev, 0x003c, 0x0006); ++ reg_w(gspca_dev, 0x003c, 0x0007); ++ usb_set_interface(gspca_dev->dev, gspca_dev->iface, gspca_dev->nbalt - 1); ++} ++ ++static void sd_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* isoc packet */ ++ int len) /* iso packet length */ ++{ ++ /* unused */ ++} ++ ++/* reception of an URB */ ++static void sd_isoc_irq(struct urb *urb) ++{ ++ struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; ++ struct urb *urb0; ++ u8 *data; ++ int i, st; ++ ++ PDEBUG(D_PACK, "sd isoc irq"); ++ if (!gspca_dev->streaming) ++ return; ++ if (urb->status != 0) { ++ if (urb->status == -ESHUTDOWN) ++ return; /* disconnection */ ++#ifdef CONFIG_PM ++ if (gspca_dev->frozen) ++ return; ++#endif ++ PDEBUG(D_ERR|D_PACK, "urb status: %d", urb->status); ++ return; ++ } ++ ++ /* if this is a control URN (ep 0x83), wait */ ++ if (urb == gspca_dev->urb[0] || urb == gspca_dev->urb[2]) ++ return; ++ ++ /* scan both received URBs */ ++ if (urb == gspca_dev->urb[1]) ++ urb0 = gspca_dev->urb[0]; ++ else ++ urb0 = gspca_dev->urb[2]; ++ for (i = 0; i < urb->number_of_packets; i++) { ++ ++ /* check the packet status and length */ ++ if (urb0->iso_frame_desc[i].actual_length != SD_PKT_SZ ++ || urb->iso_frame_desc[i].actual_length != SD_PKT_SZ) { ++ PDEBUG(D_ERR, "ISOC bad lengths %d / %d", ++ urb0->iso_frame_desc[i].actual_length, ++ urb->iso_frame_desc[i].actual_length); ++ gspca_dev->last_packet_type = DISCARD_PACKET; ++ continue; ++ } ++ st = urb0->iso_frame_desc[i].status; ++ if (st == 0) ++ st = urb->iso_frame_desc[i].status; ++ if (st) { ++ PDEBUG(D_ERR, ++ "ISOC data error: [%d] status=%d", ++ i, st); ++ gspca_dev->last_packet_type = DISCARD_PACKET; ++ continue; ++ } ++ ++ /* ++ * The images are received in URBs of different endpoints ++ * (0x83 and 0x82). ++ * Image pieces in URBs of ep 0x83 are continuated in URBs of ++ * ep 0x82 of the same index. ++ * The packets in the URBs of endpoint 0x83 start with: ++ * - 80 ba/bb 00 00 = start of image followed by 'ff d8' ++ * - 04 ba/bb oo oo = image piece ++ * where 'oo oo' is the image offset ++ (not cheked) ++ * - (other -> bad frame) ++ * The images are JPEG encoded with full header and ++ * normal ff escape. ++ * The end of image ('ff d9') may occur in any URB. ++ * (not cheked) ++ */ ++ data = (u8 *) urb0->transfer_buffer ++ + urb0->iso_frame_desc[i].offset; ++ if (data[0] == 0x80 && (data[1] & 0xfe) == 0xba) { ++ ++ /* new image */ ++ gspca_frame_add(gspca_dev, LAST_PACKET, ++ NULL, 0); ++ gspca_frame_add(gspca_dev, FIRST_PACKET, ++ data + 4, SD_PKT_SZ - 4); ++ } else if (data[0] == 0x04 && (data[1] & 0xfe) == 0xba) { ++ gspca_frame_add(gspca_dev, INTER_PACKET, ++ data + 4, SD_PKT_SZ - 4); ++ } else { ++ gspca_dev->last_packet_type = DISCARD_PACKET; ++ continue; ++ } ++ data = (u8 *) urb->transfer_buffer ++ + urb->iso_frame_desc[i].offset; ++ gspca_frame_add(gspca_dev, INTER_PACKET, ++ data, SD_PKT_SZ); ++ } ++ ++ /* resubmit the URBs */ ++ st = usb_submit_urb(urb0, GFP_ATOMIC); ++ if (st < 0) ++ PDEBUG(D_ERR|D_PACK, "usb_submit_urb(0) ret %d", st); ++ st = usb_submit_urb(urb, GFP_ATOMIC); ++ if (st < 0) ++ PDEBUG(D_ERR|D_PACK, "usb_submit_urb() ret %d", st); ++} ++ ++/* sub-driver description */ ++static const struct sd_desc sd_desc = { ++ .name = MODULE_NAME, ++ .ctrls = sd_ctrls, ++ .nctrls = ARRAY_SIZE(sd_ctrls), ++ .config = sd_config, ++ .init = sd_init, ++ .isoc_init = sd_isoc_init, ++ .start = sd_start, ++ .stopN = sd_stopN, ++ .pkt_scan = sd_pkt_scan, ++}; ++ ++/* -- module initialisation -- */ ++static const __devinitdata struct usb_device_id device_table[] = { ++ {USB_DEVICE(0x04a5, 0x3035)}, ++ {} ++}; ++MODULE_DEVICE_TABLE(usb, device_table); ++ ++/* -- device connect -- */ ++static int sd_probe(struct usb_interface *intf, ++ const struct usb_device_id *id) ++{ ++ return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), ++ THIS_MODULE); ++} ++ ++static struct usb_driver sd_driver = { ++ .name = MODULE_NAME, ++ .id_table = device_table, ++ .probe = sd_probe, ++ .disconnect = gspca_disconnect, ++#ifdef CONFIG_PM ++ .suspend = gspca_suspend, ++ .resume = gspca_resume, ++#endif ++}; ++ ++/* -- module insert / remove -- */ ++static int __init sd_mod_init(void) ++{ ++ int ret; ++ ++ ret = usb_register(&sd_driver); ++ if (ret < 0) ++ return ret; ++ info("registered"); ++ return 0; ++} ++static void __exit sd_mod_exit(void) ++{ ++ usb_deregister(&sd_driver); ++ info("deregistered"); ++} ++ ++module_init(sd_mod_init); ++module_exit(sd_mod_exit); +diff --git a/drivers/media/video/gspca/coarse_expo_autogain.h b/drivers/media/video/gspca/coarse_expo_autogain.h +new file mode 100644 +index 0000000..1cb9d94 +--- /dev/null ++++ b/drivers/media/video/gspca/coarse_expo_autogain.h +@@ -0,0 +1,116 @@ ++/* ++ * Auto gain algorithm for camera's with a coarse exposure control ++ * ++ * Copyright (C) 2010 Hans de Goede ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++/* Autogain + exposure algorithm for cameras with a coarse exposure control ++ (usually this means we can only control the clockdiv to change exposure) ++ As changing the clockdiv so that the fps drops from 30 to 15 fps for ++ example, will lead to a huge exposure change (it effectively doubles), ++ this algorithm normally tries to only adjust the gain (between 40 and ++ 80 %) and if that does not help, only then changes exposure. This leads ++ to a much more stable image then using the knee algorithm which at ++ certain points of the knee graph will only try to adjust exposure, ++ which leads to oscilating as one exposure step is huge. ++ ++ Note this assumes that the sd struct for the cam in question has ++ exp_too_high_cnt and exp_too_high_cnt int members for use by this function. ++ ++ Returns 0 if no changes were made, 1 if the gain and or exposure settings ++ where changed. */ ++static int gspca_coarse_grained_expo_autogain(struct gspca_dev *gspca_dev, ++ int avg_lum, int desired_avg_lum, int deadzone) ++{ ++ int i, steps, gain, orig_gain, exposure, orig_exposure; ++ int gain_low, gain_high; ++ const struct ctrl *gain_ctrl = NULL; ++ const struct ctrl *exposure_ctrl = NULL; ++ struct sd *sd = (struct sd *) gspca_dev; ++ int retval = 0; ++ ++ for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { ++ if (gspca_dev->ctrl_dis & (1 << i)) ++ continue; ++ if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN) ++ gain_ctrl = &gspca_dev->sd_desc->ctrls[i]; ++ if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE) ++ exposure_ctrl = &gspca_dev->sd_desc->ctrls[i]; ++ } ++ if (!gain_ctrl || !exposure_ctrl) { ++ PDEBUG(D_ERR, "Error: gspca_coarse_grained_expo_autogain " ++ "called on cam without gain or exposure"); ++ return 0; ++ } ++ ++ if (gain_ctrl->get(gspca_dev, &gain) || ++ exposure_ctrl->get(gspca_dev, &exposure)) ++ return 0; ++ ++ orig_gain = gain; ++ orig_exposure = exposure; ++ gain_low = ++ (gain_ctrl->qctrl.maximum - gain_ctrl->qctrl.minimum) / 5 * 2; ++ gain_low += gain_ctrl->qctrl.minimum; ++ gain_high = ++ (gain_ctrl->qctrl.maximum - gain_ctrl->qctrl.minimum) / 5 * 4; ++ gain_high += gain_ctrl->qctrl.minimum; ++ ++ /* If we are of a multiple of deadzone, do multiple steps to reach the ++ desired lumination fast (with the risc of a slight overshoot) */ ++ steps = (desired_avg_lum - avg_lum) / deadzone; ++ ++ PDEBUG(D_FRAM, "autogain: lum: %d, desired: %d, steps: %d", ++ avg_lum, desired_avg_lum, steps); ++ ++ if ((gain + steps) > gain_high && ++ sd->exposure < exposure_ctrl->qctrl.maximum) { ++ gain = gain_high; ++ sd->exp_too_low_cnt++; ++ } else if ((gain + steps) < gain_low && ++ sd->exposure > exposure_ctrl->qctrl.minimum) { ++ gain = gain_low; ++ sd->exp_too_high_cnt++; ++ } else { ++ gain += steps; ++ if (gain > gain_ctrl->qctrl.maximum) ++ gain = gain_ctrl->qctrl.maximum; ++ else if (gain < gain_ctrl->qctrl.minimum) ++ gain = gain_ctrl->qctrl.minimum; ++ sd->exp_too_high_cnt = 0; ++ sd->exp_too_low_cnt = 0; ++ } ++ ++ if (sd->exp_too_high_cnt > 3) { ++ exposure--; ++ sd->exp_too_high_cnt = 0; ++ } else if (sd->exp_too_low_cnt > 3) { ++ exposure++; ++ sd->exp_too_low_cnt = 0; ++ } ++ ++ if (gain != orig_gain) { ++ gain_ctrl->set(gspca_dev, gain); ++ retval = 1; ++ } ++ if (exposure != orig_exposure) { ++ exposure_ctrl->set(gspca_dev, exposure); ++ retval = 1; ++ } ++ ++ return retval; ++} +diff --git a/drivers/media/video/gspca/conex.c b/drivers/media/video/gspca/conex.c +index c98b5d6..19fe6b2 100644 +--- a/drivers/media/video/gspca/conex.c ++++ b/drivers/media/video/gspca/conex.c +@@ -52,7 +52,7 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -1032,7 +1032,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev, + } + + /* sub-driver description */ +-static struct sd_desc sd_desc = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), +diff --git a/drivers/media/video/gspca/cpia1.c b/drivers/media/video/gspca/cpia1.c +new file mode 100644 +index 0000000..7afdc58 +--- /dev/null ++++ b/drivers/media/video/gspca/cpia1.c +@@ -0,0 +1,2022 @@ ++/* ++ * cpia CPiA (1) gspca driver ++ * ++ * Copyright (C) 2010 Hans de Goede ++ * ++ * This module is adapted from the in kernel v4l1 cpia driver which is : ++ * ++ * (C) Copyright 1999-2000 Peter Pregler ++ * (C) Copyright 1999-2000 Scott J. Bertin ++ * (C) Copyright 1999-2000 Johannes Erdfelt ++ * (C) Copyright 2000 STMicroelectronics ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++#define MODULE_NAME "cpia1" ++ ++#include "gspca.h" ++ ++MODULE_AUTHOR("Hans de Goede "); ++MODULE_DESCRIPTION("Vision CPiA"); ++MODULE_LICENSE("GPL"); ++ ++/* constant value's */ ++#define MAGIC_0 0x19 ++#define MAGIC_1 0x68 ++#define DATA_IN 0xC0 ++#define DATA_OUT 0x40 ++#define VIDEOSIZE_QCIF 0 /* 176x144 */ ++#define VIDEOSIZE_CIF 1 /* 352x288 */ ++#define SUBSAMPLE_420 0 ++#define SUBSAMPLE_422 1 ++#define YUVORDER_YUYV 0 ++#define YUVORDER_UYVY 1 ++#define NOT_COMPRESSED 0 ++#define COMPRESSED 1 ++#define NO_DECIMATION 0 ++#define DECIMATION_ENAB 1 ++#define EOI 0xff /* End Of Image */ ++#define EOL 0xfd /* End Of Line */ ++#define FRAME_HEADER_SIZE 64 ++ ++/* Image grab modes */ ++#define CPIA_GRAB_SINGLE 0 ++#define CPIA_GRAB_CONTINEOUS 1 ++ ++/* Compression parameters */ ++#define CPIA_COMPRESSION_NONE 0 ++#define CPIA_COMPRESSION_AUTO 1 ++#define CPIA_COMPRESSION_MANUAL 2 ++#define CPIA_COMPRESSION_TARGET_QUALITY 0 ++#define CPIA_COMPRESSION_TARGET_FRAMERATE 1 ++ ++/* Return offsets for GetCameraState */ ++#define SYSTEMSTATE 0 ++#define GRABSTATE 1 ++#define STREAMSTATE 2 ++#define FATALERROR 3 ++#define CMDERROR 4 ++#define DEBUGFLAGS 5 ++#define VPSTATUS 6 ++#define ERRORCODE 7 ++ ++/* SystemState */ ++#define UNINITIALISED_STATE 0 ++#define PASS_THROUGH_STATE 1 ++#define LO_POWER_STATE 2 ++#define HI_POWER_STATE 3 ++#define WARM_BOOT_STATE 4 ++ ++/* GrabState */ ++#define GRAB_IDLE 0 ++#define GRAB_ACTIVE 1 ++#define GRAB_DONE 2 ++ ++/* StreamState */ ++#define STREAM_NOT_READY 0 ++#define STREAM_READY 1 ++#define STREAM_OPEN 2 ++#define STREAM_PAUSED 3 ++#define STREAM_FINISHED 4 ++ ++/* Fatal Error, CmdError, and DebugFlags */ ++#define CPIA_FLAG 1 ++#define SYSTEM_FLAG 2 ++#define INT_CTRL_FLAG 4 ++#define PROCESS_FLAG 8 ++#define COM_FLAG 16 ++#define VP_CTRL_FLAG 32 ++#define CAPTURE_FLAG 64 ++#define DEBUG_FLAG 128 ++ ++/* VPStatus */ ++#define VP_STATE_OK 0x00 ++ ++#define VP_STATE_FAILED_VIDEOINIT 0x01 ++#define VP_STATE_FAILED_AECACBINIT 0x02 ++#define VP_STATE_AEC_MAX 0x04 ++#define VP_STATE_ACB_BMAX 0x08 ++ ++#define VP_STATE_ACB_RMIN 0x10 ++#define VP_STATE_ACB_GMIN 0x20 ++#define VP_STATE_ACB_RMAX 0x40 ++#define VP_STATE_ACB_GMAX 0x80 ++ ++/* default (minimum) compensation values */ ++#define COMP_RED 220 ++#define COMP_GREEN1 214 ++#define COMP_GREEN2 COMP_GREEN1 ++#define COMP_BLUE 230 ++ ++/* exposure status */ ++#define EXPOSURE_VERY_LIGHT 0 ++#define EXPOSURE_LIGHT 1 ++#define EXPOSURE_NORMAL 2 ++#define EXPOSURE_DARK 3 ++#define EXPOSURE_VERY_DARK 4 ++ ++#define CPIA_MODULE_CPIA (0 << 5) ++#define CPIA_MODULE_SYSTEM (1 << 5) ++#define CPIA_MODULE_VP_CTRL (5 << 5) ++#define CPIA_MODULE_CAPTURE (6 << 5) ++#define CPIA_MODULE_DEBUG (7 << 5) ++ ++#define INPUT (DATA_IN << 8) ++#define OUTPUT (DATA_OUT << 8) ++ ++#define CPIA_COMMAND_GetCPIAVersion (INPUT | CPIA_MODULE_CPIA | 1) ++#define CPIA_COMMAND_GetPnPID (INPUT | CPIA_MODULE_CPIA | 2) ++#define CPIA_COMMAND_GetCameraStatus (INPUT | CPIA_MODULE_CPIA | 3) ++#define CPIA_COMMAND_GotoHiPower (OUTPUT | CPIA_MODULE_CPIA | 4) ++#define CPIA_COMMAND_GotoLoPower (OUTPUT | CPIA_MODULE_CPIA | 5) ++#define CPIA_COMMAND_GotoSuspend (OUTPUT | CPIA_MODULE_CPIA | 7) ++#define CPIA_COMMAND_GotoPassThrough (OUTPUT | CPIA_MODULE_CPIA | 8) ++#define CPIA_COMMAND_ModifyCameraStatus (OUTPUT | CPIA_MODULE_CPIA | 10) ++ ++#define CPIA_COMMAND_ReadVCRegs (INPUT | CPIA_MODULE_SYSTEM | 1) ++#define CPIA_COMMAND_WriteVCReg (OUTPUT | CPIA_MODULE_SYSTEM | 2) ++#define CPIA_COMMAND_ReadMCPorts (INPUT | CPIA_MODULE_SYSTEM | 3) ++#define CPIA_COMMAND_WriteMCPort (OUTPUT | CPIA_MODULE_SYSTEM | 4) ++#define CPIA_COMMAND_SetBaudRate (OUTPUT | CPIA_MODULE_SYSTEM | 5) ++#define CPIA_COMMAND_SetECPTiming (OUTPUT | CPIA_MODULE_SYSTEM | 6) ++#define CPIA_COMMAND_ReadIDATA (INPUT | CPIA_MODULE_SYSTEM | 7) ++#define CPIA_COMMAND_WriteIDATA (OUTPUT | CPIA_MODULE_SYSTEM | 8) ++#define CPIA_COMMAND_GenericCall (OUTPUT | CPIA_MODULE_SYSTEM | 9) ++#define CPIA_COMMAND_I2CStart (OUTPUT | CPIA_MODULE_SYSTEM | 10) ++#define CPIA_COMMAND_I2CStop (OUTPUT | CPIA_MODULE_SYSTEM | 11) ++#define CPIA_COMMAND_I2CWrite (OUTPUT | CPIA_MODULE_SYSTEM | 12) ++#define CPIA_COMMAND_I2CRead (INPUT | CPIA_MODULE_SYSTEM | 13) ++ ++#define CPIA_COMMAND_GetVPVersion (INPUT | CPIA_MODULE_VP_CTRL | 1) ++#define CPIA_COMMAND_ResetFrameCounter (INPUT | CPIA_MODULE_VP_CTRL | 2) ++#define CPIA_COMMAND_SetColourParams (OUTPUT | CPIA_MODULE_VP_CTRL | 3) ++#define CPIA_COMMAND_SetExposure (OUTPUT | CPIA_MODULE_VP_CTRL | 4) ++#define CPIA_COMMAND_SetColourBalance (OUTPUT | CPIA_MODULE_VP_CTRL | 6) ++#define CPIA_COMMAND_SetSensorFPS (OUTPUT | CPIA_MODULE_VP_CTRL | 7) ++#define CPIA_COMMAND_SetVPDefaults (OUTPUT | CPIA_MODULE_VP_CTRL | 8) ++#define CPIA_COMMAND_SetApcor (OUTPUT | CPIA_MODULE_VP_CTRL | 9) ++#define CPIA_COMMAND_SetFlickerCtrl (OUTPUT | CPIA_MODULE_VP_CTRL | 10) ++#define CPIA_COMMAND_SetVLOffset (OUTPUT | CPIA_MODULE_VP_CTRL | 11) ++#define CPIA_COMMAND_GetColourParams (INPUT | CPIA_MODULE_VP_CTRL | 16) ++#define CPIA_COMMAND_GetColourBalance (INPUT | CPIA_MODULE_VP_CTRL | 17) ++#define CPIA_COMMAND_GetExposure (INPUT | CPIA_MODULE_VP_CTRL | 18) ++#define CPIA_COMMAND_SetSensorMatrix (OUTPUT | CPIA_MODULE_VP_CTRL | 19) ++#define CPIA_COMMAND_ColourBars (OUTPUT | CPIA_MODULE_VP_CTRL | 25) ++#define CPIA_COMMAND_ReadVPRegs (INPUT | CPIA_MODULE_VP_CTRL | 30) ++#define CPIA_COMMAND_WriteVPReg (OUTPUT | CPIA_MODULE_VP_CTRL | 31) ++ ++#define CPIA_COMMAND_GrabFrame (OUTPUT | CPIA_MODULE_CAPTURE | 1) ++#define CPIA_COMMAND_UploadFrame (OUTPUT | CPIA_MODULE_CAPTURE | 2) ++#define CPIA_COMMAND_SetGrabMode (OUTPUT | CPIA_MODULE_CAPTURE | 3) ++#define CPIA_COMMAND_InitStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 4) ++#define CPIA_COMMAND_FiniStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 5) ++#define CPIA_COMMAND_StartStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 6) ++#define CPIA_COMMAND_EndStreamCap (OUTPUT | CPIA_MODULE_CAPTURE | 7) ++#define CPIA_COMMAND_SetFormat (OUTPUT | CPIA_MODULE_CAPTURE | 8) ++#define CPIA_COMMAND_SetROI (OUTPUT | CPIA_MODULE_CAPTURE | 9) ++#define CPIA_COMMAND_SetCompression (OUTPUT | CPIA_MODULE_CAPTURE | 10) ++#define CPIA_COMMAND_SetCompressionTarget (OUTPUT | CPIA_MODULE_CAPTURE | 11) ++#define CPIA_COMMAND_SetYUVThresh (OUTPUT | CPIA_MODULE_CAPTURE | 12) ++#define CPIA_COMMAND_SetCompressionParams (OUTPUT | CPIA_MODULE_CAPTURE | 13) ++#define CPIA_COMMAND_DiscardFrame (OUTPUT | CPIA_MODULE_CAPTURE | 14) ++#define CPIA_COMMAND_GrabReset (OUTPUT | CPIA_MODULE_CAPTURE | 15) ++ ++#define CPIA_COMMAND_OutputRS232 (OUTPUT | CPIA_MODULE_DEBUG | 1) ++#define CPIA_COMMAND_AbortProcess (OUTPUT | CPIA_MODULE_DEBUG | 4) ++#define CPIA_COMMAND_SetDramPage (OUTPUT | CPIA_MODULE_DEBUG | 5) ++#define CPIA_COMMAND_StartDramUpload (OUTPUT | CPIA_MODULE_DEBUG | 6) ++#define CPIA_COMMAND_StartDummyDtream (OUTPUT | CPIA_MODULE_DEBUG | 8) ++#define CPIA_COMMAND_AbortStream (OUTPUT | CPIA_MODULE_DEBUG | 9) ++#define CPIA_COMMAND_DownloadDRAM (OUTPUT | CPIA_MODULE_DEBUG | 10) ++#define CPIA_COMMAND_Null (OUTPUT | CPIA_MODULE_DEBUG | 11) ++ ++#define ROUND_UP_EXP_FOR_FLICKER 15 ++ ++/* Constants for automatic frame rate adjustment */ ++#define MAX_EXP 302 ++#define MAX_EXP_102 255 ++#define LOW_EXP 140 ++#define VERY_LOW_EXP 70 ++#define TC 94 ++#define EXP_ACC_DARK 50 ++#define EXP_ACC_LIGHT 90 ++#define HIGH_COMP_102 160 ++#define MAX_COMP 239 ++#define DARK_TIME 3 ++#define LIGHT_TIME 3 ++ ++#define FIRMWARE_VERSION(x, y) (sd->params.version.firmwareVersion == (x) && \ ++ sd->params.version.firmwareRevision == (y)) ++ ++/* Developer's Guide Table 5 p 3-34 ++ * indexed by [mains][sensorFps.baserate][sensorFps.divisor]*/ ++static u8 flicker_jumps[2][2][4] = ++{ { { 76, 38, 19, 9 }, { 92, 46, 23, 11 } }, ++ { { 64, 32, 16, 8 }, { 76, 38, 19, 9} } ++}; ++ ++struct cam_params { ++ struct { ++ u8 firmwareVersion; ++ u8 firmwareRevision; ++ u8 vcVersion; ++ u8 vcRevision; ++ } version; ++ struct { ++ u16 vendor; ++ u16 product; ++ u16 deviceRevision; ++ } pnpID; ++ struct { ++ u8 vpVersion; ++ u8 vpRevision; ++ u16 cameraHeadID; ++ } vpVersion; ++ struct { ++ u8 systemState; ++ u8 grabState; ++ u8 streamState; ++ u8 fatalError; ++ u8 cmdError; ++ u8 debugFlags; ++ u8 vpStatus; ++ u8 errorCode; ++ } status; ++ struct { ++ u8 brightness; ++ u8 contrast; ++ u8 saturation; ++ } colourParams; ++ struct { ++ u8 gainMode; ++ u8 expMode; ++ u8 compMode; ++ u8 centreWeight; ++ u8 gain; ++ u8 fineExp; ++ u8 coarseExpLo; ++ u8 coarseExpHi; ++ u8 redComp; ++ u8 green1Comp; ++ u8 green2Comp; ++ u8 blueComp; ++ } exposure; ++ struct { ++ u8 balanceMode; ++ u8 redGain; ++ u8 greenGain; ++ u8 blueGain; ++ } colourBalance; ++ struct { ++ u8 divisor; ++ u8 baserate; ++ } sensorFps; ++ struct { ++ u8 gain1; ++ u8 gain2; ++ u8 gain4; ++ u8 gain8; ++ } apcor; ++ struct { ++ u8 disabled; ++ u8 flickerMode; ++ u8 coarseJump; ++ u8 allowableOverExposure; ++ } flickerControl; ++ struct { ++ u8 gain1; ++ u8 gain2; ++ u8 gain4; ++ u8 gain8; ++ } vlOffset; ++ struct { ++ u8 mode; ++ u8 decimation; ++ } compression; ++ struct { ++ u8 frTargeting; ++ u8 targetFR; ++ u8 targetQ; ++ } compressionTarget; ++ struct { ++ u8 yThreshold; ++ u8 uvThreshold; ++ } yuvThreshold; ++ struct { ++ u8 hysteresis; ++ u8 threshMax; ++ u8 smallStep; ++ u8 largeStep; ++ u8 decimationHysteresis; ++ u8 frDiffStepThresh; ++ u8 qDiffStepThresh; ++ u8 decimationThreshMod; ++ } compressionParams; ++ struct { ++ u8 videoSize; /* CIF/QCIF */ ++ u8 subSample; ++ u8 yuvOrder; ++ } format; ++ struct { /* Intel QX3 specific data */ ++ u8 qx3_detected; /* a QX3 is present */ ++ u8 toplight; /* top light lit , R/W */ ++ u8 bottomlight; /* bottom light lit, R/W */ ++ u8 button; /* snapshot button pressed (R/O) */ ++ u8 cradled; /* microscope is in cradle (R/O) */ ++ } qx3; ++ struct { ++ u8 colStart; /* skip first 8*colStart pixels */ ++ u8 colEnd; /* finish at 8*colEnd pixels */ ++ u8 rowStart; /* skip first 4*rowStart lines */ ++ u8 rowEnd; /* finish at 4*rowEnd lines */ ++ } roi; ++ u8 ecpTiming; ++ u8 streamStartLine; ++}; ++ ++/* specific webcam descriptor */ ++struct sd { ++ struct gspca_dev gspca_dev; /* !! must be the first item */ ++ struct cam_params params; /* camera settings */ ++ ++ atomic_t cam_exposure; ++ atomic_t fps; ++ int exposure_count; ++ u8 exposure_status; ++ u8 mainsFreq; /* 0 = 50hz, 1 = 60hz */ ++ u8 first_frame; ++ u8 freq; ++}; ++ ++/* V4L2 controls supported by the driver */ ++static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setcomptarget(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getcomptarget(struct gspca_dev *gspca_dev, __s32 *val); ++ ++static struct ctrl sd_ctrls[] = { ++ { ++ { ++ .id = V4L2_CID_BRIGHTNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Brightness", ++ .minimum = 0, ++ .maximum = 100, ++ .step = 1, ++#define BRIGHTNESS_DEF 50 ++ .default_value = BRIGHTNESS_DEF, ++ .flags = 0, ++ }, ++ .set = sd_setbrightness, ++ .get = sd_getbrightness, ++ }, ++ { ++ { ++ .id = V4L2_CID_CONTRAST, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Contrast", ++ .minimum = 0, ++ .maximum = 96, ++ .step = 8, ++#define CONTRAST_DEF 48 ++ .default_value = CONTRAST_DEF, ++ }, ++ .set = sd_setcontrast, ++ .get = sd_getcontrast, ++ }, ++ { ++ { ++ .id = V4L2_CID_SATURATION, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Saturation", ++ .minimum = 0, ++ .maximum = 100, ++ .step = 1, ++#define SATURATION_DEF 50 ++ .default_value = SATURATION_DEF, ++ }, ++ .set = sd_setsaturation, ++ .get = sd_getsaturation, ++ }, ++ { ++ { ++ .id = V4L2_CID_POWER_LINE_FREQUENCY, ++ .type = V4L2_CTRL_TYPE_MENU, ++ .name = "Light frequency filter", ++ .minimum = 0, ++ .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ ++ .step = 1, ++#define FREQ_DEF 1 ++ .default_value = FREQ_DEF, ++ }, ++ .set = sd_setfreq, ++ .get = sd_getfreq, ++ }, ++ { ++ { ++#define V4L2_CID_COMP_TARGET V4L2_CID_PRIVATE_BASE ++ .id = V4L2_CID_COMP_TARGET, ++ .type = V4L2_CTRL_TYPE_MENU, ++ .name = "Compression Target", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, ++#define COMP_TARGET_DEF CPIA_COMPRESSION_TARGET_QUALITY ++ .default_value = COMP_TARGET_DEF, ++ }, ++ .set = sd_setcomptarget, ++ .get = sd_getcomptarget, ++ }, ++}; ++ ++static const struct v4l2_pix_format mode[] = { ++ {160, 120, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE, ++ /* The sizeimage is trial and error, as with low framerates ++ the camera will pad out usb frames, making the image ++ data larger then strictly necessary */ ++ .bytesperline = 160, ++ .sizeimage = 65536, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 3}, ++ {176, 144, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE, ++ .bytesperline = 172, ++ .sizeimage = 65536, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 2}, ++ {320, 240, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE, ++ .bytesperline = 320, ++ .sizeimage = 262144, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 1}, ++ {352, 288, V4L2_PIX_FMT_CPIA1, V4L2_FIELD_NONE, ++ .bytesperline = 352, ++ .sizeimage = 262144, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 0}, ++}; ++ ++/********************************************************************** ++ * ++ * General functions ++ * ++ **********************************************************************/ ++ ++static int cpia_usb_transferCmd(struct gspca_dev *gspca_dev, u8 *command) ++{ ++ u8 requesttype; ++ unsigned int pipe; ++ int ret, databytes = command[6] | (command[7] << 8); ++ /* Sometimes we see spurious EPIPE errors */ ++ int retries = 3; ++ ++ if (command[0] == DATA_IN) { ++ pipe = usb_rcvctrlpipe(gspca_dev->dev, 0); ++ requesttype = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE; ++ } else if (command[0] == DATA_OUT) { ++ pipe = usb_sndctrlpipe(gspca_dev->dev, 0); ++ requesttype = USB_TYPE_VENDOR | USB_RECIP_DEVICE; ++ } else { ++ PDEBUG(D_ERR, "Unexpected first byte of command: %x", ++ command[0]); ++ return -EINVAL; ++ } ++ ++retry: ++ ret = usb_control_msg(gspca_dev->dev, pipe, ++ command[1], ++ requesttype, ++ command[2] | (command[3] << 8), ++ command[4] | (command[5] << 8), ++ gspca_dev->usb_buf, databytes, 1000); ++ ++ if (ret < 0) ++ PDEBUG(D_ERR, "usb_control_msg %02x, error %d", command[1], ++ ret); ++ ++ if (ret == -EPIPE && retries > 0) { ++ retries--; ++ goto retry; ++ } ++ ++ return (ret < 0) ? ret : 0; ++} ++ ++/* send an arbitrary command to the camera */ ++static int do_command(struct gspca_dev *gspca_dev, u16 command, ++ u8 a, u8 b, u8 c, u8 d) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret, datasize; ++ u8 cmd[8]; ++ ++ switch (command) { ++ case CPIA_COMMAND_GetCPIAVersion: ++ case CPIA_COMMAND_GetPnPID: ++ case CPIA_COMMAND_GetCameraStatus: ++ case CPIA_COMMAND_GetVPVersion: ++ case CPIA_COMMAND_GetColourParams: ++ case CPIA_COMMAND_GetColourBalance: ++ case CPIA_COMMAND_GetExposure: ++ datasize = 8; ++ break; ++ case CPIA_COMMAND_ReadMCPorts: ++ case CPIA_COMMAND_ReadVCRegs: ++ datasize = 4; ++ break; ++ default: ++ datasize = 0; ++ break; ++ } ++ ++ cmd[0] = command >> 8; ++ cmd[1] = command & 0xff; ++ cmd[2] = a; ++ cmd[3] = b; ++ cmd[4] = c; ++ cmd[5] = d; ++ cmd[6] = datasize; ++ cmd[7] = 0; ++ ++ ret = cpia_usb_transferCmd(gspca_dev, cmd); ++ if (ret) ++ return ret; ++ ++ switch (command) { ++ case CPIA_COMMAND_GetCPIAVersion: ++ sd->params.version.firmwareVersion = gspca_dev->usb_buf[0]; ++ sd->params.version.firmwareRevision = gspca_dev->usb_buf[1]; ++ sd->params.version.vcVersion = gspca_dev->usb_buf[2]; ++ sd->params.version.vcRevision = gspca_dev->usb_buf[3]; ++ break; ++ case CPIA_COMMAND_GetPnPID: ++ sd->params.pnpID.vendor = ++ gspca_dev->usb_buf[0] | (gspca_dev->usb_buf[1] << 8); ++ sd->params.pnpID.product = ++ gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8); ++ sd->params.pnpID.deviceRevision = ++ gspca_dev->usb_buf[4] | (gspca_dev->usb_buf[5] << 8); ++ break; ++ case CPIA_COMMAND_GetCameraStatus: ++ sd->params.status.systemState = gspca_dev->usb_buf[0]; ++ sd->params.status.grabState = gspca_dev->usb_buf[1]; ++ sd->params.status.streamState = gspca_dev->usb_buf[2]; ++ sd->params.status.fatalError = gspca_dev->usb_buf[3]; ++ sd->params.status.cmdError = gspca_dev->usb_buf[4]; ++ sd->params.status.debugFlags = gspca_dev->usb_buf[5]; ++ sd->params.status.vpStatus = gspca_dev->usb_buf[6]; ++ sd->params.status.errorCode = gspca_dev->usb_buf[7]; ++ break; ++ case CPIA_COMMAND_GetVPVersion: ++ sd->params.vpVersion.vpVersion = gspca_dev->usb_buf[0]; ++ sd->params.vpVersion.vpRevision = gspca_dev->usb_buf[1]; ++ sd->params.vpVersion.cameraHeadID = ++ gspca_dev->usb_buf[2] | (gspca_dev->usb_buf[3] << 8); ++ break; ++ case CPIA_COMMAND_GetColourParams: ++ sd->params.colourParams.brightness = gspca_dev->usb_buf[0]; ++ sd->params.colourParams.contrast = gspca_dev->usb_buf[1]; ++ sd->params.colourParams.saturation = gspca_dev->usb_buf[2]; ++ break; ++ case CPIA_COMMAND_GetColourBalance: ++ sd->params.colourBalance.redGain = gspca_dev->usb_buf[0]; ++ sd->params.colourBalance.greenGain = gspca_dev->usb_buf[1]; ++ sd->params.colourBalance.blueGain = gspca_dev->usb_buf[2]; ++ break; ++ case CPIA_COMMAND_GetExposure: ++ sd->params.exposure.gain = gspca_dev->usb_buf[0]; ++ sd->params.exposure.fineExp = gspca_dev->usb_buf[1]; ++ sd->params.exposure.coarseExpLo = gspca_dev->usb_buf[2]; ++ sd->params.exposure.coarseExpHi = gspca_dev->usb_buf[3]; ++ sd->params.exposure.redComp = gspca_dev->usb_buf[4]; ++ sd->params.exposure.green1Comp = gspca_dev->usb_buf[5]; ++ sd->params.exposure.green2Comp = gspca_dev->usb_buf[6]; ++ sd->params.exposure.blueComp = gspca_dev->usb_buf[7]; ++ break; ++ ++ case CPIA_COMMAND_ReadMCPorts: ++ if (!sd->params.qx3.qx3_detected) ++ break; ++ /* test button press */ ++ sd->params.qx3.button = ((gspca_dev->usb_buf[1] & 0x02) == 0); ++ if (sd->params.qx3.button) { ++ /* button pressed - unlock the latch */ ++ do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, ++ 3, 0xDF, 0xDF, 0); ++ do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, ++ 3, 0xFF, 0xFF, 0); ++ } ++ ++ /* test whether microscope is cradled */ ++ sd->params.qx3.cradled = ((gspca_dev->usb_buf[2] & 0x40) == 0); ++ break; ++ } ++ ++ return 0; ++} ++ ++/* send a command to the camera with an additional data transaction */ ++static int do_command_extended(struct gspca_dev *gspca_dev, u16 command, ++ u8 a, u8 b, u8 c, u8 d, ++ u8 e, u8 f, u8 g, u8 h, ++ u8 i, u8 j, u8 k, u8 l) ++{ ++ u8 cmd[8]; ++ ++ cmd[0] = command >> 8; ++ cmd[1] = command & 0xff; ++ cmd[2] = a; ++ cmd[3] = b; ++ cmd[4] = c; ++ cmd[5] = d; ++ cmd[6] = 8; ++ cmd[7] = 0; ++ gspca_dev->usb_buf[0] = e; ++ gspca_dev->usb_buf[1] = f; ++ gspca_dev->usb_buf[2] = g; ++ gspca_dev->usb_buf[3] = h; ++ gspca_dev->usb_buf[4] = i; ++ gspca_dev->usb_buf[5] = j; ++ gspca_dev->usb_buf[6] = k; ++ gspca_dev->usb_buf[7] = l; ++ ++ return cpia_usb_transferCmd(gspca_dev, cmd); ++} ++ ++/* find_over_exposure ++ * Finds a suitable value of OverExposure for use with SetFlickerCtrl ++ * Some calculation is required because this value changes with the brightness ++ * set with SetColourParameters ++ * ++ * Parameters: Brightness - last brightness value set with SetColourParameters ++ * ++ * Returns: OverExposure value to use with SetFlickerCtrl ++ */ ++#define FLICKER_MAX_EXPOSURE 250 ++#define FLICKER_ALLOWABLE_OVER_EXPOSURE 146 ++#define FLICKER_BRIGHTNESS_CONSTANT 59 ++static int find_over_exposure(int brightness) ++{ ++ int MaxAllowableOverExposure, OverExposure; ++ ++ MaxAllowableOverExposure = FLICKER_MAX_EXPOSURE - brightness - ++ FLICKER_BRIGHTNESS_CONSTANT; ++ ++ if (MaxAllowableOverExposure < FLICKER_ALLOWABLE_OVER_EXPOSURE) ++ OverExposure = MaxAllowableOverExposure; ++ else ++ OverExposure = FLICKER_ALLOWABLE_OVER_EXPOSURE; ++ ++ return OverExposure; ++} ++#undef FLICKER_MAX_EXPOSURE ++#undef FLICKER_ALLOWABLE_OVER_EXPOSURE ++#undef FLICKER_BRIGHTNESS_CONSTANT ++ ++/* initialise cam_data structure */ ++static void reset_camera_params(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ struct cam_params *params = &sd->params; ++ ++ /* The following parameter values are the defaults from ++ * "Software Developer's Guide for CPiA Cameras". Any changes ++ * to the defaults are noted in comments. */ ++ params->colourParams.brightness = BRIGHTNESS_DEF; ++ params->colourParams.contrast = CONTRAST_DEF; ++ params->colourParams.saturation = SATURATION_DEF; ++ params->exposure.gainMode = 4; ++ params->exposure.expMode = 2; /* AEC */ ++ params->exposure.compMode = 1; ++ params->exposure.centreWeight = 1; ++ params->exposure.gain = 0; ++ params->exposure.fineExp = 0; ++ params->exposure.coarseExpLo = 185; ++ params->exposure.coarseExpHi = 0; ++ params->exposure.redComp = COMP_RED; ++ params->exposure.green1Comp = COMP_GREEN1; ++ params->exposure.green2Comp = COMP_GREEN2; ++ params->exposure.blueComp = COMP_BLUE; ++ params->colourBalance.balanceMode = 2; /* ACB */ ++ params->colourBalance.redGain = 32; ++ params->colourBalance.greenGain = 6; ++ params->colourBalance.blueGain = 92; ++ params->apcor.gain1 = 0x18; ++ params->apcor.gain2 = 0x16; ++ params->apcor.gain4 = 0x24; ++ params->apcor.gain8 = 0x34; ++ params->flickerControl.flickerMode = 0; ++ params->flickerControl.disabled = 1; ++ ++ params->flickerControl.coarseJump = ++ flicker_jumps[sd->mainsFreq] ++ [params->sensorFps.baserate] ++ [params->sensorFps.divisor]; ++ params->flickerControl.allowableOverExposure = ++ find_over_exposure(params->colourParams.brightness); ++ params->vlOffset.gain1 = 20; ++ params->vlOffset.gain2 = 24; ++ params->vlOffset.gain4 = 26; ++ params->vlOffset.gain8 = 26; ++ params->compressionParams.hysteresis = 3; ++ params->compressionParams.threshMax = 11; ++ params->compressionParams.smallStep = 1; ++ params->compressionParams.largeStep = 3; ++ params->compressionParams.decimationHysteresis = 2; ++ params->compressionParams.frDiffStepThresh = 5; ++ params->compressionParams.qDiffStepThresh = 3; ++ params->compressionParams.decimationThreshMod = 2; ++ /* End of default values from Software Developer's Guide */ ++ ++ /* Set Sensor FPS to 15fps. This seems better than 30fps ++ * for indoor lighting. */ ++ params->sensorFps.divisor = 1; ++ params->sensorFps.baserate = 1; ++ ++ params->yuvThreshold.yThreshold = 6; /* From windows driver */ ++ params->yuvThreshold.uvThreshold = 6; /* From windows driver */ ++ ++ params->format.subSample = SUBSAMPLE_420; ++ params->format.yuvOrder = YUVORDER_YUYV; ++ ++ params->compression.mode = CPIA_COMPRESSION_AUTO; ++ params->compression.decimation = NO_DECIMATION; ++ ++ params->compressionTarget.frTargeting = COMP_TARGET_DEF; ++ params->compressionTarget.targetFR = 15; /* From windows driver */ ++ params->compressionTarget.targetQ = 5; /* From windows driver */ ++ ++ params->qx3.qx3_detected = 0; ++ params->qx3.toplight = 0; ++ params->qx3.bottomlight = 0; ++ params->qx3.button = 0; ++ params->qx3.cradled = 0; ++} ++ ++static void printstatus(struct cam_params *params) ++{ ++ PDEBUG(D_PROBE, "status: %02x %02x %02x %02x %02x %02x %02x %02x", ++ params->status.systemState, params->status.grabState, ++ params->status.streamState, params->status.fatalError, ++ params->status.cmdError, params->status.debugFlags, ++ params->status.vpStatus, params->status.errorCode); ++} ++ ++static int goto_low_power(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_GotoLoPower, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ if (sd->params.status.systemState != LO_POWER_STATE) { ++ if (sd->params.status.systemState != WARM_BOOT_STATE) { ++ PDEBUG(D_ERR, ++ "unexpected state after lo power cmd: %02x", ++ sd->params.status.systemState); ++ printstatus(&sd->params); ++ } ++ return -EIO; ++ } ++ ++ PDEBUG(D_CONF, "camera now in LOW power state"); ++ return 0; ++} ++ ++static int goto_high_power(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_GotoHiPower, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ msleep_interruptible(40); /* windows driver does it too */ ++ ++ if (signal_pending(current)) ++ return -EINTR; ++ ++ do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ if (sd->params.status.systemState != HI_POWER_STATE) { ++ PDEBUG(D_ERR, "unexpected state after hi power cmd: %02x", ++ sd->params.status.systemState); ++ printstatus(&sd->params); ++ return -EIO; ++ } ++ ++ PDEBUG(D_CONF, "camera now in HIGH power state"); ++ return 0; ++} ++ ++static int get_version_information(struct gspca_dev *gspca_dev) ++{ ++ int ret; ++ ++ /* GetCPIAVersion */ ++ ret = do_command(gspca_dev, CPIA_COMMAND_GetCPIAVersion, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ /* GetPnPID */ ++ return do_command(gspca_dev, CPIA_COMMAND_GetPnPID, 0, 0, 0, 0); ++} ++ ++static int save_camera_state(struct gspca_dev *gspca_dev) ++{ ++ int ret; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_GetColourBalance, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0); ++} ++ ++int command_setformat(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_SetFormat, ++ sd->params.format.videoSize, ++ sd->params.format.subSample, ++ sd->params.format.yuvOrder, 0); ++ if (ret) ++ return ret; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetROI, ++ sd->params.roi.colStart, sd->params.roi.colEnd, ++ sd->params.roi.rowStart, sd->params.roi.rowEnd); ++} ++ ++int command_setcolourparams(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ return do_command(gspca_dev, CPIA_COMMAND_SetColourParams, ++ sd->params.colourParams.brightness, ++ sd->params.colourParams.contrast, ++ sd->params.colourParams.saturation, 0); ++} ++ ++int command_setapcor(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ return do_command(gspca_dev, CPIA_COMMAND_SetApcor, ++ sd->params.apcor.gain1, ++ sd->params.apcor.gain2, ++ sd->params.apcor.gain4, ++ sd->params.apcor.gain8); ++} ++ ++int command_setvloffset(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ return do_command(gspca_dev, CPIA_COMMAND_SetVLOffset, ++ sd->params.vlOffset.gain1, ++ sd->params.vlOffset.gain2, ++ sd->params.vlOffset.gain4, ++ sd->params.vlOffset.gain8); ++} ++ ++int command_setexposure(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret; ++ ++ ret = do_command_extended(gspca_dev, CPIA_COMMAND_SetExposure, ++ sd->params.exposure.gainMode, ++ 1, ++ sd->params.exposure.compMode, ++ sd->params.exposure.centreWeight, ++ sd->params.exposure.gain, ++ sd->params.exposure.fineExp, ++ sd->params.exposure.coarseExpLo, ++ sd->params.exposure.coarseExpHi, ++ sd->params.exposure.redComp, ++ sd->params.exposure.green1Comp, ++ sd->params.exposure.green2Comp, ++ sd->params.exposure.blueComp); ++ if (ret) ++ return ret; ++ ++ if (sd->params.exposure.expMode != 1) { ++ ret = do_command_extended(gspca_dev, CPIA_COMMAND_SetExposure, ++ 0, ++ sd->params.exposure.expMode, ++ 0, 0, ++ sd->params.exposure.gain, ++ sd->params.exposure.fineExp, ++ sd->params.exposure.coarseExpLo, ++ sd->params.exposure.coarseExpHi, ++ 0, 0, 0, 0); ++ } ++ ++ return ret; ++} ++ ++int command_setcolourbalance(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (sd->params.colourBalance.balanceMode == 1) { ++ int ret; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_SetColourBalance, ++ 1, ++ sd->params.colourBalance.redGain, ++ sd->params.colourBalance.greenGain, ++ sd->params.colourBalance.blueGain); ++ if (ret) ++ return ret; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetColourBalance, ++ 3, 0, 0, 0); ++ } ++ if (sd->params.colourBalance.balanceMode == 2) { ++ return do_command(gspca_dev, CPIA_COMMAND_SetColourBalance, ++ 2, 0, 0, 0); ++ } ++ if (sd->params.colourBalance.balanceMode == 3) { ++ return do_command(gspca_dev, CPIA_COMMAND_SetColourBalance, ++ 3, 0, 0, 0); ++ } ++ ++ return -EINVAL; ++} ++ ++int command_setcompressiontarget(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetCompressionTarget, ++ sd->params.compressionTarget.frTargeting, ++ sd->params.compressionTarget.targetFR, ++ sd->params.compressionTarget.targetQ, 0); ++} ++ ++int command_setyuvtresh(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetYUVThresh, ++ sd->params.yuvThreshold.yThreshold, ++ sd->params.yuvThreshold.uvThreshold, 0, 0); ++} ++ ++int command_setcompressionparams(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command_extended(gspca_dev, ++ CPIA_COMMAND_SetCompressionParams, ++ 0, 0, 0, 0, ++ sd->params.compressionParams.hysteresis, ++ sd->params.compressionParams.threshMax, ++ sd->params.compressionParams.smallStep, ++ sd->params.compressionParams.largeStep, ++ sd->params.compressionParams.decimationHysteresis, ++ sd->params.compressionParams.frDiffStepThresh, ++ sd->params.compressionParams.qDiffStepThresh, ++ sd->params.compressionParams.decimationThreshMod); ++} ++ ++int command_setcompression(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetCompression, ++ sd->params.compression.mode, ++ sd->params.compression.decimation, 0, 0); ++} ++ ++int command_setsensorfps(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetSensorFPS, ++ sd->params.sensorFps.divisor, ++ sd->params.sensorFps.baserate, 0, 0); ++} ++ ++int command_setflickerctrl(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetFlickerCtrl, ++ sd->params.flickerControl.flickerMode, ++ sd->params.flickerControl.coarseJump, ++ sd->params.flickerControl.allowableOverExposure, ++ 0); ++} ++ ++int command_setecptiming(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_SetECPTiming, ++ sd->params.ecpTiming, 0, 0, 0); ++} ++ ++int command_pause(struct gspca_dev *gspca_dev) ++{ ++ return do_command(gspca_dev, CPIA_COMMAND_EndStreamCap, 0, 0, 0, 0); ++} ++ ++int command_resume(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_InitStreamCap, ++ 0, sd->params.streamStartLine, 0, 0); ++} ++ ++int command_setlights(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret, p1, p2; ++ ++ if (!sd->params.qx3.qx3_detected) ++ return 0; ++ ++ p1 = (sd->params.qx3.bottomlight == 0) << 1; ++ p2 = (sd->params.qx3.toplight == 0) << 3; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_WriteVCReg, ++ 0x90, 0x8F, 0x50, 0); ++ if (ret) ++ return ret; ++ ++ return do_command(gspca_dev, CPIA_COMMAND_WriteMCPort, 2, 0, ++ p1 | p2 | 0xE0, 0); ++} ++ ++static int set_flicker(struct gspca_dev *gspca_dev, int on, int apply) ++{ ++ /* Everything in here is from the Windows driver */ ++/* define for compgain calculation */ ++#if 0 /* keep */ ++#define COMPGAIN(base, curexp, newexp) \ ++ (u8) ((((float) base - 128.0) * ((float) curexp / (float) newexp)) + 128.5) ++#define EXP_FROM_COMP(basecomp, curcomp, curexp) \ ++ (u16)((float)curexp * (float)(u8)(curcomp + 128) / \ ++ (float)(u8)(basecomp - 128)) ++#else ++ /* equivalent functions without floating point math */ ++#define COMPGAIN(base, curexp, newexp) \ ++ (u8)(128 + (((u32)(2*(base-128)*curexp + newexp)) / (2 * newexp))) ++#define EXP_FROM_COMP(basecomp, curcomp, curexp) \ ++ (u16)(((u32)(curexp * (u8)(curcomp + 128)) / (u8)(basecomp - 128))) ++#endif ++ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int currentexp = sd->params.exposure.coarseExpLo + ++ sd->params.exposure.coarseExpHi * 256; ++ int ret, startexp; ++ ++ if (on) { ++ int cj = sd->params.flickerControl.coarseJump; ++ sd->params.flickerControl.flickerMode = 1; ++ sd->params.flickerControl.disabled = 0; ++ if (sd->params.exposure.expMode != 2) { ++ sd->params.exposure.expMode = 2; ++ sd->exposure_status = EXPOSURE_NORMAL; ++ } ++ currentexp = currentexp << sd->params.exposure.gain; ++ sd->params.exposure.gain = 0; ++ /* round down current exposure to nearest value */ ++ startexp = (currentexp + ROUND_UP_EXP_FOR_FLICKER) / cj; ++ if (startexp < 1) ++ startexp = 1; ++ startexp = (startexp * cj) - 1; ++ if (FIRMWARE_VERSION(1, 2)) ++ while (startexp > MAX_EXP_102) ++ startexp -= cj; ++ else ++ while (startexp > MAX_EXP) ++ startexp -= cj; ++ sd->params.exposure.coarseExpLo = startexp & 0xff; ++ sd->params.exposure.coarseExpHi = startexp >> 8; ++ if (currentexp > startexp) { ++ if (currentexp > (2 * startexp)) ++ currentexp = 2 * startexp; ++ sd->params.exposure.redComp = ++ COMPGAIN(COMP_RED, currentexp, startexp); ++ sd->params.exposure.green1Comp = ++ COMPGAIN(COMP_GREEN1, currentexp, startexp); ++ sd->params.exposure.green2Comp = ++ COMPGAIN(COMP_GREEN2, currentexp, startexp); ++ sd->params.exposure.blueComp = ++ COMPGAIN(COMP_BLUE, currentexp, startexp); ++ } else { ++ sd->params.exposure.redComp = COMP_RED; ++ sd->params.exposure.green1Comp = COMP_GREEN1; ++ sd->params.exposure.green2Comp = COMP_GREEN2; ++ sd->params.exposure.blueComp = COMP_BLUE; ++ } ++ if (FIRMWARE_VERSION(1, 2)) ++ sd->params.exposure.compMode = 0; ++ else ++ sd->params.exposure.compMode = 1; ++ ++ sd->params.apcor.gain1 = 0x18; ++ sd->params.apcor.gain2 = 0x18; ++ sd->params.apcor.gain4 = 0x16; ++ sd->params.apcor.gain8 = 0x14; ++ } else { ++ sd->params.flickerControl.flickerMode = 0; ++ sd->params.flickerControl.disabled = 1; ++ /* Average equivalent coarse for each comp channel */ ++ startexp = EXP_FROM_COMP(COMP_RED, ++ sd->params.exposure.redComp, currentexp); ++ startexp += EXP_FROM_COMP(COMP_GREEN1, ++ sd->params.exposure.green1Comp, currentexp); ++ startexp += EXP_FROM_COMP(COMP_GREEN2, ++ sd->params.exposure.green2Comp, currentexp); ++ startexp += EXP_FROM_COMP(COMP_BLUE, ++ sd->params.exposure.blueComp, currentexp); ++ startexp = startexp >> 2; ++ while (startexp > MAX_EXP && sd->params.exposure.gain < ++ sd->params.exposure.gainMode - 1) { ++ startexp = startexp >> 1; ++ ++sd->params.exposure.gain; ++ } ++ if (FIRMWARE_VERSION(1, 2) && startexp > MAX_EXP_102) ++ startexp = MAX_EXP_102; ++ if (startexp > MAX_EXP) ++ startexp = MAX_EXP; ++ sd->params.exposure.coarseExpLo = startexp & 0xff; ++ sd->params.exposure.coarseExpHi = startexp >> 8; ++ sd->params.exposure.redComp = COMP_RED; ++ sd->params.exposure.green1Comp = COMP_GREEN1; ++ sd->params.exposure.green2Comp = COMP_GREEN2; ++ sd->params.exposure.blueComp = COMP_BLUE; ++ sd->params.exposure.compMode = 1; ++ sd->params.apcor.gain1 = 0x18; ++ sd->params.apcor.gain2 = 0x16; ++ sd->params.apcor.gain4 = 0x24; ++ sd->params.apcor.gain8 = 0x34; ++ } ++ sd->params.vlOffset.gain1 = 20; ++ sd->params.vlOffset.gain2 = 24; ++ sd->params.vlOffset.gain4 = 26; ++ sd->params.vlOffset.gain8 = 26; ++ ++ if (apply) { ++ ret = command_setexposure(gspca_dev); ++ if (ret) ++ return ret; ++ ++ ret = command_setapcor(gspca_dev); ++ if (ret) ++ return ret; ++ ++ ret = command_setvloffset(gspca_dev); ++ if (ret) ++ return ret; ++ ++ ret = command_setflickerctrl(gspca_dev); ++ if (ret) ++ return ret; ++ } ++ ++ return 0; ++#undef EXP_FROM_COMP ++#undef COMPGAIN ++} ++ ++/* monitor the exposure and adjust the sensor frame rate if needed */ ++static void monitor_exposure(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 exp_acc, bcomp, gain, coarseL, cmd[8]; ++ int ret, light_exp, dark_exp, very_dark_exp; ++ int old_exposure, new_exposure, framerate; ++ int setfps = 0, setexp = 0, setflicker = 0; ++ ++ /* get necessary stats and register settings from camera */ ++ /* do_command can't handle this, so do it ourselves */ ++ cmd[0] = CPIA_COMMAND_ReadVPRegs >> 8; ++ cmd[1] = CPIA_COMMAND_ReadVPRegs & 0xff; ++ cmd[2] = 30; ++ cmd[3] = 4; ++ cmd[4] = 9; ++ cmd[5] = 8; ++ cmd[6] = 8; ++ cmd[7] = 0; ++ ret = cpia_usb_transferCmd(gspca_dev, cmd); ++ if (ret) { ++ PDEBUG(D_ERR, "ReadVPRegs(30,4,9,8) - failed: %d", ret); ++ return; ++ } ++ exp_acc = gspca_dev->usb_buf[0]; ++ bcomp = gspca_dev->usb_buf[1]; ++ gain = gspca_dev->usb_buf[2]; ++ coarseL = gspca_dev->usb_buf[3]; ++ ++ light_exp = sd->params.colourParams.brightness + ++ TC - 50 + EXP_ACC_LIGHT; ++ if (light_exp > 255) ++ light_exp = 255; ++ dark_exp = sd->params.colourParams.brightness + ++ TC - 50 - EXP_ACC_DARK; ++ if (dark_exp < 0) ++ dark_exp = 0; ++ very_dark_exp = dark_exp / 2; ++ ++ old_exposure = sd->params.exposure.coarseExpHi * 256 + ++ sd->params.exposure.coarseExpLo; ++ ++ if (!sd->params.flickerControl.disabled) { ++ /* Flicker control on */ ++ int max_comp = FIRMWARE_VERSION(1, 2) ? MAX_COMP : ++ HIGH_COMP_102; ++ bcomp += 128; /* decode */ ++ if (bcomp >= max_comp && exp_acc < dark_exp) { ++ /* dark */ ++ if (exp_acc < very_dark_exp) { ++ /* very dark */ ++ if (sd->exposure_status == EXPOSURE_VERY_DARK) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = ++ EXPOSURE_VERY_DARK; ++ sd->exposure_count = 1; ++ } ++ } else { ++ /* just dark */ ++ if (sd->exposure_status == EXPOSURE_DARK) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = EXPOSURE_DARK; ++ sd->exposure_count = 1; ++ } ++ } ++ } else if (old_exposure <= LOW_EXP || exp_acc > light_exp) { ++ /* light */ ++ if (old_exposure <= VERY_LOW_EXP) { ++ /* very light */ ++ if (sd->exposure_status == EXPOSURE_VERY_LIGHT) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = ++ EXPOSURE_VERY_LIGHT; ++ sd->exposure_count = 1; ++ } ++ } else { ++ /* just light */ ++ if (sd->exposure_status == EXPOSURE_LIGHT) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = EXPOSURE_LIGHT; ++ sd->exposure_count = 1; ++ } ++ } ++ } else { ++ /* not dark or light */ ++ sd->exposure_status = EXPOSURE_NORMAL; ++ } ++ } else { ++ /* Flicker control off */ ++ if (old_exposure >= MAX_EXP && exp_acc < dark_exp) { ++ /* dark */ ++ if (exp_acc < very_dark_exp) { ++ /* very dark */ ++ if (sd->exposure_status == EXPOSURE_VERY_DARK) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = ++ EXPOSURE_VERY_DARK; ++ sd->exposure_count = 1; ++ } ++ } else { ++ /* just dark */ ++ if (sd->exposure_status == EXPOSURE_DARK) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = EXPOSURE_DARK; ++ sd->exposure_count = 1; ++ } ++ } ++ } else if (old_exposure <= LOW_EXP || exp_acc > light_exp) { ++ /* light */ ++ if (old_exposure <= VERY_LOW_EXP) { ++ /* very light */ ++ if (sd->exposure_status == EXPOSURE_VERY_LIGHT) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = ++ EXPOSURE_VERY_LIGHT; ++ sd->exposure_count = 1; ++ } ++ } else { ++ /* just light */ ++ if (sd->exposure_status == EXPOSURE_LIGHT) ++ ++sd->exposure_count; ++ else { ++ sd->exposure_status = EXPOSURE_LIGHT; ++ sd->exposure_count = 1; ++ } ++ } ++ } else { ++ /* not dark or light */ ++ sd->exposure_status = EXPOSURE_NORMAL; ++ } ++ } ++ ++ framerate = atomic_read(&sd->fps); ++ if (framerate > 30 || framerate < 1) ++ framerate = 1; ++ ++ if (!sd->params.flickerControl.disabled) { ++ /* Flicker control on */ ++ if ((sd->exposure_status == EXPOSURE_VERY_DARK || ++ sd->exposure_status == EXPOSURE_DARK) && ++ sd->exposure_count >= DARK_TIME * framerate && ++ sd->params.sensorFps.divisor < 3) { ++ ++ /* dark for too long */ ++ ++sd->params.sensorFps.divisor; ++ setfps = 1; ++ ++ sd->params.flickerControl.coarseJump = ++ flicker_jumps[sd->mainsFreq] ++ [sd->params.sensorFps.baserate] ++ [sd->params.sensorFps.divisor]; ++ setflicker = 1; ++ ++ new_exposure = sd->params.flickerControl.coarseJump-1; ++ while (new_exposure < old_exposure / 2) ++ new_exposure += ++ sd->params.flickerControl.coarseJump; ++ sd->params.exposure.coarseExpLo = new_exposure & 0xff; ++ sd->params.exposure.coarseExpHi = new_exposure >> 8; ++ setexp = 1; ++ sd->exposure_status = EXPOSURE_NORMAL; ++ PDEBUG(D_CONF, "Automatically decreasing sensor_fps"); ++ ++ } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || ++ sd->exposure_status == EXPOSURE_LIGHT) && ++ sd->exposure_count >= LIGHT_TIME * framerate && ++ sd->params.sensorFps.divisor > 0) { ++ ++ /* light for too long */ ++ int max_exp = FIRMWARE_VERSION(1, 2) ? MAX_EXP_102 : ++ MAX_EXP; ++ --sd->params.sensorFps.divisor; ++ setfps = 1; ++ ++ sd->params.flickerControl.coarseJump = ++ flicker_jumps[sd->mainsFreq] ++ [sd->params.sensorFps.baserate] ++ [sd->params.sensorFps.divisor]; ++ setflicker = 1; ++ ++ new_exposure = sd->params.flickerControl.coarseJump-1; ++ while (new_exposure < 2 * old_exposure && ++ new_exposure + ++ sd->params.flickerControl.coarseJump < max_exp) ++ new_exposure += ++ sd->params.flickerControl.coarseJump; ++ sd->params.exposure.coarseExpLo = new_exposure & 0xff; ++ sd->params.exposure.coarseExpHi = new_exposure >> 8; ++ setexp = 1; ++ sd->exposure_status = EXPOSURE_NORMAL; ++ PDEBUG(D_CONF, "Automatically increasing sensor_fps"); ++ } ++ } else { ++ /* Flicker control off */ ++ if ((sd->exposure_status == EXPOSURE_VERY_DARK || ++ sd->exposure_status == EXPOSURE_DARK) && ++ sd->exposure_count >= DARK_TIME * framerate && ++ sd->params.sensorFps.divisor < 3) { ++ ++ /* dark for too long */ ++ ++sd->params.sensorFps.divisor; ++ setfps = 1; ++ ++ if (sd->params.exposure.gain > 0) { ++ --sd->params.exposure.gain; ++ setexp = 1; ++ } ++ sd->exposure_status = EXPOSURE_NORMAL; ++ PDEBUG(D_CONF, "Automatically decreasing sensor_fps"); ++ ++ } else if ((sd->exposure_status == EXPOSURE_VERY_LIGHT || ++ sd->exposure_status == EXPOSURE_LIGHT) && ++ sd->exposure_count >= LIGHT_TIME * framerate && ++ sd->params.sensorFps.divisor > 0) { ++ ++ /* light for too long */ ++ --sd->params.sensorFps.divisor; ++ setfps = 1; ++ ++ if (sd->params.exposure.gain < ++ sd->params.exposure.gainMode - 1) { ++ ++sd->params.exposure.gain; ++ setexp = 1; ++ } ++ sd->exposure_status = EXPOSURE_NORMAL; ++ PDEBUG(D_CONF, "Automatically increasing sensor_fps"); ++ } ++ } ++ ++ if (setexp) ++ command_setexposure(gspca_dev); ++ ++ if (setfps) ++ command_setsensorfps(gspca_dev); ++ ++ if (setflicker) ++ command_setflickerctrl(gspca_dev); ++} ++ ++/*-----------------------------------------------------------------*/ ++/* if flicker is switched off, this function switches it back on.It checks, ++ however, that conditions are suitable before restarting it. ++ This should only be called for firmware version 1.2. ++ ++ It also adjust the colour balance when an exposure step is detected - as ++ long as flicker is running ++*/ ++static void restart_flicker(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int cam_exposure, old_exp; ++ ++ if (!FIRMWARE_VERSION(1, 2)) ++ return; ++ ++ cam_exposure = atomic_read(&sd->cam_exposure); ++ ++ if (sd->params.flickerControl.flickerMode == 0 || ++ cam_exposure == 0) ++ return; ++ ++ old_exp = sd->params.exposure.coarseExpLo + ++ sd->params.exposure.coarseExpHi*256; ++ /* ++ see how far away camera exposure is from a valid ++ flicker exposure value ++ */ ++ cam_exposure %= sd->params.flickerControl.coarseJump; ++ if (!sd->params.flickerControl.disabled && ++ cam_exposure <= sd->params.flickerControl.coarseJump - 3) { ++ /* Flicker control auto-disabled */ ++ sd->params.flickerControl.disabled = 1; ++ } ++ ++ if (sd->params.flickerControl.disabled && ++ old_exp > sd->params.flickerControl.coarseJump + ++ ROUND_UP_EXP_FOR_FLICKER) { ++ /* exposure is now high enough to switch ++ flicker control back on */ ++ set_flicker(gspca_dev, 1, 1); ++ } ++} ++ ++/* this function is called at probe time */ ++static int sd_config(struct gspca_dev *gspca_dev, ++ const struct usb_device_id *id) ++{ ++ struct cam *cam; ++ ++ reset_camera_params(gspca_dev); ++ ++ PDEBUG(D_PROBE, "cpia CPiA camera detected (vid/pid 0x%04X:0x%04X)", ++ id->idVendor, id->idProduct); ++ ++ cam = &gspca_dev->cam; ++ cam->cam_mode = mode; ++ cam->nmodes = ARRAY_SIZE(mode); ++ ++ sd_setfreq(gspca_dev, FREQ_DEF); ++ ++ return 0; ++} ++ ++/* -- start the camera -- */ ++static int sd_start(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int priv, ret; ++ ++ /* Start the camera in low power mode */ ++ if (goto_low_power(gspca_dev)) { ++ if (sd->params.status.systemState != WARM_BOOT_STATE) { ++ PDEBUG(D_ERR, "unexpected systemstate: %02x", ++ sd->params.status.systemState); ++ printstatus(&sd->params); ++ return -ENODEV; ++ } ++ ++ /* FIXME: this is just dirty trial and error */ ++ ret = goto_high_power(gspca_dev); ++ if (ret) ++ return ret; ++ ++ ret = do_command(gspca_dev, CPIA_COMMAND_DiscardFrame, ++ 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ ret = goto_low_power(gspca_dev); ++ if (ret) ++ return ret; ++ } ++ ++ /* procedure described in developer's guide p3-28 */ ++ ++ /* Check the firmware version. */ ++ sd->params.version.firmwareVersion = 0; ++ get_version_information(gspca_dev); ++ if (sd->params.version.firmwareVersion != 1) { ++ PDEBUG(D_ERR, "only firmware version 1 is supported (got: %d)", ++ sd->params.version.firmwareVersion); ++ return -ENODEV; ++ } ++ ++ /* A bug in firmware 1-02 limits gainMode to 2 */ ++ if (sd->params.version.firmwareRevision <= 2 && ++ sd->params.exposure.gainMode > 2) { ++ sd->params.exposure.gainMode = 2; ++ } ++ ++ /* set QX3 detected flag */ ++ sd->params.qx3.qx3_detected = (sd->params.pnpID.vendor == 0x0813 && ++ sd->params.pnpID.product == 0x0001); ++ ++ /* The fatal error checking should be done after ++ * the camera powers up (developer's guide p 3-38) */ ++ ++ /* Set streamState before transition to high power to avoid bug ++ * in firmware 1-02 */ ++ ret = do_command(gspca_dev, CPIA_COMMAND_ModifyCameraStatus, ++ STREAMSTATE, 0, STREAM_NOT_READY, 0); ++ if (ret) ++ return ret; ++ ++ /* GotoHiPower */ ++ ret = goto_high_power(gspca_dev); ++ if (ret) ++ return ret; ++ ++ /* Check the camera status */ ++ ret = do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ if (sd->params.status.fatalError) { ++ PDEBUG(D_ERR, "fatal_error: %04x, vp_status: %04x", ++ sd->params.status.fatalError, ++ sd->params.status.vpStatus); ++ return -EIO; ++ } ++ ++ /* VPVersion can't be retrieved before the camera is in HiPower, ++ * so get it here instead of in get_version_information. */ ++ ret = do_command(gspca_dev, CPIA_COMMAND_GetVPVersion, 0, 0, 0, 0); ++ if (ret) ++ return ret; ++ ++ /* Determine video mode settings */ ++ sd->params.streamStartLine = 120; ++ ++ priv = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; ++ if (priv & 0x01) { /* crop */ ++ sd->params.roi.colStart = 2; ++ sd->params.roi.rowStart = 6; ++ } else { ++ sd->params.roi.colStart = 0; ++ sd->params.roi.rowStart = 0; ++ } ++ ++ if (priv & 0x02) { /* quarter */ ++ sd->params.format.videoSize = VIDEOSIZE_QCIF; ++ sd->params.roi.colStart /= 2; ++ sd->params.roi.rowStart /= 2; ++ sd->params.streamStartLine /= 2; ++ } else ++ sd->params.format.videoSize = VIDEOSIZE_CIF; ++ ++ sd->params.roi.colEnd = sd->params.roi.colStart + ++ (gspca_dev->width >> 3); ++ sd->params.roi.rowEnd = sd->params.roi.rowStart + ++ (gspca_dev->height >> 2); ++ ++ /* And now set the camera to a known state */ ++ ret = do_command(gspca_dev, CPIA_COMMAND_SetGrabMode, ++ CPIA_GRAB_CONTINEOUS, 0, 0, 0); ++ if (ret) ++ return ret; ++ /* We start with compression disabled, as we need one uncompressed ++ frame to handle later compressed frames */ ++ ret = do_command(gspca_dev, CPIA_COMMAND_SetCompression, ++ CPIA_COMPRESSION_NONE, ++ NO_DECIMATION, 0, 0); ++ if (ret) ++ return ret; ++ ret = command_setcompressiontarget(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setcolourparams(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setformat(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setyuvtresh(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setecptiming(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setcompressionparams(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setexposure(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setcolourbalance(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setsensorfps(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setapcor(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setflickerctrl(gspca_dev); ++ if (ret) ++ return ret; ++ ret = command_setvloffset(gspca_dev); ++ if (ret) ++ return ret; ++ ++ /* Start stream */ ++ ret = command_resume(gspca_dev); ++ if (ret) ++ return ret; ++ ++ /* Wait 6 frames before turning compression on for the sensor to get ++ all settings and AEC/ACB to settle */ ++ sd->first_frame = 6; ++ sd->exposure_status = EXPOSURE_NORMAL; ++ sd->exposure_count = 0; ++ atomic_set(&sd->cam_exposure, 0); ++ atomic_set(&sd->fps, 0); ++ ++ return 0; ++} ++ ++static void sd_stopN(struct gspca_dev *gspca_dev) ++{ ++ command_pause(gspca_dev); ++ ++ /* save camera state for later open (developers guide ch 3.5.3) */ ++ save_camera_state(gspca_dev); ++ ++ /* GotoLoPower */ ++ goto_low_power(gspca_dev); ++ ++ /* Update the camera status */ ++ do_command(gspca_dev, CPIA_COMMAND_GetCameraStatus, 0, 0, 0, 0); ++} ++ ++/* this function is called at probe and resume time */ ++static int sd_init(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret; ++ ++ /* Start / Stop the camera to make sure we are talking to ++ a supported camera, and to get some information from it ++ to print. */ ++ ret = sd_start(gspca_dev); ++ if (ret) ++ return ret; ++ ++ sd_stopN(gspca_dev); ++ ++ PDEBUG(D_PROBE, "CPIA Version: %d.%02d (%d.%d)", ++ sd->params.version.firmwareVersion, ++ sd->params.version.firmwareRevision, ++ sd->params.version.vcVersion, ++ sd->params.version.vcRevision); ++ PDEBUG(D_PROBE, "CPIA PnP-ID: %04x:%04x:%04x", ++ sd->params.pnpID.vendor, sd->params.pnpID.product, ++ sd->params.pnpID.deviceRevision); ++ PDEBUG(D_PROBE, "VP-Version: %d.%d %04x", ++ sd->params.vpVersion.vpVersion, ++ sd->params.vpVersion.vpRevision, ++ sd->params.vpVersion.cameraHeadID); ++ ++ return 0; ++} ++ ++static void sd_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, ++ int len) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ /* Check for SOF */ ++ if (len >= 64 && ++ data[0] == MAGIC_0 && data[1] == MAGIC_1 && ++ data[16] == sd->params.format.videoSize && ++ data[17] == sd->params.format.subSample && ++ data[18] == sd->params.format.yuvOrder && ++ data[24] == sd->params.roi.colStart && ++ data[25] == sd->params.roi.colEnd && ++ data[26] == sd->params.roi.rowStart && ++ data[27] == sd->params.roi.rowEnd) { ++ struct gspca_frame *frame = gspca_get_i_frame(gspca_dev); ++ ++ atomic_set(&sd->cam_exposure, data[39] * 2); ++ atomic_set(&sd->fps, data[41]); ++ ++ if (frame == NULL) { ++ gspca_dev->last_packet_type = DISCARD_PACKET; ++ return; ++ } ++ ++ /* Check for proper EOF for last frame */ ++ if ((frame->data_end - frame->data) > 4 && ++ frame->data_end[-4] == 0xff && ++ frame->data_end[-3] == 0xff && ++ frame->data_end[-2] == 0xff && ++ frame->data_end[-1] == 0xff) ++ gspca_frame_add(gspca_dev, LAST_PACKET, ++ NULL, 0); ++ ++ gspca_frame_add(gspca_dev, FIRST_PACKET, data, len); ++ return; ++ } ++ ++ gspca_frame_add(gspca_dev, INTER_PACKET, data, len); ++} ++ ++static void sd_dq_callback(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ /* Set the normal compression settings once we have captured a ++ few uncompressed frames (and AEC has hopefully settled) */ ++ if (sd->first_frame) { ++ sd->first_frame--; ++ if (sd->first_frame == 0) ++ command_setcompression(gspca_dev); ++ } ++ ++ /* Switch flicker control back on if it got turned off */ ++ restart_flicker(gspca_dev); ++ ++ /* If AEC is enabled, monitor the exposure and ++ adjust the sensor frame rate if needed */ ++ if (sd->params.exposure.expMode == 2) ++ monitor_exposure(gspca_dev); ++ ++ /* Update our knowledge of the camera state */ ++ do_command(gspca_dev, CPIA_COMMAND_GetExposure, 0, 0, 0, 0); ++ if (sd->params.qx3.qx3_detected) ++ do_command(gspca_dev, CPIA_COMMAND_ReadMCPorts, 0, 0, 0, 0); ++} ++ ++static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int ret; ++ ++ sd->params.colourParams.brightness = val; ++ sd->params.flickerControl.allowableOverExposure = ++ find_over_exposure(sd->params.colourParams.brightness); ++ if (gspca_dev->streaming) { ++ ret = command_setcolourparams(gspca_dev); ++ if (ret) ++ return ret; ++ return command_setflickerctrl(gspca_dev); ++ } ++ return 0; ++} ++ ++static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->params.colourParams.brightness; ++ return 0; ++} ++ ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->params.colourParams.contrast = val; ++ if (gspca_dev->streaming) ++ return command_setcolourparams(gspca_dev); ++ ++ return 0; ++} ++ ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->params.colourParams.contrast; ++ return 0; ++} ++ ++static int sd_setsaturation(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->params.colourParams.saturation = val; ++ if (gspca_dev->streaming) ++ return command_setcolourparams(gspca_dev); ++ ++ return 0; ++} ++ ++static int sd_getsaturation(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->params.colourParams.saturation; ++ return 0; ++} ++ ++static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int on; ++ ++ switch (val) { ++ case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ ++ on = 0; ++ break; ++ case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ ++ on = 1; ++ sd->mainsFreq = 0; ++ break; ++ case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ ++ on = 1; ++ sd->mainsFreq = 1; ++ break; ++ default: ++ return -EINVAL; ++ } ++ ++ sd->freq = val; ++ sd->params.flickerControl.coarseJump = ++ flicker_jumps[sd->mainsFreq] ++ [sd->params.sensorFps.baserate] ++ [sd->params.sensorFps.divisor]; ++ ++ return set_flicker(gspca_dev, on, gspca_dev->streaming); ++} ++ ++static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->freq; ++ return 0; ++} ++ ++static int sd_setcomptarget(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->params.compressionTarget.frTargeting = val; ++ if (gspca_dev->streaming) ++ return command_setcompressiontarget(gspca_dev); ++ ++ return 0; ++} ++ ++static int sd_getcomptarget(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->params.compressionTarget.frTargeting; ++ return 0; ++} ++ ++static int sd_querymenu(struct gspca_dev *gspca_dev, ++ struct v4l2_querymenu *menu) ++{ ++ switch (menu->id) { ++ case V4L2_CID_POWER_LINE_FREQUENCY: ++ switch (menu->index) { ++ case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ ++ strcpy((char *) menu->name, "NoFliker"); ++ return 0; ++ case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ ++ strcpy((char *) menu->name, "50 Hz"); ++ return 0; ++ case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ ++ strcpy((char *) menu->name, "60 Hz"); ++ return 0; ++ } ++ break; ++ case V4L2_CID_COMP_TARGET: ++ switch (menu->index) { ++ case CPIA_COMPRESSION_TARGET_QUALITY: ++ strcpy((char *) menu->name, "Quality"); ++ return 0; ++ case CPIA_COMPRESSION_TARGET_FRAMERATE: ++ strcpy((char *) menu->name, "Framerate"); ++ return 0; ++ } ++ break; ++ } ++ return -EINVAL; ++} ++ ++/* sub-driver description */ ++static const struct sd_desc sd_desc = { ++ .name = MODULE_NAME, ++ .ctrls = sd_ctrls, ++ .nctrls = ARRAY_SIZE(sd_ctrls), ++ .config = sd_config, ++ .init = sd_init, ++ .start = sd_start, ++ .stopN = sd_stopN, ++ .dq_callback = sd_dq_callback, ++ .pkt_scan = sd_pkt_scan, ++ .querymenu = sd_querymenu, ++}; ++ ++/* -- module initialisation -- */ ++static const __devinitdata struct usb_device_id device_table[] = { ++ {USB_DEVICE(0x0553, 0x0002)}, ++ {USB_DEVICE(0x0813, 0x0001)}, ++ {} ++}; ++MODULE_DEVICE_TABLE(usb, device_table); ++ ++/* -- device connect -- */ ++static int sd_probe(struct usb_interface *intf, ++ const struct usb_device_id *id) ++{ ++ return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), ++ THIS_MODULE); ++} ++ ++static struct usb_driver sd_driver = { ++ .name = MODULE_NAME, ++ .id_table = device_table, ++ .probe = sd_probe, ++ .disconnect = gspca_disconnect, ++#ifdef CONFIG_PM ++ .suspend = gspca_suspend, ++ .resume = gspca_resume, ++#endif ++}; ++ ++/* -- module insert / remove -- */ ++static int __init sd_mod_init(void) ++{ ++ int ret; ++ ret = usb_register(&sd_driver); ++ if (ret < 0) ++ return ret; ++ PDEBUG(D_PROBE, "registered"); ++ return 0; ++} ++static void __exit sd_mod_exit(void) ++{ ++ usb_deregister(&sd_driver); ++ PDEBUG(D_PROBE, "deregistered"); ++} ++ ++module_init(sd_mod_init); ++module_exit(sd_mod_exit); +diff --git a/drivers/media/video/gspca/etoms.c b/drivers/media/video/gspca/etoms.c +index fdf4c0e..6ac9eac 100644 +--- a/drivers/media/video/gspca/etoms.c ++++ b/drivers/media/video/gspca/etoms.c +@@ -52,7 +52,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -706,6 +706,12 @@ static void Et_setgainG(struct gspca_dev *gspca_dev, __u8 gain) + + i2c_w(gspca_dev, PAS106_REG13, &i2cflags, 1, 3); + i2c_w(gspca_dev, PAS106_REG0e, &gain, 1, 1); ++#if 0 ++ i2c_w(gspca_dev, 0x09, &gain, 1, 1); ++ i2c_w(gspca_dev, 0x0a, &gain, 1, 1); ++ i2c_w(gspca_dev, 0x0b, &gain, 1, 1); ++ i2c_w(gspca_dev, 0x0c, &gain, 1, 1); ++#endif + } + } + +@@ -851,7 +857,7 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) + } + + /* sub-driver description */ +-static struct sd_desc sd_desc = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), +diff --git a/drivers/media/video/gspca/gl860/gl860.c b/drivers/media/video/gspca/gl860/gl860.c +index 4878c8f..9e42476 100644 +--- a/drivers/media/video/gspca/gl860/gl860.c ++++ b/drivers/media/video/gspca/gl860/gl860.c +@@ -161,7 +161,7 @@ static int gl860_build_control_table(struct gspca_dev *gspca_dev) + + /*==================== sud-driver structure initialisation =================*/ + +-static struct sd_desc sd_desc_mi1320 = { ++static const struct sd_desc sd_desc_mi1320 = { + .name = MODULE_NAME, + .ctrls = sd_ctrls_mi1320, + .nctrls = GL860_NCTRLS, +@@ -174,7 +174,7 @@ static struct sd_desc sd_desc_mi1320 = { + .dq_callback = sd_callback, + }; + +-static struct sd_desc sd_desc_mi2020 = { ++static const struct sd_desc sd_desc_mi2020 = { + .name = MODULE_NAME, + .ctrls = sd_ctrls_mi2020, + .nctrls = GL860_NCTRLS, +@@ -187,7 +187,7 @@ static struct sd_desc sd_desc_mi2020 = { + .dq_callback = sd_callback, + }; + +-static struct sd_desc sd_desc_mi2020b = { ++static const struct sd_desc sd_desc_mi2020b = { + .name = MODULE_NAME, + .ctrls = sd_ctrls_mi2020b, + .nctrls = GL860_NCTRLS, +@@ -200,7 +200,7 @@ static struct sd_desc sd_desc_mi2020b = { + .dq_callback = sd_callback, + }; + +-static struct sd_desc sd_desc_ov2640 = { ++static const struct sd_desc sd_desc_ov2640 = { + .name = MODULE_NAME, + .ctrls = sd_ctrls_ov2640, + .nctrls = GL860_NCTRLS, +@@ -213,7 +213,7 @@ static struct sd_desc sd_desc_ov2640 = { + .dq_callback = sd_callback, + }; + +-static struct sd_desc sd_desc_ov9655 = { ++static const struct sd_desc sd_desc_ov9655 = { + .name = MODULE_NAME, + .ctrls = sd_ctrls_ov9655, + .nctrls = GL860_NCTRLS, +diff --git a/drivers/media/video/gspca/gspca.c b/drivers/media/video/gspca/gspca.c +index bd6214d..85c966e 100644 +--- a/drivers/media/video/gspca/gspca.c ++++ b/drivers/media/video/gspca/gspca.c +@@ -3,6 +3,9 @@ + * + * Copyright (C) 2008-2009 Jean-Francois Moine (http://moinejf.free.fr) + * ++ * Camera button input handling by Márton Németh ++ * Copyright (C) 2009-2010 Márton Németh ++ * + * This program is free software; you can redistribute it and/or modify it + * under the terms of the GNU General Public License as published by the + * Free Software Foundation; either version 2 of the License, or (at your +@@ -37,6 +40,9 @@ + + #include "gspca.h" + ++#include ++#include ++ + /* global values */ + #define DEF_NURBS 3 /* default number of URBs */ + #if DEF_NURBS > MAX_NURBS +@@ -47,7 +53,7 @@ MODULE_AUTHOR("Jean-Francois Moine "); + MODULE_DESCRIPTION("GSPCA USB Camera Driver"); + MODULE_LICENSE("GPL"); + +-#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 8, 0) ++#define DRIVER_VERSION_NUMBER KERNEL_VERSION(2, 9, 0) + + #ifdef GSPCA_DEBUG + int gspca_debug = D_ERR | D_PROBE; +@@ -104,15 +110,184 @@ static const struct vm_operations_struct gspca_vm_ops = { + .close = gspca_vm_close, + }; + ++/* ++ * Input and interrupt endpoint handling functions ++ */ ++#ifdef CONFIG_INPUT ++static void int_irq(struct urb *urb) ++{ ++ struct gspca_dev *gspca_dev = (struct gspca_dev *) urb->context; ++ int ret; ++ ++ ret = urb->status; ++ switch (ret) { ++ case 0: ++ if (gspca_dev->sd_desc->int_pkt_scan(gspca_dev, ++ urb->transfer_buffer, urb->actual_length) < 0) { ++ PDEBUG(D_ERR, "Unknown packet received"); ++ } ++ break; ++ ++ case -ENOENT: ++ case -ECONNRESET: ++ case -ENODEV: ++ case -ESHUTDOWN: ++ /* Stop is requested either by software or hardware is gone, ++ * keep the ret value non-zero and don't resubmit later. ++ */ ++ break; ++ ++ default: ++ PDEBUG(D_ERR, "URB error %i, resubmitting", urb->status); ++ urb->status = 0; ++ ret = 0; ++ } ++ ++ if (ret == 0) { ++ ret = usb_submit_urb(urb, GFP_ATOMIC); ++ if (ret < 0) ++ PDEBUG(D_ERR, "Resubmit URB failed with error %i", ret); ++ } ++} ++ ++static int gspca_input_connect(struct gspca_dev *dev) ++{ ++ struct input_dev *input_dev; ++ int err = 0; ++ ++ dev->input_dev = NULL; ++ if (dev->sd_desc->int_pkt_scan || dev->sd_desc->other_input) { ++ input_dev = input_allocate_device(); ++ if (!input_dev) ++ return -ENOMEM; ++ ++ usb_make_path(dev->dev, dev->phys, sizeof(dev->phys)); ++ strlcat(dev->phys, "/input0", sizeof(dev->phys)); ++ ++ input_dev->name = dev->sd_desc->name; ++ input_dev->phys = dev->phys; ++ ++ usb_to_input_id(dev->dev, &input_dev->id); ++ ++ input_dev->evbit[0] = BIT_MASK(EV_KEY); ++ input_dev->keybit[BIT_WORD(KEY_CAMERA)] = BIT_MASK(KEY_CAMERA); ++ input_dev->dev.parent = &dev->dev->dev; ++ err = input_register_device(input_dev); ++ if (err) { ++ PDEBUG(D_ERR, "Input device registration failed " ++ "with error %i", err); ++ input_dev->dev.parent = NULL; ++ input_free_device(input_dev); ++ } else { ++ dev->input_dev = input_dev; ++ } ++ } ++ ++ return err; ++} ++ ++static int alloc_and_submit_int_urb(struct gspca_dev *gspca_dev, ++ struct usb_endpoint_descriptor *ep) ++{ ++ unsigned int buffer_len; ++ int interval; ++ struct urb *urb; ++ struct usb_device *dev; ++ void *buffer = NULL; ++ int ret = -EINVAL; ++ ++ buffer_len = ep->wMaxPacketSize; ++ interval = ep->bInterval; ++ PDEBUG(D_PROBE, "found int in endpoint: 0x%x, " ++ "buffer_len=%u, interval=%u", ++ ep->bEndpointAddress, buffer_len, interval); ++ ++ dev = gspca_dev->dev; ++ ++ urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!urb) { ++ ret = -ENOMEM; ++ goto error; ++ } ++ ++ buffer = usb_buffer_alloc(dev, ep->wMaxPacketSize, ++ GFP_KERNEL, &urb->transfer_dma); ++ if (!buffer) { ++ ret = -ENOMEM; ++ goto error_buffer; ++ } ++ usb_fill_int_urb(urb, dev, ++ usb_rcvintpipe(dev, ep->bEndpointAddress), ++ buffer, buffer_len, ++ int_irq, (void *)gspca_dev, interval); ++ gspca_dev->int_urb = urb; ++ ret = usb_submit_urb(urb, GFP_KERNEL); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "submit URB failed with error %i", ret); ++ goto error_submit; ++ } ++ return ret; ++ ++error_submit: ++ usb_buffer_free(dev, ++ urb->transfer_buffer_length, ++ urb->transfer_buffer, ++ urb->transfer_dma); ++error_buffer: ++ usb_free_urb(urb); ++error: ++ return ret; ++} ++ ++static void gspca_input_create_urb(struct gspca_dev *gspca_dev) ++{ ++ struct usb_interface *intf; ++ struct usb_host_interface *intf_desc; ++ struct usb_endpoint_descriptor *ep; ++ int i; ++ ++ if (gspca_dev->sd_desc->int_pkt_scan) { ++ intf = usb_ifnum_to_if(gspca_dev->dev, gspca_dev->iface); ++ intf_desc = intf->cur_altsetting; ++ for (i = 0; i < intf_desc->desc.bNumEndpoints; i++) { ++ ep = &intf_desc->endpoint[i].desc; ++ if (usb_endpoint_dir_in(ep) && ++ usb_endpoint_xfer_int(ep)) { ++ ++ alloc_and_submit_int_urb(gspca_dev, ep); ++ break; ++ } ++ } ++ } ++} ++ ++static void gspca_input_destroy_urb(struct gspca_dev *gspca_dev) ++{ ++ struct urb *urb; ++ ++ urb = gspca_dev->int_urb; ++ if (urb) { ++ gspca_dev->int_urb = NULL; ++ usb_kill_urb(urb); ++ usb_buffer_free(gspca_dev->dev, ++ urb->transfer_buffer_length, ++ urb->transfer_buffer, ++ urb->transfer_dma); ++ usb_free_urb(urb); ++ } ++} ++#else ++#define gspca_input_connect(gspca_dev) 0 ++#define gspca_input_create_urb(gspca_dev) ++#define gspca_input_destroy_urb(gspca_dev) ++#endif ++ + /* get the current input frame buffer */ + struct gspca_frame *gspca_get_i_frame(struct gspca_dev *gspca_dev) + { + struct gspca_frame *frame; +- int i; + +- i = gspca_dev->fr_i; +- i = gspca_dev->fr_queue[i]; +- frame = &gspca_dev->frame[i]; ++ frame = gspca_dev->cur_frame; + if ((frame->v4l2_buf.flags & BUF_ALL_FLAGS) + != V4L2_BUF_FLAG_QUEUED) + return NULL; +@@ -486,11 +661,13 @@ static struct usb_host_endpoint *get_ep(struct gspca_dev *gspca_dev) + i, ep->desc.bEndpointAddress); + gspca_dev->alt = i; /* memorize the current alt setting */ + if (gspca_dev->nbalt > 1) { ++ gspca_input_destroy_urb(gspca_dev); + ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, i); + if (ret < 0) { + err("set alt %d err %d", i, ret); +- return NULL; ++ ep = NULL; + } ++ gspca_input_create_urb(gspca_dev); + } + return ep; + } +@@ -534,26 +711,22 @@ static int create_urbs(struct gspca_dev *gspca_dev, + nurbs = 1; + } + +- gspca_dev->nurbs = nurbs; + for (n = 0; n < nurbs; n++) { + urb = usb_alloc_urb(npkt, GFP_KERNEL); + if (!urb) { + err("usb_alloc_urb failed"); +- destroy_urbs(gspca_dev); + return -ENOMEM; + } ++ gspca_dev->urb[n] = urb; + urb->transfer_buffer = usb_buffer_alloc(gspca_dev->dev, + bsize, + GFP_KERNEL, + &urb->transfer_dma); + + if (urb->transfer_buffer == NULL) { +- usb_free_urb(urb); +- err("usb_buffer_urb failed"); +- destroy_urbs(gspca_dev); ++ err("usb_buffer_alloc failed"); + return -ENOMEM; + } +- gspca_dev->urb[n] = urb; + urb->dev = gspca_dev->dev; + urb->context = gspca_dev; + urb->transfer_buffer_length = bsize; +@@ -585,6 +758,7 @@ static int create_urbs(struct gspca_dev *gspca_dev, + static int gspca_init_transfer(struct gspca_dev *gspca_dev) + { + struct usb_host_endpoint *ep; ++ struct urb *urb; + int n, ret; + + if (mutex_lock_interruptible(&gspca_dev->usb_lock)) +@@ -595,6 +769,8 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) + goto out; + } + ++ gspca_dev->usb_err = 0; ++ + /* set the higher alternate setting and + * loop until urb submit succeeds */ + if (gspca_dev->cam.reverse_alts) +@@ -613,10 +789,15 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) + goto out; + } + for (;;) { +- PDEBUG(D_STREAM, "init transfer alt %d", gspca_dev->alt); +- ret = create_urbs(gspca_dev, ep); +- if (ret < 0) +- goto out; ++ if (!gspca_dev->cam.no_urb_create) { ++ PDEBUG(D_STREAM, "init transfer alt %d", ++ gspca_dev->alt); ++ ret = create_urbs(gspca_dev, ep); ++ if (ret < 0) { ++ destroy_urbs(gspca_dev); ++ goto out; ++ } ++ } + + /* clear the bulk endpoint */ + if (gspca_dev->cam.bulk) +@@ -636,8 +817,11 @@ static int gspca_init_transfer(struct gspca_dev *gspca_dev) + break; + + /* submit the URBs */ +- for (n = 0; n < gspca_dev->nurbs; n++) { +- ret = usb_submit_urb(gspca_dev->urb[n], GFP_KERNEL); ++ for (n = 0; n < MAX_NURBS; n++) { ++ urb = gspca_dev->urb[n]; ++ if (urb == NULL) ++ break; ++ ret = usb_submit_urb(urb, GFP_KERNEL); + if (ret < 0) + break; + } +@@ -694,7 +878,9 @@ static void gspca_stream_off(struct gspca_dev *gspca_dev) + if (gspca_dev->sd_desc->stopN) + gspca_dev->sd_desc->stopN(gspca_dev); + destroy_urbs(gspca_dev); ++ gspca_input_destroy_urb(gspca_dev); + gspca_set_alt0(gspca_dev); ++ gspca_input_create_urb(gspca_dev); + } + + /* always call stop0 to free the subdriver's resources */ +@@ -2060,11 +2246,12 @@ int gspca_dev_probe(struct usb_interface *intf, + PDEBUG(D_ERR, "Too many config"); + return -ENODEV; + } ++ ++ /* the USB video interface must be the first one */ + interface = &intf->cur_altsetting->desc; +- if (interface->bInterfaceNumber > 0) { +- PDEBUG(D_ERR, "intf != 0"); ++ if (dev->config->desc.bNumInterfaces != 1 && ++ interface->bInterfaceNumber != 0) + return -ENODEV; +- } + + /* create the device */ + if (dev_size < sizeof *gspca_dev) +@@ -2096,6 +2283,10 @@ int gspca_dev_probe(struct usb_interface *intf, + goto out; + gspca_set_default_mode(gspca_dev); + ++ ret = gspca_input_connect(gspca_dev); ++ if (ret) ++ goto out; ++ + mutex_init(&gspca_dev->usb_lock); + mutex_init(&gspca_dev->read_lock); + mutex_init(&gspca_dev->queue_lock); +@@ -2116,8 +2307,15 @@ int gspca_dev_probe(struct usb_interface *intf, + + usb_set_intfdata(intf, gspca_dev); + PDEBUG(D_PROBE, "%s created", video_device_node_name(&gspca_dev->vdev)); ++ ++ gspca_input_create_urb(gspca_dev); ++ + return 0; + out: ++#ifdef CONFIG_INPUT ++ if (gspca_dev->input_dev) ++ input_unregister_device(gspca_dev->input_dev); ++#endif + kfree(gspca_dev->usb_buf); + kfree(gspca_dev); + return ret; +@@ -2133,6 +2331,7 @@ EXPORT_SYMBOL(gspca_dev_probe); + void gspca_disconnect(struct usb_interface *intf) + { + struct gspca_dev *gspca_dev = usb_get_intfdata(intf); ++ struct input_dev *input_dev; + + PDEBUG(D_PROBE, "%s disconnect", + video_device_node_name(&gspca_dev->vdev)); +@@ -2144,6 +2343,13 @@ void gspca_disconnect(struct usb_interface *intf) + wake_up_interruptible(&gspca_dev->wq); + } + ++ gspca_input_destroy_urb(gspca_dev); ++ input_dev = gspca_dev->input_dev; ++ if (input_dev) { ++ gspca_dev->input_dev = NULL; ++ input_unregister_device(input_dev); ++ } ++ + /* the device is freed at exit of this function */ + gspca_dev->dev = NULL; + mutex_unlock(&gspca_dev->usb_lock); +@@ -2169,6 +2375,7 @@ int gspca_suspend(struct usb_interface *intf, pm_message_t message) + if (gspca_dev->sd_desc->stopN) + gspca_dev->sd_desc->stopN(gspca_dev); + destroy_urbs(gspca_dev); ++ gspca_input_destroy_urb(gspca_dev); + gspca_set_alt0(gspca_dev); + if (gspca_dev->sd_desc->stop0) + gspca_dev->sd_desc->stop0(gspca_dev); +@@ -2182,6 +2389,7 @@ int gspca_resume(struct usb_interface *intf) + + gspca_dev->frozen = 0; + gspca_dev->sd_desc->init(gspca_dev); ++ gspca_input_create_urb(gspca_dev); + if (gspca_dev->streaming) + return gspca_init_transfer(gspca_dev); + return 0; +@@ -2205,6 +2413,8 @@ int gspca_auto_gain_n_exposure(struct gspca_dev *gspca_dev, int avg_lum, + int retval = 0; + + for (i = 0; i < gspca_dev->sd_desc->nctrls; i++) { ++ if (gspca_dev->ctrl_dis & (1 << i)) ++ continue; + if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_GAIN) + gain_ctrl = &gspca_dev->sd_desc->ctrls[i]; + if (gspca_dev->sd_desc->ctrls[i].qctrl.id == V4L2_CID_EXPOSURE) +diff --git a/drivers/media/video/gspca/gspca.h b/drivers/media/video/gspca/gspca.h +index 59c7941..02c696a 100644 +--- a/drivers/media/video/gspca/gspca.h ++++ b/drivers/media/video/gspca/gspca.h +@@ -48,26 +48,27 @@ extern int gspca_debug; + + /* used to list framerates supported by a camera mode (resolution) */ + struct framerates { +- int *rates; ++ const u8 *rates; + int nrates; + }; + + /* device information - set at probe time */ + struct cam { +- int bulk_size; /* buffer size when image transfer by bulk */ + const struct v4l2_pix_format *cam_mode; /* size nmodes */ +- char nmodes; + const struct framerates *mode_framerates; /* must have size nmode, + * just like cam_mode */ +- __u8 bulk_nurbs; /* number of URBs in bulk mode ++ u32 bulk_size; /* buffer size when image transfer by bulk */ ++ u32 input_flags; /* value for ENUM_INPUT status flags */ ++ u8 nmodes; /* size of cam_mode */ ++ u8 no_urb_create; /* don't create transfer URBs */ ++ u8 bulk_nurbs; /* number of URBs in bulk mode + * - cannot be > MAX_NURBS + * - when 0 and bulk_size != 0 means + * 1 URB and submit done by subdriver */ + u8 bulk; /* image transfer by 0:isoc / 1:bulk */ + u8 npkt; /* number of packets in an ISOC message + * 0 is the default value: 32 packets */ +- u32 input_flags; /* value for ENUM_INPUT status flags */ +- char reverse_alts; /* Alt settings are in high to low order */ ++ u8 reverse_alts; /* Alt settings are in high to low order */ + }; + + struct gspca_dev; +@@ -90,6 +91,9 @@ typedef int (*cam_qmnu_op) (struct gspca_dev *, + typedef void (*cam_pkt_op) (struct gspca_dev *gspca_dev, + u8 *data, + int len); ++typedef int (*cam_int_pkt_op) (struct gspca_dev *gspca_dev, ++ u8 *data, ++ int len); + + struct ctrl { + struct v4l2_queryctrl qctrl; +@@ -125,6 +129,12 @@ struct sd_desc { + cam_reg_op get_register; + #endif + cam_ident_op get_chip_ident; ++#ifdef CONFIG_INPUT ++ cam_int_pkt_op int_pkt_scan; ++ /* other_input makes the gspca core create gspca_dev->input even when ++ int_pkt_scan is NULL, for cams with non interrupt driven buttons */ ++ u8 other_input; ++#endif + }; + + /* packet types when moving from iso buf to frame buf */ +@@ -147,6 +157,10 @@ struct gspca_dev { + struct module *module; /* subdriver handling the device */ + struct usb_device *dev; + struct file *capt_file; /* file doing video capture */ ++#ifdef CONFIG_INPUT ++ struct input_dev *input_dev; ++ char phys[64]; /* physical device path */ ++#endif + + struct cam cam; /* device information */ + const struct sd_desc *sd_desc; /* subdriver description */ +@@ -156,6 +170,9 @@ struct gspca_dev { + #define USB_BUF_SZ 64 + __u8 *usb_buf; /* buffer for USB exchanges */ + struct urb *urb[MAX_NURBS]; ++#ifdef CONFIG_INPUT ++ struct urb *int_urb; ++#endif + + __u8 *frbuf; /* buffer for nframes */ + struct gspca_frame frame[GSPCA_MAX_FRAMES]; +@@ -187,7 +204,6 @@ struct gspca_dev { + char users; /* number of opens */ + char present; /* device connected */ + char nbufread; /* number of buffers for read() */ +- char nurbs; /* number of allocated URBs */ + char memory; /* memory type (V4L2_MEMORY_xxx) */ + __u8 iface; /* USB interface number */ + __u8 alt; /* USB alternate setting */ +diff --git a/drivers/media/video/gspca/m5602/m5602_mt9m111.c b/drivers/media/video/gspca/m5602/m5602_mt9m111.c +index 8d071df..de5425a 100644 +--- a/drivers/media/video/gspca/m5602/m5602_mt9m111.c ++++ b/drivers/media/video/gspca/m5602/m5602_mt9m111.c +@@ -36,6 +36,18 @@ static int mt9m111_get_red_balance(struct gspca_dev *gspca_dev, __s32 *val); + static int mt9m111_set_red_balance(struct gspca_dev *gspca_dev, __s32 val); + + static struct v4l2_pix_format mt9m111_modes[] = { ++#if 0 ++ { ++ 320, ++ 240, ++ V4L2_PIX_FMT_SBGGR8, ++ V4L2_FIELD_NONE, ++ .sizeimage = 320 * 240, ++ .bytesperline = 320, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 0 ++ }, ++#endif + { + 640, + 480, +@@ -48,7 +60,7 @@ static struct v4l2_pix_format mt9m111_modes[] = { + } + }; + +-const static struct ctrl mt9m111_ctrls[] = { ++static const struct ctrl mt9m111_ctrls[] = { + #define VFLIP_IDX 0 + { + { +@@ -171,7 +183,7 @@ int mt9m111_probe(struct sd *sd) + return -ENODEV; + } + +- info("Probing for a mt9m111 sensor"); ++ PDEBUG(D_PROBE, "Probing for a mt9m111 sensor"); + + /* Do the preinit */ + for (i = 0; i < ARRAY_SIZE(preinit_mt9m111); i++) { +diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.c b/drivers/media/video/gspca/m5602/m5602_ov7660.c +index 2a28b74..99fef65 100644 +--- a/drivers/media/video/gspca/m5602/m5602_ov7660.c ++++ b/drivers/media/video/gspca/m5602/m5602_ov7660.c +@@ -20,6 +20,12 @@ + + static int ov7660_get_gain(struct gspca_dev *gspca_dev, __s32 *val); + static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val); ++#if 0 ++static int ov7660_get_blue_gain(struct gspca_dev *gspca_dev, __s32 *val); ++static int ov7660_set_blue_gain(struct gspca_dev *gspca_dev, __s32 val); ++static int ov7660_get_red_gain(struct gspca_dev *gspca_dev, __s32 *val); ++static int ov7660_set_red_gain(struct gspca_dev *gspca_dev, __s32 val); ++#endif + static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev, + __s32 *val); + static int ov7660_set_auto_white_balance(struct gspca_dev *gspca_dev, +@@ -33,7 +39,7 @@ static int ov7660_set_hflip(struct gspca_dev *gspca_dev, __s32 val); + static int ov7660_get_vflip(struct gspca_dev *gspca_dev, __s32 *val); + static int ov7660_set_vflip(struct gspca_dev *gspca_dev, __s32 val); + +-const static struct ctrl ov7660_ctrls[] = { ++static const struct ctrl ov7660_ctrls[] = { + #define GAIN_IDX 1 + { + { +@@ -50,7 +56,39 @@ const static struct ctrl ov7660_ctrls[] = { + .get = ov7660_get_gain + }, + #define BLUE_BALANCE_IDX 2 ++#if 0 ++ { ++ { ++ .id = V4L2_CID_BLUE_BALANCE, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "blue balance", ++ .minimum = 0x00, ++ .maximum = 0x7f, ++ .step = 0x1, ++ .default_value = OV7660_DEFAULT_BLUE_GAIN, ++ .flags = V4L2_CTRL_FLAG_SLIDER ++ }, ++ .set = ov7660_set_blue_gain, ++ .get = ov7660_get_blue_gain ++ }, ++#endif + #define RED_BALANCE_IDX 3 ++#if 0 ++ { ++ { ++ .id = V4L2_CID_RED_BALANCE, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "red balance", ++ .minimum = 0x00, ++ .maximum = 0x7f, ++ .step = 0x1, ++ .default_value = OV7660_DEFAULT_RED_GAIN, ++ .flags = V4L2_CTRL_FLAG_SLIDER ++ }, ++ .set = ov7660_set_red_gain, ++ .get = ov7660_get_red_gain ++ }, ++#endif + #define AUTO_WHITE_BALANCE_IDX 4 + { + { +@@ -247,6 +285,17 @@ int ov7660_init(struct sd *sd) + sensor_settings[AUTO_EXPOSURE_IDX]); + if (err < 0) + return err; ++#if 0 ++ err = ov7660_set_blue_gain(&sd->gspca_dev, ++ sensor_settings[BLUE_BALANCE_IDX]); ++ if (err < 0) ++ return err; ++ ++ err = ov7660_set_red_gain(&sd->gspca_dev, ++ sensor_settings[RED_BALANCE_IDX]); ++ if (err < 0) ++ return err; ++#endif + err = ov7660_set_hflip(&sd->gspca_dev, + sensor_settings[HFLIP_IDX]); + if (err < 0) +@@ -301,6 +350,57 @@ static int ov7660_set_gain(struct gspca_dev *gspca_dev, __s32 val) + return err; + } + ++#if 0 ++static int ov7660_get_blue_gain(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ s32 *sensor_settings = sd->sensor_priv; ++ ++ *val = sensor_settings[BLUE_BALANCE_IDX]; ++ PDEBUG(D_V4L2, "Read blue balance %d", *val); ++ return 0; ++} ++ ++static int ov7660_set_blue_gain(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ int err; ++ u8 i2c_data; ++ struct sd *sd = (struct sd *) gspca_dev; ++ s32 *sensor_settings = sd->sensor_priv; ++ ++ PDEBUG(D_V4L2, "Setting blue balance to %d", val); ++ ++ sensor_settings[BLUE_BALANCE_IDX] = val; ++ ++ err = m5602_write_sensor(sd, OV7660_BLUE_GAIN, &i2c_data, 1); ++ return err; ++} ++ ++static int ov7660_get_red_gain(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ s32 *sensor_settings = sd->sensor_priv; ++ ++ *val = sensor_settings[RED_BALANCE_IDX]; ++ PDEBUG(D_V4L2, "Read red balance %d", *val); ++ return 0; ++} ++ ++static int ov7660_set_red_gain(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ int err; ++ u8 i2c_data; ++ struct sd *sd = (struct sd *) gspca_dev; ++ s32 *sensor_settings = sd->sensor_priv; ++ ++ PDEBUG(D_V4L2, "Setting red balance to %d", val); ++ ++ sensor_settings[RED_BALANCE_IDX] = val; ++ ++ err = m5602_write_sensor(sd, OV7660_RED_GAIN, &i2c_data, 1); ++ return err; ++} ++#endif + + static int ov7660_get_auto_white_balance(struct gspca_dev *gspca_dev, + __s32 *val) +diff --git a/drivers/media/video/gspca/m5602/m5602_ov7660.h b/drivers/media/video/gspca/m5602/m5602_ov7660.h +index f5588eb..4d9dcf2 100644 +--- a/drivers/media/video/gspca/m5602/m5602_ov7660.h ++++ b/drivers/media/video/gspca/m5602/m5602_ov7660.h +@@ -94,7 +94,7 @@ int ov7660_start(struct sd *sd); + int ov7660_stop(struct sd *sd); + void ov7660_disconnect(struct sd *sd); + +-const static struct m5602_sensor ov7660 = { ++static const struct m5602_sensor ov7660 = { + .name = "ov7660", + .i2c_slave_id = 0x42, + .i2c_regW = 1, +diff --git a/drivers/media/video/gspca/m5602/m5602_ov9650.c b/drivers/media/video/gspca/m5602/m5602_ov9650.c +index 923cdd5..069ba00 100644 +--- a/drivers/media/video/gspca/m5602/m5602_ov9650.c ++++ b/drivers/media/video/gspca/m5602/m5602_ov9650.c +@@ -307,7 +307,7 @@ int ov9650_probe(struct sd *sd) + return -ENODEV; + } + +- info("Probing for an ov9650 sensor"); ++ PDEBUG(D_PROBE, "Probing for an ov9650 sensor"); + + /* Run the pre-init before probing the sensor */ + for (i = 0; i < ARRAY_SIZE(preinit_ov9650) && !err; i++) { +diff --git a/drivers/media/video/gspca/m5602/m5602_po1030.c b/drivers/media/video/gspca/m5602/m5602_po1030.c +index 8d74d80..03b8a3a 100644 +--- a/drivers/media/video/gspca/m5602/m5602_po1030.c ++++ b/drivers/media/video/gspca/m5602/m5602_po1030.c +@@ -42,6 +42,18 @@ static int po1030_get_auto_exposure(struct gspca_dev *gspca_dev, + __s32 *val); + + static struct v4l2_pix_format po1030_modes[] = { ++#if 0 ++ { ++ 320, ++ 240, ++ V4L2_PIX_FMT_SBGGR8, ++ V4L2_FIELD_NONE, ++ .sizeimage = 320 * 240, ++ .bytesperline = 320, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 2 ++ }, ++#endif + { + 640, + 480, +@@ -205,7 +217,7 @@ int po1030_probe(struct sd *sd) + return -ENODEV; + } + +- info("Probing for a po1030 sensor"); ++ PDEBUG(D_PROBE, "Probing for a po1030 sensor"); + + /* Run the pre-init to actually probe the unit */ + for (i = 0; i < ARRAY_SIZE(preinit_po1030); i++) { +diff --git a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c +index 1b536f7..da0a38c 100644 +--- a/drivers/media/video/gspca/m5602/m5602_s5k4aa.c ++++ b/drivers/media/video/gspca/m5602/m5602_s5k4aa.c +@@ -248,7 +248,7 @@ int s5k4aa_probe(struct sd *sd) + return -ENODEV; + } + +- info("Probing for a s5k4aa sensor"); ++ PDEBUG(D_PROBE, "Probing for a s5k4aa sensor"); + + /* Preinit the sensor */ + for (i = 0; i < ARRAY_SIZE(preinit_s5k4aa) && !err; i++) { +diff --git a/drivers/media/video/gspca/m5602/m5602_s5k83a.c b/drivers/media/video/gspca/m5602/m5602_s5k83a.c +index 6b89f33..fbd9154 100644 +--- a/drivers/media/video/gspca/m5602/m5602_s5k83a.c ++++ b/drivers/media/video/gspca/m5602/m5602_s5k83a.c +@@ -143,7 +143,7 @@ int s5k83a_probe(struct sd *sd) + return -ENODEV; + } + +- info("Probing for a s5k83a sensor"); ++ PDEBUG(D_PROBE, "Probing for a s5k83a sensor"); + + /* Preinit the sensor */ + for (i = 0; i < ARRAY_SIZE(preinit_s5k83a) && !err; i++) { +diff --git a/drivers/media/video/gspca/mars.c b/drivers/media/video/gspca/mars.c +index 9cf8d68..a08cd2b 100644 +--- a/drivers/media/video/gspca/mars.c ++++ b/drivers/media/video/gspca/mars.c +@@ -54,7 +54,7 @@ static int sd_getgamma(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -232,8 +232,13 @@ static int sd_start(struct gspca_dev *gspca_dev) + /* data[9]= 0x56; * reg 8, 24MHz, 2:1 scale down */ + /* else */ + data[9] = 0x52; /* reg 8, 24MHz, no scale down */ ++#if 1 + /*jfm: from win trace*/ + data[10] = 0x18; ++#else ++ data[10] = 0x5d; /* reg 9, I2C device address ++ * [for PAS5101 (0x40)] [for MI (0x5d)] */ ++#endif + + err_code = reg_w(gspca_dev, 11); + if (err_code < 0) +@@ -260,6 +265,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + /* auto dark-gain */ + data[0] = 0x5e; /* address */ + data[1] = 0; /* reg 94, Y Gain (auto) */ ++#if 1 + /*jfm: from win trace*/ + /* reg 0x5f/0x60 (LE) = saturation */ + /* h (60): xxxx x100 +@@ -268,12 +274,40 @@ static int sd_start(struct gspca_dev *gspca_dev) + data[3] = ((sd->colors >> 2) & 0xf8) | 0x04; + data[4] = sd->brightness; /* reg 0x61 = brightness */ + data[5] = 0x00; ++#else ++ data[2] = 0; /* reg 95, UV Gain (1.75) */ ++ data[3] = 0x78; /* reg 96, Y Gain/UV Gain/disable ++ * auto dark-gain */ ++ switch (gspca_dev->width) { ++/* case 1280: */ ++/* data[4] = 154; ++ * reg 97, %3 shadow point (unit: 256 pixel) */ ++/* data[5] = 51; ++ * reg 98, %1 highlight point ++ * (uint: 256 pixel) */ ++/* break; */ ++ default: ++/* case 640: */ ++ data[4] = 36; /* reg 97, %3 shadow point ++ * (unit: 256 pixel) */ ++ data[5] = 12; /* reg 98, %1 highlight point ++ * (uint: 256 pixel) */ ++ break; ++ case 320: ++ data[4] = 9; /* reg 97, %3 shadow point ++ * (unit: 256 pixel) */ ++ data[5] = 3; /* reg 98, %1 highlight point ++ * (uint: 256 pixel) */ ++ break; ++ } ++#endif + + err_code = reg_w(gspca_dev, 6); + if (err_code < 0) + return err_code; + + data[0] = 0x67; ++#if 1 + /*jfm: from win trace*/ + data[1] = sd->sharpness * 4 + 3; + data[2] = 0x14; +@@ -293,6 +327,10 @@ static int sd_start(struct gspca_dev *gspca_dev) + data[1] = 0x07; + err_code = reg_w(gspca_dev, 2); + /*jfm: win trace - many writes here to reg 0x64*/ ++#else ++ data[1] = 0x13; /* reg 103, first pixel B, disable sharpness */ ++ err_code = reg_w(gspca_dev, 2); ++#endif + if (err_code < 0) + return err_code; + +diff --git a/drivers/media/video/gspca/mr97310a.c b/drivers/media/video/gspca/mr97310a.c +index 9154870..33744e7 100644 +--- a/drivers/media/video/gspca/mr97310a.c ++++ b/drivers/media/video/gspca/mr97310a.c +@@ -57,6 +57,14 @@ + #define MR97310A_GAIN_MAX 31 + #define MR97310A_GAIN_DEFAULT 25 + ++#define MR97310A_CONTRAST_MIN 0 ++#define MR97310A_CONTRAST_MAX 31 ++#define MR97310A_CONTRAST_DEFAULT 23 ++ ++#define MR97310A_CS_GAIN_MIN 0 ++#define MR97310A_CS_GAIN_MAX 0x7ff ++#define MR97310A_CS_GAIN_DEFAULT 0x110 ++ + #define MR97310A_MIN_CLOCKDIV_MIN 3 + #define MR97310A_MIN_CLOCKDIV_MAX 8 + #define MR97310A_MIN_CLOCKDIV_DEFAULT 3 +@@ -82,7 +90,8 @@ struct sd { + + int brightness; + u16 exposure; +- u8 gain; ++ u32 gain; ++ u8 contrast; + u8 min_clockdiv; + }; + +@@ -98,6 +107,8 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); + static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setmin_clockdiv(struct gspca_dev *gspca_dev, __s32 val); +@@ -105,11 +116,13 @@ static int sd_getmin_clockdiv(struct gspca_dev *gspca_dev, __s32 *val); + static void setbrightness(struct gspca_dev *gspca_dev); + static void setexposure(struct gspca_dev *gspca_dev); + static void setgain(struct gspca_dev *gspca_dev); ++static void setcontrast(struct gspca_dev *gspca_dev); + + /* V4L2 controls supported by the driver */ +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + /* Separate brightness control description for Argus QuickClix as it has +- different limits from the other mr97310a cameras */ ++ * different limits from the other mr97310a cameras, and separate gain ++ * control for Sakar CyberPix camera. */ + { + #define NORM_BRIGHTNESS_IDX 0 + { +@@ -171,7 +184,37 @@ static struct ctrl sd_ctrls[] = { + .get = sd_getgain, + }, + { +-#define MIN_CLOCKDIV_IDX 4 ++#define SAKAR_CS_GAIN_IDX 4 ++ { ++ .id = V4L2_CID_GAIN, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Gain", ++ .minimum = MR97310A_CS_GAIN_MIN, ++ .maximum = MR97310A_CS_GAIN_MAX, ++ .step = 1, ++ .default_value = MR97310A_CS_GAIN_DEFAULT, ++ .flags = 0, ++ }, ++ .set = sd_setgain, ++ .get = sd_getgain, ++ }, ++ { ++#define CONTRAST_IDX 5 ++ { ++ .id = V4L2_CID_CONTRAST, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Contrast", ++ .minimum = MR97310A_CONTRAST_MIN, ++ .maximum = MR97310A_CONTRAST_MAX, ++ .step = 1, ++ .default_value = MR97310A_CONTRAST_DEFAULT, ++ .flags = 0, ++ }, ++ .set = sd_setcontrast, ++ .get = sd_getcontrast, ++ }, ++ { ++#define MIN_CLOCKDIV_IDX 6 + { + .id = V4L2_CID_PRIVATE_BASE, + .type = V4L2_CTRL_TYPE_INTEGER, +@@ -327,7 +370,6 @@ static int zero_the_pointer(struct gspca_dev *gspca_dev) + if (err_code < 0) + return err_code; + +- err_code = mr_write(gspca_dev, 1); + data[0] = 0x19; + data[1] = 0x51; + err_code = mr_write(gspca_dev, 2); +@@ -437,6 +479,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + { + struct sd *sd = (struct sd *) gspca_dev; + struct cam *cam; ++ int gain_default = MR97310A_GAIN_DEFAULT; + int err_code; + + cam = &gspca_dev->cam; +@@ -460,12 +503,14 @@ static int sd_config(struct gspca_dev *gspca_dev, + if (err_code < 0) + return err_code; + ++ /* Now, the query for sensor type. */ ++ err_code = cam_get_response16(gspca_dev, 0x07, 1); ++ if (err_code < 0) ++ return err_code; ++ + if (id->idProduct == 0x0110 || id->idProduct == 0x010e) { + sd->cam_type = CAM_TYPE_CIF; + cam->nmodes--; +- err_code = cam_get_response16(gspca_dev, 0x06, 1); +- if (err_code < 0) +- return err_code; + /* + * All but one of the known CIF cameras share the same USB ID, + * but two different init routines are in use, and the control +@@ -473,12 +518,12 @@ static int sd_config(struct gspca_dev *gspca_dev, + * of the two known varieties is connected! + * + * A list of known CIF cameras follows. They all report either +- * 0002 for type 0 or 0003 for type 1. ++ * 0200 for type 0 or 0300 for type 1. + * If you have another to report, please do + * + * Name sd->sensor_type reported by + * +- * Sakar Spy-shot 0 T. Kilgore ++ * Sakar 56379 Spy-shot 0 T. Kilgore + * Innovage 0 T. Kilgore + * Vivitar Mini 0 H. De Goede + * Vivitar Mini 0 E. Rodriguez +@@ -487,7 +532,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + * Philips dig. keych. 1 T. Kilgore + * Trust Spyc@m 100 1 A. Jacobs + */ +- switch (gspca_dev->usb_buf[1]) { ++ switch (gspca_dev->usb_buf[0]) { + case 2: + sd->sensor_type = 0; + break; +@@ -504,20 +549,19 @@ static int sd_config(struct gspca_dev *gspca_dev, + } else { + sd->cam_type = CAM_TYPE_VGA; + +- err_code = cam_get_response16(gspca_dev, 0x07, 1); +- if (err_code < 0) +- return err_code; +- + /* +- * Here is a table of the responses to the previous command +- * from the known MR97310A VGA cameras. ++ * Here is a table of the responses to the query for sensor ++ * type, from the known MR97310A VGA cameras. Six different ++ * cameras of which five share the same USB ID. + * + * Name gspca_dev->usb_buf[] sd->sensor_type + * sd->do_lcd_stop + * Aiptek Pencam VGA+ 0300 0 1 +- * ION digital 0350 0 1 ++ * ION digital 0300 0 1 + * Argus DC-1620 0450 1 0 + * Argus QuickClix 0420 1 1 ++ * Sakar 77379 Digital 0350 0 1 ++ * Sakar 1638x CyberPix 0120 0 2 + * + * Based upon these results, we assume default settings + * and then correct as necessary, as follows. +@@ -527,10 +571,12 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->sensor_type = 1; + sd->do_lcd_stop = 0; + sd->adj_colors = 0; +- if ((gspca_dev->usb_buf[0] != 0x03) && ++ if (gspca_dev->usb_buf[0] == 0x01) { ++ sd->sensor_type = 2; ++ } else if ((gspca_dev->usb_buf[0] != 0x03) && + (gspca_dev->usb_buf[0] != 0x04)) { + PDEBUG(D_ERR, "Unknown VGA Sensor id Byte 0: %02x", +- gspca_dev->usb_buf[1]); ++ gspca_dev->usb_buf[0]); + PDEBUG(D_ERR, "Defaults assumed, may not work"); + PDEBUG(D_ERR, "Please report this"); + } +@@ -560,7 +606,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + PDEBUG(D_PROBE, "MR97310A VGA camera detected, sensor: %d", + sd->sensor_type); + } +- /* Stop streaming as we've started it to probe the sensor type. */ ++ /* Stop streaming as we've started it only to probe the sensor type. */ + sd_stopN(gspca_dev); + + if (force_sensor_type != -1) { +@@ -574,9 +620,13 @@ static int sd_config(struct gspca_dev *gspca_dev, + /* No brightness for sensor_type 0 */ + if (sd->sensor_type == 0) + gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) | +- (1 << ARGUS_QC_BRIGHTNESS_IDX); ++ (1 << ARGUS_QC_BRIGHTNESS_IDX) | ++ (1 << CONTRAST_IDX) | ++ (1 << SAKAR_CS_GAIN_IDX); + else + gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX) | ++ (1 << CONTRAST_IDX) | ++ (1 << SAKAR_CS_GAIN_IDX) | + (1 << MIN_CLOCKDIV_IDX); + } else { + /* All controls need to be disabled if VGA sensor_type is 0 */ +@@ -585,17 +635,30 @@ static int sd_config(struct gspca_dev *gspca_dev, + (1 << ARGUS_QC_BRIGHTNESS_IDX) | + (1 << EXPOSURE_IDX) | + (1 << GAIN_IDX) | ++ (1 << CONTRAST_IDX) | ++ (1 << SAKAR_CS_GAIN_IDX) | + (1 << MIN_CLOCKDIV_IDX); +- else if (sd->do_lcd_stop) ++ else if (sd->sensor_type == 2) { ++ gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) | ++ (1 << ARGUS_QC_BRIGHTNESS_IDX) | ++ (1 << GAIN_IDX) | ++ (1 << MIN_CLOCKDIV_IDX); ++ gain_default = MR97310A_CS_GAIN_DEFAULT; ++ } else if (sd->do_lcd_stop) + /* Argus QuickClix has different brightness limits */ +- gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX); ++ gspca_dev->ctrl_dis = (1 << NORM_BRIGHTNESS_IDX) | ++ (1 << CONTRAST_IDX) | ++ (1 << SAKAR_CS_GAIN_IDX); + else +- gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX); ++ gspca_dev->ctrl_dis = (1 << ARGUS_QC_BRIGHTNESS_IDX) | ++ (1 << CONTRAST_IDX) | ++ (1 << SAKAR_CS_GAIN_IDX); + } + + sd->brightness = MR97310A_BRIGHTNESS_DEFAULT; + sd->exposure = MR97310A_EXPOSURE_DEFAULT; +- sd->gain = MR97310A_GAIN_DEFAULT; ++ sd->gain = gain_default; ++ sd->contrast = MR97310A_CONTRAST_DEFAULT; + sd->min_clockdiv = MR97310A_MIN_CLOCKDIV_DEFAULT; + + return 0; +@@ -697,6 +760,12 @@ static int start_cif_cam(struct gspca_dev *gspca_dev) + {0x13, 0x00, {0x01}, 1}, + {0, 0, {0}, 0} + }; ++ /* Without this command the cam won't work with USB-UHCI */ ++ gspca_dev->usb_buf[0] = 0x0a; ++ gspca_dev->usb_buf[1] = 0x00; ++ err_code = mr_write(gspca_dev, 2); ++ if (err_code < 0) ++ return err_code; + err_code = sensor_write_regs(gspca_dev, cif_sensor1_init_data, + ARRAY_SIZE(cif_sensor1_init_data)); + } +@@ -717,6 +786,10 @@ static int start_vga_cam(struct gspca_dev *gspca_dev) + data[5] = 0x00; + data[10] = 0x91; + } ++ if (sd->sensor_type == 2) { ++ data[5] = 0x00; ++ data[10] = 0x18; ++ } + + switch (gspca_dev->width) { + case 160: +@@ -731,6 +804,10 @@ static int start_vga_cam(struct gspca_dev *gspca_dev) + data[4] = 0x78; /* reg 3, V size/4 */ + data[6] = 0x04; /* reg 5, H start */ + data[8] = 0x03; /* reg 7, V start */ ++ if (sd->sensor_type == 2) { ++ data[6] = 2; ++ data[8] = 1; ++ } + if (sd->do_lcd_stop) + data[8] = 0x04; /* Bayer tile shifted */ + break; +@@ -753,7 +830,6 @@ static int start_vga_cam(struct gspca_dev *gspca_dev) + return err_code; + + if (!sd->sensor_type) { +- /* The only known sensor_type 0 cam is the Argus DC-1620 */ + const struct sensor_w_data vga_sensor0_init_data[] = { + {0x01, 0x00, {0x0c, 0x00, 0x04}, 3}, + {0x14, 0x00, {0x01, 0xe4, 0x02, 0x84}, 4}, +@@ -764,7 +840,7 @@ static int start_vga_cam(struct gspca_dev *gspca_dev) + }; + err_code = sensor_write_regs(gspca_dev, vga_sensor0_init_data, + ARRAY_SIZE(vga_sensor0_init_data)); +- } else { /* sd->sensor_type = 1 */ ++ } else if (sd->sensor_type == 1) { + const struct sensor_w_data color_adj[] = { + {0x02, 0x00, {0x06, 0x59, 0x0c, 0x16, 0x00, + /* adjusted blue, green, red gain correct +@@ -802,6 +878,48 @@ static int start_vga_cam(struct gspca_dev *gspca_dev) + + err_code = sensor_write_regs(gspca_dev, vga_sensor1_init_data, + ARRAY_SIZE(vga_sensor1_init_data)); ++ } else { /* sensor type == 2 */ ++ const struct sensor_w_data vga_sensor2_init_data[] = { ++ ++ {0x01, 0x00, {0x48}, 1}, ++ {0x02, 0x00, {0x22}, 1}, ++ /* Reg 3 msb and 4 is lsb of the exposure setting*/ ++ {0x05, 0x00, {0x10}, 1}, ++ {0x06, 0x00, {0x00}, 1}, ++ {0x07, 0x00, {0x00}, 1}, ++ {0x08, 0x00, {0x00}, 1}, ++ {0x09, 0x00, {0x00}, 1}, ++ /* The following are used in the gain control ++ * which is BTW completely borked in the OEM driver ++ * The values for each color go from 0 to 0x7ff ++ *{0x0a, 0x00, {0x01}, 1}, green1 gain msb ++ *{0x0b, 0x00, {0x10}, 1}, green1 gain lsb ++ *{0x0c, 0x00, {0x01}, 1}, red gain msb ++ *{0x0d, 0x00, {0x10}, 1}, red gain lsb ++ *{0x0e, 0x00, {0x01}, 1}, blue gain msb ++ *{0x0f, 0x00, {0x10}, 1}, blue gain lsb ++ *{0x10, 0x00, {0x01}, 1}, green2 gain msb ++ *{0x11, 0x00, {0x10}, 1}, green2 gain lsb ++ */ ++ {0x12, 0x00, {0x00}, 1}, ++ {0x13, 0x00, {0x04}, 1}, /* weird effect on colors */ ++ {0x14, 0x00, {0x00}, 1}, ++ {0x15, 0x00, {0x06}, 1}, ++ {0x16, 0x00, {0x01}, 1}, ++ {0x17, 0x00, {0xe2}, 1}, /* vertical alignment */ ++ {0x18, 0x00, {0x02}, 1}, ++ {0x19, 0x00, {0x82}, 1}, /* don't mess with */ ++ {0x1a, 0x00, {0x00}, 1}, ++ {0x1b, 0x00, {0x20}, 1}, ++ /* {0x1c, 0x00, {0x17}, 1}, contrast control */ ++ {0x1d, 0x00, {0x80}, 1}, /* moving causes a mess */ ++ {0x1e, 0x00, {0x08}, 1}, /* moving jams the camera */ ++ {0x1f, 0x00, {0x0c}, 1}, ++ {0x20, 0x00, {0x00}, 1}, ++ {0, 0, {0}, 0} ++ }; ++ err_code = sensor_write_regs(gspca_dev, vga_sensor2_init_data, ++ ARRAY_SIZE(vga_sensor2_init_data)); + } + return err_code; + } +@@ -834,6 +952,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + return err_code; + + setbrightness(gspca_dev); ++ setcontrast(gspca_dev); + setexposure(gspca_dev); + setgain(gspca_dev); + +@@ -893,7 +1012,7 @@ static void setbrightness(struct gspca_dev *gspca_dev) + static void setexposure(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int exposure; ++ int exposure = MR97310A_EXPOSURE_DEFAULT; + u8 buf[2]; + + if (gspca_dev->ctrl_dis & (1 << EXPOSURE_IDX)) +@@ -905,6 +1024,11 @@ static void setexposure(struct gspca_dev *gspca_dev) + exposure = (sd->exposure * 9267) / 10000 + 300; + sensor_write1(gspca_dev, 3, exposure >> 4); + sensor_write1(gspca_dev, 4, exposure & 0x0f); ++ } else if (sd->sensor_type == 2) { ++ exposure = sd->exposure; ++ exposure >>= 3; ++ sensor_write1(gspca_dev, 3, exposure >> 8); ++ sensor_write1(gspca_dev, 4, exposure & 0xff); + } else { + /* We have both a clock divider and an exposure register. + We first calculate the clock divider, as that determines +@@ -943,17 +1067,34 @@ static void setexposure(struct gspca_dev *gspca_dev) + static void setgain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; ++ u8 gainreg; + +- if (gspca_dev->ctrl_dis & (1 << GAIN_IDX)) ++ if ((gspca_dev->ctrl_dis & (1 << GAIN_IDX)) && ++ (gspca_dev->ctrl_dis & (1 << SAKAR_CS_GAIN_IDX))) + return; + +- if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) { ++ if (sd->cam_type == CAM_TYPE_CIF && sd->sensor_type == 1) + sensor_write1(gspca_dev, 0x0e, sd->gain); +- } else { ++ else if (sd->cam_type == CAM_TYPE_VGA && sd->sensor_type == 2) ++ for (gainreg = 0x0a; gainreg < 0x11; gainreg += 2) { ++ sensor_write1(gspca_dev, gainreg, sd->gain >> 8); ++ sensor_write1(gspca_dev, gainreg + 1, sd->gain & 0xff); ++ } ++ else + sensor_write1(gspca_dev, 0x10, sd->gain); +- } + } + ++static void setcontrast(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (gspca_dev->ctrl_dis & (1 << CONTRAST_IDX)) ++ return; ++ ++ sensor_write1(gspca_dev, 0x1c, sd->contrast); ++} ++ ++ + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -1008,6 +1149,25 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->contrast = val; ++ if (gspca_dev->streaming) ++ setcontrast(gspca_dev); ++ return 0; ++} ++ ++ ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->contrast; ++ return 0; ++} ++ + static int sd_setmin_clockdiv(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +diff --git a/drivers/media/video/gspca/ov519.c b/drivers/media/video/gspca/ov519.c +index b4f9657..16fabc2 100644 +--- a/drivers/media/video/gspca/ov519.c ++++ b/drivers/media/video/gspca/ov519.c +@@ -38,6 +38,7 @@ + */ + #define MODULE_NAME "ov519" + ++#include + #include "gspca.h" + + MODULE_AUTHOR("Jean-Francois Moine "); +@@ -70,6 +71,9 @@ struct sd { + char invert_led; + #define BRIDGE_INVERT_LED 8 + ++ char snapshot_pressed; ++ char snapshot_needs_reset; ++ + /* Determined by sensor type */ + __u8 sif; + +@@ -99,10 +103,12 @@ struct sd { + #define SEN_OV66308AF 5 + #define SEN_OV7610 6 + #define SEN_OV7620 7 +-#define SEN_OV7640 8 +-#define SEN_OV7670 9 +-#define SEN_OV76BE 10 +-#define SEN_OV8610 11 ++#define SEN_OV7620AE 8 ++#define SEN_OV7640 9 ++#define SEN_OV7648 10 ++#define SEN_OV7670 11 ++#define SEN_OV76BE 12 ++#define SEN_OV8610 13 + + u8 sensor_addr; + int sensor_width; +@@ -139,6 +145,7 @@ static void setautobrightness(struct sd *sd); + static void setfreq(struct sd *sd); + + static const struct ctrl sd_ctrls[] = { ++#define BRIGHTNESS_IDX 0 + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -153,6 +160,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setbrightness, + .get = sd_getbrightness, + }, ++#define CONTRAST_IDX 1 + { + { + .id = V4L2_CID_CONTRAST, +@@ -167,6 +175,7 @@ static const struct ctrl sd_ctrls[] = { + .set = sd_setcontrast, + .get = sd_getcontrast, + }, ++#define COLOR_IDX 2 + { + { + .id = V4L2_CID_SATURATION, +@@ -2030,6 +2039,10 @@ static int ov511_i2c_w(struct sd *sd, __u8 reg, __u8 value) + + if ((rc & 2) == 0) /* Ack? */ + break; ++#if 0 ++ /* I2C abort */ ++ reg_w(sd, R511_I2C_CTL, 0x10); ++#endif + if (--retries < 0) { + PDEBUG(D_USBO, "i2c write retries exhausted"); + return -1; +@@ -2554,7 +2567,7 @@ static int ov7xx0_configure(struct sd *sd) + /* I don't know what's different about the 76BE yet. */ + if (i2c_r(sd, 0x15) & 1) { + PDEBUG(D_PROBE, "Sensor is an OV7620AE"); +- sd->sensor = SEN_OV7620; ++ sd->sensor = SEN_OV7620AE; + } else { + PDEBUG(D_PROBE, "Sensor is an OV76BE"); + sd->sensor = SEN_OV76BE; +@@ -2588,7 +2601,7 @@ static int ov7xx0_configure(struct sd *sd) + break; + case 0x48: + PDEBUG(D_PROBE, "Sensor is an OV7648"); +- sd->sensor = SEN_OV7640; /* FIXME */ ++ sd->sensor = SEN_OV7648; + break; + default: + PDEBUG(D_PROBE, "Unknown sensor: 0x76%x", low); +@@ -2680,6 +2693,36 @@ static void ov51x_led_control(struct sd *sd, int on) + } + } + ++static void sd_reset_snapshot(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (!sd->snapshot_needs_reset) ++ return; ++ ++ /* Note it is important that we clear sd->snapshot_needs_reset, ++ before actually clearing the snapshot state in the bridge ++ otherwise we might race with the pkt_scan interrupt handler */ ++ sd->snapshot_needs_reset = 0; ++ ++ switch (sd->bridge) { ++ case BRIDGE_OV511: ++ case BRIDGE_OV511PLUS: ++ reg_w(sd, R51x_SYS_SNAP, 0x02); ++ reg_w(sd, R51x_SYS_SNAP, 0x00); ++ break; ++ case BRIDGE_OV518: ++ case BRIDGE_OV518PLUS: ++ reg_w(sd, R51x_SYS_SNAP, 0x02); /* Reset */ ++ reg_w(sd, R51x_SYS_SNAP, 0x01); /* Enable */ ++ break; ++ case BRIDGE_OV519: ++ reg_w(sd, R51x_SYS_RESET, 0x40); ++ reg_w(sd, R51x_SYS_RESET, 0x00); ++ break; ++ } ++} ++ + static int ov51x_upload_quan_tables(struct sd *sd) + { + const unsigned char yQuanTable511[] = { +@@ -3115,7 +3158,11 @@ static int sd_config(struct gspca_dev *gspca_dev, + (1 << OV7670_FREQ_IDX); + } + sd->quality = QUALITY_DEF; +- if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670) ++ if (sd->sensor == SEN_OV7640 || ++ sd->sensor == SEN_OV7648) ++ gspca_dev->ctrl_dis |= (1 << AUTOBRIGHT_IDX) | ++ (1 << CONTRAST_IDX); ++ if (sd->sensor == SEN_OV7670) + gspca_dev->ctrl_dis |= 1 << AUTOBRIGHT_IDX; + /* OV8610 Frequency filter control should work but needs testing */ + if (sd->sensor == SEN_OV8610) +@@ -3169,10 +3216,12 @@ static int sd_init(struct gspca_dev *gspca_dev) + return -EIO; + break; + case SEN_OV7620: ++ case SEN_OV7620AE: + if (write_i2c_regvals(sd, norm_7620, ARRAY_SIZE(norm_7620))) + return -EIO; + break; + case SEN_OV7640: ++ case SEN_OV7648: + if (write_i2c_regvals(sd, norm_7640, ARRAY_SIZE(norm_7640))) + return -EIO; + break; +@@ -3246,7 +3295,9 @@ static int ov511_mode_init_regs(struct sd *sd) + /* Note once the FIXME's in mode_init_ov_sensor_regs() are fixed + for more sensors we need to do this for them too */ + case SEN_OV7620: ++ case SEN_OV7620AE: + case SEN_OV7640: ++ case SEN_OV7648: + case SEN_OV76BE: + if (sd->gspca_dev.width == 320) + interlaced = 1; +@@ -3377,7 +3428,7 @@ static int ov518_mode_init_regs(struct sd *sd) + + if (sd->bridge == BRIDGE_OV518PLUS) { + switch (sd->sensor) { +- case SEN_OV7620: ++ case SEN_OV7620AE: + if (sd->gspca_dev.width == 320) { + reg_w(sd, 0x20, 0x00); + reg_w(sd, 0x21, 0x19); +@@ -3386,6 +3437,10 @@ static int ov518_mode_init_regs(struct sd *sd) + reg_w(sd, 0x21, 0x1f); + } + break; ++ case SEN_OV7620: ++ reg_w(sd, 0x20, 0x00); ++ reg_w(sd, 0x21, 0x19); ++ break; + default: + reg_w(sd, 0x21, 0x19); + } +@@ -3488,7 +3543,8 @@ static int ov519_mode_init_regs(struct sd *sd) + if (write_regvals(sd, mode_init_519, + ARRAY_SIZE(mode_init_519))) + return -EIO; +- if (sd->sensor == SEN_OV7640) { ++ if (sd->sensor == SEN_OV7640 || ++ sd->sensor == SEN_OV7648) { + /* Select 8-bit input mode */ + reg_w_mask(sd, OV519_R20_DFR, 0x10, 0x10); + } +@@ -3503,6 +3559,9 @@ static int ov519_mode_init_regs(struct sd *sd) + if (sd->sensor == SEN_OV7670 && + sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv) + reg_w(sd, OV519_R12_X_OFFSETL, 0x04); ++ else if (sd->sensor == SEN_OV7648 && ++ sd->gspca_dev.cam.cam_mode[sd->gspca_dev.curr_mode].priv) ++ reg_w(sd, OV519_R12_X_OFFSETL, 0x01); + else + reg_w(sd, OV519_R12_X_OFFSETL, 0x00); + reg_w(sd, OV519_R13_X_OFFSETH, 0x00); +@@ -3520,6 +3579,7 @@ static int ov519_mode_init_regs(struct sd *sd) + sd->clockdiv = 0; + switch (sd->sensor) { + case SEN_OV7640: ++ case SEN_OV7648: + switch (sd->frame_rate) { + default: + /* case 30: */ +@@ -3637,6 +3697,14 @@ static int mode_init_ov_sensor_regs(struct sd *sd) + case SEN_OV8610: + /* For OV8610 qvga means qsvga */ + i2c_w_mask(sd, OV7610_REG_COM_C, qvga ? (1 << 5) : 0, 1 << 5); ++#if 0 ++ /* FIXME: Does this improve the image quality or frame rate? */ ++ i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); ++ i2c_w(sd, 0x24, 0x10); ++ i2c_w(sd, 0x25, qvga ? 0x40 : 0x8a); ++ i2c_w(sd, 0x2f, qvga ? 0x30 : 0xb0); ++ i2c_w(sd, 0x35, qvga ? 0x1c : 0x9c); ++#endif + i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ + i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ + i2c_w_mask(sd, 0x2d, 0x00, 0x40); /* from windrv 090403 */ +@@ -3644,11 +3712,19 @@ static int mode_init_ov_sensor_regs(struct sd *sd) + break; + case SEN_OV7610: + i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); ++#if 0 ++ /* FIXME: Does this improve the image quality or frame rate? */ ++ i2c_w_mask(sd, 0x28, qvga?0x00:0x20, 0x20); ++ i2c_w(sd, 0x24, 0x10); ++ i2c_w(sd, 0x25, qvga?0x40:0x8a); ++ i2c_w(sd, 0x2f, qvga?0x30:0xb0); ++#endif + i2c_w(sd, 0x35, qvga?0x1e:0x9e); + i2c_w_mask(sd, 0x13, 0x00, 0x20); /* Select 16 bit data bus */ + i2c_w_mask(sd, 0x12, 0x04, 0x06); /* AWB: 1 Test pattern: 0 */ + break; + case SEN_OV7620: ++ case SEN_OV7620AE: + case SEN_OV76BE: + i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); + i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); +@@ -3663,13 +3739,16 @@ static int mode_init_ov_sensor_regs(struct sd *sd) + i2c_w(sd, 0x35, qvga ? 0x1e : 0x9e); + break; + case SEN_OV7640: ++ case SEN_OV7648: + i2c_w_mask(sd, 0x14, qvga ? 0x20 : 0x00, 0x20); + i2c_w_mask(sd, 0x28, qvga ? 0x00 : 0x20, 0x20); +-/* i2c_w(sd, 0x24, qvga ? 0x20 : 0x3a); */ +-/* i2c_w(sd, 0x25, qvga ? 0x30 : 0x60); */ +-/* i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); */ +-/* i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); */ +-/* i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); */ ++ /* Setting this undocumented bit in qvga mode removes a very ++ annoying vertical shaking of the image */ ++ i2c_w_mask(sd, 0x2d, qvga ? 0x40 : 0x00, 0x40); ++ /* Unknown */ ++ i2c_w_mask(sd, 0x67, qvga ? 0xf0 : 0x90, 0xf0); ++ /* Allow higher automatic gain (to allow higher framerates) */ ++ i2c_w_mask(sd, 0x74, qvga ? 0x20 : 0x00, 0x20); + i2c_w_mask(sd, 0x12, 0x04, 0x04); /* AWB: 1 */ + break; + case SEN_OV7670: +@@ -3795,11 +3874,13 @@ static int set_ov_sensor_window(struct sd *sd) + } + break; + case SEN_OV7620: ++ case SEN_OV7620AE: + hwsbase = 0x2f; /* From 7620.SET (spec is wrong) */ + hwebase = 0x2f; + vwsbase = vwebase = 0x05; + break; + case SEN_OV7640: ++ case SEN_OV7648: + hwsbase = 0x1a; + hwebase = 0x1a; + vwsbase = vwebase = 0x03; +@@ -3893,6 +3974,12 @@ static int sd_start(struct gspca_dev *gspca_dev) + setautobrightness(sd); + setfreq(sd); + ++ /* Force clear snapshot state in case the snapshot button was ++ pressed while we weren't streaming */ ++ sd->snapshot_needs_reset = 1; ++ sd_reset_snapshot(gspca_dev); ++ sd->snapshot_pressed = 0; ++ + ret = ov51x_restart(sd); + if (ret < 0) + goto out; +@@ -3919,6 +4006,34 @@ static void sd_stop0(struct gspca_dev *gspca_dev) + w9968cf_stop0(sd); + } + ++static void ov51x_handle_button(struct gspca_dev *gspca_dev, u8 state) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (sd->snapshot_pressed != state) { ++#ifdef CONFIG_INPUT ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, state); ++ input_sync(gspca_dev->input_dev); ++#endif ++ if (state) ++ sd->snapshot_needs_reset = 1; ++ ++ sd->snapshot_pressed = state; ++ } else { ++ /* On the ov511 / ov519 we need to reset the button state ++ multiple times, as resetting does not work as long as the ++ button stays pressed */ ++ switch (sd->bridge) { ++ case BRIDGE_OV511: ++ case BRIDGE_OV511PLUS: ++ case BRIDGE_OV519: ++ if (state) ++ sd->snapshot_needs_reset = 1; ++ break; ++ } ++ } ++} ++ + static void ov511_pkt_scan(struct gspca_dev *gspca_dev, + u8 *in, /* isoc packet */ + int len) /* iso packet length */ +@@ -3940,6 +4055,7 @@ static void ov511_pkt_scan(struct gspca_dev *gspca_dev, + */ + if (!(in[0] | in[1] | in[2] | in[3] | in[4] | in[5] | in[6] | in[7]) && + (in[8] & 0x08)) { ++ ov51x_handle_button(gspca_dev, (in[8] >> 2) & 1); + if (in[8] & 0x80) { + /* Frame end */ + if ((in[9] + 1) * 8 != gspca_dev->width || +@@ -3977,6 +4093,7 @@ static void ov518_pkt_scan(struct gspca_dev *gspca_dev, + /* A false positive here is likely, until OVT gives me + * the definitive SOF/EOF format */ + if ((!(data[0] | data[1] | data[2] | data[3] | data[5])) && data[6]) { ++ ov51x_handle_button(gspca_dev, (data[6] >> 1) & 1); + gspca_frame_add(gspca_dev, LAST_PACKET, NULL, 0); + gspca_frame_add(gspca_dev, FIRST_PACKET, NULL, 0); + sd->packet_nr = 0; +@@ -4024,6 +4141,9 @@ static void ov519_pkt_scan(struct gspca_dev *gspca_dev, + if (data[0] == 0xff && data[1] == 0xff && data[2] == 0xff) { + switch (data[3]) { + case 0x50: /* start of frame */ ++ /* Don't check the button state here, as the state ++ usually (always ?) changes at EOF and checking it ++ here leads to unnecessary snapshot state resets. */ + #define HDRSZ 16 + data += HDRSZ; + len -= HDRSZ; +@@ -4035,6 +4155,7 @@ static void ov519_pkt_scan(struct gspca_dev *gspca_dev, + gspca_dev->last_packet_type = DISCARD_PACKET; + return; + case 0x51: /* end of frame */ ++ ov51x_handle_button(gspca_dev, data[11] & 1); + if (data[9] != 0) + gspca_dev->last_packet_type = DISCARD_PACKET; + gspca_frame_add(gspca_dev, LAST_PACKET, +@@ -4103,9 +4224,11 @@ static void setbrightness(struct gspca_dev *gspca_dev) + case SEN_OV6630: + case SEN_OV66308AF: + case SEN_OV7640: ++ case SEN_OV7648: + i2c_w(sd, OV7610_REG_BRT, val); + break; + case SEN_OV7620: ++ case SEN_OV7620AE: + /* 7620 doesn't like manual changes when in auto mode */ + if (!sd->autobrightness) + i2c_w(sd, OV7610_REG_BRT, val); +@@ -4142,7 +4265,8 @@ static void setcontrast(struct gspca_dev *gspca_dev) + i2c_w(sd, 0x64, ctab[val >> 5]); + break; + } +- case SEN_OV7620: { ++ case SEN_OV7620: ++ case SEN_OV7620AE: { + static const __u8 ctab[] = { + 0x01, 0x05, 0x09, 0x11, 0x15, 0x35, 0x37, 0x57, + 0x5b, 0xa5, 0xa7, 0xc7, 0xc9, 0xcf, 0xef, 0xff +@@ -4152,10 +4276,6 @@ static void setcontrast(struct gspca_dev *gspca_dev) + i2c_w(sd, 0x64, ctab[val >> 4]); + break; + } +- case SEN_OV7640: +- /* Use gain control instead. */ +- i2c_w(sd, OV7610_REG_GAIN, val >> 2); +- break; + case SEN_OV7670: + /* check that this isn't just the same as ov7610 */ + i2c_w(sd, OV7670_REG_CONTRAS, val >> 1); +@@ -4179,6 +4299,7 @@ static void setcolors(struct gspca_dev *gspca_dev) + i2c_w(sd, OV7610_REG_SAT, val); + break; + case SEN_OV7620: ++ case SEN_OV7620AE: + /* Use UV gamma control instead. Bits 0 & 7 are reserved. */ + /* rc = ov_i2c_write(sd->dev, 0x62, (val >> 9) & 0x7e); + if (rc < 0) +@@ -4186,6 +4307,7 @@ static void setcolors(struct gspca_dev *gspca_dev) + i2c_w(sd, OV7610_REG_SAT, val); + break; + case SEN_OV7640: ++ case SEN_OV7648: + i2c_w(sd, OV7610_REG_SAT, val & 0xf0); + break; + case SEN_OV7670: +@@ -4198,7 +4320,8 @@ static void setcolors(struct gspca_dev *gspca_dev) + + static void setautobrightness(struct sd *sd) + { +- if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7670 || ++ if (sd->sensor == SEN_OV7640 || sd->sensor == SEN_OV7648 || ++ sd->sensor == SEN_OV7670 || + sd->sensor == SEN_OV2610 || sd->sensor == SEN_OV3610) + return; + +@@ -4475,9 +4598,13 @@ static const struct sd_desc sd_desc = { + .stopN = sd_stopN, + .stop0 = sd_stop0, + .pkt_scan = sd_pkt_scan, ++ .dq_callback = sd_reset_snapshot, + .querymenu = sd_querymenu, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, ++#ifdef CONFIG_INPUT ++ .other_input = 1, ++#endif + }; + + /* -- module initialisation -- */ +@@ -4494,7 +4621,8 @@ static const __devinitdata struct usb_device_id device_table[] = { + .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, + {USB_DEVICE(0x045e, 0x028c), .driver_info = BRIDGE_OV519 }, + {USB_DEVICE(0x054c, 0x0154), .driver_info = BRIDGE_OV519 }, +- {USB_DEVICE(0x054c, 0x0155), .driver_info = BRIDGE_OV519 }, ++ {USB_DEVICE(0x054c, 0x0155), ++ .driver_info = BRIDGE_OV519 | BRIDGE_INVERT_LED }, + {USB_DEVICE(0x05a9, 0x0511), .driver_info = BRIDGE_OV511 }, + {USB_DEVICE(0x05a9, 0x0518), .driver_info = BRIDGE_OV518 }, + {USB_DEVICE(0x05a9, 0x0519), .driver_info = BRIDGE_OV519 }, +diff --git a/drivers/media/video/gspca/ov534.c b/drivers/media/video/gspca/ov534.c +index 0a6b8f0..957e05e 100644 +--- a/drivers/media/video/gspca/ov534.c ++++ b/drivers/media/video/gspca/ov534.c +@@ -1,5 +1,5 @@ + /* +- * ov534 gspca driver ++ * ov534-ov772x gspca driver + * + * Copyright (C) 2008 Antonio Ospite + * Copyright (C) 2008 Jim Paris +@@ -68,12 +68,7 @@ struct sd { + s8 sharpness; + u8 hflip; + u8 vflip; +- u8 satur; +- u8 lightfreq; + +- u8 sensor; +-#define SENSOR_OV772X 0 +-#define SENSOR_OV965X 1 + }; + + /* V4L2 controls supported by the driver */ +@@ -101,12 +96,8 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); +-static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val); +-static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val); +-static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); +-static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls_ov772x[] = { ++static const struct ctrl sd_ctrls[] = { + { /* 0 */ + { + .id = V4L2_CID_BRIGHTNESS, +@@ -115,8 +106,8 @@ static struct ctrl sd_ctrls_ov772x[] = { + .minimum = 0, + .maximum = 255, + .step = 1, +-#define BRIGHTNESS_77_DEF 20 +- .default_value = BRIGHTNESS_77_DEF, ++#define BRIGHTNESS_DEF 20 ++ .default_value = BRIGHTNESS_DEF, + }, + .set = sd_setbrightness, + .get = sd_getbrightness, +@@ -129,8 +120,8 @@ static struct ctrl sd_ctrls_ov772x[] = { + .minimum = 0, + .maximum = 255, + .step = 1, +-#define CONTRAST_77_DEF 37 +- .default_value = CONTRAST_77_DEF, ++#define CONTRAST_DEF 37 ++ .default_value = CONTRAST_DEF, + }, + .set = sd_setcontrast, + .get = sd_getcontrast, +@@ -157,8 +148,8 @@ static struct ctrl sd_ctrls_ov772x[] = { + .minimum = 0, + .maximum = 255, + .step = 1, +-#define EXPO_77_DEF 120 +- .default_value = EXPO_77_DEF, ++#define EXPO_DEF 120 ++ .default_value = EXPO_DEF, + }, + .set = sd_setexposure, + .get = sd_getexposure, +@@ -213,13 +204,13 @@ static struct ctrl sd_ctrls_ov772x[] = { + .minimum = 0, + .maximum = 1, + .step = 1, +-#define AUTOGAIN_77_DEF 0 +- .default_value = AUTOGAIN_77_DEF, ++#define AUTOGAIN_DEF 0 ++ .default_value = AUTOGAIN_DEF, + }, + .set = sd_setautogain, + .get = sd_getautogain, + }, +-#define AWB_77_IDX 8 ++#define AWB_IDX 8 + { /* 8 */ + { + .id = V4L2_CID_AUTO_WHITE_BALANCE, +@@ -242,8 +233,8 @@ static struct ctrl sd_ctrls_ov772x[] = { + .minimum = 0, + .maximum = 63, + .step = 1, +-#define SHARPNESS_77_DEF 0 +- .default_value = SHARPNESS_77_DEF, ++#define SHARPNESS_DEF 0 ++ .default_value = SHARPNESS_DEF, + }, + .set = sd_setsharpness, + .get = sd_getsharpness, +@@ -277,107 +268,6 @@ static struct ctrl sd_ctrls_ov772x[] = { + .get = sd_getvflip, + }, + }; +-static struct ctrl sd_ctrls_ov965x[] = { +- { /* 0 */ +- { +- .id = V4L2_CID_BRIGHTNESS, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Brightness", +- .minimum = 0, +- .maximum = 15, +- .step = 1, +-#define BRIGHTNESS_96_DEF 7 +- .default_value = BRIGHTNESS_96_DEF, +- }, +- .set = sd_setbrightness, +- .get = sd_getbrightness, +- }, +- { /* 1 */ +- { +- .id = V4L2_CID_CONTRAST, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Contrast", +- .minimum = 0, +- .maximum = 15, +- .step = 1, +-#define CONTRAST_96_DEF 3 +- .default_value = CONTRAST_96_DEF, +- }, +- .set = sd_setcontrast, +- .get = sd_getcontrast, +- }, +- { /* 2 */ +- { +- .id = V4L2_CID_AUTOGAIN, +- .type = V4L2_CTRL_TYPE_BOOLEAN, +- .name = "Autogain", +- .minimum = 0, +- .maximum = 1, +- .step = 1, +-#define AUTOGAIN_96_DEF 1 +- .default_value = AUTOGAIN_96_DEF, +- }, +- .set = sd_setautogain, +- .get = sd_getautogain, +- }, +-#define EXPO_96_IDX 3 +- { /* 3 */ +- { +- .id = V4L2_CID_EXPOSURE, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Exposure", +- .minimum = 0, +- .maximum = 3, +- .step = 1, +-#define EXPO_96_DEF 0 +- .default_value = EXPO_96_DEF, +- }, +- .set = sd_setexposure, +- .get = sd_getexposure, +- }, +- { /* 4 */ +- { +- .id = V4L2_CID_SHARPNESS, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Sharpness", +- .minimum = -1, /* -1 = auto */ +- .maximum = 4, +- .step = 1, +-#define SHARPNESS_96_DEF -1 +- .default_value = SHARPNESS_96_DEF, +- }, +- .set = sd_setsharpness, +- .get = sd_getsharpness, +- }, +- { /* 5 */ +- { +- .id = V4L2_CID_SATURATION, +- .type = V4L2_CTRL_TYPE_INTEGER, +- .name = "Saturation", +- .minimum = 0, +- .maximum = 4, +- .step = 1, +-#define SATUR_DEF 2 +- .default_value = SATUR_DEF, +- }, +- .set = sd_setsatur, +- .get = sd_getsatur, +- }, +- { +- { +- .id = V4L2_CID_POWER_LINE_FREQUENCY, +- .type = V4L2_CTRL_TYPE_MENU, +- .name = "Light frequency filter", +- .minimum = 0, +- .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ +- .step = 1, +-#define FREQ_DEF 0 +- .default_value = FREQ_DEF, +- }, +- .set = sd_setfreq, +- .get = sd_getfreq, +- }, +-}; + + static const struct v4l2_pix_format ov772x_mode[] = { + {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, +@@ -392,35 +282,21 @@ static const struct v4l2_pix_format ov772x_mode[] = { + .priv = 0}, + }; + +-static const struct v4l2_pix_format ov965x_mode[] = { +- {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, +- .bytesperline = 320, +- .sizeimage = 320 * 240 * 3 / 8 + 590, +- .colorspace = V4L2_COLORSPACE_JPEG, +- .priv = 4}, +- {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, +- .bytesperline = 640, +- .sizeimage = 640 * 480 * 3 / 8 + 590, +- .colorspace = V4L2_COLORSPACE_JPEG, +- .priv = 3}, +- {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, +- .bytesperline = 800, +- .sizeimage = 800 * 600 * 3 / 8 + 590, +- .colorspace = V4L2_COLORSPACE_JPEG, +- .priv = 2}, +- {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, +- .bytesperline = 1024, +- .sizeimage = 1024 * 768 * 3 / 8 + 590, +- .colorspace = V4L2_COLORSPACE_JPEG, +- .priv = 1}, +- {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, +- .bytesperline = 1280, +- .sizeimage = 1280 * 1024 * 3 / 8 + 590, +- .colorspace = V4L2_COLORSPACE_JPEG, +- .priv = 0}, ++static const u8 qvga_rates[] = {125, 100, 75, 60, 50, 40, 30}; ++static const u8 vga_rates[] = {60, 50, 40, 30, 15}; ++ ++static const struct framerates ov772x_framerates[] = { ++ { /* 320x240 */ ++ .rates = qvga_rates, ++ .nrates = ARRAY_SIZE(qvga_rates), ++ }, ++ { /* 640x480 */ ++ .rates = vga_rates, ++ .nrates = ARRAY_SIZE(vga_rates), ++ }, + }; + +-static const u8 bridge_init_ov772x[][2] = { ++static const u8 bridge_init[][2] = { + { 0xc2, 0x0c }, + { 0x88, 0xf8 }, + { 0xc3, 0x69 }, +@@ -478,7 +354,7 @@ static const u8 bridge_init_ov772x[][2] = { + { 0xc1, 0x3c }, + { 0xc2, 0x0c }, + }; +-static const u8 sensor_init_ov772x[][2] = { ++static const u8 sensor_init[][2] = { + { 0x12, 0x80 }, + { 0x11, 0x01 }, + /*fixme: better have a delay?*/ +@@ -571,7 +447,7 @@ static const u8 sensor_init_ov772x[][2] = { + { 0x8e, 0x00 }, /* De-noise threshold */ + { 0x0c, 0xd0 } + }; +-static const u8 bridge_start_ov772x_vga[][2] = { ++static const u8 bridge_start_vga[][2] = { + {0x1c, 0x00}, + {0x1d, 0x40}, + {0x1d, 0x02}, +@@ -582,7 +458,7 @@ static const u8 bridge_start_ov772x_vga[][2] = { + {0xc0, 0x50}, + {0xc1, 0x3c}, + }; +-static const u8 sensor_start_ov772x_vga[][2] = { ++static const u8 sensor_start_vga[][2] = { + {0x12, 0x00}, + {0x17, 0x26}, + {0x18, 0xa0}, +@@ -592,7 +468,7 @@ static const u8 sensor_start_ov772x_vga[][2] = { + {0x2c, 0xf0}, + {0x65, 0x20}, + }; +-static const u8 bridge_start_ov772x_qvga[][2] = { ++static const u8 bridge_start_qvga[][2] = { + {0x1c, 0x00}, + {0x1d, 0x40}, + {0x1d, 0x02}, +@@ -603,7 +479,7 @@ static const u8 bridge_start_ov772x_qvga[][2] = { + {0xc0, 0x28}, + {0xc1, 0x1e}, + }; +-static const u8 sensor_start_ov772x_qvga[][2] = { ++static const u8 sensor_start_qvga[][2] = { + {0x12, 0x40}, + {0x17, 0x3f}, + {0x18, 0x50}, +@@ -614,571 +490,6 @@ static const u8 sensor_start_ov772x_qvga[][2] = { + {0x65, 0x2f}, + }; + +-static const u8 bridge_init_ov965x[][2] = { +- {0x88, 0xf8}, +- {0x89, 0xff}, +- {0x76, 0x03}, +- {0x92, 0x03}, +- {0x95, 0x10}, +- {0xe2, 0x00}, +- {0xe7, 0x3e}, +- {0x8d, 0x1c}, +- {0x8e, 0x00}, +- {0x8f, 0x00}, +- {0x1f, 0x00}, +- {0xc3, 0xf9}, +- {0x89, 0xff}, +- {0x88, 0xf8}, +- {0x76, 0x03}, +- {0x92, 0x01}, +- {0x93, 0x18}, +- {0x1c, 0x0a}, +- {0x1d, 0x48}, +- {0xc0, 0x50}, +- {0xc1, 0x3c}, +- {0x34, 0x05}, +- {0xc2, 0x0c}, +- {0xc3, 0xf9}, +- {0x34, 0x05}, +- {0xe7, 0x2e}, +- {0x31, 0xf9}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0x25, 0x42}, +- {0x94, 0x11}, +-}; +- +-static const u8 sensor_init_ov965x[][2] = { +- {0x12, 0x80}, /* com7 - SSCB reset */ +- {0x00, 0x00}, /* gain */ +- {0x01, 0x80}, /* blue */ +- {0x02, 0x80}, /* red */ +- {0x03, 0x1b}, /* vref */ +- {0x04, 0x03}, /* com1 - exposure low bits */ +- {0x0b, 0x57}, /* ver */ +- {0x0e, 0x61}, /* com5 */ +- {0x0f, 0x42}, /* com6 */ +- {0x11, 0x00}, /* clkrc */ +- {0x12, 0x02}, /* com7 - 15fps VGA YUYV */ +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +- {0x14, 0x28}, /* com9 */ +- {0x16, 0x24}, /* reg16 */ +- {0x17, 0x1d}, /* hstart*/ +- {0x18, 0xbd}, /* hstop */ +- {0x19, 0x01}, /* vstrt */ +- {0x1a, 0x81}, /* vstop*/ +- {0x1e, 0x04}, /* mvfp */ +- {0x24, 0x3c}, /* aew */ +- {0x25, 0x36}, /* aeb */ +- {0x26, 0x71}, /* vpt */ +- {0x27, 0x08}, /* bbias */ +- {0x28, 0x08}, /* gbbias */ +- {0x29, 0x15}, /* gr com */ +- {0x2a, 0x00}, /* exhch */ +- {0x2b, 0x00}, /* exhcl */ +- {0x2c, 0x08}, /* rbias */ +- {0x32, 0xff}, /* href */ +- {0x33, 0x00}, /* chlf */ +- {0x34, 0x3f}, /* aref1 */ +- {0x35, 0x00}, /* aref2 */ +- {0x36, 0xf8}, /* aref3 */ +- {0x38, 0x72}, /* adc2 */ +- {0x39, 0x57}, /* aref4 */ +- {0x3a, 0x80}, /* tslb - yuyv */ +- {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ +- {0x3d, 0x99}, /* com13 */ +- {0x3f, 0xc1}, /* edge */ +- {0x40, 0xc0}, /* com15 */ +- {0x41, 0x40}, /* com16 */ +- {0x42, 0xc0}, /* com17 */ +- {0x43, 0x0a}, /* rsvd */ +- {0x44, 0xf0}, +- {0x45, 0x46}, +- {0x46, 0x62}, +- {0x47, 0x2a}, +- {0x48, 0x3c}, +- {0x4a, 0xfc}, +- {0x4b, 0xfc}, +- {0x4c, 0x7f}, +- {0x4d, 0x7f}, +- {0x4e, 0x7f}, +- {0x4f, 0x98}, /* matrix */ +- {0x50, 0x98}, +- {0x51, 0x00}, +- {0x52, 0x28}, +- {0x53, 0x70}, +- {0x54, 0x98}, +- {0x58, 0x1a}, /* matrix coef sign */ +- {0x59, 0x85}, /* AWB control */ +- {0x5a, 0xa9}, +- {0x5b, 0x64}, +- {0x5c, 0x84}, +- {0x5d, 0x53}, +- {0x5e, 0x0e}, +- {0x5f, 0xf0}, /* AWB blue limit */ +- {0x60, 0xf0}, /* AWB red limit */ +- {0x61, 0xf0}, /* AWB green limit */ +- {0x62, 0x00}, /* lcc1 */ +- {0x63, 0x00}, /* lcc2 */ +- {0x64, 0x02}, /* lcc3 */ +- {0x65, 0x16}, /* lcc4 */ +- {0x66, 0x01}, /* lcc5 */ +- {0x69, 0x02}, /* hv */ +- {0x6b, 0x5a}, /* dbvl */ +- {0x6c, 0x04}, +- {0x6d, 0x55}, +- {0x6e, 0x00}, +- {0x6f, 0x9d}, +- {0x70, 0x21}, /* dnsth */ +- {0x71, 0x78}, +- {0x72, 0x00}, /* poidx */ +- {0x73, 0x01}, /* pckdv */ +- {0x74, 0x3a}, /* xindx */ +- {0x75, 0x35}, /* yindx */ +- {0x76, 0x01}, +- {0x77, 0x02}, +- {0x7a, 0x12}, /* gamma curve */ +- {0x7b, 0x08}, +- {0x7c, 0x16}, +- {0x7d, 0x30}, +- {0x7e, 0x5e}, +- {0x7f, 0x72}, +- {0x80, 0x82}, +- {0x81, 0x8e}, +- {0x82, 0x9a}, +- {0x83, 0xa4}, +- {0x84, 0xac}, +- {0x85, 0xb8}, +- {0x86, 0xc3}, +- {0x87, 0xd6}, +- {0x88, 0xe6}, +- {0x89, 0xf2}, +- {0x8a, 0x03}, +- {0x8c, 0x89}, /* com19 */ +- {0x14, 0x28}, /* com9 */ +- {0x90, 0x7d}, +- {0x91, 0x7b}, +- {0x9d, 0x03}, /* lcc6 */ +- {0x9e, 0x04}, /* lcc7 */ +- {0x9f, 0x7a}, +- {0xa0, 0x79}, +- {0xa1, 0x40}, /* aechm */ +- {0xa4, 0x50}, /* com21 */ +- {0xa5, 0x68}, /* com26 */ +- {0xa6, 0x4a}, /* AWB green */ +- {0xa8, 0xc1}, /* refa8 */ +- {0xa9, 0xef}, /* refa9 */ +- {0xaa, 0x92}, +- {0xab, 0x04}, +- {0xac, 0x80}, /* black level control */ +- {0xad, 0x80}, +- {0xae, 0x80}, +- {0xaf, 0x80}, +- {0xb2, 0xf2}, +- {0xb3, 0x20}, +- {0xb4, 0x20}, /* ctrlb4 */ +- {0xb5, 0x00}, +- {0xb6, 0xaf}, +- {0xbb, 0xae}, +- {0xbc, 0x7f}, /* ADC channel offsets */ +- {0xdb, 0x7f}, +- {0xbe, 0x7f}, +- {0xbf, 0x7f}, +- {0xc0, 0xe2}, +- {0xc1, 0xc0}, +- {0xc2, 0x01}, +- {0xc3, 0x4e}, +- {0xc6, 0x85}, +- {0xc7, 0x80}, /* com24 */ +- {0xc9, 0xe0}, +- {0xca, 0xe8}, +- {0xcb, 0xf0}, +- {0xcc, 0xd8}, +- {0xcd, 0xf1}, +- {0x4f, 0x98}, /* matrix */ +- {0x50, 0x98}, +- {0x51, 0x00}, +- {0x52, 0x28}, +- {0x53, 0x70}, +- {0x54, 0x98}, +- {0x58, 0x1a}, +- {0xff, 0x41}, /* read 41, write ff 00 */ +- {0x41, 0x40}, /* com16 */ +- +- {0xc5, 0x03}, /* 60 Hz banding filter */ +- {0x6a, 0x02}, /* 50 Hz banding filter */ +- +- {0x12, 0x62}, /* com7 - 30fps VGA YUV */ +- {0x36, 0xfa}, /* aref3 */ +- {0x69, 0x0a}, /* hv */ +- {0x8c, 0x89}, /* com22 */ +- {0x14, 0x28}, /* com9 */ +- {0x3e, 0x0c}, +- {0x41, 0x40}, /* com16 */ +- {0x72, 0x00}, +- {0x73, 0x00}, +- {0x74, 0x3a}, +- {0x75, 0x35}, +- {0x76, 0x01}, +- {0xc7, 0x80}, +- {0x03, 0x12}, /* vref */ +- {0x17, 0x16}, /* hstart */ +- {0x18, 0x02}, /* hstop */ +- {0x19, 0x01}, /* vstrt */ +- {0x1a, 0x3d}, /* vstop */ +- {0x32, 0xff}, /* href */ +- {0xc0, 0xaa}, +-}; +- +-static const u8 bridge_init_ov965x_2[][2] = { +- {0x94, 0xaa}, +- {0xf1, 0x60}, +- {0xe5, 0x04}, +- {0xc0, 0x50}, +- {0xc1, 0x3c}, +- {0x8c, 0x00}, +- {0x8d, 0x1c}, +- {0x34, 0x05}, +- +- {0xc2, 0x0c}, +- {0xc3, 0xf9}, +- {0xda, 0x01}, +- {0x50, 0x00}, +- {0x51, 0xa0}, +- {0x52, 0x3c}, +- {0x53, 0x00}, +- {0x54, 0x00}, +- {0x55, 0x00}, +- {0x57, 0x00}, +- {0x5c, 0x00}, +- {0x5a, 0xa0}, +- {0x5b, 0x78}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0x94, 0x11}, +-}; +- +-static const u8 sensor_init_ov965x_2[][2] = { +- {0x3b, 0xc4}, +- {0x1e, 0x04}, /* mvfp */ +- {0x13, 0xe0}, /* com8 */ +- {0x00, 0x00}, /* gain */ +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +- {0x11, 0x03}, /* clkrc */ +- {0x6b, 0x5a}, /* dblv */ +- {0x6a, 0x05}, +- {0xc5, 0x07}, +- {0xa2, 0x4b}, +- {0xa3, 0x3e}, +- {0x2d, 0x00}, +- {0xff, 0x42}, /* read 42, write ff 00 */ +- {0x42, 0xc0}, /* com17 */ +- {0x2d, 0x00}, +- {0xff, 0x42}, /* read 42, write ff 00 */ +- {0x42, 0xc1}, /* com17 */ +-/* sharpness */ +- {0x3f, 0x01}, +- {0xff, 0x42}, /* read 42, write ff 00 */ +- {0x42, 0xc1}, /* com17 */ +-/* saturation */ +- {0x4f, 0x98}, /* matrix */ +- {0x50, 0x98}, +- {0x51, 0x00}, +- {0x52, 0x28}, +- {0x53, 0x70}, +- {0x54, 0x98}, +- {0x58, 0x1a}, +- {0xff, 0x41}, /* read 41, write ff 00 */ +- {0x41, 0x40}, /* com16 */ +-/* contrast */ +- {0x56, 0x40}, +-/* brightness */ +- {0x55, 0x8f}, +-/* expo */ +- {0x10, 0x25}, /* aech - exposure high bits */ +- {0xff, 0x13}, /* read 13, write ff 00 */ +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +-}; +- +-static const u8 sensor_start_ov965x_1_vga[][2] = { /* same for qvga */ +- {0x12, 0x62}, /* com7 - 30fps VGA YUV */ +- {0x36, 0xfa}, /* aref3 */ +- {0x69, 0x0a}, /* hv */ +- {0x8c, 0x89}, /* com22 */ +- {0x14, 0x28}, /* com9 */ +- {0x3e, 0x0c}, /* com14 */ +- {0x41, 0x40}, /* com16 */ +- {0x72, 0x00}, +- {0x73, 0x00}, +- {0x74, 0x3a}, +- {0x75, 0x35}, +- {0x76, 0x01}, +- {0xc7, 0x80}, /* com24 */ +- {0x03, 0x12}, /* vref */ +- {0x17, 0x16}, /* hstart */ +- {0x18, 0x02}, /* hstop */ +- {0x19, 0x01}, /* vstrt */ +- {0x1a, 0x3d}, /* vstop */ +- {0x32, 0xff}, /* href */ +- {0xc0, 0xaa}, +-}; +- +-static const u8 sensor_start_ov965x_1_svga[][2] = { +- {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */ +- {0x36, 0xf8}, /* aref3 */ +- {0x69, 0x02}, /* hv */ +- {0x8c, 0x0d}, /* com22 */ +- {0x3e, 0x0c}, /* com14 */ +- {0x41, 0x40}, /* com16 */ +- {0x72, 0x00}, +- {0x73, 0x01}, +- {0x74, 0x3a}, +- {0x75, 0x35}, +- {0x76, 0x01}, +- {0xc7, 0x80}, /* com24 */ +- {0x03, 0x1b}, /* vref */ +- {0x17, 0x1d}, /* hstart */ +- {0x18, 0xbd}, /* hstop */ +- {0x19, 0x01}, /* vstrt */ +- {0x1a, 0x81}, /* vstop */ +- {0x32, 0xff}, /* href */ +- {0xc0, 0xe2}, +-}; +- +-static const u8 sensor_start_ov965x_1_xga[][2] = { +- {0x12, 0x02}, /* com7 */ +- {0x36, 0xf8}, /* aref3 */ +- {0x69, 0x02}, /* hv */ +- {0x8c, 0x89}, /* com22 */ +- {0x14, 0x28}, /* com9 */ +- {0x3e, 0x0c}, /* com14 */ +- {0x41, 0x40}, /* com16 */ +- {0x72, 0x00}, +- {0x73, 0x01}, +- {0x74, 0x3a}, +- {0x75, 0x35}, +- {0x76, 0x01}, +- {0xc7, 0x80}, /* com24 */ +- {0x03, 0x1b}, /* vref */ +- {0x17, 0x1d}, /* hstart */ +- {0x18, 0xbd}, /* hstop */ +- {0x19, 0x01}, /* vstrt */ +- {0x1a, 0x81}, /* vstop */ +- {0x32, 0xff}, /* href */ +- {0xc0, 0xe2}, +-}; +- +-static const u8 sensor_start_ov965x_1_sxga[][2] = { +- {0x12, 0x02}, /* com7 */ +- {0x36, 0xf8}, /* aref3 */ +- {0x69, 0x02}, /* hv */ +- {0x8c, 0x89}, /* com22 */ +- {0x14, 0x28}, /* com9 */ +- {0x3e, 0x0c}, /* com14 */ +- {0x41, 0x40}, /* com16 */ +- {0x72, 0x00}, +- {0x73, 0x01}, +- {0x74, 0x3a}, +- {0x75, 0x35}, +- {0x76, 0x01}, +- {0xc7, 0x80}, /* com24 */ +- {0x03, 0x1b}, /* vref */ +- {0x17, 0x1d}, /* hstart */ +- {0x18, 0x02}, /* hstop */ +- {0x19, 0x01}, /* vstrt */ +- {0x1a, 0x81}, /* vstop */ +- {0x32, 0xff}, /* href */ +- {0xc0, 0xe2}, +-}; +- +-static const u8 bridge_start_ov965x_qvga[][2] = { +- {0x94, 0xaa}, +- {0xf1, 0x60}, +- {0xe5, 0x04}, +- {0xc0, 0x50}, +- {0xc1, 0x3c}, +- {0x8c, 0x00}, +- {0x8d, 0x1c}, +- {0x34, 0x05}, +- +- {0xc2, 0x4c}, +- {0xc3, 0xf9}, +- {0xda, 0x00}, +- {0x50, 0x00}, +- {0x51, 0xa0}, +- {0x52, 0x78}, +- {0x53, 0x00}, +- {0x54, 0x00}, +- {0x55, 0x00}, +- {0x57, 0x00}, +- {0x5c, 0x00}, +- {0x5a, 0x50}, +- {0x5b, 0x3c}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0x94, 0x11}, +-}; +- +-static const u8 bridge_start_ov965x_vga[][2] = { +- {0x94, 0xaa}, +- {0xf1, 0x60}, +- {0xe5, 0x04}, +- {0xc0, 0x50}, +- {0xc1, 0x3c}, +- {0x8c, 0x00}, +- {0x8d, 0x1c}, +- {0x34, 0x05}, +- {0xc2, 0x0c}, +- {0xc3, 0xf9}, +- {0xda, 0x01}, +- {0x50, 0x00}, +- {0x51, 0xa0}, +- {0x52, 0x3c}, +- {0x53, 0x00}, +- {0x54, 0x00}, +- {0x55, 0x00}, +- {0x57, 0x00}, +- {0x5c, 0x00}, +- {0x5a, 0xa0}, +- {0x5b, 0x78}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0x94, 0x11}, +-}; +- +-static const u8 bridge_start_ov965x_svga[][2] = { +- {0x94, 0xaa}, +- {0xf1, 0x60}, +- {0xe5, 0x04}, +- {0xc0, 0xa0}, +- {0xc1, 0x80}, +- {0x8c, 0x00}, +- {0x8d, 0x1c}, +- {0x34, 0x05}, +- {0xc2, 0x4c}, +- {0xc3, 0xf9}, +- {0x50, 0x00}, +- {0x51, 0x40}, +- {0x52, 0x00}, +- {0x53, 0x00}, +- {0x54, 0x00}, +- {0x55, 0x88}, +- {0x57, 0x00}, +- {0x5c, 0x00}, +- {0x5a, 0xc8}, +- {0x5b, 0x96}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0xda, 0x00}, +- {0x94, 0x11}, +-}; +- +-static const u8 bridge_start_ov965x_xga[][2] = { +- {0x94, 0xaa}, +- {0xf1, 0x60}, +- {0xe5, 0x04}, +- {0xc0, 0xa0}, +- {0xc1, 0x80}, +- {0x8c, 0x00}, +- {0x8d, 0x1c}, +- {0x34, 0x05}, +- {0xc2, 0x4c}, +- {0xc3, 0xf9}, +- {0x50, 0x00}, +- {0x51, 0x40}, +- {0x52, 0x00}, +- {0x53, 0x00}, +- {0x54, 0x00}, +- {0x55, 0x88}, +- {0x57, 0x00}, +- {0x5c, 0x01}, +- {0x5a, 0x00}, +- {0x5b, 0xc0}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0xda, 0x01}, +- {0x94, 0x11}, +-}; +- +-static const u8 bridge_start_ov965x_sxga[][2] = { +- {0x94, 0xaa}, +- {0xf1, 0x60}, +- {0xe5, 0x04}, +- {0xc0, 0xa0}, +- {0xc1, 0x80}, +- {0x8c, 0x00}, +- {0x8d, 0x1c}, +- {0x34, 0x05}, +- {0xc2, 0x0c}, +- {0xc3, 0xf9}, +- {0xda, 0x00}, +- {0x35, 0x02}, +- {0xd9, 0x10}, +- {0x94, 0x11}, +-}; +- +-static const u8 sensor_start_ov965x_2_qvga[][2] = { +- {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */ +- {0x1e, 0x04}, /* mvfp */ +- {0x13, 0xe0}, /* com8 */ +- {0x00, 0x00}, +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +- {0x11, 0x01}, /* clkrc */ +- {0x6b, 0x5a}, /* dblv */ +- {0x6a, 0x02}, /* 50 Hz banding filter */ +- {0xc5, 0x03}, /* 60 Hz banding filter */ +- {0xa2, 0x96}, /* bd50 */ +- {0xa3, 0x7d}, /* bd60 */ +- +- {0xff, 0x13}, /* read 13, write ff 00 */ +- {0x13, 0xe7}, +- {0x3a, 0x80}, /* tslb - yuyv */ +-}; +- +-static const u8 sensor_start_ov965x_2_vga[][2] = { +- {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ +- {0x1e, 0x04}, /* mvfp */ +- {0x13, 0xe0}, /* com8 */ +- {0x00, 0x00}, +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +- {0x11, 0x03}, /* clkrc */ +- {0x6b, 0x5a}, /* dblv */ +- {0x6a, 0x05}, /* 50 Hz banding filter */ +- {0xc5, 0x07}, /* 60 Hz banding filter */ +- {0xa2, 0x4b}, /* bd50 */ +- {0xa3, 0x3e}, /* bd60 */ +- +- {0x2d, 0x00}, /* advfl */ +-}; +- +-static const u8 sensor_start_ov965x_2_svga[][2] = { /* same for xga */ +- {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ +- {0x1e, 0x04}, /* mvfp */ +- {0x13, 0xe0}, /* com8 */ +- {0x00, 0x00}, +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +- {0x11, 0x01}, /* clkrc */ +- {0x6b, 0x5a}, /* dblv */ +- {0x6a, 0x0c}, /* 50 Hz banding filter */ +- {0xc5, 0x0f}, /* 60 Hz banding filter */ +- {0xa2, 0x4e}, /* bd50 */ +- {0xa3, 0x41}, /* bd60 */ +-}; +- +-static const u8 sensor_start_ov965x_2_sxga[][2] = { +- {0x13, 0xe0}, /* com8 */ +- {0x00, 0x00}, +- {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ +- {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ +- {0x1e, 0x04}, /* mvfp */ +- {0x11, 0x01}, /* clkrc */ +- {0x6b, 0x5a}, /* dblv */ +- {0x6a, 0x0c}, /* 50 Hz banding filter */ +- {0xc5, 0x0f}, /* 60 Hz banding filter */ +- {0xa2, 0x4e}, /* bd50 */ +- {0xa3, 0x41}, /* bd60 */ +-}; +- + static void ov534_reg_write(struct gspca_dev *gspca_dev, u16 reg, u8 val) + { + struct usb_device *udev = gspca_dev->dev; +@@ -1360,14 +671,14 @@ static void set_frame_rate(struct gspca_dev *gspca_dev) + PDEBUG(D_PROBE, "frame_rate: %d", r->fps); + } + +-static void setbrightness_77(struct gspca_dev *gspca_dev) ++static void setbrightness(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + + sccb_reg_write(gspca_dev, 0x9B, sd->brightness); + } + +-static void setcontrast_77(struct gspca_dev *gspca_dev) ++static void setcontrast(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + +@@ -1401,7 +712,7 @@ static void setgain(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x00, val); + } + +-static void setexposure_77(struct gspca_dev *gspca_dev) ++static void setexposure(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + u8 val; +@@ -1432,7 +743,7 @@ static void sethue(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x01, sd->hue); + } + +-static void setautogain_77(struct gspca_dev *gspca_dev) ++static void setautogain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + +@@ -1457,7 +768,7 @@ static void setawb(struct gspca_dev *gspca_dev) + sccb_reg_write(gspca_dev, 0x63, 0xaa); /* AWB off */ + } + +-static void setsharpness_77(struct gspca_dev *gspca_dev) ++static void setsharpness(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + u8 val; +@@ -1491,132 +802,6 @@ static void setvflip(struct gspca_dev *gspca_dev) + sccb_reg_read(gspca_dev, 0x0c) & 0x7f); + } + +-/* ov965x specific controls */ +-static void setbrightness_96(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- u8 val; +- +- val = sd->brightness; +- if (val < 8) +- val = 15 - val; /* f .. 8 */ +- else +- val = val - 8; /* 0 .. 7 */ +- sccb_reg_write(gspca_dev, 0x55, /* brtn - brightness adjustment */ +- 0x0f | (val << 4)); +-} +- +-static void setcontrast_96(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sccb_reg_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */ +- sd->contrast << 4); +-} +- +-static void setexposure_96(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- u8 val; +- static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e}; +- +- sccb_reg_write(gspca_dev, 0x10, /* aec[9:2] */ +- expo[sd->exposure]); +- val = sccb_reg_read(gspca_dev, 0x13); /* com8 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- sccb_reg_write(gspca_dev, 0x13, val); +- val = sccb_reg_read(gspca_dev, 0xa1); /* aech */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- sccb_reg_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */ +-} +- +-static void setsharpness_96(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- s8 val; +- +- val = sd->sharpness; +- if (val < 0) { /* auto */ +- val = sccb_reg_read(gspca_dev, 0x42); /* com17 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- sccb_reg_write(gspca_dev, 0x42, val | 0x40); +- /* Edge enhancement strength auto adjust */ +- return; +- } +- if (val != 0) +- val = 1 << (val - 1); +- sccb_reg_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */ +- val); +- val = sccb_reg_read(gspca_dev, 0x42); /* com17 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- sccb_reg_write(gspca_dev, 0x42, val & 0xbf); +-} +- +-static void setautogain_96(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- u8 val; +- +-/*fixme: should adjust agc/awb/aec by different controls */ +- val = sd->autogain; +- val = sccb_reg_read(gspca_dev, 0x13); /* com8 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- if (sd->autogain) +- val |= 0x05; /* agc & aec */ +- else +- val &= 0xfa; +- sccb_reg_write(gspca_dev, 0x13, val); +-} +- +-static void setsatur(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- u8 val1, val2, val3; +- static const u8 matrix[5][2] = { +- {0x14, 0x38}, +- {0x1e, 0x54}, +- {0x28, 0x70}, +- {0x32, 0x8c}, +- {0x48, 0x90} +- }; +- +- val1 = matrix[sd->satur][0]; +- val2 = matrix[sd->satur][1]; +- val3 = val1 + val2; +- sccb_reg_write(gspca_dev, 0x4f, val3); /* matrix coeff */ +- sccb_reg_write(gspca_dev, 0x50, val3); +- sccb_reg_write(gspca_dev, 0x51, 0x00); +- sccb_reg_write(gspca_dev, 0x52, val1); +- sccb_reg_write(gspca_dev, 0x53, val2); +- sccb_reg_write(gspca_dev, 0x54, val3); +- sccb_reg_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */ +- val1 = sccb_reg_read(gspca_dev, 0x41); /* com16 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- sccb_reg_write(gspca_dev, 0x41, val1); +-} +- +-static void setfreq(struct gspca_dev *gspca_dev) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- u8 val; +- +- val = sccb_reg_read(gspca_dev, 0x13); /* com8 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- if (sd->lightfreq == 0) { +- sccb_reg_write(gspca_dev, 0x13, val & 0xdf); +- return; +- } +- sccb_reg_write(gspca_dev, 0x13, val | 0x20); +- +- val = sccb_reg_read(gspca_dev, 0x42); /* com17 */ +- sccb_reg_write(gspca_dev, 0xff, 0x00); +- if (sd->lightfreq == 1) +- val |= 0x01; +- else +- val &= 0xfe; +- sccb_reg_write(gspca_dev, 0x42, val); +-} +- + /* this function is called at probe time */ + static int sd_config(struct gspca_dev *gspca_dev, + const struct usb_device_id *id) +@@ -1624,77 +809,50 @@ static int sd_config(struct gspca_dev *gspca_dev, + struct sd *sd = (struct sd *) gspca_dev; + struct cam *cam; + +- sd->sensor = id->driver_info; +- + cam = &gspca_dev->cam; + +- if (sd->sensor == SENSOR_OV772X) { +- cam->cam_mode = ov772x_mode; +- cam->nmodes = ARRAY_SIZE(ov772x_mode); ++ cam->cam_mode = ov772x_mode; ++ cam->nmodes = ARRAY_SIZE(ov772x_mode); ++ cam->mode_framerates = ov772x_framerates; + +- cam->bulk = 1; +- cam->bulk_size = 16384; +- cam->bulk_nurbs = 2; +- } else { /* ov965x */ +- cam->cam_mode = ov965x_mode; +- cam->nmodes = ARRAY_SIZE(ov965x_mode); +- } ++ cam->bulk = 1; ++ cam->bulk_size = 16384; ++ cam->bulk_nurbs = 2; + + sd->frame_rate = 30; + +- if (sd->sensor == SENSOR_OV772X) { +- sd->brightness = BRIGHTNESS_77_DEF; +- sd->contrast = CONTRAST_77_DEF; +- sd->gain = GAIN_DEF; +- sd->exposure = EXPO_77_DEF; +- sd->redblc = RED_BALANCE_DEF; +- sd->blueblc = BLUE_BALANCE_DEF; +- sd->hue = HUE_DEF; +-#if AUTOGAIN_77_DEF != 0 +- sd->autogain = AUTOGAIN_77_DEF; ++ sd->brightness = BRIGHTNESS_DEF; ++ sd->contrast = CONTRAST_DEF; ++ sd->gain = GAIN_DEF; ++ sd->exposure = EXPO_DEF; ++ sd->redblc = RED_BALANCE_DEF; ++ sd->blueblc = BLUE_BALANCE_DEF; ++ sd->hue = HUE_DEF; ++#if AUTOGAIN_DEF != 0 ++ sd->autogain = AUTOGAIN_DEF; + #else +- gspca_dev->ctrl_inac |= (1 << AWB_77_IDX); ++ gspca_dev->ctrl_inac |= (1 << AWB_IDX); + #endif + #if AWB_DEF != 0 +- sd->awb = AWB_DEF ++ sd->awb = AWB_DEF + #endif +-#if SHARPNESS_77_DEF != 0 +- sd->sharpness = SHARPNESS_77_DEF; ++#if SHARPNESS_DEF != 0 ++ sd->sharpness = SHARPNESS_DEF; + #endif + #if HFLIP_DEF != 0 +- sd->hflip = HFLIP_DEF; ++ sd->hflip = HFLIP_DEF; + #endif + #if VFLIP_DEF != 0 +- sd->vflip = VFLIP_DEF; +-#endif +- } else { +- sd->brightness = BRIGHTNESS_96_DEF; +- sd->contrast = CONTRAST_96_DEF; +-#if AUTOGAIN_96_DEF != 0 +- sd->autogain = AUTOGAIN_96_DEF; +- gspca_dev->ctrl_inac |= (1 << EXPO_96_IDX); ++ sd->vflip = VFLIP_DEF; + #endif +-#if EXPO_96_DEF != 0 +- sd->exposure = EXPO_96_DEF; +-#endif +-#if SHARPNESS_96_DEF != 0 +- sd->sharpness = SHARPNESS_96_DEF; +-#endif +- sd->satur = SATUR_DEF; +- sd->lightfreq = FREQ_DEF; +- } ++ + return 0; + } + + /* this function is called at probe and resume time */ + static int sd_init(struct gspca_dev *gspca_dev) + { +- struct sd *sd = (struct sd *) gspca_dev; + u16 sensor_id; +- static const u8 sensor_addr[2] = { +- 0x42, /* 0 SENSOR_OV772X */ +- 0x60, /* 1 SENSOR_OV965X */ +- }; + + /* reset bridge */ + ov534_reg_write(gspca_dev, 0xe7, 0x3a); +@@ -1702,8 +860,7 @@ static int sd_init(struct gspca_dev *gspca_dev) + msleep(100); + + /* initialize the sensor address */ +- ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, +- sensor_addr[sd->sensor]); ++ ov534_reg_write(gspca_dev, OV534_REG_ADDRESS, 0x42); + + /* reset sensor */ + sccb_reg_write(gspca_dev, 0x12, 0x80); +@@ -1717,64 +874,46 @@ static int sd_init(struct gspca_dev *gspca_dev) + PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); + + /* initialize */ +- switch (sd->sensor) { +- case SENSOR_OV772X: +- reg_w_array(gspca_dev, bridge_init_ov772x, +- ARRAY_SIZE(bridge_init_ov772x)); +- ov534_set_led(gspca_dev, 1); +- sccb_w_array(gspca_dev, sensor_init_ov772x, +- ARRAY_SIZE(sensor_init_ov772x)); +- ov534_reg_write(gspca_dev, 0xe0, 0x09); +- ov534_set_led(gspca_dev, 0); +- set_frame_rate(gspca_dev); +- break; +- default: +-/* case SENSOR_OV965X: */ +- reg_w_array(gspca_dev, bridge_init_ov965x, +- ARRAY_SIZE(bridge_init_ov965x)); +- sccb_w_array(gspca_dev, sensor_init_ov965x, +- ARRAY_SIZE(sensor_init_ov965x)); +- reg_w_array(gspca_dev, bridge_init_ov965x_2, +- ARRAY_SIZE(bridge_init_ov965x_2)); +- sccb_w_array(gspca_dev, sensor_init_ov965x_2, +- ARRAY_SIZE(sensor_init_ov965x_2)); +- ov534_reg_write(gspca_dev, 0xe0, 0x00); +- ov534_reg_write(gspca_dev, 0xe0, 0x01); +- ov534_set_led(gspca_dev, 0); +- ov534_reg_write(gspca_dev, 0xe0, 0x00); +- } ++ reg_w_array(gspca_dev, bridge_init, ++ ARRAY_SIZE(bridge_init)); ++ ov534_set_led(gspca_dev, 1); ++ sccb_w_array(gspca_dev, sensor_init, ++ ARRAY_SIZE(sensor_init)); ++ ov534_reg_write(gspca_dev, 0xe0, 0x09); ++ ov534_set_led(gspca_dev, 0); ++ set_frame_rate(gspca_dev); + + return 0; + } + +-static int sd_start_ov772x(struct gspca_dev *gspca_dev) ++static int sd_start(struct gspca_dev *gspca_dev) + { + int mode; + + mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; + if (mode != 0) { /* 320x240 */ +- reg_w_array(gspca_dev, bridge_start_ov772x_qvga, +- ARRAY_SIZE(bridge_start_ov772x_qvga)); +- sccb_w_array(gspca_dev, sensor_start_ov772x_qvga, +- ARRAY_SIZE(sensor_start_ov772x_qvga)); ++ reg_w_array(gspca_dev, bridge_start_qvga, ++ ARRAY_SIZE(bridge_start_qvga)); ++ sccb_w_array(gspca_dev, sensor_start_qvga, ++ ARRAY_SIZE(sensor_start_qvga)); + } else { /* 640x480 */ +- reg_w_array(gspca_dev, bridge_start_ov772x_vga, +- ARRAY_SIZE(bridge_start_ov772x_vga)); +- sccb_w_array(gspca_dev, sensor_start_ov772x_vga, +- ARRAY_SIZE(sensor_start_ov772x_vga)); ++ reg_w_array(gspca_dev, bridge_start_vga, ++ ARRAY_SIZE(bridge_start_vga)); ++ sccb_w_array(gspca_dev, sensor_start_vga, ++ ARRAY_SIZE(sensor_start_vga)); + } + set_frame_rate(gspca_dev); + +- setautogain_77(gspca_dev); ++ setautogain(gspca_dev); + setawb(gspca_dev); + setgain(gspca_dev); + setredblc(gspca_dev); + setblueblc(gspca_dev); + sethue(gspca_dev); +- setexposure_77(gspca_dev); +- setbrightness_77(gspca_dev); +- setcontrast_77(gspca_dev); +- setsharpness_77(gspca_dev); ++ setexposure(gspca_dev); ++ setbrightness(gspca_dev); ++ setcontrast(gspca_dev); ++ setsharpness(gspca_dev); + setvflip(gspca_dev); + sethflip(gspca_dev); + +@@ -1783,81 +922,12 @@ static int sd_start_ov772x(struct gspca_dev *gspca_dev) + return 0; + } + +-static int sd_start_ov965x(struct gspca_dev *gspca_dev) +-{ +- int mode; +- +- mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; +- switch (mode) { +- default: +-/* case 4: * 320x240 */ +- sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga, +- ARRAY_SIZE(sensor_start_ov965x_1_vga)); +- reg_w_array(gspca_dev, bridge_start_ov965x_qvga, +- ARRAY_SIZE(bridge_start_ov965x_qvga)); +- sccb_w_array(gspca_dev, sensor_start_ov965x_2_qvga, +- ARRAY_SIZE(sensor_start_ov965x_2_qvga)); +- break; +- case 3: /* 640x480 */ +- sccb_w_array(gspca_dev, sensor_start_ov965x_1_vga, +- ARRAY_SIZE(sensor_start_ov965x_1_vga)); +- reg_w_array(gspca_dev, bridge_start_ov965x_vga, +- ARRAY_SIZE(bridge_start_ov965x_vga)); +- sccb_w_array(gspca_dev, sensor_start_ov965x_2_vga, +- ARRAY_SIZE(sensor_start_ov965x_2_vga)); +- break; +- case 2: /* 800x600 */ +- sccb_w_array(gspca_dev, sensor_start_ov965x_1_svga, +- ARRAY_SIZE(sensor_start_ov965x_1_svga)); +- reg_w_array(gspca_dev, bridge_start_ov965x_svga, +- ARRAY_SIZE(bridge_start_ov965x_svga)); +- sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga, +- ARRAY_SIZE(sensor_start_ov965x_2_svga)); +- break; +- case 1: /* 1024x768 */ +- sccb_w_array(gspca_dev, sensor_start_ov965x_1_xga, +- ARRAY_SIZE(sensor_start_ov965x_1_xga)); +- reg_w_array(gspca_dev, bridge_start_ov965x_xga, +- ARRAY_SIZE(bridge_start_ov965x_xga)); +- sccb_w_array(gspca_dev, sensor_start_ov965x_2_svga, +- ARRAY_SIZE(sensor_start_ov965x_2_svga)); +- break; +- case 0: /* 1280x1024 */ +- sccb_w_array(gspca_dev, sensor_start_ov965x_1_sxga, +- ARRAY_SIZE(sensor_start_ov965x_1_sxga)); +- reg_w_array(gspca_dev, bridge_start_ov965x_sxga, +- ARRAY_SIZE(bridge_start_ov965x_sxga)); +- sccb_w_array(gspca_dev, sensor_start_ov965x_2_sxga, +- ARRAY_SIZE(sensor_start_ov965x_2_sxga)); +- break; +- } +- setfreq(gspca_dev); +- setautogain_96(gspca_dev); +- setbrightness_96(gspca_dev); +- setcontrast_96(gspca_dev); +- setexposure_96(gspca_dev); +- setsharpness_96(gspca_dev); +- setsatur(gspca_dev); +- +- ov534_reg_write(gspca_dev, 0xe0, 0x00); +- ov534_reg_write(gspca_dev, 0xe0, 0x00); +- ov534_set_led(gspca_dev, 1); +- return 0; +-} +- +-static void sd_stopN_ov772x(struct gspca_dev *gspca_dev) ++static void sd_stopN(struct gspca_dev *gspca_dev) + { + ov534_reg_write(gspca_dev, 0xe0, 0x09); + ov534_set_led(gspca_dev, 0); + } + +-static void sd_stopN_ov965x(struct gspca_dev *gspca_dev) +-{ +- ov534_reg_write(gspca_dev, 0xe0, 0x01); +- ov534_set_led(gspca_dev, 0); +- ov534_reg_write(gspca_dev, 0xe0, 0x00); +-} +- + /* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ + #define UVC_STREAM_EOH (1 << 7) + #define UVC_STREAM_ERR (1 << 6) +@@ -1875,11 +945,9 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, + __u32 this_pts; + u16 this_fid; + int remaining_len = len; +- int payload_len; + +- payload_len = gspca_dev->cam.bulk ? 2048 : 2040; + do { +- len = min(remaining_len, payload_len); ++ len = min(remaining_len, 2048); + + /* Payloads are prefixed with a UVC-style header. We + consider a frame to start when the FID toggles, or the PTS +@@ -1918,7 +986,17 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, + data + 12, len - 12); + /* If this packet is marked as EOF, end the frame */ + } else if (data[1] & UVC_STREAM_EOF) { ++ struct gspca_frame *frame; ++ + sd->last_pts = 0; ++ frame = gspca_get_i_frame(gspca_dev); ++ if (frame == NULL) ++ goto discard; ++ if (frame->data_end - frame->data + (len - 12) != ++ gspca_dev->width * gspca_dev->height * 2) { ++ PDEBUG(D_PACK, "wrong sized frame"); ++ goto discard; ++ } + gspca_frame_add(gspca_dev, LAST_PACKET, + data + 12, len - 12); + } else { +@@ -1965,12 +1043,8 @@ static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) + struct sd *sd = (struct sd *) gspca_dev; + + sd->exposure = val; +- if (gspca_dev->streaming) { +- if (sd->sensor == SENSOR_OV772X) +- setexposure_77(gspca_dev); +- else +- setexposure_96(gspca_dev); +- } ++ if (gspca_dev->streaming) ++ setexposure(gspca_dev); + return 0; + } + +@@ -1987,12 +1061,8 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) + struct sd *sd = (struct sd *) gspca_dev; + + sd->brightness = val; +- if (gspca_dev->streaming) { +- if (sd->sensor == SENSOR_OV772X) +- setbrightness_77(gspca_dev); +- else +- setbrightness_96(gspca_dev); +- } ++ if (gspca_dev->streaming) ++ setbrightness(gspca_dev); + return 0; + } + +@@ -2009,12 +1079,8 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) + struct sd *sd = (struct sd *) gspca_dev; + + sd->contrast = val; +- if (gspca_dev->streaming) { +- if (sd->sensor == SENSOR_OV772X) +- setcontrast_77(gspca_dev); +- else +- setcontrast_96(gspca_dev); +- } ++ if (gspca_dev->streaming) ++ setcontrast(gspca_dev); + return 0; + } + +@@ -2026,41 +1092,6 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + +-static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sd->satur = val; +- if (gspca_dev->streaming) +- setsatur(gspca_dev); +- return 0; +-} +- +-static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- *val = sd->satur; +- return 0; +-} +-static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- sd->lightfreq = val; +- if (gspca_dev->streaming) +- setfreq(gspca_dev); +- return 0; +-} +- +-static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) +-{ +- struct sd *sd = (struct sd *) gspca_dev; +- +- *val = sd->lightfreq; +- return 0; +-} +- + static int sd_setredblc(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -2122,22 +1153,14 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) + sd->autogain = val; + + if (gspca_dev->streaming) { +- if (sd->sensor == SENSOR_OV772X) { +- +- /* the auto white balance control works only +- * when auto gain is set */ +- if (val) +- gspca_dev->ctrl_inac &= ~(1 << AWB_77_IDX); +- else +- gspca_dev->ctrl_inac |= (1 << AWB_77_IDX); +- setautogain_77(gspca_dev); +- } else { +- if (val) +- gspca_dev->ctrl_inac |= (1 << EXPO_96_IDX); +- else +- gspca_dev->ctrl_inac &= ~(1 << EXPO_96_IDX); +- setautogain_96(gspca_dev); +- } ++ ++ /* the auto white balance control works only ++ * when auto gain is set */ ++ if (val) ++ gspca_dev->ctrl_inac &= ~(1 << AWB_IDX); ++ else ++ gspca_dev->ctrl_inac |= (1 << AWB_IDX); ++ setautogain(gspca_dev); + } + return 0; + } +@@ -2173,12 +1196,8 @@ static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) + struct sd *sd = (struct sd *) gspca_dev; + + sd->sharpness = val; +- if (gspca_dev->streaming) { +- if (sd->sensor == SENSOR_OV772X) +- setsharpness_77(gspca_dev); +- else +- setsharpness_96(gspca_dev); +- } ++ if (gspca_dev->streaming) ++ setsharpness(gspca_dev); + return 0; + } + +@@ -2257,7 +1276,7 @@ static int sd_set_streamparm(struct gspca_dev *gspca_dev, + + /* Set requested framerate */ + sd->frame_rate = tpf->denominator / tpf->numerator; +- if (gspca_dev->streaming && sd->sensor == SENSOR_OV772X) ++ if (gspca_dev->streaming) + set_frame_rate(gspca_dev); + + /* Return the actual framerate */ +@@ -2267,57 +1286,23 @@ static int sd_set_streamparm(struct gspca_dev *gspca_dev, + return 0; + } + +-static int sd_querymenu(struct gspca_dev *gspca_dev, +- struct v4l2_querymenu *menu) +-{ +- switch (menu->id) { +- case V4L2_CID_POWER_LINE_FREQUENCY: +- switch (menu->index) { +- case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ +- strcpy((char *) menu->name, "NoFliker"); +- return 0; +- case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ +- strcpy((char *) menu->name, "50 Hz"); +- return 0; +- case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ +- strcpy((char *) menu->name, "60 Hz"); +- return 0; +- } +- break; +- } +- return -EINVAL; +-} +- + /* sub-driver description */ +-static const struct sd_desc sd_desc_ov772x = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, +- .ctrls = sd_ctrls_ov772x, +- .nctrls = ARRAY_SIZE(sd_ctrls_ov772x), ++ .ctrls = sd_ctrls, ++ .nctrls = ARRAY_SIZE(sd_ctrls), + .config = sd_config, + .init = sd_init, +- .start = sd_start_ov772x, +- .stopN = sd_stopN_ov772x, ++ .start = sd_start, ++ .stopN = sd_stopN, + .pkt_scan = sd_pkt_scan, + .get_streamparm = sd_get_streamparm, + .set_streamparm = sd_set_streamparm, + }; + +-static const struct sd_desc sd_desc_ov965x = { +- .name = MODULE_NAME, +- .ctrls = sd_ctrls_ov965x, +- .nctrls = ARRAY_SIZE(sd_ctrls_ov965x), +- .config = sd_config, +- .init = sd_init, +- .start = sd_start_ov965x, +- .stopN = sd_stopN_ov965x, +- .pkt_scan = sd_pkt_scan, +- .querymenu = sd_querymenu, +-}; +- + /* -- module initialisation -- */ + static const __devinitdata struct usb_device_id device_table[] = { +- {USB_DEVICE(0x06f8, 0x3003), .driver_info = SENSOR_OV965X}, +- {USB_DEVICE(0x1415, 0x2000), .driver_info = SENSOR_OV772X}, ++ {USB_DEVICE(0x1415, 0x2000)}, + {} + }; + +@@ -2326,11 +1311,7 @@ MODULE_DEVICE_TABLE(usb, device_table); + /* -- device connect -- */ + static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) + { +- return gspca_dev_probe(intf, id, +- id->driver_info == SENSOR_OV772X +- ? &sd_desc_ov772x +- : &sd_desc_ov965x, +- sizeof(struct sd), ++ return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), + THIS_MODULE); + } + +diff --git a/drivers/media/video/gspca/ov534_9.c b/drivers/media/video/gspca/ov534_9.c +new file mode 100644 +index 0000000..bbe5a03 +--- /dev/null ++++ b/drivers/media/video/gspca/ov534_9.c +@@ -0,0 +1,1477 @@ ++/* ++ * ov534-ov965x gspca driver ++ * ++ * Copyright (C) 2009-2010 Jean-Francois Moine http://moinejf.free.fr ++ * Copyright (C) 2008 Antonio Ospite ++ * Copyright (C) 2008 Jim Paris ++ * ++ * Based on a prototype written by Mark Ferrell ++ * USB protocol reverse engineered by Jim Paris ++ * https://jim.sh/svn/jim/devl/playstation/ps3/eye/test/ ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#define MODULE_NAME "ov534_9" ++ ++#include "gspca.h" ++ ++#define OV534_REG_ADDRESS 0xf1 /* sensor address */ ++#define OV534_REG_SUBADDR 0xf2 ++#define OV534_REG_WRITE 0xf3 ++#define OV534_REG_READ 0xf4 ++#define OV534_REG_OPERATION 0xf5 ++#define OV534_REG_STATUS 0xf6 ++ ++#define OV534_OP_WRITE_3 0x37 ++#define OV534_OP_WRITE_2 0x33 ++#define OV534_OP_READ_2 0xf9 ++ ++#define CTRL_TIMEOUT 500 ++ ++MODULE_AUTHOR("Jean-Francois Moine "); ++MODULE_DESCRIPTION("GSPCA/OV534_9 USB Camera Driver"); ++MODULE_LICENSE("GPL"); ++ ++/* specific webcam descriptor */ ++struct sd { ++ struct gspca_dev gspca_dev; /* !! must be the first item */ ++ __u32 last_pts; ++ u8 last_fid; ++ ++ u8 brightness; ++ u8 contrast; ++ u8 autogain; ++ u8 exposure; ++ s8 sharpness; ++ u8 satur; ++ u8 freq; ++}; ++ ++/* V4L2 controls supported by the driver */ ++static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); ++ ++static const struct ctrl sd_ctrls[] = { ++ { /* 0 */ ++ { ++ .id = V4L2_CID_BRIGHTNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Brightness", ++ .minimum = 0, ++ .maximum = 15, ++ .step = 1, ++#define BRIGHTNESS_DEF 7 ++ .default_value = BRIGHTNESS_DEF, ++ }, ++ .set = sd_setbrightness, ++ .get = sd_getbrightness, ++ }, ++ { /* 1 */ ++ { ++ .id = V4L2_CID_CONTRAST, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Contrast", ++ .minimum = 0, ++ .maximum = 15, ++ .step = 1, ++#define CONTRAST_DEF 3 ++ .default_value = CONTRAST_DEF, ++ }, ++ .set = sd_setcontrast, ++ .get = sd_getcontrast, ++ }, ++ { /* 2 */ ++ { ++ .id = V4L2_CID_AUTOGAIN, ++ .type = V4L2_CTRL_TYPE_BOOLEAN, ++ .name = "Autogain", ++ .minimum = 0, ++ .maximum = 1, ++ .step = 1, ++#define AUTOGAIN_DEF 1 ++ .default_value = AUTOGAIN_DEF, ++ }, ++ .set = sd_setautogain, ++ .get = sd_getautogain, ++ }, ++#define EXPO_IDX 3 ++ { /* 3 */ ++ { ++ .id = V4L2_CID_EXPOSURE, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Exposure", ++ .minimum = 0, ++ .maximum = 3, ++ .step = 1, ++#define EXPO_DEF 0 ++ .default_value = EXPO_DEF, ++ }, ++ .set = sd_setexposure, ++ .get = sd_getexposure, ++ }, ++ { /* 4 */ ++ { ++ .id = V4L2_CID_SHARPNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Sharpness", ++ .minimum = -1, /* -1 = auto */ ++ .maximum = 4, ++ .step = 1, ++#define SHARPNESS_DEF -1 ++ .default_value = SHARPNESS_DEF, ++ }, ++ .set = sd_setsharpness, ++ .get = sd_getsharpness, ++ }, ++ { /* 5 */ ++ { ++ .id = V4L2_CID_SATURATION, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Saturation", ++ .minimum = 0, ++ .maximum = 4, ++ .step = 1, ++#define SATUR_DEF 2 ++ .default_value = SATUR_DEF, ++ }, ++ .set = sd_setsatur, ++ .get = sd_getsatur, ++ }, ++ { ++ { ++ .id = V4L2_CID_POWER_LINE_FREQUENCY, ++ .type = V4L2_CTRL_TYPE_MENU, ++ .name = "Light frequency filter", ++ .minimum = 0, ++ .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ ++ .step = 1, ++#define FREQ_DEF 0 ++ .default_value = FREQ_DEF, ++ }, ++ .set = sd_setfreq, ++ .get = sd_getfreq, ++ }, ++}; ++ ++static const struct v4l2_pix_format ov965x_mode[] = { ++#define QVGA_MODE 0 ++ {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 320, ++ .sizeimage = 320 * 240 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG}, ++#define VGA_MODE 1 ++ {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 640, ++ .sizeimage = 640 * 480 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG}, ++#define SVGA_MODE 2 ++ {800, 600, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 800, ++ .sizeimage = 800 * 600 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG}, ++#define XGA_MODE 3 ++ {1024, 768, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 1024, ++ .sizeimage = 1024 * 768 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG}, ++#define SXGA_MODE 4 ++ {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 1280, ++ .sizeimage = 1280 * 1024 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG}, ++}; ++ ++static const u8 bridge_init[][2] = { ++ {0x88, 0xf8}, ++ {0x89, 0xff}, ++ {0x76, 0x03}, ++ {0x92, 0x03}, ++ {0x95, 0x10}, ++ {0xe2, 0x00}, ++ {0xe7, 0x3e}, ++ {0x8d, 0x1c}, ++ {0x8e, 0x00}, ++ {0x8f, 0x00}, ++ {0x1f, 0x00}, ++ {0xc3, 0xf9}, ++ {0x89, 0xff}, ++ {0x88, 0xf8}, ++ {0x76, 0x03}, ++ {0x92, 0x01}, ++ {0x93, 0x18}, ++ {0x1c, 0x0a}, ++ {0x1d, 0x48}, ++ {0xc0, 0x50}, ++ {0xc1, 0x3c}, ++ {0x34, 0x05}, ++ {0xc2, 0x0c}, ++ {0xc3, 0xf9}, ++ {0x34, 0x05}, ++ {0xe7, 0x2e}, ++ {0x31, 0xf9}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0x25, 0x42}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 sensor_init[][2] = { ++ {0x12, 0x80}, /* com7 - SSCB reset */ ++ {0x00, 0x00}, /* gain */ ++ {0x01, 0x80}, /* blue */ ++ {0x02, 0x80}, /* red */ ++ {0x03, 0x1b}, /* vref */ ++ {0x04, 0x03}, /* com1 - exposure low bits */ ++ {0x0b, 0x57}, /* ver */ ++ {0x0e, 0x61}, /* com5 */ ++ {0x0f, 0x42}, /* com6 */ ++ {0x11, 0x00}, /* clkrc */ ++ {0x12, 0x02}, /* com7 - 15fps VGA YUYV */ ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++ {0x14, 0x28}, /* com9 */ ++ {0x16, 0x24}, /* reg16 */ ++ {0x17, 0x1d}, /* hstart*/ ++ {0x18, 0xbd}, /* hstop */ ++ {0x19, 0x01}, /* vstrt */ ++ {0x1a, 0x81}, /* vstop*/ ++ {0x1e, 0x04}, /* mvfp */ ++ {0x24, 0x3c}, /* aew */ ++ {0x25, 0x36}, /* aeb */ ++ {0x26, 0x71}, /* vpt */ ++ {0x27, 0x08}, /* bbias */ ++ {0x28, 0x08}, /* gbbias */ ++ {0x29, 0x15}, /* gr com */ ++ {0x2a, 0x00}, /* exhch */ ++ {0x2b, 0x00}, /* exhcl */ ++ {0x2c, 0x08}, /* rbias */ ++ {0x32, 0xff}, /* href */ ++ {0x33, 0x00}, /* chlf */ ++ {0x34, 0x3f}, /* aref1 */ ++ {0x35, 0x00}, /* aref2 */ ++ {0x36, 0xf8}, /* aref3 */ ++ {0x38, 0x72}, /* adc2 */ ++ {0x39, 0x57}, /* aref4 */ ++ {0x3a, 0x80}, /* tslb - yuyv */ ++ {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ ++ {0x3d, 0x99}, /* com13 */ ++ {0x3f, 0xc1}, /* edge */ ++ {0x40, 0xc0}, /* com15 */ ++ {0x41, 0x40}, /* com16 */ ++ {0x42, 0xc0}, /* com17 */ ++ {0x43, 0x0a}, /* rsvd */ ++ {0x44, 0xf0}, ++ {0x45, 0x46}, ++ {0x46, 0x62}, ++ {0x47, 0x2a}, ++ {0x48, 0x3c}, ++ {0x4a, 0xfc}, ++ {0x4b, 0xfc}, ++ {0x4c, 0x7f}, ++ {0x4d, 0x7f}, ++ {0x4e, 0x7f}, ++ {0x4f, 0x98}, /* matrix */ ++ {0x50, 0x98}, ++ {0x51, 0x00}, ++ {0x52, 0x28}, ++ {0x53, 0x70}, ++ {0x54, 0x98}, ++ {0x58, 0x1a}, /* matrix coef sign */ ++ {0x59, 0x85}, /* AWB control */ ++ {0x5a, 0xa9}, ++ {0x5b, 0x64}, ++ {0x5c, 0x84}, ++ {0x5d, 0x53}, ++ {0x5e, 0x0e}, ++ {0x5f, 0xf0}, /* AWB blue limit */ ++ {0x60, 0xf0}, /* AWB red limit */ ++ {0x61, 0xf0}, /* AWB green limit */ ++ {0x62, 0x00}, /* lcc1 */ ++ {0x63, 0x00}, /* lcc2 */ ++ {0x64, 0x02}, /* lcc3 */ ++ {0x65, 0x16}, /* lcc4 */ ++ {0x66, 0x01}, /* lcc5 */ ++ {0x69, 0x02}, /* hv */ ++ {0x6b, 0x5a}, /* dbvl */ ++ {0x6c, 0x04}, ++ {0x6d, 0x55}, ++ {0x6e, 0x00}, ++ {0x6f, 0x9d}, ++ {0x70, 0x21}, /* dnsth */ ++ {0x71, 0x78}, ++ {0x72, 0x00}, /* poidx */ ++ {0x73, 0x01}, /* pckdv */ ++ {0x74, 0x3a}, /* xindx */ ++ {0x75, 0x35}, /* yindx */ ++ {0x76, 0x01}, ++ {0x77, 0x02}, ++ {0x7a, 0x12}, /* gamma curve */ ++ {0x7b, 0x08}, ++ {0x7c, 0x16}, ++ {0x7d, 0x30}, ++ {0x7e, 0x5e}, ++ {0x7f, 0x72}, ++ {0x80, 0x82}, ++ {0x81, 0x8e}, ++ {0x82, 0x9a}, ++ {0x83, 0xa4}, ++ {0x84, 0xac}, ++ {0x85, 0xb8}, ++ {0x86, 0xc3}, ++ {0x87, 0xd6}, ++ {0x88, 0xe6}, ++ {0x89, 0xf2}, ++ {0x8a, 0x03}, ++ {0x8c, 0x89}, /* com19 */ ++ {0x14, 0x28}, /* com9 */ ++ {0x90, 0x7d}, ++ {0x91, 0x7b}, ++ {0x9d, 0x03}, /* lcc6 */ ++ {0x9e, 0x04}, /* lcc7 */ ++ {0x9f, 0x7a}, ++ {0xa0, 0x79}, ++ {0xa1, 0x40}, /* aechm */ ++ {0xa4, 0x50}, /* com21 */ ++ {0xa5, 0x68}, /* com26 */ ++ {0xa6, 0x4a}, /* AWB green */ ++ {0xa8, 0xc1}, /* refa8 */ ++ {0xa9, 0xef}, /* refa9 */ ++ {0xaa, 0x92}, ++ {0xab, 0x04}, ++ {0xac, 0x80}, /* black level control */ ++ {0xad, 0x80}, ++ {0xae, 0x80}, ++ {0xaf, 0x80}, ++ {0xb2, 0xf2}, ++ {0xb3, 0x20}, ++ {0xb4, 0x20}, /* ctrlb4 */ ++ {0xb5, 0x00}, ++ {0xb6, 0xaf}, ++ {0xbb, 0xae}, ++ {0xbc, 0x7f}, /* ADC channel offsets */ ++ {0xdb, 0x7f}, ++ {0xbe, 0x7f}, ++ {0xbf, 0x7f}, ++ {0xc0, 0xe2}, ++ {0xc1, 0xc0}, ++ {0xc2, 0x01}, ++ {0xc3, 0x4e}, ++ {0xc6, 0x85}, ++ {0xc7, 0x80}, /* com24 */ ++ {0xc9, 0xe0}, ++ {0xca, 0xe8}, ++ {0xcb, 0xf0}, ++ {0xcc, 0xd8}, ++ {0xcd, 0xf1}, ++ {0x4f, 0x98}, /* matrix */ ++ {0x50, 0x98}, ++ {0x51, 0x00}, ++ {0x52, 0x28}, ++ {0x53, 0x70}, ++ {0x54, 0x98}, ++ {0x58, 0x1a}, ++ {0xff, 0x41}, /* read 41, write ff 00 */ ++ {0x41, 0x40}, /* com16 */ ++ ++ {0xc5, 0x03}, /* 60 Hz banding filter */ ++ {0x6a, 0x02}, /* 50 Hz banding filter */ ++ ++ {0x12, 0x62}, /* com7 - 30fps VGA YUV */ ++ {0x36, 0xfa}, /* aref3 */ ++ {0x69, 0x0a}, /* hv */ ++ {0x8c, 0x89}, /* com22 */ ++ {0x14, 0x28}, /* com9 */ ++ {0x3e, 0x0c}, ++ {0x41, 0x40}, /* com16 */ ++ {0x72, 0x00}, ++ {0x73, 0x00}, ++ {0x74, 0x3a}, ++ {0x75, 0x35}, ++ {0x76, 0x01}, ++ {0xc7, 0x80}, ++ {0x03, 0x12}, /* vref */ ++ {0x17, 0x16}, /* hstart */ ++ {0x18, 0x02}, /* hstop */ ++ {0x19, 0x01}, /* vstrt */ ++ {0x1a, 0x3d}, /* vstop */ ++ {0x32, 0xff}, /* href */ ++ {0xc0, 0xaa}, ++}; ++ ++static const u8 bridge_init_2[][2] = { ++ {0x94, 0xaa}, ++ {0xf1, 0x60}, ++ {0xe5, 0x04}, ++ {0xc0, 0x50}, ++ {0xc1, 0x3c}, ++ {0x8c, 0x00}, ++ {0x8d, 0x1c}, ++ {0x34, 0x05}, ++ ++ {0xc2, 0x0c}, ++ {0xc3, 0xf9}, ++ {0xda, 0x01}, ++ {0x50, 0x00}, ++ {0x51, 0xa0}, ++ {0x52, 0x3c}, ++ {0x53, 0x00}, ++ {0x54, 0x00}, ++ {0x55, 0x00}, ++ {0x57, 0x00}, ++ {0x5c, 0x00}, ++ {0x5a, 0xa0}, ++ {0x5b, 0x78}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 sensor_init_2[][2] = { ++ {0x3b, 0xc4}, ++ {0x1e, 0x04}, /* mvfp */ ++ {0x13, 0xe0}, /* com8 */ ++ {0x00, 0x00}, /* gain */ ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++ {0x11, 0x03}, /* clkrc */ ++ {0x6b, 0x5a}, /* dblv */ ++ {0x6a, 0x05}, ++ {0xc5, 0x07}, ++ {0xa2, 0x4b}, ++ {0xa3, 0x3e}, ++ {0x2d, 0x00}, ++ {0xff, 0x42}, /* read 42, write ff 00 */ ++ {0x42, 0xc0}, /* com17 */ ++ {0x2d, 0x00}, ++ {0xff, 0x42}, /* read 42, write ff 00 */ ++ {0x42, 0xc1}, /* com17 */ ++/* sharpness */ ++ {0x3f, 0x01}, ++ {0xff, 0x42}, /* read 42, write ff 00 */ ++ {0x42, 0xc1}, /* com17 */ ++/* saturation */ ++ {0x4f, 0x98}, /* matrix */ ++ {0x50, 0x98}, ++ {0x51, 0x00}, ++ {0x52, 0x28}, ++ {0x53, 0x70}, ++ {0x54, 0x98}, ++ {0x58, 0x1a}, ++ {0xff, 0x41}, /* read 41, write ff 00 */ ++ {0x41, 0x40}, /* com16 */ ++/* contrast */ ++ {0x56, 0x40}, ++/* brightness */ ++ {0x55, 0x8f}, ++/* expo */ ++ {0x10, 0x25}, /* aech - exposure high bits */ ++ {0xff, 0x13}, /* read 13, write ff 00 */ ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++}; ++ ++static const u8 sensor_start_1_vga[][2] = { /* same for qvga */ ++ {0x12, 0x62}, /* com7 - 30fps VGA YUV */ ++ {0x36, 0xfa}, /* aref3 */ ++ {0x69, 0x0a}, /* hv */ ++ {0x8c, 0x89}, /* com22 */ ++ {0x14, 0x28}, /* com9 */ ++ {0x3e, 0x0c}, /* com14 */ ++ {0x41, 0x40}, /* com16 */ ++ {0x72, 0x00}, ++ {0x73, 0x00}, ++ {0x74, 0x3a}, ++ {0x75, 0x35}, ++ {0x76, 0x01}, ++ {0xc7, 0x80}, /* com24 */ ++ {0x03, 0x12}, /* vref */ ++ {0x17, 0x16}, /* hstart */ ++ {0x18, 0x02}, /* hstop */ ++ {0x19, 0x01}, /* vstrt */ ++ {0x1a, 0x3d}, /* vstop */ ++ {0x32, 0xff}, /* href */ ++ {0xc0, 0xaa}, ++}; ++ ++static const u8 sensor_start_1_svga[][2] = { ++ {0x12, 0x02}, /* com7 - YUYV - VGA 15 full resolution */ ++ {0x36, 0xf8}, /* aref3 */ ++ {0x69, 0x02}, /* hv */ ++ {0x8c, 0x0d}, /* com22 */ ++ {0x3e, 0x0c}, /* com14 */ ++ {0x41, 0x40}, /* com16 */ ++ {0x72, 0x00}, ++ {0x73, 0x01}, ++ {0x74, 0x3a}, ++ {0x75, 0x35}, ++ {0x76, 0x01}, ++ {0xc7, 0x80}, /* com24 */ ++ {0x03, 0x1b}, /* vref */ ++ {0x17, 0x1d}, /* hstart */ ++ {0x18, 0xbd}, /* hstop */ ++ {0x19, 0x01}, /* vstrt */ ++ {0x1a, 0x81}, /* vstop */ ++ {0x32, 0xff}, /* href */ ++ {0xc0, 0xe2}, ++}; ++ ++static const u8 sensor_start_1_xga[][2] = { ++ {0x12, 0x02}, /* com7 */ ++ {0x36, 0xf8}, /* aref3 */ ++ {0x69, 0x02}, /* hv */ ++ {0x8c, 0x89}, /* com22 */ ++ {0x14, 0x28}, /* com9 */ ++ {0x3e, 0x0c}, /* com14 */ ++ {0x41, 0x40}, /* com16 */ ++ {0x72, 0x00}, ++ {0x73, 0x01}, ++ {0x74, 0x3a}, ++ {0x75, 0x35}, ++ {0x76, 0x01}, ++ {0xc7, 0x80}, /* com24 */ ++ {0x03, 0x1b}, /* vref */ ++ {0x17, 0x1d}, /* hstart */ ++ {0x18, 0xbd}, /* hstop */ ++ {0x19, 0x01}, /* vstrt */ ++ {0x1a, 0x81}, /* vstop */ ++ {0x32, 0xff}, /* href */ ++ {0xc0, 0xe2}, ++}; ++ ++static const u8 sensor_start_1_sxga[][2] = { ++ {0x12, 0x02}, /* com7 */ ++ {0x36, 0xf8}, /* aref3 */ ++ {0x69, 0x02}, /* hv */ ++ {0x8c, 0x89}, /* com22 */ ++ {0x14, 0x28}, /* com9 */ ++ {0x3e, 0x0c}, /* com14 */ ++ {0x41, 0x40}, /* com16 */ ++ {0x72, 0x00}, ++ {0x73, 0x01}, ++ {0x74, 0x3a}, ++ {0x75, 0x35}, ++ {0x76, 0x01}, ++ {0xc7, 0x80}, /* com24 */ ++ {0x03, 0x1b}, /* vref */ ++ {0x17, 0x1d}, /* hstart */ ++ {0x18, 0x02}, /* hstop */ ++ {0x19, 0x01}, /* vstrt */ ++ {0x1a, 0x81}, /* vstop */ ++ {0x32, 0xff}, /* href */ ++ {0xc0, 0xe2}, ++}; ++ ++static const u8 bridge_start_qvga[][2] = { ++ {0x94, 0xaa}, ++ {0xf1, 0x60}, ++ {0xe5, 0x04}, ++ {0xc0, 0x50}, ++ {0xc1, 0x3c}, ++ {0x8c, 0x00}, ++ {0x8d, 0x1c}, ++ {0x34, 0x05}, ++ ++ {0xc2, 0x4c}, ++ {0xc3, 0xf9}, ++ {0xda, 0x00}, ++ {0x50, 0x00}, ++ {0x51, 0xa0}, ++ {0x52, 0x78}, ++ {0x53, 0x00}, ++ {0x54, 0x00}, ++ {0x55, 0x00}, ++ {0x57, 0x00}, ++ {0x5c, 0x00}, ++ {0x5a, 0x50}, ++ {0x5b, 0x3c}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 bridge_start_vga[][2] = { ++ {0x94, 0xaa}, ++ {0xf1, 0x60}, ++ {0xe5, 0x04}, ++ {0xc0, 0x50}, ++ {0xc1, 0x3c}, ++ {0x8c, 0x00}, ++ {0x8d, 0x1c}, ++ {0x34, 0x05}, ++ {0xc2, 0x0c}, ++ {0xc3, 0xf9}, ++ {0xda, 0x01}, ++ {0x50, 0x00}, ++ {0x51, 0xa0}, ++ {0x52, 0x3c}, ++ {0x53, 0x00}, ++ {0x54, 0x00}, ++ {0x55, 0x00}, ++ {0x57, 0x00}, ++ {0x5c, 0x00}, ++ {0x5a, 0xa0}, ++ {0x5b, 0x78}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 bridge_start_svga[][2] = { ++ {0x94, 0xaa}, ++ {0xf1, 0x60}, ++ {0xe5, 0x04}, ++ {0xc0, 0xa0}, ++ {0xc1, 0x80}, ++ {0x8c, 0x00}, ++ {0x8d, 0x1c}, ++ {0x34, 0x05}, ++ {0xc2, 0x4c}, ++ {0xc3, 0xf9}, ++ {0x50, 0x00}, ++ {0x51, 0x40}, ++ {0x52, 0x00}, ++ {0x53, 0x00}, ++ {0x54, 0x00}, ++ {0x55, 0x88}, ++ {0x57, 0x00}, ++ {0x5c, 0x00}, ++ {0x5a, 0xc8}, ++ {0x5b, 0x96}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0xda, 0x00}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 bridge_start_xga[][2] = { ++ {0x94, 0xaa}, ++ {0xf1, 0x60}, ++ {0xe5, 0x04}, ++ {0xc0, 0xa0}, ++ {0xc1, 0x80}, ++ {0x8c, 0x00}, ++ {0x8d, 0x1c}, ++ {0x34, 0x05}, ++ {0xc2, 0x4c}, ++ {0xc3, 0xf9}, ++ {0x50, 0x00}, ++ {0x51, 0x40}, ++ {0x52, 0x00}, ++ {0x53, 0x00}, ++ {0x54, 0x00}, ++ {0x55, 0x88}, ++ {0x57, 0x00}, ++ {0x5c, 0x01}, ++ {0x5a, 0x00}, ++ {0x5b, 0xc0}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0xda, 0x01}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 bridge_start_sxga[][2] = { ++ {0x94, 0xaa}, ++ {0xf1, 0x60}, ++ {0xe5, 0x04}, ++ {0xc0, 0xa0}, ++ {0xc1, 0x80}, ++ {0x8c, 0x00}, ++ {0x8d, 0x1c}, ++ {0x34, 0x05}, ++ {0xc2, 0x0c}, ++ {0xc3, 0xf9}, ++ {0xda, 0x00}, ++ {0x35, 0x02}, ++ {0xd9, 0x10}, ++ {0x94, 0x11}, ++}; ++ ++static const u8 sensor_start_2_qvga[][2] = { ++ {0x3b, 0xe4}, /* com11 - night mode 1/4 frame rate */ ++ {0x1e, 0x04}, /* mvfp */ ++ {0x13, 0xe0}, /* com8 */ ++ {0x00, 0x00}, ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++ {0x11, 0x01}, /* clkrc */ ++ {0x6b, 0x5a}, /* dblv */ ++ {0x6a, 0x02}, /* 50 Hz banding filter */ ++ {0xc5, 0x03}, /* 60 Hz banding filter */ ++ {0xa2, 0x96}, /* bd50 */ ++ {0xa3, 0x7d}, /* bd60 */ ++ ++ {0xff, 0x13}, /* read 13, write ff 00 */ ++ {0x13, 0xe7}, ++ {0x3a, 0x80}, /* tslb - yuyv */ ++}; ++ ++static const u8 sensor_start_2_vga[][2] = { ++ {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ ++ {0x1e, 0x04}, /* mvfp */ ++ {0x13, 0xe0}, /* com8 */ ++ {0x00, 0x00}, ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++ {0x11, 0x03}, /* clkrc */ ++ {0x6b, 0x5a}, /* dblv */ ++ {0x6a, 0x05}, /* 50 Hz banding filter */ ++ {0xc5, 0x07}, /* 60 Hz banding filter */ ++ {0xa2, 0x4b}, /* bd50 */ ++ {0xa3, 0x3e}, /* bd60 */ ++ ++ {0x2d, 0x00}, /* advfl */ ++}; ++ ++static const u8 sensor_start_2_svga[][2] = { /* same for xga */ ++ {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ ++ {0x1e, 0x04}, /* mvfp */ ++ {0x13, 0xe0}, /* com8 */ ++ {0x00, 0x00}, ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++ {0x11, 0x01}, /* clkrc */ ++ {0x6b, 0x5a}, /* dblv */ ++ {0x6a, 0x0c}, /* 50 Hz banding filter */ ++ {0xc5, 0x0f}, /* 60 Hz banding filter */ ++ {0xa2, 0x4e}, /* bd50 */ ++ {0xa3, 0x41}, /* bd60 */ ++}; ++ ++static const u8 sensor_start_2_sxga[][2] = { ++ {0x13, 0xe0}, /* com8 */ ++ {0x00, 0x00}, ++ {0x13, 0xe7}, /* com8 - everything (AGC, AWB and AEC) */ ++ {0x3b, 0xc4}, /* com11 - night mode 1/4 frame rate */ ++ {0x1e, 0x04}, /* mvfp */ ++ {0x11, 0x01}, /* clkrc */ ++ {0x6b, 0x5a}, /* dblv */ ++ {0x6a, 0x0c}, /* 50 Hz banding filter */ ++ {0xc5, 0x0f}, /* 60 Hz banding filter */ ++ {0xa2, 0x4e}, /* bd50 */ ++ {0xa3, 0x41}, /* bd60 */ ++}; ++ ++static void reg_w_i(struct gspca_dev *gspca_dev, u16 reg, u8 val) ++{ ++ struct usb_device *udev = gspca_dev->dev; ++ int ret; ++ ++ if (gspca_dev->usb_err < 0) ++ return; ++ gspca_dev->usb_buf[0] = val; ++ ret = usb_control_msg(udev, ++ usb_sndctrlpipe(udev, 0), ++ 0x01, ++ USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "reg_w failed %d", ret); ++ gspca_dev->usb_err = ret; ++ } ++} ++ ++static void reg_w(struct gspca_dev *gspca_dev, u16 reg, u8 val) ++{ ++ PDEBUG(D_USBO, "reg_w [%04x] = %02x", reg, val); ++ reg_w_i(gspca_dev, reg, val); ++} ++ ++static u8 reg_r(struct gspca_dev *gspca_dev, u16 reg) ++{ ++ struct usb_device *udev = gspca_dev->dev; ++ int ret; ++ ++ if (gspca_dev->usb_err < 0) ++ return 0; ++ ret = usb_control_msg(udev, ++ usb_rcvctrlpipe(udev, 0), ++ 0x01, ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ 0x00, reg, gspca_dev->usb_buf, 1, CTRL_TIMEOUT); ++ PDEBUG(D_USBI, "reg_r [%04x] -> %02x", reg, gspca_dev->usb_buf[0]); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "reg_r err %d", ret); ++ gspca_dev->usb_err = ret; ++ } ++ return gspca_dev->usb_buf[0]; ++} ++ ++static int sccb_check_status(struct gspca_dev *gspca_dev) ++{ ++ u8 data; ++ int i; ++ ++ for (i = 0; i < 5; i++) { ++ data = reg_r(gspca_dev, OV534_REG_STATUS); ++ ++ switch (data) { ++ case 0x00: ++ return 1; ++ case 0x04: ++ return 0; ++ case 0x03: ++ break; ++ default: ++ PDEBUG(D_USBI|D_USBO, ++ "sccb status 0x%02x, attempt %d/5", ++ data, i + 1); ++ } ++ } ++ return 0; ++} ++ ++static void sccb_write(struct gspca_dev *gspca_dev, u8 reg, u8 val) ++{ ++ PDEBUG(D_USBO, "sccb_write [%02x] = %02x", reg, val); ++ reg_w_i(gspca_dev, OV534_REG_SUBADDR, reg); ++ reg_w_i(gspca_dev, OV534_REG_WRITE, val); ++ reg_w_i(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_3); ++ ++ if (!sccb_check_status(gspca_dev)) ++ PDEBUG(D_ERR, "sccb_write failed"); ++} ++ ++static u8 sccb_read(struct gspca_dev *gspca_dev, u16 reg) ++{ ++ reg_w(gspca_dev, OV534_REG_SUBADDR, reg); ++ reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_WRITE_2); ++ if (!sccb_check_status(gspca_dev)) ++ PDEBUG(D_ERR, "sccb_read failed 1"); ++ ++ reg_w(gspca_dev, OV534_REG_OPERATION, OV534_OP_READ_2); ++ if (!sccb_check_status(gspca_dev)) ++ PDEBUG(D_ERR, "sccb_read failed 2"); ++ ++ return reg_r(gspca_dev, OV534_REG_READ); ++} ++ ++/* output a bridge sequence (reg - val) */ ++static void reg_w_array(struct gspca_dev *gspca_dev, ++ const u8 (*data)[2], int len) ++{ ++ while (--len >= 0) { ++ reg_w(gspca_dev, (*data)[0], (*data)[1]); ++ data++; ++ } ++} ++ ++/* output a sensor sequence (reg - val) */ ++static void sccb_w_array(struct gspca_dev *gspca_dev, ++ const u8 (*data)[2], int len) ++{ ++ while (--len >= 0) { ++ if ((*data)[0] != 0xff) { ++ sccb_write(gspca_dev, (*data)[0], (*data)[1]); ++ } else { ++ sccb_read(gspca_dev, (*data)[1]); ++ sccb_write(gspca_dev, 0xff, 0x00); ++ } ++ data++; ++ } ++} ++ ++/* Two bits control LED: 0x21 bit 7 and 0x23 bit 7. ++ * (direction and output)? */ ++static void set_led(struct gspca_dev *gspca_dev, int status) ++{ ++ u8 data; ++ ++ PDEBUG(D_CONF, "led status: %d", status); ++ ++ data = reg_r(gspca_dev, 0x21); ++ data |= 0x80; ++ reg_w(gspca_dev, 0x21, data); ++ ++ data = reg_r(gspca_dev, 0x23); ++ if (status) ++ data |= 0x80; ++ else ++ data &= ~0x80; ++ ++ reg_w(gspca_dev, 0x23, data); ++ ++ if (!status) { ++ data = reg_r(gspca_dev, 0x21); ++ data &= ~0x80; ++ reg_w(gspca_dev, 0x21, data); ++ } ++} ++ ++static void setbrightness(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 val; ++ ++ val = sd->brightness; ++ if (val < 8) ++ val = 15 - val; /* f .. 8 */ ++ else ++ val = val - 8; /* 0 .. 7 */ ++ sccb_write(gspca_dev, 0x55, /* brtn - brightness adjustment */ ++ 0x0f | (val << 4)); ++} ++ ++static void setcontrast(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sccb_write(gspca_dev, 0x56, /* cnst1 - contrast 1 ctrl coeff */ ++ sd->contrast << 4); ++} ++ ++static void setautogain(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 val; ++ ++/*fixme: should adjust agc/awb/aec by different controls */ ++ val = sd->autogain; ++ val = sccb_read(gspca_dev, 0x13); /* com8 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ if (sd->autogain) ++ val |= 0x05; /* agc & aec */ ++ else ++ val &= 0xfa; ++ sccb_write(gspca_dev, 0x13, val); ++} ++ ++static void setexposure(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 val; ++ static const u8 expo[4] = {0x00, 0x25, 0x38, 0x5e}; ++ ++ sccb_write(gspca_dev, 0x10, /* aec[9:2] */ ++ expo[sd->exposure]); ++ ++ val = sccb_read(gspca_dev, 0x13); /* com8 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ sccb_write(gspca_dev, 0x13, val); ++ ++ val = sccb_read(gspca_dev, 0xa1); /* aech */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ sccb_write(gspca_dev, 0xa1, val & 0xe0); /* aec[15:10] = 0 */ ++} ++ ++static void setsharpness(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ s8 val; ++ ++ val = sd->sharpness; ++ if (val < 0) { /* auto */ ++ val = sccb_read(gspca_dev, 0x42); /* com17 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ sccb_write(gspca_dev, 0x42, val | 0x40); ++ /* Edge enhancement strength auto adjust */ ++ return; ++ } ++ if (val != 0) ++ val = 1 << (val - 1); ++ sccb_write(gspca_dev, 0x3f, /* edge - edge enhance. factor */ ++ val); ++ val = sccb_read(gspca_dev, 0x42); /* com17 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ sccb_write(gspca_dev, 0x42, val & 0xbf); ++} ++ ++static void setsatur(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 val1, val2, val3; ++ static const u8 matrix[5][2] = { ++ {0x14, 0x38}, ++ {0x1e, 0x54}, ++ {0x28, 0x70}, ++ {0x32, 0x8c}, ++ {0x48, 0x90} ++ }; ++ ++ val1 = matrix[sd->satur][0]; ++ val2 = matrix[sd->satur][1]; ++ val3 = val1 + val2; ++ sccb_write(gspca_dev, 0x4f, val3); /* matrix coeff */ ++ sccb_write(gspca_dev, 0x50, val3); ++ sccb_write(gspca_dev, 0x51, 0x00); ++ sccb_write(gspca_dev, 0x52, val1); ++ sccb_write(gspca_dev, 0x53, val2); ++ sccb_write(gspca_dev, 0x54, val3); ++ sccb_write(gspca_dev, 0x58, 0x1a); /* mtxs - coeff signs */ ++ ++ val1 = sccb_read(gspca_dev, 0x41); /* com16 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ sccb_write(gspca_dev, 0x41, val1); ++} ++ ++static void setfreq(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 val; ++ ++ val = sccb_read(gspca_dev, 0x13); /* com8 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ if (sd->freq == 0) { ++ sccb_write(gspca_dev, 0x13, val & 0xdf); ++ return; ++ } ++ sccb_write(gspca_dev, 0x13, val | 0x20); ++ ++ val = sccb_read(gspca_dev, 0x42); /* com17 */ ++ sccb_write(gspca_dev, 0xff, 0x00); ++ if (sd->freq == 1) ++ val |= 0x01; ++ else ++ val &= 0xfe; ++ sccb_write(gspca_dev, 0x42, val); ++} ++ ++/* this function is called at probe time */ ++static int sd_config(struct gspca_dev *gspca_dev, ++ const struct usb_device_id *id) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ struct cam *cam; ++ ++ cam = &gspca_dev->cam; ++ ++ cam->cam_mode = ov965x_mode; ++ cam->nmodes = ARRAY_SIZE(ov965x_mode); ++ ++ sd->brightness = BRIGHTNESS_DEF; ++ sd->contrast = CONTRAST_DEF; ++#if AUTOGAIN_DEF != 0 ++ sd->autogain = AUTOGAIN_DEF; ++ gspca_dev->ctrl_inac |= (1 << EXPO_IDX); ++#endif ++#if EXPO_DEF != 0 ++ sd->exposure = EXPO_DEF; ++#endif ++#if SHARPNESS_DEF != 0 ++ sd->sharpness = SHARPNESS_DEF; ++#endif ++ sd->satur = SATUR_DEF; ++ sd->freq = FREQ_DEF; ++ ++ return 0; ++} ++ ++/* this function is called at probe and resume time */ ++static int sd_init(struct gspca_dev *gspca_dev) ++{ ++ u16 sensor_id; ++ ++ /* reset bridge */ ++ reg_w(gspca_dev, 0xe7, 0x3a); ++ reg_w(gspca_dev, 0xe0, 0x08); ++ msleep(100); ++ ++ /* initialize the sensor address */ ++ reg_w(gspca_dev, OV534_REG_ADDRESS, 0x60); ++ ++ /* reset sensor */ ++ sccb_write(gspca_dev, 0x12, 0x80); ++ msleep(10); ++ ++ /* probe the sensor */ ++ sccb_read(gspca_dev, 0x0a); ++ sensor_id = sccb_read(gspca_dev, 0x0a) << 8; ++ sccb_read(gspca_dev, 0x0b); ++ sensor_id |= sccb_read(gspca_dev, 0x0b); ++ PDEBUG(D_PROBE, "Sensor ID: %04x", sensor_id); ++ ++ /* initialize */ ++ reg_w_array(gspca_dev, bridge_init, ++ ARRAY_SIZE(bridge_init)); ++ sccb_w_array(gspca_dev, sensor_init, ++ ARRAY_SIZE(sensor_init)); ++ reg_w_array(gspca_dev, bridge_init_2, ++ ARRAY_SIZE(bridge_init_2)); ++ sccb_w_array(gspca_dev, sensor_init_2, ++ ARRAY_SIZE(sensor_init_2)); ++ reg_w(gspca_dev, 0xe0, 0x00); ++ reg_w(gspca_dev, 0xe0, 0x01); ++ set_led(gspca_dev, 0); ++ reg_w(gspca_dev, 0xe0, 0x00); ++ ++ return gspca_dev->usb_err; ++} ++ ++static int sd_start(struct gspca_dev *gspca_dev) ++{ ++ switch (gspca_dev->curr_mode) { ++ case QVGA_MODE: /* 320x240 */ ++ sccb_w_array(gspca_dev, sensor_start_1_vga, ++ ARRAY_SIZE(sensor_start_1_vga)); ++ reg_w_array(gspca_dev, bridge_start_qvga, ++ ARRAY_SIZE(bridge_start_qvga)); ++ sccb_w_array(gspca_dev, sensor_start_2_qvga, ++ ARRAY_SIZE(sensor_start_2_qvga)); ++ break; ++ case VGA_MODE: /* 640x480 */ ++ sccb_w_array(gspca_dev, sensor_start_1_vga, ++ ARRAY_SIZE(sensor_start_1_vga)); ++ reg_w_array(gspca_dev, bridge_start_vga, ++ ARRAY_SIZE(bridge_start_vga)); ++ sccb_w_array(gspca_dev, sensor_start_2_vga, ++ ARRAY_SIZE(sensor_start_2_vga)); ++ break; ++ case SVGA_MODE: /* 800x600 */ ++ sccb_w_array(gspca_dev, sensor_start_1_svga, ++ ARRAY_SIZE(sensor_start_1_svga)); ++ reg_w_array(gspca_dev, bridge_start_svga, ++ ARRAY_SIZE(bridge_start_svga)); ++ sccb_w_array(gspca_dev, sensor_start_2_svga, ++ ARRAY_SIZE(sensor_start_2_svga)); ++ break; ++ case XGA_MODE: /* 1024x768 */ ++ sccb_w_array(gspca_dev, sensor_start_1_xga, ++ ARRAY_SIZE(sensor_start_1_xga)); ++ reg_w_array(gspca_dev, bridge_start_xga, ++ ARRAY_SIZE(bridge_start_xga)); ++ sccb_w_array(gspca_dev, sensor_start_2_svga, ++ ARRAY_SIZE(sensor_start_2_svga)); ++ break; ++ default: ++/* case SXGA_MODE: * 1280x1024 */ ++ sccb_w_array(gspca_dev, sensor_start_1_sxga, ++ ARRAY_SIZE(sensor_start_1_sxga)); ++ reg_w_array(gspca_dev, bridge_start_sxga, ++ ARRAY_SIZE(bridge_start_sxga)); ++ sccb_w_array(gspca_dev, sensor_start_2_sxga, ++ ARRAY_SIZE(sensor_start_2_sxga)); ++ break; ++ } ++ setfreq(gspca_dev); ++ setautogain(gspca_dev); ++ setbrightness(gspca_dev); ++ setcontrast(gspca_dev); ++ setexposure(gspca_dev); ++ setsharpness(gspca_dev); ++ setsatur(gspca_dev); ++ ++ reg_w(gspca_dev, 0xe0, 0x00); ++ reg_w(gspca_dev, 0xe0, 0x00); ++ set_led(gspca_dev, 1); ++ return gspca_dev->usb_err; ++} ++ ++static void sd_stopN(struct gspca_dev *gspca_dev) ++{ ++ reg_w(gspca_dev, 0xe0, 0x01); ++ set_led(gspca_dev, 0); ++ reg_w(gspca_dev, 0xe0, 0x00); ++} ++ ++/* Values for bmHeaderInfo (Video and Still Image Payload Headers, 2.4.3.3) */ ++#define UVC_STREAM_EOH (1 << 7) ++#define UVC_STREAM_ERR (1 << 6) ++#define UVC_STREAM_STI (1 << 5) ++#define UVC_STREAM_RES (1 << 4) ++#define UVC_STREAM_SCR (1 << 3) ++#define UVC_STREAM_PTS (1 << 2) ++#define UVC_STREAM_EOF (1 << 1) ++#define UVC_STREAM_FID (1 << 0) ++ ++static void sd_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, int len) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ __u32 this_pts; ++ u8 this_fid; ++ int remaining_len = len; ++ ++ do { ++ len = min(remaining_len, 2040); ++ ++ /* Payloads are prefixed with a UVC-style header. We ++ consider a frame to start when the FID toggles, or the PTS ++ changes. A frame ends when EOF is set, and we've received ++ the correct number of bytes. */ ++ ++ /* Verify UVC header. Header length is always 12 */ ++ if (data[0] != 12 || len < 12) { ++ PDEBUG(D_PACK, "bad header"); ++ goto discard; ++ } ++ ++ /* Check errors */ ++ if (data[1] & UVC_STREAM_ERR) { ++ PDEBUG(D_PACK, "payload error"); ++ goto discard; ++ } ++ ++ /* Extract PTS and FID */ ++ if (!(data[1] & UVC_STREAM_PTS)) { ++ PDEBUG(D_PACK, "PTS not present"); ++ goto discard; ++ } ++ this_pts = (data[5] << 24) | (data[4] << 16) ++ | (data[3] << 8) | data[2]; ++ this_fid = data[1] & UVC_STREAM_FID; ++ ++ /* If PTS or FID has changed, start a new frame. */ ++ if (this_pts != sd->last_pts || this_fid != sd->last_fid) { ++ if (gspca_dev->last_packet_type == INTER_PACKET) ++ gspca_frame_add(gspca_dev, LAST_PACKET, ++ NULL, 0); ++ sd->last_pts = this_pts; ++ sd->last_fid = this_fid; ++ gspca_frame_add(gspca_dev, FIRST_PACKET, ++ data + 12, len - 12); ++ /* If this packet is marked as EOF, end the frame */ ++ } else if (data[1] & UVC_STREAM_EOF) { ++ sd->last_pts = 0; ++ gspca_frame_add(gspca_dev, LAST_PACKET, ++ data + 12, len - 12); ++ } else { ++ ++ /* Add the data from this payload */ ++ gspca_frame_add(gspca_dev, INTER_PACKET, ++ data + 12, len - 12); ++ } ++ ++ /* Done this payload */ ++ goto scan_next; ++ ++discard: ++ /* Discard data until a new frame starts. */ ++ gspca_dev->last_packet_type = DISCARD_PACKET; ++ ++scan_next: ++ remaining_len -= len; ++ data += len; ++ } while (remaining_len > 0); ++} ++ ++/* controls */ ++static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->brightness = val; ++ if (gspca_dev->streaming) ++ setbrightness(gspca_dev); ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->brightness; ++ return 0; ++} ++ ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->contrast = val; ++ if (gspca_dev->streaming) ++ setcontrast(gspca_dev); ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->contrast; ++ return 0; ++} ++ ++static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->autogain = val; ++ ++ if (gspca_dev->streaming) { ++ if (val) ++ gspca_dev->ctrl_inac |= (1 << EXPO_IDX); ++ else ++ gspca_dev->ctrl_inac &= ~(1 << EXPO_IDX); ++ setautogain(gspca_dev); ++ } ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->autogain; ++ return 0; ++} ++ ++static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->exposure = val; ++ if (gspca_dev->streaming) ++ setexposure(gspca_dev); ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->exposure; ++ return 0; ++} ++ ++static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->sharpness = val; ++ if (gspca_dev->streaming) ++ setsharpness(gspca_dev); ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->sharpness; ++ return 0; ++} ++ ++static int sd_setsatur(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->satur = val; ++ if (gspca_dev->streaming) ++ setsatur(gspca_dev); ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getsatur(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->satur; ++ return 0; ++} ++static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->freq = val; ++ if (gspca_dev->streaming) ++ setfreq(gspca_dev); ++ return gspca_dev->usb_err; ++} ++ ++static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->freq; ++ return 0; ++} ++ ++static int sd_querymenu(struct gspca_dev *gspca_dev, ++ struct v4l2_querymenu *menu) ++{ ++ switch (menu->id) { ++ case V4L2_CID_POWER_LINE_FREQUENCY: ++ switch (menu->index) { ++ case 0: /* V4L2_CID_POWER_LINE_FREQUENCY_DISABLED */ ++ strcpy((char *) menu->name, "NoFliker"); ++ return 0; ++ case 1: /* V4L2_CID_POWER_LINE_FREQUENCY_50HZ */ ++ strcpy((char *) menu->name, "50 Hz"); ++ return 0; ++ case 2: /* V4L2_CID_POWER_LINE_FREQUENCY_60HZ */ ++ strcpy((char *) menu->name, "60 Hz"); ++ return 0; ++ } ++ break; ++ } ++ return -EINVAL; ++} ++ ++/* sub-driver description */ ++static const struct sd_desc sd_desc = { ++ .name = MODULE_NAME, ++ .ctrls = sd_ctrls, ++ .nctrls = ARRAY_SIZE(sd_ctrls), ++ .config = sd_config, ++ .init = sd_init, ++ .start = sd_start, ++ .stopN = sd_stopN, ++ .pkt_scan = sd_pkt_scan, ++ .querymenu = sd_querymenu, ++}; ++ ++/* -- module initialisation -- */ ++static const __devinitdata struct usb_device_id device_table[] = { ++ {USB_DEVICE(0x06f8, 0x3003)}, ++ {} ++}; ++ ++MODULE_DEVICE_TABLE(usb, device_table); ++ ++/* -- device connect -- */ ++static int sd_probe(struct usb_interface *intf, const struct usb_device_id *id) ++{ ++ return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), ++ THIS_MODULE); ++} ++ ++static struct usb_driver sd_driver = { ++ .name = MODULE_NAME, ++ .id_table = device_table, ++ .probe = sd_probe, ++ .disconnect = gspca_disconnect, ++#ifdef CONFIG_PM ++ .suspend = gspca_suspend, ++ .resume = gspca_resume, ++#endif ++}; ++ ++/* -- module insert / remove -- */ ++static int __init sd_mod_init(void) ++{ ++ int ret; ++ ++ ret = usb_register(&sd_driver); ++ if (ret < 0) ++ return ret; ++ PDEBUG(D_PROBE, "registered"); ++ return 0; ++} ++ ++static void __exit sd_mod_exit(void) ++{ ++ usb_deregister(&sd_driver); ++ PDEBUG(D_PROBE, "deregistered"); ++} ++ ++module_init(sd_mod_init); ++module_exit(sd_mod_exit); +diff --git a/drivers/media/video/gspca/pac207.c b/drivers/media/video/gspca/pac207.c +index 4706a82..0c87c34 100644 +--- a/drivers/media/video/gspca/pac207.c ++++ b/drivers/media/video/gspca/pac207.c +@@ -25,6 +25,7 @@ + + #define MODULE_NAME "pac207" + ++#include + #include "gspca.h" + + MODULE_AUTHOR("Hans de Goede "); +@@ -77,7 +78,7 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + #define SD_BRIGHTNESS 0 + { + { +@@ -495,6 +496,25 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrput packet length */ ++{ ++ int ret = -EINVAL; ++ ++ if (len == 2 && data[0] == 0x5a && data[1] == 0x5a) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ ++ return ret; ++} ++#endif ++ + /* sub-driver description */ + static const struct sd_desc sd_desc = { + .name = MODULE_NAME, +@@ -506,6 +526,9 @@ static const struct sd_desc sd_desc = { + .stopN = sd_stopN, + .dq_callback = pac207_do_auto_gain, + .pkt_scan = sd_pkt_scan, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + /* -- module initialisation -- */ +diff --git a/drivers/media/video/gspca/pac7302.c b/drivers/media/video/gspca/pac7302.c +index de0b66c..7722f7a 100644 +--- a/drivers/media/video/gspca/pac7302.c ++++ b/drivers/media/video/gspca/pac7302.c +@@ -4,7 +4,9 @@ + * + * V4L2 by Jean-Francois Moine + * +- * Separated from Pixart PAC7311 library by Márton Németh ++ * Separated from Pixart PAC7311 library by Márton Németh ++ * Camera button input handling by Márton Németh ++ * Copyright (C) 2009-2010 Márton Németh + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by +@@ -22,33 +24,26 @@ + */ + + /* Some documentation about various registers as determined by trial and error. +- When the register addresses differ between the 7202 and the 7311 the 2 +- different addresses are written as 7302addr/7311addr, when one of the 2 +- addresses is a - sign that register description is not valid for the +- matching IC. + + Register page 1: + + Address Description +- -/0x08 Unknown compressor related, must always be 8 except when not +- in 640x480 resolution and page 4 reg 2 <= 3 then set it to 9 ! +- -/0x1b Auto white balance related, bit 0 is AWB enable (inverted) +- bits 345 seem to toggle per color gains on/off (inverted) + 0x78 Global control, bit 6 controls the LED (inverted) +- -/0x80 JPEG compression ratio ? Best not touched + +- Register page 3/4: ++ Register page 3: + + Address Description +- 0x02 Clock divider 2-63, fps =~ 60 / val. Must be a multiple of 3 on ++ 0x02 Clock divider 3-63, fps = 90 / val. Must be a multiple of 3 on + the 7302, so one of 3, 6, 9, ..., except when between 6 and 12? +- -/0x0f Master gain 1-245, low value = high gain +- 0x10/- Master gain 0-31 +- -/0x10 Another gain 0-15, limited influence (1-2x gain I guess) ++ 0x03 Variable framerate ctrl reg2==3: 0 -> ~30 fps, 255 -> ~22fps ++ 0x04 Another var framerate ctrl reg2==3, reg3==0: 0 -> ~30 fps, ++ 63 -> ~27 fps, the 2 msb's must always be 1 !! ++ 0x05 Another var framerate ctrl reg2==3, reg3==0, reg4==0xc0: ++ 1 -> ~30 fps, 2 -> ~20 fps ++ 0x0e Exposure bits 0-7, 0-448, 0 = use full frame time ++ 0x0f Exposure bit 8, 0-448, 448 = no exposure at all ++ 0x10 Master gain 0-31 + 0x21 Bitfield: 0-1 unused, 2-3 vflip/hflip, 4-5 unknown, 6-7 unused +- -/0x27 Seems to toggle various gains on / off, Setting bit 7 seems to +- completely disable the analog amplification block. Set to 0x68 +- for max gain, 0x14 for minimal gain. + + The registers are accessed in the following functions: + +@@ -68,6 +63,7 @@ + + #define MODULE_NAME "pac7302" + ++#include + #include + #include "gspca.h" + +@@ -86,8 +82,8 @@ struct sd { + unsigned char red_balance; + unsigned char blue_balance; + unsigned char gain; +- unsigned char exposure; + unsigned char autogain; ++ unsigned short exposure; + __u8 hflip; + __u8 vflip; + u8 flags; +@@ -124,8 +120,7 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { +-/* This control is pac7302 only */ ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -141,7 +136,6 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setbrightness, + .get = sd_getbrightness, + }, +-/* This control is for both the 7302 and the 7311 */ + { + { + .id = V4L2_CID_CONTRAST, +@@ -157,7 +151,6 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setcontrast, + .get = sd_getcontrast, + }, +-/* This control is pac7302 only */ + { + { + .id = V4L2_CID_SATURATION, +@@ -215,7 +208,6 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setbluebalance, + .get = sd_getbluebalance, + }, +-/* All controls below are for both the 7302 and the 7311 */ + { + { + .id = V4L2_CID_GAIN, +@@ -238,11 +230,10 @@ static struct ctrl sd_ctrls[] = { + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Exposure", + .minimum = 0, +-#define EXPOSURE_MAX 255 +- .maximum = EXPOSURE_MAX, ++ .maximum = 1023, + .step = 1, +-#define EXPOSURE_DEF 16 /* 32 ms / 30 fps */ +-#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */ ++#define EXPOSURE_DEF 66 /* 33 ms / 30 fps */ ++#define EXPOSURE_KNEE 133 /* 66 ms / 15 fps */ + .default_value = EXPOSURE_DEF, + }, + .set = sd_setexposure, +@@ -301,7 +292,6 @@ static const struct v4l2_pix_format vga_mode[] = { + }; + + #define LOAD_PAGE3 255 +-#define LOAD_PAGE4 254 + #define END_OF_SEQUENCE 0 + + /* pac 7302 */ +@@ -379,7 +369,7 @@ static const __u8 start_7302[] = { + #define SKIP 0xaa + /* page 3 - the value SKIP says skip the index - see reg_w_page() */ + static const __u8 page3_7302[] = { +- 0x90, 0x40, 0x03, 0x50, 0xc2, 0x01, 0x14, 0x16, ++ 0x90, 0x40, 0x03, 0x00, 0xc0, 0x01, 0x14, 0x16, + 0x14, 0x12, 0x00, 0x00, 0x00, 0x02, 0x33, 0x00, + 0x0f, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x47, 0x01, 0xb3, 0x01, 0x00, +@@ -388,7 +378,7 @@ static const __u8 page3_7302[] = { + 0xa4, 0xb8, 0xe0, 0x2a, 0xf6, 0x00, 0x00, 0x00, + 0x00, 0x1e, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0xfc, 0x00, 0xf2, 0x1f, 0x04, 0x00, 0x00, +- 0x00, 0x00, 0x00, 0xc0, 0xc0, 0x10, 0x00, 0x00, ++ SKIP, 0x00, 0x00, 0xc0, 0xc0, 0x10, 0x00, 0x00, + 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x40, 0xff, 0x03, 0x19, 0x00, 0x00, 0x00, + 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, +@@ -401,12 +391,14 @@ static const __u8 page3_7302[] = { + 0x00 + }; + +-static int reg_w_buf(struct gspca_dev *gspca_dev, ++static void reg_w_buf(struct gspca_dev *gspca_dev, + __u8 index, + const char *buffer, int len) + { + int ret; + ++ if (gspca_dev->usb_err < 0) ++ return; + memcpy(gspca_dev->usb_buf, buffer, len); + ret = usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), +@@ -415,20 +407,44 @@ static int reg_w_buf(struct gspca_dev *gspca_dev, + 0, /* value */ + index, gspca_dev->usb_buf, len, + 500); +- if (ret < 0) ++ if (ret < 0) { + PDEBUG(D_ERR, "reg_w_buf(): " + "Failed to write registers to index 0x%x, error %i", + index, ret); +- return ret; ++ gspca_dev->usb_err = ret; ++ } + } + ++#if 0 /* not used */ ++static __u8 reg_r(struct gspca_dev *gspca_dev, ++ __u8 index) ++{ ++ int ret; ++ ++ ret = usb_control_msg(gspca_dev->dev, ++ usb_rcvctrlpipe(gspca_dev->dev, 0), ++ 0, /* request */ ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ 0, /* value */ ++ index, gspca_dev->usb_buf, 1, ++ 500); ++ if (ret < 0) ++ PDEBUG(D_ERR, "reg_r(): " ++ "Failed to read register from index 0x%x, error %i", ++ index, ret); ++ ++ return gspca_dev->usb_buf[0]; ++} ++#endif + +-static int reg_w(struct gspca_dev *gspca_dev, ++static void reg_w(struct gspca_dev *gspca_dev, + __u8 index, + __u8 value) + { + int ret; + ++ if (gspca_dev->usb_err < 0) ++ return; + gspca_dev->usb_buf[0] = value; + ret = usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), +@@ -436,32 +452,32 @@ static int reg_w(struct gspca_dev *gspca_dev, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 0, index, gspca_dev->usb_buf, 1, + 500); +- if (ret < 0) ++ if (ret < 0) { + PDEBUG(D_ERR, "reg_w(): " + "Failed to write register to index 0x%x, value 0x%x, error %i", + index, value, ret); +- return ret; ++ gspca_dev->usb_err = ret; ++ } + } + +-static int reg_w_seq(struct gspca_dev *gspca_dev, ++static void reg_w_seq(struct gspca_dev *gspca_dev, + const __u8 *seq, int len) + { +- int ret = 0; + while (--len >= 0) { +- if (0 <= ret) +- ret = reg_w(gspca_dev, seq[0], seq[1]); ++ reg_w(gspca_dev, seq[0], seq[1]); + seq += 2; + } +- return ret; + } + + /* load the beginning of a page */ +-static int reg_w_page(struct gspca_dev *gspca_dev, ++static void reg_w_page(struct gspca_dev *gspca_dev, + const __u8 *page, int len) + { + int index; + int ret = 0; + ++ if (gspca_dev->usb_err < 0) ++ return; + for (index = 0; index < len; index++) { + if (page[index] == SKIP) /* skip this index */ + continue; +@@ -477,56 +493,47 @@ static int reg_w_page(struct gspca_dev *gspca_dev, + "Failed to write register to index 0x%x, " + "value 0x%x, error %i", + index, page[index], ret); ++ gspca_dev->usb_err = ret; + break; + } + } +- return ret; + } + + /* output a variable sequence */ +-static int reg_w_var(struct gspca_dev *gspca_dev, ++static void reg_w_var(struct gspca_dev *gspca_dev, + const __u8 *seq, +- const __u8 *page3, unsigned int page3_len, +- const __u8 *page4, unsigned int page4_len) ++ const __u8 *page3, unsigned int page3_len) + { + int index, len; +- int ret = 0; + + for (;;) { + index = *seq++; + len = *seq++; + switch (len) { + case END_OF_SEQUENCE: +- return ret; +- case LOAD_PAGE4: +- ret = reg_w_page(gspca_dev, page4, page4_len); +- break; ++ return; + case LOAD_PAGE3: +- ret = reg_w_page(gspca_dev, page3, page3_len); ++ reg_w_page(gspca_dev, page3, page3_len); + break; + default: + if (len > USB_BUF_SZ) { + PDEBUG(D_ERR|D_STREAM, + "Incorrect variable sequence"); +- return -EINVAL; ++ return; + } + while (len > 0) { + if (len < 8) { +- ret = reg_w_buf(gspca_dev, ++ reg_w_buf(gspca_dev, + index, seq, len); +- if (ret < 0) +- return ret; + seq += len; + break; + } +- ret = reg_w_buf(gspca_dev, index, seq, 8); ++ reg_w_buf(gspca_dev, index, seq, 8); + seq += 8; + index += 8; + len -= 8; + } + } +- if (ret < 0) +- return ret; + } + /* not reached */ + } +@@ -560,11 +567,10 @@ static int sd_config(struct gspca_dev *gspca_dev, + } + + /* This function is used by pac7302 only */ +-static int setbrightcont(struct gspca_dev *gspca_dev) ++static void setbrightcont(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + int i, v; +- int ret; + static const __u8 max[10] = + {0x29, 0x33, 0x42, 0x5a, 0x6e, 0x80, 0x9f, 0xbb, + 0xd4, 0xec}; +@@ -572,7 +578,7 @@ static int setbrightcont(struct gspca_dev *gspca_dev) + {0x35, 0x33, 0x33, 0x2f, 0x2a, 0x25, 0x1e, 0x17, + 0x11, 0x0b}; + +- ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ ++ reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ + for (i = 0; i < 10; i++) { + v = max[i]; + v += (sd->brightness - BRIGHTNESS_MAX) +@@ -582,136 +588,121 @@ static int setbrightcont(struct gspca_dev *gspca_dev) + v = 0; + else if (v > 0xff) + v = 0xff; +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xa2 + i, v); ++ reg_w(gspca_dev, 0xa2 + i, v); + } +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xdc, 0x01); +- return ret; ++ reg_w(gspca_dev, 0xdc, 0x01); + } + + /* This function is used by pac7302 only */ +-static int setcolors(struct gspca_dev *gspca_dev) ++static void setcolors(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + int i, v; +- int ret; + static const int a[9] = + {217, -212, 0, -101, 170, -67, -38, -315, 355}; + static const int b[9] = + {19, 106, 0, 19, 106, 1, 19, 106, 1}; + +- ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ ++ reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ ++ reg_w(gspca_dev, 0x11, 0x01); ++ reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ + for (i = 0; i < 9; i++) { + v = a[i] * sd->colors / COLOR_MAX + b[i]; +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x0f + 2 * i + 1, v); ++ reg_w(gspca_dev, 0x0f + 2 * i, (v >> 8) & 0x07); ++ reg_w(gspca_dev, 0x0f + 2 * i + 1, v); + } +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xdc, 0x01); ++ reg_w(gspca_dev, 0xdc, 0x01); + PDEBUG(D_CONF|D_STREAM, "color: %i", sd->colors); +- return ret; + } + +-static int setwhitebalance(struct gspca_dev *gspca_dev) ++static void setwhitebalance(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + +- ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xc6, sd->white_balance); ++ reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ ++ reg_w(gspca_dev, 0xc6, sd->white_balance); + +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xdc, 0x01); ++ reg_w(gspca_dev, 0xdc, 0x01); + PDEBUG(D_CONF|D_STREAM, "white_balance: %i", sd->white_balance); +- return ret; + } + +-static int setredbalance(struct gspca_dev *gspca_dev) ++static void setredbalance(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + +- ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xc5, sd->red_balance); ++ reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ ++ reg_w(gspca_dev, 0xc5, sd->red_balance); + +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xdc, 0x01); ++ reg_w(gspca_dev, 0xdc, 0x01); + PDEBUG(D_CONF|D_STREAM, "red_balance: %i", sd->red_balance); +- return ret; + } + +-static int setbluebalance(struct gspca_dev *gspca_dev) ++static void setbluebalance(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + +- ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xc7, sd->blue_balance); ++ reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ ++ reg_w(gspca_dev, 0xc7, sd->blue_balance); + +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xdc, 0x01); ++ reg_w(gspca_dev, 0xdc, 0x01); + PDEBUG(D_CONF|D_STREAM, "blue_balance: %i", sd->blue_balance); +- return ret; + } + +-static int setgain(struct gspca_dev *gspca_dev) ++static void setgain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + +- ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x10, sd->gain >> 3); ++ reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ ++ reg_w(gspca_dev, 0x10, sd->gain >> 3); + + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + +-static int setexposure(struct gspca_dev *gspca_dev) ++static void setexposure(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; +- __u8 reg; +- +- /* register 2 of frame 3/4 contains the clock divider configuring the +- no fps according to the formula: 60 / reg. sd->exposure is the +- desired exposure time in ms. */ +- reg = 120 * sd->exposure / 1000; +- if (reg < 2) +- reg = 2; +- else if (reg > 63) +- reg = 63; +- +- /* On the pac7302 reg2 MUST be a multiple of 3, so round it to +- the nearest multiple of 3, except when between 6 and 12? */ +- if (reg < 6 || reg > 12) +- reg = ((reg + 1) / 3) * 3; +- ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x02, reg); ++ __u8 clockdiv; ++ __u16 exposure; ++ ++ /* register 2 of frame 3 contains the clock divider configuring the ++ no fps according to the formula: 90 / reg. sd->exposure is the ++ desired exposure time in 0.5 ms. */ ++ clockdiv = (90 * sd->exposure + 1999) / 2000; ++ ++ /* Note clockdiv = 3 also works, but when running at 30 fps, depending ++ on the scene being recorded, the camera switches to another ++ quantization table for certain JPEG blocks, and we don't know how ++ to decompress these blocks. So we cap the framerate at 15 fps */ ++ if (clockdiv < 6) ++ clockdiv = 6; ++ else if (clockdiv > 63) ++ clockdiv = 63; ++ ++ /* reg2 MUST be a multiple of 3, except when between 6 and 12? ++ Always round up, otherwise we cannot get the desired frametime ++ using the partial frame time exposure control */ ++ if (clockdiv < 6 || clockdiv > 12) ++ clockdiv = ((clockdiv + 2) / 3) * 3; ++ ++ /* frame exposure time in ms = 1000 * clockdiv / 90 -> ++ exposure = (sd->exposure / 2) * 448 / (1000 * clockdiv / 90) */ ++ exposure = (sd->exposure * 45 * 448) / (1000 * clockdiv); ++ /* 0 = use full frametime, 448 = no exposure, reverse it */ ++ exposure = 448 - exposure; ++ ++ reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ ++ reg_w(gspca_dev, 0x02, clockdiv); ++ reg_w(gspca_dev, 0x0e, exposure & 0xff); ++ reg_w(gspca_dev, 0x0f, exposure >> 8); + + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + +-static int sethvflip(struct gspca_dev *gspca_dev) ++static void sethvflip(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + u8 data, hflip, vflip; + + hflip = sd->hflip; +@@ -721,48 +712,37 @@ static int sethvflip(struct gspca_dev *gspca_dev) + if (sd->flags & FL_VFLIP) + vflip = !vflip; + +- ret = reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ ++ reg_w(gspca_dev, 0xff, 0x03); /* page 3 */ + data = (hflip ? 0x08 : 0x00) | (vflip ? 0x04 : 0x00); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x21, data); ++ reg_w(gspca_dev, 0x21, data); ++ + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + + /* this function is called at probe and resume time for pac7302 */ + static int sd_init(struct gspca_dev *gspca_dev) + { +- return reg_w_seq(gspca_dev, init_7302, sizeof(init_7302)/2); ++ reg_w_seq(gspca_dev, init_7302, sizeof(init_7302)/2); ++ return gspca_dev->usb_err; + } + + static int sd_start(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret = 0; + + sd->sof_read = 0; + +- ret = reg_w_var(gspca_dev, start_7302, +- page3_7302, sizeof(page3_7302), +- NULL, 0); +- if (0 <= ret) +- ret = setbrightcont(gspca_dev); +- if (0 <= ret) +- ret = setcolors(gspca_dev); +- if (0 <= ret) +- ret = setwhitebalance(gspca_dev); +- if (0 <= ret) +- ret = setredbalance(gspca_dev); +- if (0 <= ret) +- ret = setbluebalance(gspca_dev); +- if (0 <= ret) +- ret = setgain(gspca_dev); +- if (0 <= ret) +- ret = setexposure(gspca_dev); +- if (0 <= ret) +- ret = sethvflip(gspca_dev); ++ reg_w_var(gspca_dev, start_7302, ++ page3_7302, sizeof(page3_7302)); ++ setbrightcont(gspca_dev); ++ setcolors(gspca_dev); ++ setwhitebalance(gspca_dev); ++ setredbalance(gspca_dev); ++ setbluebalance(gspca_dev); ++ setgain(gspca_dev); ++ setexposure(gspca_dev); ++ sethvflip(gspca_dev); + + /* only resolution 640x480 is supported for pac7302 */ + +@@ -771,34 +751,27 @@ static int sd_start(struct gspca_dev *gspca_dev) + atomic_set(&sd->avg_lum, -1); + + /* start stream */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x01); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x78, 0x01); + +- return ret; ++ return gspca_dev->usb_err; + } + + static void sd_stopN(struct gspca_dev *gspca_dev) + { +- int ret; + + /* stop stream */ +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x00); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x78, 0x00); + } + + /* called on streamoff with alt 0 and on disconnect for pac7302 */ + static void sd_stop0(struct gspca_dev *gspca_dev) + { +- int ret; +- + if (!gspca_dev->present) + return; +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x40); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x78, 0x40); + } + + /* Include pac common sof detection functions */ +@@ -808,22 +781,13 @@ static void do_autogain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + int avg_lum = atomic_read(&sd->avg_lum); +- int desired_lum, deadzone; ++ int desired_lum; ++ const int deadzone = 30; + + if (avg_lum == -1) + return; + +- desired_lum = 270 + sd->brightness * 4; +- /* Hack hack, with the 7202 the first exposure step is +- pretty large, so if we're about to make the first +- exposure increase make the deadzone large to avoid +- oscilating */ +- if (desired_lum > avg_lum && sd->gain == GAIN_DEF && +- sd->exposure > EXPOSURE_DEF && +- sd->exposure < 42) +- deadzone = 90; +- else +- deadzone = 30; ++ desired_lum = 270 + sd->brightness; + + if (sd->autogain_ignore_frames > 0) + sd->autogain_ignore_frames--; +@@ -947,7 +911,7 @@ static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) + sd->brightness = val; + if (gspca_dev->streaming) + setbrightcont(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) +@@ -966,7 +930,7 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) + if (gspca_dev->streaming) { + setbrightcont(gspca_dev); + } +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) +@@ -984,7 +948,7 @@ static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) + sd->colors = val; + if (gspca_dev->streaming) + setcolors(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) +@@ -998,14 +962,11 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) + static int sd_setwhitebalance(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret = 0; + + sd->white_balance = val; + if (gspca_dev->streaming) +- ret = setwhitebalance(gspca_dev); +- if (0 <= ret) +- ret = 0; +- return ret; ++ setwhitebalance(gspca_dev); ++ return gspca_dev->usb_err; + } + + static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1019,14 +980,11 @@ static int sd_getwhitebalance(struct gspca_dev *gspca_dev, __s32 *val) + static int sd_setredbalance(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret = 0; + + sd->red_balance = val; + if (gspca_dev->streaming) +- ret = setredbalance(gspca_dev); +- if (0 <= ret) +- ret = 0; +- return ret; ++ setredbalance(gspca_dev); ++ return gspca_dev->usb_err; + } + + static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1040,14 +998,11 @@ static int sd_getredbalance(struct gspca_dev *gspca_dev, __s32 *val) + static int sd_setbluebalance(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret = 0; + + sd->blue_balance = val; + if (gspca_dev->streaming) +- ret = setbluebalance(gspca_dev); +- if (0 <= ret) +- ret = 0; +- return ret; ++ setbluebalance(gspca_dev); ++ return gspca_dev->usb_err; + } + + static int sd_getbluebalance(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1065,7 +1020,7 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) + sd->gain = val; + if (gspca_dev->streaming) + setgain(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1083,7 +1038,7 @@ static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) + sd->exposure = val; + if (gspca_dev->streaming) + setexposure(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1114,7 +1069,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) + } + } + +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1132,7 +1087,7 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) + sd->hflip = val; + if (gspca_dev->streaming) + sethvflip(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1150,7 +1105,7 @@ static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) + sd->vflip = val; + if (gspca_dev->streaming) + sethvflip(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) +@@ -1165,7 +1120,6 @@ static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) + static int sd_dbg_s_register(struct gspca_dev *gspca_dev, + struct v4l2_dbg_register *reg) + { +- int ret = -EINVAL; + __u8 index; + __u8 value; + +@@ -1185,14 +1139,12 @@ static int sd_dbg_s_register(struct gspca_dev *gspca_dev, + /* Note that there shall be no access to other page + by any other function between the page swith and + the actual register write */ +- ret = reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, index, value); ++ reg_w(gspca_dev, 0xff, 0x00); /* page 0 */ ++ reg_w(gspca_dev, index, value); + +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xdc, 0x01); ++ reg_w(gspca_dev, 0xdc, 0x01); + } +- return ret; ++ return gspca_dev->usb_err; + } + + static int sd_chip_ident(struct gspca_dev *gspca_dev, +@@ -1210,8 +1162,39 @@ static int sd_chip_ident(struct gspca_dev *gspca_dev, + } + #endif + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrput packet length */ ++{ ++ int ret = -EINVAL; ++ u8 data0, data1; ++ ++ if (len == 2) { ++ data0 = data[0]; ++ data1 = data[1]; ++ if ((data0 == 0x00 && data1 == 0x11) || ++ (data0 == 0x22 && data1 == 0x33) || ++ (data0 == 0x44 && data1 == 0x55) || ++ (data0 == 0x66 && data1 == 0x77) || ++ (data0 == 0x88 && data1 == 0x99) || ++ (data0 == 0xaa && data1 == 0xbb) || ++ (data0 == 0xcc && data1 == 0xdd) || ++ (data0 == 0xee && data1 == 0xff)) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ } ++ ++ return ret; ++} ++#endif ++ + /* sub-driver description for pac7302 */ +-static struct sd_desc sd_desc = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), +@@ -1226,6 +1209,9 @@ static struct sd_desc sd_desc = { + .set_register = sd_dbg_s_register, + .get_chip_ident = sd_chip_ident, + #endif ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + /* -- module initialisation -- */ +diff --git a/drivers/media/video/gspca/pac7311.c b/drivers/media/video/gspca/pac7311.c +index 42cfcdf..322140d 100644 +--- a/drivers/media/video/gspca/pac7311.c ++++ b/drivers/media/video/gspca/pac7311.c +@@ -51,6 +51,7 @@ + + #define MODULE_NAME "pac7311" + ++#include + #include "gspca.h" + + MODULE_AUTHOR("Thomas Kaiser thomas@kaiser-linux.li"); +@@ -88,7 +89,7 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + /* This control is for both the 7302 and the 7311 */ + { + { +@@ -200,7 +201,6 @@ static const struct v4l2_pix_format vga_mode[] = { + .priv = 0}, + }; + +-#define LOAD_PAGE3 255 + #define LOAD_PAGE4 254 + #define END_OF_SEQUENCE 0 + +@@ -259,12 +259,14 @@ static const __u8 page4_7311[] = { + 0x23, 0x28, 0x04, 0x11, 0x00, 0x00 + }; + +-static int reg_w_buf(struct gspca_dev *gspca_dev, ++static void reg_w_buf(struct gspca_dev *gspca_dev, + __u8 index, + const char *buffer, int len) + { + int ret; + ++ if (gspca_dev->usb_err < 0) ++ return; + memcpy(gspca_dev->usb_buf, buffer, len); + ret = usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), +@@ -273,20 +275,44 @@ static int reg_w_buf(struct gspca_dev *gspca_dev, + 0, /* value */ + index, gspca_dev->usb_buf, len, + 500); +- if (ret < 0) ++ if (ret < 0) { + PDEBUG(D_ERR, "reg_w_buf(): " + "Failed to write registers to index 0x%x, error %i", + index, ret); +- return ret; ++ gspca_dev->usb_err = ret; ++ } + } + ++#if 0 /* not used */ ++static __u8 reg_r(struct gspca_dev *gspca_dev, ++ __u8 index) ++{ ++ int ret; ++ ++ ret = usb_control_msg(gspca_dev->dev, ++ usb_rcvctrlpipe(gspca_dev->dev, 0), ++ 0, /* request */ ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ 0, /* value */ ++ index, gspca_dev->usb_buf, 1, ++ 500); ++ if (ret < 0) ++ PDEBUG(D_ERR, "reg_r(): " ++ "Failed to read register from index 0x%x, error %i", ++ index, ret); + +-static int reg_w(struct gspca_dev *gspca_dev, ++ return gspca_dev->usb_buf[0]; ++} ++#endif ++ ++static void reg_w(struct gspca_dev *gspca_dev, + __u8 index, + __u8 value) + { + int ret; + ++ if (gspca_dev->usb_err < 0) ++ return; + gspca_dev->usb_buf[0] = value; + ret = usb_control_msg(gspca_dev->dev, + usb_sndctrlpipe(gspca_dev->dev, 0), +@@ -294,32 +320,32 @@ static int reg_w(struct gspca_dev *gspca_dev, + USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE, + 0, index, gspca_dev->usb_buf, 1, + 500); +- if (ret < 0) ++ if (ret < 0) { + PDEBUG(D_ERR, "reg_w(): " + "Failed to write register to index 0x%x, value 0x%x, error %i", + index, value, ret); +- return ret; ++ gspca_dev->usb_err = ret; ++ } + } + +-static int reg_w_seq(struct gspca_dev *gspca_dev, ++static void reg_w_seq(struct gspca_dev *gspca_dev, + const __u8 *seq, int len) + { +- int ret = 0; + while (--len >= 0) { +- if (0 <= ret) +- ret = reg_w(gspca_dev, seq[0], seq[1]); ++ reg_w(gspca_dev, seq[0], seq[1]); + seq += 2; + } +- return ret; + } + + /* load the beginning of a page */ +-static int reg_w_page(struct gspca_dev *gspca_dev, ++static void reg_w_page(struct gspca_dev *gspca_dev, + const __u8 *page, int len) + { + int index; + int ret = 0; + ++ if (gspca_dev->usb_err < 0) ++ return; + for (index = 0; index < len; index++) { + if (page[index] == SKIP) /* skip this index */ + continue; +@@ -335,56 +361,47 @@ static int reg_w_page(struct gspca_dev *gspca_dev, + "Failed to write register to index 0x%x, " + "value 0x%x, error %i", + index, page[index], ret); ++ gspca_dev->usb_err = ret; + break; + } + } +- return ret; + } + + /* output a variable sequence */ +-static int reg_w_var(struct gspca_dev *gspca_dev, ++static void reg_w_var(struct gspca_dev *gspca_dev, + const __u8 *seq, +- const __u8 *page3, unsigned int page3_len, + const __u8 *page4, unsigned int page4_len) + { + int index, len; +- int ret = 0; + + for (;;) { + index = *seq++; + len = *seq++; + switch (len) { + case END_OF_SEQUENCE: +- return ret; ++ return; + case LOAD_PAGE4: +- ret = reg_w_page(gspca_dev, page4, page4_len); +- break; +- case LOAD_PAGE3: +- ret = reg_w_page(gspca_dev, page3, page3_len); ++ reg_w_page(gspca_dev, page4, page4_len); + break; + default: + if (len > USB_BUF_SZ) { + PDEBUG(D_ERR|D_STREAM, + "Incorrect variable sequence"); +- return -EINVAL; ++ return; + } + while (len > 0) { + if (len < 8) { +- ret = reg_w_buf(gspca_dev, ++ reg_w_buf(gspca_dev, + index, seq, len); +- if (ret < 0) +- return ret; + seq += len; + break; + } +- ret = reg_w_buf(gspca_dev, index, seq, 8); ++ reg_w_buf(gspca_dev, index, seq, 8); + seq += 8; + index += 8; + len -= 8; + } + } +- if (ret < 0) +- return ret; + } + /* not reached */ + } +@@ -412,46 +429,36 @@ static int sd_config(struct gspca_dev *gspca_dev, + } + + /* This function is used by pac7311 only */ +-static int setcontrast(struct gspca_dev *gspca_dev) ++static void setcontrast(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + +- ret = reg_w(gspca_dev, 0xff, 0x04); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x10, sd->contrast >> 4); ++ reg_w(gspca_dev, 0xff, 0x04); ++ reg_w(gspca_dev, 0x10, sd->contrast >> 4); + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + +-static int setgain(struct gspca_dev *gspca_dev) ++static void setgain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + int gain = GAIN_MAX - sd->gain; +- int ret; + + if (gain < 1) + gain = 1; + else if (gain > 245) + gain = 245; +- ret = reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x0e, 0x00); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x0f, gain); ++ reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ ++ reg_w(gspca_dev, 0x0e, 0x00); ++ reg_w(gspca_dev, 0x0f, gain); + + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + +-static int setexposure(struct gspca_dev *gspca_dev) ++static void setexposure(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + __u8 reg; + + /* register 2 of frame 3/4 contains the clock divider configuring the +@@ -463,94 +470,72 @@ static int setexposure(struct gspca_dev *gspca_dev) + else if (reg > 63) + reg = 63; + +- ret = reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x02, reg); ++ reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ ++ reg_w(gspca_dev, 0x02, reg); ++ + /* Page 1 register 8 must always be 0x08 except when not in + 640x480 mode and Page3/4 reg 2 <= 3 then it must be 9 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0xff, 0x01); + if (gspca_dev->cam.cam_mode[(int)gspca_dev->curr_mode].priv && + reg <= 3) { +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x08, 0x09); ++ reg_w(gspca_dev, 0x08, 0x09); + } else { +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x08, 0x08); ++ reg_w(gspca_dev, 0x08, 0x08); + } + + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + +-static int sethvflip(struct gspca_dev *gspca_dev) ++static void sethvflip(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + __u8 data; + +- ret = reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ ++ reg_w(gspca_dev, 0xff, 0x04); /* page 4 */ + data = (sd->hflip ? 0x04 : 0x00) | (sd->vflip ? 0x08 : 0x00); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x21, data); ++ reg_w(gspca_dev, 0x21, data); ++ + /* load registers to sensor (Bit 0, auto clear) */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x11, 0x01); +- return ret; ++ reg_w(gspca_dev, 0x11, 0x01); + } + + /* this function is called at probe and resume time for pac7311 */ + static int sd_init(struct gspca_dev *gspca_dev) + { +- return reg_w_seq(gspca_dev, init_7311, sizeof(init_7311)/2); ++ reg_w_seq(gspca_dev, init_7311, sizeof(init_7311)/2); ++ return gspca_dev->usb_err; + } + + static int sd_start(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int ret; + + sd->sof_read = 0; + +- ret = reg_w_var(gspca_dev, start_7311, +- NULL, 0, ++ reg_w_var(gspca_dev, start_7311, + page4_7311, sizeof(page4_7311)); +- if (0 <= ret) +- ret = setcontrast(gspca_dev); +- if (0 <= ret) +- ret = setgain(gspca_dev); +- if (0 <= ret) +- ret = setexposure(gspca_dev); +- if (0 <= ret) +- ret = sethvflip(gspca_dev); ++ setcontrast(gspca_dev); ++ setgain(gspca_dev); ++ setexposure(gspca_dev); ++ sethvflip(gspca_dev); + + /* set correct resolution */ + switch (gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv) { + case 2: /* 160x120 pac7311 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x17, 0x20); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x87, 0x10); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x17, 0x20); ++ reg_w(gspca_dev, 0x87, 0x10); + break; + case 1: /* 320x240 pac7311 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x17, 0x30); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x87, 0x11); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x17, 0x30); ++ reg_w(gspca_dev, 0x87, 0x11); + break; + case 0: /* 640x480 */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x17, 0x00); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x87, 0x12); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x17, 0x00); ++ reg_w(gspca_dev, 0x87, 0x12); + break; + } + +@@ -559,37 +544,24 @@ static int sd_start(struct gspca_dev *gspca_dev) + atomic_set(&sd->avg_lum, -1); + + /* start stream */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x05); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x78, 0x05); + +- return ret; ++ return gspca_dev->usb_err; + } + + static void sd_stopN(struct gspca_dev *gspca_dev) + { +- int ret; +- +- ret = reg_w(gspca_dev, 0xff, 0x04); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x27, 0x80); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x28, 0xca); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x29, 0x53); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x2a, 0x0e); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0xff, 0x01); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x3e, 0x20); +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ +- if (0 <= ret) +- ret = reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ ++ reg_w(gspca_dev, 0xff, 0x04); ++ reg_w(gspca_dev, 0x27, 0x80); ++ reg_w(gspca_dev, 0x28, 0xca); ++ reg_w(gspca_dev, 0x29, 0x53); ++ reg_w(gspca_dev, 0x2a, 0x0e); ++ reg_w(gspca_dev, 0xff, 0x01); ++ reg_w(gspca_dev, 0x3e, 0x20); ++ reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ ++ reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ ++ reg_w(gspca_dev, 0x78, 0x44); /* Bit_0=start stream, Bit_6=LED */ + } + + /* called on streamoff with alt 0 and on disconnect for 7311 */ +@@ -734,7 +706,7 @@ static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) + if (gspca_dev->streaming) { + setcontrast(gspca_dev); + } +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) +@@ -752,7 +724,7 @@ static int sd_setgain(struct gspca_dev *gspca_dev, __s32 val) + sd->gain = val; + if (gspca_dev->streaming) + setgain(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) +@@ -770,7 +742,7 @@ static int sd_setexposure(struct gspca_dev *gspca_dev, __s32 val) + sd->exposure = val; + if (gspca_dev->streaming) + setexposure(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getexposure(struct gspca_dev *gspca_dev, __s32 *val) +@@ -801,7 +773,7 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) + } + } + +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) +@@ -819,7 +791,7 @@ static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) + sd->hflip = val; + if (gspca_dev->streaming) + sethvflip(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val) +@@ -837,7 +809,7 @@ static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) + sd->vflip = val; + if (gspca_dev->streaming) + sethvflip(gspca_dev); +- return 0; ++ return gspca_dev->usb_err; + } + + static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) +@@ -848,8 +820,39 @@ static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrupt packet length */ ++{ ++ int ret = -EINVAL; ++ u8 data0, data1; ++ ++ if (len == 2) { ++ data0 = data[0]; ++ data1 = data[1]; ++ if ((data0 == 0x00 && data1 == 0x11) || ++ (data0 == 0x22 && data1 == 0x33) || ++ (data0 == 0x44 && data1 == 0x55) || ++ (data0 == 0x66 && data1 == 0x77) || ++ (data0 == 0x88 && data1 == 0x99) || ++ (data0 == 0xaa && data1 == 0xbb) || ++ (data0 == 0xcc && data1 == 0xdd) || ++ (data0 == 0xee && data1 == 0xff)) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ } ++ ++ return ret; ++} ++#endif ++ + /* sub-driver description for pac7311 */ +-static struct sd_desc sd_desc = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), +@@ -860,6 +863,9 @@ static struct sd_desc sd_desc = { + .stop0 = sd_stop0, + .pkt_scan = sd_pkt_scan, + .dq_callback = do_autogain, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + /* -- module initialisation -- */ +diff --git a/drivers/media/video/gspca/pac_common.h b/drivers/media/video/gspca/pac_common.h +index 20f67d9..8462a7c 100644 +--- a/drivers/media/video/gspca/pac_common.h ++++ b/drivers/media/video/gspca/pac_common.h +@@ -24,11 +24,10 @@ + */ + + /* We calculate the autogain at the end of the transfer of a frame, at this +- moment a frame with the old settings is being transmitted, and a frame is +- being captured with the old settings. So if we adjust the autogain we must +- ignore atleast the 2 next frames for the new settings to come into effect +- before doing any other adjustments */ +-#define PAC_AUTOGAIN_IGNORE_FRAMES 3 ++ moment a frame with the old settings is being captured and transmitted. So ++ if we adjust the gain or exposure we must ignore atleast the next frame for ++ the new settings to come into effect before doing any other adjustments. */ ++#define PAC_AUTOGAIN_IGNORE_FRAMES 2 + + static const unsigned char pac_sof_marker[5] = + { 0xff, 0xff, 0x00, 0xff, 0x96 }; +diff --git a/drivers/media/video/gspca/sn9c2028.c b/drivers/media/video/gspca/sn9c2028.c +new file mode 100644 +index 0000000..dda5fd4 +--- /dev/null ++++ b/drivers/media/video/gspca/sn9c2028.c +@@ -0,0 +1,757 @@ ++/* ++ * SN9C2028 library ++ * ++ * Copyright (C) 2009 Theodore Kilgore ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#define MODULE_NAME "sn9c2028" ++ ++#include "gspca.h" ++ ++MODULE_AUTHOR("Theodore Kilgore"); ++MODULE_DESCRIPTION("Sonix SN9C2028 USB Camera Driver"); ++MODULE_LICENSE("GPL"); ++ ++/* specific webcam descriptor */ ++struct sd { ++ struct gspca_dev gspca_dev; /* !! must be the first item */ ++ u8 sof_read; ++ u16 model; ++}; ++ ++struct init_command { ++ unsigned char instruction[6]; ++ unsigned char to_read; /* length to read. 0 means no reply requested */ ++}; ++ ++/* V4L2 controls supported by the driver */ ++static struct ctrl sd_ctrls[] = { ++}; ++ ++/* How to change the resolution of any of the VGA cams is unknown */ ++static const struct v4l2_pix_format vga_mode[] = { ++ {640, 480, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE, ++ .bytesperline = 640, ++ .sizeimage = 640 * 480 * 3 / 4, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 0}, ++}; ++ ++/* No way to change the resolution of the CIF cams is known */ ++static const struct v4l2_pix_format cif_mode[] = { ++ {352, 288, V4L2_PIX_FMT_SN9C2028, V4L2_FIELD_NONE, ++ .bytesperline = 352, ++ .sizeimage = 352 * 288 * 3 / 4, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = 0}, ++}; ++ ++/* the bytes to write are in gspca_dev->usb_buf */ ++static int sn9c2028_command(struct gspca_dev *gspca_dev, u8 *command) ++{ ++ int rc; ++ ++ PDEBUG(D_USBO, "sending command %02x%02x%02x%02x%02x%02x", command[0], ++ command[1], command[2], command[3], command[4], command[5]); ++ ++ memcpy(gspca_dev->usb_buf, command, 6); ++ rc = usb_control_msg(gspca_dev->dev, ++ usb_sndctrlpipe(gspca_dev->dev, 0), ++ USB_REQ_GET_CONFIGURATION, ++ USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, ++ 2, 0, gspca_dev->usb_buf, 6, 500); ++ if (rc < 0) { ++ PDEBUG(D_ERR, "command write [%02x] error %d", ++ gspca_dev->usb_buf[0], rc); ++ return rc; ++ } ++ ++ return 0; ++} ++ ++static int sn9c2028_read1(struct gspca_dev *gspca_dev) ++{ ++ int rc; ++ ++ rc = usb_control_msg(gspca_dev->dev, ++ usb_rcvctrlpipe(gspca_dev->dev, 0), ++ USB_REQ_GET_STATUS, ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, ++ 1, 0, gspca_dev->usb_buf, 1, 500); ++ if (rc != 1) { ++ PDEBUG(D_ERR, "read1 error %d", rc); ++ return (rc < 0) ? rc : -EIO; ++ } ++ PDEBUG(D_USBI, "read1 response %02x", gspca_dev->usb_buf[0]); ++ return gspca_dev->usb_buf[0]; ++} ++ ++static int sn9c2028_read4(struct gspca_dev *gspca_dev, u8 *reading) ++{ ++ int rc; ++ rc = usb_control_msg(gspca_dev->dev, ++ usb_rcvctrlpipe(gspca_dev->dev, 0), ++ USB_REQ_GET_STATUS, ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_INTERFACE, ++ 4, 0, gspca_dev->usb_buf, 4, 500); ++ if (rc != 4) { ++ PDEBUG(D_ERR, "read4 error %d", rc); ++ return (rc < 0) ? rc : -EIO; ++ } ++ memcpy(reading, gspca_dev->usb_buf, 4); ++ PDEBUG(D_USBI, "read4 response %02x%02x%02x%02x", reading[0], ++ reading[1], reading[2], reading[3]); ++ return rc; ++} ++ ++static int sn9c2028_long_command(struct gspca_dev *gspca_dev, u8 *command) ++{ ++ int i, status; ++ __u8 reading[4]; ++ ++ status = sn9c2028_command(gspca_dev, command); ++ if (status < 0) ++ return status; ++ ++ status = -1; ++ for (i = 0; i < 256 && status < 2; i++) ++ status = sn9c2028_read1(gspca_dev); ++ if (status != 2) { ++ PDEBUG(D_ERR, "long command status read error %d", status); ++ return (status < 0) ? status : -EIO; ++ } ++ ++ memset(reading, 0, 4); ++ status = sn9c2028_read4(gspca_dev, reading); ++ if (status < 0) ++ return status; ++ ++ /* in general, the first byte of the response is the first byte of ++ * the command, or'ed with 8 */ ++ status = sn9c2028_read1(gspca_dev); ++ if (status < 0) ++ return status; ++ ++ return 0; ++} ++ ++static int sn9c2028_short_command(struct gspca_dev *gspca_dev, u8 *command) ++{ ++ int err_code; ++ ++ err_code = sn9c2028_command(gspca_dev, command); ++ if (err_code < 0) ++ return err_code; ++ ++ err_code = sn9c2028_read1(gspca_dev); ++ if (err_code < 0) ++ return err_code; ++ ++ return 0; ++} ++ ++/* this function is called at probe time */ ++static int sd_config(struct gspca_dev *gspca_dev, ++ const struct usb_device_id *id) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ struct cam *cam = &gspca_dev->cam; ++ ++ PDEBUG(D_PROBE, "SN9C2028 camera detected (vid/pid 0x%04X:0x%04X)", ++ id->idVendor, id->idProduct); ++ ++ sd->model = id->idProduct; ++ ++ switch (sd->model) { ++ case 0x7005: ++ PDEBUG(D_PROBE, "Genius Smart 300 camera"); ++ break; ++ case 0x8000: ++ PDEBUG(D_PROBE, "DC31VC"); ++ break; ++ case 0x8001: ++ PDEBUG(D_PROBE, "Spy camera"); ++ break; ++ case 0x8003: ++ PDEBUG(D_PROBE, "CIF camera"); ++ break; ++ case 0x8008: ++ PDEBUG(D_PROBE, "Mini-Shotz ms-350 camera"); ++ break; ++ case 0x800a: ++ PDEBUG(D_PROBE, "Vivitar 3350b type camera"); ++ cam->input_flags = V4L2_IN_ST_VFLIP | V4L2_IN_ST_HFLIP; ++ break; ++ } ++ ++ switch (sd->model) { ++ case 0x8000: ++ case 0x8001: ++ case 0x8003: ++ cam->cam_mode = cif_mode; ++ cam->nmodes = ARRAY_SIZE(cif_mode); ++ break; ++ default: ++ cam->cam_mode = vga_mode; ++ cam->nmodes = ARRAY_SIZE(vga_mode); ++ } ++ return 0; ++} ++ ++/* this function is called at probe and resume time */ ++static int sd_init(struct gspca_dev *gspca_dev) ++{ ++ int status = -1; ++ ++ sn9c2028_read1(gspca_dev); ++ sn9c2028_read1(gspca_dev); ++ status = sn9c2028_read1(gspca_dev); ++ ++ return (status < 0) ? status : 0; ++} ++ ++static int run_start_commands(struct gspca_dev *gspca_dev, ++ struct init_command *cam_commands, int n) ++{ ++ int i, err_code = -1; ++ ++ for (i = 0; i < n; i++) { ++ switch (cam_commands[i].to_read) { ++ case 4: ++ err_code = sn9c2028_long_command(gspca_dev, ++ cam_commands[i].instruction); ++ break; ++ case 1: ++ err_code = sn9c2028_short_command(gspca_dev, ++ cam_commands[i].instruction); ++ break; ++ case 0: ++ err_code = sn9c2028_command(gspca_dev, ++ cam_commands[i].instruction); ++ break; ++ } ++ if (err_code < 0) ++ return err_code; ++ } ++ return 0; ++} ++ ++static int start_spy_cam(struct gspca_dev *gspca_dev) ++{ ++ struct init_command spy_start_commands[] = { ++ {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4}, ++ {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, /* width 352 */ ++ {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, /* height 288 */ ++ /* {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, */ ++ {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, ++ {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* red gain ?*/ ++ /* {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, */ ++ {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4}, ++ /* {{0x13, 0x29, 0x01, 0x0c, 0x00, 0x00}, 4}, */ ++ {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4}, ++ /* {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, */ ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4}, ++ /* {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, */ ++ {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4}, ++ {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4}, ++ {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x02, 0x06, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x03, 0x13, 0x00, 0x00, 0x00}, 4}, /*don't mess with*/ ++ /*{{0x11, 0x04, 0x06, 0x00, 0x00, 0x00}, 4}, observed */ ++ {{0x11, 0x04, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */ ++ /*{{0x11, 0x05, 0x65, 0x00, 0x00, 0x00}, 4}, observed */ ++ {{0x11, 0x05, 0x00, 0x00, 0x00, 0x00}, 4}, /* brighter */ ++ {{0x11, 0x06, 0xb1, 0x00, 0x00, 0x00}, 4}, /* observed */ ++ {{0x11, 0x07, 0x00, 0x00, 0x00, 0x00}, 4}, ++ /*{{0x11, 0x08, 0x06, 0x00, 0x00, 0x00}, 4}, observed */ ++ {{0x11, 0x08, 0x0b, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x09, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0a, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0c, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0d, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0e, 0x04, 0x00, 0x00, 0x00}, 4}, ++ /* {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4}, */ ++ /* brightness or gain. 0 is default. 4 is good ++ * indoors at night with incandescent lighting */ ++ {{0x11, 0x0f, 0x04, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x10, 0x06, 0x00, 0x00, 0x00}, 4}, /*hstart or hoffs*/ ++ {{0x11, 0x11, 0x06, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x14, 0x02, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x13, 0x01, 0x00, 0x00, 0x00}, 4}, ++ /* {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, observed */ ++ {{0x1b, 0x02, 0x11, 0x00, 0x00, 0x00}, 1}, /* brighter */ ++ /* {{0x1b, 0x13, 0x01, 0x00, 0x00, 0x00}, 1}, observed */ ++ {{0x1b, 0x13, 0x11, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1}, /* compresses */ ++ /* Camera should start to capture now. */ ++ }; ++ ++ return run_start_commands(gspca_dev, spy_start_commands, ++ ARRAY_SIZE(spy_start_commands)); ++} ++ ++static int start_cif_cam(struct gspca_dev *gspca_dev) ++{ ++ struct init_command cif_start_commands[] = { ++ {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ /* The entire sequence below seems redundant */ ++ /* {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x22, 0x01, 0x06, 0x00, 0x00}, 4}, ++ {{0x13, 0x23, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, width? ++ {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, height? ++ {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample? ++ {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4}, ++ {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4}, ++ {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4}, ++ {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4},*/ ++ {{0x1b, 0x21, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x17, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x19, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x03, 0x5a, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x04, 0x27, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x05, 0x01, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x12, 0x14, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x14, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x15, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x16, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x77, 0xa2, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x06, 0x0f, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x07, 0x14, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x08, 0x0f, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x09, 0x10, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x0e, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x12, 0x07, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x10, 0x1f, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1}, ++ {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 1}, /* width/8 */ ++ {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 1}, /* height/8 */ ++ /* {{0x13, 0x27, 0x01, 0x68, 0x00, 0x00}, 4}, subsample? ++ * {{0x13, 0x28, 0x01, 0x1e, 0x00, 0x00}, 4}, does nothing ++ * {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, */ ++ /* {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4}, ++ * causes subsampling ++ * but not a change in the resolution setting! */ ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x01, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x08, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x06, 0x00, 0x00}, 4}, ++ {{0x13, 0x28, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x1b, 0x04, 0x6d, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x05, 0x03, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x0e, 0x01, 0x00, 0x00, 0x00}, 1}, ++ {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x1b, 0x0f, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x10, 0x0f, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x02, 0x06, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1},/* use compression */ ++ /* Camera should start to capture now. */ ++ }; ++ ++ return run_start_commands(gspca_dev, cif_start_commands, ++ ARRAY_SIZE(cif_start_commands)); ++} ++ ++static int start_ms350_cam(struct gspca_dev *gspca_dev) ++{ ++ struct init_command ms350_start_commands[] = { ++ {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x22, 0x01, 0x04, 0x00, 0x00}, 4}, ++ {{0x13, 0x23, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, ++ {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, ++ {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, ++ {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, ++ {{0x13, 0x29, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4}, ++ {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4}, ++ {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x00, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x01, 0x70, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x02, 0x05, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x03, 0x5d, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x04, 0x07, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x05, 0x25, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x06, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x07, 0x09, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x08, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x09, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0a, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0b, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0c, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0d, 0x0c, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0e, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x0f, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x11, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x13, 0x63, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x15, 0x70, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x18, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x11, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* width */ ++ {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* height */ ++ {{0x13, 0x28, 0x01, 0x09, 0x00, 0x00}, 4}, /* vstart? */ ++ {{0x13, 0x27, 0x01, 0x28, 0x00, 0x00}, 4}, ++ {{0x13, 0x29, 0x01, 0x40, 0x00, 0x00}, 4}, /* hstart? */ ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4}, ++ {{0x1b, 0x02, 0x05, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x18, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x02, 0x0a, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x11, 0x01, 0x00, 0x00, 0x00}, 0}, ++ /* Camera should start to capture now. */ ++ }; ++ ++ return run_start_commands(gspca_dev, ms350_start_commands, ++ ARRAY_SIZE(ms350_start_commands)); ++} ++ ++static int start_genius_cam(struct gspca_dev *gspca_dev) ++{ ++ struct init_command genius_start_commands[] = { ++ {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x16, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x10, 0x00, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x16, 0x00, 0x00}, 4}, ++ {{0x13, 0x26, 0x01, 0x12, 0x00, 0x00}, 4}, ++ /* "preliminary" width and height settings */ ++ {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4}, ++ {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, ++ {{0x13, 0x29, 0x01, 0x22, 0x00, 0x00}, 4}, ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x09, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x07, 0x00, 0x00}, 4}, ++ {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x11, 0x64, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x13, 0x91, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x15, 0x20, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x16, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x17, 0x60, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x21, 0x2d, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x23, 0x03, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x25, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x26, 0x02, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x27, 0x88, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x30, 0x38, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x31, 0x2a, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x32, 0x2a, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x33, 0x2a, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x34, 0x02, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x5b, 0x0a, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, /* real width */ ++ {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, /* real height */ ++ {{0x13, 0x28, 0x01, 0x0e, 0x00, 0x00}, 4}, ++ {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, ++ {{0x13, 0x29, 0x01, 0x62, 0x00, 0x00}, 4}, ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4}, ++ {{0x11, 0x20, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x21, 0x2a, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x22, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x23, 0x28, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x10, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x11, 0x04, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x12, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x13, 0x03, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x14, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x15, 0xe0, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x16, 0x02, 0x00, 0x00, 0x00}, 4}, ++ {{0x11, 0x17, 0x80, 0x00, 0x00, 0x00}, 4}, ++ {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1}, ++ {{0x1c, 0x20, 0x00, 0x2a, 0x00, 0x00}, 1}, ++ {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 0} ++ /* Camera should start to capture now. */ ++ }; ++ ++ return run_start_commands(gspca_dev, genius_start_commands, ++ ARRAY_SIZE(genius_start_commands)); ++} ++ ++static int start_vivitar_cam(struct gspca_dev *gspca_dev) ++{ ++ struct init_command vivitar_start_commands[] = { ++ {{0x0c, 0x01, 0x00, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x20, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x21, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x22, 0x01, 0x01, 0x00, 0x00}, 4}, ++ {{0x13, 0x23, 0x01, 0x01, 0x00, 0x00}, 4}, ++ {{0x13, 0x24, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, ++ {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, ++ {{0x13, 0x27, 0x01, 0x20, 0x00, 0x00}, 4}, ++ {{0x13, 0x28, 0x01, 0x0a, 0x00, 0x00}, 4}, ++ /* ++ * Above is changed from OEM 0x0b. Fixes Bayer tiling. ++ * Presumably gives a vertical shift of one row. ++ */ ++ {{0x13, 0x29, 0x01, 0x20, 0x00, 0x00}, 4}, ++ /* Above seems to do horizontal shift. */ ++ {{0x13, 0x2a, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2b, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x2c, 0x01, 0x02, 0x00, 0x00}, 4}, ++ {{0x13, 0x2d, 0x01, 0x03, 0x00, 0x00}, 4}, ++ {{0x13, 0x2e, 0x01, 0x0f, 0x00, 0x00}, 4}, ++ {{0x13, 0x2f, 0x01, 0x0c, 0x00, 0x00}, 4}, ++ /* Above three commands seem to relate to brightness. */ ++ {{0x12, 0x34, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x13, 0x34, 0x01, 0xa1, 0x00, 0x00}, 4}, ++ {{0x13, 0x35, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x1b, 0x12, 0x80, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x01, 0x77, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x02, 0x3a, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x12, 0x78, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x13, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x14, 0x80, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x15, 0x34, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x1b, 0x04, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x20, 0x44, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x23, 0xee, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x26, 0xa0, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x27, 0x9a, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x28, 0xa0, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x29, 0x30, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x2a, 0x80, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x2b, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x2f, 0x3d, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x30, 0x24, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x32, 0x86, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x60, 0xa9, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x61, 0x42, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x65, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x69, 0x38, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x6f, 0x88, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x70, 0x0b, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x71, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x74, 0x21, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x75, 0x86, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x76, 0x00, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x7d, 0xf3, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x17, 0x1c, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x18, 0xc0, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x19, 0x05, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x1a, 0xf6, 0x00, 0x00, 0x00}, 1}, ++ /* {{0x13, 0x25, 0x01, 0x28, 0x00, 0x00}, 4}, ++ {{0x13, 0x26, 0x01, 0x1e, 0x00, 0x00}, 4}, ++ {{0x13, 0x28, 0x01, 0x0b, 0x00, 0x00}, 4}, */ ++ {{0x20, 0x36, 0x06, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x10, 0x26, 0x00, 0x00, 0x00}, 1}, ++ {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x1b, 0x76, 0x03, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x36, 0x05, 0x00, 0x00, 0x00}, 1}, ++ {{0x1b, 0x00, 0x3f, 0x00, 0x00, 0x00}, 1}, ++ /* Above is brightness; OEM driver setting is 0x10 */ ++ {{0x12, 0x27, 0x01, 0x00, 0x00, 0x00}, 4}, ++ {{0x20, 0x29, 0x30, 0x00, 0x00, 0x00}, 1}, ++ {{0x20, 0x34, 0xa1, 0x00, 0x00, 0x00}, 1} ++ }; ++ ++ return run_start_commands(gspca_dev, vivitar_start_commands, ++ ARRAY_SIZE(vivitar_start_commands)); ++} ++ ++static int sd_start(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int err_code; ++ ++ sd->sof_read = 0; ++ ++ switch (sd->model) { ++ case 0x7005: ++ err_code = start_genius_cam(gspca_dev); ++ break; ++ case 0x8001: ++ err_code = start_spy_cam(gspca_dev); ++ break; ++ case 0x8003: ++ err_code = start_cif_cam(gspca_dev); ++ break; ++ case 0x8008: ++ err_code = start_ms350_cam(gspca_dev); ++ break; ++ case 0x800a: ++ err_code = start_vivitar_cam(gspca_dev); ++ break; ++ default: ++ PDEBUG(D_ERR, "Starting unknown camera, please report this"); ++ return -ENXIO; ++ } ++ ++ return err_code; ++} ++ ++static void sd_stopN(struct gspca_dev *gspca_dev) ++{ ++ int result; ++ __u8 data[6]; ++ ++ result = sn9c2028_read1(gspca_dev); ++ if (result < 0) ++ PDEBUG(D_ERR, "Camera Stop read failed"); ++ ++ memset(data, 0, 6); ++ data[0] = 0x14; ++ result = sn9c2028_command(gspca_dev, data); ++ if (result < 0) ++ PDEBUG(D_ERR, "Camera Stop command failed"); ++} ++ ++/* Include sn9c2028 sof detection functions */ ++#include "sn9c2028.h" ++ ++static void sd_pkt_scan(struct gspca_dev *gspca_dev, ++ __u8 *data, /* isoc packet */ ++ int len) /* iso packet length */ ++{ ++ unsigned char *sof; ++ ++ sof = sn9c2028_find_sof(gspca_dev, data, len); ++ if (sof) { ++ int n; ++ ++ /* finish decoding current frame */ ++ n = sof - data; ++ if (n > sizeof sn9c2028_sof_marker) ++ n -= sizeof sn9c2028_sof_marker; ++ else ++ n = 0; ++ gspca_frame_add(gspca_dev, LAST_PACKET, data, n); ++ /* Start next frame. */ ++ gspca_frame_add(gspca_dev, FIRST_PACKET, ++ sn9c2028_sof_marker, sizeof sn9c2028_sof_marker); ++ len -= sof - data; ++ data = sof; ++ } ++ gspca_frame_add(gspca_dev, INTER_PACKET, data, len); ++} ++ ++/* sub-driver description */ ++static const struct sd_desc sd_desc = { ++ .name = MODULE_NAME, ++ .ctrls = sd_ctrls, ++ .nctrls = ARRAY_SIZE(sd_ctrls), ++ .config = sd_config, ++ .init = sd_init, ++ .start = sd_start, ++ .stopN = sd_stopN, ++ .pkt_scan = sd_pkt_scan, ++}; ++ ++/* -- module initialisation -- */ ++static const __devinitdata struct usb_device_id device_table[] = { ++ {USB_DEVICE(0x0458, 0x7005)}, /* Genius Smart 300, version 2 */ ++ /* The Genius Smart is untested. I can't find an owner ! */ ++ /* {USB_DEVICE(0x0c45, 0x8000)}, DC31VC, Don't know this camera */ ++ {USB_DEVICE(0x0c45, 0x8001)}, /* Wild Planet digital spy cam */ ++ {USB_DEVICE(0x0c45, 0x8003)}, /* Several small CIF cameras */ ++ /* {USB_DEVICE(0x0c45, 0x8006)}, Unknown VGA camera */ ++ {USB_DEVICE(0x0c45, 0x8008)}, /* Mini-Shotz ms-350 */ ++ {USB_DEVICE(0x0c45, 0x800a)}, /* Vivicam 3350B */ ++ {} ++}; ++MODULE_DEVICE_TABLE(usb, device_table); ++ ++/* -- device connect -- */ ++static int sd_probe(struct usb_interface *intf, ++ const struct usb_device_id *id) ++{ ++ return gspca_dev_probe(intf, id, &sd_desc, sizeof(struct sd), ++ THIS_MODULE); ++} ++ ++static struct usb_driver sd_driver = { ++ .name = MODULE_NAME, ++ .id_table = device_table, ++ .probe = sd_probe, ++ .disconnect = gspca_disconnect, ++#ifdef CONFIG_PM ++ .suspend = gspca_suspend, ++ .resume = gspca_resume, ++#endif ++}; ++ ++/* -- module insert / remove -- */ ++static int __init sd_mod_init(void) ++{ ++ int ret; ++ ++ ret = usb_register(&sd_driver); ++ if (ret < 0) ++ return ret; ++ PDEBUG(D_PROBE, "registered"); ++ return 0; ++} ++ ++static void __exit sd_mod_exit(void) ++{ ++ usb_deregister(&sd_driver); ++ PDEBUG(D_PROBE, "deregistered"); ++} ++ ++module_init(sd_mod_init); ++module_exit(sd_mod_exit); +diff --git a/drivers/media/video/gspca/sn9c2028.h b/drivers/media/video/gspca/sn9c2028.h +new file mode 100644 +index 0000000..8fd1d3e +--- /dev/null ++++ b/drivers/media/video/gspca/sn9c2028.h +@@ -0,0 +1,51 @@ ++/* ++ * SN9C2028 common functions ++ * ++ * Copyright (C) 2009 Theodore Kilgore ++ * ++ * Based closely upon the file gspca/pac_common.h ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++static const unsigned char sn9c2028_sof_marker[5] = ++ { 0xff, 0xff, 0x00, 0xc4, 0xc4 }; ++ ++static unsigned char *sn9c2028_find_sof(struct gspca_dev *gspca_dev, ++ unsigned char *m, int len) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ int i; ++ ++ /* Search for the SOF marker (fixed part) in the header */ ++ for (i = 0; i < len; i++) { ++ if (m[i] == sn9c2028_sof_marker[sd->sof_read]) { ++ sd->sof_read++; ++ if (sd->sof_read == sizeof(sn9c2028_sof_marker)) { ++ PDEBUG(D_FRAM, ++ "SOF found, bytes to analyze: %u." ++ " Frame starts at byte #%u", ++ len, i + 1); ++ sd->sof_read = 0; ++ return m + i + 1; ++ } ++ } else { ++ sd->sof_read = 0; ++ } ++ } ++ ++ return NULL; ++} +diff --git a/drivers/media/video/gspca/sn9c20x.c b/drivers/media/video/gspca/sn9c20x.c +index 0ca1c06..4a1bc08 100644 +--- a/drivers/media/video/gspca/sn9c20x.c ++++ b/drivers/media/video/gspca/sn9c20x.c +@@ -129,7 +129,7 @@ static int sd_getexposure(struct gspca_dev *gspca_dev, s32 *val); + static int sd_setautoexposure(struct gspca_dev *gspca_dev, s32 val); + static int sd_getautoexposure(struct gspca_dev *gspca_dev, s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + #define BRIGHTNESS_IDX 0 + { +@@ -1506,36 +1506,36 @@ static int set_cmatrix(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + s32 hue_coord, hue_index = 180 + sd->hue; + u8 cmatrix[21]; +- memset(cmatrix, 0, 21); + ++ memset(cmatrix, 0, sizeof cmatrix); + cmatrix[2] = (sd->contrast * 0x25 / 0x100) + 0x26; + cmatrix[0] = 0x13 + (cmatrix[2] - 0x26) * 0x13 / 0x25; + cmatrix[4] = 0x07 + (cmatrix[2] - 0x26) * 0x07 / 0x25; + cmatrix[18] = sd->brightness - 0x80; + + hue_coord = (hsv_red_x[hue_index] * sd->saturation) >> 8; +- cmatrix[6] = (unsigned char)(hue_coord & 0xff); +- cmatrix[7] = (unsigned char)((hue_coord >> 8) & 0x0f); ++ cmatrix[6] = hue_coord; ++ cmatrix[7] = (hue_coord >> 8) & 0x0f; + + hue_coord = (hsv_red_y[hue_index] * sd->saturation) >> 8; +- cmatrix[8] = (unsigned char)(hue_coord & 0xff); +- cmatrix[9] = (unsigned char)((hue_coord >> 8) & 0x0f); ++ cmatrix[8] = hue_coord; ++ cmatrix[9] = (hue_coord >> 8) & 0x0f; + + hue_coord = (hsv_green_x[hue_index] * sd->saturation) >> 8; +- cmatrix[10] = (unsigned char)(hue_coord & 0xff); +- cmatrix[11] = (unsigned char)((hue_coord >> 8) & 0x0f); ++ cmatrix[10] = hue_coord; ++ cmatrix[11] = (hue_coord >> 8) & 0x0f; + + hue_coord = (hsv_green_y[hue_index] * sd->saturation) >> 8; +- cmatrix[12] = (unsigned char)(hue_coord & 0xff); +- cmatrix[13] = (unsigned char)((hue_coord >> 8) & 0x0f); ++ cmatrix[12] = hue_coord; ++ cmatrix[13] = (hue_coord >> 8) & 0x0f; + + hue_coord = (hsv_blue_x[hue_index] * sd->saturation) >> 8; +- cmatrix[14] = (unsigned char)(hue_coord & 0xff); +- cmatrix[15] = (unsigned char)((hue_coord >> 8) & 0x0f); ++ cmatrix[14] = hue_coord; ++ cmatrix[15] = (hue_coord >> 8) & 0x0f; + + hue_coord = (hsv_blue_y[hue_index] * sd->saturation) >> 8; +- cmatrix[16] = (unsigned char)(hue_coord & 0xff); +- cmatrix[17] = (unsigned char)((hue_coord >> 8) & 0x0f); ++ cmatrix[16] = hue_coord; ++ cmatrix[17] = (hue_coord >> 8) & 0x0f; + + return reg_w(gspca_dev, 0x10e1, cmatrix, 21); + } +@@ -2015,6 +2015,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + default: + cam->cam_mode = vga_mode; + cam->nmodes = ARRAY_SIZE(vga_mode); ++ break; + } + + sd->old_step = 0; +@@ -2319,7 +2320,7 @@ static void do_autogain(struct gspca_dev *gspca_dev, u16 avg_lum) + } + } + if (avg_lum > MAX_AVG_LUM) { +- if (sd->gain >= 1) { ++ if (sd->gain > 0) { + sd->gain--; + set_gain(gspca_dev); + } +@@ -2347,7 +2348,7 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, + { + struct sd *sd = (struct sd *) gspca_dev; + int avg_lum; +- static unsigned char frame_header[] = ++ static u8 frame_header[] = + {0xff, 0xff, 0x00, 0xc4, 0xc4, 0x96}; + if (len == 64 && memcmp(data, frame_header, 6) == 0) { + avg_lum = ((data[35] >> 2) & 3) | +diff --git a/drivers/media/video/gspca/sonixb.c b/drivers/media/video/gspca/sonixb.c +index ddff2b5..3830973 100644 +--- a/drivers/media/video/gspca/sonixb.c ++++ b/drivers/media/video/gspca/sonixb.c +@@ -42,6 +42,7 @@ Reg Use + + #define MODULE_NAME "sonixb" + ++#include + #include "gspca.h" + + MODULE_AUTHOR("Michel Xhaard "); +@@ -53,9 +54,11 @@ struct sd { + struct gspca_dev gspca_dev; /* !! must be the first item */ + atomic_t avg_lum; + int prev_avg_lum; ++ int exp_too_low_cnt; ++ int exp_too_high_cnt; + ++ unsigned short exposure; + unsigned char gain; +- unsigned char exposure; + unsigned char brightness; + unsigned char autogain; + unsigned char autogain_ignore_frames; +@@ -73,8 +76,9 @@ struct sd { + #define SENSOR_OV7630 2 + #define SENSOR_PAS106 3 + #define SENSOR_PAS202 4 +-#define SENSOR_TAS5110 5 +-#define SENSOR_TAS5130CXX 6 ++#define SENSOR_TAS5110C 5 ++#define SENSOR_TAS5110D 6 ++#define SENSOR_TAS5130CXX 7 + __u8 reg11; + }; + +@@ -95,13 +99,15 @@ struct sensor_data { + /* sensor_data flags */ + #define F_GAIN 0x01 /* has gain */ + #define F_SIF 0x02 /* sif or vga */ ++#define F_COARSE_EXPO 0x04 /* exposure control is coarse */ + + /* priv field of struct v4l2_pix_format flags (do not use low nibble!) */ + #define MODE_RAW 0x10 /* raw bayer mode */ + #define MODE_REDUCED_SIF 0x20 /* vga mode (320x240 / 160x120) on sif cam */ + + /* ctrl_dis helper macros */ +-#define NO_EXPO ((1 << EXPOSURE_IDX) | (1 << AUTOGAIN_IDX)) ++#define NO_EXPO ((1 << EXPOSURE_IDX) | (1 << COARSE_EXPOSURE_IDX) | \ ++ (1 << AUTOGAIN_IDX)) + #define NO_FREQ (1 << FREQ_IDX) + #define NO_BRIGHTNESS (1 << BRIGHTNESS_IDX) + +@@ -127,11 +133,10 @@ struct sensor_data { + } + + /* We calculate the autogain at the end of the transfer of a frame, at this +- moment a frame with the old settings is being transmitted, and a frame is +- being captured with the old settings. So if we adjust the autogain we must +- ignore atleast the 2 next frames for the new settings to come into effect +- before doing any other adjustments */ +-#define AUTOGAIN_IGNORE_FRAMES 3 ++ moment a frame with the old settings is being captured and transmitted. So ++ if we adjust the gain or exposure we must ignore atleast the next frame for ++ the new settings to come into effect before doing any other adjustments. */ ++#define AUTOGAIN_IGNORE_FRAMES 1 + + /* V4L2 controls supported by the driver */ + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); +@@ -145,7 +150,7 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + #define BRIGHTNESS_IDX 0 + { + { +@@ -171,7 +176,7 @@ static struct ctrl sd_ctrls[] = { + .maximum = 255, + .step = 1, + #define GAIN_DEF 127 +-#define GAIN_KNEE 200 ++#define GAIN_KNEE 230 + .default_value = GAIN_DEF, + }, + .set = sd_setgain, +@@ -183,10 +188,10 @@ static struct ctrl sd_ctrls[] = { + .id = V4L2_CID_EXPOSURE, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Exposure", +-#define EXPOSURE_DEF 16 /* 32 ms / 30 fps */ +-#define EXPOSURE_KNEE 50 /* 100 ms / 10 fps */ ++#define EXPOSURE_DEF 66 /* 33 ms / 30 fps (except on PASXXX) */ ++#define EXPOSURE_KNEE 200 /* 100 ms / 10 fps (except on PASXXX) */ + .minimum = 0, +- .maximum = 255, ++ .maximum = 1023, + .step = 1, + .default_value = EXPOSURE_DEF, + .flags = 0, +@@ -194,7 +199,23 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setexposure, + .get = sd_getexposure, + }, +-#define AUTOGAIN_IDX 3 ++#define COARSE_EXPOSURE_IDX 3 ++ { ++ { ++ .id = V4L2_CID_EXPOSURE, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Exposure", ++#define COARSE_EXPOSURE_DEF 2 /* 30 fps */ ++ .minimum = 2, ++ .maximum = 15, ++ .step = 1, ++ .default_value = COARSE_EXPOSURE_DEF, ++ .flags = 0, ++ }, ++ .set = sd_setexposure, ++ .get = sd_getexposure, ++ }, ++#define AUTOGAIN_IDX 4 + { + { + .id = V4L2_CID_AUTOGAIN, +@@ -210,7 +231,7 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setautogain, + .get = sd_getautogain, + }, +-#define FREQ_IDX 4 ++#define FREQ_IDX 5 + { + { + .id = V4L2_CID_POWER_LINE_FREQUENCY, +@@ -219,7 +240,7 @@ static struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ + .step = 1, +-#define FREQ_DEF 1 ++#define FREQ_DEF 0 + .default_value = FREQ_DEF, + }, + .set = sd_setfreq, +@@ -297,10 +318,18 @@ static const __u8 hv7131_sensor_init[][8] = { + {0xa0, 0x11, 0x30, 0x10, 0x0e, 0x28, 0x00, 0x15}, + }; + static const __u8 initOv6650[] = { ++#if 1 + 0x44, 0x44, 0x00, 0x00, 0x00, 0x00, 0x00, 0x80, + 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, + 0x00, 0x01, 0x01, 0x0a, 0x16, 0x12, 0x68, 0x8b, + 0x10, 0x1d, 0x10, 0x02, 0x02, 0x09, 0x07 ++#else ++/* old version? */ ++ 0x64, 0x44, 0x28, 0x00, 0x00, 0x00, 0x00, 0x10, ++ 0x60, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x01, 0x01, 0x0a, 0x14, 0x0f, 0x68, 0x8b, ++ 0x10, 0x1d, 0x10, 0x01, 0x01, 0x07, 0x06 ++#endif + }; + static const __u8 ov6650_sensor_init[][8] = + { +@@ -333,6 +362,24 @@ static const __u8 ov6650_sensor_init[][8] = + /* Some more unknown stuff */ + {0xa0, 0x60, 0x68, 0x04, 0x68, 0xd8, 0xa4, 0x10}, + {0xd0, 0x60, 0x17, 0x24, 0xd6, 0x04, 0x94, 0x10}, /* Clipreg */ ++#if 0 ++ /* HDG, don't change registers 0x2d, 0x32 & 0x33 from their reset ++ defaults, doing so mucks up the framerate, where as the defaults ++ seem to work good, the combinations below have been observed ++ under windows and are kept for future reference */ ++ {0xa0, 0x60, 0x2d, 0x0a, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x33, 0x40, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x2d, 0x2a, 0x99, 0x04, 0x94, 0x15}, ++ {0xa0, 0x60, 0x2d, 0x2b, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x33, 0x00, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x2d, 0x2b, 0x99, 0x04, 0x94, 0x16}, ++ {0xa0, 0x60, 0x32, 0x00, 0x99, 0x04, 0x94, 0x16}, ++ /* Low Light (Enabled: 0x32 0x1 | Disabled: 0x32 0x00) */ ++ {0xa0, 0x60, 0x33, 0x29, 0x99, 0x04, 0x94, 0x16}, ++ /* Low Ligth (Enabled: 0x33 0x13 | Disabled: 0x33 0x29) */ ++#endif + }; + + static const __u8 initOv7630[] = { +@@ -341,11 +388,15 @@ static const __u8 initOv7630[] = { + 0x00, 0x01, 0x01, 0x0a, /* r11 .. r14 */ + 0x28, 0x1e, /* H & V sizes r15 .. r16 */ + 0x68, COMP2, MCK_INIT1, /* r17 .. r19 */ ++#if 1 + 0x1d, 0x10, 0x02, 0x03, 0x0f, 0x0c /* r1a .. r1f */ ++#else /* jfm from win */ ++ 0x1d, 0x10, 0x06, 0x01, 0x00, 0x03 /* r1a .. r1f */ ++#endif + }; + static const __u8 initOv7630_3[] = { + 0x44, 0x44, 0x00, 0x1a, 0x20, 0x20, 0x20, 0x80, /* r01 .. r08 */ +- 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x04, /* r09 .. r10 */ ++ 0x21, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, /* r09 .. r10 */ + 0x00, 0x02, 0x01, 0x0a, /* r11 .. r14 */ + 0x28, 0x1e, /* H & V sizes r15 .. r16 */ + 0x68, 0x8f, MCK_INIT1, /* r17 .. r19 */ +@@ -387,6 +438,30 @@ static const __u8 initPas106[] = { + 0x18, 0x10, 0x02, 0x02, 0x09, 0x07 + }; + /* compression 0x86 mckinit1 0x2b */ ++ ++/* "Known" PAS106B registers: ++ 0x02 clock divider ++ 0x03 Variable framerate bits 4-11 ++ 0x04 Var framerate bits 0-3, one must leave the 4 msb's at 0 !! ++ The variable framerate control must never be set lower then 300, ++ which sets the framerate at 90 / reg02, otherwise vsync is lost. ++ 0x05 Shutter Time Line Offset, this can be used as an exposure control: ++ 0 = use full frame time, 255 = no exposure at all ++ Note this may never be larger then "var-framerate control" / 2 - 2. ++ When var-framerate control is < 514, no exposure is reached at the max ++ allowed value for the framerate control value, rather then at 255. ++ 0x06 Shutter Time Pixel Offset, like reg05 this influences exposure, but ++ only a very little bit, leave at 0xcd ++ 0x07 offset sign bit (bit0 1 > negative offset) ++ 0x08 offset ++ 0x09 Blue Gain ++ 0x0a Green1 Gain ++ 0x0b Green2 Gain ++ 0x0c Red Gain ++ 0x0e Global gain ++ 0x13 Write 1 to commit settings to sensor ++*/ ++ + static const __u8 pas106_sensor_init[][8] = { + /* Pixel Clock Divider 6 */ + { 0xa1, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x14 }, +@@ -433,37 +508,55 @@ static const __u8 initPas202[] = { + 0x44, 0x44, 0x21, 0x30, 0x00, 0x00, 0x00, 0x80, 0x40, 0x00, 0x00, 0x00, + 0x00, 0x00, + 0x00, 0x00, 0x00, 0x06, 0x03, 0x0a, +- 0x28, 0x1e, 0x28, 0x89, 0x20, ++ 0x28, 0x1e, 0x20, 0x89, 0x20, + 0x00, 0x00, 0x02, 0x03, 0x0f, 0x0c + }; ++ ++/* "Known" PAS202BCB registers: ++ 0x02 clock divider ++ 0x04 Variable framerate bits 6-11 (*) ++ 0x05 Var framerate bits 0-5, one must leave the 2 msb's at 0 !! ++ 0x07 Blue Gain ++ 0x08 Green Gain ++ 0x09 Red Gain ++ 0x0b offset sign bit (bit0 1 > negative offset) ++ 0x0c offset ++ 0x0e Unknown image is slightly brighter when bit 0 is 0, if reg0f is 0 too, ++ leave at 1 otherwise we get a jump in our exposure control ++ 0x0f Exposure 0-255, 0 = use full frame time, 255 = no exposure at all ++ 0x10 Master gain 0 - 31 ++ 0x11 write 1 to apply changes ++ (*) The variable framerate control must never be set lower then 500 ++ which sets the framerate at 30 / reg02, otherwise vsync is lost. ++*/ + static const __u8 pas202_sensor_init[][8] = { +- {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10}, ++ /* Set the clock divider to 4 -> 30 / 4 = 7.5 fps, we would like ++ to set it lower, but for some reason the bridge starts missing ++ vsync's then */ ++ {0xa0, 0x40, 0x02, 0x04, 0x00, 0x00, 0x00, 0x10}, + {0xd0, 0x40, 0x04, 0x07, 0x34, 0x00, 0x09, 0x10}, + {0xd0, 0x40, 0x08, 0x01, 0x00, 0x00, 0x01, 0x10}, +- {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x00, 0x32, 0x10}, ++ {0xd0, 0x40, 0x0C, 0x00, 0x0C, 0x01, 0x32, 0x10}, + {0xd0, 0x40, 0x10, 0x00, 0x01, 0x00, 0x63, 0x10}, + {0xa0, 0x40, 0x15, 0x70, 0x01, 0x00, 0x63, 0x10}, + {0xa0, 0x40, 0x18, 0x00, 0x01, 0x00, 0x63, 0x10}, + {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, + {0xa0, 0x40, 0x03, 0x56, 0x01, 0x00, 0x63, 0x10}, + {0xa0, 0x40, 0x11, 0x01, 0x01, 0x00, 0x63, 0x10}, +- {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x10}, +- {0xb0, 0x40, 0x0e, 0x00, 0x3d, 0x00, 0x63, 0x10}, +- +- {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16}, +- {0xa0, 0x40, 0x10, 0x08, 0x3d, 0x00, 0x63, 0x15}, +- {0xa0, 0x40, 0x02, 0x04, 0x3d, 0x00, 0x63, 0x16}, +- {0xa0, 0x40, 0x11, 0x01, 0x3d, 0x00, 0x63, 0x16}, +- {0xb0, 0x40, 0x0e, 0x00, 0x31, 0x00, 0x63, 0x16}, +- {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16}, +- {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15}, +- {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16}, + }; + +-static const __u8 initTas5110[] = { ++static const __u8 initTas5110c[] = { + 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, + 0x00, 0x00, +- 0x00, 0x01, 0x00, 0x45, 0x09, 0x0a, ++ 0x00, 0x00, 0x00, 0x45, 0x09, 0x0a, ++ 0x16, 0x12, 0x60, 0x86, 0x2b, ++ 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07 ++}; ++/* Same as above, except a different hstart */ ++static const __u8 initTas5110d[] = { ++ 0x44, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, ++ 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x41, 0x09, 0x0a, + 0x16, 0x12, 0x60, 0x86, 0x2b, + 0x14, 0x0a, 0x02, 0x02, 0x09, 0x07 + }; +@@ -476,7 +569,7 @@ static const __u8 tas5110_sensor_init[][8] = { + static const __u8 initTas5130[] = { + 0x04, 0x03, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x11, 0x00, 0x00, 0x00, + 0x00, 0x00, +- 0x00, 0x01, 0x00, 0x68, 0x0c, 0x0a, ++ 0x00, 0x00, 0x00, 0x68, 0x0c, 0x0a, + 0x28, 0x1e, 0x60, COMP, MCK_INIT, + 0x18, 0x10, 0x04, 0x03, 0x11, 0x0c + }; +@@ -493,12 +586,14 @@ SENS(initHv7131, NULL, hv7131_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, 0), + SENS(initOv6650, NULL, ov6650_sensor_init, NULL, NULL, F_GAIN|F_SIF, 0, 0x60), + SENS(initOv7630, initOv7630_3, ov7630_sensor_init, NULL, ov7630_sensor_init_3, + F_GAIN, 0, 0x21), +-SENS(initPas106, NULL, pas106_sensor_init, NULL, NULL, F_SIF, NO_EXPO|NO_FREQ, ++SENS(initPas106, NULL, pas106_sensor_init, NULL, NULL, F_GAIN|F_SIF, NO_FREQ, + 0), +-SENS(initPas202, initPas202, pas202_sensor_init, NULL, NULL, 0, +- NO_EXPO|NO_FREQ, 0), +-SENS(initTas5110, NULL, tas5110_sensor_init, NULL, NULL, F_GAIN|F_SIF, +- NO_BRIGHTNESS|NO_FREQ, 0), ++SENS(initPas202, initPas202, pas202_sensor_init, NULL, NULL, F_GAIN, ++ NO_FREQ, 0), ++SENS(initTas5110c, NULL, tas5110_sensor_init, NULL, NULL, ++ F_GAIN|F_SIF|F_COARSE_EXPO, NO_BRIGHTNESS|NO_FREQ, 0), ++SENS(initTas5110d, NULL, tas5110_sensor_init, NULL, NULL, ++ F_GAIN|F_SIF|F_COARSE_EXPO, NO_BRIGHTNESS|NO_FREQ, 0), + SENS(initTas5130, NULL, tas5130_sensor_init, NULL, NULL, 0, NO_EXPO|NO_FREQ, + 0), + }; +@@ -587,42 +682,28 @@ static void setbrightness(struct gspca_dev *gspca_dev) + goto err; + break; + } +- case SENSOR_PAS106: { +- __u8 i2c1[] = +- {0xa1, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x14}; +- +- i2c1[3] = sd->brightness >> 3; +- i2c1[2] = 0x0e; +- if (i2c_w(gspca_dev, i2c1) < 0) +- goto err; +- i2c1[3] = 0x01; +- i2c1[2] = 0x13; +- if (i2c_w(gspca_dev, i2c1) < 0) +- goto err; +- break; +- } ++ case SENSOR_PAS106: + case SENSOR_PAS202: { +- /* __u8 i2cpexpo1[] = +- {0xb0, 0x40, 0x04, 0x07, 0x2a, 0x00, 0x63, 0x16}; */ +- __u8 i2cpexpo[] = +- {0xb0, 0x40, 0x0e, 0x01, 0xab, 0x00, 0x63, 0x16}; +- __u8 i2cp202[] = +- {0xa0, 0x40, 0x10, 0x0e, 0x31, 0x00, 0x63, 0x15}; +- static __u8 i2cpdoit[] = +- {0xa0, 0x40, 0x11, 0x01, 0x31, 0x00, 0x63, 0x16}; +- +- /* change reg 0x10 */ +- i2cpexpo[4] = 0xff - sd->brightness; +-/* if(i2c_w(gspca_dev,i2cpexpo1) < 0) +- goto err; */ +-/* if(i2c_w(gspca_dev,i2cpdoit) < 0) +- goto err; */ +- if (i2c_w(gspca_dev, i2cpexpo) < 0) +- goto err; +- if (i2c_w(gspca_dev, i2cpdoit) < 0) +- goto err; +- i2cp202[3] = sd->brightness >> 3; +- if (i2c_w(gspca_dev, i2cp202) < 0) ++ __u8 i2cpbright[] = ++ {0xb0, 0x40, 0x0b, 0x00, 0x00, 0x00, 0x00, 0x16}; ++ __u8 i2cpdoit[] = ++ {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; ++ ++ /* PAS106 uses reg 7 and 8 instead of b and c */ ++ if (sd->sensor == SENSOR_PAS106) { ++ i2cpbright[2] = 7; ++ i2cpdoit[2] = 0x13; ++ } ++ ++ if (sd->brightness < 127) { ++ /* change reg 0x0b, signreg */ ++ i2cpbright[3] = 0x01; ++ /* set reg 0x0c, offset */ ++ i2cpbright[4] = 127 - sd->brightness; ++ } else ++ i2cpbright[4] = sd->brightness - 127; ++ ++ if (i2c_w(gspca_dev, i2cpbright) < 0) + goto err; + if (i2c_w(gspca_dev, i2cpdoit) < 0) + goto err; +@@ -652,7 +733,8 @@ static void setsensorgain(struct gspca_dev *gspca_dev) + + switch (sd->sensor) { + +- case SENSOR_TAS5110: { ++ case SENSOR_TAS5110C: ++ case SENSOR_TAS5110D: { + __u8 i2c[] = + {0x30, 0x11, 0x02, 0x20, 0x70, 0x00, 0x00, 0x10}; + +@@ -674,6 +756,37 @@ static void setsensorgain(struct gspca_dev *gspca_dev) + goto err; + break; + } ++ case SENSOR_PAS106: ++ case SENSOR_PAS202: { ++ __u8 i2cpgain[] = ++ {0xa0, 0x40, 0x10, 0x00, 0x00, 0x00, 0x00, 0x15}; ++ __u8 i2cpcolorgain[] = ++ {0xc0, 0x40, 0x07, 0x00, 0x00, 0x00, 0x00, 0x15}; ++ __u8 i2cpdoit[] = ++ {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; ++ ++ /* PAS106 uses different regs (and has split green gains) */ ++ if (sd->sensor == SENSOR_PAS106) { ++ i2cpgain[2] = 0x0e; ++ i2cpcolorgain[0] = 0xd0; ++ i2cpcolorgain[2] = 0x09; ++ i2cpdoit[2] = 0x13; ++ } ++ ++ i2cpgain[3] = sd->gain >> 3; ++ i2cpcolorgain[3] = sd->gain >> 4; ++ i2cpcolorgain[4] = sd->gain >> 4; ++ i2cpcolorgain[5] = sd->gain >> 4; ++ i2cpcolorgain[6] = sd->gain >> 4; ++ ++ if (i2c_w(gspca_dev, i2cpgain) < 0) ++ goto err; ++ if (i2c_w(gspca_dev, i2cpcolorgain) < 0) ++ goto err; ++ if (i2c_w(gspca_dev, i2cpdoit) < 0) ++ goto err; ++ break; ++ } + } + return; + err: +@@ -684,19 +797,21 @@ static void setgain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + __u8 gain; +- __u8 rgb_value; ++ __u8 buf[2] = { 0, 0 }; ++ ++ if (sensor_data[sd->sensor].flags & F_GAIN) { ++ /* Use the sensor gain to do the actual gain */ ++ setsensorgain(gspca_dev); ++ return; ++ } + + gain = sd->gain >> 4; + + /* red and blue gain */ +- rgb_value = gain << 4 | gain; +- reg_w(gspca_dev, 0x10, &rgb_value, 1); ++ buf[0] = gain << 4 | gain; + /* green gain */ +- rgb_value = gain; +- reg_w(gspca_dev, 0x11, &rgb_value, 1); +- +- if (sensor_data[sd->sensor].flags & F_GAIN) +- setsensorgain(gspca_dev); ++ buf[1] = gain; ++ reg_w(gspca_dev, 0x10, buf, 2); + } + + static void setexposure(struct gspca_dev *gspca_dev) +@@ -704,17 +819,12 @@ static void setexposure(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + + switch (sd->sensor) { +- case SENSOR_TAS5110: { +- __u8 reg; +- ++ case SENSOR_TAS5110C: ++ case SENSOR_TAS5110D: { + /* register 19's high nibble contains the sn9c10x clock divider + The high nibble configures the no fps according to the + formula: 60 / high_nibble. With a maximum of 30 fps */ +- reg = 120 * sd->exposure / 1000; +- if (reg < 2) +- reg = 2; +- else if (reg > 15) +- reg = 15; ++ __u8 reg = sd->exposure; + reg = (reg << 4) | 0x0b; + reg_w(gspca_dev, 0x19, ®, 1); + break; +@@ -750,20 +860,21 @@ static void setexposure(struct gspca_dev *gspca_dev) + } else + reg10_max = 0x41; + +- reg11 = (60 * sd->exposure + 999) / 1000; ++ reg11 = (15 * sd->exposure + 999) / 1000; + if (reg11 < 1) + reg11 = 1; + else if (reg11 > 16) + reg11 = 16; + +- /* In 640x480, if the reg11 has less than 3, the image is +- unstable (not enough bandwidth). */ +- if (gspca_dev->width == 640 && reg11 < 3) +- reg11 = 3; ++ /* In 640x480, if the reg11 has less than 4, the image is ++ unstable (the bridge goes into a higher compression mode ++ which we have not reverse engineered yet). */ ++ if (gspca_dev->width == 640 && reg11 < 4) ++ reg11 = 4; + + /* frame exposure time in ms = 1000 * reg11 / 30 -> +- reg10 = sd->exposure * 2 * reg10_max / (1000 * reg11 / 30) */ +- reg10 = (sd->exposure * 60 * reg10_max) / (1000 * reg11); ++ reg10 = (sd->exposure / 2) * reg10_max / (1000 * reg11 / 30) */ ++ reg10 = (sd->exposure * 15 * reg10_max) / (1000 * reg11); + + /* Don't allow this to get below 10 when using autogain, the + steps become very large (relatively) when below 10 causing +@@ -786,10 +897,85 @@ static void setexposure(struct gspca_dev *gspca_dev) + if (i2c_w(gspca_dev, i2c) == 0) + sd->reg11 = reg11; + else +- PDEBUG(D_ERR, "i2c error exposure"); ++ goto err; ++ break; ++ } ++ case SENSOR_PAS202: { ++ __u8 i2cpframerate[] = ++ {0xb0, 0x40, 0x04, 0x00, 0x00, 0x00, 0x00, 0x16}; ++ __u8 i2cpexpo[] = ++ {0xa0, 0x40, 0x0f, 0x00, 0x00, 0x00, 0x00, 0x16}; ++ const __u8 i2cpdoit[] = ++ {0xa0, 0x40, 0x11, 0x01, 0x00, 0x00, 0x00, 0x16}; ++ int framerate_ctrl; ++ ++ /* The exposure knee for the autogain algorithm is 200 ++ (100 ms / 10 fps on other sensors), for values below this ++ use the control for setting the partial frame expose time, ++ above that use variable framerate. This way we run at max ++ framerate (640x480@7.5 fps, 320x240@10fps) until the knee ++ is reached. Using the variable framerate control above 200 ++ is better then playing around with both clockdiv + partial ++ frame exposure times (like we are doing with the ov chips), ++ as that sometimes leads to jumps in the exposure control, ++ which are bad for auto exposure. */ ++ if (sd->exposure < 200) { ++ i2cpexpo[3] = 255 - (sd->exposure * 255) / 200; ++ framerate_ctrl = 500; ++ } else { ++ /* The PAS202's exposure control goes from 0 - 4095, ++ but anything below 500 causes vsync issues, so scale ++ our 200-1023 to 500-4095 */ ++ framerate_ctrl = (sd->exposure - 200) * 1000 / 229 + ++ 500; ++ } ++ ++ i2cpframerate[3] = framerate_ctrl >> 6; ++ i2cpframerate[4] = framerate_ctrl & 0x3f; ++ if (i2c_w(gspca_dev, i2cpframerate) < 0) ++ goto err; ++ if (i2c_w(gspca_dev, i2cpexpo) < 0) ++ goto err; ++ if (i2c_w(gspca_dev, i2cpdoit) < 0) ++ goto err; ++ break; ++ } ++ case SENSOR_PAS106: { ++ __u8 i2cpframerate[] = ++ {0xb1, 0x40, 0x03, 0x00, 0x00, 0x00, 0x00, 0x14}; ++ __u8 i2cpexpo[] = ++ {0xa1, 0x40, 0x05, 0x00, 0x00, 0x00, 0x00, 0x14}; ++ const __u8 i2cpdoit[] = ++ {0xa1, 0x40, 0x13, 0x01, 0x00, 0x00, 0x00, 0x14}; ++ int framerate_ctrl; ++ ++ /* For values below 150 use partial frame exposure, above ++ that use framerate ctrl */ ++ if (sd->exposure < 150) { ++ i2cpexpo[3] = 150 - sd->exposure; ++ framerate_ctrl = 300; ++ } else { ++ /* The PAS106's exposure control goes from 0 - 4095, ++ but anything below 300 causes vsync issues, so scale ++ our 150-1023 to 300-4095 */ ++ framerate_ctrl = (sd->exposure - 150) * 1000 / 230 + ++ 300; ++ } ++ ++ i2cpframerate[3] = framerate_ctrl >> 4; ++ i2cpframerate[4] = framerate_ctrl & 0x0f; ++ if (i2c_w(gspca_dev, i2cpframerate) < 0) ++ goto err; ++ if (i2c_w(gspca_dev, i2cpexpo) < 0) ++ goto err; ++ if (i2c_w(gspca_dev, i2cpdoit) < 0) ++ goto err; + break; + } + } ++ return; ++err: ++ PDEBUG(D_ERR, "i2c error exposure"); + } + + static void setfreq(struct gspca_dev *gspca_dev) +@@ -823,30 +1009,43 @@ static void setfreq(struct gspca_dev *gspca_dev) + } + } + ++#include "coarse_expo_autogain.h" ++ + static void do_autogain(struct gspca_dev *gspca_dev) + { +- int deadzone, desired_avg_lum; ++ int deadzone, desired_avg_lum, result; + struct sd *sd = (struct sd *) gspca_dev; + int avg_lum = atomic_read(&sd->avg_lum); + +- if (avg_lum == -1) ++ if (avg_lum == -1 || !sd->autogain) + return; + ++ if (sd->autogain_ignore_frames > 0) { ++ sd->autogain_ignore_frames--; ++ return; ++ } ++ + /* SIF / VGA sensors have a different autoexposure area and thus + different avg_lum values for the same picture brightness */ + if (sensor_data[sd->sensor].flags & F_SIF) { +- deadzone = 1000; +- desired_avg_lum = 7000; ++ deadzone = 500; ++ /* SIF sensors tend to overexpose, so keep this small */ ++ desired_avg_lum = 5000; + } else { +- deadzone = 3000; +- desired_avg_lum = 23000; ++ deadzone = 1500; ++ desired_avg_lum = 18000; + } + +- if (sd->autogain_ignore_frames > 0) +- sd->autogain_ignore_frames--; +- else if (gspca_auto_gain_n_exposure(gspca_dev, avg_lum, +- sd->brightness * desired_avg_lum / 127, +- deadzone, GAIN_KNEE, EXPOSURE_KNEE)) { ++ if (sensor_data[sd->sensor].flags & F_COARSE_EXPO) ++ result = gspca_coarse_grained_expo_autogain(gspca_dev, avg_lum, ++ sd->brightness * desired_avg_lum / 127, ++ deadzone); ++ else ++ result = gspca_auto_gain_n_exposure(gspca_dev, avg_lum, ++ sd->brightness * desired_avg_lum / 127, ++ deadzone, GAIN_KNEE, EXPOSURE_KNEE); ++ ++ if (result) { + PDEBUG(D_FRAM, "autogain: gain changed: gain: %d expo: %d", + (int)sd->gain, (int)sd->exposure); + sd->autogain_ignore_frames = AUTOGAIN_IGNORE_FRAMES; +@@ -881,7 +1080,13 @@ static int sd_config(struct gspca_dev *gspca_dev, + + sd->brightness = BRIGHTNESS_DEF; + sd->gain = GAIN_DEF; +- sd->exposure = EXPOSURE_DEF; ++ if (sensor_data[sd->sensor].flags & F_COARSE_EXPO) { ++ sd->exposure = COARSE_EXPOSURE_DEF; ++ gspca_dev->ctrl_dis |= (1 << EXPOSURE_IDX); ++ } else { ++ sd->exposure = EXPOSURE_DEF; ++ gspca_dev->ctrl_dis |= (1 << COARSE_EXPOSURE_IDX); ++ } + if (gspca_dev->ctrl_dis & (1 << AUTOGAIN_IDX)) + sd->autogain = 0; /* Disable do_autogain callback */ + else +@@ -917,9 +1122,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg12_19[6] = sn9c10x[0x18 - 1] | (mode << 4); + /* Special cases where reg 17 and or 19 value depends on mode */ + switch (sd->sensor) { +- case SENSOR_PAS202: +- reg12_19[5] = mode ? 0x24 : 0x20; +- break; + case SENSOR_TAS5130CXX: + /* probably not mode specific at all most likely the upper + nibble of 0x19 is exposure (clock divider) just as with +@@ -955,6 +1157,16 @@ static int sd_start(struct gspca_dev *gspca_dev) + sensor_data[sd->sensor].sensor_bridge_init_size[ + sd->bridge]); + ++ /* Mode specific sensor setup */ ++ switch (sd->sensor) { ++ case SENSOR_PAS202: { ++ const __u8 i2cpclockdiv[] = ++ {0xa0, 0x40, 0x02, 0x03, 0x00, 0x00, 0x00, 0x10}; ++ /* clockdiv from 4 to 3 (7.5 -> 10 fps) when in low res mode */ ++ if (mode) ++ i2c_w(gspca_dev, i2cpclockdiv); ++ } ++ } + /* H_size V_size 0x28, 0x1e -> 640x480. 0x16, 0x12 -> 352x288 */ + reg_w(gspca_dev, 0x15, ®12_19[3], 2); + /* compression register */ +@@ -985,6 +1197,8 @@ static int sd_start(struct gspca_dev *gspca_dev) + + sd->frames_to_drop = 0; + sd->autogain_ignore_frames = 0; ++ sd->exp_too_high_cnt = 0; ++ sd->exp_too_low_cnt = 0; + atomic_set(&sd->avg_lum, -1); + return 0; + } +@@ -1143,11 +1357,14 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val) + struct sd *sd = (struct sd *) gspca_dev; + + sd->autogain = val; ++ sd->exp_too_high_cnt = 0; ++ sd->exp_too_low_cnt = 0; ++ + /* when switching to autogain set defaults to make sure + we are on a valid point of the autogain gain / + exposure knee graph, and give this change time to + take effect before doing autogain. */ +- if (sd->autogain) { ++ if (sd->autogain && !(sensor_data[sd->sensor].flags & F_COARSE_EXPO)) { + sd->exposure = EXPOSURE_DEF; + sd->gain = GAIN_DEF; + if (gspca_dev->streaming) { +@@ -1207,6 +1424,25 @@ static int sd_querymenu(struct gspca_dev *gspca_dev, + return -EINVAL; + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrupt packet length */ ++{ ++ int ret = -EINVAL; ++ ++ if (len == 1 && data[0] == 1) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ ++ return ret; ++} ++#endif ++ + /* sub-driver description */ + static const struct sd_desc sd_desc = { + .name = MODULE_NAME, +@@ -1219,6 +1455,9 @@ static const struct sd_desc sd_desc = { + .pkt_scan = sd_pkt_scan, + .querymenu = sd_querymenu, + .dq_callback = do_autogain, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + /* -- module initialisation -- */ +@@ -1227,21 +1466,21 @@ static const struct sd_desc sd_desc = { + + + static const struct usb_device_id device_table[] __devinitconst = { +- {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110, 102)}, /* TAS5110C1B */ +- {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110, 101)}, /* TAS5110C1B */ ++ {USB_DEVICE(0x0c45, 0x6001), SB(TAS5110C, 102)}, /* TAS5110C1B */ ++ {USB_DEVICE(0x0c45, 0x6005), SB(TAS5110C, 101)}, /* TAS5110C1B */ + #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE +- {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110, 101)}, /* TAS5110D */ ++ {USB_DEVICE(0x0c45, 0x6007), SB(TAS5110D, 101)}, /* TAS5110D */ ++#endif + {USB_DEVICE(0x0c45, 0x6009), SB(PAS106, 101)}, + {USB_DEVICE(0x0c45, 0x600d), SB(PAS106, 101)}, +-#endif + {USB_DEVICE(0x0c45, 0x6011), SB(OV6650, 101)}, + #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE + {USB_DEVICE(0x0c45, 0x6019), SB(OV7630, 101)}, + {USB_DEVICE(0x0c45, 0x6024), SB(TAS5130CXX, 102)}, + {USB_DEVICE(0x0c45, 0x6025), SB(TAS5130CXX, 102)}, ++#endif + {USB_DEVICE(0x0c45, 0x6028), SB(PAS202, 102)}, + {USB_DEVICE(0x0c45, 0x6029), SB(PAS106, 102)}, +-#endif + {USB_DEVICE(0x0c45, 0x602c), SB(OV7630, 102)}, + {USB_DEVICE(0x0c45, 0x602d), SB(HV7131R, 102)}, + #if !defined CONFIG_USB_SN9C102 && !defined CONFIG_USB_SN9C102_MODULE +diff --git a/drivers/media/video/gspca/sonixj.c b/drivers/media/video/gspca/sonixj.c +index 0bd36a0..c5a2423 100644 +--- a/drivers/media/video/gspca/sonixj.c ++++ b/drivers/media/video/gspca/sonixj.c +@@ -21,6 +21,7 @@ + + #define MODULE_NAME "sonixj" + ++#include + #include "gspca.h" + #include "jpeg.h" + +@@ -45,6 +46,7 @@ struct sd { + u8 red; + u8 gamma; + u8 vflip; /* ov7630/ov7648 only */ ++ u8 sharpness; + u8 infrared; /* mt9v111 only */ + u8 freq; /* ov76xx only */ + u8 quality; /* image quality */ +@@ -64,16 +66,17 @@ struct sd { + #define BRIDGE_SN9C110 2 + #define BRIDGE_SN9C120 3 + u8 sensor; /* Type of image sensor chip */ +-#define SENSOR_HV7131R 0 +-#define SENSOR_MI0360 1 +-#define SENSOR_MO4000 2 +-#define SENSOR_MT9V111 3 +-#define SENSOR_OM6802 4 +-#define SENSOR_OV7630 5 +-#define SENSOR_OV7648 6 +-#define SENSOR_OV7660 7 +-#define SENSOR_PO1030 8 +-#define SENSOR_SP80708 9 ++#define SENSOR_ADCM1700 0 ++#define SENSOR_HV7131R 1 ++#define SENSOR_MI0360 2 ++#define SENSOR_MO4000 3 ++#define SENSOR_MT9V111 4 ++#define SENSOR_OM6802 5 ++#define SENSOR_OV7630 6 ++#define SENSOR_OV7648 7 ++#define SENSOR_OV7660 8 ++#define SENSOR_PO1030 9 ++#define SENSOR_SP80708 10 + u8 i2c_addr; + + u8 *jpeg_hdr; +@@ -96,12 +99,14 @@ static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getvflip(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setinfrared(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getinfrared(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + #define BRIGHTNESS_IDX 0 + { + { +@@ -225,8 +230,23 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setvflip, + .get = sd_getvflip, + }, ++#define SHARPNESS_IDX 8 ++ { ++ { ++ .id = V4L2_CID_SHARPNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Sharpness", ++ .minimum = 0, ++ .maximum = 255, ++ .step = 1, ++#define SHARPNESS_DEF 90 ++ .default_value = SHARPNESS_DEF, ++ }, ++ .set = sd_setsharpness, ++ .get = sd_getsharpness, ++ }, + /* mt9v111 only */ +-#define INFRARED_IDX 8 ++#define INFRARED_IDX 9 + { + { + .id = V4L2_CID_INFRARED, +@@ -242,7 +262,7 @@ static struct ctrl sd_ctrls[] = { + .get = sd_getinfrared, + }, + /* ov7630/ov7648/ov7660 only */ +-#define FREQ_IDX 9 ++#define FREQ_IDX 10 + { + { + .id = V4L2_CID_POWER_LINE_FREQUENCY, +@@ -261,28 +281,37 @@ static struct ctrl sd_ctrls[] = { + + /* table of the disabled controls */ + static __u32 ctrl_dis[] = { ++ (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX) | ++ (1 << AUTOGAIN_IDX), /* SENSOR_ADCM1700 0 */ + (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_HV7131R 0 */ ++ /* SENSOR_HV7131R 1 */ + (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_MI0360 1 */ ++ /* SENSOR_MI0360 2 */ + (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_MO4000 2 */ ++ /* SENSOR_MO4000 3 */ + (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_MT9V111 3 */ ++ /* SENSOR_MT9V111 4 */ + (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | (1 << FREQ_IDX), +- /* SENSOR_OM6802 4 */ ++ /* SENSOR_OM6802 5 */ + (1 << INFRARED_IDX), +- /* SENSOR_OV7630 5 */ ++ /* SENSOR_OV7630 6 */ + (1 << INFRARED_IDX), +- /* SENSOR_OV7648 6 */ ++ /* SENSOR_OV7648 7 */ + (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX), +- /* SENSOR_OV7660 7 */ ++ /* SENSOR_OV7660 8 */ + (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | +- (1 << FREQ_IDX), /* SENSOR_PO1030 8 */ ++ (1 << FREQ_IDX), /* SENSOR_PO1030 9 */ + (1 << AUTOGAIN_IDX) | (1 << INFRARED_IDX) | (1 << VFLIP_IDX) | +- (1 << FREQ_IDX), /* SENSOR_SP80708 9 */ ++ (1 << FREQ_IDX), /* SENSOR_SP80708 10 */ + }; + ++static const struct v4l2_pix_format cif_mode[] = { ++ {352, 288, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 352, ++ .sizeimage = 352 * 288 * 4 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG, ++ .priv = 0}, ++}; + static const struct v4l2_pix_format vga_mode[] = { + {160, 120, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, + .bytesperline = 160, +@@ -302,6 +335,17 @@ static const struct v4l2_pix_format vga_mode[] = { + .priv = 0}, + }; + ++static const u8 sn_adcm1700[0x1c] = { ++/* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ ++ 0x00, 0x43, 0x60, 0x00, 0x1a, 0x00, 0x00, 0x00, ++/* reg8 reg9 rega regb regc regd rege regf */ ++ 0x80, 0x51, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++/* reg10 reg11 reg12 reg13 reg14 reg15 reg16 reg17 */ ++ 0x03, 0x00, 0x05, 0x01, 0x05, 0x16, 0x12, 0x42, ++/* reg18 reg19 reg1a reg1b */ ++ 0x06, 0x00, 0x00, 0x00 ++}; ++ + /*Data from sn9c102p+hv7131r */ + static const u8 sn_hv7131[0x1c] = { + /* reg0 reg1 reg2 reg3 reg4 reg5 reg6 reg7 */ +@@ -415,6 +459,7 @@ static const u8 sn_sp80708[0x1c] = { + + /* sequence specific to the sensors - !! index = SENSOR_xxx */ + static const u8 *sn_tb[] = { ++ sn_adcm1700, + sn_hv7131, + sn_mi0360, + sn_mo4000, +@@ -432,6 +477,11 @@ static const u8 gamma_def[17] = { + 0x00, 0x2d, 0x46, 0x5a, 0x6c, 0x7c, 0x8b, 0x99, + 0xa6, 0xb2, 0xbf, 0xca, 0xd5, 0xe0, 0xeb, 0xf5, 0xff + }; ++/* gamma for sensor ADCM1700 */ ++static const u8 gamma_spec_0[17] = { ++ 0x0f, 0x39, 0x5a, 0x74, 0x86, 0x95, 0xa6, 0xb4, ++ 0xbd, 0xc4, 0xcc, 0xd4, 0xd5, 0xde, 0xe4, 0xed, 0xf5 ++}; + /* gamma for sensors HV7131R and MT9V111 */ + static const u8 gamma_spec_1[17] = { + 0x08, 0x3a, 0x52, 0x65, 0x75, 0x83, 0x91, 0x9d, +@@ -450,6 +500,42 @@ static const u8 reg84[] = { + 0x3e, 0x00, 0xcd, 0x0f, 0xf7, 0x0f, /* VR VG VB */ + 0x00, 0x00, 0x00 /* YUV offsets */ + }; ++static const u8 adcm1700_sensor_init[][8] = { ++ {0xa0, 0x51, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x04, 0x08, 0x00, 0x00, 0x00, 0x10}, /* reset */ ++ {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, ++ {0xb0, 0x51, 0x04, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, ++ {0xb0, 0x51, 0x0c, 0xe0, 0x2e, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x10, 0x02, 0x02, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x14, 0x0e, 0x0e, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x1c, 0x00, 0x80, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x20, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, ++ {0xb0, 0x51, 0x04, 0x04, 0x00, 0x00, 0x00, 0x10}, ++ {0xdd, 0xff, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00}, ++ {0xb0, 0x51, 0x04, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x14, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x32, 0x00, 0x00, 0x00, 0x00, 0x10}, ++ {} ++}; ++static const u8 adcm1700_sensor_param1[][8] = { ++ {0xb0, 0x51, 0x26, 0xf9, 0x01, 0x00, 0x00, 0x10}, /* exposure? */ ++ {0xd0, 0x51, 0x1e, 0x8e, 0x8e, 0x8e, 0x8e, 0x10}, ++ ++ {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x32, 0x00, 0x72, 0x00, 0x00, 0x10}, ++ {0xd0, 0x51, 0x1e, 0xbe, 0xd7, 0xe8, 0xbe, 0x10}, /* exposure? */ ++ ++ {0xa0, 0x51, 0xfe, 0x01, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x00, 0x02, 0x00, 0x00, 0x00, 0x10}, ++ {0xa0, 0x51, 0xfe, 0x10, 0x00, 0x00, 0x00, 0x10}, ++ {0xb0, 0x51, 0x32, 0x00, 0xa2, 0x00, 0x00, 0x10}, ++ {} ++}; + static const u8 hv7131r_sensor_init[][8] = { + {0xc1, 0x11, 0x01, 0x08, 0x01, 0x00, 0x00, 0x10}, + {0xb1, 0x11, 0x34, 0x17, 0x7f, 0x00, 0x00, 0x10}, +@@ -986,17 +1116,18 @@ static const u8 sp80708_sensor_param1[][8] = { + {} + }; + +-static const u8 (*sensor_init[10])[8] = { +- hv7131r_sensor_init, /* HV7131R 0 */ +- mi0360_sensor_init, /* MI0360 1 */ +- mo4000_sensor_init, /* MO4000 2 */ +- mt9v111_sensor_init, /* MT9V111 3 */ +- om6802_sensor_init, /* OM6802 4 */ +- ov7630_sensor_init, /* OV7630 5 */ +- ov7648_sensor_init, /* OV7648 6 */ +- ov7660_sensor_init, /* OV7660 7 */ +- po1030_sensor_init, /* PO1030 8 */ +- sp80708_sensor_init, /* SP80708 9 */ ++static const u8 (*sensor_init[11])[8] = { ++ adcm1700_sensor_init, /* ADCM1700 0 */ ++ hv7131r_sensor_init, /* HV7131R 1 */ ++ mi0360_sensor_init, /* MI0360 2 */ ++ mo4000_sensor_init, /* MO4000 3 */ ++ mt9v111_sensor_init, /* MT9V111 4 */ ++ om6802_sensor_init, /* OM6802 5 */ ++ ov7630_sensor_init, /* OV7630 6 */ ++ ov7648_sensor_init, /* OV7648 7 */ ++ ov7660_sensor_init, /* OV7660 8 */ ++ po1030_sensor_init, /* PO1030 9 */ ++ sp80708_sensor_init, /* SP80708 10 */ + }; + + /* read bytes to gspca_dev->usb_buf */ +@@ -1064,6 +1195,7 @@ static void i2c_w1(struct gspca_dev *gspca_dev, u8 reg, u8 val) + + PDEBUG(D_USBO, "i2c_w2 [%02x] = %02x", reg, val); + switch (sd->sensor) { ++ case SENSOR_ADCM1700: + case SENSOR_OM6802: /* i2c command = a0 (100 kHz) */ + gspca_dev->usb_buf[0] = 0x80 | (2 << 4); + break; +@@ -1110,6 +1242,7 @@ static void i2c_r(struct gspca_dev *gspca_dev, u8 reg, int len) + u8 mode[8]; + + switch (sd->sensor) { ++ case SENSOR_ADCM1700: + case SENSOR_OM6802: /* i2c command = 90 (100 kHz) */ + mode[0] = 0x80 | 0x10; + break; +@@ -1255,13 +1388,22 @@ static void bridge_init(struct gspca_dev *gspca_dev, + struct sd *sd = (struct sd *) gspca_dev; + const u8 *reg9a; + static const u8 reg9a_def[] = ++#if 1 + {0x00, 0x40, 0x20, 0x00, 0x00, 0x00}; ++#else ++ {0x00, 0x40, 0x20, 0x10, 0x00, 0x04}; ++#endif + static const u8 reg9a_spec[] = + {0x00, 0x40, 0x38, 0x30, 0x00, 0x20}; + static const u8 regd4[] = {0x60, 0x00, 0x00}; + +- reg_w1(gspca_dev, 0xf1, 0x00); ++ /* sensor clock already enabled in sd_init */ ++ /* reg_w1(gspca_dev, 0xf1, 0x00); */ ++#if 1 + reg_w1(gspca_dev, 0x01, sn9c1xx[1]); ++#else ++ reg_w1(gspca_dev, 0x01, 0x00); /*jfm: in some win traces*/ ++#endif + + /* configure gpio */ + reg_w(gspca_dev, 0x01, &sn9c1xx[1], 2); +@@ -1284,6 +1426,12 @@ static void bridge_init(struct gspca_dev *gspca_dev, + reg_w(gspca_dev, 0x03, &sn9c1xx[3], 0x0f); + + switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ reg_w1(gspca_dev, 0x01, 0x43); ++ reg_w1(gspca_dev, 0x17, 0x62); ++ reg_w1(gspca_dev, 0x01, 0x42); ++ reg_w1(gspca_dev, 0x01, 0x42); ++ break; + case SENSOR_MT9V111: + reg_w1(gspca_dev, 0x01, 0x61); + reg_w1(gspca_dev, 0x17, 0x61); +@@ -1357,14 +1513,19 @@ static int sd_config(struct gspca_dev *gspca_dev, + struct sd *sd = (struct sd *) gspca_dev; + struct cam *cam; + +- cam = &gspca_dev->cam; +- cam->cam_mode = vga_mode; +- cam->nmodes = ARRAY_SIZE(vga_mode); +- cam->npkt = 24; /* 24 packets per ISOC message */ +- + sd->bridge = id->driver_info >> 16; + sd->sensor = id->driver_info; + ++ cam = &gspca_dev->cam; ++ if (sd->sensor == SENSOR_ADCM1700) { ++ cam->cam_mode = cif_mode; ++ cam->nmodes = ARRAY_SIZE(cif_mode); ++ } else { ++ cam->cam_mode = vga_mode; ++ cam->nmodes = ARRAY_SIZE(vga_mode); ++ } ++ cam->npkt = 24; /* 24 packets per ISOC message */ ++ + sd->brightness = BRIGHTNESS_DEF; + sd->contrast = CONTRAST_DEF; + sd->colors = COLOR_DEF; +@@ -1374,6 +1535,14 @@ static int sd_config(struct gspca_dev *gspca_dev, + sd->autogain = AUTOGAIN_DEF; + sd->ag_cnt = -1; + sd->vflip = VFLIP_DEF; ++ switch (sd->sensor) { ++ case SENSOR_OM6802: ++ sd->sharpness = 0x10; ++ break; ++ default: ++ sd->sharpness = SHARPNESS_DEF; ++ break; ++ } + sd->infrared = INFRARED_DEF; + sd->freq = FREQ_DEF; + sd->quality = QUALITY_DEF; +@@ -1433,7 +1602,9 @@ static int sd_init(struct gspca_dev *gspca_dev) + break; + } + +- reg_w1(gspca_dev, 0xf1, 0x01); ++ /* Note we do not disable the sensor clock here (power saving mode), ++ as that also disables the button on the cam. */ ++ reg_w1(gspca_dev, 0xf1, 0x00); + + /* set the i2c address */ + sn9c1xx = sn_tb[sd->sensor]; +@@ -1543,6 +1724,10 @@ static void setbrightness(struct gspca_dev *gspca_dev) + + k2 = ((int) sd->brightness - 0x8000) >> 10; + switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ if (k2 > 0x1f) ++ k2 = 0; /* only positive Y offset */ ++ break; + case SENSOR_HV7131R: + expo = sd->brightness << 4; + if (expo > 0x002dc6c0) +@@ -1625,6 +1810,9 @@ static void setgamma(struct gspca_dev *gspca_dev) + }; + + switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ gamma_base = gamma_spec_0; ++ break; + case SENSOR_HV7131R: + case SENSOR_MT9V111: + gamma_base = gamma_spec_1; +@@ -1689,14 +1877,25 @@ static void setvflip(struct sd *sd) + i2c_w1(&sd->gspca_dev, 0x75, comn); + } + ++static void setsharpness(struct sd *sd) ++{ ++ reg_w1(&sd->gspca_dev, 0x99, sd->sharpness); ++} ++ + static void setinfrared(struct sd *sd) + { + if (sd->gspca_dev.ctrl_dis & (1 << INFRARED_IDX)) + return; + /*fixme: different sequence for StarCam Clip and StarCam 370i */ ++#if 1 + /* Clip */ + i2c_w1(&sd->gspca_dev, 0x02, /* gpio */ + sd->infrared ? 0x66 : 0x64); ++#else ++/* 370i */ ++ i2c_w1(&sd->gspca_dev, 0x02, /* gpio */ ++ sd->infrared ? 0x55 : 0x54); ++#endif + } + + static void setfreq(struct gspca_dev *gspca_dev) +@@ -1804,6 +2007,8 @@ static int sd_start(struct gspca_dev *gspca_dev) + int mode; + static const u8 C0[] = { 0x2d, 0x2d, 0x3a, 0x05, 0x04, 0x3f }; + static const u8 CA[] = { 0x28, 0xd8, 0x14, 0xec }; ++ static const u8 CA_adcm1700[] = ++ { 0x14, 0xec, 0x0a, 0xf6 }; + static const u8 CE[] = { 0x32, 0xdd, 0x2d, 0xdd }; /* MI0360 */ + static const u8 CE_ov76xx[] = + { 0x32, 0xdd, 0x32, 0xdd }; +@@ -1824,6 +2029,9 @@ static int sd_start(struct gspca_dev *gspca_dev) + i2c_w_seq(gspca_dev, sensor_init[sd->sensor]); + + switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ reg2 = 0x60; ++ break; + case SENSOR_OM6802: + reg2 = 0x71; + break; +@@ -1842,17 +2050,28 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg_w1(gspca_dev, 0x12, sn9c1xx[0x12]); + reg_w1(gspca_dev, 0x13, sn9c1xx[0x13]); + reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); +- reg_w1(gspca_dev, 0xd2, 0x6a); /* DC29 */ +- reg_w1(gspca_dev, 0xd3, 0x50); ++ if (sd->sensor == SENSOR_ADCM1700) { ++ reg_w1(gspca_dev, 0xd2, 0x3a); /* AE_H_SIZE = 116 */ ++ reg_w1(gspca_dev, 0xd3, 0x30); /* AE_V_SIZE = 96 */ ++ } else { ++ reg_w1(gspca_dev, 0xd2, 0x6a); /* AE_H_SIZE = 212 */ ++ reg_w1(gspca_dev, 0xd3, 0x50); /* AE_V_SIZE = 160 */ ++ } + reg_w1(gspca_dev, 0xc6, 0x00); + reg_w1(gspca_dev, 0xc7, 0x00); +- reg_w1(gspca_dev, 0xc8, 0x50); +- reg_w1(gspca_dev, 0xc9, 0x3c); ++ if (sd->sensor == SENSOR_ADCM1700) { ++ reg_w1(gspca_dev, 0xc8, 0x2c); /* AW_H_STOP = 352 */ ++ reg_w1(gspca_dev, 0xc9, 0x24); /* AW_V_STOP = 288 */ ++ } else { ++ reg_w1(gspca_dev, 0xc8, 0x50); /* AW_H_STOP = 640 */ ++ reg_w1(gspca_dev, 0xc9, 0x3c); /* AW_V_STOP = 480 */ ++ } + reg_w1(gspca_dev, 0x18, sn9c1xx[0x18]); + switch (sd->sensor) { + case SENSOR_MT9V111: + reg17 = 0xe0; + break; ++ case SENSOR_ADCM1700: + case SENSOR_OV7630: + reg17 = 0xe2; + break; +@@ -1863,44 +2082,39 @@ static int sd_start(struct gspca_dev *gspca_dev) + break; + } + reg_w1(gspca_dev, 0x17, reg17); +-/* set reg1 was here */ +- reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */ +- reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */ +- reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */ ++ ++ reg_w1(gspca_dev, 0x05, 0x00); /* red */ ++ reg_w1(gspca_dev, 0x07, 0x00); /* green */ ++ reg_w1(gspca_dev, 0x06, 0x00); /* blue */ + reg_w1(gspca_dev, 0x14, sn9c1xx[0x14]); + + setgamma(gspca_dev); + ++/*fixme: 8 times with all zeroes and 1 or 2 times with normal values */ + for (i = 0; i < 8; i++) + reg_w(gspca_dev, 0x84, reg84, sizeof reg84); + switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ case SENSOR_OV7660: ++ case SENSOR_SP80708: ++ reg_w1(gspca_dev, 0x9a, 0x05); ++ break; + case SENSOR_MT9V111: + reg_w1(gspca_dev, 0x9a, 0x07); +- reg_w1(gspca_dev, 0x99, 0x59); +- break; +- case SENSOR_OM6802: +- reg_w1(gspca_dev, 0x9a, 0x08); +- reg_w1(gspca_dev, 0x99, 0x10); + break; + case SENSOR_OV7648: + reg_w1(gspca_dev, 0x9a, 0x0a); +- reg_w1(gspca_dev, 0x99, 0x60); +- break; +- case SENSOR_OV7660: +- case SENSOR_SP80708: +- reg_w1(gspca_dev, 0x9a, 0x05); +- reg_w1(gspca_dev, 0x99, 0x59); + break; + default: + reg_w1(gspca_dev, 0x9a, 0x08); +- reg_w1(gspca_dev, 0x99, 0x59); + break; + } ++ setsharpness(sd); + + reg_w(gspca_dev, 0x84, reg84, sizeof reg84); +- reg_w1(gspca_dev, 0x05, sn9c1xx[5]); /* red */ +- reg_w1(gspca_dev, 0x07, sn9c1xx[7]); /* green */ +- reg_w1(gspca_dev, 0x06, sn9c1xx[6]); /* blue */ ++ reg_w1(gspca_dev, 0x05, 0x20); /* red */ ++ reg_w1(gspca_dev, 0x07, 0x20); /* green */ ++ reg_w1(gspca_dev, 0x06, 0x20); /* blue */ + + init = NULL; + mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; +@@ -1917,6 +2135,11 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg1 = 0x06; /* 640x480: clk 24Mhz, video trf enable */ + reg17 = 0x61; /* 0x:20: enable sensor clock */ + switch (sd->sensor) { ++ case SENSOR_ADCM1700: ++ init = adcm1700_sensor_param1; ++ reg1 = 0x46; ++ reg17 = 0xe2; ++ break; + case SENSOR_MO4000: + if (mode) { + /* reg1 = 0x46; * 320 clk 48Mhz 60fp/s */ +@@ -1986,8 +2209,12 @@ static int sd_start(struct gspca_dev *gspca_dev) + } + + reg_w(gspca_dev, 0xc0, C0, 6); +- reg_w(gspca_dev, 0xca, CA, 4); ++ if (sd->sensor == SENSOR_ADCM1700) ++ reg_w(gspca_dev, 0xca, CA_adcm1700, 4); ++ else ++ reg_w(gspca_dev, 0xca, CA, 4); + switch (sd->sensor) { ++ case SENSOR_ADCM1700: + case SENSOR_OV7630: + case SENSOR_OV7648: + case SENSOR_OV7660: +@@ -2056,7 +2300,8 @@ static void sd_stopN(struct gspca_dev *gspca_dev) + reg_w1(gspca_dev, 0x17, sn9c1xx[0x17]); + reg_w1(gspca_dev, 0x01, sn9c1xx[1]); + reg_w1(gspca_dev, 0x01, data); +- reg_w1(gspca_dev, 0xf1, 0x00); ++ /* Don't disable sensor clock as that disables the button on the cam */ ++ /* reg_w1(gspca_dev, 0xf1, 0x01); */ + } + + static void sd_stop0(struct gspca_dev *gspca_dev) +@@ -2288,6 +2533,24 @@ static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val) + return 0; + } + ++static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->sharpness = val; ++ if (gspca_dev->streaming) ++ setsharpness(sd); ++ return 0; ++} ++ ++static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->sharpness; ++ return 0; ++} ++ + static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -2391,6 +2654,25 @@ static int sd_querymenu(struct gspca_dev *gspca_dev, + return -EINVAL; + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrupt packet length */ ++{ ++ int ret = -EINVAL; ++ ++ if (len == 1 && data[0] == 1) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ ++ return ret; ++} ++#endif ++ + /* sub-driver description */ + static const struct sd_desc sd_desc = { + .name = MODULE_NAME, +@@ -2406,6 +2688,9 @@ static const struct sd_desc sd_desc = { + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, + .querymenu = sd_querymenu, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + /* -- module initialisation -- */ +@@ -2472,6 +2762,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + /* {USB_DEVICE(0x0c45, 0x6142), BS(SN9C120, PO2030N)}, *sn9c120b*/ + {USB_DEVICE(0x0c45, 0x6143), BS(SN9C120, SP80708)}, /*sn9c120b*/ + {USB_DEVICE(0x0c45, 0x6148), BS(SN9C120, OM6802)}, /*sn9c120b*/ ++ {USB_DEVICE(0x0c45, 0x614a), BS(SN9C120, ADCM1700)}, /*sn9c120b*/ + {} + }; + MODULE_DEVICE_TABLE(usb, device_table); +diff --git a/drivers/media/video/gspca/spca500.c b/drivers/media/video/gspca/spca500.c +index fe46868..29e1699 100644 +--- a/drivers/media/video/gspca/spca500.c ++++ b/drivers/media/video/gspca/spca500.c +@@ -68,7 +68,7 @@ static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -153,6 +153,23 @@ static const struct v4l2_pix_format sif_mode[] = { + #define SPCA500_OFFSET_AUGPIO 12 + #define SPCA500_OFFSET_DATA 16 + ++#if 0 ++static const __u16 spca500_read_stats[][3] = { ++ {0x0c, 0x0000, 0x0000}, ++ {0x30, 0x03fd, 0x0001}, ++ /* possible values for following call: 0x01b3, 0x01e6, 0x01f7, 0x0218 */ ++ {0x30, 0x01b3, 0x0002}, ++ /* possible values for following call: 0x0000, 0x0001, 0x0002 */ ++ {0x30, 0x0000, 0x0003}, ++ {0x30, 0x003b, 0x0004}, ++ /* possible values for following call: 0x00aa, 0x00e0 */ ++ {0x30, 0x00e0, 0x0005}, ++ {0x30, 0x0001, 0x0006}, ++ {0x30, 0x0080, 0x0007}, ++ {0x30, 0x0004, 0x0000}, ++ {} ++}; ++#endif + + static const __u16 spca500_visual_defaults[][3] = { + {0x00, 0x0003, 0x816b}, /* SSI not active sync with vsync, +@@ -1047,7 +1064,7 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev, + } + + /* sub-driver description */ +-static struct sd_desc sd_desc = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), +diff --git a/drivers/media/video/gspca/spca501.c b/drivers/media/video/gspca/spca501.c +index 6761a30..543f4db 100644 +--- a/drivers/media/video/gspca/spca501.c ++++ b/drivers/media/video/gspca/spca501.c +@@ -59,7 +59,7 @@ static int sd_getblue_balance(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setred_balance(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getred_balance(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + #define MY_BRIGHTNESS 0 + { + { +@@ -1856,6 +1856,31 @@ static int reg_write(struct usb_device *dev, + return ret; + } + ++#if 0 ++/* returns: negative is error, pos or zero is data */ ++static int reg_read(struct gspca_dev *gspca_dev, ++ __u16 req, /* bRequest */ ++ __u16 index, /* wIndex */ ++ __u16 length) /* wLength (1 or 2 only) */ ++{ ++ int ret; ++ ++ gspca_dev->usb_buf[1] = 0; ++ ret = usb_control_msg(gspca_dev->dev, ++ usb_rcvctrlpipe(gspca_dev->dev, 0), ++ req, ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ 0, /* value */ ++ index, ++ gspca_dev->usb_buf, length, ++ 500); /* timeout */ ++ if (ret < 0) { ++ PDEBUG(D_ERR, "reg_read err %d", ret); ++ return -1; ++ } ++ return (gspca_dev->usb_buf[1] << 8) + gspca_dev->usb_buf[0]; ++} ++#endif + + static int write_vector(struct gspca_dev *gspca_dev, + const __u16 data[][3]) +diff --git a/drivers/media/video/gspca/spca505.c b/drivers/media/video/gspca/spca505.c +index 0f9232f..c576eed 100644 +--- a/drivers/media/video/gspca/spca505.c ++++ b/drivers/media/video/gspca/spca505.c +@@ -42,7 +42,7 @@ struct sd { + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +diff --git a/drivers/media/video/gspca/spca506.c b/drivers/media/video/gspca/spca506.c +index 39257e4..89fec4c 100644 +--- a/drivers/media/video/gspca/spca506.c ++++ b/drivers/media/video/gspca/spca506.c +@@ -51,7 +51,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_sethue(struct gspca_dev *gspca_dev, __s32 val); + static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + #define SD_BRIGHTNESS 0 + { + { +@@ -673,7 +673,7 @@ static int sd_gethue(struct gspca_dev *gspca_dev, __s32 *val) + } + + /* sub-driver description */ +-static struct sd_desc sd_desc = { ++static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, + .nctrls = ARRAY_SIZE(sd_ctrls), +diff --git a/drivers/media/video/gspca/spca508.c b/drivers/media/video/gspca/spca508.c +index 4d8e6cf..b202e62 100644 +--- a/drivers/media/video/gspca/spca508.c ++++ b/drivers/media/video/gspca/spca508.c +@@ -45,7 +45,7 @@ struct sd { + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -86,6 +86,26 @@ static const struct v4l2_pix_format sif_mode[] = { + }; + + /* Frame packet header offsets for the spca508 */ ++#if 0 ++#define SPCA508_OFFSET_ ++#define SPCA508_OFFSET_TYPE 1 ++#define SPCA508_IMAGE_TYPE_MASK 0x1f ++#define SPCA508_SNAPBIT 0x20 ++#define SPCA508_SNAPCTRL 0x40 ++#define SPCA508_OFFSET_COMPRESS 2 ++#define SPCA508_OFFSET_FRAMSEQ 8 ++#define SPCA508_OFFSET_GPIO 9 ++#define SPCA508_OFFSET_GLBINF 10 ++#define SPCA508_OFFSET_WIN1LUM 11 ++#define SPCA508_OFFSET_WIN2LUM 12 ++#define SPCA508_OFFSET_WIN1RG 13 ++#define SPCA508_OFFSET_WIN1BG 14 ++#define SPCA508_OFFSET_WIN2RG 15 ++#define SPCA508_OFFSET_WIN2BG 16 ++#define SPCA508_OFFSET_21 21 ++#define SPCA508_GAMMAEN 0x01 ++#define SPCA508_EDGEMODE 0x02 ++#endif + #define SPCA508_OFFSET_DATA 37 + + /* +@@ -423,7 +443,24 @@ static const u16 spca508_init_data[][2] = + {0x007d, 0x8800}, + /* READ { 0x0001, 0x8803 } -> 0000: 00 */ + ++#if 0 ++ /* experimental. dark version. */ ++ {0xba, 0x8705}, /* total pixel clocks per hsync cycle (L) */ ++ {0x00, 0x8706}, /* total pixel clocks per hsync cycle (H in 2:0) */ ++ {0x5a, 0x8707}, /* total pixel clocks per hsync blank period (L) */ ++#elif 0 ++ /* experimental. factory default. */ ++ {0x8e, 0x8705}, /* total pixel clocks per hsync cycle (L) */ ++ {0x03, 0x8706}, /* total pixel clocks per hsync cycle (H in 2:0) */ ++ {0x5a, 0x8707}, /* total pixel clocks per hsync blank period (L) */ ++#elif 0 ++ /* experimental. light. */ ++ {0xba, 0x8705}, /* total pixel clocks per hsync cycle (L) */ ++ {0x01, 0x8706}, /* total pixel clocks per hsync cycle (H in 2:0) */ ++ {0x10, 0x8707}, /* total pixel clocks per hsync blank period (L) */ ++#endif + ++#if 1 + /* This chunk is seemingly redundant with */ + /* earlier commands (A11 Coef...), but if I disable it, */ + /* the image appears too dark. Maybe there was some kind of */ +@@ -438,6 +475,7 @@ static const u16 spca508_init_data[][2] = + {0xffdc, 0x860f}, + {0x0039, 0x8610}, + {0x0018, 0x8657}, ++#endif + + {0x0000, 0x8508}, /* Disable compression. */ + /* Previous line was: +@@ -480,8 +518,16 @@ static const u16 spca508_init_data[][2] = + /* READ { 0x0001, 0x8803 } -> 0000: 00 */ + {0x0001, 0x8602}, /* optical black level for user settning = 1 */ + ++#if 0 ++ /* NOTE: Code like this case lets this driver (often) work */ ++ /* in 352x288 resolution, apparently by slowing down the */ ++ /* clock. */ ++ ++ {0x002f, 0x8700}, /* Clock speed */ ++#else + /* Original: */ + {0x0023, 0x8700}, /* Clock speed 48Mhz/(3+2)/4= 2.4 Mhz */ ++#endif + {0x000f, 0x8602}, /* optical black level for user settning = 15 */ + + {0x0028, 0x8802}, +diff --git a/drivers/media/video/gspca/spca561.c b/drivers/media/video/gspca/spca561.c +index 58c2f00..85eeb51 100644 +--- a/drivers/media/video/gspca/spca561.c ++++ b/drivers/media/video/gspca/spca561.c +@@ -190,16 +190,36 @@ static const __u16 rev72a_init_data2[][2] = { + {0x0002, 0x8201}, /* Output address for r/w serial EEPROM */ + {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ + {0x0001, 0x8200}, /* OprMode to be executed by hardware */ ++#if 0 ++ {0x0007, 0x8201}, /* Output address for r/w serial EEPROM */ ++ {0x0008, 0x8200}, /* Clear valid bit for serial EEPROM */ ++ {0x0001, 0x8200}, /* OprMode to be executed by hardware */ ++ {0x0010, 0x8660}, /* Compensation memory stuff */ ++ {0x0018, 0x8660}, /* Compensation memory stuff */ ++#endif ++#if 1 + /* from ms-win */ + {0x0000, 0x8611}, /* R offset for white balance */ + {0x00fd, 0x8612}, /* Gr offset for white balance */ + {0x0003, 0x8613}, /* B offset for white balance */ ++#else ++ {0x0004, 0x8611}, /* R offset for white balance */ ++ {0x0004, 0x8612}, /* Gr offset for white balance */ ++ {0x0007, 0x8613}, /* B offset for white balance */ ++#endif + {0x0000, 0x8614}, /* Gb offset for white balance */ ++#if 1 + /* from ms-win */ + {0x0035, 0x8651}, /* R gain for white balance */ + {0x0040, 0x8652}, /* Gr gain for white balance */ + {0x005f, 0x8653}, /* B gain for white balance */ + {0x0040, 0x8654}, /* Gb gain for white balance */ ++#else ++ {0x008c, 0x8651}, /* R gain for white balance */ ++ {0x008c, 0x8652}, /* Gr gain for white balance */ ++ {0x00b5, 0x8653}, /* B gain for white balance */ ++ {0x008c, 0x8654}, /* Gb gain for white balance */ ++#endif + {0x0002, 0x8502}, /* Maximum average bit rate stuff */ + {0x0011, 0x8802}, + +@@ -224,6 +244,17 @@ static const u16 rev72a_init_sensor2[][2] = { + {0x0035, 0x0014}, + {} + }; ++#if 0 ++static const __u16 rev72a_init_data3[][2] = { ++ {0x0087, 0x8700}, /* overwrite by start */ ++ {0x0081, 0x8702}, ++ {0x0000, 0x8500}, ++/* {0x0010, 0x8500}, -- Previous line was this */ ++ {0x0002, 0x865b}, ++ {0x0003, 0x865c}, ++ {} ++}; ++#endif + + /******************** QC Express etch2 stuff ********************/ + static const __u16 Pb100_1map8300[][2] = { +@@ -922,7 +953,7 @@ static int sd_getgain(struct gspca_dev *gspca_dev, __s32 *val) + } + + /* control tables */ +-static struct ctrl sd_ctrls_12a[] = { ++static const struct ctrl sd_ctrls_12a[] = { + { + { + .id = V4L2_CID_HUE, +@@ -964,7 +995,7 @@ static struct ctrl sd_ctrls_12a[] = { + }, + }; + +-static struct ctrl sd_ctrls_72a[] = { ++static const struct ctrl sd_ctrls_72a[] = { + { + { + .id = V4L2_CID_HUE, +diff --git a/drivers/media/video/gspca/sq905c.c b/drivers/media/video/gspca/sq905c.c +index d70b156..e646620 100644 +--- a/drivers/media/video/gspca/sq905c.c ++++ b/drivers/media/video/gspca/sq905c.c +@@ -47,6 +47,7 @@ MODULE_LICENSE("GPL"); + + /* Commands. These go in the "value" slot. */ + #define SQ905C_CLEAR 0xa0 /* clear everything */ ++#define SQ905C_GET_ID 0x14f4 /* Read version number */ + #define SQ905C_CAPTURE_LOW 0xa040 /* Starts capture at 160x120 */ + #define SQ905C_CAPTURE_MED 0x1440 /* Starts capture at 320x240 */ + #define SQ905C_CAPTURE_HI 0x2840 /* Starts capture at 320x240 */ +@@ -101,6 +102,26 @@ static int sq905c_command(struct gspca_dev *gspca_dev, u16 command, u16 index) + return 0; + } + ++static int sq905c_read(struct gspca_dev *gspca_dev, u16 command, u16 index, ++ int size) ++{ ++ int ret; ++ ++ ret = usb_control_msg(gspca_dev->dev, ++ usb_rcvctrlpipe(gspca_dev->dev, 0), ++ USB_REQ_SYNCH_FRAME, /* request */ ++ USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_DEVICE, ++ command, index, gspca_dev->usb_buf, size, ++ SQ905C_CMD_TIMEOUT); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "%s: usb_control_msg failed (%d)", ++ __func__, ret); ++ return ret; ++ } ++ ++ return 0; ++} ++ + /* This function is called as a workqueue function and runs whenever the camera + * is streaming data. Because it is a workqueue function it is allowed to sleep + * so we can use synchronous USB calls. To avoid possible collisions with other +@@ -183,13 +204,34 @@ static int sd_config(struct gspca_dev *gspca_dev, + { + struct cam *cam = &gspca_dev->cam; + struct sd *dev = (struct sd *) gspca_dev; ++ int ret; + + PDEBUG(D_PROBE, + "SQ9050 camera detected" + " (vid/pid 0x%04X:0x%04X)", id->idVendor, id->idProduct); ++ ++ ret = sq905c_command(gspca_dev, SQ905C_GET_ID, 0); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "Get version command failed"); ++ return ret; ++ } ++ ++ ret = sq905c_read(gspca_dev, 0xf5, 0, 20); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "Reading version command failed"); ++ return ret; ++ } ++ /* Note we leave out the usb id and the manufacturing date */ ++ PDEBUG(D_PROBE, ++ "SQ9050 ID string: %02x - %02x %02x %02x %02x %02x %02x", ++ gspca_dev->usb_buf[3], ++ gspca_dev->usb_buf[14], gspca_dev->usb_buf[15], ++ gspca_dev->usb_buf[16], gspca_dev->usb_buf[17], ++ gspca_dev->usb_buf[18], gspca_dev->usb_buf[19]); ++ + cam->cam_mode = sq905c_mode; + cam->nmodes = 2; +- if (id->idProduct == 0x9050) ++ if (gspca_dev->usb_buf[15] == 0) + cam->nmodes = 1; + /* We don't use the buffer gspca allocates so make it small. */ + cam->bulk_size = 32; +@@ -258,6 +300,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x2770, 0x905c)}, + {USB_DEVICE(0x2770, 0x9050)}, ++ {USB_DEVICE(0x2770, 0x9052)}, + {USB_DEVICE(0x2770, 0x913d)}, + {} + }; +diff --git a/drivers/media/video/gspca/stk014.c b/drivers/media/video/gspca/stk014.c +index 2e29355..0fb5342 100644 +--- a/drivers/media/video/gspca/stk014.c ++++ b/drivers/media/video/gspca/stk014.c +@@ -53,7 +53,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setfreq(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +diff --git a/drivers/media/video/gspca/stv0680.c b/drivers/media/video/gspca/stv0680.c +index 2a69d7c..c3743c9 100644 +--- a/drivers/media/video/gspca/stv0680.c ++++ b/drivers/media/video/gspca/stv0680.c +@@ -45,7 +45,7 @@ struct sd { + }; + + /* V4L2 controls supported by the driver */ +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + }; + + static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val, +@@ -53,24 +53,28 @@ static int stv_sndctrl(struct gspca_dev *gspca_dev, int set, u8 req, u16 val, + { + int ret = -1; + u8 req_type = 0; ++ unsigned int pipe = 0; + + switch (set) { + case 0: /* 0xc1 */ + req_type = USB_DIR_IN | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; ++ pipe = usb_rcvctrlpipe(gspca_dev->dev, 0); + break; + case 1: /* 0x41 */ + req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_ENDPOINT; ++ pipe = usb_sndctrlpipe(gspca_dev->dev, 0); + break; + case 2: /* 0x80 */ + req_type = USB_DIR_IN | USB_RECIP_DEVICE; ++ pipe = usb_rcvctrlpipe(gspca_dev->dev, 0); + break; + case 3: /* 0x40 */ + req_type = USB_DIR_OUT | USB_TYPE_VENDOR | USB_RECIP_DEVICE; ++ pipe = usb_sndctrlpipe(gspca_dev->dev, 0); + break; + } + +- ret = usb_control_msg(gspca_dev->dev, +- usb_rcvctrlpipe(gspca_dev->dev, 0), ++ ret = usb_control_msg(gspca_dev->dev, pipe, + req, req_type, + val, 0, gspca_dev->usb_buf, size, 500); + +@@ -138,6 +142,10 @@ static int sd_config(struct gspca_dev *gspca_dev, + struct sd *sd = (struct sd *) gspca_dev; + struct cam *cam = &gspca_dev->cam; + ++ /* Give the camera some time to settle, otherwise initalization will ++ fail on hotplug, and yes it really needs a full second. */ ++ msleep(1000); ++ + /* ping camera to be sure STV0680 is present */ + if (stv_sndctrl(gspca_dev, 0, 0x88, 0x5678, 0x02) != 0x02 || + gspca_dev->usb_buf[0] != 0x56 || gspca_dev->usb_buf[1] != 0x78) { +@@ -169,6 +177,8 @@ static int sd_config(struct gspca_dev *gspca_dev, + PDEBUG(D_PROBE, "Camera supports CIF mode"); + if (gspca_dev->usb_buf[7] & 0x02) + PDEBUG(D_PROBE, "Camera supports VGA mode"); ++ if (gspca_dev->usb_buf[7] & 0x04) ++ PDEBUG(D_PROBE, "Camera supports QCIF mode"); + if (gspca_dev->usb_buf[7] & 0x08) + PDEBUG(D_PROBE, "Camera supports QVGA mode"); + +@@ -185,6 +195,19 @@ static int sd_config(struct gspca_dev *gspca_dev, + PDEBUG(D_PROBE, "Sensor ID is %i", + (gspca_dev->usb_buf[4]*16) + (gspca_dev->usb_buf[5]>>4)); + ++#if 0 /* The v4l1 driver used to this but I don't think it is necessary */ ++ ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 1); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "Set alt 1 failed (%d)", ret); ++ return ret; ++ } ++ ++ if (stv_sndctrl(gspca_dev, 0, 0x85, 0, 0x10) != 0x10) ++ return stv0680_handle_error(gspca_dev, -EIO); ++ if (stv_sndctrl(gspca_dev, 0, 0x8d, 0, 0x08) != 0x08) ++ return stv0680_handle_error(gspca_dev, -EIO); ++ PDEBUG(D_PROBE, "Camera has %i pictures.", gspca_dev->usb_buf[3]); ++#endif + + ret = stv0680_get_video_mode(gspca_dev); + if (ret < 0) +@@ -220,6 +243,13 @@ static int sd_config(struct gspca_dev *gspca_dev, + cam->cam_mode = &sd->mode; + cam->nmodes = 1; + ++#if 0 /* The v4l1 driver used to this but I don't think it is necessary */ ++ ret = usb_set_interface(gspca_dev->dev, gspca_dev->iface, 0); ++ if (ret < 0) { ++ PDEBUG(D_ERR, "Set alt 0 failed (%d)", ret); ++ return ret; ++ } ++#endif + + ret = stv0680_set_video_mode(gspca_dev, sd->orig_mode); + if (ret < 0) +diff --git a/drivers/media/video/gspca/stv06xx/stv06xx.c b/drivers/media/video/gspca/stv06xx/stv06xx.c +index 5d0241b..af73da3 100644 +--- a/drivers/media/video/gspca/stv06xx/stv06xx.c ++++ b/drivers/media/video/gspca/stv06xx/stv06xx.c +@@ -27,6 +27,7 @@ + * P/N 861040-0000: Sensor ST VV6410 ASIC STV0610 - QuickCam Web + */ + ++#include + #include "stv06xx_sensor.h" + + MODULE_AUTHOR("Erik Andrén"); +@@ -219,6 +220,7 @@ static void stv06xx_dump_bridge(struct sd *sd) + info("Read 0x%x from address 0x%x", data, i); + } + ++ info("Testing stv06xx bridge registers for writability"); + for (i = 0x1400; i < 0x160f; i++) { + stv06xx_read_bridge(sd, i, &data); + buf = data; +@@ -229,7 +231,7 @@ static void stv06xx_dump_bridge(struct sd *sd) + info("Register 0x%x is read/write", i); + else if (data != buf) + info("Register 0x%x is read/write," +- "but only partially", i); ++ " but only partially", i); + else + info("Register 0x%x is read-only", i); + +@@ -426,6 +428,29 @@ frame_data: + } + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrupt packet length */ ++{ ++ int ret = -EINVAL; ++ ++ if (len == 1 && data[0] == 0x80) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ ++ if (len == 1 && data[0] == 0x88) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ ret = 0; ++ } ++ ++ return ret; ++} ++#endif ++ + static int stv06xx_config(struct gspca_dev *gspca_dev, + const struct usb_device_id *id); + +@@ -436,7 +461,10 @@ static const struct sd_desc sd_desc = { + .init = stv06xx_init, + .start = stv06xx_start, + .stopN = stv06xx_stopN, +- .pkt_scan = stv06xx_pkt_scan ++ .pkt_scan = stv06xx_pkt_scan, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + /* This function is called at probe time */ +diff --git a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c +index 285221e..180f52c 100644 +--- a/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c ++++ b/drivers/media/video/gspca/stv06xx/stv06xx_pb0100.c +@@ -150,6 +150,28 @@ static const struct ctrl pb0100_ctrl[] = { + static struct v4l2_pix_format pb0100_mode[] = { + /* low res / subsample modes disabled as they are only half res horizontal, + halving the vertical resolution does not seem to work */ ++#if 0 ++ { ++ 160, ++ 120, ++ V4L2_PIX_FMT_SGRBG8, ++ V4L2_FIELD_NONE, ++ .sizeimage = 160 * 120 * 2, ++ .bytesperline = 160, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = PB0100_CROP_TO_VGA | PB0100_SUBSAMPLE ++ }, ++ { ++ 176, ++ 144, ++ V4L2_PIX_FMT_SGRBG8, ++ V4L2_FIELD_NONE, ++ .sizeimage = 176 * 144 * 2, ++ .bytesperline = 176, ++ .colorspace = V4L2_COLORSPACE_SRGB, ++ .priv = PB0100_SUBSAMPLE ++ }, ++#endif + { + 320, + 240, +diff --git a/drivers/media/video/gspca/sunplus.c b/drivers/media/video/gspca/sunplus.c +index 306b7d7..378c4dd 100644 +--- a/drivers/media/video/gspca/sunplus.c ++++ b/drivers/media/video/gspca/sunplus.c +@@ -67,7 +67,7 @@ static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setautogain(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getautogain(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -207,6 +207,13 @@ static const struct cmd spca504_pccam600_init_data[] = { + {0x00, 0x0000, 0x21ad}, /* hue */ + {0x00, 0x001a, 0x21ae}, /* saturation */ + {0x00, 0x0002, 0x21a3}, /* gamma */ ++#if 0 ++ {0xb0, 0x0000, 0x0000}, /* reset auto exposure */ ++ {0x0c, 0x0000, 0x0000}, /* reset auto whiteness */ ++ {0x0c, 0x0004, 0x0000}, /* enable auto whiteness */ ++ {0x30, 0x020f, 0x0001}, /* exposure compensation */ ++ {0x30, 0x01f7, 0x0002}, /* whiteness balance */ ++#endif + {0x30, 0x0154, 0x0008}, + {0x30, 0x0004, 0x0006}, + {0x30, 0x0258, 0x0009}, +@@ -244,10 +251,20 @@ static const struct cmd spca504A_clicksmart420_init_data[] = { + {0x00, 0x0000, 0x21ad}, /* hue */ + {0x00, 0x001a, 0x21ae}, /* saturation */ + {0x00, 0x0002, 0x21a3}, /* gamma */ ++#if 1 + {0x30, 0x0004, 0x000a}, + {0xb0, 0x0001, 0x0000}, ++#endif + ++#if 0 ++ {0xb0, 0x0000, 0x0000}, /* reset auto exposure */ ++ {0x0c, 0x0000, 0x0000}, /* reset auto whiteness */ ++ {0x0c, 0x0004, 0x0000}, /* enable auto whiteness */ ++ {0x30, 0x020f, 0x0001}, /* exposure compensation */ ++ {0x30, 0x01f7, 0x0002}, /* whiteness balance */ ++#endif + ++#if 1 + {0xa1, 0x0080, 0x0001}, + {0x30, 0x0049, 0x0000}, + {0x30, 0x0060, 0x0005}, +@@ -257,6 +274,7 @@ static const struct cmd spca504A_clicksmart420_init_data[] = { + {0x00, 0x0013, 0x2301}, + {0x00, 0x0003, 0x2000}, + {0x00, 0x0000, 0x2000}, ++#endif + + }; + +@@ -267,6 +285,8 @@ static const struct cmd spca504A_clicksmart420_open_data[] = { + {0x06, 0x0000, 0x0000}, + {0x00, 0x0004, 0x2880}, + {0x00, 0x0001, 0x2881}, ++#if 0 ++/*jfm: overloaded by setup_qtable()*/ + /* look like setting a qTable */ + {0x00, 0x0006, 0x2800}, + {0x00, 0x0004, 0x2801}, +@@ -403,6 +423,7 @@ static const struct cmd spca504A_clicksmart420_open_data[] = { + {0x00, 0x0028, 0x287d}, + {0x00, 0x0028, 0x287e}, + {0x00, 0x0028, 0x287f}, ++#endif + + {0xa0, 0x0000, 0x0503}, + }; +@@ -622,6 +643,20 @@ static void spca504_acknowledged_command(struct gspca_dev *gspca_dev, + PDEBUG(D_FRAM, "after wait 0x%04x", notdone); + } + ++static void spca504_read_info(struct gspca_dev *gspca_dev) ++{ ++ int i; ++ u8 info[6]; ++ ++ for (i = 0; i < 6; i++) ++ info[i] = reg_r_1(gspca_dev, i); ++ PDEBUG(D_STREAM, ++ "Read info: %d %d %d %d %d %d." ++ " Should be 1,0,2,2,0,0", ++ info[0], info[1], info[2], ++ info[3], info[4], info[5]); ++} ++ + static void spca504A_acknowledged_command(struct gspca_dev *gspca_dev, + u8 req, + u16 idx, u16 val, u16 endcode, u8 count) +@@ -881,8 +916,6 @@ static int sd_config(struct gspca_dev *gspca_dev, + static int sd_init(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- int i; +- u8 info[6]; + + switch (sd->bridge) { + case BRIDGE_SPCA504B: +@@ -924,15 +957,8 @@ static int sd_init(struct gspca_dev *gspca_dev) + /* case BRIDGE_SPCA504: */ + PDEBUG(D_STREAM, "Opening SPCA504"); + if (sd->subtype == AiptekMiniPenCam13) { +- /*****************************/ +- for (i = 0; i < 6; i++) +- info[i] = reg_r_1(gspca_dev, i); +- PDEBUG(D_STREAM, +- "Read info: %d %d %d %d %d %d." +- " Should be 1,0,2,2,0,0", +- info[0], info[1], info[2], +- info[3], info[4], info[5]); +- /* spca504a aiptek */ ++ spca504_read_info(gspca_dev); ++ + /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ + spca504A_acknowledged_command(gspca_dev, 0x24, + 8, 3, 0x9e, 1); +@@ -971,8 +997,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + int enable; +- int i; +- u8 info[6]; + + /* create the JPEG header */ + sd->jpeg_hdr = kmalloc(JPEG_HDR_SZ, GFP_KERNEL); +@@ -1008,14 +1032,8 @@ static int sd_start(struct gspca_dev *gspca_dev) + break; + case BRIDGE_SPCA504: + if (sd->subtype == AiptekMiniPenCam13) { +- for (i = 0; i < 6; i++) +- info[i] = reg_r_1(gspca_dev, i); +- PDEBUG(D_STREAM, +- "Read info: %d %d %d %d %d %d." +- " Should be 1,0,2,2,0,0", +- info[0], info[1], info[2], +- info[3], info[4], info[5]); +- /* spca504a aiptek */ ++ spca504_read_info(gspca_dev); ++ + /* Set AE AWB Banding Type 3-> 50Hz 2-> 60Hz */ + spca504A_acknowledged_command(gspca_dev, 0x24, + 8, 3, 0x9e, 1); +@@ -1026,13 +1044,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + 0, 0, 0x9d, 1); + } else { + spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); +- for (i = 0; i < 6; i++) +- info[i] = reg_r_1(gspca_dev, i); +- PDEBUG(D_STREAM, +- "Read info: %d %d %d %d %d %d." +- " Should be 1,0,2,2,0,0", +- info[0], info[1], info[2], +- info[3], info[4], info[5]); ++ spca504_read_info(gspca_dev); + spca504_acknowledged_command(gspca_dev, 0x24, 8, 3); + spca504_acknowledged_command(gspca_dev, 0x24, 0, 0); + } +@@ -1336,6 +1348,7 @@ static const __devinitdata struct usb_device_id device_table[] = { + {USB_DEVICE(0x04fc, 0x5330), BS(SPCA533, 0)}, + {USB_DEVICE(0x04fc, 0x5360), BS(SPCA536, 0)}, + {USB_DEVICE(0x04fc, 0xffff), BS(SPCA504B, 0)}, ++ {USB_DEVICE(0x052b, 0x1507), BS(SPCA533, MegapixV4)}, + {USB_DEVICE(0x052b, 0x1513), BS(SPCA533, MegapixV4)}, + {USB_DEVICE(0x052b, 0x1803), BS(SPCA533, MegaImageVI)}, + {USB_DEVICE(0x0546, 0x3155), BS(SPCA533, 0)}, +diff --git a/drivers/media/video/gspca/t613.c b/drivers/media/video/gspca/t613.c +index 55ef6a7..07002d3 100644 +--- a/drivers/media/video/gspca/t613.c ++++ b/drivers/media/video/gspca/t613.c +@@ -52,6 +52,7 @@ struct sd { + #define SENSOR_OM6802 0 + #define SENSOR_OTHER 1 + #define SENSOR_TAS5130A 2 ++#define SENSOR_LT168G 3 /* must verify if this is the actual model */ + }; + + /* V4L2 controls supported by the driver */ +@@ -78,7 +79,7 @@ static int sd_geteffect(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_querymenu(struct gspca_dev *gspca_dev, + struct v4l2_querymenu *menu); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -306,6 +307,17 @@ static const u8 n4_tas5130a[] = { + 0xbe, 0x36, 0xbf, 0xff, 0xc2, 0x88, 0xc5, 0xc8, + 0xc6, 0xda + }; ++static const u8 n4_lt168g[] = { ++ 0x66, 0x01, 0x7f, 0x00, 0x80, 0x7c, 0x81, 0x28, ++ 0x83, 0x44, 0x84, 0x20, 0x86, 0x20, 0x8a, 0x70, ++ 0x8b, 0x58, 0x8c, 0x88, 0x8d, 0xa0, 0x8e, 0xb3, ++ 0x8f, 0x24, 0xa1, 0xb0, 0xa2, 0x38, 0xa5, 0x20, ++ 0xa6, 0x4a, 0xa8, 0xe8, 0xaf, 0x38, 0xb0, 0x68, ++ 0xb1, 0x44, 0xb2, 0x88, 0xbb, 0x86, 0xbd, 0x40, ++ 0xbe, 0x26, 0xc1, 0x05, 0xc2, 0x88, 0xc5, 0xc0, ++ 0xda, 0x8e, 0xdb, 0xca, 0xdc, 0xa8, 0xdd, 0x8c, ++ 0xde, 0x44, 0xdf, 0x0c, 0xe9, 0x80 ++}; + + static const struct additional_sensor_data sensor_data[] = { + { /* 0: OM6802 */ +@@ -317,16 +329,35 @@ static const struct additional_sensor_data sensor_data[] = { + .reg8e = 0x33, + .nset8 = {0xa8, 0xf0, 0xc6, 0x88, 0xc0, 0x00}, + .data1 = ++#if 1 + {0xc2, 0x28, 0x0f, 0x22, 0xcd, 0x27, 0x2c, 0x06, + 0xb3, 0xfc}, ++#else ++ {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27, ++ 0xc8, 0xfc}, ++#endif + .data2 = ++#if 1 + {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff, + 0xff}, ++#else ++ {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8, ++ 0xe0}, ++#endif + .data3 = ++#if 1 + {0x80, 0xff, 0xff, 0x80, 0xff, 0xff, 0x80, 0xff, + 0xff}, ++#else ++ {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8, ++ 0xe0}, ++#endif + .data4 = /*Freq (50/60Hz). Splitted for test purpose */ ++#if 0 ++ {0x66, 0x8a, 0xa8, 0xe8}, ++#else + {0x66, 0xca, 0xa8, 0xf0}, ++#endif + .data5 = /* this could be removed later */ + {0x0c, 0x03, 0xab, 0x13, 0x81, 0x23}, + .stream = +@@ -365,21 +396,61 @@ static const struct additional_sensor_data sensor_data[] = { + .reg8e = 0xb4, + .nset8 = {0xa8, 0xf0, 0xc6, 0xda, 0xc0, 0x00}, + .data1 = ++#if 1 + {0xbb, 0x28, 0x10, 0x10, 0xbb, 0x28, 0x1e, 0x27, + 0xc8, 0xfc}, ++#else ++ {0xf3, 0xa1, 0x0a, 0x2f, 0xbb, 0x2e, 0x21, 0x68, ++ 0xea, 0xbf}, ++#endif + .data2 = ++#if 1 + {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8, + 0xe0}, ++#else ++ {0x40, 0x80, 0xc0, 0x40, 0x80, 0xc0, 0x4d, 0x97, ++ 0xe4}, ++#endif + .data3 = ++#if 1 + {0x60, 0xa8, 0xe0, 0x60, 0xa8, 0xe0, 0x60, 0xa8, + 0xe0}, ++#else ++ {0x40, 0x80, 0xc0, 0x41, 0x81, 0xc3, 0x5c, 0x99, ++ 0xe0}, ++#endif + .data4 = /* Freq (50/60Hz). Splitted for test purpose */ ++#if 1 + {0x66, 0x00, 0xa8, 0xe8}, ++#else ++ {0x66, 0x40, 0xa8, 0xf0}, ++#endif + .data5 = ++#if 0 ++ {0x0c, 0x03, 0xab, 0x08, 0x81, 0x68}, ++#else + {0x0c, 0x03, 0xab, 0x10, 0x81, 0x20}, ++#endif + .stream = + {0x0b, 0x04, 0x0a, 0x40}, + }, ++ { /* 3: LT168G */ ++ .n3 = {0x61, 0xc2, 0x65, 0x68, 0x60, 0x00}, ++ .n4 = n4_lt168g, ++ .n4sz = sizeof n4_lt168g, ++ .reg80 = 0x7c, ++ .reg8e = 0xb3, ++ .nset8 = {0xa8, 0xf0, 0xc6, 0xba, 0xc0, 0x00}, ++ .data1 = {0xc0, 0x38, 0x08, 0x10, 0xc0, 0x30, 0x10, 0x40, ++ 0xb0, 0xf4}, ++ .data2 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6, ++ 0xff}, ++ .data3 = {0x40, 0x80, 0xc0, 0x50, 0xa0, 0xf0, 0x53, 0xa6, ++ 0xff}, ++ .data4 = {0x66, 0x41, 0xa8, 0xf0}, ++ .data5 = {0x0c, 0x03, 0xab, 0x4b, 0x81, 0x2b}, ++ .stream = {0x0b, 0x04, 0x0a, 0x28}, ++ }, + }; + + #define MAX_EFFECTS 7 +@@ -716,6 +787,10 @@ static int sd_init(struct gspca_dev *gspca_dev) + PDEBUG(D_PROBE, "sensor tas5130a"); + sd->sensor = SENSOR_TAS5130A; + break; ++ case 0x0802: ++ PDEBUG(D_PROBE, "sensor lt168g"); ++ sd->sensor = SENSOR_LT168G; ++ break; + case 0x0803: + PDEBUG(D_PROBE, "sensor 'other'"); + sd->sensor = SENSOR_OTHER; +@@ -758,6 +833,13 @@ static int sd_init(struct gspca_dev *gspca_dev) + reg_w_buf(gspca_dev, sensor->n3, sizeof sensor->n3); + reg_w_buf(gspca_dev, sensor->n4, sensor->n4sz); + ++ if (sd->sensor == SENSOR_LT168G) { ++ test_byte = reg_r(gspca_dev, 0x80); ++ PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80, ++ test_byte); ++ reg_w(gspca_dev, 0x6c80); ++ } ++ + reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1); + reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2); + reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3); +@@ -782,6 +864,13 @@ static int sd_init(struct gspca_dev *gspca_dev) + reg_w_buf(gspca_dev, sensor->nset8, sizeof sensor->nset8); + reg_w_buf(gspca_dev, sensor->stream, sizeof sensor->stream); + ++ if (sd->sensor == SENSOR_LT168G) { ++ test_byte = reg_r(gspca_dev, 0x80); ++ PDEBUG(D_STREAM, "Reg 0x%02x = 0x%02x", 0x80, ++ test_byte); ++ reg_w(gspca_dev, 0x6c80); ++ } ++ + reg_w_ixbuf(gspca_dev, 0xd0, sensor->data1, sizeof sensor->data1); + reg_w_ixbuf(gspca_dev, 0xc7, sensor->data2, sizeof sensor->data2); + reg_w_ixbuf(gspca_dev, 0xe0, sensor->data3, sizeof sensor->data3); +@@ -888,6 +977,8 @@ static int sd_start(struct gspca_dev *gspca_dev) + case SENSOR_OM6802: + om6802_sensor_init(gspca_dev); + break; ++ case SENSOR_LT168G: ++ break; + case SENSOR_OTHER: + break; + default: +@@ -920,6 +1011,15 @@ static int sd_start(struct gspca_dev *gspca_dev) + if (sd->sensor == SENSOR_OM6802) + poll_sensor(gspca_dev); + ++#if 0 ++ /* restart on each start, just in case, sometimes regs goes wrong ++ * when using controls from app */ ++ setbrightness(gspca_dev); ++ setcontrast(gspca_dev); ++ setcolors(gspca_dev); ++ seteffect(gspca_dev); ++ setflip(gspca_dev); ++#endif + return 0; + } + +diff --git a/drivers/media/video/gspca/tv8532.c b/drivers/media/video/gspca/tv8532.c +index b74a3b6..0267396 100644 +--- a/drivers/media/video/gspca/tv8532.c ++++ b/drivers/media/video/gspca/tv8532.c +@@ -39,7 +39,7 @@ struct sd { + static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -228,6 +228,12 @@ static void tv_8532ReadRegisters(struct gspca_dev *gspca_dev) + 0 + }; + ++#if 0 ++ data = reg_r(gspca_dev, 0x0001); ++ PDEBUG(D_USBI, "register 0x01-> %x", data); ++ data = reg_r(gspca_dev, 0x0002); ++ PDEBUG(D_USBI, "register 0x02-> %x", data); ++#endif + i = 0; + do { + reg_r(gspca_dev, reg_tb[i]); +diff --git a/drivers/media/video/gspca/vc032x.c b/drivers/media/video/gspca/vc032x.c +index 71921c8..e42e55a 100644 +--- a/drivers/media/video/gspca/vc032x.c ++++ b/drivers/media/video/gspca/vc032x.c +@@ -32,10 +32,13 @@ MODULE_LICENSE("GPL"); + struct sd { + struct gspca_dev gspca_dev; /* !! must be the first item */ + ++ u8 brightness; ++ u8 contrast; ++ u8 colors; + u8 hflip; + u8 vflip; + u8 lightfreq; +- u8 sharpness; ++ s8 sharpness; + + u8 image_offset; + +@@ -52,6 +55,7 @@ struct sd { + #define SENSOR_OV7670 6 + #define SENSOR_PO1200 7 + #define SENSOR_PO3130NC 8 ++#define SENSOR_POxxxx 9 + u8 flags; + #define FL_SAMSUNG 0x01 /* SamsungQ1 (2 sensors) */ + #define FL_HFLIP 0x02 /* mirrored by default */ +@@ -59,6 +63,12 @@ struct sd { + }; + + /* V4L2 controls supported by the driver */ ++static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val); ++static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val); ++static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val); + static int sd_gethflip(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setvflip(struct gspca_dev *gspca_dev, __s32 val); +@@ -68,9 +78,54 @@ static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { ++#define BRIGHTNESS_IDX 0 ++ { ++ { ++ .id = V4L2_CID_BRIGHTNESS, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Brightness", ++ .minimum = 0, ++ .maximum = 255, ++ .step = 1, ++#define BRIGHTNESS_DEF 128 ++ .default_value = BRIGHTNESS_DEF, ++ }, ++ .set = sd_setbrightness, ++ .get = sd_getbrightness, ++ }, ++#define CONTRAST_IDX 1 ++ { ++ { ++ .id = V4L2_CID_CONTRAST, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Contrast", ++ .minimum = 0, ++ .maximum = 255, ++ .step = 1, ++#define CONTRAST_DEF 127 ++ .default_value = CONTRAST_DEF, ++ }, ++ .set = sd_setcontrast, ++ .get = sd_getcontrast, ++ }, ++#define COLORS_IDX 2 ++ { ++ { ++ .id = V4L2_CID_SATURATION, ++ .type = V4L2_CTRL_TYPE_INTEGER, ++ .name = "Saturation", ++ .minimum = 1, ++ .maximum = 127, ++ .step = 1, ++#define COLOR_DEF 63 ++ .default_value = COLOR_DEF, ++ }, ++ .set = sd_setcolors, ++ .get = sd_getcolors, ++ }, + /* next 2 controls work with some sensors only */ +-#define HFLIP_IDX 0 ++#define HFLIP_IDX 3 + { + { + .id = V4L2_CID_HFLIP, +@@ -85,7 +140,7 @@ static struct ctrl sd_ctrls[] = { + .set = sd_sethflip, + .get = sd_gethflip, + }, +-#define VFLIP_IDX 1 ++#define VFLIP_IDX 4 + { + { + .id = V4L2_CID_VFLIP, +@@ -100,7 +155,7 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setvflip, + .get = sd_getvflip, + }, +-#define LIGHTFREQ_IDX 2 ++#define LIGHTFREQ_IDX 5 + { + { + .id = V4L2_CID_POWER_LINE_FREQUENCY, +@@ -115,17 +170,16 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setfreq, + .get = sd_getfreq, + }, +-/* po1200 only */ +-#define SHARPNESS_IDX 3 ++#define SHARPNESS_IDX 6 + { + { + .id = V4L2_CID_SHARPNESS, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Sharpness", +- .minimum = 0, ++ .minimum = -1, + .maximum = 2, + .step = 1, +-#define SHARPNESS_DEF 1 ++#define SHARPNESS_DEF -1 + .default_value = SHARPNESS_DEF, + }, + .set = sd_setsharpness, +@@ -133,6 +187,42 @@ static struct ctrl sd_ctrls[] = { + }, + }; + ++/* table of the disabled controls */ ++static u32 ctrl_dis[] = { ++/* SENSOR_HV7131R 0 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) ++ | (1 << SHARPNESS_IDX), ++/* SENSOR_MI0360 1 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) ++ | (1 << SHARPNESS_IDX), ++/* SENSOR_MI1310_SOC 2 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), ++/* SENSOR_MI1320 3 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), ++/* SENSOR_MI1320_SOC 4 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), ++/* SENSOR_OV7660 5 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << LIGHTFREQ_IDX) | (1 << SHARPNESS_IDX), ++/* SENSOR_OV7670 6 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << SHARPNESS_IDX), ++/* SENSOR_PO1200 7 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << LIGHTFREQ_IDX), ++/* SENSOR_PO3130NC 8 */ ++ (1 << BRIGHTNESS_IDX) | (1 << CONTRAST_IDX) | (1 << COLORS_IDX) ++ | (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX) ++ | (1 << SHARPNESS_IDX), ++/* SENSOR_POxxxx 9 */ ++ (1 << HFLIP_IDX) | (1 << VFLIP_IDX) | (1 << LIGHTFREQ_IDX), ++}; ++ + static const struct v4l2_pix_format vc0321_mode[] = { + {320, 240, V4L2_PIX_FMT_YVYU, V4L2_FIELD_NONE, + .bytesperline = 320, +@@ -163,16 +253,37 @@ static const struct v4l2_pix_format vc0323_mode[] = { + .priv = 2}, + }; + static const struct v4l2_pix_format bi_mode[] = { ++#if 0 /* JPEG vc0323 */ ++ {320, 240, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 320, ++ .sizeimage = 320 * 240 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG, ++ .priv = 5}, ++#endif + {320, 240, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, + .bytesperline = 320, + .sizeimage = 320 * 240 * 2, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 2}, ++#if 0 /* JPEG vc0323 */ ++ {640, 480, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 640, ++ .sizeimage = 640 * 480 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG, ++ .priv = 4}, ++#endif + {640, 480, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, + .bytesperline = 640, + .sizeimage = 640 * 480 * 2, + .colorspace = V4L2_COLORSPACE_SRGB, + .priv = 1}, ++#if 0 /* JPEG vc0323 */ ++ {1280, 1024, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 1280, ++ .sizeimage = 1280 * 1024 * 1 / 4 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG, ++ .priv = 3}, ++#endif + {1280, 1024, V4L2_PIX_FMT_YUYV, V4L2_FIELD_NONE, + .bytesperline = 1280, + .sizeimage = 1280 * 1024 * 2, +@@ -215,7 +326,7 @@ static const u8 mi0360_initVGA_JPG[][4] = { + {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x02, 0xcc}, + {0xb3, 0x17, 0x7f, 0xcc}, +- {0xb3, 0x35, 0xdd, 0xcc}, ++ {0xb3, 0x35, 0xdd, 0xcc}, /* i2c add: 5d */ + {0xb3, 0x34, 0x02, 0xcc}, + {0xb3, 0x00, 0x25, 0xcc}, + {0xbc, 0x00, 0x71, 0xcc}, +@@ -435,7 +546,7 @@ static const u8 mi1310_socinitVGA_JPG[][4] = { + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, +- {0xb3, 0x35, 0xdd, 0xcc}, ++ {0xb3, 0x35, 0xdd, 0xcc}, /* i2c add: 5d */ + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, +@@ -681,7 +792,11 @@ static const u8 mi1310_soc_InitSXGA_JPG[][4] = { + {0xc8, 0x9f, 0x0b, 0xbb}, + {0x5b, 0x00, 0x01, 0xbb}, + {0xf0, 0x00, 0x00, 0xbb}, ++#if 1 + {0x20, 0x03, 0x02, 0xbb}, /* h/v flip */ ++#else ++ {0x20, 0x03, 0x03, 0xbb}, /* h/v flip */ ++#endif + {0xf0, 0x00, 0x01, 0xbb}, + {0x05, 0x00, 0x07, 0xbb}, + {0x34, 0x00, 0x00, 0xbb}, +@@ -860,7 +975,8 @@ static const u8 mi1320_initVGA_data[][4] = { + {0xb0, 0x16, 0x03, 0xcc}, {0xb3, 0x05, 0x00, 0xcc}, + {0xb3, 0x06, 0x00, 0xcc}, {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, {0xb3, 0x34, 0x02, 0xcc}, +- {0xb3, 0x35, 0xc8, 0xcc}, {0xb3, 0x02, 0x00, 0xcc}, ++ {0xb3, 0x35, 0xc8, 0xcc}, /* i2c add: 48 */ ++ {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, {0xb3, 0x04, 0x05, 0xcc}, + {0xb3, 0x20, 0x00, 0xcc}, {0xb3, 0x21, 0x00, 0xcc}, + {0xb3, 0x22, 0x03, 0xcc}, {0xb3, 0x23, 0xc0, 0xcc}, +@@ -901,7 +1017,8 @@ static const u8 mi1320_initVGA_data[][4] = { + {0xc3, 0x01, 0x03, 0xbb}, {0xc4, 0x00, 0x04, 0xbb}, + {0xf0, 0x00, 0x00, 0xbb}, {0x05, 0x01, 0x13, 0xbb}, + {0x06, 0x00, 0x11, 0xbb}, {0x07, 0x00, 0x85, 0xbb}, +- {0x08, 0x00, 0x27, 0xbb}, {0x20, 0x01, 0x03, 0xbb}, ++ {0x08, 0x00, 0x27, 0xbb}, ++ {0x20, 0x01, 0x00, 0xbb}, /* h/v flips - was 03 */ + {0x21, 0x80, 0x00, 0xbb}, {0x22, 0x0d, 0x0f, 0xbb}, + {0x24, 0x80, 0x00, 0xbb}, {0x59, 0x00, 0xff, 0xbb}, + {0xf0, 0x00, 0x02, 0xbb}, {0x39, 0x03, 0x0d, 0xbb}, +@@ -1012,7 +1129,7 @@ static const u8 mi1320_soc_InitVGA[][4] = { + {0xb3, 0x08, 0x01, 0xcc}, + {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x34, 0x02, 0xcc}, +- {0xb3, 0x35, 0xc8, 0xcc}, ++ {0xb3, 0x35, 0xc8, 0xcc}, /* i2c add: 48 */ + {0xb3, 0x02, 0x00, 0xcc}, + {0xb3, 0x03, 0x0a, 0xcc}, + {0xb3, 0x04, 0x05, 0xcc}, +@@ -1103,6 +1220,123 @@ static const u8 mi1320_soc_InitVGA[][4] = { + {0xb3, 0x5c, 0x01, 0xcc}, + {} + }; ++#if 0 /* JPEG vc0323 */ ++static const u8 mi1320_soc_InitVGA_JPG[][4] = { ++ {0xb3, 0x01, 0x01, 0xcc}, ++ {0xb0, 0x03, 0x19, 0xcc}, ++ {0xb0, 0x04, 0x02, 0xcc}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xb3, 0x00, 0x64, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb3, 0x05, 0x01, 0xcc}, ++ {0xb3, 0x06, 0x01, 0xcc}, ++ {0xb3, 0x08, 0x01, 0xcc}, ++ {0xb3, 0x09, 0x0c, 0xcc}, ++ {0xb3, 0x34, 0x02, 0xcc}, ++ {0xb3, 0x35, 0xc8, 0xcc}, ++ {0xb3, 0x02, 0x00, 0xcc}, ++ {0xb3, 0x03, 0x0a, 0xcc}, ++ {0xb3, 0x04, 0x05, 0xcc}, ++ {0xb3, 0x20, 0x00, 0xcc}, ++ {0xb3, 0x21, 0x00, 0xcc}, ++ {0xb3, 0x22, 0x01, 0xcc}, ++ {0xb3, 0x23, 0xe0, 0xcc}, ++ {0xb3, 0x14, 0x00, 0xcc}, ++ {0xb3, 0x15, 0x00, 0xcc}, ++ {0xb3, 0x16, 0x02, 0xcc}, ++ {0xb3, 0x17, 0x7f, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb8, 0x00, 0x00, 0xcc}, ++ {0xbc, 0x00, 0x71, 0xcc}, ++ {0xbc, 0x01, 0x01, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xc8, 0x00, 0x00, 0xbb}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0x07, 0x00, 0xe0, 0xbb}, ++ {0x08, 0x00, 0x0b, 0xbb}, ++ {0x21, 0x00, 0x0c, 0xbb}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0xb6, 0x00, 0x00, 0xcc}, ++ {0xb6, 0x03, 0x02, 0xcc}, ++ {0xb6, 0x02, 0x80, 0xcc}, ++ {0xb6, 0x05, 0x01, 0xcc}, ++ {0xb6, 0x04, 0xe0, 0xcc}, ++ {0xb6, 0x12, 0xf8, 0xcc}, ++ {0xb6, 0x13, 0x05, 0xcc}, ++ {0xb6, 0x18, 0x02, 0xcc}, ++ {0xb6, 0x17, 0x58, 0xcc}, ++ {0xb6, 0x16, 0x00, 0xcc}, ++ {0xb6, 0x22, 0x12, 0xcc}, ++ {0xb6, 0x23, 0x0b, 0xcc}, ++ {0xbf, 0xc0, 0x39, 0xcc}, ++ {0xbf, 0xc1, 0x04, 0xcc}, ++ {0xbf, 0xcc, 0x00, 0xcc}, ++ {0xb3, 0x01, 0x41, 0xcc}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x05, 0x01, 0x78, 0xbb}, ++ {0x06, 0x00, 0x11, 0xbb}, ++ {0x07, 0x01, 0x42, 0xbb}, ++ {0x08, 0x00, 0x11, 0xbb}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0x21, 0x80, 0x00, 0xbb}, ++ {0x22, 0x0d, 0x0f, 0xbb}, ++ {0x24, 0x80, 0x00, 0xbb}, ++ {0x59, 0x00, 0xff, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x39, 0x03, 0xca, 0xbb}, ++ {0x3a, 0x06, 0x80, 0xbb}, ++ {0x3b, 0x01, 0x52, 0xbb}, ++ {0x3c, 0x05, 0x40, 0xbb}, ++ {0x57, 0x01, 0x9c, 0xbb}, ++ {0x58, 0x01, 0xee, 0xbb}, ++ {0x59, 0x00, 0xf0, 0xbb}, ++ {0x5a, 0x01, 0x20, 0xbb}, ++ {0x5c, 0x1d, 0x17, 0xbb}, ++ {0x5d, 0x22, 0x1c, 0xbb}, ++ {0x64, 0x1e, 0x1c, 0xbb}, ++ {0x5b, 0x00, 0x00, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x22, 0xa0, 0x78, 0xbb}, ++ {0x23, 0xa0, 0x78, 0xbb}, ++ {0x24, 0x7f, 0x00, 0xbb}, ++ {0x28, 0xea, 0x02, 0xbb}, ++ {0x29, 0x86, 0x7a, 0xbb}, ++ {0x5e, 0x52, 0x4c, 0xbb}, ++ {0x5f, 0x20, 0x24, 0xbb}, ++ {0x60, 0x00, 0x02, 0xbb}, ++ {0x02, 0x00, 0xee, 0xbb}, ++ {0x03, 0x39, 0x23, 0xbb}, ++ {0x04, 0x07, 0x24, 0xbb}, ++ {0x09, 0x00, 0xc0, 0xbb}, ++ {0x0a, 0x00, 0x79, 0xbb}, ++ {0x0b, 0x00, 0x04, 0xbb}, ++ {0x0c, 0x00, 0x5c, 0xbb}, ++ {0x0d, 0x00, 0xd9, 0xbb}, ++ {0x0e, 0x00, 0x53, 0xbb}, ++ {0x0f, 0x00, 0x21, 0xbb}, ++ {0x10, 0x00, 0xa4, 0xbb}, ++ {0x11, 0x00, 0xe5, 0xbb}, ++ {0x15, 0x00, 0x00, 0xbb}, ++ {0x16, 0x00, 0x00, 0xbb}, ++ {0x17, 0x00, 0x00, 0xbb}, ++ {0x18, 0x00, 0x00, 0xbb}, ++ {0x19, 0x00, 0x00, 0xbb}, ++ {0x1a, 0x00, 0x00, 0xbb}, ++ {0x1b, 0x00, 0x00, 0xbb}, ++ {0x1c, 0x00, 0x00, 0xbb}, ++ {0x1d, 0x00, 0x00, 0xbb}, ++ {0x1e, 0x00, 0x00, 0xbb}, ++ {0xf0, 0x00, 0x01, 0xbb}, ++ {0x06, 0xe0, 0x0e, 0xbb}, ++ {0x06, 0x60, 0x0e, 0xbb}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {} ++}; ++#endif + static const u8 mi1320_soc_InitQVGA[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, +@@ -1216,6 +1450,272 @@ static const u8 mi1320_soc_InitQVGA[][4] = { + {0xb3, 0x5c, 0x01, 0xcc}, + {} + }; ++#if 0 /* JPEG vc0323 */ ++static const u8 mi1320_soc_InitQVGA_JPG[][4] = { ++ {0xb3, 0x01, 0x01, 0xcc}, ++ {0xb0, 0x03, 0x19, 0xcc}, ++ {0xb0, 0x04, 0x02, 0xcc}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xb3, 0x00, 0x64, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb3, 0x05, 0x01, 0xcc}, ++ {0xb3, 0x06, 0x01, 0xcc}, ++ {0xb3, 0x08, 0x01, 0xcc}, ++ {0xb3, 0x09, 0x0c, 0xcc}, ++ {0xb3, 0x34, 0x02, 0xcc}, ++ {0xb3, 0x35, 0xc8, 0xcc}, ++ {0xb3, 0x02, 0x00, 0xcc}, ++ {0xb3, 0x03, 0x0a, 0xcc}, ++ {0xb3, 0x04, 0x05, 0xcc}, ++ {0xb3, 0x20, 0x00, 0xcc}, ++ {0xb3, 0x21, 0x00, 0xcc}, ++ {0xb3, 0x22, 0x01, 0xcc}, ++ {0xb3, 0x23, 0xe0, 0xcc}, ++ {0xb3, 0x14, 0x00, 0xcc}, ++ {0xb3, 0x15, 0x00, 0xcc}, ++ {0xb3, 0x16, 0x02, 0xcc}, ++ {0xb3, 0x17, 0x7f, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb8, 0x00, 0x00, 0xcc}, ++ {0xbc, 0x00, 0xd1, 0xcc}, ++ {0xbc, 0x01, 0x01, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xc8, 0x00, 0x00, 0xbb}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0x07, 0x00, 0xe0, 0xbb}, ++ {0x08, 0x00, 0x0b, 0xbb}, ++ {0x21, 0x00, 0x0c, 0xbb}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0xb6, 0x00, 0x00, 0xcc}, ++ {0xb6, 0x03, 0x01, 0xcc}, ++ {0xb6, 0x02, 0x40, 0xcc}, ++ {0xb6, 0x05, 0x00, 0xcc}, ++ {0xb6, 0x04, 0xf0, 0xcc}, ++ {0xb6, 0x12, 0xf8, 0xcc}, ++ {0xb6, 0x13, 0x05, 0xcc}, ++ {0xb6, 0x18, 0x00, 0xcc}, ++ {0xb6, 0x17, 0x96, 0xcc}, ++ {0xb6, 0x16, 0x00, 0xcc}, ++ {0xb6, 0x22, 0x12, 0xcc}, ++ {0xb6, 0x23, 0x0b, 0xcc}, ++ {0xbf, 0xc0, 0x39, 0xcc}, ++ {0xbf, 0xc1, 0x04, 0xcc}, ++ {0xbf, 0xcc, 0x00, 0xcc}, ++ {0xbc, 0x02, 0x18, 0xcc}, ++ {0xbc, 0x03, 0x50, 0xcc}, ++ {0xbc, 0x04, 0x18, 0xcc}, ++ {0xbc, 0x05, 0x00, 0xcc}, ++ {0xbc, 0x06, 0x00, 0xcc}, ++ {0xbc, 0x08, 0x30, 0xcc}, ++ {0xbc, 0x09, 0x40, 0xcc}, ++ {0xbc, 0x0a, 0x10, 0xcc}, ++ {0xbc, 0x0b, 0x00, 0xcc}, ++ {0xbc, 0x0c, 0x00, 0xcc}, ++ {0xb3, 0x01, 0x41, 0xcc}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x05, 0x01, 0x78, 0xbb}, ++ {0x06, 0x00, 0x11, 0xbb}, ++ {0x07, 0x01, 0x42, 0xbb}, ++ {0x08, 0x00, 0x11, 0xbb}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0x21, 0x80, 0x00, 0xbb}, ++ {0x22, 0x0d, 0x0f, 0xbb}, ++ {0x24, 0x80, 0x00, 0xbb}, ++ {0x59, 0x00, 0xff, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x39, 0x03, 0xca, 0xbb}, ++ {0x3a, 0x06, 0x80, 0xbb}, ++ {0x3b, 0x01, 0x52, 0xbb}, ++ {0x3c, 0x05, 0x40, 0xbb}, ++ {0x57, 0x01, 0x9c, 0xbb}, ++ {0x58, 0x01, 0xee, 0xbb}, ++ {0x59, 0x00, 0xf0, 0xbb}, ++ {0x5a, 0x01, 0x20, 0xbb}, ++ {0x5c, 0x1d, 0x17, 0xbb}, ++ {0x5d, 0x22, 0x1c, 0xbb}, ++ {0x64, 0x1e, 0x1c, 0xbb}, ++ {0x5b, 0x00, 0x00, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x22, 0xa0, 0x78, 0xbb}, ++ {0x23, 0xa0, 0x78, 0xbb}, ++ {0x24, 0x7f, 0x00, 0xbb}, ++ {0x28, 0xea, 0x02, 0xbb}, ++ {0x29, 0x86, 0x7a, 0xbb}, ++ {0x5e, 0x52, 0x4c, 0xbb}, ++ {0x5f, 0x20, 0x24, 0xbb}, ++ {0x60, 0x00, 0x02, 0xbb}, ++ {0x02, 0x00, 0xee, 0xbb}, ++ {0x03, 0x39, 0x23, 0xbb}, ++ {0x04, 0x07, 0x24, 0xbb}, ++ {0x09, 0x00, 0xc0, 0xbb}, ++ {0x0a, 0x00, 0x79, 0xbb}, ++ {0x0b, 0x00, 0x04, 0xbb}, ++ {0x0c, 0x00, 0x5c, 0xbb}, ++ {0x0d, 0x00, 0xd9, 0xbb}, ++ {0x0e, 0x00, 0x53, 0xbb}, ++ {0x0f, 0x00, 0x21, 0xbb}, ++ {0x10, 0x00, 0xa4, 0xbb}, ++ {0x11, 0x00, 0xe5, 0xbb}, ++ {0x15, 0x00, 0x00, 0xbb}, ++ {0x16, 0x00, 0x00, 0xbb}, ++ {0x17, 0x00, 0x00, 0xbb}, ++ {0x18, 0x00, 0x00, 0xbb}, ++ {0x19, 0x00, 0x00, 0xbb}, ++ {0x1a, 0x00, 0x00, 0xbb}, ++ {0x1b, 0x00, 0x00, 0xbb}, ++ {0x1c, 0x00, 0x00, 0xbb}, ++ {0x1d, 0x00, 0x00, 0xbb}, ++ {0x1e, 0x00, 0x00, 0xbb}, ++ {0xf0, 0x00, 0x01, 0xbb}, ++ {0x06, 0xe0, 0x0e, 0xbb}, ++ {0x06, 0x60, 0x0e, 0xbb}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {} ++}; ++#endif ++#if 0 /* JPEG vc0323 */ ++static const u8 mi1320_soc_InitSXGA_JPG[][4] = { ++ {0xb3, 0x01, 0x01, 0xcc}, ++ {0xb0, 0x03, 0x19, 0xcc}, ++ {0xb0, 0x04, 0x02, 0xcc}, ++ {0x00, 0x00, 0x33, 0xdd}, ++ {0xb3, 0x00, 0x64, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb3, 0x05, 0x00, 0xcc}, ++ {0xb3, 0x06, 0x00, 0xcc}, ++ {0xb3, 0x08, 0x01, 0xcc}, ++ {0xb3, 0x09, 0x0c, 0xcc}, ++ {0xb3, 0x34, 0x02, 0xcc}, ++ {0xb3, 0x35, 0xc8, 0xcc}, ++ {0xb3, 0x02, 0x00, 0xcc}, ++ {0xb3, 0x03, 0x0a, 0xcc}, ++ {0xb3, 0x04, 0x05, 0xcc}, ++ {0xb3, 0x20, 0x00, 0xcc}, ++ {0xb3, 0x21, 0x00, 0xcc}, ++ {0xb3, 0x22, 0x04, 0xcc}, ++ {0xb3, 0x23, 0x00, 0xcc}, ++ {0xb3, 0x14, 0x00, 0xcc}, ++ {0xb3, 0x15, 0x00, 0xcc}, ++ {0xb3, 0x16, 0x04, 0xcc}, ++ {0xb3, 0x17, 0xff, 0xcc}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xbc, 0x00, 0x71, 0xcc}, ++ {0xbc, 0x01, 0x01, 0xcc}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0xc8, 0x9f, 0x0b, 0xbb}, ++ {0x00, 0x00, 0x20, 0xdd}, ++ {0x5b, 0x00, 0x01, 0xbb}, ++ {0x00, 0x00, 0x20, 0xdd}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x00, 0x00, 0x30, 0xdd}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0x00, 0x00, 0x20, 0xdd}, ++ {0xb6, 0x00, 0x00, 0xcc}, ++ {0xb6, 0x03, 0x05, 0xcc}, ++ {0xb6, 0x02, 0x00, 0xcc}, ++ {0xb6, 0x05, 0x04, 0xcc}, ++ {0xb6, 0x04, 0x00, 0xcc}, ++ {0xb6, 0x12, 0xf8, 0xcc}, ++ {0xb6, 0x13, 0x29, 0xcc}, ++ {0xb6, 0x18, 0x0a, 0xcc}, ++ {0xb6, 0x17, 0x00, 0xcc}, ++ {0xb6, 0x16, 0x00, 0xcc}, ++ {0xb6, 0x22, 0x12, 0xcc}, ++ {0xb6, 0x23, 0x0b, 0xcc}, ++ {0xbf, 0xc0, 0x39, 0xcc}, ++ {0xbf, 0xc1, 0x04, 0xcc}, ++ {0xbf, 0xcc, 0x00, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xb3, 0x01, 0x41, 0xcc}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x05, 0x01, 0x78, 0xbb}, ++ {0x06, 0x00, 0x11, 0xbb}, ++ {0x07, 0x01, 0x42, 0xbb}, ++ {0x08, 0x00, 0x11, 0xbb}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0x21, 0x80, 0x00, 0xbb}, ++ {0x22, 0x0d, 0x0f, 0xbb}, ++ {0x24, 0x80, 0x00, 0xbb}, ++ {0x59, 0x00, 0xff, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x39, 0x03, 0xca, 0xbb}, ++ {0x3a, 0x06, 0x80, 0xbb}, ++ {0x3b, 0x01, 0x52, 0xbb}, ++ {0x3c, 0x05, 0x40, 0xbb}, ++ {0x57, 0x01, 0x9c, 0xbb}, ++ {0x58, 0x01, 0xee, 0xbb}, ++ {0x59, 0x00, 0xf0, 0xbb}, ++ {0x5a, 0x01, 0x20, 0xbb}, ++ {0x5c, 0x1d, 0x17, 0xbb}, ++ {0x5d, 0x22, 0x1c, 0xbb}, ++ {0x64, 0x1e, 0x1c, 0xbb}, ++ {0x5b, 0x00, 0x00, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x22, 0xa0, 0x78, 0xbb}, ++ {0x23, 0xa0, 0x78, 0xbb}, ++ {0x24, 0x7f, 0x00, 0xbb}, ++ {0x28, 0xea, 0x02, 0xbb}, ++ {0x29, 0x86, 0x7a, 0xbb}, ++ {0x5e, 0x52, 0x4c, 0xbb}, ++ {0x5f, 0x20, 0x24, 0xbb}, ++ {0x60, 0x00, 0x02, 0xbb}, ++ {0x02, 0x00, 0xee, 0xbb}, ++ {0x03, 0x39, 0x23, 0xbb}, ++ {0x04, 0x07, 0x24, 0xbb}, ++ {0x09, 0x00, 0xc0, 0xbb}, ++ {0x0a, 0x00, 0x79, 0xbb}, ++ {0x0b, 0x00, 0x04, 0xbb}, ++ {0x0c, 0x00, 0x5c, 0xbb}, ++ {0x0d, 0x00, 0xd9, 0xbb}, ++ {0x0e, 0x00, 0x53, 0xbb}, ++ {0x0f, 0x00, 0x21, 0xbb}, ++ {0x10, 0x00, 0xa4, 0xbb}, ++ {0x11, 0x00, 0xe5, 0xbb}, ++ {0x15, 0x00, 0x00, 0xbb}, ++ {0x16, 0x00, 0x00, 0xbb}, ++ {0x17, 0x00, 0x00, 0xbb}, ++ {0x18, 0x00, 0x00, 0xbb}, ++ {0x19, 0x00, 0x00, 0xbb}, ++ {0x1a, 0x00, 0x00, 0xbb}, ++ {0x1b, 0x00, 0x00, 0xbb}, ++ {0x1c, 0x00, 0x00, 0xbb}, ++ {0x1d, 0x00, 0x00, 0xbb}, ++ {0x1e, 0x00, 0x00, 0xbb}, ++ {0xf0, 0x00, 0x01, 0xbb}, ++ {0x06, 0xe0, 0x0e, 0xbb}, ++ {0x06, 0x60, 0x0e, 0xbb}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xf0, 0x00, 0x00, 0xbb}, ++ {0x05, 0x01, 0x13, 0xbb}, ++ {0x06, 0x00, 0x11, 0xbb}, ++ {0x07, 0x00, 0x85, 0xbb}, ++ {0x08, 0x00, 0x27, 0xbb}, ++ {0x20, 0x01, 0x03, 0xbb}, /* h/v flip */ ++ {0x21, 0x80, 0x00, 0xbb}, ++ {0x22, 0x0d, 0x0f, 0xbb}, ++ {0x24, 0x80, 0x00, 0xbb}, ++ {0x59, 0x00, 0xff, 0xbb}, ++ {0xf0, 0x00, 0x02, 0xbb}, ++ {0x39, 0x03, 0x0d, 0xbb}, ++ {0x3a, 0x06, 0x1b, 0xbb}, ++ {0x3b, 0x00, 0x95, 0xbb}, ++ {0x3c, 0x04, 0xdb, 0xbb}, ++ {0x57, 0x02, 0x00, 0xbb}, ++ {0x58, 0x02, 0x66, 0xbb}, ++ {0x59, 0x00, 0xff, 0xbb}, ++ {0x5a, 0x01, 0x33, 0xbb}, ++ {0x5c, 0x12, 0x0d, 0xbb}, ++ {0x5d, 0x16, 0x11, 0xbb}, ++ {0x64, 0x5e, 0x1c, 0xbb}, ++ {0x2f, 0x90, 0x00, 0xbb}, ++ {} ++}; ++#endif + static const u8 mi1320_soc_InitSXGA[][4] = { + {0xb3, 0x01, 0x01, 0xcc}, + {0xb0, 0x03, 0x19, 0xcc}, +@@ -1359,7 +1859,8 @@ static const u8 po3130_initVGA_data[][4] = { + {0xb3, 0x23, 0xe8, 0xcc}, {0xb8, 0x08, 0xe8, 0xcc}, + {0xb3, 0x14, 0x00, 0xcc}, {0xb3, 0x15, 0x00, 0xcc}, + {0xb3, 0x16, 0x02, 0xcc}, {0xb3, 0x17, 0x7f, 0xcc}, +- {0xb3, 0x34, 0x01, 0xcc}, {0xb3, 0x35, 0xf6, 0xcc}, ++ {0xb3, 0x34, 0x01, 0xcc}, ++ {0xb3, 0x35, 0xf6, 0xcc}, /* i2c add: 76 */ + {0xb3, 0x00, 0x27, 0xcc}, {0xbc, 0x00, 0x71, 0xcc}, + {0xb8, 0x00, 0x21, 0xcc}, {0xb8, 0x27, 0x20, 0xcc}, + {0xb8, 0x01, 0x79, 0xcc}, {0xb8, 0x81, 0x09, 0xcc}, +@@ -1532,8 +2033,13 @@ static const u8 po3130_initQVGA_data[][4] = { + }; + + static const u8 hv7131r_gamma[17] = { ++#if 1 + 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, + 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff ++#else ++ 0x04, 0x1a, 0x36, 0x55, 0x6f, 0x87, 0x9d, 0xb0, 0xc1, ++ 0xcf, 0xda, 0xe4, 0xec, 0xf3, 0xf8, 0xfd, 0xff ++#endif + }; + static const u8 hv7131r_matrix[9] = { + 0x5f, 0xec, 0xf5, 0xf1, 0x5a, 0xf5, 0xf1, 0xec, 0x63 +@@ -1561,7 +2067,7 @@ static const u8 hv7131r_initVGA_data[][4] = { + {0xb3, 0x16, 0x02, 0xcc}, + {0xb3, 0x17, 0x7f, 0xcc}, + {0xb3, 0x34, 0x01, 0xcc}, +- {0xb3, 0x35, 0x91, 0xcc}, ++ {0xb3, 0x35, 0x91, 0xcc}, /* i2c add: 11 */ + {0xb3, 0x00, 0x27, 0xcc}, + {0xbc, 0x00, 0x73, 0xcc}, + {0xb8, 0x00, 0x23, 0xcc}, +@@ -1747,7 +2253,8 @@ static const u8 ov7660_initVGA_data[][4] = { + {0xb3, 0x23, 0xe0, 0xcc}, {0xb3, 0x1d, 0x01, 0xcc}, + {0xb3, 0x1f, 0x02, 0xcc}, + {0xb3, 0x34, 0x01, 0xcc}, +- {0xb3, 0x35, 0xa1, 0xcc}, {0xb3, 0x00, 0x26, 0xcc}, ++ {0xb3, 0x35, 0xa1, 0xcc}, /* i2c add: 21 */ ++ {0xb3, 0x00, 0x26, 0xcc}, + {0xb8, 0x00, 0x33, 0xcc}, /* 13 */ + {0xb8, 0x01, 0x7d, 0xcc}, + {0xbc, 0x00, 0x73, 0xcc}, {0xb8, 0x81, 0x09, 0xcc}, +@@ -1883,7 +2390,8 @@ static const u8 ov7670_initVGA_JPG[][4] = { + {0x00, 0x00, 0x10, 0xdd}, + {0xb0, 0x04, 0x02, 0xcc}, {0x00, 0x00, 0x10, 0xdd}, + {0xb3, 0x00, 0x66, 0xcc}, {0xb3, 0x00, 0x67, 0xcc}, +- {0xb3, 0x35, 0xa1, 0xcc}, {0xb3, 0x34, 0x01, 0xcc}, ++ {0xb3, 0x35, 0xa1, 0xcc}, /* i2c add: 21 */ ++ {0xb3, 0x34, 0x01, 0xcc}, + {0xb3, 0x05, 0x01, 0xcc}, {0xb3, 0x06, 0x01, 0xcc}, + {0xb3, 0x08, 0x01, 0xcc}, {0xb3, 0x09, 0x0c, 0xcc}, + {0xb3, 0x02, 0x02, 0xcc}, {0xb3, 0x03, 0x1f, 0xcc}, +@@ -2143,14 +2651,26 @@ static const u8 ov7670_initQVGA_JPG[][4] = { + + /* PO1200 - values from usbvm326.inf and ms-win trace */ + static const u8 po1200_gamma[17] = { ++#if 1 + 0x00, 0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, + 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff ++#else ++/*ms-win trace*/ ++ 0x01, 0x0b, 0x1e, 0x38, 0x51, 0x6b, 0x83, 0x9a, 0xaf, ++ 0xc1, 0xd0, 0xdd, 0xe8, 0xf2, 0xf9, 0xff, 0xff ++#endif + }; + static const u8 po1200_matrix[9] = { + 0x60, 0xf9, 0xe5, 0xe7, 0x50, 0x05, 0xf3, 0xe6, 0x5e + }; + static const u8 po1200_initVGA_data[][4] = { + {0xb0, 0x03, 0x19, 0xcc}, /* reset? */ ++#if 0 ++ {0x00, 0x00, 0x64, 0xdd}, ++ {0xb3, 0x49, 0x11, 0xcc}, ++ {0x00, 0x00, 0x33, 0xdd}, ++/*read b349*/ ++#endif + {0xb0, 0x03, 0x19, 0xcc}, + /* {0x00, 0x00, 0x33, 0xdd}, */ + {0xb0, 0x04, 0x02, 0xcc}, +@@ -2181,7 +2701,7 @@ static const u8 po1200_initVGA_data[][4] = { + {0xb0, 0x54, 0x13, 0xcc}, + {0xb3, 0x00, 0x67, 0xcc}, + {0xb3, 0x34, 0x01, 0xcc}, +- {0xb3, 0x35, 0xdc, 0xcc}, ++ {0xb3, 0x35, 0xdc, 0xcc}, /* i2c add: 5c */ + {0x00, 0x03, 0x00, 0xaa}, + {0x00, 0x12, 0x05, 0xaa}, + {0x00, 0x13, 0x02, 0xaa}, +@@ -2346,7 +2866,12 @@ static const u8 po1200_initVGA_data[][4] = { + {0x00, 0xe2, 0x01, 0xaa}, + {0x00, 0xd6, 0x40, 0xaa}, + {0x00, 0xe4, 0x40, 0xaa}, ++#if 1 + {0x00, 0xa8, 0x8f, 0xaa}, ++#else ++/*modified later*/ ++ {0x00, 0xa8, 0x9f, 0xaa}, ++#endif + {0x00, 0xb4, 0x16, 0xaa}, + {0xb0, 0x02, 0x06, 0xcc}, + {0xb0, 0x18, 0x06, 0xcc}, +@@ -2383,6 +2908,10 @@ static const u8 po1200_initVGA_data[][4] = { + {0x00, 0x03, 0x00, 0xaa}, + {0x00, 0x95, 0x85, 0xaa}, + /*matrix*/ ++#if 0 ++ {0x00, 0x03, 0x00, 0xaa}, ++ {0x00, 0x61, 0xb8, 0xaa}, /* sharpness */ ++#endif + {0x00, 0x03, 0x00, 0xaa}, + {0x00, 0x4d, 0x20, 0xaa}, + {0xb8, 0x22, 0x40, 0xcc}, +@@ -2402,12 +2931,270 @@ static const u8 po1200_initVGA_data[][4] = { + {0x00, 0x46, 0x3c, 0xaa}, + {0x00, 0x00, 0x18, 0xdd}, + /*read bfff*/ ++#if 0 ++ {0x00, 0x03, 0x00, 0xaa}, ++ {0x00, 0x1e, 0x46, 0xaa}, /* h/v flip */ ++ {0x00, 0xa8, 0x8f, 0xaa}, ++#endif + {0x00, 0x03, 0x00, 0xaa}, + {0x00, 0xb4, 0x1c, 0xaa}, + {0x00, 0xb5, 0x92, 0xaa}, + {0x00, 0xb6, 0x39, 0xaa}, + {0x00, 0xb7, 0x24, 0xaa}, + /*write 89 0400 1415*/ ++ {} ++}; ++ ++static const u8 poxxxx_init_common[][4] = { ++ {0xb3, 0x00, 0x04, 0xcc}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xb3, 0x00, 0x64, 0xcc}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xb3, 0x00, 0x65, 0xcc}, ++ {0x00, 0x00, 0x10, 0xdd}, ++ {0xb3, 0x00, 0x67, 0xcc}, ++ {0xb0, 0x03, 0x09, 0xcc}, ++ {0xb3, 0x05, 0x00, 0xcc}, ++ {0xb3, 0x06, 0x00, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0xb3, 0x08, 0x01, 0xcc}, ++ {0xb3, 0x09, 0x0c, 0xcc}, ++ {0xb3, 0x34, 0x01, 0xcc}, ++ {0xb3, 0x35, 0xf6, 0xcc}, /* i2c add: 76 */ ++ {0xb3, 0x02, 0xb0, 0xcc}, ++ {0xb3, 0x03, 0x18, 0xcc}, ++ {0xb3, 0x04, 0x15, 0xcc}, ++ {0xb3, 0x20, 0x00, 0xcc}, ++ {0xb3, 0x21, 0x00, 0xcc}, ++ {0xb3, 0x22, 0x04, 0xcc}, ++ {0xb3, 0x23, 0x00, 0xcc}, ++ {0xb3, 0x14, 0x00, 0xcc}, ++ {0xb3, 0x15, 0x00, 0xcc}, ++ {0xb3, 0x16, 0x04, 0xcc}, ++ {0xb3, 0x17, 0xff, 0xcc}, ++ {0xb3, 0x2c, 0x03, 0xcc}, ++ {0xb3, 0x2d, 0x56, 0xcc}, ++ {0xb3, 0x2e, 0x02, 0xcc}, ++ {0xb3, 0x2f, 0x0a, 0xcc}, ++ {0xb3, 0x40, 0x00, 0xcc}, ++ {0xb3, 0x41, 0x34, 0xcc}, ++ {0xb3, 0x42, 0x01, 0xcc}, ++ {0xb3, 0x43, 0xe0, 0xcc}, ++ {0xbc, 0x00, 0x71, 0xcc}, ++ {0xbc, 0x01, 0x01, 0xcc}, ++ {0xb3, 0x01, 0x41, 0xcc}, ++ {0xb3, 0x4d, 0x00, 0xcc}, ++ {0x00, 0x0b, 0x2a, 0xaa}, ++ {0x00, 0x0e, 0x03, 0xaa}, ++ {0x00, 0x0f, 0xea, 0xaa}, ++ {0x00, 0x12, 0x08, 0xaa}, ++ {0x00, 0x1e, 0x06, 0xaa}, ++ {0x00, 0x21, 0x00, 0xaa}, ++ {0x00, 0x31, 0x1f, 0xaa}, ++ {0x00, 0x33, 0x38, 0xaa}, ++ {0x00, 0x36, 0xc0, 0xaa}, ++ {0x00, 0x37, 0xc8, 0xaa}, ++ {0x00, 0x3b, 0x36, 0xaa}, ++ {0x00, 0x4b, 0xfe, 0xaa}, ++ {0x00, 0x4d, 0x2e, 0xaa}, ++ {0x00, 0x51, 0x1c, 0xaa}, ++ {0x00, 0x52, 0x01, 0xaa}, ++ {0x00, 0x55, 0x0a, 0xaa}, ++ {0x00, 0x56, 0x0a, 0xaa}, ++ {0x00, 0x57, 0x07, 0xaa}, ++ {0x00, 0x58, 0x07, 0xaa}, ++ {0x00, 0x59, 0x04, 0xaa}, ++ {0x00, 0x70, 0x68, 0xaa}, ++ {0x00, 0x71, 0x04, 0xaa}, ++ {0x00, 0x72, 0x10, 0xaa}, ++ {0x00, 0x80, 0x71, 0xaa}, ++ {0x00, 0x81, 0x08, 0xaa}, ++ {0x00, 0x82, 0x00, 0xaa}, ++ {0x00, 0x83, 0x55, 0xaa}, ++ {0x00, 0x84, 0x06, 0xaa}, ++ {0x00, 0x85, 0x06, 0xaa}, ++ {0x00, 0x8b, 0x25, 0xaa}, ++ {0x00, 0x8c, 0x00, 0xaa}, ++ {0x00, 0x8d, 0x86, 0xaa}, ++ {0x00, 0x8e, 0x82, 0xaa}, ++ {0x00, 0x8f, 0x2d, 0xaa}, ++ {0x00, 0x90, 0x8b, 0xaa}, ++ {0x00, 0x91, 0x81, 0xaa}, ++ {0x00, 0x92, 0x81, 0xaa}, ++ {0x00, 0x93, 0x23, 0xaa}, ++ {0x00, 0xa3, 0x2a, 0xaa}, ++ {0x00, 0xa4, 0x03, 0xaa}, ++ {0x00, 0xa5, 0xea, 0xaa}, ++ {0x00, 0xb0, 0x68, 0xaa}, ++ {0x00, 0xbc, 0x04, 0xaa}, ++ {0x00, 0xbe, 0x3b, 0xaa}, ++ {0x00, 0x4e, 0x40, 0xaa}, ++ {0x00, 0x06, 0x04, 0xaa}, ++ {0x00, 0x07, 0x03, 0xaa}, ++ {0x00, 0xcd, 0x18, 0xaa}, ++ {0x00, 0x28, 0x03, 0xaa}, ++ {0x00, 0x29, 0xef, 0xaa}, ++/* reinit on alt 2 (qvga) or alt7 (vga) */ ++ {0xb3, 0x05, 0x00, 0xcc}, ++ {0xb3, 0x06, 0x00, 0xcc}, ++ {0xb8, 0x00, 0x01, 0xcc}, ++ ++ {0x00, 0x1d, 0x85, 0xaa}, ++ {0x00, 0x1e, 0xc6, 0xaa}, ++ {0x00, 0x00, 0x40, 0xdd}, ++ {0x00, 0x1d, 0x05, 0xaa}, ++ ++ {0x00, 0xd6, 0x22, 0xaa}, /* gamma 0 */ ++ {0x00, 0x73, 0x00, 0xaa}, ++ {0x00, 0x74, 0x0a, 0xaa}, ++ {0x00, 0x75, 0x16, 0xaa}, ++ {0x00, 0x76, 0x25, 0xaa}, ++ {0x00, 0x77, 0x34, 0xaa}, ++ {0x00, 0x78, 0x49, 0xaa}, ++ {0x00, 0x79, 0x5a, 0xaa}, ++ {0x00, 0x7a, 0x7f, 0xaa}, ++ {0x00, 0x7b, 0x9b, 0xaa}, ++ {0x00, 0x7c, 0xba, 0xaa}, ++ {0x00, 0x7d, 0xd4, 0xaa}, ++ {0x00, 0x7e, 0xea, 0xaa}, ++ ++ {0x00, 0xd6, 0x62, 0xaa}, /* gamma 1 */ ++ {0x00, 0x73, 0x00, 0xaa}, ++ {0x00, 0x74, 0x0a, 0xaa}, ++ {0x00, 0x75, 0x16, 0xaa}, ++ {0x00, 0x76, 0x25, 0xaa}, ++ {0x00, 0x77, 0x34, 0xaa}, ++ {0x00, 0x78, 0x49, 0xaa}, ++ {0x00, 0x79, 0x5a, 0xaa}, ++ {0x00, 0x7a, 0x7f, 0xaa}, ++ {0x00, 0x7b, 0x9b, 0xaa}, ++ {0x00, 0x7c, 0xba, 0xaa}, ++ {0x00, 0x7d, 0xd4, 0xaa}, ++ {0x00, 0x7e, 0xea, 0xaa}, ++ ++ {0x00, 0xd6, 0xa2, 0xaa}, /* gamma 2 */ ++ {0x00, 0x73, 0x00, 0xaa}, ++ {0x00, 0x74, 0x0a, 0xaa}, ++ {0x00, 0x75, 0x16, 0xaa}, ++ {0x00, 0x76, 0x25, 0xaa}, ++ {0x00, 0x77, 0x34, 0xaa}, ++ {0x00, 0x78, 0x49, 0xaa}, ++ {0x00, 0x79, 0x5a, 0xaa}, ++ {0x00, 0x7a, 0x7f, 0xaa}, ++ {0x00, 0x7b, 0x9b, 0xaa}, ++ {0x00, 0x7c, 0xba, 0xaa}, ++ {0x00, 0x7d, 0xd4, 0xaa}, ++ {0x00, 0x7e, 0xea, 0xaa}, ++ ++ {0x00, 0xaa, 0xff, 0xaa}, /* back light comp */ ++ {0x00, 0xc4, 0x03, 0xaa}, ++ {0x00, 0xc5, 0x19, 0xaa}, ++ {0x00, 0xc6, 0x03, 0xaa}, ++ {0x00, 0xc7, 0x91, 0xaa}, ++ {0x00, 0xc8, 0x01, 0xaa}, ++ {0x00, 0xc9, 0xdd, 0xaa}, ++ {0x00, 0xca, 0x02, 0xaa}, ++ {0x00, 0xcb, 0x37, 0xaa}, ++ ++/* read d1 */ ++ {0x00, 0xd1, 0x3c, 0xaa}, ++ {0x00, 0xb8, 0x28, 0xaa}, ++ {0x00, 0xb9, 0x1e, 0xaa}, ++ {0x00, 0xb6, 0x14, 0xaa}, ++ {0x00, 0xb7, 0x0f, 0xaa}, ++ {0x00, 0x5c, 0x10, 0xaa}, ++ {0x00, 0x5d, 0x18, 0xaa}, ++ {0x00, 0x5e, 0x24, 0xaa}, ++ {0x00, 0x5f, 0x24, 0xaa}, ++ {0x00, 0x86, 0x1a, 0xaa}, ++ {0x00, 0x60, 0x00, 0xaa}, ++ {0x00, 0x61, 0x1b, 0xaa}, ++ {0x00, 0x62, 0x30, 0xaa}, ++ {0x00, 0x63, 0x40, 0xaa}, ++ {0x00, 0x87, 0x1a, 0xaa}, ++ {0x00, 0x64, 0x00, 0xaa}, ++ {0x00, 0x65, 0x08, 0xaa}, ++ {0x00, 0x66, 0x10, 0xaa}, ++ {0x00, 0x67, 0x20, 0xaa}, ++ {0x00, 0x88, 0x10, 0xaa}, ++ {0x00, 0x68, 0x00, 0xaa}, ++ {0x00, 0x69, 0x08, 0xaa}, ++ {0x00, 0x6a, 0x0f, 0xaa}, ++ {0x00, 0x6b, 0x0f, 0xaa}, ++ {0x00, 0x89, 0x07, 0xaa}, ++ {0x00, 0xd5, 0x4c, 0xaa}, ++ {0x00, 0x0a, 0x00, 0xaa}, ++ {0x00, 0x0b, 0x2a, 0xaa}, ++ {0x00, 0x0e, 0x03, 0xaa}, ++ {0x00, 0x0f, 0xea, 0xaa}, ++ {0x00, 0xa2, 0x00, 0xaa}, ++ {0x00, 0xa3, 0x2a, 0xaa}, ++ {0x00, 0xa4, 0x03, 0xaa}, ++ {0x00, 0xa5, 0xea, 0xaa}, ++ {} ++}; ++static const u8 poxxxx_initVGA[][4] = { ++ {0x00, 0x20, 0x11, 0xaa}, ++ {0x00, 0x33, 0x38, 0xaa}, ++ {0x00, 0xbb, 0x0d, 0xaa}, ++ {0xb3, 0x22, 0x01, 0xcc}, ++ {0xb3, 0x23, 0xe0, 0xcc}, ++ {0xb3, 0x16, 0x02, 0xcc}, ++ {0xb3, 0x17, 0x7f, 0xcc}, ++ {0xb3, 0x02, 0xb0, 0xcc}, ++ {0xb3, 0x06, 0x00, 0xcc}, ++ {0xb3, 0x5c, 0x01, 0xcc}, ++ {0x00, 0x04, 0x06, 0xaa}, ++ {0x00, 0x05, 0x3f, 0xaa}, ++ {0x00, 0x04, 0x00, 0xdd}, /* delay 1s */ ++ {} ++}; ++static const u8 poxxxx_initQVGA[][4] = { ++ {0x00, 0x20, 0x33, 0xaa}, ++ {0x00, 0x33, 0x38, 0xaa}, ++ {0x00, 0xbb, 0x0d, 0xaa}, ++ {0xb3, 0x22, 0x00, 0xcc}, ++ {0xb3, 0x23, 0xf0, 0xcc}, ++ {0xb3, 0x16, 0x01, 0xcc}, ++ {0xb3, 0x17, 0x3f, 0xcc}, ++ {0xb3, 0x02, 0xb0, 0xcc}, ++ {0xb3, 0x06, 0x01, 0xcc}, ++ {0xb3, 0x5c, 0x00, 0xcc}, ++ {0x00, 0x04, 0x06, 0xaa}, ++ {0x00, 0x05, 0x3f, 0xaa}, ++ {0x00, 0x04, 0x00, 0xdd}, /* delay 1s */ ++ {} ++}; ++static const u8 poxxxx_init_end_1[][4] = { ++ {0x00, 0x47, 0x25, 0xaa}, ++ {0x00, 0x48, 0x80, 0xaa}, ++ {0x00, 0x49, 0x1f, 0xaa}, ++ {0x00, 0x4a, 0x40, 0xaa}, ++ {0x00, 0x44, 0x40, 0xaa}, ++ {0x00, 0xab, 0x4a, 0xaa}, ++ {0x00, 0xb1, 0x00, 0xaa}, ++ {0x00, 0xb2, 0x04, 0xaa}, ++ {0x00, 0xb3, 0x08, 0xaa}, ++ {0x00, 0xb4, 0x0b, 0xaa}, ++ {0x00, 0xb5, 0x0d, 0xaa}, ++ {0x00, 0x59, 0x7e, 0xaa}, /* sharpness */ ++ {0x00, 0x16, 0x00, 0xaa}, /* white balance */ ++ {0x00, 0x18, 0x00, 0xaa}, ++#if 0 ++/* read d1 */ ++ {0x00, 0xd1, 0x3c, 0xaa}, ++ {0x00, 0x94, 0x46, 0xaa}, /* colors */ ++ {0x00, 0x95, 0x51, 0xaa}, ++ {0x00, 0x98, 0x88, 0xaa}, /* contrast */ ++ {0x00, 0x99, 0x93, 0xaa}, /* brightness */ ++#endif ++ {} ++}; ++static const u8 poxxxx_init_end_2[][4] = { ++ {0x00, 0x1d, 0x85, 0xaa}, ++ {0x00, 0x1e, 0x06, 0xaa}, ++ {0x00, 0x1d, 0x05, 0xaa}, ++ {} + }; + + struct sensor_info { +@@ -2420,33 +3207,89 @@ struct sensor_info { + u8 op; + }; + +-static const struct sensor_info sensor_info_data[] = { +-/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */ ++/* probe values */ ++static const struct sensor_info vc0321_probe_data[] = { ++/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */ ++/* 0 OV9640 */ + {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, ++/* 1 ICM108T (may respond on IdAdd == 0x83 - tested in vc032x_probe_sensor) */ + {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01}, +-/* (tested in vc032x_probe_sensor) */ +-/* {-1, 0x80 | 0x20, 0x83, 0x0000, 0x24, 0x25, 0x01}, */ +- {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, ++/* 2 PO2130 (may detect PO3130NC - tested in vc032x_probe_sensor)*/ ++ {-1, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* 3 MI1310 */ ++ {-1, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* 4 MI360 - tested in vc032x_probe_sensor */ ++/* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */ ++/* 5 7131R */ ++ {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01}, ++/* 6 OV7649 */ ++ {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05}, ++/* 7 PAS302BCW */ ++ {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05}, ++/* 8 OV7660 */ ++ {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05}, ++/* 9 PO3130NC - (tested in vc032x_probe_sensor) */ ++/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, */ ++/* 10 PO1030KC */ ++ {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* 11 MI1310_SOC */ + {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, +-/* (tested in vc032x_probe_sensor) */ ++/* 12 OV9650 */ ++ {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, ++/* 13 S5K532 */ ++ {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01}, ++/* 14 MI360_SOC - ??? */ ++/* 15 PO1200N */ ++ {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01}, ++/* 16 PO3030K */ ++ {-1, 0x80 | 0x18, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* 17 PO2030 */ ++ {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* ?? */ ++ {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01}, ++ {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01}, ++}; ++static const struct sensor_info vc0323_probe_data[] = { ++/* sensorId, I2cAdd, IdAdd, VpId, m1, m2, op */ ++/* 0 OV9640 */ ++ {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, ++/* 1 ICM108T (may respond on IdAdd == 0x83 - tested in vc032x_probe_sensor) */ ++ {-1, 0x80 | 0x20, 0x82, 0x0000, 0x24, 0x25, 0x01}, ++/* 2 PO2130 (may detect PO3130NC - tested in vc032x_probe_sensor)*/ ++ {-1, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* 3 MI1310 */ ++ {-1, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* 4 MI360 - tested in vc032x_probe_sensor */ + /* {SENSOR_MI0360, 0x80 | 0x5d, 0x00, 0x8243, 0x24, 0x25, 0x01}, */ ++/* 5 7131R */ + {SENSOR_HV7131R, 0x80 | 0x11, 0x00, 0x0209, 0x24, 0x25, 0x01}, ++/* 6 OV7649 */ + {-1, 0x80 | 0x21, 0x0a, 0x0000, 0x21, 0x20, 0x05}, ++/* 7 PAS302BCW */ + {-1, 0x80 | 0x40, 0x00, 0x0000, 0x20, 0x22, 0x05}, ++/* 8 OV7660 */ + {SENSOR_OV7660, 0x80 | 0x21, 0x0a, 0x7660, 0x26, 0x26, 0x05}, +-/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x0000, 0x24, 0x25, 0x01}, */ ++/* 9 PO3130NC - (tested in vc032x_probe_sensor) */ ++/* {SENSOR_PO3130NC, 0x80 | 0x76, 0x00, 0x3130, 0x24, 0x25, 0x01}, */ ++/* 10 PO1030KC */ + {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, +-/* {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x0000, 0x24, 0x25, 0x01}, */ +-/* {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, */ ++/* 11 MI1310_SOC */ ++ {SENSOR_MI1310_SOC, 0x80 | 0x5d, 0x00, 0x143a, 0x24, 0x25, 0x01}, ++/* 12 OV9650 */ ++ {-1, 0x80 | 0x30, 0x0a, 0x0000, 0x25, 0x24, 0x05}, ++/* 13 S5K532 */ + {-1, 0x80 | 0x11, 0x39, 0x0000, 0x24, 0x25, 0x01}, ++/* 14 MI360_SOC - ??? */ ++/* 15 PO1200N */ + {SENSOR_PO1200, 0x80 | 0x5c, 0x00, 0x1200, 0x67, 0x67, 0x01}, ++/* 16 ?? */ + {-1, 0x80 | 0x2d, 0x00, 0x0000, 0x65, 0x67, 0x01}, ++/* 17 PO2030 */ + {-1, 0x80 | 0x6e, 0x00, 0x0000, 0x24, 0x25, 0x01}, ++/* ?? */ + {-1, 0x80 | 0x56, 0x01, 0x0000, 0x64, 0x67, 0x01}, + {SENSOR_MI1320_SOC, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x67, 0x01}, +-/*fixme: previously detected?*/ +- {SENSOR_MI1320, 0x80 | 0x48, 0x00, 0x148c, 0x64, 0x65, 0x01}, +-/*fixme: not in the ms-win probe - may be found before?*/ ++/*fixme: not in the ms-win probe - may be found before? */ + {SENSOR_OV7670, 0x80 | 0x21, 0x0a, 0x7673, 0x66, 0x67, 0x05}, + }; + +@@ -2520,20 +3363,31 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + struct usb_device *dev = gspca_dev->dev; +- int i; ++ int i, n; + u16 value; + const struct sensor_info *ptsensor_info; + + /*fixme: should also check the other sensor (back mi1320_soc, front mc501cb)*/ + if (sd->flags & FL_SAMSUNG) { + reg_w(dev, 0xa0, 0x01, 0xb301); ++#if 1 + reg_w(dev, 0x89, 0xf0ff, 0xffff); /* select the back sensor */ ++#else ++ reg_w(dev, 0x89, 0xf3ff, 0xffff); /* select the front sensor */ ++#endif + } + + reg_r(gspca_dev, 0xa1, 0xbfcf, 1); +- PDEBUG(D_PROBE, "check sensor header %02x", gspca_dev->usb_buf[0]); +- for (i = 0; i < ARRAY_SIZE(sensor_info_data); i++) { +- ptsensor_info = &sensor_info_data[i]; ++ PDEBUG(D_PROBE, "vc032%d check sensor header %02x", ++ sd->bridge == BRIDGE_VC0321 ? 1 : 3, gspca_dev->usb_buf[0]); ++ if (sd->bridge == BRIDGE_VC0321) { ++ ptsensor_info = vc0321_probe_data; ++ n = ARRAY_SIZE(vc0321_probe_data); ++ } else { ++ ptsensor_info = vc0323_probe_data; ++ n = ARRAY_SIZE(vc0323_probe_data); ++ } ++ for (i = 0; i < n; i++) { + reg_w(dev, 0xa0, 0x02, 0xb334); + reg_w(dev, 0xa0, ptsensor_info->m1, 0xb300); + reg_w(dev, 0xa0, ptsensor_info->m2, 0xb300); +@@ -2551,13 +3405,15 @@ static int vc032x_probe_sensor(struct gspca_dev *gspca_dev) + return ptsensor_info->sensorId; + + switch (value) { ++ case 0x3130: ++ return SENSOR_PO3130NC; + case 0x7673: + return SENSOR_OV7670; + case 0x8243: + return SENSOR_MI0360; + } +-/*fixme: should return here*/ + } ++ ptsensor_info++; + } + return -1; + } +@@ -2619,7 +3475,7 @@ static void usb_exchange(struct gspca_dev *gspca_dev, + i2c_write(gspca_dev, data[i][0], &data[i][1], 2); + break; + case 0xdd: +- msleep(data[i][2] + 10); ++ msleep(data[i][1] * 256 + data[i][2] + 10); + break; + } + i++; +@@ -2627,6 +3483,16 @@ static void usb_exchange(struct gspca_dev *gspca_dev, + /*not reached*/ + } + ++#if 0 ++static void vc0321_reset(struct gspca_dev *gspca_dev) ++{ ++ reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb04d); ++ reg_w(gspca_dev->dev, 0xa0, 0x01, 0xb301); ++ msleep(100); ++ reg_w(gspca_dev->dev, 0xa0, 0x01, 0xb003); ++ msleep(100); ++} ++#endif + + /* this function is called at probe time */ + static int sd_config(struct gspca_dev *gspca_dev, +@@ -2646,12 +3512,20 @@ static int sd_config(struct gspca_dev *gspca_dev, + 64, /* OV7670 6 */ + 128, /* PO1200 7 */ + 128, /* PO3130NC 8 */ ++ 128, /* POxxxx 9 */ + }; + + cam = &gspca_dev->cam; + sd->bridge = id->driver_info >> 8; + sd->flags = id->driver_info & 0xff; +- sensor = vc032x_probe_sensor(gspca_dev); ++#if 0 ++ vc0321_reset(gspca_dev); ++#endif ++ if (id->idVendor == 0x046d && ++ (id->idProduct == 0x0892 || id->idProduct == 0x0896)) ++ sensor = SENSOR_POxxxx; ++ else ++ sensor = vc032x_probe_sensor(gspca_dev); + switch (sensor) { + case -1: + PDEBUG(D_PROBE, "Unknown sensor..."); +@@ -2684,6 +3558,9 @@ static int sd_config(struct gspca_dev *gspca_dev, + case SENSOR_PO3130NC: + PDEBUG(D_PROBE, "Find Sensor PO3130NC"); + break; ++ case SENSOR_POxxxx: ++ PDEBUG(D_PROBE, "Sensor POxxxx"); ++ break; + } + sd->sensor = sensor; + +@@ -2712,28 +3589,19 @@ static int sd_config(struct gspca_dev *gspca_dev, + } + cam->npkt = npkt[sd->sensor]; + ++ sd->brightness = BRIGHTNESS_DEF; ++ sd->contrast = CONTRAST_DEF; ++ sd->colors = COLOR_DEF; + sd->hflip = HFLIP_DEF; + sd->vflip = VFLIP_DEF; +- if (sd->sensor == SENSOR_OV7670) +- sd->flags |= FL_HFLIP | FL_VFLIP; + sd->lightfreq = FREQ_DEF; +- if (sd->sensor != SENSOR_OV7670) +- gspca_dev->ctrl_dis = (1 << LIGHTFREQ_IDX); +- switch (sd->sensor) { +- case SENSOR_MI1310_SOC: +- case SENSOR_MI1320_SOC: +- case SENSOR_OV7660: +- case SENSOR_OV7670: +- case SENSOR_PO1200: +- break; +- default: +- gspca_dev->ctrl_dis = (1 << HFLIP_IDX) +- | (1 << VFLIP_IDX); +- break; +- } +- + sd->sharpness = SHARPNESS_DEF; + ++ gspca_dev->ctrl_dis = ctrl_dis[sd->sensor]; ++ ++ if (sd->sensor == SENSOR_OV7670) ++ sd->flags |= FL_HFLIP | FL_VFLIP; ++ + if (sd->bridge == BRIDGE_VC0321) { + reg_r(gspca_dev, 0x8a, 0, 3); + reg_w(dev, 0x87, 0x00, 0x0f0f); +@@ -2747,10 +3615,55 @@ static int sd_config(struct gspca_dev *gspca_dev, + /* this function is called at probe and resume time */ + static int sd_init(struct gspca_dev *gspca_dev) + { ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (sd->sensor == SENSOR_POxxxx) { ++ reg_r(gspca_dev, 0xa1, 0xb300, 1); ++ if (gspca_dev->usb_buf[0] != 0) { ++ reg_w(gspca_dev->dev, 0xa0, 0x26, 0xb300); ++ reg_w(gspca_dev->dev, 0xa0, 0x04, 0xb300); ++ reg_w(gspca_dev->dev, 0xa0, 0x00, 0xb300); ++ } ++ } + return 0; + } + +-/* some sensors only */ ++static void setbrightness(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 data; ++ ++ if (gspca_dev->ctrl_dis & (1 << BRIGHTNESS_IDX)) ++ return; ++ data = sd->brightness; ++ if (data >= 0x80) ++ data &= 0x7f; ++ else ++ data = 0xff ^ data; ++ i2c_write(gspca_dev, 0x98, &data, 1); ++} ++ ++static void setcontrast(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ if (gspca_dev->ctrl_dis & (1 << CONTRAST_IDX)) ++ return; ++ i2c_write(gspca_dev, 0x99, &sd->contrast, 1); ++} ++ ++static void setcolors(struct gspca_dev *gspca_dev) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ u8 data; ++ ++ if (gspca_dev->ctrl_dis & (1 << COLORS_IDX)) ++ return; ++ data = sd->colors - (sd->colors >> 3) - 1; ++ i2c_write(gspca_dev, 0x94, &data, 1); ++ i2c_write(gspca_dev, 0x95, &sd->colors, 1); ++} ++ + static void sethvflip(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +@@ -2764,6 +3677,7 @@ static void sethvflip(struct gspca_dev *gspca_dev) + vflip = !vflip; + switch (sd->sensor) { + case SENSOR_MI1310_SOC: ++ case SENSOR_MI1320: + case SENSOR_MI1320_SOC: + data[0] = data[1] = 0; /* select page 0 */ + i2c_write(gspca_dev, 0xf0, data, 2); +@@ -2801,18 +3715,29 @@ static void setlightfreq(struct gspca_dev *gspca_dev) + usb_exchange(gspca_dev, ov7660_freq_tb[sd->lightfreq]); + } + +-/* po1200 only */ + static void setsharpness(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + u8 data; + +- if (sd->sensor != SENSOR_PO1200) +- return; +- data = 0; +- i2c_write(gspca_dev, 0x03, &data, 1); +- data = 0xb5 + sd->sharpness * 3; +- i2c_write(gspca_dev, 0x61, &data, 1); ++ switch (sd->sensor) { ++ case SENSOR_PO1200: ++ data = 0; ++ i2c_write(gspca_dev, 0x03, &data, 1); ++ if (sd->sharpness < 0) ++ data = 0x6a; ++ else ++ data = 0xb5 + sd->sharpness * 3; ++ i2c_write(gspca_dev, 0x61, &data, 1); ++ break; ++ case SENSOR_POxxxx: ++ if (sd->sharpness < 0) ++ data = 0x7e; /* def = max */ ++ else ++ data = 0x60 + sd->sharpness * 0x0f; ++ i2c_write(gspca_dev, 0x59, &data, 1); ++ break; ++ } + } + + static int sd_start(struct gspca_dev *gspca_dev) +@@ -2826,6 +3751,11 @@ static int sd_start(struct gspca_dev *gspca_dev) + mi1320_soc_InitSXGA, + mi1320_soc_InitVGA, + mi1320_soc_InitQVGA, ++#if 0 /* JPEG vc0323 */ ++ mi1320_soc_InitSXGA_JPG, ++ mi1320_soc_InitVGA_JPG, ++ mi1320_soc_InitQVGA_JPG ++#endif + }; + + /*fixme: back sensor only*/ +@@ -2922,12 +3852,27 @@ static int sd_start(struct gspca_dev *gspca_dev) + usb_exchange(gspca_dev, init); + init = po3130_rundata; + break; +- default: +-/* case SENSOR_PO1200: */ ++ case SENSOR_PO1200: + GammaT = po1200_gamma; + MatrixT = po1200_matrix; + init = po1200_initVGA_data; + break; ++ default: ++/* case SENSOR_POxxxx: */ ++ usb_exchange(gspca_dev, poxxxx_init_common); ++ if (mode) ++ init = poxxxx_initQVGA; ++ else ++ init = poxxxx_initVGA; ++ usb_exchange(gspca_dev, init); ++ reg_r(gspca_dev, 0x8c, 0x0000, 3); ++ reg_w(gspca_dev->dev, 0xa0, ++ gspca_dev->usb_buf[2] & 1 ? 0 : 1, ++ 0xb35c); ++ msleep(300); ++/*fixme: i2c read 04 and 05*/ ++ init = poxxxx_init_end_1; ++ break; + } + usb_exchange(gspca_dev, init); + if (GammaT && MatrixT) { +@@ -2936,7 +3881,6 @@ static int sd_start(struct gspca_dev *gspca_dev) + put_tab_to_reg(gspca_dev, GammaT, 17, 0xb86c); + put_tab_to_reg(gspca_dev, MatrixT, 9, 0xb82c); + +- /* set the led on 0x0892 0x0896 */ + switch (sd->sensor) { + case SENSOR_PO1200: + case SENSOR_HV7131R: +@@ -2945,16 +3889,22 @@ static int sd_start(struct gspca_dev *gspca_dev) + case SENSOR_MI1310_SOC: + reg_w(gspca_dev->dev, 0x89, 0x058c, 0x0000); + break; +- default: +- if (!(sd->flags & FL_SAMSUNG)) +- reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); +- break; + } + msleep(100); + setsharpness(gspca_dev); + sethvflip(gspca_dev); + setlightfreq(gspca_dev); + } ++ if (sd->sensor == SENSOR_POxxxx) { ++ setcolors(gspca_dev); ++ setbrightness(gspca_dev); ++ setcontrast(gspca_dev); ++ ++ /* led on */ ++ msleep(80); ++ reg_w(gspca_dev->dev, 0x89, 0xffff, 0xfdff); ++ usb_exchange(gspca_dev, poxxxx_init_end_2); ++ } + return 0; + } + +@@ -2963,10 +3913,17 @@ static void sd_stopN(struct gspca_dev *gspca_dev) + struct usb_device *dev = gspca_dev->dev; + struct sd *sd = (struct sd *) gspca_dev; + +- if (sd->sensor == SENSOR_MI1310_SOC) ++ switch (sd->sensor) { ++ case SENSOR_MI1310_SOC: + reg_w(dev, 0x89, 0x058c, 0x00ff); +- else if (!(sd->flags & FL_SAMSUNG)) +- reg_w(dev, 0x89, 0xffff, 0xffff); ++ break; ++ case SENSOR_POxxxx: ++ return; ++ default: ++ if (!(sd->flags & FL_SAMSUNG)) ++ reg_w(dev, 0x89, 0xffff, 0xffff); ++ break; ++ } + reg_w(dev, 0xa0, 0x01, 0xb301); + reg_w(dev, 0xa0, 0x09, 0xb003); + } +@@ -2984,6 +3941,12 @@ static void sd_stop0(struct gspca_dev *gspca_dev) + reg_w(dev, 0x89, 0x058c, 0x00ff); + else if (!(sd->flags & FL_SAMSUNG)) + reg_w(dev, 0x89, 0xffff, 0xffff); ++ ++ if (sd->sensor == SENSOR_POxxxx) { ++ reg_w(dev, 0xa0, 0x26, 0xb300); ++ reg_w(dev, 0xa0, 0x04, 0xb300); ++ reg_w(dev, 0xa0, 0x00, 0xb300); ++ } + } + + static void sd_pkt_scan(struct gspca_dev *gspca_dev, +@@ -3020,6 +3983,60 @@ static void sd_pkt_scan(struct gspca_dev *gspca_dev, + gspca_frame_add(gspca_dev, INTER_PACKET, data, len); + } + ++static int sd_setbrightness(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->brightness = val; ++ if (gspca_dev->streaming) ++ setbrightness(gspca_dev); ++ return 0; ++} ++ ++static int sd_getbrightness(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->brightness; ++ return 0; ++} ++ ++static int sd_setcontrast(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->contrast = val; ++ if (gspca_dev->streaming) ++ setcontrast(gspca_dev); ++ return 0; ++} ++ ++static int sd_getcontrast(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->contrast; ++ return 0; ++} ++ ++static int sd_setcolors(struct gspca_dev *gspca_dev, __s32 val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ sd->colors = val; ++ if (gspca_dev->streaming) ++ setcolors(gspca_dev); ++ return 0; ++} ++ ++static int sd_getcolors(struct gspca_dev *gspca_dev, __s32 *val) ++{ ++ struct sd *sd = (struct sd *) gspca_dev; ++ ++ *val = sd->colors; ++ return 0; ++} ++ + static int sd_sethflip(struct gspca_dev *gspca_dev, __s32 val) + { + struct sd *sd = (struct sd *) gspca_dev; +diff --git a/drivers/media/video/gspca/zc3xx.c b/drivers/media/video/gspca/zc3xx.c +index 1a800fc..56fc686 100644 +--- a/drivers/media/video/gspca/zc3xx.c ++++ b/drivers/media/video/gspca/zc3xx.c +@@ -1,9 +1,8 @@ + /* +- * Z-Star/Vimicro zc301/zc302p/vc30x library +- * Copyright (C) 2004 2005 2006 Michel Xhaard +- * mxhaard@magic.fr ++ * Z-Star/Vimicro zc301/zc302p/vc30x library + * +- * V4L2 by Jean-Francois Moine ++ * Copyright (C) 2009-2010 Jean-Francois Moine ++ * Copyright (C) 2004 2005 2006 Michel Xhaard mxhaard@magic.fr + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by +@@ -22,10 +21,11 @@ + + #define MODULE_NAME "zc3xx" + ++#include + #include "gspca.h" + #include "jpeg.h" + +-MODULE_AUTHOR("Michel Xhaard , " ++MODULE_AUTHOR("Jean-Francois Moine , " + "Serge A. Suchkov "); + MODULE_DESCRIPTION("GSPCA ZC03xx/VC3xx USB Camera Driver"); + MODULE_LICENSE("GPL"); +@@ -39,18 +39,18 @@ static int force_sensor = -1; + struct sd { + struct gspca_dev gspca_dev; /* !! must be the first item */ + +- __u8 brightness; +- __u8 contrast; +- __u8 gamma; +- __u8 autogain; +- __u8 lightfreq; +- __u8 sharpness; ++ u8 brightness; ++ u8 contrast; ++ u8 gamma; ++ u8 autogain; ++ u8 lightfreq; ++ u8 sharpness; + u8 quality; /* image quality */ + #define QUALITY_MIN 40 + #define QUALITY_MAX 60 + #define QUALITY_DEF 50 + +- signed char sensor; /* Type of image sensor chip */ ++ u8 sensor; /* Type of image sensor chip */ + /* !! values used in different tables */ + #define SENSOR_ADCM2700 0 + #define SENSOR_CS2102 1 +@@ -92,9 +92,8 @@ static int sd_getfreq(struct gspca_dev *gspca_dev, __s32 *val); + static int sd_setsharpness(struct gspca_dev *gspca_dev, __s32 val); + static int sd_getsharpness(struct gspca_dev *gspca_dev, __s32 *val); + +-static struct ctrl sd_ctrls[] = { ++static const struct ctrl sd_ctrls[] = { + #define BRIGHTNESS_IDX 0 +-#define SD_BRIGHTNESS 0 + { + { + .id = V4L2_CID_BRIGHTNESS, +@@ -103,26 +102,26 @@ static struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 255, + .step = 1, +- .default_value = 128, ++#define BRIGHTNESS_DEF 128 ++ .default_value = BRIGHTNESS_DEF, + }, + .set = sd_setbrightness, + .get = sd_getbrightness, + }, +-#define SD_CONTRAST 1 + { + { + .id = V4L2_CID_CONTRAST, + .type = V4L2_CTRL_TYPE_INTEGER, + .name = "Contrast", + .minimum = 0, +- .maximum = 256, ++ .maximum = 255, + .step = 1, +- .default_value = 128, ++#define CONTRAST_DEF 128 ++ .default_value = CONTRAST_DEF, + }, + .set = sd_setcontrast, + .get = sd_getcontrast, + }, +-#define SD_GAMMA 2 + { + { + .id = V4L2_CID_GAMMA, +@@ -136,7 +135,6 @@ static struct ctrl sd_ctrls[] = { + .set = sd_setgamma, + .get = sd_getgamma, + }, +-#define SD_AUTOGAIN 3 + { + { + .id = V4L2_CID_AUTOGAIN, +@@ -145,13 +143,13 @@ static struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 1, + .step = 1, +- .default_value = 1, ++#define AUTOGAIN_DEF 1 ++ .default_value = AUTOGAIN_DEF, + }, + .set = sd_setautogain, + .get = sd_getautogain, + }, + #define LIGHTFREQ_IDX 4 +-#define SD_FREQ 4 + { + { + .id = V4L2_CID_POWER_LINE_FREQUENCY, +@@ -160,12 +158,12 @@ static struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 2, /* 0: 0, 1: 50Hz, 2:60Hz */ + .step = 1, +- .default_value = 1, ++#define FREQ_DEF 0 ++ .default_value = FREQ_DEF, + }, + .set = sd_setfreq, + .get = sd_getfreq, + }, +-#define SD_SHARPNESS 5 + { + { + .id = V4L2_CID_SHARPNESS, +@@ -174,7 +172,8 @@ static struct ctrl sd_ctrls[] = { + .minimum = 0, + .maximum = 3, + .step = 1, +- .default_value = 2, ++#define SHARPNESS_DEF 2 ++ .default_value = SHARPNESS_DEF, + }, + .set = sd_setsharpness, + .get = sd_getsharpness, +@@ -194,6 +193,19 @@ static const struct v4l2_pix_format vga_mode[] = { + .priv = 0}, + }; + ++static const struct v4l2_pix_format broken_vga_mode[] = { ++ {320, 232, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 320, ++ .sizeimage = 320 * 232 * 4 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG, ++ .priv = 1}, ++ {640, 472, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, ++ .bytesperline = 640, ++ .sizeimage = 640 * 472 * 3 / 8 + 590, ++ .colorspace = V4L2_COLORSPACE_JPEG, ++ .priv = 0}, ++}; ++ + static const struct v4l2_pix_format sif_mode[] = { + {176, 144, V4L2_PIX_FMT_JPEG, V4L2_FIELD_NONE, + .bytesperline = 176, +@@ -209,15 +221,19 @@ static const struct v4l2_pix_format sif_mode[] = { + + /* usb exchanges */ + struct usb_action { +- __u8 req; +- __u8 val; +- __u16 idx; ++ u8 req; ++ u8 val; ++ u16 idx; + }; + + static const struct usb_action adcm2700_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT}, /* 00,02,04,cc */ ++#if 1 /*jfm*/ + {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,03,cc */ ++#else ++ {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00,08,03,cc */ ++#endif + {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */ + {0xa0, 0xd3, ZC3XX_R08B_I2CDEVICEADDR}, /* 00,8b,d3,cc */ + {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */ +@@ -237,7 +253,11 @@ static const struct usb_action adcm2700_Initial[] = { + {0xbb, 0x00, 0x0400}, /* 04,00,00,bb */ + {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */ + {0xbb, 0x0f, 0x140f}, /* 14,0f,0f,bb */ ++#if 1 /*jfm-mswin*/ + {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION}, /* 01,01,37,cc */ ++#else ++ {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, /* 01,01,37,cc */ ++#endif + {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0d,cc */ + {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* 01,89,06,cc */ + {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* 01,c5,03,cc */ +@@ -306,7 +326,11 @@ static const struct usb_action adcm2700_Initial[] = { + static const struct usb_action adcm2700_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ ++#if 1 /*jfm*/ + {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,03,cc */ ++#else ++ {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00,08,03,cc */ ++#endif + {0xa0, 0x0a, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0a,cc */ + {0xa0, 0xd3, ZC3XX_R08B_I2CDEVICEADDR}, /* 00,8b,d3,cc */ + {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */ +@@ -326,7 +350,11 @@ static const struct usb_action adcm2700_InitialScale[] = { + {0xbb, 0x00, 0x0400}, /* 04,00,00,bb */ + {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */ + {0xbb, 0x0f, 0x140f}, /* 14,0f,0f,bb */ ++#if 1 /*jfm-mswin*/ + {0xa0, 0xb7, ZC3XX_R101_SENSORCORRECTION}, /* 01,01,37,cc */ ++#else ++ {0xa0, 0x37, ZC3XX_R101_SENSORCORRECTION}, /* 01,01,37,cc */ ++#endif + {0xa0, 0x0d, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0d,cc */ + {0xa0, 0x06, ZC3XX_R189_AWBSTATUS}, /* 01,89,06,cc */ + {0xa0, 0x03, ZC3XX_R1C5_SHARPNESSMODE}, /* 01,c5,03,cc */ +@@ -354,9 +382,17 @@ static const struct usb_action adcm2700_InitialScale[] = { + {0xbb, 0x5f, 0x2090}, /* 20,5f,90,bb */ + {0xbb, 0x01, 0x8000}, /* 80,01,00,bb */ + {0xbb, 0x09, 0x8400}, /* 84,09,00,bb */ ++#if 1 /*jfm-mswin*/ + {0xbb, 0x86, 0x0002}, /* 00,88,02,bb */ ++#else ++ {0xbb, 0x88, 0x0002}, /* 00,88,02,bb */ ++#endif + {0xbb, 0xe6, 0x0401}, /* 04,e6,01,bb */ ++#if 1 /*jfm-mswin*/ + {0xbb, 0x86, 0x0802}, /* 08,88,02,bb */ ++#else ++ {0xbb, 0x88, 0x0802}, /* 08,88,02,bb */ ++#endif + {0xbb, 0xe6, 0x0c01}, /* 0c,e6,01,bb */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ + {0xdd, 0x00, 0x0010}, /* 00,00,10,dd */ +@@ -421,7 +457,7 @@ static const struct usb_action adcm2700_NoFliker[] = { + {0xaa, 0xfe, 0x0010}, /* 00,fe,10,aa */ + {} + }; +-static const struct usb_action cs2102_Initial[] = { /* 320x240 */ ++static const struct usb_action cs2102_InitialScale[] = { /* 320x240 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, +@@ -473,7 +509,7 @@ static const struct usb_action cs2102_Initial[] = { /* 320x240 */ + {} + }; + +-static const struct usb_action cs2102_InitialScale[] = { /* 640x480 */ ++static const struct usb_action cs2102_Initial[] = { /* 640x480 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, +@@ -524,7 +560,7 @@ static const struct usb_action cs2102_InitialScale[] = { /* 640x480 */ + {0xa0, 0x00, 0x01ad}, + {} + }; +-static const struct usb_action cs2102_50HZ[] = { ++static const struct usb_action cs2102_50HZScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, + {0xaa, 0x23, 0x0001}, + {0xaa, 0x24, 0x005f}, +@@ -546,7 +582,7 @@ static const struct usb_action cs2102_50HZ[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, + {} + }; +-static const struct usb_action cs2102_50HZScale[] = { ++static const struct usb_action cs2102_50HZ[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, + {0xaa, 0x23, 0x0000}, + {0xaa, 0x24, 0x00af}, +@@ -568,7 +604,7 @@ static const struct usb_action cs2102_50HZScale[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, + {} + }; +-static const struct usb_action cs2102_60HZ[] = { ++static const struct usb_action cs2102_60HZScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, + {0xaa, 0x23, 0x0001}, + {0xaa, 0x24, 0x0055}, +@@ -590,7 +626,7 @@ static const struct usb_action cs2102_60HZ[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, + {} + }; +-static const struct usb_action cs2102_60HZScale[] = { ++static const struct usb_action cs2102_60HZ[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, + {0xaa, 0x23, 0x0000}, + {0xaa, 0x24, 0x00aa}, +@@ -612,7 +648,7 @@ static const struct usb_action cs2102_60HZScale[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, + {} + }; +-static const struct usb_action cs2102_NoFliker[] = { ++static const struct usb_action cs2102_NoFlikerScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, + {0xaa, 0x23, 0x0001}, + {0xaa, 0x24, 0x005f}, +@@ -634,7 +670,7 @@ static const struct usb_action cs2102_NoFliker[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, + {} + }; +-static const struct usb_action cs2102_NoFlikerScale[] = { ++static const struct usb_action cs2102_NoFliker[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, + {0xaa, 0x23, 0x0000}, + {0xaa, 0x24, 0x00af}, +@@ -658,7 +694,7 @@ static const struct usb_action cs2102_NoFlikerScale[] = { + }; + + /* CS2102_KOCOM */ +-static const struct usb_action cs2102K_Initial[] = { ++static const struct usb_action cs2102K_InitialScale[] = { + {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, + {0xa0, 0x08, ZC3XX_R010_CMOSSENSORSELECT}, +@@ -917,7 +953,7 @@ static const struct usb_action cs2102K_Initial[] = { + {} + }; + +-static const struct usb_action cs2102K_InitialScale[] = { ++static const struct usb_action cs2102K_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, +@@ -1495,7 +1531,7 @@ static const struct usb_action gc0305_NoFliker[] = { + {} + }; + +-static const struct usb_action hdcs2020xb_Initial[] = { ++static const struct usb_action hdcs2020b_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x11, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* qtable 0x05 */ +@@ -1627,7 +1663,7 @@ static const struct usb_action hdcs2020xb_Initial[] = { + {0xa0, 0x40, ZC3XX_R118_BGAIN}, + {} + }; +-static const struct usb_action hdcs2020xb_InitialScale[] = { ++static const struct usb_action hdcs2020b_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, +@@ -1819,7 +1855,7 @@ static const struct usb_action hdcs2020b_NoFliker[] = { + {} + }; + +-static const struct usb_action hv7131bxx_Initial[] = { /* 320x240 */ ++static const struct usb_action hv7131b_InitialScale[] = { /* 320x240 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, +@@ -1866,7 +1902,7 @@ static const struct usb_action hv7131bxx_Initial[] = { /* 320x240 */ + {} + }; + +-static const struct usb_action hv7131bxx_InitialScale[] = { /* 640x480*/ ++static const struct usb_action hv7131b_Initial[] = { /* 640x480*/ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x00, ZC3XX_R010_CMOSSENSORSELECT}, +@@ -2063,7 +2099,7 @@ static const struct usb_action hv7131b_NoFlikerScale[] = { /* 320x240 */ + {} + }; + +-static const struct usb_action hv7131cxx_Initial[] = { ++static const struct usb_action hv7131r_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, +@@ -2157,7 +2193,7 @@ static const struct usb_action hv7131cxx_Initial[] = { + {} + }; + +-static const struct usb_action hv7131cxx_InitialScale[] = { ++static const struct usb_action hv7131r_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* diff */ +@@ -2259,7 +2295,7 @@ static const struct usb_action hv7131cxx_InitialScale[] = { + {} + }; + +-static const struct usb_action icm105axx_Initial[] = { ++static const struct usb_action icm105a_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, +@@ -2436,7 +2472,7 @@ static const struct usb_action icm105axx_Initial[] = { + {} + }; + +-static const struct usb_action icm105axx_InitialScale[] = { ++static const struct usb_action icm105a_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, +@@ -2615,7 +2651,7 @@ static const struct usb_action icm105axx_InitialScale[] = { + {0xa0, 0x40, ZC3XX_R118_BGAIN}, + {} + }; +-static const struct usb_action icm105a_50HZ[] = { ++static const struct usb_action icm105a_50HZScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ + {0xaa, 0x0c, 0x0020}, /* 00,0c,20,aa */ +@@ -2646,7 +2682,7 @@ static const struct usb_action icm105a_50HZ[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */ + {} + }; +-static const struct usb_action icm105a_50HZScale[] = { ++static const struct usb_action icm105a_50HZ[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ + {0xaa, 0x0c, 0x008c}, /* 00,0c,8c,aa */ +@@ -2679,7 +2715,7 @@ static const struct usb_action icm105a_50HZScale[] = { + {0xa0, 0xc0, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,c0,cc */ + {} + }; +-static const struct usb_action icm105a_60HZ[] = { ++static const struct usb_action icm105a_60HZScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ + {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */ +@@ -2710,7 +2746,7 @@ static const struct usb_action icm105a_60HZ[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */ + {} + }; +-static const struct usb_action icm105a_60HZScale[] = { ++static const struct usb_action icm105a_60HZ[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ + {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */ +@@ -2743,7 +2779,7 @@ static const struct usb_action icm105a_60HZScale[] = { + {0xa0, 0xc0, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,c0,cc */ + {} + }; +-static const struct usb_action icm105a_NoFliker[] = { ++static const struct usb_action icm105a_NoFlikerScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ + {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */ +@@ -2774,7 +2810,7 @@ static const struct usb_action icm105a_NoFliker[] = { + {0xa0, 0xff, ZC3XX_R020_HSYNC_3}, /* 00,20,ff,cc */ + {} + }; +-static const struct usb_action icm105a_NoFlikerScale[] = { ++static const struct usb_action icm105a_NoFliker[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xaa, 0x0d, 0x0003}, /* 00,0d,03,aa */ + {0xaa, 0x0c, 0x0004}, /* 00,0c,04,aa */ +@@ -2808,7 +2844,7 @@ static const struct usb_action icm105a_NoFlikerScale[] = { + {} + }; + +-static const struct usb_action MC501CB_InitialScale[] = { ++static const struct usb_action mc501cb_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* 00,02,00,cc */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ +@@ -2928,7 +2964,7 @@ static const struct usb_action MC501CB_InitialScale[] = { + {} + }; + +-static const struct usb_action MC501CB_Initial[] = { /* 320x240 */ ++static const struct usb_action mc501cb_InitialScale[] = { /* 320x240 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ +@@ -3047,7 +3083,7 @@ static const struct usb_action MC501CB_Initial[] = { /* 320x240 */ + {} + }; + +-static const struct usb_action MC501CB_50HZ[] = { ++static const struct usb_action mc501cb_50HZScale[] = { + {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ + {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ + {0xaa, 0x36, 0x001d}, /* 00,36,1D,aa */ +@@ -3064,7 +3100,7 @@ static const struct usb_action MC501CB_50HZ[] = { + {} + }; + +-static const struct usb_action MC501CB_50HZScale[] = { ++static const struct usb_action mc501cb_50HZ[] = { + {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ + {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ + {0xaa, 0x36, 0x003a}, /* 00,36,3A,aa */ +@@ -3081,7 +3117,7 @@ static const struct usb_action MC501CB_50HZScale[] = { + {} + }; + +-static const struct usb_action MC501CB_60HZ[] = { ++static const struct usb_action mc501cb_60HZScale[] = { + {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ + {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ + {0xaa, 0x36, 0x0018}, /* 00,36,18,aa */ +@@ -3098,7 +3134,7 @@ static const struct usb_action MC501CB_60HZ[] = { + {} + }; + +-static const struct usb_action MC501CB_60HZScale[] = { ++static const struct usb_action mc501cb_60HZ[] = { + {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ + {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ + {0xaa, 0x36, 0x0030}, /* 00,36,30,aa */ +@@ -3115,7 +3151,7 @@ static const struct usb_action MC501CB_60HZScale[] = { + {} + }; + +-static const struct usb_action MC501CB_NoFliker[] = { ++static const struct usb_action mc501cb_NoFlikerScale[] = { + {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ + {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ + {0xaa, 0x36, 0x0018}, /* 00,36,18,aa */ +@@ -3132,7 +3168,7 @@ static const struct usb_action MC501CB_NoFliker[] = { + {} + }; + +-static const struct usb_action MC501CB_NoFlikerScale[] = { ++static const struct usb_action mc501cb_NoFliker[] = { + {0xaa, 0x03, 0x0003}, /* 00,03,03,aa */ + {0xaa, 0x10, 0x00fc}, /* 00,10,fc,aa */ + {0xaa, 0x36, 0x0030}, /* 00,36,30,aa */ +@@ -3144,11 +3180,16 @@ static const struct usb_action MC501CB_NoFlikerScale[] = { + {} + }; + +-/* from zs211.inf - HKR,%OV7620%,Initial - 640x480 */ +-static const struct usb_action OV7620_mode0[] = { ++/* from zs211.inf */ ++static const struct usb_action ov7620_Initial[] = { /* 640x480 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x40, ZC3XX_R002_CLOCKSELECT}, /* 00,02,40,cc */ ++#if 1 /*jfm*/ + {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ ++#else ++ {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ ++ /* mx change? */ ++#endif + {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* 00,01,01,cc */ + {0xa0, 0x06, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,06,cc */ + {0xa0, 0x02, ZC3XX_R083_RGAINADDR}, /* 00,83,02,cc */ +@@ -3214,9 +3255,7 @@ static const struct usb_action OV7620_mode0[] = { + {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,50,cc */ + {} + }; +- +-/* from zs211.inf - HKR,%OV7620%,InitialScale - 320x240 */ +-static const struct usb_action OV7620_mode1[] = { ++static const struct usb_action ov7620_InitialScale[] = { /* 320x240 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x50, ZC3XX_R002_CLOCKSELECT}, /* 00,02,50,cc */ + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ +@@ -3287,9 +3326,7 @@ static const struct usb_action OV7620_mode1[] = { + {0xa0, 0x50, ZC3XX_R1A8_DIGITALGAIN}, /* 01,a8,50,cc */ + {} + }; +- +-/* from zs211.inf - HKR,%OV7620%\AE,50HZ */ +-static const struct usb_action OV7620_50HZ[] = { ++static const struct usb_action ov7620_50HZ[] = { + {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */ + {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */ + {0xaa, 0x2b, 0x0096}, /* 00,2b,96,aa */ +@@ -3307,9 +3344,7 @@ static const struct usb_action OV7620_50HZ[] = { + if mode0 (640x480) */ + {} + }; +- +-/* from zs211.inf - HKR,%OV7620%\AE,60HZ */ +-static const struct usb_action OV7620_60HZ[] = { ++static const struct usb_action ov7620_60HZ[] = { + {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */ + /* (bug in zs211.inf) */ + {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */ +@@ -3331,9 +3366,7 @@ static const struct usb_action OV7620_60HZ[] = { + {0xa1, 0x01, 0x0037}, */ + {} + }; +- +-/* from zs211.inf - HKR,%OV7620%\AE,NoFliker */ +-static const struct usb_action OV7620_NoFliker[] = { ++static const struct usb_action ov7620_NoFliker[] = { + {0xaa, 0x13, 0x00a3}, /* 00,13,a3,aa */ + /* (bug in zs211.inf) */ + {0xdd, 0x00, 0x0100}, /* 00,01,00,dd */ +@@ -3354,7 +3387,7 @@ static const struct usb_action OV7620_NoFliker[] = { + {} + }; + +-static const struct usb_action ov7630c_Initial[] = { ++static const struct usb_action ov7630c_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, +@@ -3511,7 +3544,7 @@ static const struct usb_action ov7630c_Initial[] = { + {} + }; + +-static const struct usb_action ov7630c_InitialScale[] = { ++static const struct usb_action ov7630c_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, +@@ -3682,7 +3715,7 @@ static const struct usb_action pas106b_Initial_com[] = { + {} + }; + +-static const struct usb_action pas106b_Initial[] = { /* 176x144 */ ++static const struct usb_action pas106b_InitialScale[] = { /* 176x144 */ + /* JPEG control */ + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, + /* Sream and Sensor specific */ +@@ -3800,7 +3833,7 @@ static const struct usb_action pas106b_Initial[] = { /* 176x144 */ + {} + }; + +-static const struct usb_action pas106b_InitialScale[] = { /* 352x288 */ ++static const struct usb_action pas106b_Initial[] = { /* 352x288 */ + /* JPEG control */ + {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, + /* Sream and Sensor specific */ +@@ -3972,10 +4005,10 @@ static const struct usb_action pas106b_NoFliker[] = { + {} + }; + +-/* from usbvm31b.inf */ ++/* from lvWIMv.inf 046d:08a2/:08aa 2007/06/03 */ + static const struct usb_action pas202b_Initial[] = { /* 640x480 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ +- {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ ++ {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, + {0xa0, 0x0e, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0e,cc */ + {0xa0, 0x00, ZC3XX_R002_CLOCKSELECT}, /* 00,02,00,cc */ + {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */ +@@ -4000,7 +4033,7 @@ static const struct usb_action pas202b_Initial[] = { /* 640x480 */ + {0xaa, 0x09, 0x0006}, /* 00,09,06,aa */ + {0xaa, 0x0a, 0x0001}, /* 00,0a,01,aa */ + {0xaa, 0x0b, 0x0001}, /* 00,0b,01,aa */ +- {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */ ++ {0xaa, 0x0c, 0x0006}, + {0xaa, 0x0d, 0x0000}, /* 00,0d,00,aa */ + {0xaa, 0x10, 0x0000}, /* 00,10,00,aa */ + {0xaa, 0x12, 0x0005}, /* 00,12,05,aa */ +@@ -4019,13 +4052,13 @@ static const struct usb_action pas202b_Initial[] = { /* 640x480 */ + }; + static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ +- {0xa0, 0x00, ZC3XX_R008_CLOCKSETTING}, /* 00,08,00,cc */ ++ {0xa0, 0x03, ZC3XX_R008_CLOCKSETTING}, + {0xa0, 0x0e, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,0e,cc */ + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ + {0xa0, 0x02, ZC3XX_R003_FRAMEWIDTHHIGH}, /* 00,03,02,cc */ + {0xa0, 0x80, ZC3XX_R004_FRAMEWIDTHLOW}, /* 00,04,80,cc */ + {0xa0, 0x01, ZC3XX_R005_FRAMEHEIGHTHIGH}, /* 00,05,01,cc */ +- {0xa0, 0xd0, ZC3XX_R006_FRAMEHEIGHTLOW}, /* 00,06,d0,cc */ ++ {0xa0, 0xe0, ZC3XX_R006_FRAMEHEIGHTLOW}, + {0xa0, 0x01, ZC3XX_R001_SYSTEMOPERATING}, /* 00,01,01,cc */ + {0xa0, 0x03, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,03,cc */ + {0xa0, 0x01, ZC3XX_R012_VIDEOCONTROLFUNC}, /* 00,12,01,cc */ +@@ -4035,7 +4068,7 @@ static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */ + {0xa0, 0x08, ZC3XX_R11A_FIRSTYLOW}, /* 01,1a,08,cc */ + {0xa0, 0x02, ZC3XX_R11C_FIRSTXLOW}, /* 01,1c,02,cc */ + {0xa0, 0x01, ZC3XX_R09B_WINHEIGHTHIGH}, /* 00,9b,01,cc */ +- {0xa0, 0xd8, ZC3XX_R09C_WINHEIGHTLOW}, /* 00,9c,d8,cc */ ++ {0xa0, 0xe8, ZC3XX_R09C_WINHEIGHTLOW}, + {0xa0, 0x02, ZC3XX_R09D_WINWIDTHHIGH}, /* 00,9d,02,cc */ + {0xa0, 0x88, ZC3XX_R09E_WINWIDTHLOW}, /* 00,9e,88,cc */ + {0xaa, 0x02, 0x0002}, /* 00,02,02,aa */ +@@ -4044,7 +4077,7 @@ static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */ + {0xaa, 0x09, 0x0006}, /* 00,09,06,aa */ + {0xaa, 0x0a, 0x0001}, /* 00,0a,01,aa */ + {0xaa, 0x0b, 0x0001}, /* 00,0b,01,aa */ +- {0xaa, 0x0c, 0x0008}, /* 00,0c,08,aa */ ++ {0xaa, 0x0c, 0x0006}, + {0xaa, 0x0d, 0x0000}, /* 00,0d,00,aa */ + {0xaa, 0x10, 0x0000}, /* 00,10,00,aa */ + {0xaa, 0x12, 0x0005}, /* 00,12,05,aa */ +@@ -4059,6 +4092,8 @@ static const struct usb_action pas202b_InitialScale[] = { /* 320x240 */ + {0xa0, 0x08, ZC3XX_R250_DEADPIXELSMODE}, /* 02,50,08,cc */ + {0xa0, 0x08, ZC3XX_R301_EEPROMACCESS}, /* 03,01,08,cc */ + {0xa0, 0x70, ZC3XX_R18D_YTARGET}, /* 01,8d,70,cc */ ++ {0xa0, 0xff, ZC3XX_R097_WINYSTARTHIGH}, ++ {0xa0, 0xfe, ZC3XX_R098_WINYSTARTLOW}, + {} + }; + static const struct usb_action pas202b_50HZ[] = { +@@ -4066,22 +4101,22 @@ static const struct usb_action pas202b_50HZ[] = { + {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ + {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ + {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ +- {0xaa, 0x21, 0x0068}, /* 00,21,68,aa */ ++ {0xaa, 0x21, 0x001b}, + {0xaa, 0x03, 0x0044}, /* 00,03,44,aa */ +- {0xaa, 0x04, 0x0009}, /* 00,04,09,aa */ +- {0xaa, 0x05, 0x0028}, /* 00,05,28,aa */ ++ {0xaa, 0x04, 0x0008}, ++ {0xaa, 0x05, 0x001b}, + {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ + {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ +- {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ ++ {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF}, + {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ + {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ +- {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,07,cc */ +- {0xa0, 0xd2, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,d2,cc */ ++ {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, ++ {0xa0, 0x1b, ZC3XX_R192_EXPOSURELIMITLOW}, + {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ + {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ + {0xa0, 0x4d, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,4d,cc */ +- {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ +- {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ ++ {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE}, ++ {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE}, + {0xa0, 0x44, ZC3XX_R01D_HSYNC_0}, /* 00,1d,44,cc */ + {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */ + {0xa0, 0xad, ZC3XX_R01F_HSYNC_2}, /* 00,1f,ad,cc */ +@@ -4094,23 +4129,23 @@ static const struct usb_action pas202b_50HZScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ + {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ +- {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ +- {0xaa, 0x21, 0x006c}, /* 00,21,6c,aa */ ++ {0xaa, 0x20, 0x0004}, ++ {0xaa, 0x21, 0x003d}, + {0xaa, 0x03, 0x0041}, /* 00,03,41,aa */ +- {0xaa, 0x04, 0x0009}, /* 00,04,09,aa */ +- {0xaa, 0x05, 0x002c}, /* 00,05,2c,aa */ ++ {0xaa, 0x04, 0x0010}, ++ {0xaa, 0x05, 0x003d}, + {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ + {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ +- {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ ++ {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF}, + {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ + {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ +- {0xa0, 0x0f, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,0f,cc */ +- {0xa0, 0xbe, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,be,cc */ ++ {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID}, ++ {0xa0, 0x3d, ZC3XX_R192_EXPOSURELIMITLOW}, + {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ + {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ + {0xa0, 0x9b, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,9b,cc */ +- {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ +- {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ ++ {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE}, ++ {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE}, + {0xa0, 0x41, ZC3XX_R01D_HSYNC_0}, /* 00,1d,41,cc */ + {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */ + {0xa0, 0xad, ZC3XX_R01F_HSYNC_2}, /* 00,1f,ad,cc */ +@@ -4130,16 +4165,16 @@ static const struct usb_action pas202b_60HZ[] = { + {0xaa, 0x05, 0x0000}, /* 00,05,00,aa */ + {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ + {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ +- {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ ++ {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF}, + {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ + {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ +- {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,07,cc */ +- {0xa0, 0xc0, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,c0,cc */ ++ {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, ++ {0xa0, 0x00, ZC3XX_R192_EXPOSURELIMITLOW}, + {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ + {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ + {0xa0, 0x40, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,40,cc */ +- {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ +- {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ ++ {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE}, ++ {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE}, + {0xa0, 0x45, ZC3XX_R01D_HSYNC_0}, /* 00,1d,45,cc */ + {0xa0, 0x8e, ZC3XX_R01E_HSYNC_1}, /* 00,1e,8e,cc */ + {0xa0, 0xc1, ZC3XX_R01F_HSYNC_2}, /* 00,1f,c1,cc */ +@@ -4152,23 +4187,23 @@ static const struct usb_action pas202b_60HZScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ + {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ +- {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ +- {0xaa, 0x21, 0x0004}, /* 00,21,04,aa */ ++ {0xaa, 0x20, 0x0004}, ++ {0xaa, 0x21, 0x0008}, + {0xaa, 0x03, 0x0042}, /* 00,03,42,aa */ +- {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */ +- {0xaa, 0x05, 0x0004}, /* 00,05,04,aa */ ++ {0xaa, 0x04, 0x0010}, ++ {0xaa, 0x05, 0x0008}, + {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ + {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ +- {0xa0, 0x14, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,14,cc */ ++ {0xa0, 0x1c, ZC3XX_R1A9_DIGITALLIMITDIFF}, + {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,24,cc */ + {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ +- {0xa0, 0x0f, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,0f,cc */ +- {0xa0, 0x9f, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,9f,cc */ ++ {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID}, ++ {0xa0, 0x08, ZC3XX_R192_EXPOSURELIMITLOW}, + {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ + {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ + {0xa0, 0x81, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,81,cc */ +- {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ +- {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ ++ {0xa0, 0x0e, ZC3XX_R18C_AEFREEZE}, ++ {0xa0, 0x1b, ZC3XX_R18F_AEUNFREEZE}, + {0xa0, 0x42, ZC3XX_R01D_HSYNC_0}, /* 00,1d,42,cc */ + {0xa0, 0x6f, ZC3XX_R01E_HSYNC_1}, /* 00,1e,6f,cc */ + {0xa0, 0xaf, ZC3XX_R01F_HSYNC_2}, /* 00,1f,af,cc */ +@@ -4182,22 +4217,22 @@ static const struct usb_action pas202b_NoFliker[] = { + {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ + {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ + {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ +- {0xaa, 0x21, 0x0020}, /* 00,21,20,aa */ ++ {0xaa, 0x21, 0x0006}, + {0xaa, 0x03, 0x0040}, /* 00,03,40,aa */ + {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */ +- {0xaa, 0x05, 0x0020}, /* 00,05,20,aa */ ++ {0xaa, 0x05, 0x0006}, + {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ + {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ + {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ +- {0xa0, 0x07, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,07,cc */ +- {0xa0, 0xf0, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,f0,cc */ ++ {0xa0, 0x02, ZC3XX_R191_EXPOSURELIMITMID}, ++ {0xa0, 0x06, ZC3XX_R192_EXPOSURELIMITLOW}, + {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ + {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ +- {0xa0, 0x02, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,02,cc */ ++ {0xa0, 0x01, ZC3XX_R197_ANTIFLICKERLOW}, + {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ + {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ + {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,00,cc */ +- {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,00,cc */ ++ {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, + {0xa0, 0x40, ZC3XX_R01D_HSYNC_0}, /* 00,1d,40,cc */ + {0xa0, 0x60, ZC3XX_R01E_HSYNC_1}, /* 00,1e,60,cc */ + {0xa0, 0x90, ZC3XX_R01F_HSYNC_2}, /* 00,1f,90,cc */ +@@ -4210,23 +4245,23 @@ static const struct usb_action pas202b_NoFlikerScale[] = { + {0xa0, 0x00, ZC3XX_R019_AUTOADJUSTFPS}, /* 00,19,00,cc */ + {0xa0, 0x20, ZC3XX_R087_EXPTIMEMID}, /* 00,87,20,cc */ + {0xa0, 0x21, ZC3XX_R088_EXPTIMELOW}, /* 00,88,21,cc */ +- {0xaa, 0x20, 0x0002}, /* 00,20,02,aa */ +- {0xaa, 0x21, 0x0010}, /* 00,21,10,aa */ ++ {0xaa, 0x20, 0x0004}, ++ {0xaa, 0x21, 0x000c}, + {0xaa, 0x03, 0x0040}, /* 00,03,40,aa */ +- {0xaa, 0x04, 0x0008}, /* 00,04,08,aa */ +- {0xaa, 0x05, 0x0010}, /* 00,05,10,aa */ ++ {0xaa, 0x04, 0x0010}, ++ {0xaa, 0x05, 0x000c}, + {0xaa, 0x0e, 0x0001}, /* 00,0e,01,aa */ + {0xaa, 0x0f, 0x0000}, /* 00,0f,00,aa */ + {0xa0, 0x00, ZC3XX_R190_EXPOSURELIMITHIGH}, /* 01,90,00,cc */ +- {0xa0, 0x0f, ZC3XX_R191_EXPOSURELIMITMID}, /* 01,91,0f,cc */ +- {0xa0, 0xf0, ZC3XX_R192_EXPOSURELIMITLOW}, /* 01,92,f0,cc */ ++ {0xa0, 0x04, ZC3XX_R191_EXPOSURELIMITMID}, ++ {0xa0, 0x0c, ZC3XX_R192_EXPOSURELIMITLOW}, + {0xa0, 0x00, ZC3XX_R195_ANTIFLICKERHIGH}, /* 01,95,00,cc */ + {0xa0, 0x00, ZC3XX_R196_ANTIFLICKERMID}, /* 01,96,00,cc */ + {0xa0, 0x02, ZC3XX_R197_ANTIFLICKERLOW}, /* 01,97,02,cc */ + {0xa0, 0x10, ZC3XX_R18C_AEFREEZE}, /* 01,8c,10,cc */ + {0xa0, 0x20, ZC3XX_R18F_AEUNFREEZE}, /* 01,8f,20,cc */ + {0xa0, 0x00, ZC3XX_R1A9_DIGITALLIMITDIFF}, /* 01,a9,00,cc */ +- {0xa0, 0x00, ZC3XX_R1AA_DIGITALGAINSTEP}, /* 01,aa,00,cc */ ++ {0xa0, 0x24, ZC3XX_R1AA_DIGITALGAINSTEP}, + {0xa0, 0x40, ZC3XX_R01D_HSYNC_0}, /* 00,1d,40,cc */ + {0xa0, 0x60, ZC3XX_R01E_HSYNC_1}, /* 00,1e,60,cc */ + {0xa0, 0x90, ZC3XX_R01F_HSYNC_2}, /* 00,1f,90,cc */ +@@ -4713,8 +4748,8 @@ static const struct usb_action pb0330_NoFlikerScale[] = { + {} + }; + +-/* from oem9.inf - HKR,%PO2030%,Initial - 640x480 - (close to CS2102) */ +-static const struct usb_action PO2030_mode0[] = { ++/* from oem9.inf */ ++static const struct usb_action po2030_Initial[] = { /* 640x480 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x04, ZC3XX_R002_CLOCKSELECT}, /* 00,02,04,cc */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ +@@ -4790,8 +4825,8 @@ static const struct usb_action PO2030_mode0[] = { + {} + }; + +-/* from oem9.inf - HKR,%PO2030%,InitialScale - 320x240 */ +-static const struct usb_action PO2030_mode1[] = { ++/* from oem9.inf */ ++static const struct usb_action po2030_InitialScale[] = { /* 320x240 */ + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc */ + {0xa0, 0x10, ZC3XX_R002_CLOCKSELECT}, /* 00,02,10,cc */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc */ +@@ -4867,7 +4902,7 @@ static const struct usb_action PO2030_mode1[] = { + {} + }; + +-static const struct usb_action PO2030_50HZ[] = { ++static const struct usb_action po2030_50HZ[] = { + {0xaa, 0x8d, 0x0008}, /* 00,8d,08,aa */ + {0xaa, 0x1a, 0x0001}, /* 00,1a,01,aa */ + {0xaa, 0x1b, 0x000a}, /* 00,1b,0a,aa */ +@@ -4889,7 +4924,7 @@ static const struct usb_action PO2030_50HZ[] = { + {} + }; + +-static const struct usb_action PO2030_60HZ[] = { ++static const struct usb_action po2030_60HZ[] = { + {0xaa, 0x8d, 0x0008}, /* 00,8d,08,aa */ + {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa */ + {0xaa, 0x1b, 0x00de}, /* 00,1b,de,aa */ +@@ -4912,7 +4947,7 @@ static const struct usb_action PO2030_60HZ[] = { + {} + }; + +-static const struct usb_action PO2030_NoFliker[] = { ++static const struct usb_action po2030_NoFliker[] = { + {0xa0, 0x02, ZC3XX_R180_AUTOCORRECTENABLE}, /* 01,80,02,cc */ + {0xaa, 0x8d, 0x000d}, /* 00,8d,0d,aa */ + {0xaa, 0x1a, 0x0000}, /* 00,1a,00,aa */ +@@ -4924,7 +4959,7 @@ static const struct usb_action PO2030_NoFliker[] = { + }; + + /* TEST */ +-static const struct usb_action tas5130CK_Initial[] = { ++static const struct usb_action tas5130cK_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x01, 0x003b}, + {0xa0, 0x0e, 0x003a}, +@@ -5127,7 +5162,7 @@ static const struct usb_action tas5130CK_Initial[] = { + {} + }; + +-static const struct usb_action tas5130CK_InitialScale[] = { ++static const struct usb_action tas5130cK_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, + {0xa0, 0x01, 0x003b}, + {0xa0, 0x0e, 0x003a}, +@@ -5560,7 +5595,7 @@ static const struct usb_action tas5130cxx_NoFlikerScale[] = { + {} + }; + +-static const struct usb_action tas5130c_vf0250_Initial[] = { ++static const struct usb_action tas5130c_vf0250_InitialScale[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */ + {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */ +@@ -5627,7 +5662,7 @@ static const struct usb_action tas5130c_vf0250_Initial[] = { + {} + }; + +-static const struct usb_action tas5130c_vf0250_InitialScale[] = { ++static const struct usb_action tas5130c_vf0250_Initial[] = { + {0xa0, 0x01, ZC3XX_R000_SYSTEMCONTROL}, /* 00,00,01,cc, */ + {0xa0, 0x02, ZC3XX_R008_CLOCKSETTING}, /* 00,08,02,cc, */ + {0xa0, 0x01, ZC3XX_R010_CMOSSENSORSELECT}, /* 00,10,01,cc, */ +@@ -5692,8 +5727,7 @@ static const struct usb_action tas5130c_vf0250_InitialScale[] = { + {0xa0, 0x65, ZC3XX_R118_BGAIN}, /* 01,18,65,cc */ + {} + }; +-/* "50HZ" light frequency banding filter */ +-static const struct usb_action tas5130c_vf0250_50HZ[] = { ++static const struct usb_action tas5130c_vf0250_50HZScale[] = { + {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ + {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */ + {0xaa, 0x84, 0x00aa}, /* 00,84,aa,aa */ +@@ -5717,8 +5751,7 @@ static const struct usb_action tas5130c_vf0250_50HZ[] = { + {} + }; + +-/* "50HZScale" light frequency banding filter */ +-static const struct usb_action tas5130c_vf0250_50HZScale[] = { ++static const struct usb_action tas5130c_vf0250_50HZ[] = { + {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ + {0xaa, 0x83, 0x0003}, /* 00,83,03,aa */ + {0xaa, 0x84, 0x0054}, /* 00,84,54,aa */ +@@ -5742,8 +5775,7 @@ static const struct usb_action tas5130c_vf0250_50HZScale[] = { + {} + }; + +-/* "60HZ" light frequency banding filter */ +-static const struct usb_action tas5130c_vf0250_60HZ[] = { ++static const struct usb_action tas5130c_vf0250_60HZScale[] = { + {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ + {0xaa, 0x83, 0x0001}, /* 00,83,01,aa */ + {0xaa, 0x84, 0x0062}, /* 00,84,62,aa */ +@@ -5767,8 +5799,7 @@ static const struct usb_action tas5130c_vf0250_60HZ[] = { + {} + }; + +-/* "60HZScale" light frequency banding ilter */ +-static const struct usb_action tas5130c_vf0250_60HZScale[] = { ++static const struct usb_action tas5130c_vf0250_60HZ[] = { + {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ + {0xaa, 0x83, 0x0002}, /* 00,83,02,aa */ + {0xaa, 0x84, 0x00c4}, /* 00,84,c4,aa */ +@@ -5792,8 +5823,7 @@ static const struct usb_action tas5130c_vf0250_60HZScale[] = { + {} + }; + +-/* "NoFliker" light frequency banding flter */ +-static const struct usb_action tas5130c_vf0250_NoFliker[] = { ++static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = { + {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */ + {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ + {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */ +@@ -5815,8 +5845,7 @@ static const struct usb_action tas5130c_vf0250_NoFliker[] = { + {} + }; + +-/* "NoFlikerScale" light frequency banding filter */ +-static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = { ++static const struct usb_action tas5130c_vf0250_NoFliker[] = { + {0xa0, 0x0c, ZC3XX_R100_OPERATIONMODE}, /* 01,00,0c,cc, */ + {0xaa, 0x82, 0x0000}, /* 00,82,00,aa */ + {0xaa, 0x83, 0x0000}, /* 00,83,00,aa */ +@@ -5839,7 +5868,7 @@ static const struct usb_action tas5130c_vf0250_NoFlikerScale[] = { + }; + + static u8 reg_r_i(struct gspca_dev *gspca_dev, +- __u16 index) ++ u16 index) + { + usb_control_msg(gspca_dev->dev, + usb_rcvctrlpipe(gspca_dev->dev, 0), +@@ -5852,7 +5881,7 @@ static u8 reg_r_i(struct gspca_dev *gspca_dev, + } + + static u8 reg_r(struct gspca_dev *gspca_dev, +- __u16 index) ++ u16 index) + { + u8 ret; + +@@ -5862,8 +5891,8 @@ static u8 reg_r(struct gspca_dev *gspca_dev, + } + + static void reg_w_i(struct usb_device *dev, +- __u8 value, +- __u16 index) ++ u8 value, ++ u16 index) + { + usb_control_msg(dev, + usb_sndctrlpipe(dev, 0), +@@ -5874,18 +5903,18 @@ static void reg_w_i(struct usb_device *dev, + } + + static void reg_w(struct usb_device *dev, +- __u8 value, +- __u16 index) ++ u8 value, ++ u16 index) + { + PDEBUG(D_USBO, "reg w [%04x] = %02x", index, value); + reg_w_i(dev, value, index); + } + +-static __u16 i2c_read(struct gspca_dev *gspca_dev, +- __u8 reg) ++static u16 i2c_read(struct gspca_dev *gspca_dev, ++ u8 reg) + { +- __u8 retbyte; +- __u16 retval; ++ u8 retbyte; ++ u16 retval; + + reg_w_i(gspca_dev->dev, reg, 0x0092); + reg_w_i(gspca_dev->dev, 0x02, 0x0090); /* <- read command */ +@@ -5900,12 +5929,12 @@ static __u16 i2c_read(struct gspca_dev *gspca_dev, + return retval; + } + +-static __u8 i2c_write(struct gspca_dev *gspca_dev, +- __u8 reg, +- __u8 valL, +- __u8 valH) ++static u8 i2c_write(struct gspca_dev *gspca_dev, ++ u8 reg, ++ u8 valL, ++ u8 valH) + { +- __u8 retbyte; ++ u8 retbyte; + + reg_w_i(gspca_dev->dev, reg, 0x92); + reg_w_i(gspca_dev->dev, valL, 0x93); +@@ -5957,24 +5986,24 @@ static void setmatrix(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + int i; +- const __u8 *matrix; ++ const u8 *matrix; + static const u8 adcm2700_matrix[9] = + /* {0x66, 0xed, 0xed, 0xed, 0x66, 0xed, 0xed, 0xed, 0x66}; */ + /*ms-win*/ + {0x74, 0xed, 0xed, 0xed, 0x74, 0xed, 0xed, 0xed, 0x74}; +- static const __u8 gc0305_matrix[9] = ++ static const u8 gc0305_matrix[9] = + {0x50, 0xf8, 0xf8, 0xf8, 0x50, 0xf8, 0xf8, 0xf8, 0x50}; +- static const __u8 ov7620_matrix[9] = ++ static const u8 ov7620_matrix[9] = + {0x58, 0xf4, 0xf4, 0xf4, 0x58, 0xf4, 0xf4, 0xf4, 0x58}; +- static const __u8 pas202b_matrix[9] = ++ static const u8 pas202b_matrix[9] = + {0x4c, 0xf5, 0xff, 0xf9, 0x51, 0xf5, 0xfb, 0xed, 0x5f}; +- static const __u8 po2030_matrix[9] = ++ static const u8 po2030_matrix[9] = + {0x60, 0xf0, 0xf0, 0xf0, 0x60, 0xf0, 0xf0, 0xf0, 0x60}; + static const u8 tas5130c_matrix[9] = + {0x68, 0xec, 0xec, 0xec, 0x68, 0xec, 0xec, 0xec, 0x68}; +- static const __u8 vf0250_matrix[9] = ++ static const u8 vf0250_matrix[9] = + {0x7b, 0xea, 0xea, 0xea, 0x7b, 0xea, 0xea, 0xea, 0x7b}; +- static const __u8 *matrix_tb[SENSOR_MAX] = { ++ static const u8 *matrix_tb[SENSOR_MAX] = { + adcm2700_matrix, /* SENSOR_ADCM2700 0 */ + ov7620_matrix, /* SENSOR_CS2102 1 */ + NULL, /* SENSOR_CS2102K 2 */ +@@ -6006,11 +6035,12 @@ static void setmatrix(struct gspca_dev *gspca_dev) + static void setbrightness(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- __u8 brightness; ++ u8 brightness; + + switch (sd->sensor) { + case SENSOR_GC0305: + case SENSOR_OV7620: ++ case SENSOR_PAS202B: + case SENSOR_PO2030: + return; + } +@@ -6034,7 +6064,7 @@ static void setsharpness(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + struct usb_device *dev = gspca_dev->dev; + int sharpness; +- static const __u8 sharpness_tb[][2] = { ++ static const u8 sharpness_tb[][2] = { + {0x02, 0x03}, + {0x04, 0x07}, + {0x08, 0x0f}, +@@ -6053,118 +6083,69 @@ static void setcontrast(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + struct usb_device *dev = gspca_dev->dev; +- const __u8 *Tgamma, *Tgradient; +- int g, i, k; +- static const __u8 kgamma_tb[16] = /* delta for contrast */ ++ const u8 *Tgamma; ++ int g, i, k, adj, gp; ++ u8 gr[16]; ++ static const u8 delta_tb[16] = /* delta for contrast */ + {0x15, 0x0d, 0x0a, 0x09, 0x08, 0x08, 0x08, 0x08, + 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08}; +- static const __u8 kgrad_tb[16] = +- {0x1b, 0x06, 0x03, 0x02, 0x00, 0x00, 0x00, 0x00, +- 0x00, 0x00, 0x00, 0x00, 0x00, 0x02, 0x06, 0x04}; +- static const __u8 Tgamma_1[16] = ++ static const u8 gamma_tb[6][16] = { + {0x00, 0x00, 0x03, 0x0d, 0x1b, 0x2e, 0x45, 0x5f, +- 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff}; +- static const __u8 Tgradient_1[16] = +- {0x00, 0x01, 0x05, 0x0b, 0x10, 0x15, 0x18, 0x1a, +- 0x1a, 0x18, 0x16, 0x14, 0x12, 0x0f, 0x0d, 0x06}; +- static const __u8 Tgamma_2[16] = ++ 0x79, 0x93, 0xab, 0xc1, 0xd4, 0xe5, 0xf3, 0xff}, + {0x01, 0x0c, 0x1f, 0x3a, 0x53, 0x6d, 0x85, 0x9c, +- 0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff}; +- static const __u8 Tgradient_2[16] = +- {0x05, 0x0f, 0x16, 0x1a, 0x19, 0x19, 0x17, 0x15, +- 0x12, 0x10, 0x0e, 0x0b, 0x09, 0x08, 0x06, 0x03}; +- static const __u8 Tgamma_3[16] = ++ 0xb0, 0xc2, 0xd1, 0xde, 0xe9, 0xf2, 0xf9, 0xff}, + {0x04, 0x16, 0x30, 0x4e, 0x68, 0x81, 0x98, 0xac, +- 0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff}; +- static const __u8 Tgradient_3[16] = +- {0x0c, 0x16, 0x1b, 0x1c, 0x19, 0x18, 0x15, 0x12, +- 0x10, 0x0d, 0x0b, 0x09, 0x08, 0x06, 0x05, 0x03}; +- static const __u8 Tgamma_4[16] = ++ 0xbe, 0xcd, 0xda, 0xe4, 0xed, 0xf5, 0xfb, 0xff}, + {0x13, 0x38, 0x59, 0x79, 0x92, 0xa7, 0xb9, 0xc8, +- 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff}; +- static const __u8 Tgradient_4[16] = +- {0x26, 0x22, 0x20, 0x1c, 0x16, 0x13, 0x10, 0x0d, +- 0x0b, 0x09, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02}; +- static const __u8 Tgamma_5[16] = ++ 0xd4, 0xdf, 0xe7, 0xee, 0xf4, 0xf9, 0xfc, 0xff}, + {0x20, 0x4b, 0x6e, 0x8d, 0xa3, 0xb5, 0xc5, 0xd2, +- 0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff}; +- static const __u8 Tgradient_5[16] = +- {0x37, 0x26, 0x20, 0x1a, 0x14, 0x10, 0x0e, 0x0b, +- 0x09, 0x07, 0x06, 0x05, 0x04, 0x03, 0x02, 0x02}; +- static const __u8 Tgamma_6[16] = /* ?? was gamma 5 */ ++ 0xdc, 0xe5, 0xec, 0xf2, 0xf6, 0xfa, 0xfd, 0xff}, + {0x24, 0x44, 0x64, 0x84, 0x9d, 0xb2, 0xc4, 0xd3, +- 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}; +- static const __u8 Tgradient_6[16] = +- {0x18, 0x20, 0x20, 0x1c, 0x16, 0x13, 0x10, 0x0e, +- 0x0b, 0x09, 0x07, 0x00, 0x00, 0x00, 0x00, 0x01}; +- static const __u8 *gamma_tb[] = { +- NULL, Tgamma_1, Tgamma_2, +- Tgamma_3, Tgamma_4, Tgamma_5, Tgamma_6 +- }; +- static const __u8 *gradient_tb[] = { +- NULL, Tgradient_1, Tgradient_2, +- Tgradient_3, Tgradient_4, Tgradient_5, Tgradient_6 ++ 0xe0, 0xeb, 0xf4, 0xff, 0xff, 0xff, 0xff, 0xff}, + }; +-#ifdef GSPCA_DEBUG +- __u8 v[16]; +-#endif + +- Tgamma = gamma_tb[sd->gamma]; +- Tgradient = gradient_tb[sd->gamma]; ++ Tgamma = gamma_tb[sd->gamma - 1]; + +- k = (sd->contrast - 128) /* -128 / 128 */ +- * Tgamma[0]; +- PDEBUG(D_CONF, "gamma:%d contrast:%d gamma coeff: %d/128", +- sd->gamma, sd->contrast, k); ++ k = ((int) sd->contrast - 128); /* -128 / 128 */ ++ adj = 0; ++ gp = 0; + for (i = 0; i < 16; i++) { +- g = Tgamma[i] + kgamma_tb[i] * k / 128; ++ g = Tgamma[i] - delta_tb[i] * k / 128 - adj / 2; + if (g > 0xff) + g = 0xff; + else if (g <= 0) + g = 1; + reg_w(dev, g, 0x0120 + i); /* gamma */ +-#ifdef GSPCA_DEBUG +- if (gspca_debug & D_CONF) +- v[i] = g; +-#endif +- } +- PDEBUG(D_CONF, "tb: %02x %02x %02x %02x %02x %02x %02x %02x", +- v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); +- PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", +- v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); +- for (i = 0; i < 16; i++) { +- g = Tgradient[i] - kgrad_tb[i] * k / 128; +- if (g > 0xff) +- g = 0xff; +- else if (g <= 0) { +- if (i != 15) +- g = 0; ++ if (k > 0) ++ adj--; ++ else ++ adj++; ++ ++ if (i != 0) { ++ if (gp == 0) ++ gr[i - 1] = 0; + else +- g = 1; ++ gr[i - 1] = g - gp; + } +- reg_w(dev, g, 0x0130 + i); /* gradient */ +-#ifdef GSPCA_DEBUG +- if (gspca_debug & D_CONF) +- v[i] = g; +-#endif ++ gp = g; + } +- PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", +- v[0], v[1], v[2], v[3], v[4], v[5], v[6], v[7]); +- PDEBUG(D_CONF, " %02x %02x %02x %02x %02x %02x %02x %02x", +- v[8], v[9], v[10], v[11], v[12], v[13], v[14], v[15]); ++ gr[15] = gr[14] / 2; ++ for (i = 0; i < 16; i++) ++ reg_w(dev, gr[i], 0x0130 + i); /* gradient */ + } + + static void setquality(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + struct usb_device *dev = gspca_dev->dev; +- __u8 frxt; ++ u8 frxt; + + switch (sd->sensor) { + case SENSOR_ADCM2700: + case SENSOR_GC0305: + case SENSOR_HV7131B: + case SENSOR_OV7620: ++ case SENSOR_PAS202B: + case SENSOR_PO2030: + return; + } +@@ -6218,9 +6199,9 @@ static int setlightfreq(struct gspca_dev *gspca_dev) + hdcs2020b_50HZ, hdcs2020b_50HZ, + hdcs2020b_60HZ, hdcs2020b_60HZ}, + /* SENSOR_HV7131B 5 */ +- {hv7131b_NoFlikerScale, hv7131b_NoFliker, +- hv7131b_50HZScale, hv7131b_50HZ, +- hv7131b_60HZScale, hv7131b_60HZ}, ++ {hv7131b_NoFliker, hv7131b_NoFlikerScale, ++ hv7131b_50HZ, hv7131b_50HZScale, ++ hv7131b_60HZ, hv7131b_60HZScale}, + /* SENSOR_HV7131C 6 */ + {NULL, NULL, + NULL, NULL, +@@ -6230,17 +6211,17 @@ static int setlightfreq(struct gspca_dev *gspca_dev) + icm105a_50HZ, icm105a_50HZScale, + icm105a_60HZ, icm105a_60HZScale}, + /* SENSOR_MC501CB 8 */ +- {MC501CB_NoFliker, MC501CB_NoFlikerScale, +- MC501CB_50HZ, MC501CB_50HZScale, +- MC501CB_60HZ, MC501CB_60HZScale}, ++ {mc501cb_NoFliker, mc501cb_NoFlikerScale, ++ mc501cb_50HZ, mc501cb_50HZScale, ++ mc501cb_60HZ, mc501cb_60HZScale}, + /* SENSOR_MI0360SOC 9 */ +- {mi360soc_AENoFlikerScale, mi360soc_AENoFliker, +- mi360soc_AE50HZScale, mi360soc_AE50HZ, +- mi360soc_AE60HZScale, mi360soc_AE60HZ}, ++ {mi360soc_AENoFliker, mi360soc_AENoFlikerScale, ++ mi360soc_AE50HZ, mi360soc_AE50HZScale, ++ mi360soc_AE60HZ, mi360soc_AE60HZScale}, + /* SENSOR_OV7620 10 */ +- {OV7620_NoFliker, OV7620_NoFliker, +- OV7620_50HZ, OV7620_50HZ, +- OV7620_60HZ, OV7620_60HZ}, ++ {ov7620_NoFliker, ov7620_NoFliker, ++ ov7620_50HZ, ov7620_50HZ, ++ ov7620_60HZ, ov7620_60HZ}, + /* SENSOR_OV7630C 11 */ + {NULL, NULL, + NULL, NULL, +@@ -6258,17 +6239,17 @@ static int setlightfreq(struct gspca_dev *gspca_dev) + pb0330_50HZScale, pb0330_50HZ, + pb0330_60HZScale, pb0330_60HZ}, + /* SENSOR_PO2030 15 */ +- {PO2030_NoFliker, PO2030_NoFliker, +- PO2030_50HZ, PO2030_50HZ, +- PO2030_60HZ, PO2030_60HZ}, ++ {po2030_NoFliker, po2030_NoFliker, ++ po2030_50HZ, po2030_50HZ, ++ po2030_60HZ, po2030_60HZ}, + /* SENSOR_TAS5130CK 16 */ +- {tas5130cxx_NoFlikerScale, tas5130cxx_NoFliker, +- tas5130cxx_50HZScale, tas5130cxx_50HZ, +- tas5130cxx_60HZScale, tas5130cxx_60HZ}, ++ {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale, ++ tas5130cxx_50HZ, tas5130cxx_50HZScale, ++ tas5130cxx_60HZ, tas5130cxx_60HZScale}, + /* SENSOR_TAS5130CXX 17 */ +- {tas5130cxx_NoFlikerScale, tas5130cxx_NoFliker, +- tas5130cxx_50HZScale, tas5130cxx_50HZ, +- tas5130cxx_60HZScale, tas5130cxx_60HZ}, ++ {tas5130cxx_NoFliker, tas5130cxx_NoFlikerScale, ++ tas5130cxx_50HZ, tas5130cxx_50HZScale, ++ tas5130cxx_60HZ, tas5130cxx_60HZScale}, + /* SENSOR_TAS5130C_VF0250 18 */ + {tas5130c_vf0250_NoFliker, tas5130c_vf0250_NoFlikerScale, + tas5130c_vf0250_50HZ, tas5130c_vf0250_50HZScale, +@@ -6277,9 +6258,9 @@ static int setlightfreq(struct gspca_dev *gspca_dev) + + i = sd->lightfreq * 2; + mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; +- if (!mode) +- i++; /* 640x480 */ +- zc3_freq = freq_tb[(int) sd->sensor][i]; ++ if (mode) ++ i++; /* 320x240 */ ++ zc3_freq = freq_tb[sd->sensor][i]; + if (zc3_freq != NULL) { + usb_exchange(gspca_dev, zc3_freq); + switch (sd->sensor) { +@@ -6297,6 +6278,9 @@ static int setlightfreq(struct gspca_dev *gspca_dev) + reg_w(gspca_dev->dev, 0x44, 0x0002); + } + break; ++ case SENSOR_PAS202B: ++ reg_w(gspca_dev->dev, 0x00, 0x01a7); ++ break; + } + } + return 0; +@@ -6305,7 +6289,7 @@ static int setlightfreq(struct gspca_dev *gspca_dev) + static void setautogain(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; +- __u8 autoval; ++ u8 autoval; + + if (sd->autogain) + autoval = 0x42; +@@ -6333,6 +6317,12 @@ static void send_unknown(struct usb_device *dev, int sensor) + reg_w(dev, 0x02, 0x003b); + reg_w(dev, 0x00, 0x0038); + break; ++ case SENSOR_PAS202B: ++ reg_w(dev, 0x03, 0x003b); ++ reg_w(dev, 0x0c, 0x003a); ++ reg_w(dev, 0x0b, 0x0039); ++ reg_w(dev, 0x0b, 0x0038); ++ break; + } + } + +@@ -6349,7 +6339,7 @@ static void start_2wr_probe(struct usb_device *dev, int sensor) + + static int sif_probe(struct gspca_dev *gspca_dev) + { +- __u16 checkword; ++ u16 checkword; + + start_2wr_probe(gspca_dev->dev, 0x0f); /* PAS106 */ + reg_w(gspca_dev->dev, 0x08, 0x008d); +@@ -6392,6 +6382,7 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev) + } + + start_2wr_probe(dev, 0x08); /* HDCS2020 */ ++ i2c_write(gspca_dev, 0x1c, 0x00, 0x00); + i2c_write(gspca_dev, 0x15, 0xaa, 0x00); + retword = i2c_read(gspca_dev, 0x15); + if (retword != 0) +@@ -6410,7 +6401,11 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev) + return 0x0a; /* PB0330 ?? */ + + start_2wr_probe(dev, 0x0c); /* ICM105A */ ++#if 1 + i2c_write(gspca_dev, 0x01, 0x11, 0x00); ++#else ++ i2c_write(gspca_dev, 0x01, 0xaa, 0x00); ++#endif + retword = i2c_read(gspca_dev, 0x01); + if (retword != 0) + return 0x0c; /* ICM105A */ +@@ -6420,8 +6415,10 @@ static int vga_2wr_probe(struct gspca_dev *gspca_dev) + i2c_write(gspca_dev, 0x03, 0xaa, 0x00); + msleep(50); + retword = i2c_read(gspca_dev, 0x03); +- if (retword != 0) ++ if (retword != 0) { ++ send_unknown(dev, SENSOR_PAS202B); + return 0x0e; /* PAS202BCB */ ++ } + + start_2wr_probe(dev, 0x02); /* TAS5130C */ + i2c_write(gspca_dev, 0x01, 0xaa, 0x00); +@@ -6457,8 +6454,8 @@ ov_check: + } + + struct sensor_by_chipset_revision { +- __u16 revision; +- __u8 internal_sensor_id; ++ u16 revision; ++ u8 internal_sensor_id; + }; + static const struct sensor_by_chipset_revision chipset_revision_sensor[] = { + {0xc000, 0x12}, /* TAS5130C */ +@@ -6467,6 +6464,7 @@ static const struct sensor_by_chipset_revision chipset_revision_sensor[] = { + {0x8001, 0x13}, + {0x8000, 0x14}, /* CS2102K */ + {0x8400, 0x15}, /* TAS5130K */ ++ {0xe400, 0x15}, + }; + + static int vga_3wr_probe(struct gspca_dev *gspca_dev) +@@ -6474,7 +6472,7 @@ static int vga_3wr_probe(struct gspca_dev *gspca_dev) + struct sd *sd = (struct sd *) gspca_dev; + struct usb_device *dev = gspca_dev->dev; + int i; +- __u8 retbyte; ++ u8 retbyte; + u16 retword; + + /*fixme: lack of 8b=b3 (11,12)-> 10, 8b=e0 (14,15,16)-> 12 found in gspcav1*/ +@@ -6622,8 +6620,7 @@ static int sd_config(struct gspca_dev *gspca_dev, + struct sd *sd = (struct sd *) gspca_dev; + struct cam *cam; + int sensor; +- int vga = 1; /* 1: vga, 0: sif */ +- static const __u8 gamma[SENSOR_MAX] = { ++ static const u8 gamma[SENSOR_MAX] = { + 4, /* SENSOR_ADCM2700 0 */ + 4, /* SENSOR_CS2102 1 */ + 5, /* SENSOR_CS2102K 2 */ +@@ -6644,9 +6641,30 @@ static int sd_config(struct gspca_dev *gspca_dev, + 3, /* SENSOR_TAS5130CXX 17 */ + 3, /* SENSOR_TAS5130C_VF0250 18 */ + }; ++ static const u8 mode_tb[SENSOR_MAX] = { ++ 2, /* SENSOR_ADCM2700 0 */ ++ 1, /* SENSOR_CS2102 1 */ ++ 1, /* SENSOR_CS2102K 2 */ ++ 1, /* SENSOR_GC0305 3 */ ++ 1, /* SENSOR_HDCS2020b 4 */ ++ 1, /* SENSOR_HV7131B 5 */ ++ 1, /* SENSOR_HV7131C 6 */ ++ 1, /* SENSOR_ICM105A 7 */ ++ 2, /* SENSOR_MC501CB 8 */ ++ 1, /* SENSOR_MI0360SOC 9 */ ++ 2, /* SENSOR_OV7620 10 */ ++ 1, /* SENSOR_OV7630C 11 */ ++ 0, /* SENSOR_PAS106 12 */ ++ 1, /* SENSOR_PAS202B 13 */ ++ 1, /* SENSOR_PB0330 14 */ ++ 1, /* SENSOR_PO2030 15 */ ++ 1, /* SENSOR_TAS5130CK 16 */ ++ 1, /* SENSOR_TAS5130CXX 17 */ ++ 1, /* SENSOR_TAS5130C_VF0250 18 */ ++ }; + + /* define some sensors from the vendor/product */ +- sd->sharpness = 2; ++ sd->sharpness = SHARPNESS_DEF; + sd->sensor = id->driver_info; + sensor = zcxx_probeSensor(gspca_dev); + if (sensor >= 0) +@@ -6671,8 +6689,21 @@ static int sd_config(struct gspca_dev *gspca_dev, + } + break; + case 0: +- PDEBUG(D_PROBE, "Find Sensor HV7131B"); +- sd->sensor = SENSOR_HV7131B; ++ /* check the sensor type */ ++ sensor = i2c_read(gspca_dev, 0x00); ++ PDEBUG(D_PROBE, "Sensor hv7131 type %d", sensor); ++ switch (sensor) { ++ case 0: /* hv7131b */ ++ case 1: /* hv7131e */ ++ PDEBUG(D_PROBE, "Find Sensor HV7131B"); ++ sd->sensor = SENSOR_HV7131B; ++ break; ++ default: ++/* case 2: * hv7131r */ ++ PDEBUG(D_PROBE, "Find Sensor HV7131R(c)"); ++ sd->sensor = SENSOR_HV7131C; ++ break; ++ } + break; + case 0x02: + PDEBUG(D_PROBE, "Sensor TAS5130C"); +@@ -6699,12 +6730,11 @@ static int sd_config(struct gspca_dev *gspca_dev, + case 0x0e: + PDEBUG(D_PROBE, "Find Sensor PAS202B"); + sd->sensor = SENSOR_PAS202B; +- sd->sharpness = 1; ++/* sd->sharpness = 1; */ + break; + case 0x0f: + PDEBUG(D_PROBE, "Find Sensor PAS106"); + sd->sensor = SENSOR_PAS106; +- vga = 0; /* SIF */ + break; + case 0x10: + case 0x12: +@@ -6770,31 +6800,42 @@ static int sd_config(struct gspca_dev *gspca_dev, + if (sensor < 0x20) { + if (sensor == -1 || sensor == 0x10 || sensor == 0x12) + reg_w(gspca_dev->dev, 0x02, 0x0010); ++#if 0 + else + reg_w(gspca_dev->dev, sensor & 0x0f, 0x0010); ++#endif + reg_r(gspca_dev, 0x0010); + } + + cam = &gspca_dev->cam; + /*fixme:test*/ + gspca_dev->nbalt--; +- if (vga) { +- cam->cam_mode = vga_mode; +- cam->nmodes = ARRAY_SIZE(vga_mode); +- } else { ++ switch (mode_tb[sd->sensor]) { ++ case 0: + cam->cam_mode = sif_mode; + cam->nmodes = ARRAY_SIZE(sif_mode); ++ break; ++ case 1: ++ cam->cam_mode = vga_mode; ++ cam->nmodes = ARRAY_SIZE(vga_mode); ++ break; ++ default: ++/* case 2: */ ++ cam->cam_mode = broken_vga_mode; ++ cam->nmodes = ARRAY_SIZE(broken_vga_mode); ++ break; + } +- sd->brightness = sd_ctrls[SD_BRIGHTNESS].qctrl.default_value; +- sd->contrast = sd_ctrls[SD_CONTRAST].qctrl.default_value; +- sd->gamma = gamma[(int) sd->sensor]; +- sd->autogain = sd_ctrls[SD_AUTOGAIN].qctrl.default_value; +- sd->lightfreq = sd_ctrls[SD_FREQ].qctrl.default_value; ++ sd->brightness = BRIGHTNESS_DEF; ++ sd->contrast = CONTRAST_DEF; ++ sd->gamma = gamma[sd->sensor]; ++ sd->autogain = AUTOGAIN_DEF; ++ sd->lightfreq = FREQ_DEF; + sd->quality = QUALITY_DEF; + + switch (sd->sensor) { + case SENSOR_GC0305: + case SENSOR_OV7620: ++ case SENSOR_PAS202B: + case SENSOR_PO2030: + gspca_dev->ctrl_dis = (1 << BRIGHTNESS_IDX); + break; +@@ -6805,14 +6846,13 @@ static int sd_config(struct gspca_dev *gspca_dev, + break; + } + +- /* switch the led off */ +- reg_w(gspca_dev->dev, 0x01, 0x0000); + return 0; + } + + /* this function is called at probe and resume time */ + static int sd_init(struct gspca_dev *gspca_dev) + { ++ /* switch off the led */ + reg_w(gspca_dev->dev, 0x01, 0x0000); + return 0; + } +@@ -6821,28 +6861,27 @@ static int sd_start(struct gspca_dev *gspca_dev) + { + struct sd *sd = (struct sd *) gspca_dev; + struct usb_device *dev = gspca_dev->dev; +- const struct usb_action *zc3_init; + int mode; + static const struct usb_action *init_tb[SENSOR_MAX][2] = { + {adcm2700_Initial, adcm2700_InitialScale}, /* 0 */ +- {cs2102_InitialScale, cs2102_Initial}, /* 1 */ +- {cs2102K_InitialScale, cs2102K_Initial}, /* 2 */ ++ {cs2102_Initial, cs2102_InitialScale}, /* 1 */ ++ {cs2102K_Initial, cs2102K_InitialScale}, /* 2 */ + {gc0305_Initial, gc0305_InitialScale}, /* 3 */ +- {hdcs2020xb_InitialScale, hdcs2020xb_Initial}, /* 4 */ +- {hv7131bxx_InitialScale, hv7131bxx_Initial}, /* 5 */ +- {hv7131cxx_InitialScale, hv7131cxx_Initial}, /* 6 */ +- {icm105axx_InitialScale, icm105axx_Initial}, /* 7 */ +- {MC501CB_InitialScale, MC501CB_Initial}, /* 8 */ ++ {hdcs2020b_Initial, hdcs2020b_InitialScale}, /* 4 */ ++ {hv7131b_Initial, hv7131b_InitialScale}, /* 5 */ ++ {hv7131r_Initial, hv7131r_InitialScale}, /* 6 */ ++ {icm105a_Initial, icm105a_InitialScale}, /* 7 */ ++ {mc501cb_Initial, mc501cb_InitialScale}, /* 8 */ + {mi0360soc_Initial, mi0360soc_InitialScale}, /* 9 */ +- {OV7620_mode0, OV7620_mode1}, /* 10 */ +- {ov7630c_InitialScale, ov7630c_Initial}, /* 11 */ +- {pas106b_InitialScale, pas106b_Initial}, /* 12 */ ++ {ov7620_Initial, ov7620_InitialScale}, /* 10 */ ++ {ov7630c_Initial, ov7630c_InitialScale}, /* 11 */ ++ {pas106b_Initial, pas106b_InitialScale}, /* 12 */ + {pas202b_Initial, pas202b_InitialScale}, /* 13 */ + {pb0330_Initial, pb0330_InitialScale}, /* 14 */ +- {PO2030_mode0, PO2030_mode1}, /* 15 */ +- {tas5130CK_InitialScale, tas5130CK_Initial}, /* 16 */ ++ {po2030_Initial, po2030_InitialScale}, /* 15 */ ++ {tas5130cK_Initial, tas5130cK_InitialScale}, /* 16 */ + {tas5130cxx_Initial, tas5130cxx_InitialScale}, /* 17 */ +- {tas5130c_vf0250_InitialScale, tas5130c_vf0250_Initial}, ++ {tas5130c_vf0250_Initial, tas5130c_vf0250_InitialScale}, + /* 18 */ + }; + +@@ -6854,8 +6893,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + 0x21); /* JPEG 422 */ + jpeg_set_qual(sd->jpeg_hdr, sd->quality); + +- mode = gspca_dev->cam.cam_mode[(int) gspca_dev->curr_mode].priv; +- zc3_init = init_tb[(int) sd->sensor][mode]; ++ mode = gspca_dev->cam.cam_mode[gspca_dev->curr_mode].priv; + switch (sd->sensor) { + case SENSOR_HV7131C: + zcxx_probeSensor(gspca_dev); +@@ -6864,7 +6902,7 @@ static int sd_start(struct gspca_dev *gspca_dev) + usb_exchange(gspca_dev, pas106b_Initial_com); + break; + } +- usb_exchange(gspca_dev, zc3_init); ++ usb_exchange(gspca_dev, init_tb[sd->sensor][mode]); + + switch (sd->sensor) { + case SENSOR_ADCM2700: +@@ -6883,6 +6921,11 @@ static int sd_start(struct gspca_dev *gspca_dev) + reg_w(dev, 0x02, 0x003b); + reg_w(dev, 0x00, 0x0038); + break; ++ case SENSOR_PAS202B: ++ reg_w(dev, 0x03, 0x003b); ++ reg_w(dev, 0x0c, 0x003a); ++ reg_w(dev, 0x0b, 0x0039); ++ break; + } + + setmatrix(gspca_dev); +@@ -6961,13 +7004,13 @@ static int sd_start(struct gspca_dev *gspca_dev) + switch (sd->sensor) { + case SENSOR_PO2030: + msleep(50); +- reg_r(gspca_dev, 0x0008); +- reg_r(gspca_dev, 0x0007); +- /*fall thru*/ +- case SENSOR_PAS202B: + reg_w(dev, 0x00, 0x0007); /* (from win traces) */ + reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING); + break; ++ case SENSOR_PAS202B: ++ reg_w(dev, 0x32, 0x0007); /* (from win traces) */ ++ reg_w(dev, 0x02, ZC3XX_R008_CLOCKSETTING); ++ break; + } + return 0; + } +@@ -7165,6 +7208,22 @@ static int sd_get_jcomp(struct gspca_dev *gspca_dev, + return 0; + } + ++#ifdef CONFIG_INPUT ++static int sd_int_pkt_scan(struct gspca_dev *gspca_dev, ++ u8 *data, /* interrupt packet data */ ++ int len) /* interrput packet length */ ++{ ++ if (len == 8 && data[4] == 1) { ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 1); ++ input_sync(gspca_dev->input_dev); ++ input_report_key(gspca_dev->input_dev, KEY_CAMERA, 0); ++ input_sync(gspca_dev->input_dev); ++ } ++ ++ return 0; ++} ++#endif ++ + static const struct sd_desc sd_desc = { + .name = MODULE_NAME, + .ctrls = sd_ctrls, +@@ -7177,6 +7236,9 @@ static const struct sd_desc sd_desc = { + .querymenu = sd_querymenu, + .get_jcomp = sd_get_jcomp, + .set_jcomp = sd_set_jcomp, ++#ifdef CONFIG_INPUT ++ .int_pkt_scan = sd_int_pkt_scan, ++#endif + }; + + static const __devinitdata struct usb_device_id device_table[] = { +diff --git a/include/linux/videodev2.h b/include/linux/videodev2.h +index d4962a7..3793d16 100644 +--- a/include/linux/videodev2.h ++++ b/include/linux/videodev2.h +@@ -350,6 +350,7 @@ struct v4l2_pix_format { + #define V4L2_PIX_FMT_MPEG v4l2_fourcc('M', 'P', 'E', 'G') /* MPEG-1/2/4 */ + + /* Vendor-specific formats */ ++#define V4L2_PIX_FMT_CPIA1 v4l2_fourcc('C', 'P', 'I', 'A') /* cpia1 YUV */ + #define V4L2_PIX_FMT_WNVA v4l2_fourcc('W', 'N', 'V', 'A') /* Winnov hw compress */ + #define V4L2_PIX_FMT_SN9C10X v4l2_fourcc('S', '9', '1', '0') /* SN9C10x compression */ + #define V4L2_PIX_FMT_SN9C20X_I420 v4l2_fourcc('S', '9', '2', '0') /* SN9C20x YUV 4:2:0 */ +@@ -362,6 +363,7 @@ struct v4l2_pix_format { + #define V4L2_PIX_FMT_SPCA561 v4l2_fourcc('S', '5', '6', '1') /* compressed GBRG bayer */ + #define V4L2_PIX_FMT_PAC207 v4l2_fourcc('P', '2', '0', '7') /* compressed BGGR bayer */ + #define V4L2_PIX_FMT_MR97310A v4l2_fourcc('M', '3', '1', '0') /* compressed BGGR bayer */ ++#define V4L2_PIX_FMT_SN9C2028 v4l2_fourcc('S', 'O', 'N', 'X') /* compressed GBRG bayer */ + #define V4L2_PIX_FMT_SQ905C v4l2_fourcc('9', '0', '5', 'C') /* compressed RGGB bayer */ + #define V4L2_PIX_FMT_PJPG v4l2_fourcc('P', 'J', 'P', 'G') /* Pixart 73xx JPEG */ + #define V4L2_PIX_FMT_OV511 v4l2_fourcc('O', '5', '1', '1') /* ov511 JPEG */ +-- +1.7.0 + diff --git a/linux-2.6-v4l-dvb-update.patch b/linux-2.6-v4l-dvb-update.patch new file mode 100644 index 000000000..e69de29bb diff --git a/linux-2.6-vio-modalias.patch b/linux-2.6-vio-modalias.patch new file mode 100644 index 000000000..057eac781 --- /dev/null +++ b/linux-2.6-vio-modalias.patch @@ -0,0 +1,32 @@ +diff --git a/arch/powerpc/kernel/vio.c b/arch/powerpc/kernel/vio.c +index f988672..12a0851 100644 +--- a/arch/powerpc/kernel/vio.c ++++ b/arch/powerpc/kernel/vio.c +@@ -294,9 +294,27 @@ static ssize_t devspec_show(struct device *dev, + return sprintf(buf, "%s\n", of_node ? of_node->full_name : "none"); + } + ++static ssize_t modalias_show(struct device *dev, struct device_attribute *attr, ++ char *buf) ++{ ++ const struct vio_dev *vio_dev = to_vio_dev(dev); ++ struct device_node *dn; ++ const char *cp; ++ ++ dn = dev->archdata.of_node; ++ if (!dn) ++ return -ENODEV; ++ cp = of_get_property(dn, "compatible", NULL); ++ if (!cp) ++ return -ENODEV; ++ ++ return sprintf(buf, "vio:T%sS%s\n", vio_dev->type, cp); ++} ++ + static struct device_attribute vio_dev_attrs[] = { + __ATTR_RO(name), + __ATTR_RO(devspec), ++ __ATTR_RO(modalias), + __ATTR_NULL + }; + diff --git a/linux-2.6-x86-64-fbdev-primary.patch b/linux-2.6-x86-64-fbdev-primary.patch new file mode 100644 index 000000000..b35096fa1 --- /dev/null +++ b/linux-2.6-x86-64-fbdev-primary.patch @@ -0,0 +1,49 @@ +From cdd54d73203838f249291988d5f79e40fee00a05 Mon Sep 17 00:00:00 2001 +From: Dave Airlie +Date: Thu, 7 Jan 2010 16:59:06 +1000 +Subject: [PATCH] x86: allow fbdev primary video code on 64-bit. + +For some reason the 64-bit tree was doing this differently and +I can't see why it would need to. + +This correct behaviour when you have two GPUs plugged in and +32-bit put the console in one place and 64-bit in another. + +Signed-off-by: Dave Airlie +--- + arch/x86/Makefile | 2 -- + arch/x86/include/asm/fb.h | 4 ---- + 2 files changed, 0 insertions(+), 6 deletions(-) + +diff --git a/arch/x86/Makefile b/arch/x86/Makefile +index 78b32be..0a43dc5 100644 +--- a/arch/x86/Makefile ++++ b/arch/x86/Makefile +@@ -135,9 +135,7 @@ drivers-$(CONFIG_OPROFILE) += arch/x86/oprofile/ + # suspend and hibernation support + drivers-$(CONFIG_PM) += arch/x86/power/ + +-ifeq ($(CONFIG_X86_32),y) + drivers-$(CONFIG_FB) += arch/x86/video/ +-endif + + #### + # boot loader support. Several targets are kept for legacy purposes +diff --git a/arch/x86/include/asm/fb.h b/arch/x86/include/asm/fb.h +index 5301846..2519d06 100644 +--- a/arch/x86/include/asm/fb.h ++++ b/arch/x86/include/asm/fb.h +@@ -12,10 +12,6 @@ static inline void fb_pgprotect(struct file *file, struct vm_area_struct *vma, + pgprot_val(vma->vm_page_prot) |= _PAGE_PCD; + } + +-#ifdef CONFIG_X86_32 + extern int fb_is_primary_device(struct fb_info *info); +-#else +-static inline int fb_is_primary_device(struct fb_info *info) { return 0; } +-#endif + + #endif /* _ASM_X86_FB_H */ +-- +1.6.5.2 + diff --git a/linux-2.6-x86-cfi_sections.patch b/linux-2.6-x86-cfi_sections.patch new file mode 100644 index 000000000..646d4fea6 --- /dev/null +++ b/linux-2.6-x86-cfi_sections.patch @@ -0,0 +1,60 @@ +From 9e565292270a2d55524be38835104c564ac8f795 Mon Sep 17 00:00:00 2001 +From: Roland McGrath +Date: Thu, 13 May 2010 21:43:03 -0700 +Subject: [PATCH] x86: Use .cfi_sections for assembly code + +The newer assemblers support the .cfi_sections directive so we can put +the CFI from .S files into the .debug_frame section that is preserved +in unstripped vmlinux and in separate debuginfo, rather than the +.eh_frame section that is now discarded by vmlinux.lds.S. + +Signed-off-by: Roland McGrath +LKML-Reference: <20100514044303.A6FE7400BE@magilla.sf.frob.com> +Signed-off-by: H. Peter Anvin +--- + arch/x86/Makefile | 5 +++-- + arch/x86/include/asm/dwarf2.h | 12 ++++++++++++ + 2 files changed, 15 insertions(+), 2 deletions(-) + +diff --git a/arch/x86/Makefile b/arch/x86/Makefile +index 0a43dc5..8aa1b59 100644 +--- a/arch/x86/Makefile ++++ b/arch/x86/Makefile +@@ -95,8 +95,9 @@ sp-$(CONFIG_X86_64) := rsp + cfi := $(call as-instr,.cfi_startproc\n.cfi_rel_offset $(sp-y)$(comma)0\n.cfi_endproc,-DCONFIG_AS_CFI=1) + # is .cfi_signal_frame supported too? + cfi-sigframe := $(call as-instr,.cfi_startproc\n.cfi_signal_frame\n.cfi_endproc,-DCONFIG_AS_CFI_SIGNAL_FRAME=1) +-KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) +-KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) ++cfi-sections := $(call as-instr,.cfi_sections .debug_frame,-DCONFIG_AS_CFI_SECTIONS=1) ++KBUILD_AFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) ++KBUILD_CFLAGS += $(cfi) $(cfi-sigframe) $(cfi-sections) + + LDFLAGS := -m elf_$(UTS_MACHINE) + +diff --git a/arch/x86/include/asm/dwarf2.h b/arch/x86/include/asm/dwarf2.h +index ae6253a..733f7e9 100644 +--- a/arch/x86/include/asm/dwarf2.h ++++ b/arch/x86/include/asm/dwarf2.h +@@ -34,6 +34,18 @@ + #define CFI_SIGNAL_FRAME + #endif + ++#if defined(CONFIG_AS_CFI_SECTIONS) && defined(__ASSEMBLY__) ++ /* ++ * Emit CFI data in .debug_frame sections, not .eh_frame sections. ++ * The latter we currently just discard since we don't do DWARF ++ * unwinding at runtime. So only the offline DWARF information is ++ * useful to anyone. Note we should not use this directive if this ++ * file is used in the vDSO assembly, or if vmlinux.lds.S gets ++ * changed so it doesn't discard .eh_frame. ++ */ ++ .cfi_sections .debug_frame ++#endif ++ + #else + + /* +-- +1.7.0.1 + diff --git a/linux-2.6.29-sparc-IOC_TYPECHECK.patch b/linux-2.6.29-sparc-IOC_TYPECHECK.patch new file mode 100644 index 000000000..d73c30adc --- /dev/null +++ b/linux-2.6.29-sparc-IOC_TYPECHECK.patch @@ -0,0 +1,21 @@ +diff -up vanilla-2.6.29-rc7-git2/arch/sparc/include/asm/ioctl.h.BAD vanilla-2.6.29-rc7-git2/arch/sparc/include/asm/ioctl.h +--- vanilla-2.6.29-rc7-git2/arch/sparc/include/asm/ioctl.h.BAD 2009-03-09 17:01:32.000000000 -0400 ++++ vanilla-2.6.29-rc7-git2/arch/sparc/include/asm/ioctl.h 2009-03-09 16:52:27.000000000 -0400 +@@ -41,6 +41,17 @@ + ((nr) << _IOC_NRSHIFT) | \ + ((size) << _IOC_SIZESHIFT)) + ++#ifdef __KERNEL__ ++/* provoke compile error for invalid uses of size argument */ ++extern unsigned int __invalid_size_argument_for_IOC; ++#define _IOC_TYPECHECK(t) \ ++ ((sizeof(t) == sizeof(t[1]) && \ ++ sizeof(t) < (1 << _IOC_SIZEBITS)) ? \ ++ sizeof(t) : __invalid_size_argument_for_IOC) ++#else ++#define _IOC_TYPECHECK(t) (sizeof(t)) ++#endif ++ + #define _IO(type,nr) _IOC(_IOC_NONE,(type),(nr),0) + #define _IOR(type,nr,size) _IOC(_IOC_READ,(type),(nr),sizeof(size)) + #define _IOW(type,nr,size) _IOC(_IOC_WRITE,(type),(nr),sizeof(size)) diff --git a/linux-2.6.30-hush-rom-warning.patch b/linux-2.6.30-hush-rom-warning.patch new file mode 100644 index 000000000..3486ea760 --- /dev/null +++ b/linux-2.6.30-hush-rom-warning.patch @@ -0,0 +1,41 @@ +From fe97564a6c40c1dd1e760ea9543d63709907d577 Mon Sep 17 00:00:00 2001 +From: Kyle McMartin +Date: Mon, 11 Jan 2010 08:31:34 -0500 +Subject: linux-2.6.30-hush-rom-warning.patch + +--- + drivers/pci/setup-res.c | 11 ++++++++--- + 1 files changed, 8 insertions(+), 3 deletions(-) + +diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c +index 7d678bb..5acac72 100644 +--- a/drivers/pci/setup-res.c ++++ b/drivers/pci/setup-res.c +@@ -95,6 +95,7 @@ int pci_claim_resource(struct pci_dev *dev, int resource) + struct resource *res = &dev->resource[resource]; + struct resource *root; + int err; ++ const char *dtype = resource < PCI_BRIDGE_RESOURCES ? "device" : "bridge"; + + root = pci_find_parent_resource(dev, res); + if (!root) { +@@ -104,9 +105,13 @@ int pci_claim_resource(struct pci_dev *dev, int resource) + } + + err = request_resource(root, res); +- if (err) +- dev_err(&dev->dev, +- "address space collision: %pR already in use\n", res); ++ if (err) ++ if (resource == 6) /* KERN_INFO on ROM. */ ++ dev_info(&dev->dev, ++ "address space collision: %pR already in use\n", res); ++ else ++ dev_err(&dev->dev, ++ "address space collision: %pR already in use\n", res); + + return err; + } +-- +1.6.5.2 + diff --git a/linux-2.6.30-no-pcspkr-modalias.patch b/linux-2.6.30-no-pcspkr-modalias.patch new file mode 100644 index 000000000..c703b8844 --- /dev/null +++ b/linux-2.6.30-no-pcspkr-modalias.patch @@ -0,0 +1,11 @@ +diff -up linux-2.6.30.noarch/drivers/input/misc/pcspkr.c.jx linux-2.6.30.noarch/drivers/input/misc/pcspkr.c +--- linux-2.6.30.noarch/drivers/input/misc/pcspkr.c.jx 2009-07-28 16:54:44.000000000 -0400 ++++ linux-2.6.30.noarch/drivers/input/misc/pcspkr.c 2009-07-28 16:59:36.000000000 -0400 +@@ -23,7 +23,6 @@ + MODULE_AUTHOR("Vojtech Pavlik "); + MODULE_DESCRIPTION("PC Speaker beeper driver"); + MODULE_LICENSE("GPL"); +-MODULE_ALIAS("platform:pcspkr"); + + #if defined(CONFIG_MIPS) || defined(CONFIG_X86) + /* Use the global PIT lock ! */ diff --git a/lirc-2.6.33.patch b/lirc-2.6.33.patch new file mode 100644 index 000000000..ea4f28dba --- /dev/null +++ b/lirc-2.6.33.patch @@ -0,0 +1,17434 @@ +lirc drivers, 2010.04.05 + +Generated against linus/master from the linux-2.6-lirc.git tree at +http://git.kernel.org/?p=linux/kernel/git/jarod/linux-2.6-lirc.git;a=summary + +Also includes a pure input imon driver, which used to be part of lirc_imon... + +Signed-off-by: Jarod Wilson + +--- + MAINTAINERS | 9 + + drivers/input/Kconfig | 2 + + drivers/input/Makefile | 2 + + drivers/input/lirc/Kconfig | 116 ++ + drivers/input/lirc/Makefile | 21 + + drivers/input/lirc/lirc_bt829.c | 383 +++++ + drivers/input/lirc/lirc_dev.c | 850 +++++++++++ + drivers/input/lirc/lirc_dev.h | 228 +++ + drivers/input/lirc/lirc_ene0100.c | 646 +++++++++ + drivers/input/lirc/lirc_ene0100.h | 169 +++ + drivers/input/lirc/lirc_i2c.c | 536 +++++++ + drivers/input/lirc/lirc_igorplugusb.c | 555 ++++++++ + drivers/input/lirc/lirc_imon.c | 1053 ++++++++++++++ + drivers/input/lirc/lirc_it87.c | 1021 +++++++++++++ + drivers/input/lirc/lirc_it87.h | 116 ++ + drivers/input/lirc/lirc_ite8709.c | 540 +++++++ + drivers/input/lirc/lirc_mceusb.c | 1385 ++++++++++++++++++ + drivers/input/lirc/lirc_parallel.c | 709 +++++++++ + drivers/input/lirc/lirc_parallel.h | 26 + + drivers/input/lirc/lirc_sasem.c | 931 ++++++++++++ + drivers/input/lirc/lirc_serial.c | 1317 +++++++++++++++++ + drivers/input/lirc/lirc_sir.c | 1283 +++++++++++++++++ + drivers/input/lirc/lirc_streamzap.c | 821 +++++++++++ + drivers/input/lirc/lirc_ttusbir.c | 397 ++++++ + drivers/input/lirc/lirc_zilog.c | 1388 ++++++++++++++++++ + drivers/input/misc/Kconfig | 12 + + drivers/input/misc/Makefile | 1 + + drivers/input/misc/imon.c | 2523 +++++++++++++++++++++++++++++++++ + include/linux/lirc.h | 159 +++ + 29 files changed, 17199 insertions(+), 0 deletions(-) + +diff --git a/MAINTAINERS b/MAINTAINERS +index 47cc449..ae38439 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -3427,6 +3427,15 @@ F: arch/powerpc/platforms/pasemi/ + F: drivers/*/*pasemi* + F: drivers/*/*/*pasemi* + ++LINUX INFRARED REMOTE CONTROL DRIVERS (LIRC) ++P: Jarod Wilson ++M: jarod@redhat.com ++P: Christoph Bartelmus ++M: lirc@bartelmus.de ++W: http://www.lirc.org/ ++L: lirc-list@lists.sourceforge.net ++S: Maintained ++ + LINUX SECURITY MODULE (LSM) FRAMEWORK + M: Chris Wright + L: linux-security-module@vger.kernel.org +diff --git a/drivers/input/Kconfig b/drivers/input/Kconfig +index 07c2cd4..ebc8743 100644 +--- a/drivers/input/Kconfig ++++ b/drivers/input/Kconfig +@@ -183,6 +183,8 @@ source "drivers/input/tablet/Kconfig" + + source "drivers/input/touchscreen/Kconfig" + ++source "drivers/input/lirc/Kconfig" ++ + source "drivers/input/misc/Kconfig" + + endif +diff --git a/drivers/input/Makefile b/drivers/input/Makefile +index 7ad212d..cb119e7 100644 +--- a/drivers/input/Makefile ++++ b/drivers/input/Makefile +@@ -26,3 +26,5 @@ obj-$(CONFIG_INPUT_MISC) += misc/ + obj-$(CONFIG_INPUT_APMPOWER) += apm-power.o + + obj-$(CONFIG_XEN_KBDDEV_FRONTEND) += xen-kbdfront.o ++ ++obj-$(CONFIG_INPUT_LIRC) += lirc/ +diff --git a/drivers/input/lirc/Kconfig b/drivers/input/lirc/Kconfig +new file mode 100644 +index 0000000..86fc063 +--- /dev/null ++++ b/drivers/input/lirc/Kconfig +@@ -0,0 +1,116 @@ ++# ++# LIRC driver(s) configuration ++# ++menuconfig INPUT_LIRC ++ tristate "Linux Infrared Remote Control IR receiver/transmitter drivers" ++ help ++ Say Y here, and all supported Linux Infrared Remote Control IR and ++ RF receiver and transmitter drivers will be displayed. When paired ++ with a remote control and the lirc daemon, the receiver drivers ++ allow control of your Linux system via remote control. ++ ++if INPUT_LIRC ++ ++config LIRC_BT829 ++ tristate "BT829 based hardware" ++ depends on INPUT_LIRC ++ help ++ Driver for the IR interface on BT829-based hardware ++ ++config LIRC_ENE0100 ++ tristate "ENE KB3924/ENE0100 CIR Port Reciever" ++ depends on INPUT_LIRC ++ help ++ This is a driver for CIR port handled by ENE KB3924 embedded ++ controller found on some notebooks. ++ It appears on PNP list as ENE0100. ++ ++config LIRC_I2C ++ tristate "I2C Based IR Receivers" ++ depends on INPUT_LIRC ++ help ++ Driver for I2C-based IR receivers, such as those commonly ++ found onboard Hauppauge PVR-150/250/350 video capture cards ++ ++config LIRC_IGORPLUGUSB ++ tristate "Igor Cesko's USB IR Receiver" ++ depends on INPUT_LIRC && USB ++ help ++ Driver for Igor Cesko's USB IR Receiver ++ ++config LIRC_IMON ++ tristate "Legacy SoundGraph iMON Receiver and Display" ++ depends on INPUT_LIRC ++ help ++ Driver for the original SoundGraph iMON IR Receiver and Display ++ ++ Current generation iMON devices use the input layer imon driver. ++ ++config LIRC_IT87 ++ tristate "ITE IT87XX CIR Port Receiver" ++ depends on INPUT_LIRC ++ help ++ Driver for the ITE IT87xx IR Receiver ++ ++config LIRC_ITE8709 ++ tristate "ITE8709 CIR Port Receiver" ++ depends on INPUT_LIRC && PNP ++ help ++ Driver for the ITE8709 IR Receiver ++ ++config LIRC_MCEUSB ++ tristate "Windows Media Center Ed. USB IR Transceiver" ++ depends on INPUT_LIRC && USB ++ help ++ Driver for Windows Media Center Ed. USB IR Transceivers ++ ++config LIRC_PARALLEL ++ tristate "Homebrew Parallel Port Receiver" ++ depends on INPUT_LIRC && !SMP ++ help ++ Driver for Homebrew Parallel Port Receivers ++ ++config LIRC_SASEM ++ tristate "Sasem USB IR Remote" ++ depends on INPUT_LIRC ++ help ++ Driver for the Sasem OnAir Remocon-V or Dign HV5 HTPC IR/VFD Module ++ ++config LIRC_SERIAL ++ tristate "Homebrew Serial Port Receiver" ++ depends on INPUT_LIRC ++ help ++ Driver for Homebrew Serial Port Receivers ++ ++config LIRC_SERIAL_TRANSMITTER ++ bool "Serial Port Transmitter" ++ default y ++ depends on LIRC_SERIAL ++ help ++ Serial Port Transmitter support ++ ++config LIRC_SIR ++ tristate "Built-in SIR IrDA port" ++ depends on INPUT_LIRC ++ help ++ Driver for the SIR IrDA port ++ ++config LIRC_STREAMZAP ++ tristate "Streamzap PC Receiver" ++ depends on INPUT_LIRC ++ help ++ Driver for the Streamzap PC Receiver ++ ++config LIRC_TTUSBIR ++ tristate "Technotrend USB IR Receiver" ++ depends on INPUT_LIRC && USB ++ help ++ Driver for the Technotrend USB IR Receiver ++ ++config LIRC_ZILOG ++ tristate "Zilog/Hauppauge IR Transmitter" ++ depends on INPUT_LIRC ++ help ++ Driver for the Zilog/Hauppauge IR Transmitter, found on ++ PVR-150/500, HVR-1200/1250/1700/1800, HD-PVR and other cards ++endif +diff --git a/drivers/input/lirc/Makefile b/drivers/input/lirc/Makefile +new file mode 100644 +index 0000000..9122e87 +--- /dev/null ++++ b/drivers/input/lirc/Makefile +@@ -0,0 +1,21 @@ ++# Makefile for the lirc drivers. ++# ++ ++# Each configuration option enables a list of files. ++ ++obj-$(CONFIG_INPUT_LIRC) += lirc_dev.o ++obj-$(CONFIG_LIRC_BT829) += lirc_bt829.o ++obj-$(CONFIG_LIRC_ENE0100) += lirc_ene0100.o ++obj-$(CONFIG_LIRC_I2C) += lirc_i2c.o ++obj-$(CONFIG_LIRC_IGORPLUGUSB) += lirc_igorplugusb.o ++obj-$(CONFIG_LIRC_IMON) += lirc_imon.o ++obj-$(CONFIG_LIRC_IT87) += lirc_it87.o ++obj-$(CONFIG_LIRC_ITE8709) += lirc_ite8709.o ++obj-$(CONFIG_LIRC_MCEUSB) += lirc_mceusb.o ++obj-$(CONFIG_LIRC_PARALLEL) += lirc_parallel.o ++obj-$(CONFIG_LIRC_SASEM) += lirc_sasem.o ++obj-$(CONFIG_LIRC_SERIAL) += lirc_serial.o ++obj-$(CONFIG_LIRC_SIR) += lirc_sir.o ++obj-$(CONFIG_LIRC_STREAMZAP) += lirc_streamzap.o ++obj-$(CONFIG_LIRC_TTUSBIR) += lirc_ttusbir.o ++obj-$(CONFIG_LIRC_ZILOG) += lirc_zilog.o +diff --git a/drivers/input/lirc/lirc_bt829.c b/drivers/input/lirc/lirc_bt829.c +new file mode 100644 +index 0000000..0485884 +--- /dev/null ++++ b/drivers/input/lirc/lirc_bt829.c +@@ -0,0 +1,383 @@ ++/* ++ * Remote control driver for the TV-card based on bt829 ++ * ++ * by Leonid Froenchenko ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++*/ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "lirc_dev.h" ++ ++static int poll_main(void); ++static int atir_init_start(void); ++ ++static void write_index(unsigned char index, unsigned int value); ++static unsigned int read_index(unsigned char index); ++ ++static void do_i2c_start(void); ++static void do_i2c_stop(void); ++ ++static void seems_wr_byte(unsigned char al); ++static unsigned char seems_rd_byte(void); ++ ++static unsigned int read_index(unsigned char al); ++static void write_index(unsigned char ah, unsigned int edx); ++ ++static void cycle_delay(int cycle); ++ ++static void do_set_bits(unsigned char bl); ++static unsigned char do_get_bits(void); ++ ++#define DATA_PCI_OFF 0x7FFC00 ++#define WAIT_CYCLE 20 ++ ++#define DRIVER_NAME "lirc_bt829" ++ ++static int debug; ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG DRIVER_NAME ": "fmt, ## args); \ ++ } while (0) ++ ++static int atir_minor; ++static unsigned long pci_addr_phys; ++static unsigned char *pci_addr_lin; ++ ++static struct lirc_driver atir_driver; ++ ++static struct pci_dev *do_pci_probe(void) ++{ ++ struct pci_dev *my_dev; ++ my_dev = pci_get_device(PCI_VENDOR_ID_ATI, ++ PCI_DEVICE_ID_ATI_264VT, NULL); ++ if (my_dev) { ++ printk(KERN_ERR DRIVER_NAME ": Using device: %s\n", ++ pci_name(my_dev)); ++ pci_addr_phys = 0; ++ if (my_dev->resource[0].flags & IORESOURCE_MEM) { ++ pci_addr_phys = my_dev->resource[0].start; ++ printk(KERN_INFO DRIVER_NAME ": memory at 0x%08X \n", ++ (unsigned int)pci_addr_phys); ++ } ++ if (pci_addr_phys == 0) { ++ printk(KERN_ERR DRIVER_NAME ": no memory resource ?\n"); ++ return NULL; ++ } ++ } else { ++ printk(KERN_ERR DRIVER_NAME ": pci_probe failed\n"); ++ return NULL; ++ } ++ return my_dev; ++} ++ ++static int atir_add_to_buf(void *data, struct lirc_buffer *buf) ++{ ++ unsigned char key; ++ int status; ++ status = poll_main(); ++ key = (status >> 8) & 0xFF; ++ if (status & 0xFF) { ++ dprintk("reading key %02X\n", key); ++ lirc_buffer_write(buf, &key); ++ return 0; ++ } ++ return -ENODATA; ++} ++ ++static int atir_set_use_inc(void *data) ++{ ++ dprintk("driver is opened\n"); ++ return 0; ++} ++ ++static void atir_set_use_dec(void *data) ++{ ++ dprintk("driver is closed\n"); ++} ++ ++int init_module(void) ++{ ++ struct pci_dev *pdev; ++ ++ pdev = do_pci_probe(); ++ if (pdev == NULL) ++ return 1; ++ ++ if (!atir_init_start()) ++ return 1; ++ ++ strcpy(atir_driver.name, "ATIR"); ++ atir_driver.minor = -1; ++ atir_driver.code_length = 8; ++ atir_driver.sample_rate = 10; ++ atir_driver.data = 0; ++ atir_driver.add_to_buf = atir_add_to_buf; ++ atir_driver.set_use_inc = atir_set_use_inc; ++ atir_driver.set_use_dec = atir_set_use_dec; ++ atir_driver.dev = &pdev->dev; ++ atir_driver.owner = THIS_MODULE; ++ ++ atir_minor = lirc_register_driver(&atir_driver); ++ if (atir_minor < 0) { ++ printk(KERN_ERR DRIVER_NAME ": failed to register driver!\n"); ++ return atir_minor; ++ } ++ dprintk("driver is registered on minor %d\n", atir_minor); ++ ++ return 0; ++} ++ ++ ++void cleanup_module(void) ++{ ++ lirc_unregister_driver(atir_minor); ++} ++ ++ ++static int atir_init_start(void) ++{ ++ pci_addr_lin = ioremap(pci_addr_phys + DATA_PCI_OFF, 0x400); ++ if (pci_addr_lin == 0) { ++ printk(KERN_INFO DRIVER_NAME ": pci mem must be mapped\n"); ++ return 0; ++ } ++ return 1; ++} ++ ++static void cycle_delay(int cycle) ++{ ++ udelay(WAIT_CYCLE*cycle); ++} ++ ++ ++static int poll_main() ++{ ++ unsigned char status_high, status_low; ++ ++ do_i2c_start(); ++ ++ seems_wr_byte(0xAA); ++ seems_wr_byte(0x01); ++ ++ do_i2c_start(); ++ ++ seems_wr_byte(0xAB); ++ ++ status_low = seems_rd_byte(); ++ status_high = seems_rd_byte(); ++ ++ do_i2c_stop(); ++ ++ return (status_high << 8) | status_low; ++} ++ ++static void do_i2c_start(void) ++{ ++ do_set_bits(3); ++ cycle_delay(4); ++ ++ do_set_bits(1); ++ cycle_delay(7); ++ ++ do_set_bits(0); ++ cycle_delay(2); ++} ++ ++static void do_i2c_stop(void) ++{ ++ unsigned char bits; ++ bits = do_get_bits() & 0xFD; ++ do_set_bits(bits); ++ cycle_delay(1); ++ ++ bits |= 1; ++ do_set_bits(bits); ++ cycle_delay(2); ++ ++ bits |= 2; ++ do_set_bits(bits); ++ bits = 3; ++ do_set_bits(bits); ++ cycle_delay(2); ++} ++ ++static void seems_wr_byte(unsigned char value) ++{ ++ int i; ++ unsigned char reg; ++ ++ reg = do_get_bits(); ++ for (i = 0; i < 8; i++) { ++ if (value & 0x80) ++ reg |= 0x02; ++ else ++ reg &= 0xFD; ++ ++ do_set_bits(reg); ++ cycle_delay(1); ++ ++ reg |= 1; ++ do_set_bits(reg); ++ cycle_delay(1); ++ ++ reg &= 0xFE; ++ do_set_bits(reg); ++ cycle_delay(1); ++ value <<= 1; ++ } ++ cycle_delay(2); ++ ++ reg |= 2; ++ do_set_bits(reg); ++ ++ reg |= 1; ++ do_set_bits(reg); ++ ++ cycle_delay(1); ++ do_get_bits(); ++ ++ reg &= 0xFE; ++ do_set_bits(reg); ++ cycle_delay(3); ++} ++ ++static unsigned char seems_rd_byte(void) ++{ ++ int i; ++ int rd_byte; ++ unsigned char bits_2, bits_1; ++ ++ bits_1 = do_get_bits() | 2; ++ do_set_bits(bits_1); ++ ++ rd_byte = 0; ++ for (i = 0; i < 8; i++) { ++ bits_1 &= 0xFE; ++ do_set_bits(bits_1); ++ cycle_delay(2); ++ ++ bits_1 |= 1; ++ do_set_bits(bits_1); ++ cycle_delay(1); ++ ++ bits_2 = do_get_bits(); ++ if (bits_2 & 2) ++ rd_byte |= 1; ++ ++ rd_byte <<= 1; ++ } ++ ++ bits_1 = 0; ++ if (bits_2 == 0) ++ bits_1 |= 2; ++ ++ do_set_bits(bits_1); ++ cycle_delay(2); ++ ++ bits_1 |= 1; ++ do_set_bits(bits_1); ++ cycle_delay(3); ++ ++ bits_1 &= 0xFE; ++ do_set_bits(bits_1); ++ cycle_delay(2); ++ ++ rd_byte >>= 1; ++ rd_byte &= 0xFF; ++ return rd_byte; ++} ++ ++static void do_set_bits(unsigned char new_bits) ++{ ++ int reg_val; ++ reg_val = read_index(0x34); ++ if (new_bits & 2) { ++ reg_val &= 0xFFFFFFDF; ++ reg_val |= 1; ++ } else { ++ reg_val &= 0xFFFFFFFE; ++ reg_val |= 0x20; ++ } ++ reg_val |= 0x10; ++ write_index(0x34, reg_val); ++ ++ reg_val = read_index(0x31); ++ if (new_bits & 1) ++ reg_val |= 0x1000000; ++ else ++ reg_val &= 0xFEFFFFFF; ++ ++ reg_val |= 0x8000000; ++ write_index(0x31, reg_val); ++} ++ ++static unsigned char do_get_bits(void) ++{ ++ unsigned char bits; ++ int reg_val; ++ ++ reg_val = read_index(0x34); ++ reg_val |= 0x10; ++ reg_val &= 0xFFFFFFDF; ++ write_index(0x34, reg_val); ++ ++ reg_val = read_index(0x34); ++ bits = 0; ++ if (reg_val & 8) ++ bits |= 2; ++ else ++ bits &= 0xFD; ++ ++ reg_val = read_index(0x31); ++ if (reg_val & 0x1000000) ++ bits |= 1; ++ else ++ bits &= 0xFE; ++ ++ return bits; ++} ++ ++static unsigned int read_index(unsigned char index) ++{ ++ unsigned char *addr; ++ unsigned int value; ++ /* addr = pci_addr_lin + DATA_PCI_OFF + ((index & 0xFF) << 2); */ ++ addr = pci_addr_lin + ((index & 0xFF) << 2); ++ value = readl(addr); ++ return value; ++} ++ ++static void write_index(unsigned char index, unsigned int reg_val) ++{ ++ unsigned char *addr; ++ addr = pci_addr_lin + ((index & 0xFF) << 2); ++ writel(reg_val, addr); ++} ++ ++MODULE_AUTHOR("Froenchenko Leonid"); ++MODULE_DESCRIPTION("IR remote driver for bt829 based TV cards"); ++MODULE_LICENSE("GPL"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Debug enabled or not"); +diff --git a/drivers/input/lirc/lirc_dev.c b/drivers/input/lirc/lirc_dev.c +new file mode 100644 +index 0000000..cd5d75a +--- /dev/null ++++ b/drivers/input/lirc/lirc_dev.c +@@ -0,0 +1,850 @@ ++/* ++ * LIRC base driver ++ * ++ * by Artur Lipowski ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#ifdef CONFIG_COMPAT ++#include ++#endif ++ ++#include ++#include "lirc_dev.h" ++ ++static int debug; ++ ++#define IRCTL_DEV_NAME "BaseRemoteCtl" ++#define NOPLUG -1 ++#define LOGHEAD "lirc_dev (%s[%d]): " ++ ++static dev_t lirc_base_dev; ++ ++struct irctl { ++ struct lirc_driver d; ++ int attached; ++ int open; ++ ++ struct mutex irctl_lock; ++ struct lirc_buffer *buf; ++ unsigned int chunk_size; ++ ++ struct task_struct *task; ++ long jiffies_to_wait; ++ ++ struct cdev cdev; ++}; ++ ++static DEFINE_MUTEX(lirc_dev_lock); ++ ++static struct irctl *irctls[MAX_IRCTL_DEVICES]; ++ ++/* Only used for sysfs but defined to void otherwise */ ++static struct class *lirc_class; ++ ++/* helper function ++ * initializes the irctl structure ++ */ ++static void init_irctl(struct irctl *ir) ++{ ++ dev_dbg(ir->d.dev, LOGHEAD "initializing irctl\n", ++ ir->d.name, ir->d.minor); ++ mutex_init(&ir->irctl_lock); ++ ir->d.minor = NOPLUG; ++} ++ ++static void cleanup(struct irctl *ir) ++{ ++ dev_dbg(ir->d.dev, LOGHEAD "cleaning up\n", ir->d.name, ir->d.minor); ++ ++ device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor)); ++ ++ if (ir->buf != ir->d.rbuf) { ++ lirc_buffer_free(ir->buf); ++ kfree(ir->buf); ++ } ++ ir->buf = NULL; ++} ++ ++/* helper function ++ * reads key codes from driver and puts them into buffer ++ * returns 0 on success ++ */ ++static int add_to_buf(struct irctl *ir) ++{ ++ if (ir->d.add_to_buf) { ++ int res = -ENODATA; ++ int got_data = 0; ++ ++ /* ++ * service the device as long as it is returning ++ * data and we have space ++ */ ++get_data: ++ res = ir->d.add_to_buf(ir->d.data, ir->buf); ++ if (res == 0) { ++ got_data++; ++ goto get_data; ++ } ++ ++ if (res == -ENODEV) ++ kthread_stop(ir->task); ++ ++ return got_data ? 0 : res; ++ } ++ ++ return 0; ++} ++ ++/* main function of the polling thread ++ */ ++static int lirc_thread(void *irctl) ++{ ++ struct irctl *ir = irctl; ++ ++ dev_dbg(ir->d.dev, LOGHEAD "poll thread started\n", ++ ir->d.name, ir->d.minor); ++ ++ do { ++ if (ir->open) { ++ if (ir->jiffies_to_wait) { ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(ir->jiffies_to_wait); ++ } ++ if (kthread_should_stop()) ++ break; ++ if (!add_to_buf(ir)) ++ wake_up_interruptible(&ir->buf->wait_poll); ++ } else { ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule(); ++ } ++ } while (!kthread_should_stop()); ++ ++ dev_dbg(ir->d.dev, LOGHEAD "poll thread ended\n", ++ ir->d.name, ir->d.minor); ++ ++ return 0; ++} ++ ++ ++static struct file_operations fops = { ++ .owner = THIS_MODULE, ++ .read = lirc_dev_fop_read, ++ .write = lirc_dev_fop_write, ++ .poll = lirc_dev_fop_poll, ++ .ioctl = lirc_dev_fop_ioctl, ++#ifdef CONFIG_COMPAT ++ .compat_ioctl = lirc_dev_fop_compat_ioctl, ++#endif ++ .open = lirc_dev_fop_open, ++ .release = lirc_dev_fop_close, ++}; ++ ++static int lirc_cdev_add(struct irctl *ir) ++{ ++ int retval; ++ struct lirc_driver *d = &ir->d; ++ ++ if (d->fops) { ++ cdev_init(&ir->cdev, d->fops); ++ ir->cdev.owner = d->owner; ++ } else { ++ cdev_init(&ir->cdev, &fops); ++ ir->cdev.owner = THIS_MODULE; ++ } ++ kobject_set_name(&ir->cdev.kobj, "lirc%d", d->minor); ++ ++ retval = cdev_add(&ir->cdev, MKDEV(MAJOR(lirc_base_dev), d->minor), 1); ++ if (retval) ++ kobject_put(&ir->cdev.kobj); ++ ++ return retval; ++} ++ ++int lirc_register_driver(struct lirc_driver *d) ++{ ++ struct irctl *ir; ++ int minor; ++ int bytes_in_key; ++ unsigned int chunk_size; ++ unsigned int buffer_size; ++ int err; ++ ++ if (!d) { ++ printk(KERN_ERR "lirc_dev: lirc_register_driver: " ++ "driver pointer must be not NULL!\n"); ++ err = -EBADRQC; ++ goto out; ++ } ++ ++ if (MAX_IRCTL_DEVICES <= d->minor) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "\"minor\" must be between 0 and %d (%d)!\n", ++ MAX_IRCTL_DEVICES-1, d->minor); ++ err = -EBADRQC; ++ goto out; ++ } ++ ++ if (1 > d->code_length || (BUFLEN * 8) < d->code_length) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "code length in bits for minor (%d) " ++ "must be less than %d!\n", ++ d->minor, BUFLEN * 8); ++ err = -EBADRQC; ++ goto out; ++ } ++ ++ dev_dbg(d->dev, "lirc_dev: lirc_register_driver: sample_rate: %d\n", ++ d->sample_rate); ++ if (d->sample_rate) { ++ if (2 > d->sample_rate || HZ < d->sample_rate) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "sample_rate must be between 2 and %d!\n", HZ); ++ err = -EBADRQC; ++ goto out; ++ } ++ if (!d->add_to_buf) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "add_to_buf cannot be NULL when " ++ "sample_rate is set\n"); ++ err = -EBADRQC; ++ goto out; ++ } ++ } else if (!(d->fops && d->fops->read) && !d->rbuf) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "fops->read and rbuf cannot all be NULL!\n"); ++ err = -EBADRQC; ++ goto out; ++ } else if (!d->rbuf) { ++ if (!(d->fops && d->fops->read && d->fops->poll && ++ d->fops->ioctl)) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "neither read, poll nor ioctl can be NULL!\n"); ++ err = -EBADRQC; ++ goto out; ++ } ++ } ++ ++ mutex_lock(&lirc_dev_lock); ++ ++ minor = d->minor; ++ ++ if (minor < 0) { ++ /* find first free slot for driver */ ++ for (minor = 0; minor < MAX_IRCTL_DEVICES; minor++) ++ if (!irctls[minor]) ++ break; ++ if (MAX_IRCTL_DEVICES == minor) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "no free slots for drivers!\n"); ++ err = -ENOMEM; ++ goto out_lock; ++ } ++ } else if (irctls[minor]) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "minor (%d) just registered!\n", minor); ++ err = -EBUSY; ++ goto out_lock; ++ } ++ ++ ir = kzalloc(sizeof(struct irctl), GFP_KERNEL); ++ if (!ir) { ++ err = -ENOMEM; ++ goto out_lock; ++ } ++ init_irctl(ir); ++ irctls[minor] = ir; ++ d->minor = minor; ++ ++ if (d->sample_rate) { ++ ir->jiffies_to_wait = HZ / d->sample_rate; ++ } else { ++ /* it means - wait for external event in task queue */ ++ ir->jiffies_to_wait = 0; ++ } ++ ++ /* some safety check 8-) */ ++ d->name[sizeof(d->name)-1] = '\0'; ++ ++ bytes_in_key = BITS_TO_LONGS(d->code_length) + ++ (d->code_length % 8 ? 1 : 0); ++ buffer_size = d->buffer_size ? d->buffer_size : BUFLEN / bytes_in_key; ++ chunk_size = d->chunk_size ? d->chunk_size : bytes_in_key; ++ ++ if (d->rbuf) { ++ ir->buf = d->rbuf; ++ } else { ++ ir->buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!ir->buf) { ++ err = -ENOMEM; ++ goto out_lock; ++ } ++ err = lirc_buffer_init(ir->buf, chunk_size, buffer_size); ++ if (err) { ++ kfree(ir->buf); ++ goto out_lock; ++ } ++ } ++ ir->chunk_size = ir->buf->chunk_size; ++ ++ if (d->features == 0) ++ d->features = LIRC_CAN_REC_LIRCCODE; ++ ++ ir->d = *d; ++ ir->d.minor = minor; ++ ++ device_create(lirc_class, ir->d.dev, ++ MKDEV(MAJOR(lirc_base_dev), ir->d.minor), NULL, ++ "lirc%u", ir->d.minor); ++ ++ if (d->sample_rate) { ++ /* try to fire up polling thread */ ++ ir->task = kthread_run(lirc_thread, (void *)ir, "lirc_dev"); ++ if (IS_ERR(ir->task)) { ++ dev_err(d->dev, "lirc_dev: lirc_register_driver: " ++ "cannot run poll thread for minor = %d\n", ++ d->minor); ++ err = -ECHILD; ++ goto out_sysfs; ++ } ++ } ++ ++ err = lirc_cdev_add(ir); ++ if (err) ++ goto out_sysfs; ++ ++ ir->attached = 1; ++ mutex_unlock(&lirc_dev_lock); ++ ++ dev_info(ir->d.dev, "lirc_dev: driver %s registered at minor = %d\n", ++ ir->d.name, ir->d.minor); ++ return minor; ++ ++out_sysfs: ++ device_destroy(lirc_class, MKDEV(MAJOR(lirc_base_dev), ir->d.minor)); ++out_lock: ++ mutex_unlock(&lirc_dev_lock); ++out: ++ return err; ++} ++EXPORT_SYMBOL(lirc_register_driver); ++ ++int lirc_unregister_driver(int minor) ++{ ++ struct irctl *ir; ++ ++ if (minor < 0 || minor >= MAX_IRCTL_DEVICES) { ++ printk(KERN_ERR "lirc_dev: lirc_unregister_driver: " ++ "\"minor (%d)\" must be between 0 and %d!\n", ++ minor, MAX_IRCTL_DEVICES-1); ++ return -EBADRQC; ++ } ++ ++ ir = irctls[minor]; ++ ++ mutex_lock(&lirc_dev_lock); ++ ++ if (ir->d.minor != minor) { ++ printk(KERN_ERR "lirc_dev: lirc_unregister_driver: " ++ "minor (%d) device not registered!", minor); ++ mutex_unlock(&lirc_dev_lock); ++ return -ENOENT; ++ } ++ ++ /* end up polling thread */ ++ if (ir->task) ++ kthread_stop(ir->task); ++ ++ dev_dbg(ir->d.dev, "lirc_dev: driver %s unregistered from minor = %d\n", ++ ir->d.name, ir->d.minor); ++ ++ ir->attached = 0; ++ if (ir->open) { ++ dev_dbg(ir->d.dev, LOGHEAD "releasing opened driver\n", ++ ir->d.name, ir->d.minor); ++ wake_up_interruptible(&ir->buf->wait_poll); ++ mutex_lock(&ir->irctl_lock); ++ ir->d.set_use_dec(ir->d.data); ++ module_put(ir->d.owner); ++ mutex_unlock(&ir->irctl_lock); ++ cdev_del(&ir->cdev); ++ } else { ++ cleanup(ir); ++ cdev_del(&ir->cdev); ++ kfree(ir); ++ irctls[minor] = NULL; ++ } ++ ++ mutex_unlock(&lirc_dev_lock); ++ ++ return 0; ++} ++EXPORT_SYMBOL(lirc_unregister_driver); ++ ++int lirc_dev_fop_open(struct inode *inode, struct file *file) ++{ ++ struct irctl *ir; ++ int retval = 0; ++ ++ if (iminor(inode) >= MAX_IRCTL_DEVICES) { ++ printk(KERN_WARNING "lirc_dev [%d]: open result = -ENODEV\n", ++ iminor(inode)); ++ return -ENODEV; ++ } ++ ++ if (mutex_lock_interruptible(&lirc_dev_lock)) ++ return -ERESTARTSYS; ++ ++ ir = irctls[iminor(inode)]; ++ if (!ir) { ++ retval = -ENODEV; ++ goto error; ++ } ++ ++ dev_dbg(ir->d.dev, LOGHEAD "open called\n", ir->d.name, ir->d.minor); ++ ++ if (ir->d.minor == NOPLUG) { ++ retval = -ENODEV; ++ goto error; ++ } ++ ++ if (ir->open) { ++ retval = -EBUSY; ++ goto error; ++ } ++ ++ if (try_module_get(ir->d.owner)) { ++ ++ir->open; ++ retval = ir->d.set_use_inc(ir->d.data); ++ ++ if (retval) { ++ module_put(ir->d.owner); ++ --ir->open; ++ } else { ++ lirc_buffer_clear(ir->buf); ++ } ++ if (ir->task) ++ wake_up_process(ir->task); ++ } ++ ++error: ++ if (ir) ++ dev_dbg(ir->d.dev, LOGHEAD "open result = %d\n", ++ ir->d.name, ir->d.minor, retval); ++ ++ mutex_unlock(&lirc_dev_lock); ++ ++ return retval; ++} ++EXPORT_SYMBOL(lirc_dev_fop_open); ++ ++int lirc_dev_fop_close(struct inode *inode, struct file *file) ++{ ++ struct irctl *ir = irctls[iminor(inode)]; ++ ++ dev_dbg(ir->d.dev, LOGHEAD "close called\n", ir->d.name, ir->d.minor); ++ ++ WARN_ON(mutex_lock_killable(&lirc_dev_lock)); ++ ++ --ir->open; ++ if (ir->attached) { ++ ir->d.set_use_dec(ir->d.data); ++ module_put(ir->d.owner); ++ } else { ++ cleanup(ir); ++ irctls[ir->d.minor] = NULL; ++ kfree(ir); ++ } ++ ++ mutex_unlock(&lirc_dev_lock); ++ ++ return 0; ++} ++EXPORT_SYMBOL(lirc_dev_fop_close); ++ ++unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait) ++{ ++ struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; ++ unsigned int ret; ++ ++ dev_dbg(ir->d.dev, LOGHEAD "poll called\n", ir->d.name, ir->d.minor); ++ ++ if (!ir->attached) { ++ mutex_unlock(&ir->irctl_lock); ++ return POLLERR; ++ } ++ ++ poll_wait(file, &ir->buf->wait_poll, wait); ++ ++ if (ir->buf) ++ if (lirc_buffer_empty(ir->buf)) ++ ret = 0; ++ else ++ ret = POLLIN | POLLRDNORM; ++ else ++ ret = POLLERR; ++ ++ dev_dbg(ir->d.dev, LOGHEAD "poll result = %d\n", ++ ir->d.name, ir->d.minor, ret); ++ ++ return ret; ++} ++EXPORT_SYMBOL(lirc_dev_fop_poll); ++ ++int lirc_dev_fop_ioctl(struct inode *inode, struct file *file, ++ unsigned int cmd, unsigned long arg) ++{ ++ unsigned long mode; ++ int result = 0; ++ struct irctl *ir = irctls[iminor(inode)]; ++ ++ dev_dbg(ir->d.dev, LOGHEAD "ioctl called (0x%x)\n", ++ ir->d.name, ir->d.minor, cmd); ++ ++ if (ir->d.minor == NOPLUG || !ir->attached) { ++ dev_dbg(ir->d.dev, LOGHEAD "ioctl result = -ENODEV\n", ++ ir->d.name, ir->d.minor); ++ return -ENODEV; ++ } ++ ++ switch (cmd) { ++ case LIRC_GET_FEATURES: ++ result = put_user(ir->d.features, (unsigned long *)arg); ++ break; ++ case LIRC_GET_REC_MODE: ++ if (!(ir->d.features & LIRC_CAN_REC_MASK)) ++ return -ENOSYS; ++ ++ result = put_user(LIRC_REC2MODE ++ (ir->d.features & LIRC_CAN_REC_MASK), ++ (unsigned long *)arg); ++ break; ++ case LIRC_SET_REC_MODE: ++ if (!(ir->d.features & LIRC_CAN_REC_MASK)) ++ return -ENOSYS; ++ ++ result = get_user(mode, (unsigned long *)arg); ++ if (!result && !(LIRC_MODE2REC(mode) & ir->d.features)) ++ result = -EINVAL; ++ /* ++ * FIXME: We should actually set the mode somehow but ++ * for now, lirc_serial doesn't support mode changing either ++ */ ++ break; ++ case LIRC_GET_LENGTH: ++ result = put_user(ir->d.code_length, (unsigned long *)arg); ++ break; ++ case LIRC_GET_MIN_TIMEOUT: ++ if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) || ++ ir->d.min_timeout == 0) ++ return -ENOSYS; ++ ++ result = put_user(ir->d.min_timeout, (int *) arg); ++ break; ++ case LIRC_GET_MAX_TIMEOUT: ++ if (!(ir->d.features & LIRC_CAN_SET_REC_TIMEOUT) || ++ ir->d.max_timeout == 0) ++ return -ENOSYS; ++ ++ result = put_user(ir->d.max_timeout, (int *) arg); ++ break; ++ default: ++ result = -EINVAL; ++ } ++ ++ dev_dbg(ir->d.dev, LOGHEAD "ioctl result = %d\n", ++ ir->d.name, ir->d.minor, result); ++ ++ return result; ++} ++EXPORT_SYMBOL(lirc_dev_fop_ioctl); ++ ++#ifdef CONFIG_COMPAT ++#define LIRC_GET_FEATURES_COMPAT32 _IOR('i', 0x00000000, __u32) ++ ++#define LIRC_GET_SEND_MODE_COMPAT32 _IOR('i', 0x00000001, __u32) ++#define LIRC_GET_REC_MODE_COMPAT32 _IOR('i', 0x00000002, __u32) ++ ++#define LIRC_GET_LENGTH_COMPAT32 _IOR('i', 0x0000000f, __u32) ++ ++#define LIRC_SET_SEND_MODE_COMPAT32 _IOW('i', 0x00000011, __u32) ++#define LIRC_SET_REC_MODE_COMPAT32 _IOW('i', 0x00000012, __u32) ++ ++long lirc_dev_fop_compat_ioctl(struct file *file, ++ unsigned int cmd32, ++ unsigned long arg) ++{ ++ mm_segment_t old_fs; ++ int ret; ++ unsigned long val; ++ unsigned int cmd; ++ ++ switch (cmd32) { ++ case LIRC_GET_FEATURES_COMPAT32: ++ case LIRC_GET_SEND_MODE_COMPAT32: ++ case LIRC_GET_REC_MODE_COMPAT32: ++ case LIRC_GET_LENGTH_COMPAT32: ++ case LIRC_SET_SEND_MODE_COMPAT32: ++ case LIRC_SET_REC_MODE_COMPAT32: ++ /* ++ * These commands expect (unsigned long *) arg ++ * but the 32-bit app supplied (__u32 *). ++ * Conversion is required. ++ */ ++ if (get_user(val, (__u32 *)compat_ptr(arg))) ++ return -EFAULT; ++ lock_kernel(); ++ /* ++ * tell lirc_dev_fop_ioctl that it's safe to use the pointer ++ * to val which is in kernel address space and not in ++ * user address space. ++ */ ++ old_fs = get_fs(); ++ set_fs(KERNEL_DS); ++ ++ cmd = _IOC(_IOC_DIR(cmd32), _IOC_TYPE(cmd32), _IOC_NR(cmd32), ++ (_IOC_TYPECHECK(unsigned long))); ++ ret = lirc_dev_fop_ioctl(file->f_path.dentry->d_inode, file, ++ cmd, (unsigned long)(&val)); ++ ++ set_fs(old_fs); ++ unlock_kernel(); ++ switch (cmd) { ++ case LIRC_GET_FEATURES: ++ case LIRC_GET_SEND_MODE: ++ case LIRC_GET_REC_MODE: ++ case LIRC_GET_LENGTH: ++ if (!ret && put_user(val, (__u32 *)compat_ptr(arg))) ++ return -EFAULT; ++ break; ++ } ++ return ret; ++ ++ case LIRC_GET_SEND_CARRIER: ++ case LIRC_GET_REC_CARRIER: ++ case LIRC_GET_SEND_DUTY_CYCLE: ++ case LIRC_GET_REC_DUTY_CYCLE: ++ case LIRC_GET_REC_RESOLUTION: ++ case LIRC_SET_SEND_CARRIER: ++ case LIRC_SET_REC_CARRIER: ++ case LIRC_SET_SEND_DUTY_CYCLE: ++ case LIRC_SET_REC_DUTY_CYCLE: ++ case LIRC_SET_TRANSMITTER_MASK: ++ case LIRC_SET_REC_DUTY_CYCLE_RANGE: ++ case LIRC_SET_REC_CARRIER_RANGE: ++ /* ++ * These commands expect (unsigned int *)arg ++ * so no problems here. Just handle the locking. ++ */ ++ lock_kernel(); ++ cmd = cmd32; ++ ret = lirc_dev_fop_ioctl(file->f_path.dentry->d_inode, ++ file, cmd, arg); ++ unlock_kernel(); ++ return ret; ++ default: ++ /* unknown */ ++ printk(KERN_ERR "lirc_dev: %s(%s:%d): Unknown cmd %08x\n", ++ __func__, current->comm, current->pid, cmd32); ++ return -ENOIOCTLCMD; ++ } ++} ++EXPORT_SYMBOL(lirc_dev_fop_compat_ioctl); ++#endif ++ ++ ++ssize_t lirc_dev_fop_read(struct file *file, ++ char *buffer, ++ size_t length, ++ loff_t *ppos) ++{ ++ struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; ++ unsigned char buf[ir->chunk_size]; ++ int ret = 0, written = 0; ++ DECLARE_WAITQUEUE(wait, current); ++ ++ dev_dbg(ir->d.dev, LOGHEAD "read called\n", ir->d.name, ir->d.minor); ++ ++ if (mutex_lock_interruptible(&ir->irctl_lock)) ++ return -ERESTARTSYS; ++ if (!ir->attached) { ++ mutex_unlock(&ir->irctl_lock); ++ return -ENODEV; ++ } ++ ++ if (length % ir->chunk_size) { ++ dev_dbg(ir->d.dev, LOGHEAD "read result = -EINVAL\n", ++ ir->d.name, ir->d.minor); ++ mutex_unlock(&ir->irctl_lock); ++ return -EINVAL; ++ } ++ ++ /* ++ * we add ourselves to the task queue before buffer check ++ * to avoid losing scan code (in case when queue is awaken somewhere ++ * between while condition checking and scheduling) ++ */ ++ add_wait_queue(&ir->buf->wait_poll, &wait); ++ set_current_state(TASK_INTERRUPTIBLE); ++ ++ /* ++ * while we didn't provide 'length' bytes, device is opened in blocking ++ * mode and 'copy_to_user' is happy, wait for data. ++ */ ++ while (written < length && ret == 0) { ++ if (lirc_buffer_empty(ir->buf)) { ++ /* According to the read(2) man page, 'written' can be ++ * returned as less than 'length', instead of blocking ++ * again, returning -EWOULDBLOCK, or returning ++ * -ERESTARTSYS */ ++ if (written) ++ break; ++ if (file->f_flags & O_NONBLOCK) { ++ ret = -EWOULDBLOCK; ++ break; ++ } ++ if (signal_pending(current)) { ++ ret = -ERESTARTSYS; ++ break; ++ } ++ ++ mutex_unlock(&ir->irctl_lock); ++ schedule(); ++ set_current_state(TASK_INTERRUPTIBLE); ++ ++ if (mutex_lock_interruptible(&ir->irctl_lock)) { ++ ret = -ERESTARTSYS; ++ break; ++ } ++ ++ if (!ir->attached) { ++ ret = -ENODEV; ++ break; ++ } ++ } else { ++ lirc_buffer_read(ir->buf, buf); ++ ret = copy_to_user((void *)buffer+written, buf, ++ ir->buf->chunk_size); ++ written += ir->buf->chunk_size; ++ } ++ } ++ ++ remove_wait_queue(&ir->buf->wait_poll, &wait); ++ set_current_state(TASK_RUNNING); ++ mutex_unlock(&ir->irctl_lock); ++ ++ dev_dbg(ir->d.dev, LOGHEAD "read result = %s (%d)\n", ++ ir->d.name, ir->d.minor, ret ? "-EFAULT" : "OK", ret); ++ ++ return ret ? ret : written; ++} ++EXPORT_SYMBOL(lirc_dev_fop_read); ++ ++void *lirc_get_pdata(struct file *file) ++{ ++ void *data = NULL; ++ ++ if (file && file->f_dentry && file->f_dentry->d_inode && ++ file->f_dentry->d_inode->i_rdev) { ++ struct irctl *ir; ++ ir = irctls[iminor(file->f_dentry->d_inode)]; ++ data = ir->d.data; ++ } ++ ++ return data; ++} ++EXPORT_SYMBOL(lirc_get_pdata); ++ ++ ++ssize_t lirc_dev_fop_write(struct file *file, const char *buffer, ++ size_t length, loff_t *ppos) ++{ ++ struct irctl *ir = irctls[iminor(file->f_dentry->d_inode)]; ++ ++ dev_dbg(ir->d.dev, LOGHEAD "write called\n", ir->d.name, ir->d.minor); ++ ++ if (!ir->attached) ++ return -ENODEV; ++ ++ return -EINVAL; ++} ++EXPORT_SYMBOL(lirc_dev_fop_write); ++ ++ ++static int __init lirc_dev_init(void) ++{ ++ int retval; ++ ++ lirc_class = class_create(THIS_MODULE, "lirc"); ++ if (IS_ERR(lirc_class)) { ++ retval = PTR_ERR(lirc_class); ++ printk(KERN_ERR "lirc_dev: class_create failed\n"); ++ goto error; ++ } ++ ++ retval = alloc_chrdev_region(&lirc_base_dev, 0, MAX_IRCTL_DEVICES, ++ IRCTL_DEV_NAME); ++ if (retval) { ++ class_destroy(lirc_class); ++ printk(KERN_ERR "lirc_dev: alloc_chrdev_region failed\n"); ++ goto error; ++ } ++ ++ ++ printk(KERN_INFO "lirc_dev: IR Remote Control driver registered, " ++ "major %d \n", MAJOR(lirc_base_dev)); ++ ++error: ++ return retval; ++} ++ ++ ++ ++static void __exit lirc_dev_exit(void) ++{ ++ class_destroy(lirc_class); ++ unregister_chrdev_region(lirc_base_dev, MAX_IRCTL_DEVICES); ++ printk(KERN_INFO "lirc_dev: module unloaded\n"); ++} ++ ++module_init(lirc_dev_init); ++module_exit(lirc_dev_exit); ++ ++MODULE_DESCRIPTION("LIRC base driver module"); ++MODULE_AUTHOR("Artur Lipowski"); ++MODULE_LICENSE("GPL"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); +diff --git a/drivers/input/lirc/lirc_dev.h b/drivers/input/lirc/lirc_dev.h +new file mode 100644 +index 0000000..56020e8 +--- /dev/null ++++ b/drivers/input/lirc/lirc_dev.h +@@ -0,0 +1,228 @@ ++/* ++ * LIRC base driver ++ * ++ * by Artur Lipowski ++ * This code is licensed under GNU GPL ++ * ++ */ ++ ++#ifndef _LINUX_LIRC_DEV_H ++#define _LINUX_LIRC_DEV_H ++ ++#define MAX_IRCTL_DEVICES 4 ++#define BUFLEN 16 ++ ++#define mod(n, div) ((n) % (div)) ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++struct lirc_buffer { ++ wait_queue_head_t wait_poll; ++ spinlock_t fifo_lock; ++ unsigned int chunk_size; ++ unsigned int size; /* in chunks */ ++ /* Using chunks instead of bytes pretends to simplify boundary checking ++ * And should allow for some performance fine tunning later */ ++ struct kfifo fifo; ++ u8 fifo_initialized; ++}; ++ ++static inline void lirc_buffer_clear(struct lirc_buffer *buf) ++{ ++ unsigned long flags; ++ ++ if (buf->fifo_initialized) { ++ spin_lock_irqsave(&buf->fifo_lock, flags); ++ kfifo_reset(&buf->fifo); ++ spin_unlock_irqrestore(&buf->fifo_lock, flags); ++ } else ++ WARN(1, "calling %s on an uninitialized lirc_buffer\n", ++ __func__); ++} ++ ++static inline int lirc_buffer_init(struct lirc_buffer *buf, ++ unsigned int chunk_size, ++ unsigned int size) ++{ ++ int ret; ++ ++ init_waitqueue_head(&buf->wait_poll); ++ spin_lock_init(&buf->fifo_lock); ++ buf->chunk_size = chunk_size; ++ buf->size = size; ++ ret = kfifo_alloc(&buf->fifo, size * chunk_size, GFP_KERNEL); ++ if (ret == 0) ++ buf->fifo_initialized = 1; ++ ++ return ret; ++} ++ ++static inline void lirc_buffer_free(struct lirc_buffer *buf) ++{ ++ if (buf->fifo_initialized) { ++ kfifo_free(&buf->fifo); ++ buf->fifo_initialized = 0; ++ } else ++ WARN(1, "calling %s on an uninitialized lirc_buffer\n", ++ __func__); ++} ++ ++static inline int lirc_buffer_len(struct lirc_buffer *buf) ++{ ++ int len; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&buf->fifo_lock, flags); ++ len = kfifo_len(&buf->fifo); ++ spin_unlock_irqrestore(&buf->fifo_lock, flags); ++ ++ return len; ++} ++ ++static inline int lirc_buffer_full(struct lirc_buffer *buf) ++{ ++ return lirc_buffer_len(buf) == buf->size * buf->chunk_size; ++} ++ ++static inline int lirc_buffer_empty(struct lirc_buffer *buf) ++{ ++ return !lirc_buffer_len(buf); ++} ++ ++static inline int lirc_buffer_available(struct lirc_buffer *buf) ++{ ++ return buf->size - (lirc_buffer_len(buf) / buf->chunk_size); ++} ++ ++static inline unsigned int lirc_buffer_read(struct lirc_buffer *buf, ++ unsigned char *dest) ++{ ++ unsigned int ret = 0; ++ ++ if (lirc_buffer_len(buf) >= buf->chunk_size) ++ ret = kfifo_out_locked(&buf->fifo, dest, buf->chunk_size, ++ &buf->fifo_lock); ++ return ret; ++ ++} ++ ++static inline unsigned int lirc_buffer_write(struct lirc_buffer *buf, ++ unsigned char *orig) ++{ ++ unsigned int ret; ++ ++ ret = kfifo_in_locked(&buf->fifo, orig, buf->chunk_size, ++ &buf->fifo_lock); ++ ++ return ret; ++} ++ ++struct lirc_driver { ++ char name[40]; ++ int minor; ++ unsigned long code_length; ++ unsigned int buffer_size; /* in chunks holding one code each */ ++ int sample_rate; ++ unsigned long features; ++ ++ unsigned int chunk_size; ++ ++ void *data; ++ int min_timeout; ++ int max_timeout; ++ int (*add_to_buf) (void *data, struct lirc_buffer *buf); ++ struct lirc_buffer *rbuf; ++ int (*set_use_inc) (void *data); ++ void (*set_use_dec) (void *data); ++ struct file_operations *fops; ++ struct device *dev; ++ struct module *owner; ++}; ++ ++/* name: ++ * this string will be used for logs ++ * ++ * minor: ++ * indicates minor device (/dev/lirc) number for registered driver ++ * if caller fills it with negative value, then the first free minor ++ * number will be used (if available) ++ * ++ * code_length: ++ * length of the remote control key code expressed in bits ++ * ++ * sample_rate: ++ * ++ * data: ++ * it may point to any driver data and this pointer will be passed to ++ * all callback functions ++ * ++ * add_to_buf: ++ * add_to_buf will be called after specified period of the time or ++ * triggered by the external event, this behavior depends on value of ++ * the sample_rate this function will be called in user context. This ++ * routine should return 0 if data was added to the buffer and ++ * -ENODATA if none was available. This should add some number of bits ++ * evenly divisible by code_length to the buffer ++ * ++ * rbuf: ++ * if not NULL, it will be used as a read buffer, you will have to ++ * write to the buffer by other means, like irq's (see also ++ * lirc_serial.c). ++ * ++ * set_use_inc: ++ * set_use_inc will be called after device is opened ++ * ++ * set_use_dec: ++ * set_use_dec will be called after device is closed ++ * ++ * fops: ++ * file_operations for drivers which don't fit the current driver model. ++ * ++ * Some ioctl's can be directly handled by lirc_dev if the driver's ++ * ioctl function is NULL or if it returns -ENOIOCTLCMD (see also ++ * lirc_serial.c). ++ * ++ * owner: ++ * the module owning this struct ++ * ++ */ ++ ++ ++/* following functions can be called ONLY from user context ++ * ++ * returns negative value on error or minor number ++ * of the registered device if success ++ * contents of the structure pointed by p is copied ++ */ ++extern int lirc_register_driver(struct lirc_driver *d); ++ ++/* returns negative value on error or 0 if success ++*/ ++extern int lirc_unregister_driver(int minor); ++ ++/* Returns the private data stored in the lirc_driver ++ * associated with the given device file pointer. ++ */ ++void *lirc_get_pdata(struct file *file); ++ ++/* default file operations ++ * used by drivers if they override only some operations ++ */ ++int lirc_dev_fop_open(struct inode *inode, struct file *file); ++int lirc_dev_fop_close(struct inode *inode, struct file *file); ++unsigned int lirc_dev_fop_poll(struct file *file, poll_table *wait); ++int lirc_dev_fop_ioctl(struct inode *inode, struct file *file, ++ unsigned int cmd, unsigned long arg); ++ssize_t lirc_dev_fop_read(struct file *file, char *buffer, size_t length, ++ loff_t *ppos); ++ssize_t lirc_dev_fop_write(struct file *file, const char *buffer, size_t length, ++ loff_t *ppos); ++long lirc_dev_fop_compat_ioctl(struct file *file, unsigned int cmd32, ++ unsigned long arg); ++ ++#endif +diff --git a/drivers/input/lirc/lirc_ene0100.c b/drivers/input/lirc/lirc_ene0100.c +new file mode 100644 +index 0000000..a152c52 +--- /dev/null ++++ b/drivers/input/lirc/lirc_ene0100.c +@@ -0,0 +1,646 @@ ++/* ++ * driver for ENE KB3926 B/C/D CIR (also known as ENE0100) ++ * ++ * Copyright (C) 2009 Maxim Levitsky ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ++ * USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include "lirc_ene0100.h" ++ ++static int sample_period = 75; ++static int enable_idle = 1; ++static int enable_learning; ++ ++static void ene_set_idle(struct ene_device *dev, int idle); ++static void ene_set_inputs(struct ene_device *dev, int enable); ++ ++/* read a hardware register */ ++static u8 ene_hw_read_reg(struct ene_device *dev, u16 reg) ++{ ++ outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); ++ outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); ++ return inb(dev->hw_io + ENE_IO); ++} ++ ++/* write a hardware register */ ++static void ene_hw_write_reg(struct ene_device *dev, u16 reg, u8 value) ++{ ++ outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); ++ outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); ++ outb(value, dev->hw_io + ENE_IO); ++} ++ ++/* change specific bits in hardware register */ ++static void ene_hw_write_reg_mask(struct ene_device *dev, ++ u16 reg, u8 value, u8 mask) ++{ ++ u8 regvalue; ++ ++ outb(reg >> 8, dev->hw_io + ENE_ADDR_HI); ++ outb(reg & 0xFF, dev->hw_io + ENE_ADDR_LO); ++ ++ regvalue = inb(dev->hw_io + ENE_IO) & ~mask; ++ regvalue |= (value & mask); ++ outb(regvalue, dev->hw_io + ENE_IO); ++} ++ ++/* read irq status and ack it */ ++static int ene_hw_irq_status(struct ene_device *dev, int *buffer_pointer) ++{ ++ u8 irq_status; ++ u8 fw_flags1, fw_flags2; ++ ++ fw_flags2 = ene_hw_read_reg(dev, ENE_FW2); ++ ++ if (buffer_pointer) ++ *buffer_pointer = 4 * (fw_flags2 & ENE_FW2_BUF_HIGH); ++ ++ if (dev->hw_revision < ENE_HW_C) { ++ irq_status = ene_hw_read_reg(dev, ENEB_IRQ_STATUS); ++ ++ if (!(irq_status & ENEB_IRQ_STATUS_IR)) ++ return 0; ++ ene_hw_write_reg(dev, ENEB_IRQ_STATUS, ++ irq_status & ~ENEB_IRQ_STATUS_IR); ++ ++ /* rev B support only recieving */ ++ return ENE_IRQ_RX; ++ } ++ ++ irq_status = ene_hw_read_reg(dev, ENEC_IRQ); ++ ++ if (!(irq_status & ENEC_IRQ_STATUS)) ++ return 0; ++ ++ /* original driver does that twice - a workaround ? */ ++ ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS); ++ ene_hw_write_reg(dev, ENEC_IRQ, irq_status & ~ENEC_IRQ_STATUS); ++ ++ /* clear unknown flag in F8F9 */ ++ if (fw_flags2 & ENE_FW2_IRQ_CLR) ++ ene_hw_write_reg(dev, ENE_FW2, fw_flags2 & ~ENE_FW2_IRQ_CLR); ++ ++ /* check if this is a TX interrupt */ ++ fw_flags1 = ene_hw_read_reg(dev, ENE_FW1); ++ ++ if (fw_flags1 & ENE_FW1_TXIRQ) { ++ ene_hw_write_reg(dev, ENE_FW1, fw_flags1 & ~ENE_FW1_TXIRQ); ++ return ENE_IRQ_TX; ++ } else ++ return ENE_IRQ_RX; ++} ++ ++static int ene_hw_detect(struct ene_device *dev) ++{ ++ u8 chip_major, chip_minor; ++ u8 hw_revision, old_ver; ++ u8 tmp; ++ u8 fw_capabilities; ++ ++ tmp = ene_hw_read_reg(dev, ENE_HW_UNK); ++ ene_hw_write_reg(dev, ENE_HW_UNK, tmp & ~ENE_HW_UNK_CLR); ++ ++ chip_major = ene_hw_read_reg(dev, ENE_HW_VER_MAJOR); ++ chip_minor = ene_hw_read_reg(dev, ENE_HW_VER_MINOR); ++ ++ ene_hw_write_reg(dev, ENE_HW_UNK, tmp); ++ hw_revision = ene_hw_read_reg(dev, ENE_HW_VERSION); ++ old_ver = ene_hw_read_reg(dev, ENE_HW_VER_OLD); ++ ++ if (hw_revision == 0xFF) { ++ ++ ene_printk(KERN_WARNING, "device seems to be disabled\n"); ++ ene_printk(KERN_WARNING, ++ "send a mail to lirc-list@lists.sourceforge.net\n"); ++ ene_printk(KERN_WARNING, "please attach output of acpidump\n"); ++ ++ return -ENODEV; ++ } ++ ++ if (chip_major == 0x33) { ++ ene_printk(KERN_WARNING, "chips 0x33xx aren't supported yet\n"); ++ return -ENODEV; ++ } ++ ++ if (chip_major == 0x39 && chip_minor == 0x26 && hw_revision == 0xC0) { ++ dev->hw_revision = ENE_HW_C; ++ ene_printk(KERN_WARNING, ++ "KB3926C detected, driver support is not complete!\n"); ++ ++ } else if (old_ver == 0x24 && hw_revision == 0xC0) { ++ dev->hw_revision = ENE_HW_B; ++ ene_printk(KERN_NOTICE, "KB3926B detected\n"); ++ } else { ++ dev->hw_revision = ENE_HW_D; ++ ene_printk(KERN_WARNING, ++ "unknown ENE chip detected, assuming KB3926D\n"); ++ ene_printk(KERN_WARNING, "driver support incomplete"); ++ ++ } ++ ++ ene_printk(KERN_DEBUG, "chip is 0x%02x%02x - 0x%02x, 0x%02x\n", ++ chip_major, chip_minor, old_ver, hw_revision); ++ ++ ++ /* detect features hardware supports */ ++ ++ if (dev->hw_revision < ENE_HW_C) ++ return 0; ++ ++ fw_capabilities = ene_hw_read_reg(dev, ENE_FW2); ++ ++ dev->hw_gpio40_learning = fw_capabilities & ENE_FW2_GP40_AS_LEARN; ++ dev->hw_learning_and_tx_capable = fw_capabilities & ENE_FW2_LEARNING; ++ ++ dev->hw_fan_as_normal_input = dev->hw_learning_and_tx_capable && ++ fw_capabilities & ENE_FW2_FAN_AS_NRML_IN; ++ ++ ene_printk(KERN_NOTICE, "hardware features:\n"); ++ ene_printk(KERN_NOTICE, ++ "learning and tx %s, gpio40_learn %s, fan_in %s\n", ++ dev->hw_learning_and_tx_capable ? "on" : "off", ++ dev->hw_gpio40_learning ? "on" : "off", ++ dev->hw_fan_as_normal_input ? "on" : "off"); ++ ++ if (!dev->hw_learning_and_tx_capable && enable_learning) ++ enable_learning = 0; ++ ++ if (dev->hw_learning_and_tx_capable) { ++ ene_printk(KERN_WARNING, ++ "Device supports transmitting, but the driver doesn't\n"); ++ ene_printk(KERN_WARNING, ++ "due to lack of hardware to test against.\n"); ++ ene_printk(KERN_WARNING, ++ "Send a mail to: lirc-list@lists.sourceforge.net\n"); ++ } ++ return 0; ++} ++ ++/* hardware initialization */ ++static int ene_hw_init(void *data) ++{ ++ u8 reg_value; ++ struct ene_device *dev = (struct ene_device *)data; ++ dev->in_use = 1; ++ ++ if (dev->hw_revision < ENE_HW_C) { ++ ene_hw_write_reg(dev, ENEB_IRQ, dev->irq << 1); ++ ene_hw_write_reg(dev, ENEB_IRQ_UNK1, 0x01); ++ } else { ++ reg_value = ene_hw_read_reg(dev, ENEC_IRQ) & 0xF0; ++ reg_value |= ENEC_IRQ_UNK_EN; ++ reg_value &= ~ENEC_IRQ_STATUS; ++ reg_value |= (dev->irq & ENEC_IRQ_MASK); ++ ene_hw_write_reg(dev, ENEC_IRQ, reg_value); ++ ene_hw_write_reg(dev, ENE_TX_UNK1, 0x63); ++ } ++ ++ ene_hw_write_reg(dev, ENE_CIR_CONF2, 0x00); ++ ene_set_inputs(dev, enable_learning); ++ ++ /* set sampling period */ ++ ene_hw_write_reg(dev, ENE_CIR_SAMPLE_PERIOD, sample_period); ++ ++ /* ack any pending irqs - just in case */ ++ ene_hw_irq_status(dev, NULL); ++ ++ /* enter idle mode */ ++ ene_set_idle(dev, 1); ++ ++ /* enable firmware bits */ ++ ene_hw_write_reg_mask(dev, ENE_FW1, ++ ENE_FW1_ENABLE | ENE_FW1_IRQ, ++ ENE_FW1_ENABLE | ENE_FW1_IRQ); ++ /* clear stats */ ++ dev->sample = 0; ++ return 0; ++} ++ ++/* this enables gpio40 signal, used if connected to wide band input*/ ++static void ene_enable_gpio40(struct ene_device *dev, int enable) ++{ ++ ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, enable ? ++ 0 : ENE_CIR_CONF2_GPIO40DIS, ++ ENE_CIR_CONF2_GPIO40DIS); ++} ++ ++/* this enables the classic sampler */ ++static void ene_enable_normal_recieve(struct ene_device *dev, int enable) ++{ ++ ene_hw_write_reg(dev, ENE_CIR_CONF1, enable ? ENE_CIR_CONF1_ADC_ON : 0); ++} ++ ++/* this enables recieve via fan input */ ++static void ene_enable_fan_recieve(struct ene_device *dev, int enable) ++{ ++ if (!enable) ++ ene_hw_write_reg(dev, ENE_FAN_AS_IN1, 0); ++ else { ++ ene_hw_write_reg(dev, ENE_FAN_AS_IN1, ENE_FAN_AS_IN1_EN); ++ ene_hw_write_reg(dev, ENE_FAN_AS_IN2, ENE_FAN_AS_IN2_EN); ++ } ++ dev->fan_input_inuse = enable; ++} ++ ++/* determine which input to use*/ ++static void ene_set_inputs(struct ene_device *dev, int learning_enable) ++{ ++ ene_enable_normal_recieve(dev, 1); ++ ++ /* old hardware doesn't support learning mode for sure */ ++ if (dev->hw_revision <= ENE_HW_B) ++ return; ++ ++ /* reciever not learning capable, still set gpio40 correctly */ ++ if (!dev->hw_learning_and_tx_capable) { ++ ene_enable_gpio40(dev, !dev->hw_gpio40_learning); ++ return; ++ } ++ ++ /* enable learning mode */ ++ if (learning_enable) { ++ ene_enable_gpio40(dev, dev->hw_gpio40_learning); ++ ++ /* fan input is not used for learning */ ++ if (dev->hw_fan_as_normal_input) ++ ene_enable_fan_recieve(dev, 0); ++ ++ /* disable learning mode */ ++ } else { ++ if (dev->hw_fan_as_normal_input) { ++ ene_enable_fan_recieve(dev, 1); ++ ene_enable_normal_recieve(dev, 0); ++ } else ++ ene_enable_gpio40(dev, !dev->hw_gpio40_learning); ++ } ++ ++ /* set few additional settings for this mode */ ++ ene_hw_write_reg_mask(dev, ENE_CIR_CONF1, learning_enable ? ++ ENE_CIR_CONF1_LEARN1 : 0, ENE_CIR_CONF1_LEARN1); ++ ++ ene_hw_write_reg_mask(dev, ENE_CIR_CONF2, learning_enable ? ++ ENE_CIR_CONF2_LEARN2 : 0, ENE_CIR_CONF2_LEARN2); ++} ++ ++/* deinitialization */ ++static void ene_hw_deinit(void *data) ++{ ++ struct ene_device *dev = (struct ene_device *)data; ++ ++ /* disable samplers */ ++ ene_enable_normal_recieve(dev, 0); ++ ++ if (dev->hw_fan_as_normal_input) ++ ene_enable_fan_recieve(dev, 0); ++ ++ /* disable hardware IRQ and firmware flag */ ++ ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_ENABLE | ENE_FW1_IRQ); ++ ++ ene_set_idle(dev, 1); ++ dev->in_use = 0; ++} ++ ++/* sends current sample to userspace */ ++static void send_sample(struct ene_device *dev) ++{ ++ int value = abs(dev->sample) & PULSE_MASK; ++ ++ if (dev->sample > 0) ++ value |= PULSE_BIT; ++ ++ if (!lirc_buffer_full(dev->lirc_driver->rbuf)) { ++ lirc_buffer_write(dev->lirc_driver->rbuf, (void *)&value); ++ wake_up(&dev->lirc_driver->rbuf->wait_poll); ++ } ++ dev->sample = 0; ++} ++ ++/* this updates current sample */ ++static void update_sample(struct ene_device *dev, int sample) ++{ ++ if (!dev->sample) ++ dev->sample = sample; ++ else if (same_sign(dev->sample, sample)) ++ dev->sample += sample; ++ else { ++ send_sample(dev); ++ dev->sample = sample; ++ } ++} ++ ++/* enable or disable idle mode */ ++static void ene_set_idle(struct ene_device *dev, int idle) ++{ ++ struct timeval now; ++ int disable = idle && enable_idle && (dev->hw_revision < ENE_HW_C); ++ ++ ene_hw_write_reg_mask(dev, ENE_CIR_SAMPLE_PERIOD, ++ disable ? 0 : ENE_CIR_SAMPLE_OVERFLOW, ++ ENE_CIR_SAMPLE_OVERFLOW); ++ dev->idle = idle; ++ ++ /* remember when we have entered the idle mode */ ++ if (idle) { ++ do_gettimeofday(&dev->gap_start); ++ return; ++ } ++ ++ /* send the gap between keypresses now */ ++ do_gettimeofday(&now); ++ ++ if (now.tv_sec - dev->gap_start.tv_sec > 16) ++ dev->sample = space(PULSE_MASK); ++ else ++ dev->sample = dev->sample + ++ space(1000000ull * (now.tv_sec - dev->gap_start.tv_sec)) ++ + space(now.tv_usec - dev->gap_start.tv_usec); ++ ++ if (abs(dev->sample) > PULSE_MASK) ++ dev->sample = space(PULSE_MASK); ++ send_sample(dev); ++} ++ ++/* interrupt handler */ ++static irqreturn_t ene_hw_irq(int irq, void *data) ++{ ++ u16 hw_value; ++ int i, hw_sample; ++ int space; ++ int buffer_pointer; ++ int irq_status; ++ ++ struct ene_device *dev = (struct ene_device *)data; ++ irq_status = ene_hw_irq_status(dev, &buffer_pointer); ++ ++ if (!irq_status) ++ return IRQ_NONE; ++ ++ /* TODO: only RX for now */ ++ if (irq_status == ENE_IRQ_TX) ++ return IRQ_HANDLED; ++ ++ for (i = 0; i < ENE_SAMPLES_SIZE; i++) { ++ ++ hw_value = ene_hw_read_reg(dev, ++ ENE_SAMPLE_BUFFER + buffer_pointer + i); ++ ++ if (dev->fan_input_inuse) { ++ /* read high part of the sample */ ++ hw_value |= ene_hw_read_reg(dev, ++ ENE_SAMPLE_BUFFER_FAN + buffer_pointer + i) << 8; ++ ++ /* test for _space_ bit */ ++ space = !(hw_value & ENE_FAN_SMPL_PULS_MSK); ++ ++ /* clear space bit, and other unused bits */ ++ hw_value &= ENE_FAN_VALUE_MASK; ++ hw_sample = hw_value * ENE_SAMPLE_PERIOD_FAN; ++ ++ } else { ++ space = hw_value & ENE_SAMPLE_SPC_MASK; ++ hw_value &= ENE_SAMPLE_VALUE_MASK; ++ hw_sample = hw_value * sample_period; ++ } ++ ++ /* no more data */ ++ if (!(hw_value)) ++ break; ++ ++ if (space) ++ hw_sample *= -1; ++ ++ /* overflow sample recieved, handle it */ ++ ++ if (!dev->fan_input_inuse && hw_value == ENE_SAMPLE_OVERFLOW) { ++ ++ if (dev->idle) ++ continue; ++ ++ if (dev->sample > 0 || abs(dev->sample) <= ENE_MAXGAP) ++ update_sample(dev, hw_sample); ++ else ++ ene_set_idle(dev, 1); ++ ++ continue; ++ } ++ ++ /* normal first sample recieved */ ++ if (!dev->fan_input_inuse && dev->idle) { ++ ene_set_idle(dev, 0); ++ ++ /* discard first recieved value, its random ++ since its the time signal was off before ++ first pulse if idle mode is enabled, HW ++ does that for us */ ++ ++ if (!enable_idle) ++ continue; ++ } ++ update_sample(dev, hw_sample); ++ send_sample(dev); ++ } ++ return IRQ_HANDLED; ++} ++ ++static int ene_probe(struct pnp_dev *pnp_dev, ++ const struct pnp_device_id *dev_id) ++{ ++ struct ene_device *dev; ++ struct lirc_driver *lirc_driver; ++ int error = -ENOMEM; ++ ++ dev = kzalloc(sizeof(struct ene_device), GFP_KERNEL); ++ ++ if (!dev) ++ goto err1; ++ ++ dev->pnp_dev = pnp_dev; ++ pnp_set_drvdata(pnp_dev, dev); ++ ++ ++ /* prepare lirc interface */ ++ error = -ENOMEM; ++ lirc_driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); ++ ++ if (!lirc_driver) ++ goto err2; ++ ++ dev->lirc_driver = lirc_driver; ++ ++ strcpy(lirc_driver->name, ENE_DRIVER_NAME); ++ lirc_driver->minor = -1; ++ lirc_driver->code_length = sizeof(int) * 8; ++ lirc_driver->features = LIRC_CAN_REC_MODE2; ++ lirc_driver->data = dev; ++ lirc_driver->set_use_inc = ene_hw_init; ++ lirc_driver->set_use_dec = ene_hw_deinit; ++ lirc_driver->dev = &pnp_dev->dev; ++ lirc_driver->owner = THIS_MODULE; ++ ++ lirc_driver->rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ ++ if (!lirc_driver->rbuf) ++ goto err3; ++ ++ if (lirc_buffer_init(lirc_driver->rbuf, sizeof(int), sizeof(int) * 256)) ++ goto err4; ++ ++ error = -ENODEV; ++ if (lirc_register_driver(lirc_driver)) ++ goto err5; ++ ++ /* validate resources */ ++ if (!pnp_port_valid(pnp_dev, 0) || ++ pnp_port_len(pnp_dev, 0) < ENE_MAX_IO) ++ goto err6; ++ ++ if (!pnp_irq_valid(pnp_dev, 0)) ++ goto err6; ++ ++ dev->hw_io = pnp_port_start(pnp_dev, 0); ++ dev->irq = pnp_irq(pnp_dev, 0); ++ ++ /* claim the resources */ ++ error = -EBUSY; ++ if (!request_region(dev->hw_io, ENE_MAX_IO, ENE_DRIVER_NAME)) ++ goto err6; ++ ++ if (request_irq(dev->irq, ene_hw_irq, ++ IRQF_SHARED, ENE_DRIVER_NAME, (void *)dev)) ++ goto err7; ++ ++ /* detect hardware version and features */ ++ error = ene_hw_detect(dev); ++ if (error) ++ goto err8; ++ ++ ene_printk(KERN_NOTICE, "driver has been succesfully loaded\n"); ++ return 0; ++ ++err8: ++ free_irq(dev->irq, dev); ++err7: ++ release_region(dev->hw_io, ENE_MAX_IO); ++err6: ++ lirc_unregister_driver(lirc_driver->minor); ++err5: ++ lirc_buffer_free(lirc_driver->rbuf); ++err4: ++ kfree(lirc_driver->rbuf); ++err3: ++ kfree(lirc_driver); ++err2: ++ kfree(dev); ++err1: ++ return error; ++} ++ ++static void ene_remove(struct pnp_dev *pnp_dev) ++{ ++ struct ene_device *dev = pnp_get_drvdata(pnp_dev); ++ ene_hw_deinit(dev); ++ free_irq(dev->irq, dev); ++ release_region(dev->hw_io, ENE_MAX_IO); ++ lirc_unregister_driver(dev->lirc_driver->minor); ++ lirc_buffer_free(dev->lirc_driver->rbuf); ++ kfree(dev->lirc_driver); ++ kfree(dev); ++} ++ ++#ifdef CONFIG_PM ++ ++/* TODO: make 'wake on IR' configurable and add .shutdown */ ++/* currently impossible due to lack of kernel support */ ++ ++static int ene_suspend(struct pnp_dev *pnp_dev, pm_message_t state) ++{ ++ struct ene_device *dev = pnp_get_drvdata(pnp_dev); ++ ene_hw_write_reg_mask(dev, ENE_FW1, ENE_FW1_WAKE, ENE_FW1_WAKE); ++ return 0; ++} ++ ++static int ene_resume(struct pnp_dev *pnp_dev) ++{ ++ struct ene_device *dev = pnp_get_drvdata(pnp_dev); ++ if (dev->in_use) ++ ene_hw_init(dev); ++ ++ ene_hw_write_reg_mask(dev, ENE_FW1, 0, ENE_FW1_WAKE); ++ return 0; ++} ++ ++#endif ++ ++static const struct pnp_device_id ene_ids[] = { ++ {.id = "ENE0100",}, ++ {}, ++}; ++ ++static struct pnp_driver ene_driver = { ++ .name = ENE_DRIVER_NAME, ++ .id_table = ene_ids, ++ .flags = PNP_DRIVER_RES_DO_NOT_CHANGE, ++ ++ .probe = ene_probe, ++ .remove = __devexit_p(ene_remove), ++ ++#ifdef CONFIG_PM ++ .suspend = ene_suspend, ++ .resume = ene_resume, ++#endif ++}; ++ ++static int __init ene_init(void) ++{ ++ if (sample_period < 5) { ++ ene_printk(KERN_ERR, "sample period must be at\n"); ++ ene_printk(KERN_ERR, "least 5 us, (at least 30 recommended)\n"); ++ return -EINVAL; ++ } ++ return pnp_register_driver(&ene_driver); ++} ++ ++static void ene_exit(void) ++{ ++ pnp_unregister_driver(&ene_driver); ++} ++ ++module_param(sample_period, int, S_IRUGO); ++MODULE_PARM_DESC(sample_period, "Hardware sample period (75 us default)"); ++ ++module_param(enable_idle, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(enable_idle, ++ "Enables turning off signal sampling after long inactivity time; " ++ "if disabled might help detecting input signal (default: enabled)"); ++ ++module_param(enable_learning, bool, S_IRUGO); ++MODULE_PARM_DESC(enable_learning, "Use wide band (learning) reciever"); ++ ++MODULE_DEVICE_TABLE(pnp, ene_ids); ++MODULE_DESCRIPTION ++ ("LIRC driver for KB3926B/KB3926C/KB3926D (aka ENE0100) CIR port"); ++MODULE_AUTHOR("Maxim Levitsky"); ++MODULE_LICENSE("GPL"); ++ ++module_init(ene_init); ++module_exit(ene_exit); +diff --git a/drivers/input/lirc/lirc_ene0100.h b/drivers/input/lirc/lirc_ene0100.h +new file mode 100644 +index 0000000..953e7e4 +--- /dev/null ++++ b/drivers/input/lirc/lirc_ene0100.h +@@ -0,0 +1,169 @@ ++/* ++ * driver for ENE KB3926 B/C/D CIR (also known as ENE0100) ++ * ++ * Copyright (C) 2009 Maxim Levitsky ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ++ * USA ++ */ ++ ++#include ++#include "lirc_dev.h" ++ ++/* hardware address */ ++#define ENE_STATUS 0 /* hardware status - unused */ ++#define ENE_ADDR_HI 1 /* hi byte of register address */ ++#define ENE_ADDR_LO 2 /* low byte of register address */ ++#define ENE_IO 3 /* read/write window */ ++#define ENE_MAX_IO 4 ++ ++/* 8 bytes of samples, divided in 2 halfs*/ ++#define ENE_SAMPLE_BUFFER 0xF8F0 /* regular sample buffer */ ++#define ENE_SAMPLE_SPC_MASK (1 << 7) /* sample is space */ ++#define ENE_SAMPLE_VALUE_MASK 0x7F ++#define ENE_SAMPLE_OVERFLOW 0x7F ++#define ENE_SAMPLES_SIZE 4 ++ ++/* fan input sample buffer */ ++#define ENE_SAMPLE_BUFFER_FAN 0xF8FB /* this buffer holds high byte of */ ++ /* each sample of normal buffer */ ++ ++#define ENE_FAN_SMPL_PULS_MSK 0x8000 /* this bit of combined sample */ ++ /* if set, says that sample is pulse */ ++#define ENE_FAN_VALUE_MASK 0x0FFF /* mask for valid bits of the value */ ++ ++/* first firmware register */ ++#define ENE_FW1 0xF8F8 ++#define ENE_FW1_ENABLE (1 << 0) /* enable fw processing */ ++#define ENE_FW1_TXIRQ (1 << 1) /* TX interrupt pending */ ++#define ENE_FW1_WAKE (1 << 6) /* enable wake from S3 */ ++#define ENE_FW1_IRQ (1 << 7) /* enable interrupt */ ++ ++/* second firmware register */ ++#define ENE_FW2 0xF8F9 ++#define ENE_FW2_BUF_HIGH (1 << 0) /* which half of the buffer to read */ ++#define ENE_FW2_IRQ_CLR (1 << 2) /* clear this on IRQ */ ++#define ENE_FW2_GP40_AS_LEARN (1 << 4) /* normal input is used as */ ++ /* learning input */ ++#define ENE_FW2_FAN_AS_NRML_IN (1 << 6) /* fan is used as normal input */ ++#define ENE_FW2_LEARNING (1 << 7) /* hardware supports learning and TX */ ++ ++/* fan as input settings - only if learning capable */ ++#define ENE_FAN_AS_IN1 0xFE30 /* fan init reg 1 */ ++#define ENE_FAN_AS_IN1_EN 0xCD ++#define ENE_FAN_AS_IN2 0xFE31 /* fan init reg 2 */ ++#define ENE_FAN_AS_IN2_EN 0x03 ++#define ENE_SAMPLE_PERIOD_FAN 61 /* fan input has fixed sample period */ ++ ++/* IRQ registers block (for revision B) */ ++#define ENEB_IRQ 0xFD09 /* IRQ number */ ++#define ENEB_IRQ_UNK1 0xFD17 /* unknown setting = 1 */ ++#define ENEB_IRQ_STATUS 0xFD80 /* irq status */ ++#define ENEB_IRQ_STATUS_IR (1 << 5) /* IR irq */ ++ ++/* IRQ registers block (for revision C,D) */ ++#define ENEC_IRQ 0xFE9B /* new irq settings register */ ++#define ENEC_IRQ_MASK 0x0F /* irq number mask */ ++#define ENEC_IRQ_UNK_EN (1 << 4) /* always enabled */ ++#define ENEC_IRQ_STATUS (1 << 5) /* irq status and ACK */ ++ ++/* CIR block settings */ ++#define ENE_CIR_CONF1 0xFEC0 ++#define ENE_CIR_CONF1_ADC_ON 0x7 /* reciever on gpio40 enabled */ ++#define ENE_CIR_CONF1_LEARN1 (1 << 3) /* enabled on learning mode */ ++#define ENE_CIR_CONF1_TX_ON 0x30 /* enabled on transmit */ ++#define ENE_CIR_CONF1_TX_CARR (1 << 7) /* send TX carrier or not */ ++ ++#define ENE_CIR_CONF2 0xFEC1 /* unknown setting = 0 */ ++#define ENE_CIR_CONF2_LEARN2 (1 << 4) /* set on enable learning */ ++#define ENE_CIR_CONF2_GPIO40DIS (1 << 5) /* disable normal input via gpio40 */ ++ ++#define ENE_CIR_SAMPLE_PERIOD 0xFEC8 /* sample period in us */ ++#define ENE_CIR_SAMPLE_OVERFLOW (1 << 7) /* interrupt on overflows if set */ ++ ++ ++/* transmitter - not implemented yet */ ++/* KB3926C and higher */ ++/* transmission is very similiar to recieving, a byte is written to */ ++/* ENE_TX_INPUT, in same manner as it is read from sample buffer */ ++/* sample period is fixed*/ ++ ++ ++/* transmitter ports */ ++#define ENE_TX_PORT1 0xFC01 /* this enables one or both */ ++#define ENE_TX_PORT1_EN (1 << 5) /* TX ports */ ++#define ENE_TX_PORT2 0xFC08 ++#define ENE_TX_PORT2_EN (1 << 1) ++ ++#define ENE_TX_INPUT 0xFEC9 /* next byte to transmit */ ++#define ENE_TX_SPC_MASK (1 << 7) /* Transmitted sample is space */ ++#define ENE_TX_UNK1 0xFECB /* set to 0x63 */ ++#define ENE_TX_SMPL_PERIOD 50 /* transmit sample period */ ++ ++ ++#define ENE_TX_CARRIER 0xFECE /* TX carrier * 2 (khz) */ ++#define ENE_TX_CARRIER_UNKBIT 0x80 /* This bit set on transmit */ ++#define ENE_TX_CARRIER_LOW 0xFECF /* TX carrier / 2 */ ++ ++/* Hardware versions */ ++#define ENE_HW_VERSION 0xFF00 /* hardware revision */ ++#define ENE_HW_UNK 0xFF1D ++#define ENE_HW_UNK_CLR (1 << 2) ++#define ENE_HW_VER_MAJOR 0xFF1E /* chip version */ ++#define ENE_HW_VER_MINOR 0xFF1F ++#define ENE_HW_VER_OLD 0xFD00 ++ ++#define same_sign(a, b) ((((a) > 0) && (b) > 0) || ((a) < 0 && (b) < 0)) ++ ++#define ENE_DRIVER_NAME "enecir" ++#define ENE_MAXGAP 250000 /* this is amount of time we wait ++ before turning the sampler, chosen ++ arbitry */ ++ ++#define space(len) (-(len)) /* add a space */ ++ ++/* software defines */ ++#define ENE_IRQ_RX 1 ++#define ENE_IRQ_TX 2 ++ ++#define ENE_HW_B 1 /* 3926B */ ++#define ENE_HW_C 2 /* 3926C */ ++#define ENE_HW_D 3 /* 3926D */ ++ ++#define ene_printk(level, text, ...) \ ++ printk(level ENE_DRIVER_NAME ": " text, ## __VA_ARGS__) ++ ++struct ene_device { ++ struct pnp_dev *pnp_dev; ++ struct lirc_driver *lirc_driver; ++ ++ /* hw settings */ ++ unsigned long hw_io; ++ int irq; ++ ++ int hw_revision; /* hardware revision */ ++ int hw_learning_and_tx_capable; /* learning capable */ ++ int hw_gpio40_learning; /* gpio40 is learning */ ++ int hw_fan_as_normal_input; /* fan input is used as regular input */ ++ ++ /* device data */ ++ int idle; ++ int fan_input_inuse; ++ ++ int sample; ++ int in_use; ++ ++ struct timeval gap_start; ++}; +diff --git a/drivers/input/lirc/lirc_i2c.c b/drivers/input/lirc/lirc_i2c.c +new file mode 100644 +index 0000000..f3f8c2e +--- /dev/null ++++ b/drivers/input/lirc/lirc_i2c.c +@@ -0,0 +1,536 @@ ++/* ++ * lirc_i2c.c ++ * ++ * i2c IR driver for the onboard IR port on many TV tuner cards, including: ++ * -Flavors of the Hauppauge PVR-150/250/350 ++ * -Hauppauge HVR-1300 ++ * -PixelView (BT878P+W/FM) ++ * -KNC ONE TV Station/Anubis Typhoon TView Tuner ++ * -Asus TV-Box and Creative/VisionTek BreakOut-Box ++ * -Leadtek Winfast PVR2000 ++ * ++ * Copyright (c) 2000 Gerd Knorr ++ * modified for PixelView (BT878P+W/FM) by ++ * Michal Kochanowicz ++ * Christoph Bartelmus ++ * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by ++ * Ulrich Mueller ++ * modified for Asus TV-Box and Creative/VisionTek BreakOut-Box by ++ * Stefan Jahn ++ * modified for inclusion into kernel sources by ++ * Jerome Brock ++ * modified for Leadtek Winfast PVR2000 by ++ * Thomas Reitmayr (treitmayr@yahoo.com) ++ * modified for Hauppauge HVR-1300 by ++ * Jan Frey (jfrey@gmx.de) ++ * ++ * parts are cut&pasted from the old lirc_haup.c driver ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include "lirc_dev.h" ++ ++struct IR { ++ struct lirc_driver l; ++ struct i2c_client c; ++ int nextkey; ++ unsigned char b[3]; ++ unsigned char bits; ++ unsigned char flag; ++}; ++ ++#define DEVICE_NAME "lirc_i2c" ++ ++/* module parameters */ ++static int debug; /* debug output */ ++static int minor = -1; /* minor number */ ++ ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG DEVICE_NAME ": " fmt, \ ++ ## args); \ ++ } while (0) ++ ++static int reverse(int data, int bits) ++{ ++ int i; ++ int c; ++ ++ for (c = 0, i = 0; i < bits; i++) ++ c |= ((data & (1<c, keybuf, 1); ++ /* poll IR chip */ ++ if (i2c_master_recv(&ir->c, keybuf, sizeof(keybuf)) != sizeof(keybuf)) { ++ dprintk("read error\n"); ++ return -EIO; ++ } ++ ++ dprintk("key (0x%02x%02x%02x%02x)\n", ++ keybuf[0], keybuf[1], keybuf[2], keybuf[3]); ++ ++ /* key pressed ? */ ++ if (keybuf[2] == 0xff) ++ return -ENODATA; ++ ++ /* remove repeat bit */ ++ keybuf[2] &= 0x7f; ++ keybuf[3] |= 0x80; ++ ++ lirc_buffer_write(buf, keybuf); ++ return 0; ++} ++ ++static int add_to_buf_pcf8574(void *data, struct lirc_buffer *buf) ++{ ++ struct IR *ir = data; ++ int rc; ++ unsigned char all, mask; ++ unsigned char key; ++ ++ /* compute all valid bits (key code + pressed/release flag) */ ++ all = ir->bits | ir->flag; ++ ++ /* save IR writable mask bits */ ++ mask = i2c_smbus_read_byte(&ir->c) & ~all; ++ ++ /* send bit mask */ ++ rc = i2c_smbus_write_byte(&ir->c, (0xff & all) | mask); ++ ++ /* receive scan code */ ++ rc = i2c_smbus_read_byte(&ir->c); ++ ++ if (rc == -1) { ++ dprintk("%s read error\n", ir->c.name); ++ return -EIO; ++ } ++ ++ /* drop duplicate polls */ ++ if (ir->b[0] == (rc & all)) ++ return -ENODATA; ++ ++ ir->b[0] = rc & all; ++ ++ dprintk("%s key 0x%02X %s\n", ir->c.name, rc & ir->bits, ++ (rc & ir->flag) ? "released" : "pressed"); ++ ++ /* ignore released buttons */ ++ if (rc & ir->flag) ++ return -ENODATA; ++ ++ /* set valid key code */ ++ key = rc & ir->bits; ++ lirc_buffer_write(buf, &key); ++ return 0; ++} ++ ++/* common for Hauppauge IR receivers */ ++static int add_to_buf_haup_common(void *data, struct lirc_buffer *buf, ++ unsigned char *keybuf, int size, int offset) ++{ ++ struct IR *ir = data; ++ __u16 code; ++ unsigned char codes[2]; ++ int ret; ++ ++ /* poll IR chip */ ++ ret = i2c_master_recv(&ir->c, keybuf, size); ++ if (ret == size) { ++ ir->b[0] = keybuf[offset]; ++ ir->b[1] = keybuf[offset+1]; ++ ir->b[2] = keybuf[offset+2]; ++ if (ir->b[0] != 0x00 && ir->b[1] != 0x00) ++ dprintk("key (0x%02x/0x%02x)\n", ir->b[0], ir->b[1]); ++ } else { ++ dprintk("read error (ret=%d)\n", ret); ++ /* keep last successful read buffer */ ++ } ++ ++ /* key pressed ? */ ++ if ((ir->b[0] & 0x80) == 0) ++ return -ENODATA; ++ ++ /* look what we have */ ++ code = (((__u16)ir->b[0]&0x7f)<<6) | (ir->b[1]>>2); ++ ++ codes[0] = (code >> 8) & 0xff; ++ codes[1] = code & 0xff; ++ ++ /* return it */ ++ dprintk("sending code 0x%02x%02x to lirc\n", codes[0], codes[1]); ++ lirc_buffer_write(buf, codes); ++ return 0; ++} ++ ++/* specific for the Hauppauge PVR150 IR receiver */ ++static int add_to_buf_haup_pvr150(void *data, struct lirc_buffer *buf) ++{ ++ unsigned char keybuf[6]; ++ /* fetch 6 bytes, first relevant is at offset 3 */ ++ return add_to_buf_haup_common(data, buf, keybuf, 6, 3); ++} ++ ++/* used for all Hauppauge IR receivers but the PVR150 */ ++static int add_to_buf_haup(void *data, struct lirc_buffer *buf) ++{ ++ unsigned char keybuf[3]; ++ /* fetch 3 bytes, first relevant is at offset 0 */ ++ return add_to_buf_haup_common(data, buf, keybuf, 3, 0); ++} ++ ++ ++static int add_to_buf_pvr2000(void *data, struct lirc_buffer *buf) ++{ ++ struct IR *ir = data; ++ unsigned char key; ++ s32 flags; ++ s32 code; ++ ++ /* poll IR chip */ ++ flags = i2c_smbus_read_byte_data(&ir->c, 0x10); ++ if (-1 == flags) { ++ dprintk("read error\n"); ++ return -ENODATA; ++ } ++ /* key pressed ? */ ++ if (0 == (flags & 0x80)) ++ return -ENODATA; ++ ++ /* read actual key code */ ++ code = i2c_smbus_read_byte_data(&ir->c, 0x00); ++ if (-1 == code) { ++ dprintk("read error\n"); ++ return -ENODATA; ++ } ++ ++ key = code & 0xFF; ++ ++ dprintk("IR Key/Flags: (0x%02x/0x%02x)\n", key, flags & 0xFF); ++ ++ /* return it */ ++ lirc_buffer_write(buf, &key); ++ return 0; ++} ++ ++static int add_to_buf_pixelview(void *data, struct lirc_buffer *buf) ++{ ++ struct IR *ir = data; ++ unsigned char key; ++ ++ /* poll IR chip */ ++ if (1 != i2c_master_recv(&ir->c, &key, 1)) { ++ dprintk("read error\n"); ++ return -1; ++ } ++ dprintk("key %02x\n", key); ++ ++ /* return it */ ++ lirc_buffer_write(buf, &key); ++ return 0; ++} ++ ++static int add_to_buf_pv951(void *data, struct lirc_buffer *buf) ++{ ++ struct IR *ir = data; ++ unsigned char key; ++ unsigned char codes[4]; ++ ++ /* poll IR chip */ ++ if (1 != i2c_master_recv(&ir->c, &key, 1)) { ++ dprintk("read error\n"); ++ return -ENODATA; ++ } ++ /* ignore 0xaa */ ++ if (key == 0xaa) ++ return -ENODATA; ++ dprintk("key %02x\n", key); ++ ++ codes[0] = 0x61; ++ codes[1] = 0xD6; ++ codes[2] = reverse(key, 8); ++ codes[3] = (~codes[2])&0xff; ++ ++ lirc_buffer_write(buf, codes); ++ return 0; ++} ++ ++static int add_to_buf_knc1(void *data, struct lirc_buffer *buf) ++{ ++ static unsigned char last_key = 0xFF; ++ struct IR *ir = data; ++ unsigned char key; ++ ++ /* poll IR chip */ ++ if (1 != i2c_master_recv(&ir->c, &key, 1)) { ++ dprintk("read error\n"); ++ return -ENODATA; ++ } ++ ++ /* ++ * it seems that 0xFE indicates that a button is still held ++ * down, while 0xFF indicates that no button is held ++ * down. 0xFE sequences are sometimes interrupted by 0xFF ++ */ ++ ++ dprintk("key %02x\n", key); ++ ++ if (key == 0xFF) ++ return -ENODATA; ++ ++ if (key == 0xFE) ++ key = last_key; ++ ++ last_key = key; ++ lirc_buffer_write(buf, &key); ++ ++ return 0; ++} ++ ++static int set_use_inc(void *data) ++{ ++ struct IR *ir = data; ++ ++ dprintk("%s called\n", __func__); ++ ++ /* lock bttv in memory while /dev/lirc is in use */ ++ i2c_use_client(&ir->c); ++ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++ struct IR *ir = data; ++ ++ dprintk("%s called\n", __func__); ++ ++ i2c_release_client(&ir->c); ++} ++ ++static struct lirc_driver lirc_template = { ++ .name = "lirc_i2c", ++ .set_use_inc = set_use_inc, ++ .set_use_dec = set_use_dec, ++ .dev = NULL, ++ .owner = THIS_MODULE, ++}; ++ ++static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id); ++static int ir_remove(struct i2c_client *client); ++static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg); ++ ++static const struct i2c_device_id ir_receiver_id[] = { ++ /* Generic entry for any IR receiver */ ++ { "ir_video", 0 }, ++ /* IR device specific entries could be added here */ ++ { } ++}; ++ ++static struct i2c_driver driver = { ++ .driver = { ++ .owner = THIS_MODULE, ++ .name = "i2c ir driver", ++ }, ++ .probe = ir_probe, ++ .remove = ir_remove, ++ .id_table = ir_receiver_id, ++ .command = ir_command, ++}; ++ ++static void pcf_probe(struct i2c_client *client, struct IR *ir) ++{ ++ int ret1, ret2, ret3, ret4; ++ ++ ret1 = i2c_smbus_write_byte(client, 0xff); ++ ret2 = i2c_smbus_read_byte(client); ++ ret3 = i2c_smbus_write_byte(client, 0x00); ++ ret4 = i2c_smbus_read_byte(client); ++ ++ /* in the Asus TV-Box: bit 1-0 */ ++ if (((ret2 & 0x03) == 0x03) && ((ret4 & 0x03) == 0x00)) { ++ ir->bits = (unsigned char) ~0x07; ++ ir->flag = 0x04; ++ /* in the Creative/VisionTek BreakOut-Box: bit 7-6 */ ++ } else if (((ret2 & 0xc0) == 0xc0) && ((ret4 & 0xc0) == 0x00)) { ++ ir->bits = (unsigned char) ~0xe0; ++ ir->flag = 0x20; ++ } ++ ++ return; ++} ++ ++static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ++{ ++ struct IR *ir; ++ struct i2c_adapter *adap = client->adapter; ++ unsigned short addr = client->addr; ++ int retval; ++ ++ ir = kzalloc(sizeof(struct IR), GFP_KERNEL); ++ if (!ir) ++ return -ENOMEM; ++ memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); ++ memcpy(&ir->c, client, sizeof(struct i2c_client)); ++ ++ i2c_set_clientdata(client, ir); ++ ir->l.data = ir; ++ ir->l.minor = minor; ++ ir->l.sample_rate = 10; ++ ir->l.dev = &ir->c.dev; ++ ir->nextkey = -1; ++ ++ switch (addr) { ++ case 0x64: ++ strlcpy(ir->c.name, "Pixelview IR", I2C_NAME_SIZE); ++ ir->l.code_length = 8; ++ ir->l.add_to_buf = add_to_buf_pixelview; ++ break; ++ case 0x4b: ++ strlcpy(ir->c.name, "PV951 IR", I2C_NAME_SIZE); ++ ir->l.code_length = 32; ++ ir->l.add_to_buf = add_to_buf_pv951; ++ break; ++ case 0x71: ++ if (adap->id == I2C_HW_B_CX2388x) ++ strlcpy(ir->c.name, "Hauppauge HVR1300", I2C_NAME_SIZE); ++ else /* bt8xx or cx2341x */ ++ /* ++ * The PVR150 IR receiver uses the same protocol as ++ * other Hauppauge cards, but the data flow is ++ * different, so we need to deal with it by its own. ++ */ ++ strlcpy(ir->c.name, "Hauppauge PVR150", I2C_NAME_SIZE); ++ ir->l.code_length = 13; ++ ir->l.add_to_buf = add_to_buf_haup_pvr150; ++ break; ++ case 0x6b: ++ strlcpy(ir->c.name, "Adaptec IR", I2C_NAME_SIZE); ++ ir->l.code_length = 32; ++ ir->l.add_to_buf = add_to_buf_adap; ++ break; ++ case 0x18: ++ case 0x1a: ++ if (adap->id == I2C_HW_B_CX2388x) { ++ strlcpy(ir->c.name, "Leadtek IR", I2C_NAME_SIZE); ++ ir->l.code_length = 8; ++ ir->l.add_to_buf = add_to_buf_pvr2000; ++ } else { /* bt8xx or cx2341x */ ++ strlcpy(ir->c.name, "Hauppauge IR", I2C_NAME_SIZE); ++ ir->l.code_length = 13; ++ ir->l.add_to_buf = add_to_buf_haup; ++ } ++ break; ++ case 0x30: ++ strlcpy(ir->c.name, "KNC ONE IR", I2C_NAME_SIZE); ++ ir->l.code_length = 8; ++ ir->l.add_to_buf = add_to_buf_knc1; ++ break; ++ case 0x21: ++ case 0x23: ++ pcf_probe(client, ir); ++ strlcpy(ir->c.name, "TV-Box IR", I2C_NAME_SIZE); ++ ir->l.code_length = 8; ++ ir->l.add_to_buf = add_to_buf_pcf8574; ++ break; ++ default: ++ /* shouldn't happen */ ++ printk("lirc_i2c: Huh? unknown i2c address (0x%02x)?\n", addr); ++ kfree(ir); ++ return -EINVAL; ++ } ++ printk(KERN_INFO "lirc_i2c: chip 0x%x found @ 0x%02x (%s)\n", ++ adap->id, addr, ir->c.name); ++ ++ retval = lirc_register_driver(&ir->l); ++ ++ if (retval < 0) { ++ printk(KERN_ERR "lirc_i2c: failed to register driver!\n"); ++ kfree(ir); ++ return retval; ++ } ++ ++ ir->l.minor = retval; ++ ++ return 0; ++} ++ ++static int ir_remove(struct i2c_client *client) ++{ ++ struct IR *ir = i2c_get_clientdata(client); ++ ++ /* unregister device */ ++ lirc_unregister_driver(ir->l.minor); ++ ++ /* free memory */ ++ kfree(ir); ++ return 0; ++} ++ ++static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg) ++{ ++ /* nothing */ ++ return 0; ++} ++ ++static int __init lirc_i2c_init(void) ++{ ++ i2c_add_driver(&driver); ++ return 0; ++} ++ ++static void __exit lirc_i2c_exit(void) ++{ ++ i2c_del_driver(&driver); ++} ++ ++MODULE_DESCRIPTION("Infrared receiver driver for Hauppauge and " ++ "Pixelview cards (i2c stack)"); ++MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, " ++ "Ulrich Mueller, Stefan Jahn, Jerome Brock"); ++MODULE_LICENSE("GPL"); ++ ++module_param(minor, int, S_IRUGO); ++MODULE_PARM_DESC(minor, "Preferred minor device number"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); ++ ++module_init(lirc_i2c_init); ++module_exit(lirc_i2c_exit); +diff --git a/drivers/input/lirc/lirc_igorplugusb.c b/drivers/input/lirc/lirc_igorplugusb.c +new file mode 100644 +index 0000000..d1c02c2 +--- /dev/null ++++ b/drivers/input/lirc/lirc_igorplugusb.c +@@ -0,0 +1,555 @@ ++/* ++ * lirc_igorplugusb - USB remote support for LIRC ++ * ++ * Supports the standard homebrew IgorPlugUSB receiver with Igor's firmware. ++ * See http://www.cesko.host.sk/IgorPlugUSB/IgorPlug-USB%20(AVR)_eng.htm ++ * ++ * The device can only record bursts of up to 36 pulses/spaces. ++ * Works fine with RC5. Longer commands lead to device buffer overrun. ++ * (Maybe a better firmware or a microcontroller with more ram can help?) ++ * ++ * Version 0.1 [beta status] ++ * ++ * Copyright (C) 2004 Jan M. Hochstein ++ * ++ * ++ * This driver was derived from: ++ * Paul Miller ++ * "lirc_atiusb" module ++ * Vladimir Dergachev 's 2002 ++ * "USB ATI Remote support" (input device) ++ * Adrian Dewhurst 's 2002 ++ * "USB StreamZap remote driver" (LIRC) ++ * Artur Lipowski 's 2002 ++ * "lirc_dev" and "lirc_gpio" LIRC modules ++ */ ++ ++/* ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++ ++/* module identification */ ++#define DRIVER_VERSION "0.1" ++#define DRIVER_AUTHOR \ ++ "Jan M. Hochstein " ++#define DRIVER_DESC "USB remote driver for LIRC" ++#define DRIVER_NAME "lirc_igorplugusb" ++ ++/* debugging support */ ++#ifdef CONFIG_USB_DEBUG ++static int debug = 1; ++#else ++static int debug; ++#endif ++ ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG fmt, ## args); \ ++ } while (0) ++ ++/* One mode2 pulse/space has 4 bytes. */ ++#define CODE_LENGTH sizeof(int) ++ ++/* Igor's firmware cannot record bursts longer than 36. */ ++#define DEVICE_BUFLEN 36 ++ ++/* ++ * Header at the beginning of the device's buffer: ++ * unsigned char data_length ++ * unsigned char data_start (!=0 means ring-buffer overrun) ++ * unsigned char counter (incremented by each burst) ++ */ ++#define DEVICE_HEADERLEN 3 ++ ++/* This is for the gap */ ++#define ADDITIONAL_LIRC_BYTES 2 ++ ++/* times to poll per second */ ++#define SAMPLE_RATE 100 ++static int sample_rate = SAMPLE_RATE; ++ ++ ++/**** Igor's USB Request Codes */ ++ ++#define SET_INFRABUFFER_EMPTY 1 ++/** ++ * Params: none ++ * Answer: empty ++ */ ++ ++#define GET_INFRACODE 2 ++/** ++ * Params: ++ * wValue: offset to begin reading infra buffer ++ * ++ * Answer: infra data ++ */ ++ ++#define SET_DATAPORT_DIRECTION 3 ++/** ++ * Params: ++ * wValue: (byte) 1 bit for each data port pin (0=in, 1=out) ++ * ++ * Answer: empty ++ */ ++ ++#define GET_DATAPORT_DIRECTION 4 ++/** ++ * Params: none ++ * ++ * Answer: (byte) 1 bit for each data port pin (0=in, 1=out) ++ */ ++ ++#define SET_OUT_DATAPORT 5 ++/** ++ * Params: ++ * wValue: byte to write to output data port ++ * ++ * Answer: empty ++ */ ++ ++#define GET_OUT_DATAPORT 6 ++/** ++ * Params: none ++ * ++ * Answer: least significant 3 bits read from output data port ++ */ ++ ++#define GET_IN_DATAPORT 7 ++/** ++ * Params: none ++ * ++ * Answer: least significant 3 bits read from input data port ++ */ ++ ++#define READ_EEPROM 8 ++/** ++ * Params: ++ * wValue: offset to begin reading EEPROM ++ * ++ * Answer: EEPROM bytes ++ */ ++ ++#define WRITE_EEPROM 9 ++/** ++ * Params: ++ * wValue: offset to EEPROM byte ++ * wIndex: byte to write ++ * ++ * Answer: empty ++ */ ++ ++#define SEND_RS232 10 ++/** ++ * Params: ++ * wValue: byte to send ++ * ++ * Answer: empty ++ */ ++ ++#define RECV_RS232 11 ++/** ++ * Params: none ++ * ++ * Answer: byte received ++ */ ++ ++#define SET_RS232_BAUD 12 ++/** ++ * Params: ++ * wValue: byte to write to UART bit rate register (UBRR) ++ * ++ * Answer: empty ++ */ ++ ++#define GET_RS232_BAUD 13 ++/** ++ * Params: none ++ * ++ * Answer: byte read from UART bit rate register (UBRR) ++ */ ++ ++ ++/* data structure for each usb remote */ ++struct igorplug { ++ ++ /* usb */ ++ struct usb_device *usbdev; ++ struct urb *urb_in; ++ int devnum; ++ ++ unsigned char *buf_in; ++ unsigned int len_in; ++ int in_space; ++ struct timeval last_time; ++ ++ dma_addr_t dma_in; ++ ++ /* lirc */ ++ struct lirc_driver *d; ++ ++ /* handle sending (init strings) */ ++ int send_flags; ++ wait_queue_head_t wait_out; ++}; ++ ++static int unregister_from_lirc(struct igorplug *ir) ++{ ++ struct lirc_driver *d = ir->d; ++ int devnum; ++ ++ if (!ir->d) ++ return -EINVAL; ++ ++ devnum = ir->devnum; ++ dprintk(DRIVER_NAME "[%d]: unregister from lirc called\n", devnum); ++ ++ lirc_unregister_driver(d->minor); ++ ++ printk(DRIVER_NAME "[%d]: usb remote disconnected\n", devnum); ++ ++ kfree(d); ++ ir->d = NULL; ++ kfree(ir); ++ return 0; ++} ++ ++static int set_use_inc(void *data) ++{ ++ struct igorplug *ir = data; ++ ++ if (!ir) { ++ printk(DRIVER_NAME "[?]: set_use_inc called with no context\n"); ++ return -EIO; ++ } ++ dprintk(DRIVER_NAME "[%d]: set use inc\n", ir->devnum); ++ ++ if (!ir->usbdev) ++ return -ENODEV; ++ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++ struct igorplug *ir = data; ++ ++ if (!ir) { ++ printk(DRIVER_NAME "[?]: set_use_dec called with no context\n"); ++ return; ++ } ++ dprintk(DRIVER_NAME "[%d]: set use dec\n", ir->devnum); ++} ++ ++ ++/** ++ * Called in user context. ++ * return 0 if data was added to the buffer and ++ * -ENODATA if none was available. This should add some number of bits ++ * evenly divisible by code_length to the buffer ++ */ ++static int usb_remote_poll(void *data, struct lirc_buffer *buf) ++{ ++ int ret; ++ struct igorplug *ir = (struct igorplug *)data; ++ ++ if (!ir->usbdev) /* Has the device been removed? */ ++ return -ENODEV; ++ ++ memset(ir->buf_in, 0, ir->len_in); ++ ++ ret = usb_control_msg( ++ ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), ++ GET_INFRACODE, USB_TYPE_VENDOR|USB_DIR_IN, ++ 0/* offset */, /*unused*/0, ++ ir->buf_in, ir->len_in, ++ /*timeout*/HZ * USB_CTRL_GET_TIMEOUT); ++ if (ret > 0) { ++ int i = DEVICE_HEADERLEN; ++ int code, timediff; ++ struct timeval now; ++ ++ if (ret <= 1) /* ACK packet has 1 byte --> ignore */ ++ return -ENODATA; ++ ++ dprintk(DRIVER_NAME ": Got %d bytes. Header: %02x %02x %02x\n", ++ ret, ir->buf_in[0], ir->buf_in[1], ir->buf_in[2]); ++ ++ if (ir->buf_in[2] != 0) { ++ printk(DRIVER_NAME "[%d]: Device buffer overrun.\n", ++ ir->devnum); ++ /* start at earliest byte */ ++ i = DEVICE_HEADERLEN + ir->buf_in[2]; ++ /* where are we now? space, gap or pulse? */ ++ } ++ ++ do_gettimeofday(&now); ++ timediff = now.tv_sec - ir->last_time.tv_sec; ++ if (timediff + 1 > PULSE_MASK / 1000000) ++ timediff = PULSE_MASK; ++ else { ++ timediff *= 1000000; ++ timediff += now.tv_usec - ir->last_time.tv_usec; ++ } ++ ir->last_time.tv_sec = now.tv_sec; ++ ir->last_time.tv_usec = now.tv_usec; ++ ++ /* create leading gap */ ++ code = timediff; ++ lirc_buffer_write(buf, (unsigned char *)&code); ++ ir->in_space = 1; /* next comes a pulse */ ++ ++ /* MODE2: pulse/space (PULSE_BIT) in 1us units */ ++ ++ while (i < ret) { ++ /* 1 Igor-tick = 85.333333 us */ ++ code = (unsigned int)ir->buf_in[i] * 85 ++ + (unsigned int)ir->buf_in[i] / 3; ++ if (ir->in_space) ++ code |= PULSE_BIT; ++ lirc_buffer_write(buf, (unsigned char *)&code); ++ /* 1 chunk = CODE_LENGTH bytes */ ++ ir->in_space ^= 1; ++ ++i; ++ } ++ ++ ret = usb_control_msg( ++ ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), ++ SET_INFRABUFFER_EMPTY, USB_TYPE_VENDOR|USB_DIR_IN, ++ /*unused*/0, /*unused*/0, ++ /*dummy*/ir->buf_in, /*dummy*/ir->len_in, ++ /*timeout*/HZ * USB_CTRL_GET_TIMEOUT); ++ if (ret < 0) ++ printk(DRIVER_NAME "[%d]: SET_INFRABUFFER_EMPTY: " ++ "error %d\n", ir->devnum, ret); ++ return 0; ++ } else if (ret < 0) ++ printk(DRIVER_NAME "[%d]: GET_INFRACODE: error %d\n", ++ ir->devnum, ret); ++ ++ return -ENODATA; ++} ++ ++ ++ ++static int usb_remote_probe(struct usb_interface *intf, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *dev = NULL; ++ struct usb_host_interface *idesc = NULL; ++ struct usb_host_endpoint *ep_ctl2; ++ struct igorplug *ir = NULL; ++ struct lirc_driver *driver = NULL; ++ int devnum, pipe, maxp; ++ int minor = 0; ++ char buf[63], name[128] = ""; ++ int mem_failure = 0; ++ int ret; ++ ++ dprintk(DRIVER_NAME ": usb probe called.\n"); ++ ++ dev = interface_to_usbdev(intf); ++ ++ idesc = intf->cur_altsetting; ++ ++ if (idesc->desc.bNumEndpoints != 1) ++ return -ENODEV; ++ ep_ctl2 = idesc->endpoint; ++ if (((ep_ctl2->desc.bEndpointAddress & USB_ENDPOINT_DIR_MASK) ++ != USB_DIR_IN) ++ || (ep_ctl2->desc.bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ++ != USB_ENDPOINT_XFER_CONTROL) ++ return -ENODEV; ++ pipe = usb_rcvctrlpipe(dev, ep_ctl2->desc.bEndpointAddress); ++ devnum = dev->devnum; ++ maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); ++ ++ dprintk(DRIVER_NAME "[%d]: bytes_in_key=%lu maxp=%d\n", ++ devnum, CODE_LENGTH, maxp); ++ ++ ++ mem_failure = 0; ++ ir = kzalloc(sizeof(struct igorplug), GFP_KERNEL); ++ if (!ir) { ++ mem_failure = 1; ++ goto mem_failure_switch; ++ } ++ driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); ++ if (!driver) { ++ mem_failure = 2; ++ goto mem_failure_switch; ++ } ++ ++ ir->buf_in = usb_buffer_alloc(dev, ++ DEVICE_BUFLEN+DEVICE_HEADERLEN, ++ GFP_ATOMIC, &ir->dma_in); ++ if (!ir->buf_in) { ++ mem_failure = 3; ++ goto mem_failure_switch; ++ } ++ ++ strcpy(driver->name, DRIVER_NAME " "); ++ driver->minor = -1; ++ driver->code_length = CODE_LENGTH * 8; /* in bits */ ++ driver->features = LIRC_CAN_REC_MODE2; ++ driver->data = ir; ++ driver->chunk_size = CODE_LENGTH; ++ driver->buffer_size = DEVICE_BUFLEN + ADDITIONAL_LIRC_BYTES; ++ driver->set_use_inc = &set_use_inc; ++ driver->set_use_dec = &set_use_dec; ++ driver->sample_rate = sample_rate; /* per second */ ++ driver->add_to_buf = &usb_remote_poll; ++ driver->dev = &intf->dev; ++ driver->owner = THIS_MODULE; ++ ++ init_waitqueue_head(&ir->wait_out); ++ ++ minor = lirc_register_driver(driver); ++ if (minor < 0) ++ mem_failure = 9; ++ ++mem_failure_switch: ++ ++ switch (mem_failure) { ++ case 9: ++ usb_buffer_free(dev, DEVICE_BUFLEN+DEVICE_HEADERLEN, ++ ir->buf_in, ir->dma_in); ++ case 3: ++ kfree(driver); ++ case 2: ++ kfree(ir); ++ case 1: ++ printk(DRIVER_NAME "[%d]: out of memory (code=%d)\n", ++ devnum, mem_failure); ++ return -ENOMEM; ++ } ++ ++ driver->minor = minor; ++ ir->d = driver; ++ ir->devnum = devnum; ++ ir->usbdev = dev; ++ ir->len_in = DEVICE_BUFLEN+DEVICE_HEADERLEN; ++ ir->in_space = 1; /* First mode2 event is a space. */ ++ do_gettimeofday(&ir->last_time); ++ ++ if (dev->descriptor.iManufacturer ++ && usb_string(dev, dev->descriptor.iManufacturer, ++ buf, sizeof(buf)) > 0) ++ strlcpy(name, buf, sizeof(name)); ++ if (dev->descriptor.iProduct ++ && usb_string(dev, dev->descriptor.iProduct, buf, sizeof(buf)) > 0) ++ snprintf(name + strlen(name), sizeof(name) - strlen(name), ++ " %s", buf); ++ printk(DRIVER_NAME "[%d]: %s on usb%d:%d\n", devnum, name, ++ dev->bus->busnum, devnum); ++ ++ /* clear device buffer */ ++ ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), ++ SET_INFRABUFFER_EMPTY, USB_TYPE_VENDOR|USB_DIR_IN, ++ /*unused*/0, /*unused*/0, ++ /*dummy*/ir->buf_in, /*dummy*/ir->len_in, ++ /*timeout*/HZ * USB_CTRL_GET_TIMEOUT); ++ if (ret < 0) ++ printk(DRIVER_NAME "[%d]: SET_INFRABUFFER_EMPTY: error %d\n", ++ devnum, ret); ++ ++ usb_set_intfdata(intf, ir); ++ return 0; ++} ++ ++ ++static void usb_remote_disconnect(struct usb_interface *intf) ++{ ++ struct usb_device *dev = interface_to_usbdev(intf); ++ struct igorplug *ir = usb_get_intfdata(intf); ++ usb_set_intfdata(intf, NULL); ++ ++ if (!ir || !ir->d) ++ return; ++ ++ ir->usbdev = NULL; ++ wake_up_all(&ir->wait_out); ++ ++ usb_buffer_free(dev, ir->len_in, ir->buf_in, ir->dma_in); ++ ++ unregister_from_lirc(ir); ++} ++ ++static struct usb_device_id usb_remote_id_table[] = { ++ /* Igor Plug USB (Atmel's Manufact. ID) */ ++ { USB_DEVICE(0x03eb, 0x0002) }, ++ ++ /* Terminating entry */ ++ { } ++}; ++ ++static struct usb_driver usb_remote_driver = { ++ .name = DRIVER_NAME, ++ .probe = usb_remote_probe, ++ .disconnect = usb_remote_disconnect, ++ .id_table = usb_remote_id_table ++}; ++ ++static int __init usb_remote_init(void) ++{ ++ int i; ++ ++ printk(KERN_INFO "\n" ++ DRIVER_NAME ": " DRIVER_DESC " v" DRIVER_VERSION "\n"); ++ printk(DRIVER_NAME ": " DRIVER_AUTHOR "\n"); ++ dprintk(DRIVER_NAME ": debug mode enabled\n"); ++ ++ i = usb_register(&usb_remote_driver); ++ if (i < 0) { ++ printk(DRIVER_NAME ": usb register failed, result = %d\n", i); ++ return -ENODEV; ++ } ++ ++ return 0; ++} ++ ++static void __exit usb_remote_exit(void) ++{ ++ usb_deregister(&usb_remote_driver); ++} ++ ++module_init(usb_remote_init); ++module_exit(usb_remote_exit); ++ ++#include ++MODULE_INFO(vermagic, VERMAGIC_STRING); ++ ++MODULE_DESCRIPTION(DRIVER_DESC); ++MODULE_AUTHOR(DRIVER_AUTHOR); ++MODULE_LICENSE("GPL"); ++MODULE_DEVICE_TABLE(usb, usb_remote_id_table); ++ ++module_param(sample_rate, int, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(sample_rate, "Sampling rate in Hz (default: 100)"); ++ +diff --git a/drivers/input/lirc/lirc_imon.c b/drivers/input/lirc/lirc_imon.c +new file mode 100644 +index 0000000..af5eec8 +--- /dev/null ++++ b/drivers/input/lirc/lirc_imon.c +@@ -0,0 +1,1053 @@ ++/* ++ * lirc_imon.c: LIRC/VFD/LCD driver for SoundGraph iMON IR/VFD/LCD ++ * including the iMON PAD model ++ * ++ * Copyright(C) 2004 Venky Raju(dev@venky.ws) ++ * Copyright(C) 2009 Jarod Wilson ++ * ++ * lirc_imon is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++ ++#define MOD_AUTHOR "Venky Raju " ++#define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display" ++#define MOD_NAME "lirc_imon" ++#define MOD_VERSION "0.8" ++ ++#define DISPLAY_MINOR_BASE 144 ++#define DEVICE_NAME "lcd%d" ++ ++#define BUF_CHUNK_SIZE 4 ++#define BUF_SIZE 128 ++ ++#define BIT_DURATION 250 /* each bit received is 250us */ ++ ++/*** P R O T O T Y P E S ***/ ++ ++/* USB Callback prototypes */ ++static int imon_probe(struct usb_interface *interface, ++ const struct usb_device_id *id); ++static void imon_disconnect(struct usb_interface *interface); ++static void usb_rx_callback(struct urb *urb); ++static void usb_tx_callback(struct urb *urb); ++ ++/* suspend/resume support */ ++static int imon_resume(struct usb_interface *intf); ++static int imon_suspend(struct usb_interface *intf, pm_message_t message); ++ ++/* Display file_operations function prototypes */ ++static int display_open(struct inode *inode, struct file *file); ++static int display_close(struct inode *inode, struct file *file); ++ ++/* VFD write operation */ ++static ssize_t vfd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos); ++ ++/* LIRC driver function prototypes */ ++static int ir_open(void *data); ++static void ir_close(void *data); ++ ++/* Driver init/exit prototypes */ ++static int __init imon_init(void); ++static void __exit imon_exit(void); ++ ++/*** G L O B A L S ***/ ++ ++struct imon_context { ++ struct usb_device *usbdev; ++ /* Newer devices have two interfaces */ ++ int display; /* not all controllers do */ ++ int display_isopen; /* display port has been opened */ ++ int ir_isopen; /* IR port open */ ++ int dev_present; /* USB device presence */ ++ struct mutex ctx_lock; /* to lock this object */ ++ wait_queue_head_t remove_ok; /* For unexpected USB disconnects */ ++ ++ int vfd_proto_6p; /* some VFD require a 6th packet */ ++ ++ struct lirc_driver *driver; ++ struct usb_endpoint_descriptor *rx_endpoint; ++ struct usb_endpoint_descriptor *tx_endpoint; ++ struct urb *rx_urb; ++ struct urb *tx_urb; ++ unsigned char usb_rx_buf[8]; ++ unsigned char usb_tx_buf[8]; ++ ++ struct rx_data { ++ int count; /* length of 0 or 1 sequence */ ++ int prev_bit; /* logic level of sequence */ ++ int initial_space; /* initial space flag */ ++ } rx; ++ ++ struct tx_t { ++ unsigned char data_buf[35]; /* user data buffer */ ++ struct completion finished; /* wait for write to finish */ ++ atomic_t busy; /* write in progress */ ++ int status; /* status of tx completion */ ++ } tx; ++}; ++ ++static struct file_operations display_fops = { ++ .owner = THIS_MODULE, ++ .open = &display_open, ++ .write = &vfd_write, ++ .release = &display_close ++}; ++ ++/* ++ * USB Device ID for iMON USB Control Boards ++ * ++ * The Windows drivers contain 6 different inf files, more or less one for ++ * each new device until the 0x0034-0x0046 devices, which all use the same ++ * driver. Some of the devices in the 34-46 range haven't been definitively ++ * identified yet. Early devices have either a TriGem Computer, Inc. or a ++ * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later ++ * devices use the SoundGraph vendor ID (0x15c2). ++ */ ++static struct usb_device_id imon_usb_id_table[] = { ++ /* TriGem iMON (IR only) -- TG_iMON.inf */ ++ { USB_DEVICE(0x0aa8, 0x8001) }, ++ ++ /* SoundGraph iMON (IR only) -- sg_imon.inf */ ++ { USB_DEVICE(0x04e8, 0xff30) }, ++ ++ /* SoundGraph iMON VFD (IR & VFD) -- iMON_VFD.inf */ ++ { USB_DEVICE(0x0aa8, 0xffda) }, ++ ++ /* SoundGraph iMON SS (IR & VFD) -- iMON_SS.inf */ ++ { USB_DEVICE(0x15c2, 0xffda) }, ++ ++ {} ++}; ++ ++/* Some iMON VFD models requires a 6th packet for VFD writes */ ++static struct usb_device_id vfd_proto_6p_list[] = { ++ { USB_DEVICE(0x15c2, 0xffda) }, ++ {} ++}; ++ ++/* Some iMON devices have no lcd/vfd, don't set one up */ ++static struct usb_device_id ir_only_list[] = { ++ { USB_DEVICE(0x0aa8, 0x8001) }, ++ { USB_DEVICE(0x04e8, 0xff30) }, ++ {} ++}; ++ ++/* USB Device data */ ++static struct usb_driver imon_driver = { ++ .name = MOD_NAME, ++ .probe = imon_probe, ++ .disconnect = imon_disconnect, ++ .suspend = imon_suspend, ++ .resume = imon_resume, ++ .id_table = imon_usb_id_table, ++}; ++ ++static struct usb_class_driver imon_class = { ++ .name = DEVICE_NAME, ++ .fops = &display_fops, ++ .minor_base = DISPLAY_MINOR_BASE, ++}; ++ ++/* to prevent races between open() and disconnect(), probing, etc */ ++static DEFINE_MUTEX(driver_lock); ++ ++static int debug; ++ ++/*** M O D U L E C O D E ***/ ++ ++MODULE_AUTHOR(MOD_AUTHOR); ++MODULE_DESCRIPTION(MOD_DESC); ++MODULE_VERSION(MOD_VERSION); ++MODULE_LICENSE("GPL"); ++MODULE_DEVICE_TABLE(usb, imon_usb_id_table); ++module_param(debug, int, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)"); ++ ++static void free_imon_context(struct imon_context *context) ++{ ++ struct device *dev = context->driver->dev; ++ usb_free_urb(context->tx_urb); ++ usb_free_urb(context->rx_urb); ++ lirc_buffer_free(context->driver->rbuf); ++ kfree(context->driver->rbuf); ++ kfree(context->driver); ++ kfree(context); ++ ++ dev_dbg(dev, "%s: iMON context freed\n", __func__); ++} ++ ++static void deregister_from_lirc(struct imon_context *context) ++{ ++ int retval; ++ int minor = context->driver->minor; ++ ++ retval = lirc_unregister_driver(minor); ++ if (retval) ++ err("%s: unable to deregister from lirc(%d)", ++ __func__, retval); ++ else ++ printk(KERN_INFO MOD_NAME ": Deregistered iMON driver " ++ "(minor:%d)\n", minor); ++ ++} ++ ++/** ++ * Called when the Display device (e.g. /dev/lcd0) ++ * is opened by the application. ++ */ ++static int display_open(struct inode *inode, struct file *file) ++{ ++ struct usb_interface *interface; ++ struct imon_context *context = NULL; ++ int subminor; ++ int retval = 0; ++ ++ /* prevent races with disconnect */ ++ mutex_lock(&driver_lock); ++ ++ subminor = iminor(inode); ++ interface = usb_find_interface(&imon_driver, subminor); ++ if (!interface) { ++ err("%s: could not find interface for minor %d", ++ __func__, subminor); ++ retval = -ENODEV; ++ goto exit; ++ } ++ context = usb_get_intfdata(interface); ++ ++ if (!context) { ++ err("%s: no context found for minor %d", ++ __func__, subminor); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (!context->display) { ++ err("%s: display not supported by device", __func__); ++ retval = -ENODEV; ++ } else if (context->display_isopen) { ++ err("%s: display port is already open", __func__); ++ retval = -EBUSY; ++ } else { ++ context->display_isopen = 1; ++ file->private_data = context; ++ dev_info(context->driver->dev, "display port opened\n"); ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ ++exit: ++ mutex_unlock(&driver_lock); ++ return retval; ++} ++ ++/** ++ * Called when the display device (e.g. /dev/lcd0) ++ * is closed by the application. ++ */ ++static int display_close(struct inode *inode, struct file *file) ++{ ++ struct imon_context *context = NULL; ++ int retval = 0; ++ ++ context = (struct imon_context *)file->private_data; ++ ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (!context->display) { ++ err("%s: display not supported by device", __func__); ++ retval = -ENODEV; ++ } else if (!context->display_isopen) { ++ err("%s: display is not open", __func__); ++ retval = -EIO; ++ } else { ++ context->display_isopen = 0; ++ dev_info(context->driver->dev, "display port closed\n"); ++ if (!context->dev_present && !context->ir_isopen) { ++ /* ++ * Device disconnected before close and IR port is not ++ * open. If IR port is open, context will be deleted by ++ * ir_close. ++ */ ++ mutex_unlock(&context->ctx_lock); ++ free_imon_context(context); ++ return retval; ++ } ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ return retval; ++} ++ ++/** ++ * Sends a packet to the device -- this function must be called ++ * with context->ctx_lock held. ++ */ ++static int send_packet(struct imon_context *context) ++{ ++ unsigned int pipe; ++ int interval = 0; ++ int retval = 0; ++ struct usb_ctrlrequest *control_req = NULL; ++ ++ /* Check if we need to use control or interrupt urb */ ++ pipe = usb_sndintpipe(context->usbdev, ++ context->tx_endpoint->bEndpointAddress); ++ interval = context->tx_endpoint->bInterval; ++ ++ usb_fill_int_urb(context->tx_urb, context->usbdev, pipe, ++ context->usb_tx_buf, ++ sizeof(context->usb_tx_buf), ++ usb_tx_callback, context, interval); ++ ++ context->tx_urb->actual_length = 0; ++ ++ init_completion(&context->tx.finished); ++ atomic_set(&(context->tx.busy), 1); ++ ++ retval = usb_submit_urb(context->tx_urb, GFP_KERNEL); ++ if (retval) { ++ atomic_set(&(context->tx.busy), 0); ++ err("%s: error submitting urb(%d)", __func__, retval); ++ } else { ++ /* Wait for transmission to complete (or abort) */ ++ mutex_unlock(&context->ctx_lock); ++ retval = wait_for_completion_interruptible( ++ &context->tx.finished); ++ if (retval) ++ err("%s: task interrupted", __func__); ++ mutex_lock(&context->ctx_lock); ++ ++ retval = context->tx.status; ++ if (retval) ++ err("%s: packet tx failed (%d)", __func__, retval); ++ } ++ ++ kfree(control_req); ++ ++ return retval; ++} ++ ++/** ++ * Writes data to the VFD. The iMON VFD is 2x16 characters ++ * and requires data in 5 consecutive USB interrupt packets, ++ * each packet but the last carrying 7 bytes. ++ * ++ * I don't know if the VFD board supports features such as ++ * scrolling, clearing rows, blanking, etc. so at ++ * the caller must provide a full screen of data. If fewer ++ * than 32 bytes are provided spaces will be appended to ++ * generate a full screen. ++ */ ++static ssize_t vfd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos) ++{ ++ int i; ++ int offset; ++ int seq; ++ int retval = 0; ++ struct imon_context *context; ++ const unsigned char vfd_packet6[] = { ++ 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; ++ ++ context = (struct imon_context *)file->private_data; ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (!context->dev_present) { ++ err("%s: no iMON device present", __func__); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ if (n_bytes <= 0 || n_bytes > 32) { ++ err("%s: invalid payload size", __func__); ++ retval = -EINVAL; ++ goto exit; ++ } ++ ++ if (copy_from_user(context->tx.data_buf, buf, n_bytes)) { ++ retval = -EFAULT; ++ goto exit; ++ } ++ ++ /* Pad with spaces */ ++ for (i = n_bytes; i < 32; ++i) ++ context->tx.data_buf[i] = ' '; ++ ++ for (i = 32; i < 35; ++i) ++ context->tx.data_buf[i] = 0xFF; ++ ++ offset = 0; ++ seq = 0; ++ ++ do { ++ memcpy(context->usb_tx_buf, context->tx.data_buf + offset, 7); ++ context->usb_tx_buf[7] = (unsigned char) seq; ++ ++ retval = send_packet(context); ++ if (retval) { ++ err("%s: send packet failed for packet #%d", ++ __func__, seq/2); ++ goto exit; ++ } else { ++ seq += 2; ++ offset += 7; ++ } ++ ++ } while (offset < 35); ++ ++ if (context->vfd_proto_6p) { ++ /* Send packet #6 */ ++ memcpy(context->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6)); ++ context->usb_tx_buf[7] = (unsigned char) seq; ++ retval = send_packet(context); ++ if (retval) ++ err("%s: send packet failed for packet #%d", ++ __func__, seq/2); ++ } ++ ++exit: ++ mutex_unlock(&context->ctx_lock); ++ ++ return (!retval) ? n_bytes : retval; ++} ++ ++/** ++ * Callback function for USB core API: transmit data ++ */ ++static void usb_tx_callback(struct urb *urb) ++{ ++ struct imon_context *context; ++ ++ if (!urb) ++ return; ++ context = (struct imon_context *)urb->context; ++ if (!context) ++ return; ++ ++ context->tx.status = urb->status; ++ ++ /* notify waiters that write has finished */ ++ atomic_set(&context->tx.busy, 0); ++ complete(&context->tx.finished); ++ ++ return; ++} ++ ++/** ++ * Called by lirc_dev when the application opens /dev/lirc ++ */ ++static int ir_open(void *data) ++{ ++ int retval = 0; ++ struct imon_context *context; ++ ++ /* prevent races with disconnect */ ++ mutex_lock(&driver_lock); ++ ++ context = (struct imon_context *)data; ++ ++ /* initial IR protocol decode variables */ ++ context->rx.count = 0; ++ context->rx.initial_space = 1; ++ context->rx.prev_bit = 0; ++ ++ context->ir_isopen = 1; ++ dev_info(context->driver->dev, "IR port opened\n"); ++ ++ mutex_unlock(&driver_lock); ++ return retval; ++} ++ ++/** ++ * Called by lirc_dev when the application closes /dev/lirc ++ */ ++static void ir_close(void *data) ++{ ++ struct imon_context *context; ++ ++ context = (struct imon_context *)data; ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ context->ir_isopen = 0; ++ dev_info(context->driver->dev, "IR port closed\n"); ++ ++ if (!context->dev_present) { ++ /* ++ * Device disconnected while IR port was still open. Driver ++ * was not deregistered at disconnect time, so do it now. ++ */ ++ deregister_from_lirc(context); ++ ++ if (!context->display_isopen) { ++ mutex_unlock(&context->ctx_lock); ++ free_imon_context(context); ++ return; ++ } ++ /* ++ * If display port is open, context will be deleted by ++ * display_close ++ */ ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ return; ++} ++ ++/** ++ * Convert bit count to time duration (in us) and submit ++ * the value to lirc_dev. ++ */ ++static void submit_data(struct imon_context *context) ++{ ++ unsigned char buf[4]; ++ int value = context->rx.count; ++ int i; ++ ++ dev_dbg(context->driver->dev, "submitting data to LIRC\n"); ++ ++ value *= BIT_DURATION; ++ value &= PULSE_MASK; ++ if (context->rx.prev_bit) ++ value |= PULSE_BIT; ++ ++ for (i = 0; i < 4; ++i) ++ buf[i] = value>>(i*8); ++ ++ lirc_buffer_write(context->driver->rbuf, buf); ++ wake_up(&context->driver->rbuf->wait_poll); ++ return; ++} ++ ++static inline int tv2int(const struct timeval *a, const struct timeval *b) ++{ ++ int usecs = 0; ++ int sec = 0; ++ ++ if (b->tv_usec > a->tv_usec) { ++ usecs = 1000000; ++ sec--; ++ } ++ ++ usecs += a->tv_usec - b->tv_usec; ++ ++ sec += a->tv_sec - b->tv_sec; ++ sec *= 1000; ++ usecs /= 1000; ++ sec += usecs; ++ ++ if (sec < 0) ++ sec = 1000; ++ ++ return sec; ++} ++ ++/** ++ * Process the incoming packet ++ */ ++static void imon_incoming_packet(struct imon_context *context, ++ struct urb *urb, int intf) ++{ ++ int len = urb->actual_length; ++ unsigned char *buf = urb->transfer_buffer; ++ struct device *dev = context->driver->dev; ++ int octet, bit; ++ unsigned char mask; ++ int i, chunk_num; ++ ++ /* ++ * just bail out if no listening IR client ++ */ ++ if (!context->ir_isopen) ++ return; ++ ++ if (len != 8) { ++ dev_warn(dev, "imon %s: invalid incoming packet " ++ "size (len = %d, intf%d)\n", __func__, len, intf); ++ return; ++ } ++ ++ if (debug) { ++ printk(KERN_INFO "raw packet: "); ++ for (i = 0; i < len; ++i) ++ printk("%02x ", buf[i]); ++ printk("\n"); ++ } ++ ++ /* ++ * Translate received data to pulse and space lengths. ++ * Received data is active low, i.e. pulses are 0 and ++ * spaces are 1. ++ * ++ * My original algorithm was essentially similar to ++ * Changwoo Ryu's with the exception that he switched ++ * the incoming bits to active high and also fed an ++ * initial space to LIRC at the start of a new sequence ++ * if the previous bit was a pulse. ++ * ++ * I've decided to adopt his algorithm. ++ */ ++ ++ if (buf[7] == 1 && context->rx.initial_space) { ++ /* LIRC requires a leading space */ ++ context->rx.prev_bit = 0; ++ context->rx.count = 4; ++ submit_data(context); ++ context->rx.count = 0; ++ } ++ ++ for (octet = 0; octet < 5; ++octet) { ++ mask = 0x80; ++ for (bit = 0; bit < 8; ++bit) { ++ int curr_bit = !(buf[octet] & mask); ++ if (curr_bit != context->rx.prev_bit) { ++ if (context->rx.count) { ++ submit_data(context); ++ context->rx.count = 0; ++ } ++ context->rx.prev_bit = curr_bit; ++ } ++ ++context->rx.count; ++ mask >>= 1; ++ } ++ } ++ ++ if (chunk_num == 10) { ++ if (context->rx.count) { ++ submit_data(context); ++ context->rx.count = 0; ++ } ++ context->rx.initial_space = context->rx.prev_bit; ++ } ++} ++ ++/** ++ * Callback function for USB core API: receive data ++ */ ++static void usb_rx_callback(struct urb *urb) ++{ ++ struct imon_context *context; ++ unsigned char *buf; ++ int len; ++ int intfnum = 0; ++ ++ if (!urb) ++ return; ++ ++ context = (struct imon_context *)urb->context; ++ if (!context) ++ return; ++ ++ buf = urb->transfer_buffer; ++ len = urb->actual_length; ++ ++ switch (urb->status) { ++ case -ENOENT: /* usbcore unlink successful! */ ++ return; ++ ++ case 0: ++ imon_incoming_packet(context, urb, intfnum); ++ break; ++ ++ default: ++ dev_warn(context->driver->dev, "imon %s: status(%d): ignored\n", ++ __func__, urb->status); ++ break; ++ } ++ ++ usb_submit_urb(context->rx_urb, GFP_ATOMIC); ++ ++ return; ++} ++ ++/** ++ * Callback function for USB core API: Probe ++ */ ++static int imon_probe(struct usb_interface *interface, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *usbdev = NULL; ++ struct usb_host_interface *iface_desc = NULL; ++ struct usb_endpoint_descriptor *rx_endpoint = NULL; ++ struct usb_endpoint_descriptor *tx_endpoint = NULL; ++ struct urb *rx_urb = NULL; ++ struct urb *tx_urb = NULL; ++ struct lirc_driver *driver = NULL; ++ struct lirc_buffer *rbuf = NULL; ++ struct device *dev = &interface->dev; ++ int ifnum; ++ int lirc_minor = 0; ++ int num_endpts; ++ int retval = 0; ++ int display_ep_found = 0; ++ int ir_ep_found = 0; ++ int alloc_status = 0; ++ int vfd_proto_6p = 0; ++ int code_length; ++ struct imon_context *context = NULL; ++ int i; ++ u16 vendor, product; ++ ++ context = kzalloc(sizeof(struct imon_context), GFP_KERNEL); ++ if (!context) { ++ err("%s: kzalloc failed for context", __func__); ++ alloc_status = 1; ++ goto alloc_status_switch; ++ } ++ ++ /* ++ * Try to auto-detect the type of display if the user hasn't set ++ * it by hand via the display_type modparam. Default is VFD. ++ */ ++ if (usb_match_id(interface, ir_only_list)) ++ context->display = 0; ++ else ++ context->display = 1; ++ ++ code_length = BUF_CHUNK_SIZE * 8; ++ ++ usbdev = usb_get_dev(interface_to_usbdev(interface)); ++ iface_desc = interface->cur_altsetting; ++ num_endpts = iface_desc->desc.bNumEndpoints; ++ ifnum = iface_desc->desc.bInterfaceNumber; ++ vendor = le16_to_cpu(usbdev->descriptor.idVendor); ++ product = le16_to_cpu(usbdev->descriptor.idProduct); ++ ++ dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n", ++ __func__, vendor, product, ifnum); ++ ++ /* prevent races probing devices w/multiple interfaces */ ++ mutex_lock(&driver_lock); ++ ++ /* ++ * Scan the endpoint list and set: ++ * first input endpoint = IR endpoint ++ * first output endpoint = display endpoint ++ */ ++ for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) { ++ struct usb_endpoint_descriptor *ep; ++ int ep_dir; ++ int ep_type; ++ ep = &iface_desc->endpoint[i].desc; ++ ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK; ++ ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; ++ ++ if (!ir_ep_found && ++ ep_dir == USB_DIR_IN && ++ ep_type == USB_ENDPOINT_XFER_INT) { ++ ++ rx_endpoint = ep; ++ ir_ep_found = 1; ++ dev_dbg(dev, "%s: found IR endpoint\n", __func__); ++ ++ } else if (!display_ep_found && ep_dir == USB_DIR_OUT && ++ ep_type == USB_ENDPOINT_XFER_INT) { ++ tx_endpoint = ep; ++ display_ep_found = 1; ++ dev_dbg(dev, "%s: found display endpoint\n", __func__); ++ } ++ } ++ ++ /* ++ * Some iMON receivers have no display. Unfortunately, it seems ++ * that SoundGraph recycles device IDs between devices both with ++ * and without... :\ ++ */ ++ if (context->display == 0) { ++ display_ep_found = 0; ++ dev_dbg(dev, "%s: device has no display\n", __func__); ++ } ++ ++ /* Input endpoint is mandatory */ ++ if (!ir_ep_found) { ++ err("%s: no valid input (IR) endpoint found.", __func__); ++ retval = -ENODEV; ++ alloc_status = 2; ++ goto alloc_status_switch; ++ } ++ ++ /* Determine if display requires 6 packets */ ++ if (display_ep_found) { ++ if (usb_match_id(interface, vfd_proto_6p_list)) ++ vfd_proto_6p = 1; ++ ++ dev_dbg(dev, "%s: vfd_proto_6p: %d\n", ++ __func__, vfd_proto_6p); ++ } ++ ++ driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); ++ if (!driver) { ++ err("%s: kzalloc failed for lirc_driver", __func__); ++ alloc_status = 2; ++ goto alloc_status_switch; ++ } ++ rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!rbuf) { ++ err("%s: kmalloc failed for lirc_buffer", __func__); ++ alloc_status = 3; ++ goto alloc_status_switch; ++ } ++ if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) { ++ err("%s: lirc_buffer_init failed", __func__); ++ alloc_status = 4; ++ goto alloc_status_switch; ++ } ++ rx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!rx_urb) { ++ err("%s: usb_alloc_urb failed for IR urb", __func__); ++ alloc_status = 5; ++ goto alloc_status_switch; ++ } ++ tx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!tx_urb) { ++ err("%s: usb_alloc_urb failed for display urb", ++ __func__); ++ alloc_status = 6; ++ goto alloc_status_switch; ++ } ++ ++ mutex_init(&context->ctx_lock); ++ context->vfd_proto_6p = vfd_proto_6p; ++ ++ strcpy(driver->name, MOD_NAME); ++ driver->minor = -1; ++ driver->code_length = sizeof(int) * 8; ++ driver->sample_rate = 0; ++ driver->features = LIRC_CAN_REC_MODE2; ++ driver->data = context; ++ driver->rbuf = rbuf; ++ driver->set_use_inc = ir_open; ++ driver->set_use_dec = ir_close; ++ driver->dev = &interface->dev; ++ driver->owner = THIS_MODULE; ++ ++ mutex_lock(&context->ctx_lock); ++ ++ context->driver = driver; ++ /* start out in keyboard mode */ ++ ++ lirc_minor = lirc_register_driver(driver); ++ if (lirc_minor < 0) { ++ err("%s: lirc_register_driver failed", __func__); ++ alloc_status = 7; ++ goto alloc_status_switch; ++ } else ++ dev_info(dev, "Registered iMON driver " ++ "(lirc minor: %d)\n", lirc_minor); ++ ++ /* Needed while unregistering! */ ++ driver->minor = lirc_minor; ++ ++ context->usbdev = usbdev; ++ context->dev_present = 1; ++ context->rx_endpoint = rx_endpoint; ++ context->rx_urb = rx_urb; ++ ++ /* ++ * tx is used to send characters to lcd/vfd, associate RF ++ * remotes, set IR protocol, and maybe more... ++ */ ++ context->tx_endpoint = tx_endpoint; ++ context->tx_urb = tx_urb; ++ ++ if (display_ep_found) ++ context->display = 1; ++ ++ usb_fill_int_urb(context->rx_urb, context->usbdev, ++ usb_rcvintpipe(context->usbdev, ++ context->rx_endpoint->bEndpointAddress), ++ context->usb_rx_buf, sizeof(context->usb_rx_buf), ++ usb_rx_callback, context, ++ context->rx_endpoint->bInterval); ++ ++ retval = usb_submit_urb(context->rx_urb, GFP_KERNEL); ++ ++ if (retval) { ++ err("%s: usb_submit_urb failed for intf0 (%d)", ++ __func__, retval); ++ mutex_unlock(&context->ctx_lock); ++ goto exit; ++ } ++ ++ usb_set_intfdata(interface, context); ++ ++ if (context->display && ifnum == 0) { ++ dev_dbg(dev, "%s: Registering iMON display with sysfs\n", ++ __func__); ++ ++ if (usb_register_dev(interface, &imon_class)) { ++ /* Not a fatal error, so ignore */ ++ dev_info(dev, "%s: could not get a minor number for " ++ "display\n", __func__); ++ } ++ } ++ ++ dev_info(dev, "iMON device (%04x:%04x, intf%d) on " ++ "usb<%d:%d> initialized\n", vendor, product, ifnum, ++ usbdev->bus->busnum, usbdev->devnum); ++ ++alloc_status_switch: ++ mutex_unlock(&context->ctx_lock); ++ ++ switch (alloc_status) { ++ case 7: ++ usb_free_urb(tx_urb); ++ case 6: ++ usb_free_urb(rx_urb); ++ case 5: ++ if (rbuf) ++ lirc_buffer_free(rbuf); ++ case 4: ++ kfree(rbuf); ++ case 3: ++ kfree(driver); ++ case 2: ++ kfree(context); ++ context = NULL; ++ case 1: ++ if (retval != -ENODEV) ++ retval = -ENOMEM; ++ break; ++ case 0: ++ retval = 0; ++ } ++ ++exit: ++ mutex_unlock(&driver_lock); ++ ++ return retval; ++} ++ ++/** ++ * Callback function for USB core API: disconnect ++ */ ++static void imon_disconnect(struct usb_interface *interface) ++{ ++ struct imon_context *context; ++ int ifnum; ++ ++ /* prevent races with ir_open()/display_open() */ ++ mutex_lock(&driver_lock); ++ ++ context = usb_get_intfdata(interface); ++ ifnum = interface->cur_altsetting->desc.bInterfaceNumber; ++ ++ mutex_lock(&context->ctx_lock); ++ ++ usb_set_intfdata(interface, NULL); ++ ++ /* Abort ongoing write */ ++ if (atomic_read(&context->tx.busy)) { ++ usb_kill_urb(context->tx_urb); ++ complete_all(&context->tx.finished); ++ } ++ ++ context->dev_present = 0; ++ usb_kill_urb(context->rx_urb); ++ if (context->display) ++ usb_deregister_dev(interface, &imon_class); ++ ++ if (!context->ir_isopen && !context->dev_present) { ++ deregister_from_lirc(context); ++ mutex_unlock(&context->ctx_lock); ++ if (!context->display_isopen) ++ free_imon_context(context); ++ } else ++ mutex_unlock(&context->ctx_lock); ++ ++ mutex_unlock(&driver_lock); ++ ++ printk(KERN_INFO "%s: iMON device (intf%d) disconnected\n", ++ __func__, ifnum); ++} ++ ++static int imon_suspend(struct usb_interface *intf, pm_message_t message) ++{ ++ struct imon_context *context = usb_get_intfdata(intf); ++ ++ usb_kill_urb(context->rx_urb); ++ ++ return 0; ++} ++ ++static int imon_resume(struct usb_interface *intf) ++{ ++ int rc = 0; ++ struct imon_context *context = usb_get_intfdata(intf); ++ ++ usb_fill_int_urb(context->rx_urb, context->usbdev, ++ usb_rcvintpipe(context->usbdev, ++ context->rx_endpoint->bEndpointAddress), ++ context->usb_rx_buf, sizeof(context->usb_rx_buf), ++ usb_rx_callback, context, ++ context->rx_endpoint->bInterval); ++ ++ rc = usb_submit_urb(context->rx_urb, GFP_ATOMIC); ++ ++ return rc; ++} ++ ++static int __init imon_init(void) ++{ ++ int rc; ++ ++ printk(KERN_INFO MOD_NAME ": " MOD_DESC ", v" MOD_VERSION "\n"); ++ ++ rc = usb_register(&imon_driver); ++ if (rc) { ++ err("%s: usb register failed(%d)", __func__, rc); ++ return -ENODEV; ++ } ++ ++ return 0; ++} ++ ++static void __exit imon_exit(void) ++{ ++ usb_deregister(&imon_driver); ++ printk(KERN_INFO MOD_NAME ": module removed. Goodbye!\n"); ++} ++ ++module_init(imon_init); ++module_exit(imon_exit); +diff --git a/drivers/input/lirc/lirc_it87.c b/drivers/input/lirc/lirc_it87.c +new file mode 100644 +index 0000000..a899d00 +--- /dev/null ++++ b/drivers/input/lirc/lirc_it87.c +@@ -0,0 +1,1021 @@ ++/* ++ * LIRC driver for ITE IT8712/IT8705 CIR port ++ * ++ * Copyright (C) 2001 Hans-Gunter Lutke Uphues ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ++ * USA ++ * ++ * ITE IT8705 and IT8712(not tested) and IT8720 CIR-port support for lirc based ++ * via cut and paste from lirc_sir.c (C) 2000 Milan Pikula ++ * ++ * Attention: Sendmode only tested with debugging logs ++ * ++ * 2001/02/27 Christoph Bartelmus : ++ * reimplemented read function ++ * 2005/06/05 Andrew Calkin implemented support for Asus Digimatrix, ++ * based on work of the following member of the Outertrack Digimatrix ++ * Forum: Art103 ++ * 2009/12/24 James Edwards implemeted support ++ * for ITE8704/ITE8718, on my machine, the DSDT reports 8704, but the ++ * chip identifies as 18. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++#include "lirc_it87.h" ++ ++#ifdef LIRC_IT87_DIGIMATRIX ++static int digimatrix = 1; ++static int it87_freq = 36; /* kHz */ ++static int irq = 9; ++#else ++static int digimatrix; ++static int it87_freq = 38; /* kHz */ ++static int irq = IT87_CIR_DEFAULT_IRQ; ++#endif ++ ++static unsigned long it87_bits_in_byte_out; ++static unsigned long it87_send_counter; ++static unsigned char it87_RXEN_mask = IT87_CIR_RCR_RXEN; ++ ++#define RBUF_LEN 1024 ++#define WBUF_LEN 1024 ++ ++#define LIRC_DRIVER_NAME "lirc_it87" ++ ++/* timeout for sequences in jiffies (=5/100s) */ ++/* must be longer than TIME_CONST */ ++#define IT87_TIMEOUT (HZ*5/100) ++ ++/* module parameters */ ++static int debug; ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \ ++ fmt, ## args); \ ++ } while (0) ++ ++static int io = IT87_CIR_DEFAULT_IOBASE; ++/* receiver demodulator default: off */ ++static int it87_enable_demodulator; ++ ++static int timer_enabled; ++static DEFINE_SPINLOCK(timer_lock); ++static struct timer_list timerlist; ++/* time of last signal change detected */ ++static struct timeval last_tv = {0, 0}; ++/* time of last UART data ready interrupt */ ++static struct timeval last_intr_tv = {0, 0}; ++static int last_value; ++ ++static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue); ++ ++static DEFINE_SPINLOCK(hardware_lock); ++static DEFINE_SPINLOCK(dev_lock); ++ ++static int rx_buf[RBUF_LEN]; ++unsigned int rx_tail, rx_head; ++static int tx_buf[WBUF_LEN]; ++ ++static struct pnp_driver it87_pnp_driver; ++ ++/* SECTION: Prototypes */ ++ ++/* Communication with user-space */ ++static int lirc_open(struct inode *inode, struct file *file); ++static int lirc_close(struct inode *inode, struct file *file); ++static unsigned int lirc_poll(struct file *file, poll_table *wait); ++static ssize_t lirc_read(struct file *file, char *buf, ++ size_t count, loff_t *ppos); ++static ssize_t lirc_write(struct file *file, const char *buf, ++ size_t n, loff_t *pos); ++static int lirc_ioctl(struct inode *node, struct file *filep, ++ unsigned int cmd, unsigned long arg); ++static void add_read_queue(int flag, unsigned long val); ++static int init_chrdev(void); ++static void drop_chrdev(void); ++/* Hardware */ ++static irqreturn_t it87_interrupt(int irq, void *dev_id); ++static void send_space(unsigned long len); ++static void send_pulse(unsigned long len); ++static void init_send(void); ++static void terminate_send(unsigned long len); ++static int init_hardware(void); ++static void drop_hardware(void); ++/* Initialisation */ ++static int init_port(void); ++static void drop_port(void); ++ ++ ++/* SECTION: Communication with user-space */ ++ ++static int lirc_open(struct inode *inode, struct file *file) ++{ ++ spin_lock(&dev_lock); ++ if (module_refcount(THIS_MODULE)) { ++ spin_unlock(&dev_lock); ++ return -EBUSY; ++ } ++ spin_unlock(&dev_lock); ++ return 0; ++} ++ ++ ++static int lirc_close(struct inode *inode, struct file *file) ++{ ++ return 0; ++} ++ ++ ++static unsigned int lirc_poll(struct file *file, poll_table *wait) ++{ ++ poll_wait(file, &lirc_read_queue, wait); ++ if (rx_head != rx_tail) ++ return POLLIN | POLLRDNORM; ++ return 0; ++} ++ ++ ++static ssize_t lirc_read(struct file *file, char *buf, ++ size_t count, loff_t *ppos) ++{ ++ int n = 0; ++ int retval = 0; ++ ++ while (n < count) { ++ if (file->f_flags & O_NONBLOCK && rx_head == rx_tail) { ++ retval = -EAGAIN; ++ break; ++ } ++ retval = wait_event_interruptible(lirc_read_queue, ++ rx_head != rx_tail); ++ if (retval) ++ break; ++ ++ if (copy_to_user((void *) buf + n, (void *) (rx_buf + rx_head), ++ sizeof(int))) { ++ retval = -EFAULT; ++ break; ++ } ++ rx_head = (rx_head + 1) & (RBUF_LEN - 1); ++ n += sizeof(int); ++ } ++ if (n) ++ return n; ++ return retval; ++} ++ ++ ++static ssize_t lirc_write(struct file *file, const char *buf, ++ size_t n, loff_t *pos) ++{ ++ int i = 0; ++ ++ if (n % sizeof(int) || (n / sizeof(int)) > WBUF_LEN) ++ return -EINVAL; ++ if (copy_from_user(tx_buf, buf, n)) ++ return -EFAULT; ++ n /= sizeof(int); ++ init_send(); ++ while (1) { ++ if (i >= n) ++ break; ++ if (tx_buf[i]) ++ send_pulse(tx_buf[i]); ++ i++; ++ if (i >= n) ++ break; ++ if (tx_buf[i]) ++ send_space(tx_buf[i]); ++ i++; ++ } ++ terminate_send(tx_buf[i - 1]); ++ return n; ++} ++ ++ ++static int lirc_ioctl(struct inode *node, struct file *filep, ++ unsigned int cmd, unsigned long arg) ++{ ++ int retval = 0; ++ unsigned long value = 0; ++ unsigned int ivalue; ++ unsigned long hw_flags; ++ ++ if (cmd == LIRC_GET_FEATURES) ++ value = LIRC_CAN_SEND_PULSE | ++ LIRC_CAN_SET_SEND_CARRIER | ++ LIRC_CAN_REC_MODE2; ++ else if (cmd == LIRC_GET_SEND_MODE) ++ value = LIRC_MODE_PULSE; ++ else if (cmd == LIRC_GET_REC_MODE) ++ value = LIRC_MODE_MODE2; ++ ++ switch (cmd) { ++ case LIRC_GET_FEATURES: ++ case LIRC_GET_SEND_MODE: ++ case LIRC_GET_REC_MODE: ++ retval = put_user(value, (unsigned long *) arg); ++ break; ++ ++ case LIRC_SET_SEND_MODE: ++ case LIRC_SET_REC_MODE: ++ retval = get_user(value, (unsigned long *) arg); ++ break; ++ ++ case LIRC_SET_SEND_CARRIER: ++ retval = get_user(ivalue, (unsigned int *) arg); ++ if (retval) ++ return retval; ++ ivalue /= 1000; ++ if (ivalue > IT87_CIR_FREQ_MAX || ++ ivalue < IT87_CIR_FREQ_MIN) ++ return -EINVAL; ++ ++ it87_freq = ivalue; ++ ++ spin_lock_irqsave(&hardware_lock, hw_flags); ++ outb(((inb(io + IT87_CIR_TCR2) & IT87_CIR_TCR2_TXMPW) | ++ (it87_freq - IT87_CIR_FREQ_MIN) << 3), ++ io + IT87_CIR_TCR2); ++ spin_unlock_irqrestore(&hardware_lock, hw_flags); ++ dprintk("demodulation frequency: %d kHz\n", it87_freq); ++ ++ break; ++ ++ default: ++ retval = -EINVAL; ++ } ++ ++ if (retval) ++ return retval; ++ ++ if (cmd == LIRC_SET_REC_MODE) { ++ if (value != LIRC_MODE_MODE2) ++ retval = -ENOSYS; ++ } else if (cmd == LIRC_SET_SEND_MODE) { ++ if (value != LIRC_MODE_PULSE) ++ retval = -ENOSYS; ++ } ++ return retval; ++} ++ ++static void add_read_queue(int flag, unsigned long val) ++{ ++ unsigned int new_rx_tail; ++ int newval; ++ ++ dprintk("add flag %d with val %lu\n", flag, val); ++ ++ newval = val & PULSE_MASK; ++ ++ /* ++ * statistically, pulses are ~TIME_CONST/2 too long. we could ++ * maybe make this more exact, but this is good enough ++ */ ++ if (flag) { ++ /* pulse */ ++ if (newval > TIME_CONST / 2) ++ newval -= TIME_CONST / 2; ++ else /* should not ever happen */ ++ newval = 1; ++ newval |= PULSE_BIT; ++ } else ++ newval += TIME_CONST / 2; ++ new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1); ++ if (new_rx_tail == rx_head) { ++ dprintk("Buffer overrun.\n"); ++ return; ++ } ++ rx_buf[rx_tail] = newval; ++ rx_tail = new_rx_tail; ++ wake_up_interruptible(&lirc_read_queue); ++} ++ ++ ++static struct file_operations lirc_fops = { ++ .owner = THIS_MODULE, ++ .read = lirc_read, ++ .write = lirc_write, ++ .poll = lirc_poll, ++ .ioctl = lirc_ioctl, ++ .open = lirc_open, ++ .release = lirc_close, ++}; ++ ++static int set_use_inc(void *data) ++{ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++} ++ ++static struct lirc_driver driver = { ++ .name = LIRC_DRIVER_NAME, ++ .minor = -1, ++ .code_length = 1, ++ .sample_rate = 0, ++ .data = NULL, ++ .add_to_buf = NULL, ++ .set_use_inc = set_use_inc, ++ .set_use_dec = set_use_dec, ++ .fops = &lirc_fops, ++ .dev = NULL, ++ .owner = THIS_MODULE, ++}; ++ ++ ++#ifdef MODULE ++static int init_chrdev(void) ++{ ++ driver.minor = lirc_register_driver(&driver); ++ ++ if (driver.minor < 0) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n"); ++ return -EIO; ++ } ++ return 0; ++} ++ ++ ++static void drop_chrdev(void) ++{ ++ lirc_unregister_driver(driver.minor); ++} ++#endif ++ ++ ++/* SECTION: Hardware */ ++static long delta(struct timeval *tv1, struct timeval *tv2) ++{ ++ unsigned long deltv; ++ ++ deltv = tv2->tv_sec - tv1->tv_sec; ++ if (deltv > 15) ++ deltv = 0xFFFFFF; ++ else ++ deltv = deltv*1000000 + tv2->tv_usec - tv1->tv_usec; ++ return deltv; ++} ++ ++static void it87_timeout(unsigned long data) ++{ ++ unsigned long flags; ++ ++ /* avoid interference with interrupt */ ++ spin_lock_irqsave(&timer_lock, flags); ++ ++ if (digimatrix) { ++ /* We have timed out. Disable the RX mechanism. */ ++ ++ outb((inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN) | ++ IT87_CIR_RCR_RXACT, io + IT87_CIR_RCR); ++ if (it87_RXEN_mask) ++ outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN, ++ io + IT87_CIR_RCR); ++ dprintk(" TIMEOUT\n"); ++ timer_enabled = 0; ++ ++ /* fifo clear */ ++ outb(inb(io + IT87_CIR_TCR1) | IT87_CIR_TCR1_FIFOCLR, ++ io+IT87_CIR_TCR1); ++ ++ } else { ++ /* ++ * if last received signal was a pulse, but receiving stopped ++ * within the 9 bit frame, we need to finish this pulse and ++ * simulate a signal change to from pulse to space. Otherwise ++ * upper layers will receive two sequences next time. ++ */ ++ ++ if (last_value) { ++ unsigned long pulse_end; ++ ++ /* determine 'virtual' pulse end: */ ++ pulse_end = delta(&last_tv, &last_intr_tv); ++ dprintk("timeout add %d for %lu usec\n", ++ last_value, pulse_end); ++ add_read_queue(last_value, pulse_end); ++ last_value = 0; ++ last_tv = last_intr_tv; ++ } ++ } ++ spin_unlock_irqrestore(&timer_lock, flags); ++} ++ ++static irqreturn_t it87_interrupt(int irq, void *dev_id) ++{ ++ unsigned char data; ++ struct timeval curr_tv; ++ static unsigned long deltv; ++ unsigned long deltintrtv; ++ unsigned long flags, hw_flags; ++ int iir, lsr; ++ int fifo = 0; ++ static char lastbit; ++ char bit; ++ ++ /* Bit duration in microseconds */ ++ const unsigned long bit_duration = 1000000ul / ++ (115200 / IT87_CIR_BAUDRATE_DIVISOR); ++ ++ ++ iir = inb(io + IT87_CIR_IIR); ++ ++ switch (iir & IT87_CIR_IIR_IID) { ++ case 0x4: ++ case 0x6: ++ lsr = inb(io + IT87_CIR_RSR) & (IT87_CIR_RSR_RXFTO | ++ IT87_CIR_RSR_RXFBC); ++ fifo = lsr & IT87_CIR_RSR_RXFBC; ++ dprintk("iir: 0x%x fifo: 0x%x\n", iir, lsr); ++ ++ /* avoid interference with timer */ ++ spin_lock_irqsave(&timer_lock, flags); ++ spin_lock_irqsave(&hardware_lock, hw_flags); ++ if (digimatrix) { ++ static unsigned long acc_pulse; ++ static unsigned long acc_space; ++ ++ do { ++ data = inb(io + IT87_CIR_DR); ++ data = ~data; ++ fifo--; ++ if (data != 0x00) { ++ if (timer_enabled) ++ del_timer(&timerlist); ++ /* ++ * start timer for end of ++ * sequence detection ++ */ ++ timerlist.expires = jiffies + ++ IT87_TIMEOUT; ++ add_timer(&timerlist); ++ timer_enabled = 1; ++ } ++ /* Loop through */ ++ for (bit = 0; bit < 8; ++bit) { ++ if ((data >> bit) & 1) { ++ ++acc_pulse; ++ if (lastbit == 0) { ++ add_read_queue(0, ++ acc_space * ++ bit_duration); ++ acc_space = 0; ++ } ++ } else { ++ ++acc_space; ++ if (lastbit == 1) { ++ add_read_queue(1, ++ acc_pulse * ++ bit_duration); ++ acc_pulse = 0; ++ } ++ } ++ lastbit = (data >> bit) & 1; ++ } ++ ++ } while (fifo != 0); ++ } else { /* Normal Operation */ ++ do { ++ del_timer(&timerlist); ++ data = inb(io + IT87_CIR_DR); ++ ++ dprintk("data=%02x\n", data); ++ do_gettimeofday(&curr_tv); ++ deltv = delta(&last_tv, &curr_tv); ++ deltintrtv = delta(&last_intr_tv, &curr_tv); ++ ++ dprintk("t %lu , d %d\n", ++ deltintrtv, (int)data); ++ ++ /* ++ * if nothing came in last 2 cycles, ++ * it was gap ++ */ ++ if (deltintrtv > TIME_CONST * 2) { ++ if (last_value) { ++ dprintk("GAP\n"); ++ ++ /* simulate signal change */ ++ add_read_queue(last_value, ++ deltv - ++ deltintrtv); ++ last_value = 0; ++ last_tv.tv_sec = ++ last_intr_tv.tv_sec; ++ last_tv.tv_usec = ++ last_intr_tv.tv_usec; ++ deltv = deltintrtv; ++ } ++ } ++ data = 1; ++ if (data ^ last_value) { ++ /* ++ * deltintrtv > 2*TIME_CONST, ++ * remember ? the other case is ++ * timeout ++ */ ++ add_read_queue(last_value, ++ deltv-TIME_CONST); ++ last_value = data; ++ last_tv = curr_tv; ++ if (last_tv.tv_usec >= TIME_CONST) ++ last_tv.tv_usec -= TIME_CONST; ++ else { ++ last_tv.tv_sec--; ++ last_tv.tv_usec += 1000000 - ++ TIME_CONST; ++ } ++ } ++ last_intr_tv = curr_tv; ++ if (data) { ++ /* ++ * start timer for end of ++ * sequence detection ++ */ ++ timerlist.expires = ++ jiffies + IT87_TIMEOUT; ++ add_timer(&timerlist); ++ } ++ outb((inb(io + IT87_CIR_RCR) & ++ ~IT87_CIR_RCR_RXEN) | ++ IT87_CIR_RCR_RXACT, ++ io + IT87_CIR_RCR); ++ if (it87_RXEN_mask) ++ outb(inb(io + IT87_CIR_RCR) | ++ IT87_CIR_RCR_RXEN, ++ io + IT87_CIR_RCR); ++ fifo--; ++ } while (fifo != 0); ++ } ++ spin_unlock_irqrestore(&hardware_lock, hw_flags); ++ spin_unlock_irqrestore(&timer_lock, flags); ++ ++ return IRQ_RETVAL(IRQ_HANDLED); ++ ++ default: ++ /* not our irq */ ++ dprintk("unknown IRQ (shouldn't happen) !!\n"); ++ return IRQ_RETVAL(IRQ_NONE); ++ } ++} ++ ++ ++static void send_it87(unsigned long len, unsigned long stime, ++ unsigned char send_byte, unsigned int count_bits) ++{ ++ long count = len / stime; ++ long time_left = 0; ++ static unsigned char byte_out; ++ unsigned long hw_flags; ++ ++ dprintk("%s: len=%ld, sb=%d\n", __func__, len, send_byte); ++ ++ time_left = (long)len - (long)count * (long)stime; ++ count += ((2 * time_left) / stime); ++ while (count) { ++ long i = 0; ++ for (i = 0; i < count_bits; i++) { ++ byte_out = (byte_out << 1) | (send_byte & 1); ++ it87_bits_in_byte_out++; ++ } ++ if (it87_bits_in_byte_out == 8) { ++ dprintk("out=0x%x, tsr_txfbc: 0x%x\n", ++ byte_out, ++ inb(io + IT87_CIR_TSR) & ++ IT87_CIR_TSR_TXFBC); ++ ++ while ((inb(io + IT87_CIR_TSR) & ++ IT87_CIR_TSR_TXFBC) >= IT87_CIR_FIFO_SIZE) ++ ; ++ ++ spin_lock_irqsave(&hardware_lock, hw_flags); ++ outb(byte_out, io + IT87_CIR_DR); ++ spin_unlock_irqrestore(&hardware_lock, hw_flags); ++ ++ it87_bits_in_byte_out = 0; ++ it87_send_counter++; ++ byte_out = 0; ++ } ++ count--; ++ } ++} ++ ++ ++/*TODO: maybe exchange space and pulse because it8705 only modulates 0-bits */ ++ ++static void send_space(unsigned long len) ++{ ++ send_it87(len, TIME_CONST, IT87_CIR_SPACE, IT87_CIR_BAUDRATE_DIVISOR); ++} ++ ++static void send_pulse(unsigned long len) ++{ ++ send_it87(len, TIME_CONST, IT87_CIR_PULSE, IT87_CIR_BAUDRATE_DIVISOR); ++} ++ ++ ++static void init_send() ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&hardware_lock, flags); ++ /* RXEN=0: receiver disable */ ++ it87_RXEN_mask = 0; ++ outb(inb(io + IT87_CIR_RCR) & ~IT87_CIR_RCR_RXEN, ++ io + IT87_CIR_RCR); ++ spin_unlock_irqrestore(&hardware_lock, flags); ++ it87_bits_in_byte_out = 0; ++ it87_send_counter = 0; ++} ++ ++ ++static void terminate_send(unsigned long len) ++{ ++ unsigned long flags; ++ unsigned long last = 0; ++ ++ last = it87_send_counter; ++ /* make sure all necessary data has been sent */ ++ while (last == it87_send_counter) ++ send_space(len); ++ /* wait until all data sent */ ++ while ((inb(io + IT87_CIR_TSR) & IT87_CIR_TSR_TXFBC) != 0) ++ ; ++ /* then re-enable receiver */ ++ spin_lock_irqsave(&hardware_lock, flags); ++ it87_RXEN_mask = IT87_CIR_RCR_RXEN; ++ outb(inb(io + IT87_CIR_RCR) | IT87_CIR_RCR_RXEN, ++ io + IT87_CIR_RCR); ++ spin_unlock_irqrestore(&hardware_lock, flags); ++} ++ ++ ++static int init_hardware(void) ++{ ++ unsigned long flags; ++ unsigned char it87_rcr = 0; ++ ++ spin_lock_irqsave(&hardware_lock, flags); ++ /* init cir-port */ ++ /* enable r/w-access to Baudrate-Register */ ++ outb(IT87_CIR_IER_BR, io + IT87_CIR_IER); ++ outb(IT87_CIR_BAUDRATE_DIVISOR % 0x100, io+IT87_CIR_BDLR); ++ outb(IT87_CIR_BAUDRATE_DIVISOR / 0x100, io+IT87_CIR_BDHR); ++ /* Baudrate Register off, define IRQs: Input only */ ++ if (digimatrix) { ++ outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RFOIE, io + IT87_CIR_IER); ++ /* RX: HCFS=0, RXDCR = 001b (33,75..38,25 kHz), RXEN=1 */ ++ } else { ++ outb(IT87_CIR_IER_IEC | IT87_CIR_IER_RDAIE, io + IT87_CIR_IER); ++ /* RX: HCFS=0, RXDCR = 001b (35,6..40,3 kHz), RXEN=1 */ ++ } ++ it87_rcr = (IT87_CIR_RCR_RXEN & it87_RXEN_mask) | 0x1; ++ if (it87_enable_demodulator) ++ it87_rcr |= IT87_CIR_RCR_RXEND; ++ outb(it87_rcr, io + IT87_CIR_RCR); ++ if (digimatrix) { ++ /* Set FIFO depth to 1 byte, and disable TX */ ++ outb(inb(io + IT87_CIR_TCR1) | 0x00, ++ io + IT87_CIR_TCR1); ++ ++ /* ++ * TX: it87_freq (36kHz), 'reserved' sensitivity ++ * setting (0x00) ++ */ ++ outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x00, ++ io + IT87_CIR_TCR2); ++ } else { ++ /* TX: 38kHz, 13,3us (pulse-width) */ ++ outb(((it87_freq - IT87_CIR_FREQ_MIN) << 3) | 0x06, ++ io + IT87_CIR_TCR2); ++ } ++ spin_unlock_irqrestore(&hardware_lock, flags); ++ return 0; ++} ++ ++ ++static void drop_hardware(void) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&hardware_lock, flags); ++ disable_irq(irq); ++ /* receiver disable */ ++ it87_RXEN_mask = 0; ++ outb(0x1, io + IT87_CIR_RCR); ++ /* turn off irqs */ ++ outb(0, io + IT87_CIR_IER); ++ /* fifo clear */ ++ outb(IT87_CIR_TCR1_FIFOCLR, io+IT87_CIR_TCR1); ++ /* reset */ ++ outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER); ++ enable_irq(irq); ++ spin_unlock_irqrestore(&hardware_lock, flags); ++} ++ ++ ++static unsigned char it87_read(unsigned char port) ++{ ++ outb(port, IT87_ADRPORT); ++ return inb(IT87_DATAPORT); ++} ++ ++ ++static void it87_write(unsigned char port, unsigned char data) ++{ ++ outb(port, IT87_ADRPORT); ++ outb(data, IT87_DATAPORT); ++} ++ ++ ++/* SECTION: Initialisation */ ++ ++static int init_port(void) ++{ ++ unsigned long hw_flags; ++ int retval = 0; ++ ++ unsigned char init_bytes[4] = IT87_INIT; ++ unsigned char it87_chipid = 0; ++ unsigned char ldn = 0; ++ unsigned int it87_io = 0; ++ unsigned int it87_irq = 0; ++ ++ /* Enter MB PnP Mode */ ++ outb(init_bytes[0], IT87_ADRPORT); ++ outb(init_bytes[1], IT87_ADRPORT); ++ outb(init_bytes[2], IT87_ADRPORT); ++ outb(init_bytes[3], IT87_ADRPORT); ++ ++ /* 8712 or 8705 ? */ ++ it87_chipid = it87_read(IT87_CHIP_ID1); ++ if (it87_chipid != 0x87) { ++ retval = -ENXIO; ++ return retval; ++ } ++ it87_chipid = it87_read(IT87_CHIP_ID2); ++ if ((it87_chipid != 0x05) && ++ (it87_chipid != 0x12) && ++ (it87_chipid != 0x18) && ++ (it87_chipid != 0x20)) { ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": no IT8704/05/12/18/20 found (claimed IT87%02x), " ++ "exiting..\n", it87_chipid); ++ retval = -ENXIO; ++ return retval; ++ } ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": found IT87%02x.\n", ++ it87_chipid); ++ ++ /* get I/O-Port and IRQ */ ++ if (it87_chipid == 0x12 || it87_chipid == 0x18) ++ ldn = IT8712_CIR_LDN; ++ else ++ ldn = IT8705_CIR_LDN; ++ it87_write(IT87_LDN, ldn); ++ ++ it87_io = it87_read(IT87_CIR_BASE_MSB) * 256 + ++ it87_read(IT87_CIR_BASE_LSB); ++ if (it87_io == 0) { ++ if (io == 0) ++ io = IT87_CIR_DEFAULT_IOBASE; ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": set default io 0x%x\n", ++ io); ++ it87_write(IT87_CIR_BASE_MSB, io / 0x100); ++ it87_write(IT87_CIR_BASE_LSB, io % 0x100); ++ } else ++ io = it87_io; ++ ++ it87_irq = it87_read(IT87_CIR_IRQ); ++ if (digimatrix || it87_irq == 0) { ++ if (irq == 0) ++ irq = IT87_CIR_DEFAULT_IRQ; ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": set default irq 0x%x\n", ++ irq); ++ it87_write(IT87_CIR_IRQ, irq); ++ } else ++ irq = it87_irq; ++ ++ spin_lock_irqsave(&hardware_lock, hw_flags); ++ /* reset */ ++ outb(IT87_CIR_IER_RESET, io+IT87_CIR_IER); ++ /* fifo clear */ ++ outb(IT87_CIR_TCR1_FIFOCLR | ++ /* IT87_CIR_TCR1_ILE | */ ++ IT87_CIR_TCR1_TXRLE | ++ IT87_CIR_TCR1_TXENDF, io+IT87_CIR_TCR1); ++ spin_unlock_irqrestore(&hardware_lock, hw_flags); ++ ++ /* get I/O port access and IRQ line */ ++ if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": i/o port 0x%.4x already in use.\n", io); ++ /* Leaving MB PnP Mode */ ++ it87_write(IT87_CFGCTRL, 0x2); ++ return -EBUSY; ++ } ++ ++ /* activate CIR-Device */ ++ it87_write(IT87_CIR_ACT, 0x1); ++ ++ /* Leaving MB PnP Mode */ ++ it87_write(IT87_CFGCTRL, 0x2); ++ ++ retval = request_irq(irq, it87_interrupt, 0 /*IRQF_DISABLED*/, ++ LIRC_DRIVER_NAME, NULL); ++ if (retval < 0) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": IRQ %d already in use.\n", ++ irq); ++ release_region(io, 8); ++ return retval; ++ } ++ ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": I/O port 0x%.4x, IRQ %d.\n", io, irq); ++ ++ init_timer(&timerlist); ++ timerlist.function = it87_timeout; ++ timerlist.data = 0xabadcafe; ++ ++ return 0; ++} ++ ++ ++static void drop_port(void) ++{ ++#if 0 ++ unsigned char init_bytes[4] = IT87_INIT; ++ ++ /* Enter MB PnP Mode */ ++ outb(init_bytes[0], IT87_ADRPORT); ++ outb(init_bytes[1], IT87_ADRPORT); ++ outb(init_bytes[2], IT87_ADRPORT); ++ outb(init_bytes[3], IT87_ADRPORT); ++ ++ /* deactivate CIR-Device */ ++ it87_write(IT87_CIR_ACT, 0x0); ++ ++ /* Leaving MB PnP Mode */ ++ it87_write(IT87_CFGCTRL, 0x2); ++#endif ++ ++ del_timer_sync(&timerlist); ++ free_irq(irq, NULL); ++ release_region(io, 8); ++} ++ ++ ++static int init_lirc_it87(void) ++{ ++ int retval; ++ ++ init_waitqueue_head(&lirc_read_queue); ++ retval = init_port(); ++ if (retval < 0) ++ return retval; ++ init_hardware(); ++ printk(KERN_INFO LIRC_DRIVER_NAME ": Installed.\n"); ++ return 0; ++} ++ ++static int it87_probe(struct pnp_dev *pnp_dev, ++ const struct pnp_device_id *dev_id) ++{ ++ int retval; ++ ++ driver.dev = &pnp_dev->dev; ++ ++ retval = init_chrdev(); ++ if (retval < 0) ++ return retval; ++ ++ retval = init_lirc_it87(); ++ if (retval) ++ goto init_lirc_it87_failed; ++ ++ return 0; ++ ++init_lirc_it87_failed: ++ drop_chrdev(); ++ ++ return retval; ++} ++ ++static int __init lirc_it87_init(void) ++{ ++ return pnp_register_driver(&it87_pnp_driver); ++} ++ ++ ++static void __exit lirc_it87_exit(void) ++{ ++ drop_hardware(); ++ drop_chrdev(); ++ drop_port(); ++ pnp_unregister_driver(&it87_pnp_driver); ++ printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n"); ++} ++ ++/* SECTION: PNP for ITE8704/18 */ ++ ++static const struct pnp_device_id pnp_dev_table[] = { ++ {"ITE8704", 0}, ++ {} ++}; ++ ++MODULE_DEVICE_TABLE(pnp, pnp_dev_table); ++ ++static struct pnp_driver it87_pnp_driver = { ++ .name = LIRC_DRIVER_NAME, ++ .id_table = pnp_dev_table, ++ .probe = it87_probe, ++}; ++ ++module_init(lirc_it87_init); ++module_exit(lirc_it87_exit); ++ ++MODULE_DESCRIPTION("LIRC driver for ITE IT8704/05/12/18/20 CIR port"); ++MODULE_AUTHOR("Hans-Gunter Lutke Uphues"); ++MODULE_LICENSE("GPL"); ++ ++module_param(io, int, S_IRUGO); ++MODULE_PARM_DESC(io, "I/O base address (default: 0x310)"); ++ ++module_param(irq, int, S_IRUGO); ++#ifdef LIRC_IT87_DIGIMATRIX ++MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 9)"); ++#else ++MODULE_PARM_DESC(irq, "Interrupt (1,3-12) (default: 7)"); ++#endif ++ ++module_param(it87_enable_demodulator, bool, S_IRUGO); ++MODULE_PARM_DESC(it87_enable_demodulator, ++ "Receiver demodulator enable/disable (1/0), default: 0"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); ++ ++module_param(digimatrix, bool, S_IRUGO | S_IWUSR); ++#ifdef LIRC_IT87_DIGIMATRIX ++MODULE_PARM_DESC(digimatrix, ++ "Asus Digimatrix it87 compat. enable/disable (1/0), default: 1"); ++#else ++MODULE_PARM_DESC(digimatrix, ++ "Asus Digimatrix it87 compat. enable/disable (1/0), default: 0"); ++#endif ++ ++ ++module_param(it87_freq, int, S_IRUGO); ++#ifdef LIRC_IT87_DIGIMATRIX ++MODULE_PARM_DESC(it87_freq, ++ "Carrier demodulator frequency (kHz), (default: 36)"); ++#else ++MODULE_PARM_DESC(it87_freq, ++ "Carrier demodulator frequency (kHz), (default: 38)"); ++#endif +diff --git a/drivers/input/lirc/lirc_it87.h b/drivers/input/lirc/lirc_it87.h +new file mode 100644 +index 0000000..cf021c8 +--- /dev/null ++++ b/drivers/input/lirc/lirc_it87.h +@@ -0,0 +1,116 @@ ++/* lirc_it87.h */ ++/* SECTION: Definitions */ ++ ++/********************************* ITE IT87xx ************************/ ++ ++/* based on the following documentation from ITE: ++ a) IT8712F Preliminary CIR Programming Guide V0.1 ++ b) IT8705F Simple LPC I/O Preliminary Specification V0.3 ++ c) IT8712F EC-LPC I/O Preliminary Specification V0.5 ++*/ ++ ++/* IT8712/05 Ports: */ ++#define IT87_ADRPORT 0x2e ++#define IT87_DATAPORT 0x2f ++#define IT87_INIT {0x87, 0x01, 0x55, 0x55} ++ ++/* alternate Ports: */ ++/* ++#define IT87_ADRPORT 0x4e ++#define IT87_DATAPORT 0x4f ++#define IT87_INIT {0x87, 0x01, 0x55, 0xaa} ++ */ ++ ++/* IT8712/05 Registers */ ++#define IT87_CFGCTRL 0x2 ++#define IT87_LDN 0x7 ++#define IT87_CHIP_ID1 0x20 ++#define IT87_CHIP_ID2 0x21 ++#define IT87_CFG_VERSION 0x22 ++#define IT87_SWSUSPEND 0x23 ++ ++#define IT8712_CIR_LDN 0xa ++#define IT8705_CIR_LDN 0x7 ++ ++/* CIR Configuration Registers: */ ++#define IT87_CIR_ACT 0x30 ++#define IT87_CIR_BASE_MSB 0x60 ++#define IT87_CIR_BASE_LSB 0x61 ++#define IT87_CIR_IRQ 0x70 ++#define IT87_CIR_CONFIG 0xf0 ++ ++/* List of IT87_CIR registers: offset to BaseAddr */ ++#define IT87_CIR_DR 0 ++#define IT87_CIR_IER 1 ++#define IT87_CIR_RCR 2 ++#define IT87_CIR_TCR1 3 ++#define IT87_CIR_TCR2 4 ++#define IT87_CIR_TSR 5 ++#define IT87_CIR_RSR 6 ++#define IT87_CIR_BDLR 5 ++#define IT87_CIR_BDHR 6 ++#define IT87_CIR_IIR 7 ++ ++/* Bit Definition */ ++/* IER: */ ++#define IT87_CIR_IER_TM_EN 0x80 ++#define IT87_CIR_IER_RESEVED 0x40 ++#define IT87_CIR_IER_RESET 0x20 ++#define IT87_CIR_IER_BR 0x10 ++#define IT87_CIR_IER_IEC 0x8 ++#define IT87_CIR_IER_RFOIE 0x4 ++#define IT87_CIR_IER_RDAIE 0x2 ++#define IT87_CIR_IER_TLDLIE 0x1 ++ ++/* RCR: */ ++#define IT87_CIR_RCR_RDWOS 0x80 ++#define IT87_CIR_RCR_HCFS 0x40 ++#define IT87_CIR_RCR_RXEN 0x20 ++#define IT87_CIR_RCR_RXEND 0x10 ++#define IT87_CIR_RCR_RXACT 0x8 ++#define IT87_CIR_RCR_RXDCR 0x7 ++ ++/* TCR1: */ ++#define IT87_CIR_TCR1_FIFOCLR 0x80 ++#define IT87_CIR_TCR1_ILE 0x40 ++#define IT87_CIR_TCR1_FIFOTL 0x30 ++#define IT87_CIR_TCR1_TXRLE 0x8 ++#define IT87_CIR_TCR1_TXENDF 0x4 ++#define IT87_CIR_TCR1_TXMPM 0x3 ++ ++/* TCR2: */ ++#define IT87_CIR_TCR2_CFQ 0xf8 ++#define IT87_CIR_TCR2_TXMPW 0x7 ++ ++/* TSR: */ ++#define IT87_CIR_TSR_RESERVED 0xc0 ++#define IT87_CIR_TSR_TXFBC 0x3f ++ ++/* RSR: */ ++#define IT87_CIR_RSR_RXFTO 0x80 ++#define IT87_CIR_RSR_RESERVED 0x40 ++#define IT87_CIR_RSR_RXFBC 0x3f ++ ++/* IIR: */ ++#define IT87_CIR_IIR_RESERVED 0xf8 ++#define IT87_CIR_IIR_IID 0x6 ++#define IT87_CIR_IIR_IIP 0x1 ++ ++/* TM: */ ++#define IT87_CIR_TM_IL_SEL 0x80 ++#define IT87_CIR_TM_RESERVED 0x40 ++#define IT87_CIR_TM_TM_REG 0x3f ++ ++#define IT87_CIR_FIFO_SIZE 32 ++ ++/* Baudratedivisor for IT87: power of 2: only 1,2,4 or 8) */ ++#define IT87_CIR_BAUDRATE_DIVISOR 0x1 ++#define IT87_CIR_DEFAULT_IOBASE 0x310 ++#define IT87_CIR_DEFAULT_IRQ 0x7 ++#define IT87_CIR_SPACE 0x00 ++#define IT87_CIR_PULSE 0xff ++#define IT87_CIR_FREQ_MIN 27 ++#define IT87_CIR_FREQ_MAX 58 ++#define TIME_CONST (IT87_CIR_BAUDRATE_DIVISOR * 8000000ul / 115200ul) ++ ++/********************************* ITE IT87xx ************************/ +diff --git a/drivers/input/lirc/lirc_ite8709.c b/drivers/input/lirc/lirc_ite8709.c +new file mode 100644 +index 0000000..4c3d3ad +--- /dev/null ++++ b/drivers/input/lirc/lirc_ite8709.c +@@ -0,0 +1,540 @@ ++/* ++ * LIRC driver for ITE8709 CIR port ++ * ++ * Copyright (C) 2008 Grégory Lardière ++ * ++ * This program is free software; you can redistribute it and/or ++ * modify it under the terms of the GNU General Public License as ++ * published by the Free Software Foundation; either version 2 of the ++ * License, or (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, but ++ * WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU ++ * General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 ++ * USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++#define LIRC_DRIVER_NAME "lirc_ite8709" ++ ++#define BUF_CHUNK_SIZE sizeof(int) ++#define BUF_SIZE (128*BUF_CHUNK_SIZE) ++ ++/* ++ * The ITE8709 device seems to be the combination of IT8512 superIO chip and ++ * a specific firmware running on the IT8512's embedded micro-controller. ++ * In addition of the embedded micro-controller, the IT8512 chip contains a ++ * CIR module and several other modules. A few modules are directly accessible ++ * by the host CPU, but most of them are only accessible by the ++ * micro-controller. The CIR module is only accessible by the micro-controller. ++ * The battery-backed SRAM module is accessible by the host CPU and the ++ * micro-controller. So one of the MC's firmware role is to act as a bridge ++ * between the host CPU and the CIR module. The firmware implements a kind of ++ * communication protocol using the SRAM module as a shared memory. The IT8512 ++ * specification is publicly available on ITE's web site, but the communication ++ * protocol is not, so it was reverse-engineered. ++ */ ++ ++/* ITE8709 Registers addresses and values (reverse-engineered) */ ++#define ITE8709_MODE 0x1a ++#define ITE8709_REG_ADR 0x1b ++#define ITE8709_REG_VAL 0x1c ++#define ITE8709_IIR 0x1e /* Interrupt identification register */ ++#define ITE8709_RFSR 0x1f /* Receiver FIFO status register */ ++#define ITE8709_FIFO_START 0x20 ++ ++#define ITE8709_MODE_READY 0X00 ++#define ITE8709_MODE_WRITE 0X01 ++#define ITE8709_MODE_READ 0X02 ++#define ITE8709_IIR_RDAI 0x02 /* Receiver data available interrupt */ ++#define ITE8709_IIR_RFOI 0x04 /* Receiver FIFO overrun interrupt */ ++#define ITE8709_RFSR_MASK 0x3f /* FIFO byte count mask */ ++ ++/* ++ * IT8512 CIR-module registers addresses and values ++ * (from IT8512 E/F specification v0.4.1) ++ */ ++#define IT8512_REG_MSTCR 0x01 /* Master control register */ ++#define IT8512_REG_IER 0x02 /* Interrupt enable register */ ++#define IT8512_REG_CFR 0x04 /* Carrier frequency register */ ++#define IT8512_REG_RCR 0x05 /* Receive control register */ ++#define IT8512_REG_BDLR 0x08 /* Baud rate divisor low byte register */ ++#define IT8512_REG_BDHR 0x09 /* Baud rate divisor high byte register */ ++ ++#define IT8512_MSTCR_RESET 0x01 /* Reset registers to default value */ ++#define IT8512_MSTCR_FIFOCLR 0x02 /* Clear FIFO */ ++#define IT8512_MSTCR_FIFOTL_7 0x04 /* FIFO threshold level : 7 */ ++#define IT8512_MSTCR_FIFOTL_25 0x0c /* FIFO threshold level : 25 */ ++#define IT8512_IER_RDAIE 0x02 /* Enable data interrupt request */ ++#define IT8512_IER_RFOIE 0x04 /* Enable FIFO overrun interrupt req */ ++#define IT8512_IER_IEC 0x80 /* Enable interrupt request */ ++#define IT8512_CFR_CF_36KHZ 0x09 /* Carrier freq : low speed, 36kHz */ ++#define IT8512_RCR_RXDCR_1 0x01 /* Demodulation carrier range : 1 */ ++#define IT8512_RCR_RXACT 0x08 /* Receiver active */ ++#define IT8512_RCR_RXEN 0x80 /* Receiver enable */ ++#define IT8512_BDR_6 6 /* Baud rate divisor : 6 */ ++ ++/* Actual values used by this driver */ ++#define CFG_FIFOTL IT8512_MSTCR_FIFOTL_25 ++#define CFG_CR_FREQ IT8512_CFR_CF_36KHZ ++#define CFG_DCR IT8512_RCR_RXDCR_1 ++#define CFG_BDR IT8512_BDR_6 ++#define CFG_TIMEOUT 100000 /* Rearm interrupt when a space is > 100 ms */ ++ ++static int debug; ++ ++struct ite8709_device { ++ int use_count; ++ int io; ++ int irq; ++ spinlock_t hardware_lock; ++ unsigned long long acc_pulse; ++ unsigned long long acc_space; ++ char lastbit; ++ struct timeval last_tv; ++ struct lirc_driver driver; ++ struct tasklet_struct tasklet; ++ char force_rearm; ++ char rearmed; ++ char device_busy; ++}; ++ ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \ ++ fmt, ## args); \ ++ } while (0) ++ ++ ++static unsigned char ite8709_read(struct ite8709_device *dev, ++ unsigned char port) ++{ ++ outb(port, dev->io); ++ return inb(dev->io+1); ++} ++ ++static void ite8709_write(struct ite8709_device *dev, unsigned char port, ++ unsigned char data) ++{ ++ outb(port, dev->io); ++ outb(data, dev->io+1); ++} ++ ++static void ite8709_wait_device(struct ite8709_device *dev) ++{ ++ int i = 0; ++ /* ++ * loop until device tells it's ready to continue ++ * iterations count is usually ~750 but can sometimes achieve 13000 ++ */ ++ for (i = 0; i < 15000; i++) { ++ udelay(2); ++ if (ite8709_read(dev, ITE8709_MODE) == ITE8709_MODE_READY) ++ break; ++ } ++} ++ ++static void ite8709_write_register(struct ite8709_device *dev, ++ unsigned char reg_adr, unsigned char reg_value) ++{ ++ ite8709_wait_device(dev); ++ ++ ite8709_write(dev, ITE8709_REG_VAL, reg_value); ++ ite8709_write(dev, ITE8709_REG_ADR, reg_adr); ++ ite8709_write(dev, ITE8709_MODE, ITE8709_MODE_WRITE); ++} ++ ++static void ite8709_init_hardware(struct ite8709_device *dev) ++{ ++ spin_lock_irq(&dev->hardware_lock); ++ dev->device_busy = 1; ++ spin_unlock_irq(&dev->hardware_lock); ++ ++ ite8709_write_register(dev, IT8512_REG_BDHR, (CFG_BDR >> 8) & 0xff); ++ ite8709_write_register(dev, IT8512_REG_BDLR, CFG_BDR & 0xff); ++ ite8709_write_register(dev, IT8512_REG_CFR, CFG_CR_FREQ); ++ ite8709_write_register(dev, IT8512_REG_IER, ++ IT8512_IER_IEC | IT8512_IER_RFOIE | IT8512_IER_RDAIE); ++ ite8709_write_register(dev, IT8512_REG_RCR, CFG_DCR); ++ ite8709_write_register(dev, IT8512_REG_MSTCR, ++ CFG_FIFOTL | IT8512_MSTCR_FIFOCLR); ++ ite8709_write_register(dev, IT8512_REG_RCR, ++ IT8512_RCR_RXEN | IT8512_RCR_RXACT | CFG_DCR); ++ ++ spin_lock_irq(&dev->hardware_lock); ++ dev->device_busy = 0; ++ spin_unlock_irq(&dev->hardware_lock); ++ ++ tasklet_enable(&dev->tasklet); ++} ++ ++static void ite8709_drop_hardware(struct ite8709_device *dev) ++{ ++ tasklet_disable(&dev->tasklet); ++ ++ spin_lock_irq(&dev->hardware_lock); ++ dev->device_busy = 1; ++ spin_unlock_irq(&dev->hardware_lock); ++ ++ ite8709_write_register(dev, IT8512_REG_RCR, 0); ++ ite8709_write_register(dev, IT8512_REG_MSTCR, ++ IT8512_MSTCR_RESET | IT8512_MSTCR_FIFOCLR); ++ ++ spin_lock_irq(&dev->hardware_lock); ++ dev->device_busy = 0; ++ spin_unlock_irq(&dev->hardware_lock); ++} ++ ++static int ite8709_set_use_inc(void *data) ++{ ++ struct ite8709_device *dev; ++ dev = data; ++ if (dev->use_count == 0) ++ ite8709_init_hardware(dev); ++ dev->use_count++; ++ return 0; ++} ++ ++static void ite8709_set_use_dec(void *data) ++{ ++ struct ite8709_device *dev; ++ dev = data; ++ dev->use_count--; ++ if (dev->use_count == 0) ++ ite8709_drop_hardware(dev); ++} ++ ++static void ite8709_add_read_queue(struct ite8709_device *dev, int flag, ++ unsigned long long val) ++{ ++ int value; ++ ++ dprintk("add a %llu usec %s\n", val, flag ? "pulse" : "space"); ++ ++ value = (val > PULSE_MASK) ? PULSE_MASK : val; ++ if (flag) ++ value |= PULSE_BIT; ++ ++ if (!lirc_buffer_full(dev->driver.rbuf)) { ++ lirc_buffer_write(dev->driver.rbuf, (void *) &value); ++ wake_up(&dev->driver.rbuf->wait_poll); ++ } ++} ++ ++static irqreturn_t ite8709_interrupt(int irq, void *dev_id) ++{ ++ unsigned char data; ++ int iir, rfsr, i; ++ int fifo = 0; ++ char bit; ++ struct timeval curr_tv; ++ ++ /* Bit duration in microseconds */ ++ const unsigned long bit_duration = 1000000ul / (115200 / CFG_BDR); ++ ++ struct ite8709_device *dev; ++ dev = dev_id; ++ ++ /* ++ * If device is busy, we simply discard data because we are in one of ++ * these two cases : shutting down or rearming the device, so this ++ * doesn't really matter and this avoids waiting too long in IRQ ctx ++ */ ++ spin_lock(&dev->hardware_lock); ++ if (dev->device_busy) { ++ spin_unlock(&dev->hardware_lock); ++ return IRQ_RETVAL(IRQ_HANDLED); ++ } ++ ++ iir = ite8709_read(dev, ITE8709_IIR); ++ ++ switch (iir) { ++ case ITE8709_IIR_RFOI: ++ dprintk("fifo overrun, scheduling forced rearm just in case\n"); ++ dev->force_rearm = 1; ++ tasklet_schedule(&dev->tasklet); ++ spin_unlock(&dev->hardware_lock); ++ return IRQ_RETVAL(IRQ_HANDLED); ++ ++ case ITE8709_IIR_RDAI: ++ rfsr = ite8709_read(dev, ITE8709_RFSR); ++ fifo = rfsr & ITE8709_RFSR_MASK; ++ if (fifo > 32) ++ fifo = 32; ++ dprintk("iir: 0x%x rfsr: 0x%x fifo: %d\n", iir, rfsr, fifo); ++ ++ if (dev->rearmed) { ++ do_gettimeofday(&curr_tv); ++ dev->acc_space += 1000000ull ++ * (curr_tv.tv_sec - dev->last_tv.tv_sec) ++ + (curr_tv.tv_usec - dev->last_tv.tv_usec); ++ dev->rearmed = 0; ++ } ++ for (i = 0; i < fifo; i++) { ++ data = ite8709_read(dev, i+ITE8709_FIFO_START); ++ data = ~data; ++ /* Loop through */ ++ for (bit = 0; bit < 8; ++bit) { ++ if ((data >> bit) & 1) { ++ dev->acc_pulse += bit_duration; ++ if (dev->lastbit == 0) { ++ ite8709_add_read_queue(dev, 0, ++ dev->acc_space); ++ dev->acc_space = 0; ++ } ++ } else { ++ dev->acc_space += bit_duration; ++ if (dev->lastbit == 1) { ++ ite8709_add_read_queue(dev, 1, ++ dev->acc_pulse); ++ dev->acc_pulse = 0; ++ } ++ } ++ dev->lastbit = (data >> bit) & 1; ++ } ++ } ++ ite8709_write(dev, ITE8709_RFSR, 0); ++ ++ if (dev->acc_space > CFG_TIMEOUT) { ++ dprintk("scheduling rearm IRQ\n"); ++ do_gettimeofday(&dev->last_tv); ++ dev->force_rearm = 0; ++ tasklet_schedule(&dev->tasklet); ++ } ++ ++ spin_unlock(&dev->hardware_lock); ++ return IRQ_RETVAL(IRQ_HANDLED); ++ ++ default: ++ /* not our irq */ ++ dprintk("unknown IRQ (shouldn't happen) !!\n"); ++ spin_unlock(&dev->hardware_lock); ++ return IRQ_RETVAL(IRQ_NONE); ++ } ++} ++ ++static void ite8709_rearm_irq(unsigned long data) ++{ ++ struct ite8709_device *dev; ++ unsigned long flags; ++ dev = (struct ite8709_device *) data; ++ ++ spin_lock_irqsave(&dev->hardware_lock, flags); ++ dev->device_busy = 1; ++ spin_unlock_irqrestore(&dev->hardware_lock, flags); ++ ++ if (dev->force_rearm || dev->acc_space > CFG_TIMEOUT) { ++ dprintk("rearming IRQ\n"); ++ ite8709_write_register(dev, IT8512_REG_RCR, ++ IT8512_RCR_RXACT | CFG_DCR); ++ ite8709_write_register(dev, IT8512_REG_MSTCR, ++ CFG_FIFOTL | IT8512_MSTCR_FIFOCLR); ++ ite8709_write_register(dev, IT8512_REG_RCR, ++ IT8512_RCR_RXEN | IT8512_RCR_RXACT | CFG_DCR); ++ if (!dev->force_rearm) ++ dev->rearmed = 1; ++ dev->force_rearm = 0; ++ } ++ ++ spin_lock_irqsave(&dev->hardware_lock, flags); ++ dev->device_busy = 0; ++ spin_unlock_irqrestore(&dev->hardware_lock, flags); ++} ++ ++static int ite8709_cleanup(struct ite8709_device *dev, int stage, int errno, ++ char *msg) ++{ ++ if (msg != NULL) ++ printk(KERN_ERR LIRC_DRIVER_NAME ": %s\n", msg); ++ ++ switch (stage) { ++ case 6: ++ if (dev->use_count > 0) ++ ite8709_drop_hardware(dev); ++ case 5: ++ free_irq(dev->irq, dev); ++ case 4: ++ release_region(dev->io, 2); ++ case 3: ++ lirc_unregister_driver(dev->driver.minor); ++ case 2: ++ lirc_buffer_free(dev->driver.rbuf); ++ kfree(dev->driver.rbuf); ++ case 1: ++ kfree(dev); ++ case 0: ++ ; ++ } ++ ++ return errno; ++} ++ ++static int __devinit ite8709_pnp_probe(struct pnp_dev *dev, ++ const struct pnp_device_id *dev_id) ++{ ++ struct lirc_driver *driver; ++ struct ite8709_device *ite8709_dev; ++ int ret; ++ ++ /* Check resources validity */ ++ if (!pnp_irq_valid(dev, 0)) ++ return ite8709_cleanup(NULL, 0, -ENODEV, "invalid IRQ"); ++ if (!pnp_port_valid(dev, 2)) ++ return ite8709_cleanup(NULL, 0, -ENODEV, "invalid IO port"); ++ ++ /* Allocate memory for device struct */ ++ ite8709_dev = kzalloc(sizeof(struct ite8709_device), GFP_KERNEL); ++ if (ite8709_dev == NULL) ++ return ite8709_cleanup(NULL, 0, -ENOMEM, "kzalloc failed"); ++ pnp_set_drvdata(dev, ite8709_dev); ++ ++ /* Initialize device struct */ ++ ite8709_dev->use_count = 0; ++ ite8709_dev->irq = pnp_irq(dev, 0); ++ ite8709_dev->io = pnp_port_start(dev, 2); ++ ite8709_dev->hardware_lock = ++ __SPIN_LOCK_UNLOCKED(ite8709_dev->hardware_lock); ++ ite8709_dev->acc_pulse = 0; ++ ite8709_dev->acc_space = 0; ++ ite8709_dev->lastbit = 0; ++ do_gettimeofday(&ite8709_dev->last_tv); ++ tasklet_init(&ite8709_dev->tasklet, ite8709_rearm_irq, ++ (long) ite8709_dev); ++ ite8709_dev->force_rearm = 0; ++ ite8709_dev->rearmed = 0; ++ ite8709_dev->device_busy = 0; ++ ++ /* Initialize driver struct */ ++ driver = &ite8709_dev->driver; ++ strcpy(driver->name, LIRC_DRIVER_NAME); ++ driver->minor = -1; ++ driver->code_length = sizeof(int) * 8; ++ driver->sample_rate = 0; ++ driver->features = LIRC_CAN_REC_MODE2; ++ driver->data = ite8709_dev; ++ driver->add_to_buf = NULL; ++ driver->set_use_inc = ite8709_set_use_inc; ++ driver->set_use_dec = ite8709_set_use_dec; ++ driver->dev = &dev->dev; ++ driver->owner = THIS_MODULE; ++ ++ /* Initialize LIRC buffer */ ++ driver->rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!driver->rbuf) ++ return ite8709_cleanup(ite8709_dev, 1, -ENOMEM, ++ "can't allocate lirc_buffer"); ++ if (lirc_buffer_init(driver->rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) ++ return ite8709_cleanup(ite8709_dev, 1, -ENOMEM, ++ "lirc_buffer_init() failed"); ++ ++ /* Register LIRC driver */ ++ ret = lirc_register_driver(driver); ++ if (ret < 0) ++ return ite8709_cleanup(ite8709_dev, 2, ret, ++ "lirc_register_driver() failed"); ++ ++ /* Reserve I/O port access */ ++ if (!request_region(ite8709_dev->io, 2, LIRC_DRIVER_NAME)) ++ return ite8709_cleanup(ite8709_dev, 3, -EBUSY, ++ "i/o port already in use"); ++ ++ /* Reserve IRQ line */ ++ ret = request_irq(ite8709_dev->irq, ite8709_interrupt, 0, ++ LIRC_DRIVER_NAME, ite8709_dev); ++ if (ret < 0) ++ return ite8709_cleanup(ite8709_dev, 4, ret, ++ "IRQ already in use"); ++ ++ /* Initialize hardware */ ++ ite8709_drop_hardware(ite8709_dev); /* Shutdown hw until first use */ ++ ++ printk(KERN_INFO LIRC_DRIVER_NAME ": device found : irq=%d io=0x%x\n", ++ ite8709_dev->irq, ite8709_dev->io); ++ ++ return 0; ++} ++ ++static void __devexit ite8709_pnp_remove(struct pnp_dev *dev) ++{ ++ struct ite8709_device *ite8709_dev; ++ ite8709_dev = pnp_get_drvdata(dev); ++ ++ ite8709_cleanup(ite8709_dev, 6, 0, NULL); ++ ++ printk(KERN_INFO LIRC_DRIVER_NAME ": device removed\n"); ++} ++ ++#ifdef CONFIG_PM ++static int ite8709_pnp_suspend(struct pnp_dev *dev, pm_message_t state) ++{ ++ struct ite8709_device *ite8709_dev; ++ ite8709_dev = pnp_get_drvdata(dev); ++ ++ if (ite8709_dev->use_count > 0) ++ ite8709_drop_hardware(ite8709_dev); ++ ++ return 0; ++} ++ ++static int ite8709_pnp_resume(struct pnp_dev *dev) ++{ ++ struct ite8709_device *ite8709_dev; ++ ite8709_dev = pnp_get_drvdata(dev); ++ ++ if (ite8709_dev->use_count > 0) ++ ite8709_init_hardware(ite8709_dev); ++ ++ return 0; ++} ++#else ++#define ite8709_pnp_suspend NULL ++#define ite8709_pnp_resume NULL ++#endif ++ ++static const struct pnp_device_id pnp_dev_table[] = { ++ {"ITE8709", 0}, ++ {} ++}; ++ ++MODULE_DEVICE_TABLE(pnp, pnp_dev_table); ++ ++static struct pnp_driver ite8709_pnp_driver = { ++ .name = LIRC_DRIVER_NAME, ++ .probe = ite8709_pnp_probe, ++ .remove = __devexit_p(ite8709_pnp_remove), ++ .suspend = ite8709_pnp_suspend, ++ .resume = ite8709_pnp_resume, ++ .id_table = pnp_dev_table, ++}; ++ ++int init_module(void) ++{ ++ return pnp_register_driver(&ite8709_pnp_driver); ++} ++ ++void cleanup_module(void) ++{ ++ pnp_unregister_driver(&ite8709_pnp_driver); ++} ++ ++MODULE_DESCRIPTION("LIRC driver for ITE8709 CIR port"); ++MODULE_AUTHOR("Grégory Lardière"); ++MODULE_LICENSE("GPL"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); +diff --git a/drivers/input/lirc/lirc_mceusb.c b/drivers/input/lirc/lirc_mceusb.c +new file mode 100644 +index 0000000..c0869d8 +--- /dev/null ++++ b/drivers/input/lirc/lirc_mceusb.c +@@ -0,0 +1,1385 @@ ++/* ++ * LIRC driver for Windows Media Center Edition USB Infrared Transceivers ++ * ++ * (C) by Martin A. Blatter ++ * ++ * Transmitter support and reception code cleanup. ++ * (C) by Daniel Melander ++ * ++ * Original lirc_mceusb driver for 1st-gen device: ++ * Copyright (c) 2003-2004 Dan Conti ++ * ++ * Original lirc_mceusb driver deprecated in favor of this driver, which ++ * supports the 1st-gen device now too. Transmit and receive support for ++ * the 1st-gen device added June-September 2009, ++ * by Jarod Wilson and Patrick Calhoun ++ * ++ * Derived from ATI USB driver by Paul Miller and the original ++ * MCE USB driver by Dan Conti (and now including chunks of the latter ++ * relevant to the 1st-gen device initialization) ++ * ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++#define DRIVER_VERSION "1.90" ++#define DRIVER_AUTHOR "Daniel Melander , " \ ++ "Martin Blatter , " \ ++ "Dan Conti " ++#define DRIVER_DESC "Windows Media Center Edition USB IR Transceiver " \ ++ "driver for LIRC" ++#define DRIVER_NAME "lirc_mceusb" ++ ++#define USB_BUFLEN 32 /* USB reception buffer length */ ++#define LIRCBUF_SIZE 256 /* LIRC work buffer length */ ++ ++/* MCE constants */ ++#define MCE_CMDBUF_SIZE 384 /* MCE Command buffer length */ ++#define MCE_TIME_UNIT 50 /* Approx 50us resolution */ ++#define MCE_CODE_LENGTH 5 /* Normal length of packet (with header) */ ++#define MCE_PACKET_SIZE 4 /* Normal length of packet (without header) */ ++#define MCE_PACKET_HEADER 0x84 /* Actual header format is 0x80 + num_bytes */ ++#define MCE_CONTROL_HEADER 0x9F /* MCE status header */ ++#define MCE_TX_HEADER_LENGTH 3 /* # of bytes in the initializing tx header */ ++#define MCE_MAX_CHANNELS 2 /* Two transmitters, hardware dependent? */ ++#define MCE_DEFAULT_TX_MASK 0x03 /* Val opts: TX1=0x01, TX2=0x02, ALL=0x03 */ ++#define MCE_PULSE_BIT 0x80 /* Pulse bit, MSB set == PULSE else SPACE */ ++#define MCE_PULSE_MASK 0x7F /* Pulse mask */ ++#define MCE_MAX_PULSE_LENGTH 0x7F /* Longest transmittable pulse symbol */ ++#define MCE_PACKET_LENGTH_MASK 0x7F /* Pulse mask */ ++ ++ ++/* module parameters */ ++#ifdef CONFIG_USB_DEBUG ++static int debug = 1; ++#else ++static int debug; ++#endif ++ ++/* general constants */ ++#define SEND_FLAG_IN_PROGRESS 1 ++#define SEND_FLAG_COMPLETE 2 ++#define RECV_FLAG_IN_PROGRESS 3 ++#define RECV_FLAG_COMPLETE 4 ++ ++#define MCEUSB_INBOUND 1 ++#define MCEUSB_OUTBOUND 2 ++ ++#define VENDOR_PHILIPS 0x0471 ++#define VENDOR_SMK 0x0609 ++#define VENDOR_TATUNG 0x1460 ++#define VENDOR_GATEWAY 0x107b ++#define VENDOR_SHUTTLE 0x1308 ++#define VENDOR_SHUTTLE2 0x051c ++#define VENDOR_MITSUMI 0x03ee ++#define VENDOR_TOPSEED 0x1784 ++#define VENDOR_RICAVISION 0x179d ++#define VENDOR_ITRON 0x195d ++#define VENDOR_FIC 0x1509 ++#define VENDOR_LG 0x043e ++#define VENDOR_MICROSOFT 0x045e ++#define VENDOR_FORMOSA 0x147a ++#define VENDOR_FINTEK 0x1934 ++#define VENDOR_PINNACLE 0x2304 ++#define VENDOR_ECS 0x1019 ++#define VENDOR_WISTRON 0x0fb8 ++#define VENDOR_COMPRO 0x185b ++#define VENDOR_NORTHSTAR 0x04eb ++#define VENDOR_REALTEK 0x0bda ++#define VENDOR_TIVO 0x105a ++ ++static struct usb_device_id mceusb_dev_table[] = { ++ /* Original Microsoft MCE IR Transceiver (often HP-branded) */ ++ { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) }, ++ /* Philips Infrared Transceiver - Sahara branded */ ++ { USB_DEVICE(VENDOR_PHILIPS, 0x0608) }, ++ /* Philips Infrared Transceiver - HP branded */ ++ { USB_DEVICE(VENDOR_PHILIPS, 0x060c) }, ++ /* Philips SRM5100 */ ++ { USB_DEVICE(VENDOR_PHILIPS, 0x060d) }, ++ /* Philips Infrared Transceiver - Omaura */ ++ { USB_DEVICE(VENDOR_PHILIPS, 0x060f) }, ++ /* Philips Infrared Transceiver - Spinel plus */ ++ { USB_DEVICE(VENDOR_PHILIPS, 0x0613) }, ++ /* Philips eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_PHILIPS, 0x0815) }, ++ /* Realtek MCE IR Receiver */ ++ { USB_DEVICE(VENDOR_REALTEK, 0x0161) }, ++ /* SMK/Toshiba G83C0004D410 */ ++ { USB_DEVICE(VENDOR_SMK, 0x031d) }, ++ /* SMK eHome Infrared Transceiver (Sony VAIO) */ ++ { USB_DEVICE(VENDOR_SMK, 0x0322) }, ++ /* bundled with Hauppauge PVR-150 */ ++ { USB_DEVICE(VENDOR_SMK, 0x0334) }, ++ /* SMK eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_SMK, 0x0338) }, ++ /* Tatung eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TATUNG, 0x9150) }, ++ /* Shuttle eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_SHUTTLE, 0xc001) }, ++ /* Shuttle eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_SHUTTLE2, 0xc001) }, ++ /* Gateway eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_GATEWAY, 0x3009) }, ++ /* Mitsumi */ ++ { USB_DEVICE(VENDOR_MITSUMI, 0x2501) }, ++ /* Topseed eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0001) }, ++ /* Topseed HP eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0006) }, ++ /* Topseed eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0007) }, ++ /* Topseed eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0008) }, ++ /* Topseed eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TOPSEED, 0x000a) }, ++ /* Topseed eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0011) }, ++ /* Ricavision internal Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_RICAVISION, 0x0010) }, ++ /* Itron ione Libra Q-11 */ ++ { USB_DEVICE(VENDOR_ITRON, 0x7002) }, ++ /* FIC eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_FIC, 0x9242) }, ++ /* LG eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_LG, 0x9803) }, ++ /* Microsoft MCE Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_MICROSOFT, 0x00a0) }, ++ /* Formosa eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_FORMOSA, 0xe015) }, ++ /* Formosa21 / eHome Infrared Receiver */ ++ { USB_DEVICE(VENDOR_FORMOSA, 0xe016) }, ++ /* Formosa aim / Trust MCE Infrared Receiver */ ++ { USB_DEVICE(VENDOR_FORMOSA, 0xe017) }, ++ /* Formosa Industrial Computing / Beanbag Emulation Device */ ++ { USB_DEVICE(VENDOR_FORMOSA, 0xe018) }, ++ /* Formosa21 / eHome Infrared Receiver */ ++ { USB_DEVICE(VENDOR_FORMOSA, 0xe03a) }, ++ /* Formosa Industrial Computing AIM IR605/A */ ++ { USB_DEVICE(VENDOR_FORMOSA, 0xe03c) }, ++ /* Fintek eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_FINTEK, 0x0602) }, ++ /* Fintek eHome Infrared Transceiver (in the AOpen MP45) */ ++ { USB_DEVICE(VENDOR_FINTEK, 0x0702) }, ++ /* Pinnacle Remote Kit */ ++ { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, ++ /* Elitegroup Computer Systems IR */ ++ { USB_DEVICE(VENDOR_ECS, 0x0f38) }, ++ /* Wistron Corp. eHome Infrared Receiver */ ++ { USB_DEVICE(VENDOR_WISTRON, 0x0002) }, ++ /* Compro K100 */ ++ { USB_DEVICE(VENDOR_COMPRO, 0x3020) }, ++ /* Compro K100 v2 */ ++ { USB_DEVICE(VENDOR_COMPRO, 0x3082) }, ++ /* Northstar Systems, Inc. eHome Infrared Transceiver */ ++ { USB_DEVICE(VENDOR_NORTHSTAR, 0xe004) }, ++ /* TiVo PC IR Receiver */ ++ { USB_DEVICE(VENDOR_TIVO, 0x2000) }, ++ /* Terminating entry */ ++ { } ++}; ++ ++static struct usb_device_id gen3_list[] = { ++ { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0008) }, ++ {} ++}; ++ ++static struct usb_device_id pinnacle_list[] = { ++ { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, ++ {} ++}; ++ ++static struct usb_device_id microsoft_gen1_list[] = { ++ { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) }, ++ {} ++}; ++ ++static struct usb_device_id transmitter_mask_list[] = { ++ { USB_DEVICE(VENDOR_MICROSOFT, 0x006d) }, ++ { USB_DEVICE(VENDOR_PHILIPS, 0x060c) }, ++ { USB_DEVICE(VENDOR_SMK, 0x031d) }, ++ { USB_DEVICE(VENDOR_SMK, 0x0322) }, ++ { USB_DEVICE(VENDOR_SMK, 0x0334) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0001) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0006) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0007) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0008) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x000a) }, ++ { USB_DEVICE(VENDOR_TOPSEED, 0x0011) }, ++ { USB_DEVICE(VENDOR_PINNACLE, 0x0225) }, ++ {} ++}; ++ ++/* data structure for each usb transceiver */ ++struct mceusb_dev { ++ ++ /* usb */ ++ struct usb_device *usbdev; ++ struct urb *urb_in; ++ int devnum; ++ struct usb_endpoint_descriptor *usb_ep_in; ++ struct usb_endpoint_descriptor *usb_ep_out; ++ ++ /* buffers and dma */ ++ unsigned char *buf_in; ++ unsigned int len_in; ++ dma_addr_t dma_in; ++ dma_addr_t dma_out; ++ unsigned int overflow_len; ++ ++ /* lirc */ ++ struct lirc_driver *d; ++ int lircdata; ++ unsigned char is_pulse; ++ struct { ++ u32 connected:1; ++ u32 gen3:1; ++ u32 transmitter_mask_inverted:1; ++ u32 microsoft_gen1:1; ++ u32 reserved:28; ++ } flags; ++ ++ unsigned char transmitter_mask; ++ unsigned int carrier_freq; ++ ++ /* handle sending (init strings) */ ++ int send_flags; ++ wait_queue_head_t wait_out; ++ ++ struct mutex dev_lock; ++}; ++ ++/* ++ * MCE Device Command Strings ++ * Device command responses vary from device to device... ++ * - DEVICE_RESET resets the hardware to its default state ++ * - GET_REVISION fetches the hardware/software revision, common ++ * replies are ff 0b 45 ff 1b 08 and ff 0b 50 ff 1b 42 ++ * - GET_CARRIER_FREQ gets the carrier mode and frequency of the ++ * device, with replies in the form of 9f 06 MM FF, where MM is 0-3, ++ * meaning clk of 10000000, 2500000, 625000 or 156250, and FF is ++ * ((clk / frequency) - 1) ++ * - GET_RX_TIMEOUT fetches the receiver timeout in units of 50us, ++ * response in the form of 9f 0c msb lsb ++ * - GET_TX_BITMASK fetches the transmitter bitmask, replies in ++ * the form of 9f 08 bm, where bm is the bitmask ++ * - GET_RX_SENSOR fetches the RX sensor setting -- long-range ++ * general use one or short-range learning one, in the form of ++ * 9f 14 ss, where ss is either 01 for long-range or 02 for short ++ * - SET_CARRIER_FREQ sets a new carrier mode and frequency ++ * - SET_TX_BITMASK sets the transmitter bitmask ++ * - SET_RX_TIMEOUT sets the receiver timeout ++ * - SET_RX_SENSOR sets which receiver sensor to use ++ */ ++static char DEVICE_RESET[] = {0x00, 0xff, 0xaa}; ++static char GET_REVISION[] = {0xff, 0x0b}; ++static char GET_UNKNOWN[] = {0xff, 0x18}; ++static char GET_CARRIER_FREQ[] = {0x9f, 0x07}; ++static char GET_RX_TIMEOUT[] = {0x9f, 0x0d}; ++static char GET_TX_BITMASK[] = {0x9f, 0x13}; ++static char GET_RX_SENSOR[] = {0x9f, 0x15}; ++/* sub in desired values in lower byte or bytes for full command */ ++//static char SET_CARRIER_FREQ[] = {0x9f, 0x06, 0x00, 0x00}; ++//static char SET_TX_BITMASK[] = {0x9f, 0x08, 0x00}; ++//static char SET_RX_TIMEOUT[] = {0x9f, 0x0c, 0x00, 0x00}; ++//static char SET_RX_SENSOR[] = {0x9f, 0x14, 0x00}; ++ ++static void mceusb_dev_printdata(struct mceusb_dev *ir, char *buf, ++ int len, bool out) ++{ ++ char codes[USB_BUFLEN * 3 + 1]; ++ char inout[9]; ++ int i; ++ u8 cmd, subcmd, data1, data2; ++ struct device *dev = ir->d->dev; ++ ++ if (len <= 0) ++ return; ++ ++ if (ir->flags.microsoft_gen1 && len <= 2) ++ return; ++ ++ for (i = 0; i < len && i < USB_BUFLEN; i++) ++ snprintf(codes + i * 3, 4, "%02x ", buf[i] & 0xFF); ++ ++ dev_info(dev, "%sbound data: %s (length=%d)\n", ++ (out ? "out" : " in"), codes, len); ++ ++ if (out) ++ strcpy(inout, "Request\0"); ++ else ++ strcpy(inout, "Got\0"); ++ ++ cmd = buf[0] & 0xff; ++ subcmd = buf[1] & 0xff; ++ data1 = buf[2] & 0xff; ++ data2 = buf[3] & 0xff; ++ ++ switch (cmd) { ++ case 0x00: ++ if (subcmd == 0xff && data1 == 0xaa) ++ dev_info(dev, "Device reset requested\n"); ++ else ++ dev_info(dev, "Unknown command 0x%02x 0x%02x\n", ++ cmd, subcmd); ++ break; ++ case 0xff: ++ switch (subcmd) { ++ case 0x0b: ++ if (len == 2) ++ dev_info(dev, "Get hw/sw rev?\n"); ++ else ++ dev_info(dev, "hw/sw rev 0x%02x 0x%02x " ++ "0x%02x 0x%02x\n", data1, data2, ++ buf[4], buf[5]); ++ break; ++ case 0xaa: ++ dev_info(dev, "Device reset requested\n"); ++ break; ++ case 0xfe: ++ dev_info(dev, "Previous command not supported\n"); ++ break; ++ case 0x18: ++ case 0x1b: ++ default: ++ dev_info(dev, "Unknown command 0x%02x 0x%02x\n", ++ cmd, subcmd); ++ break; ++ } ++ break; ++ case 0x9f: ++ switch (subcmd) { ++ case 0x03: ++ dev_info(dev, "Ping\n"); ++ break; ++ case 0x04: ++ dev_info(dev, "Resp to 9f 05 of 0x%02x 0x%02x\n", ++ data1, data2); ++ break; ++ case 0x06: ++ dev_info(dev, "%s carrier mode and freq of 0x%02x 0x%02x\n", ++ inout, data1, data2); ++ break; ++ case 0x07: ++ dev_info(dev, "Get carrier mode and freq\n"); ++ break; ++ case 0x08: ++ dev_info(dev, "%s transmit blaster mask of 0x%02x\n", ++ inout, data1); ++ break; ++ case 0x0c: ++ /* value is in units of 50us, so x*50/100 or x/2 ms */ ++ dev_info(dev, "%s receive timeout of %d ms\n", ++ inout, ((data1 << 8) | data2) / 2); ++ break; ++ case 0x0d: ++ dev_info(dev, "Get receive timeout\n"); ++ break; ++ case 0x13: ++ dev_info(dev, "Get transmit blaster mask\n"); ++ break; ++ case 0x14: ++ dev_info(dev, "%s %s-range receive sensor in use\n", ++ inout, data1 == 0x02 ? "short" : "long"); ++ break; ++ case 0x15: ++ if (len == 2) ++ dev_info(dev, "Get receive sensor\n"); ++ else ++ dev_info(dev, "Received pulse count is %d\n", ++ ((data1 << 8) | data2)); ++ break; ++ case 0xfe: ++ dev_info(dev, "Error! Hardware is likely wedged...\n"); ++ break; ++ case 0x05: ++ case 0x09: ++ case 0x0f: ++ default: ++ dev_info(dev, "Unknown command 0x%02x 0x%02x\n", ++ cmd, subcmd); ++ break; ++ } ++ break; ++ default: ++ break; ++ } ++} ++ ++static void usb_async_callback(struct urb *urb, struct pt_regs *regs) ++{ ++ struct mceusb_dev *ir; ++ int len; ++ ++ if (!urb) ++ return; ++ ++ ir = urb->context; ++ if (ir) { ++ len = urb->actual_length; ++ ++ dev_dbg(ir->d->dev, "callback called (status=%d len=%d)\n", ++ urb->status, len); ++ ++ if (debug) ++ mceusb_dev_printdata(ir, urb->transfer_buffer, len, true); ++ } ++ ++} ++ ++/* request incoming or send outgoing usb packet - used to initialize remote */ ++static void mce_request_packet(struct mceusb_dev *ir, ++ struct usb_endpoint_descriptor *ep, ++ unsigned char *data, int size, int urb_type) ++{ ++ int res; ++ struct urb *async_urb; ++ unsigned char *async_buf; ++ ++ if (urb_type == MCEUSB_OUTBOUND) { ++ async_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (unlikely(!async_urb)) { ++ dev_err(ir->d->dev, "Error, couldn't allocate urb!\n"); ++ return; ++ } ++ ++ async_buf = kzalloc(size, GFP_KERNEL); ++ if (!async_buf) { ++ dev_err(ir->d->dev, "Error, couldn't allocate buf!\n"); ++ usb_free_urb(async_urb); ++ return; ++ } ++ ++ /* outbound data */ ++ usb_fill_int_urb(async_urb, ir->usbdev, ++ usb_sndintpipe(ir->usbdev, ep->bEndpointAddress), ++ async_buf, size, (usb_complete_t) usb_async_callback, ++ ir, ep->bInterval); ++ memcpy(async_buf, data, size); ++ ++ } else if (urb_type == MCEUSB_INBOUND) { ++ /* standard request */ ++ async_urb = ir->urb_in; ++ ir->send_flags = RECV_FLAG_IN_PROGRESS; ++ ++ } else { ++ dev_err(ir->d->dev, "Error! Unknown urb type %d\n", urb_type); ++ return; ++ } ++ ++ dev_dbg(ir->d->dev, "receive request called (size=%#x)\n", size); ++ ++ async_urb->transfer_buffer_length = size; ++ async_urb->dev = ir->usbdev; ++ ++ res = usb_submit_urb(async_urb, GFP_ATOMIC); ++ if (res) { ++ dev_dbg(ir->d->dev, "receive request FAILED! (res=%d)\n", res); ++ return; ++ } ++ dev_dbg(ir->d->dev, "receive request complete (res=%d)\n", res); ++} ++ ++static void mce_async_out(struct mceusb_dev *ir, unsigned char *data, int size) ++{ ++ mce_request_packet(ir, ir->usb_ep_out, data, size, MCEUSB_OUTBOUND); ++} ++ ++static void mce_sync_in(struct mceusb_dev *ir, unsigned char *data, int size) ++{ ++ mce_request_packet(ir, ir->usb_ep_in, data, size, MCEUSB_INBOUND); ++} ++ ++static int unregister_from_lirc(struct mceusb_dev *ir) ++{ ++ struct lirc_driver *d = ir->d; ++ int devnum; ++ int rtn; ++ ++ devnum = ir->devnum; ++ dev_dbg(ir->d->dev, "unregister from lirc called\n"); ++ ++ rtn = lirc_unregister_driver(d->minor); ++ if (rtn > 0) { ++ dev_info(ir->d->dev, "error in lirc_unregister minor: %d\n" ++ "Trying again...\n", d->minor); ++ if (rtn == -EBUSY) { ++ dev_info(ir->d->dev, "device is opened, will " ++ "unregister on close\n"); ++ return -EAGAIN; ++ } ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(HZ); ++ ++ rtn = lirc_unregister_driver(d->minor); ++ if (rtn > 0) ++ dev_info(ir->d->dev, "lirc_unregister failed\n"); ++ } ++ ++ if (rtn) { ++ dev_info(ir->d->dev, "didn't free resources\n"); ++ return -EAGAIN; ++ } ++ ++ dev_info(ir->d->dev, "usb remote disconnected\n"); ++ ++ lirc_buffer_free(d->rbuf); ++ kfree(d->rbuf); ++ kfree(d); ++ kfree(ir); ++ return 0; ++} ++ ++static int mceusb_ir_open(void *data) ++{ ++ struct mceusb_dev *ir = data; ++ ++ if (!ir) { ++ printk(KERN_WARNING DRIVER_NAME ++ "[?]: %s called with no context\n", __func__); ++ return -EIO; ++ } ++ ++ dev_dbg(ir->d->dev, "mceusb IR device opened\n"); ++ ++ if (!ir->flags.connected) { ++ if (!ir->usbdev) ++ return -ENOENT; ++ ir->flags.connected = 1; ++ } ++ ++ return 0; ++} ++ ++static void mceusb_ir_close(void *data) ++{ ++ struct mceusb_dev *ir = data; ++ ++ if (!ir) { ++ printk(KERN_WARNING DRIVER_NAME ++ "[?]: %s called with no context\n", __func__); ++ return; ++ } ++ ++ dev_dbg(ir->d->dev, "mceusb IR device closed\n"); ++ ++ if (ir->flags.connected) { ++ mutex_lock(&ir->dev_lock); ++ ir->flags.connected = 0; ++ mutex_unlock(&ir->dev_lock); ++ } ++} ++ ++static void send_packet_to_lirc(struct mceusb_dev *ir) ++{ ++ if (ir->lircdata) { ++ lirc_buffer_write(ir->d->rbuf, ++ (unsigned char *) &ir->lircdata); ++ wake_up(&ir->d->rbuf->wait_poll); ++ ir->lircdata = 0; ++ } ++} ++ ++static void mceusb_process_ir_data(struct mceusb_dev *ir, int buf_len) ++{ ++ int i, j; ++ int packet_len = 0; ++ int start_index = 0; ++ ++ /* skip meaningless 0xb1 0x60 header bytes on orig receiver */ ++ if (ir->flags.microsoft_gen1) ++ start_index = 2; ++ ++ /* this should only trigger w/the 1st-gen mce receiver */ ++ for (i = start_index; i < (start_index + ir->overflow_len) && ++ i < buf_len; i++) { ++ /* rising/falling flank */ ++ if (ir->is_pulse != (ir->buf_in[i] & MCE_PULSE_BIT)) { ++ send_packet_to_lirc(ir); ++ ir->is_pulse = ir->buf_in[i] & MCE_PULSE_BIT; ++ } ++ ++ /* accumulate mce pulse/space values */ ++ ir->lircdata += (ir->buf_in[i] & MCE_PULSE_MASK) * ++ MCE_TIME_UNIT; ++ ir->lircdata |= (ir->is_pulse ? PULSE_BIT : 0); ++ } ++ start_index += ir->overflow_len; ++ ir->overflow_len = 0; ++ ++ for (i = start_index; i < buf_len; i++) { ++ /* decode mce packets of the form (84),AA,BB,CC,DD */ ++ ++ /* data headers */ ++ if (ir->buf_in[i] >= 0x80 && ir->buf_in[i] <= 0x9e) { ++ /* decode packet data */ ++ packet_len = ir->buf_in[i] & MCE_PACKET_LENGTH_MASK; ++ ir->overflow_len = i + 1 + packet_len - buf_len; ++ for (j = 1; j <= packet_len && (i + j < buf_len); j++) { ++ /* rising/falling flank */ ++ if (ir->is_pulse != ++ (ir->buf_in[i + j] & MCE_PULSE_BIT)) { ++ send_packet_to_lirc(ir); ++ ir->is_pulse = ++ ir->buf_in[i + j] & ++ MCE_PULSE_BIT; ++ } ++ ++ /* accumulate mce pulse/space values */ ++ ir->lircdata += ++ (ir->buf_in[i + j] & MCE_PULSE_MASK) * ++ MCE_TIME_UNIT; ++ ir->lircdata |= (ir->is_pulse ? PULSE_BIT : 0); ++ } ++ ++ i += packet_len; ++ ++ /* status header (0x9F) */ ++ } else if (ir->buf_in[i] == MCE_CONTROL_HEADER) { ++ /* ++ * A transmission containing one or more consecutive ir ++ * commands always ends with a GAP of 100ms followed by ++ * the sequence 0x9F 0x01 0x01 0x9F 0x15 0x00 0x00 0x80 ++ */ ++ ++#if 0 ++ Uncomment this if the last 100ms "infinity"-space should be transmitted ++ to lirc directly instead of at the beginning of the next transmission. ++ Changes pulse/space order. ++ ++ if (++i < buf_len && ir->buf_in[i] == 0x01) ++ send_packet_to_lirc(ir); ++ ++#endif ++ ++ /* end decode loop */ ++ dev_dbg(ir->d->dev, "[%d] %s: found control header\n", ++ ir->devnum, __func__); ++ ir->overflow_len = 0; ++ break; ++ } else { ++ dev_dbg(ir->d->dev, "[%d] %s: stray packet?\n", ++ ir->devnum, __func__); ++ ir->overflow_len = 0; ++ } ++ } ++ ++ return; ++} ++ ++static void mceusb_dev_recv(struct urb *urb, struct pt_regs *regs) ++{ ++ struct mceusb_dev *ir; ++ int buf_len; ++ ++ if (!urb) ++ return; ++ ++ ir = urb->context; ++ if (!ir) { ++ usb_unlink_urb(urb); ++ return; ++ } ++ ++ buf_len = urb->actual_length; ++ ++ if (debug) ++ mceusb_dev_printdata(ir, urb->transfer_buffer, buf_len, false); ++ ++ if (ir->send_flags == RECV_FLAG_IN_PROGRESS) { ++ ir->send_flags = SEND_FLAG_COMPLETE; ++ dev_dbg(ir->d->dev, "setup answer received %d bytes\n", ++ buf_len); ++ } ++ ++ switch (urb->status) { ++ /* success */ ++ case 0: ++ mceusb_process_ir_data(ir, buf_len); ++ break; ++ ++ case -ECONNRESET: ++ case -ENOENT: ++ case -ESHUTDOWN: ++ usb_unlink_urb(urb); ++ return; ++ ++ case -EPIPE: ++ default: ++ break; ++ } ++ ++ usb_submit_urb(urb, GFP_ATOMIC); ++} ++ ++ ++static ssize_t mceusb_transmit_ir(struct file *file, const char *buf, ++ size_t n, loff_t *ppos) ++{ ++ int i, count = 0, cmdcount = 0; ++ struct mceusb_dev *ir = NULL; ++ int wbuf[LIRCBUF_SIZE]; /* Workbuffer with values from lirc */ ++ unsigned char cmdbuf[MCE_CMDBUF_SIZE]; /* MCE command buffer */ ++ unsigned long signal_duration = 0; /* Singnal length in us */ ++ struct timeval start_time, end_time; ++ ++ do_gettimeofday(&start_time); ++ ++ /* Retrieve lirc_driver data for the device */ ++ ir = lirc_get_pdata(file); ++ if (!ir || !ir->usb_ep_out) ++ return -EFAULT; ++ ++ if (n % sizeof(int)) ++ return -EINVAL; ++ count = n / sizeof(int); ++ ++ /* Check if command is within limits */ ++ if (count > LIRCBUF_SIZE || count%2 == 0) ++ return -EINVAL; ++ if (copy_from_user(wbuf, buf, n)) ++ return -EFAULT; ++ ++ /* MCE tx init header */ ++ cmdbuf[cmdcount++] = MCE_CONTROL_HEADER; ++ cmdbuf[cmdcount++] = 0x08; ++ cmdbuf[cmdcount++] = ir->transmitter_mask; ++ ++ /* Generate mce packet data */ ++ for (i = 0; (i < count) && (cmdcount < MCE_CMDBUF_SIZE); i++) { ++ signal_duration += wbuf[i]; ++ wbuf[i] = wbuf[i] / MCE_TIME_UNIT; ++ ++ do { /* loop to support long pulses/spaces > 127*50us=6.35ms */ ++ ++ /* Insert mce packet header every 4th entry */ ++ if ((cmdcount < MCE_CMDBUF_SIZE) && ++ (cmdcount - MCE_TX_HEADER_LENGTH) % ++ MCE_CODE_LENGTH == 0) ++ cmdbuf[cmdcount++] = MCE_PACKET_HEADER; ++ ++ /* Insert mce packet data */ ++ if (cmdcount < MCE_CMDBUF_SIZE) ++ cmdbuf[cmdcount++] = ++ (wbuf[i] < MCE_PULSE_BIT ? ++ wbuf[i] : MCE_MAX_PULSE_LENGTH) | ++ (i & 1 ? 0x00 : MCE_PULSE_BIT); ++ else ++ return -EINVAL; ++ } while ((wbuf[i] > MCE_MAX_PULSE_LENGTH) && ++ (wbuf[i] -= MCE_MAX_PULSE_LENGTH)); ++ } ++ ++ /* Fix packet length in last header */ ++ cmdbuf[cmdcount - (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH] = ++ 0x80 + (cmdcount - MCE_TX_HEADER_LENGTH) % MCE_CODE_LENGTH - 1; ++ ++ /* Check if we have room for the empty packet at the end */ ++ if (cmdcount >= MCE_CMDBUF_SIZE) ++ return -EINVAL; ++ ++ /* All mce commands end with an empty packet (0x80) */ ++ cmdbuf[cmdcount++] = 0x80; ++ ++ /* Transmit the command to the mce device */ ++ mce_async_out(ir, cmdbuf, cmdcount); ++ ++ /* ++ * The lircd gap calculation expects the write function to ++ * wait the time it takes for the ircommand to be sent before ++ * it returns. ++ */ ++ do_gettimeofday(&end_time); ++ signal_duration -= (end_time.tv_usec - start_time.tv_usec) + ++ (end_time.tv_sec - start_time.tv_sec) * 1000000; ++ ++ /* delay with the closest number of ticks */ ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(usecs_to_jiffies(signal_duration)); ++ ++ return n; ++} ++ ++static void set_transmitter_mask(struct mceusb_dev *ir, unsigned int mask) ++{ ++ if (ir->flags.transmitter_mask_inverted) ++ ir->transmitter_mask = (mask != 0x03 ? mask ^ 0x03 : mask) << 1; ++ else ++ ir->transmitter_mask = mask; ++} ++ ++ ++/* Sets the send carrier frequency */ ++static int set_send_carrier(struct mceusb_dev *ir, int carrier) ++{ ++ int clk = 10000000; ++ int prescaler = 0, divisor = 0; ++ unsigned char cmdbuf[] = { 0x9F, 0x06, 0x01, 0x80 }; ++ ++ /* Carrier is changed */ ++ if (ir->carrier_freq != carrier) { ++ ++ if (carrier <= 0) { ++ ir->carrier_freq = carrier; ++ dev_dbg(ir->d->dev, "SET_CARRIER disabling carrier " ++ "modulation\n"); ++ mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); ++ return carrier; ++ } ++ ++ for (prescaler = 0; prescaler < 4; ++prescaler) { ++ divisor = (clk >> (2 * prescaler)) / carrier; ++ if (divisor <= 0xFF) { ++ ir->carrier_freq = carrier; ++ cmdbuf[2] = prescaler; ++ cmdbuf[3] = divisor; ++ dev_dbg(ir->d->dev, "SET_CARRIER requesting " ++ "%d Hz\n", carrier); ++ ++ /* Transmit new carrier to mce device */ ++ mce_async_out(ir, cmdbuf, sizeof(cmdbuf)); ++ return carrier; ++ } ++ } ++ ++ return -EINVAL; ++ ++ } ++ ++ return carrier; ++} ++ ++ ++static int mceusb_lirc_ioctl(struct inode *node, struct file *filep, ++ unsigned int cmd, unsigned long arg) ++{ ++ int result; ++ unsigned int ivalue; ++ unsigned long lvalue; ++ struct mceusb_dev *ir = NULL; ++ ++ /* Retrieve lirc_driver data for the device */ ++ ir = lirc_get_pdata(filep); ++ if (!ir || !ir->usb_ep_out) ++ return -EFAULT; ++ ++ ++ switch (cmd) { ++ case LIRC_SET_TRANSMITTER_MASK: ++ ++ result = get_user(ivalue, (unsigned int *) arg); ++ if (result) ++ return result; ++ switch (ivalue) { ++ case 0x01: /* Transmitter 1 => 0x04 */ ++ case 0x02: /* Transmitter 2 => 0x02 */ ++ case 0x03: /* Transmitter 1 & 2 => 0x06 */ ++ set_transmitter_mask(ir, ivalue); ++ break; ++ ++ default: /* Unsupported transmitter mask */ ++ return MCE_MAX_CHANNELS; ++ } ++ ++ dev_dbg(ir->d->dev, ": SET_TRANSMITTERS mask=%d\n", ivalue); ++ break; ++ ++ case LIRC_GET_SEND_MODE: ++ ++ result = put_user(LIRC_SEND2MODE(LIRC_CAN_SEND_PULSE & ++ LIRC_CAN_SEND_MASK), ++ (unsigned long *) arg); ++ ++ if (result) ++ return result; ++ break; ++ ++ case LIRC_SET_SEND_MODE: ++ ++ result = get_user(lvalue, (unsigned long *) arg); ++ ++ if (result) ++ return result; ++ if (lvalue != (LIRC_MODE_PULSE&LIRC_CAN_SEND_MASK)) ++ return -EINVAL; ++ break; ++ ++ case LIRC_SET_SEND_CARRIER: ++ ++ result = get_user(ivalue, (unsigned int *) arg); ++ if (result) ++ return result; ++ ++ set_send_carrier(ir, ivalue); ++ break; ++ ++ default: ++ return lirc_dev_fop_ioctl(node, filep, cmd, arg); ++ } ++ ++ return 0; ++} ++ ++static struct file_operations lirc_fops = { ++ .owner = THIS_MODULE, ++ .write = mceusb_transmit_ir, ++ .ioctl = mceusb_lirc_ioctl, ++ .read = lirc_dev_fop_read, ++ .poll = lirc_dev_fop_poll, ++ .open = lirc_dev_fop_open, ++ .release = lirc_dev_fop_close, ++}; ++ ++static int mceusb_gen1_init(struct mceusb_dev *ir) ++{ ++ int i, ret; ++ char junk[64], data[8]; ++ int partial = 0; ++ ++ /* ++ * Clear off the first few messages. These look like calibration ++ * or test data, I can't really tell. This also flushes in case ++ * we have random ir data queued up. ++ */ ++ for (i = 0; i < 40; i++) ++ usb_bulk_msg(ir->usbdev, ++ usb_rcvbulkpipe(ir->usbdev, ++ ir->usb_ep_in->bEndpointAddress), ++ junk, 64, &partial, HZ * 10); ++ ++ ir->is_pulse = 1; ++ ++ memset(data, 0, 8); ++ ++ /* Get Status */ ++ ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), ++ USB_REQ_GET_STATUS, USB_DIR_IN, ++ 0, 0, data, 2, HZ * 3); ++ ++ /* ret = usb_get_status( ir->usbdev, 0, 0, data ); */ ++ dev_dbg(ir->d->dev, "%s - ret = %d status = 0x%x 0x%x\n", __func__, ++ ret, data[0], data[1]); ++ ++ /* ++ * This is a strange one. They issue a set address to the device ++ * on the receive control pipe and expect a certain value pair back ++ */ ++ memset(data, 0, 8); ++ ++ ret = usb_control_msg(ir->usbdev, usb_rcvctrlpipe(ir->usbdev, 0), ++ USB_REQ_SET_ADDRESS, USB_TYPE_VENDOR, 0, 0, ++ data, 2, HZ * 3); ++ dev_dbg(ir->d->dev, "%s - ret = %d, devnum = %d\n", ++ __func__, ret, ir->usbdev->devnum); ++ dev_dbg(ir->d->dev, "%s - data[0] = %d, data[1] = %d\n", ++ __func__, data[0], data[1]); ++ ++ /* set feature: bit rate 38400 bps */ ++ ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), ++ USB_REQ_SET_FEATURE, USB_TYPE_VENDOR, ++ 0xc04e, 0x0000, NULL, 0, HZ * 3); ++ ++ dev_dbg(ir->d->dev, "%s - ret = %d\n", __func__, ret); ++ ++ /* bRequest 4: set char length to 8 bits */ ++ ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), ++ 4, USB_TYPE_VENDOR, ++ 0x0808, 0x0000, NULL, 0, HZ * 3); ++ dev_dbg(ir->d->dev, "%s - retB = %d\n", __func__, ret); ++ ++ /* bRequest 2: set handshaking to use DTR/DSR */ ++ ret = usb_control_msg(ir->usbdev, usb_sndctrlpipe(ir->usbdev, 0), ++ 2, USB_TYPE_VENDOR, ++ 0x0000, 0x0100, NULL, 0, HZ * 3); ++ dev_dbg(ir->d->dev, "%s - retC = %d\n", __func__, ret); ++ ++ return ret; ++ ++}; ++ ++static int mceusb_dev_probe(struct usb_interface *intf, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *dev = interface_to_usbdev(intf); ++ struct usb_host_interface *idesc; ++ struct usb_endpoint_descriptor *ep = NULL; ++ struct usb_endpoint_descriptor *ep_in = NULL; ++ struct usb_endpoint_descriptor *ep_out = NULL; ++ struct usb_host_config *config; ++ struct mceusb_dev *ir = NULL; ++ struct lirc_driver *driver = NULL; ++ struct lirc_buffer *rbuf = NULL; ++ int devnum, pipe, maxp; ++ int minor = 0; ++ int i; ++ char buf[63], name[128] = ""; ++ int mem_failure = 0; ++ bool is_gen3; ++ bool is_microsoft_gen1; ++ bool is_pinnacle; ++ ++ dev_dbg(&intf->dev, ": %s called\n", __func__); ++ ++ usb_reset_device(dev); ++ ++ config = dev->actconfig; ++ ++ idesc = intf->cur_altsetting; ++ ++ is_gen3 = usb_match_id(intf, gen3_list) ? 1 : 0; ++ ++ is_microsoft_gen1 = usb_match_id(intf, microsoft_gen1_list) ? 1 : 0; ++ ++ is_pinnacle = usb_match_id(intf, pinnacle_list) ? 1 : 0; ++ ++ /* step through the endpoints to find first bulk in and out endpoint */ ++ for (i = 0; i < idesc->desc.bNumEndpoints; ++i) { ++ ep = &idesc->endpoint[i].desc; ++ ++ if ((ep_in == NULL) ++ && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ++ == USB_DIR_IN) ++ && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ++ == USB_ENDPOINT_XFER_BULK) ++ || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ++ == USB_ENDPOINT_XFER_INT))) { ++ ++ dev_dbg(&intf->dev, ": acceptable inbound endpoint " ++ "found\n"); ++ ep_in = ep; ++ ep_in->bmAttributes = USB_ENDPOINT_XFER_INT; ++ if (!is_pinnacle) ++ /* ++ * Ideally, we'd use what the device offers up, ++ * but that leads to non-functioning first and ++ * second-gen devices, and many devices have an ++ * invalid bInterval of 0. Pinnacle devices ++ * don't work witha bInterval of 1 though. ++ */ ++ ep_in->bInterval = 1; ++ } ++ ++ if ((ep_out == NULL) ++ && ((ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ++ == USB_DIR_OUT) ++ && (((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ++ == USB_ENDPOINT_XFER_BULK) ++ || ((ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ++ == USB_ENDPOINT_XFER_INT))) { ++ ++ dev_dbg(&intf->dev, ": acceptable outbound endpoint " ++ "found\n"); ++ ep_out = ep; ++ ep_out->bmAttributes = USB_ENDPOINT_XFER_INT; ++ if (!is_pinnacle) ++ /* ++ * Ideally, we'd use what the device offers up, ++ * but that leads to non-functioning first and ++ * second-gen devices, and many devices have an ++ * invalid bInterval of 0. Pinnacle devices ++ * don't work witha bInterval of 1 though. ++ */ ++ ep_out->bInterval = 1; ++ } ++ } ++ if (ep_in == NULL) { ++ dev_dbg(&intf->dev, ": inbound and/or endpoint not found\n"); ++ return -ENODEV; ++ } ++ ++ devnum = dev->devnum; ++ pipe = usb_rcvintpipe(dev, ep_in->bEndpointAddress); ++ maxp = usb_maxpacket(dev, pipe, usb_pipeout(pipe)); ++ ++ mem_failure = 0; ++ ir = kzalloc(sizeof(struct mceusb_dev), GFP_KERNEL); ++ if (!ir) ++ goto mem_alloc_fail; ++ ++ driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); ++ if (!driver) ++ goto mem_alloc_fail; ++ ++ rbuf = kzalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!rbuf) ++ goto mem_alloc_fail; ++ ++ if (lirc_buffer_init(rbuf, sizeof(int), LIRCBUF_SIZE)) ++ goto mem_alloc_fail; ++ ++ ir->buf_in = usb_buffer_alloc(dev, maxp, GFP_ATOMIC, &ir->dma_in); ++ if (!ir->buf_in) ++ goto buf_in_alloc_fail; ++ ++ ir->urb_in = usb_alloc_urb(0, GFP_KERNEL); ++ if (!ir->urb_in) ++ goto urb_in_alloc_fail; ++ ++ strcpy(driver->name, DRIVER_NAME); ++ driver->minor = -1; ++ driver->features = LIRC_CAN_SEND_PULSE | ++ LIRC_CAN_SET_TRANSMITTER_MASK | ++ LIRC_CAN_REC_MODE2 | ++ LIRC_CAN_SET_SEND_CARRIER; ++ driver->data = ir; ++ driver->rbuf = rbuf; ++ driver->set_use_inc = &mceusb_ir_open; ++ driver->set_use_dec = &mceusb_ir_close; ++ driver->code_length = sizeof(int) * 8; ++ driver->fops = &lirc_fops; ++ driver->dev = &intf->dev; ++ driver->owner = THIS_MODULE; ++ ++ mutex_init(&ir->dev_lock); ++ init_waitqueue_head(&ir->wait_out); ++ ++ minor = lirc_register_driver(driver); ++ if (minor < 0) ++ goto lirc_register_fail; ++ ++ driver->minor = minor; ++ ir->d = driver; ++ ir->devnum = devnum; ++ ir->usbdev = dev; ++ ir->len_in = maxp; ++ ir->overflow_len = 0; ++ ir->flags.connected = 0; ++ ir->flags.gen3 = is_gen3; ++ ir->flags.microsoft_gen1 = is_microsoft_gen1; ++ ir->flags.transmitter_mask_inverted = ++ usb_match_id(intf, transmitter_mask_list) ? 0 : 1; ++ ++ ir->lircdata = PULSE_MASK; ++ ir->is_pulse = 0; ++ ++ /* ir->flags.transmitter_mask_inverted must be set */ ++ set_transmitter_mask(ir, MCE_DEFAULT_TX_MASK); ++ /* Saving usb interface data for use by the transmitter routine */ ++ ir->usb_ep_in = ep_in; ++ ir->usb_ep_out = ep_out; ++ ++ if (dev->descriptor.iManufacturer ++ && usb_string(dev, dev->descriptor.iManufacturer, ++ buf, sizeof(buf)) > 0) ++ strlcpy(name, buf, sizeof(name)); ++ if (dev->descriptor.iProduct ++ && usb_string(dev, dev->descriptor.iProduct, ++ buf, sizeof(buf)) > 0) ++ snprintf(name + strlen(name), sizeof(name) - strlen(name), ++ " %s", buf); ++ ++ /* inbound data */ ++ usb_fill_int_urb(ir->urb_in, dev, pipe, ir->buf_in, ++ maxp, (usb_complete_t) mceusb_dev_recv, ir, ep_in->bInterval); ++ ir->urb_in->transfer_dma = ir->dma_in; ++ ir->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; ++ ++ if (is_pinnacle) { ++ int usbret; ++ ++ /* ++ * I have no idea why but this reset seems to be crucial to ++ * getting the device to do outbound IO correctly - without ++ * this the device seems to hang, ignoring all input - although ++ * IR signals are correctly sent from the device, no input is ++ * interpreted by the device and the host never does the ++ * completion routine ++ */ ++ usbret = usb_reset_configuration(dev); ++ dev_info(ir->d->dev, "usb reset config ret %x\n", usbret); ++ } ++ ++ /* initialize device */ ++ if (ir->flags.gen3) { ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* device reset */ ++ mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* get the carrier and frequency */ ++ mce_async_out(ir, GET_CARRIER_FREQ, sizeof(GET_CARRIER_FREQ)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* get the transmitter bitmask */ ++ mce_async_out(ir, GET_TX_BITMASK, sizeof(GET_TX_BITMASK)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* get receiver timeout value */ ++ mce_async_out(ir, GET_RX_TIMEOUT, sizeof(GET_RX_TIMEOUT)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* get receiver sensor setting */ ++ mce_async_out(ir, GET_RX_SENSOR, sizeof(GET_RX_SENSOR)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ } else if (ir->flags.microsoft_gen1) { ++ /* original ms mce device requires some additional setup */ ++ mceusb_gen1_init(ir); ++ ++ } else { ++ mce_sync_in(ir, NULL, maxp); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* device reset */ ++ mce_async_out(ir, DEVICE_RESET, sizeof(DEVICE_RESET)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* get hw/sw revision? */ ++ mce_async_out(ir, GET_REVISION, sizeof(GET_REVISION)); ++ mce_sync_in(ir, NULL, maxp); ++ ++ /* unknown what this actually returns... */ ++ mce_async_out(ir, GET_UNKNOWN, sizeof(GET_UNKNOWN)); ++ mce_sync_in(ir, NULL, maxp); ++ } ++ ++ /* ++ * if we don't issue the correct number of receives (mce_sync_in()) ++ * for each outbound, then the first few ir pulses will be interpreted ++ * by the usb_async_callback routine - we should ensure we have the ++ * right amount OR less - as the mceusb_dev_recv routine will handle ++ * the control packets OK - they start with 0x9f - but the async ++ * callback doesn't handle ir pulse packets ++ */ ++ mce_sync_in(ir, NULL, maxp); ++ ++ usb_set_intfdata(intf, ir); ++ ++ dev_info(ir->d->dev, "Registered %s on usb%d:%d\n", name, ++ dev->bus->busnum, devnum); ++ ++ return 0; ++ ++ /* Error-handling path */ ++lirc_register_fail: ++ usb_free_urb(ir->urb_in); ++urb_in_alloc_fail: ++ usb_buffer_free(dev, maxp, ir->buf_in, ir->dma_in); ++buf_in_alloc_fail: ++ lirc_buffer_free(rbuf); ++mem_alloc_fail: ++ kfree(rbuf); ++ kfree(driver); ++ kfree(ir); ++ dev_info(&intf->dev, "out of memory (code=%d)\n", mem_failure); ++ ++ return -ENOMEM; ++} ++ ++ ++static void mceusb_dev_disconnect(struct usb_interface *intf) ++{ ++ struct usb_device *dev = interface_to_usbdev(intf); ++ struct mceusb_dev *ir = usb_get_intfdata(intf); ++ ++ usb_set_intfdata(intf, NULL); ++ ++ if (!ir || !ir->d) ++ return; ++ ++ ir->usbdev = NULL; ++ wake_up_all(&ir->wait_out); ++ ++ mutex_lock(&ir->dev_lock); ++ usb_kill_urb(ir->urb_in); ++ usb_free_urb(ir->urb_in); ++ usb_buffer_free(dev, ir->len_in, ir->buf_in, ir->dma_in); ++ mutex_unlock(&ir->dev_lock); ++ ++ unregister_from_lirc(ir); ++} ++ ++static int mceusb_dev_suspend(struct usb_interface *intf, pm_message_t message) ++{ ++ struct mceusb_dev *ir = usb_get_intfdata(intf); ++ dev_info(ir->d->dev, "suspend\n"); ++ usb_kill_urb(ir->urb_in); ++ return 0; ++} ++ ++static int mceusb_dev_resume(struct usb_interface *intf) ++{ ++ struct mceusb_dev *ir = usb_get_intfdata(intf); ++ dev_info(ir->d->dev, "resume\n"); ++ if (usb_submit_urb(ir->urb_in, GFP_ATOMIC)) ++ return -EIO; ++ return 0; ++} ++ ++static struct usb_driver mceusb_dev_driver = { ++ .name = DRIVER_NAME, ++ .probe = mceusb_dev_probe, ++ .disconnect = mceusb_dev_disconnect, ++ .suspend = mceusb_dev_suspend, ++ .resume = mceusb_dev_resume, ++ .reset_resume = mceusb_dev_resume, ++ .id_table = mceusb_dev_table ++}; ++ ++static int __init mceusb_dev_init(void) ++{ ++ int i; ++ ++ printk(KERN_INFO DRIVER_NAME ": " DRIVER_DESC " " DRIVER_VERSION "\n"); ++ printk(KERN_INFO DRIVER_NAME ": " DRIVER_AUTHOR "\n"); ++ if (debug) ++ printk(KERN_DEBUG DRIVER_NAME ": debug mode enabled\n"); ++ ++ i = usb_register(&mceusb_dev_driver); ++ if (i < 0) { ++ printk(KERN_ERR DRIVER_NAME ++ ": usb register failed, result = %d\n", i); ++ return -ENODEV; ++ } ++ ++ return 0; ++} ++ ++static void __exit mceusb_dev_exit(void) ++{ ++ usb_deregister(&mceusb_dev_driver); ++} ++ ++module_init(mceusb_dev_init); ++module_exit(mceusb_dev_exit); ++ ++MODULE_DESCRIPTION(DRIVER_DESC); ++MODULE_AUTHOR(DRIVER_AUTHOR); ++MODULE_LICENSE("GPL"); ++MODULE_DEVICE_TABLE(usb, mceusb_dev_table); ++/* this was originally lirc_mceusb2, lirc_mceusb and lirc_mceusb2 merged now */ ++MODULE_ALIAS("lirc_mceusb2"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Debug enabled or not"); +diff --git a/drivers/input/lirc/lirc_parallel.c b/drivers/input/lirc/lirc_parallel.c +new file mode 100644 +index 0000000..bb57b3e +--- /dev/null ++++ b/drivers/input/lirc/lirc_parallel.c +@@ -0,0 +1,709 @@ ++/* ++ * lirc_parallel.c ++ * ++ * lirc_parallel - device driver for infra-red signal receiving and ++ * transmitting unit built by the author ++ * ++ * Copyright (C) 1998 Christoph Bartelmus ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++/*** Includes ***/ ++ ++#ifdef CONFIG_SMP ++#error "--- Sorry, this driver is not SMP safe. ---" ++#endif ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++#include "lirc_parallel.h" ++ ++#define LIRC_DRIVER_NAME "lirc_parallel" ++ ++#ifndef LIRC_IRQ ++#define LIRC_IRQ 7 ++#endif ++#ifndef LIRC_PORT ++#define LIRC_PORT 0x378 ++#endif ++#ifndef LIRC_TIMER ++#define LIRC_TIMER 65536 ++#endif ++ ++/*** Global Variables ***/ ++ ++static int debug; ++static int check_pselecd; ++ ++unsigned int irq = LIRC_IRQ; ++unsigned int io = LIRC_PORT; ++#ifdef LIRC_TIMER ++unsigned int timer; ++unsigned int default_timer = LIRC_TIMER; ++#endif ++ ++#define WBUF_SIZE (256) ++#define RBUF_SIZE (256) /* this must be a power of 2 larger than 1 */ ++ ++static int wbuf[WBUF_SIZE]; ++static int rbuf[RBUF_SIZE]; ++ ++DECLARE_WAIT_QUEUE_HEAD(lirc_wait); ++ ++unsigned int rptr; ++unsigned int wptr; ++unsigned int lost_irqs; ++int is_open; ++ ++struct parport *pport; ++struct pardevice *ppdevice; ++int is_claimed; ++ ++unsigned int tx_mask = 1; ++ ++/*** Internal Functions ***/ ++ ++static unsigned int in(int offset) ++{ ++ switch (offset) { ++ case LIRC_LP_BASE: ++ return parport_read_data(pport); ++ case LIRC_LP_STATUS: ++ return parport_read_status(pport); ++ case LIRC_LP_CONTROL: ++ return parport_read_control(pport); ++ } ++ return 0; /* make compiler happy */ ++} ++ ++static void out(int offset, int value) ++{ ++ switch (offset) { ++ case LIRC_LP_BASE: ++ parport_write_data(pport, value); ++ break; ++ case LIRC_LP_CONTROL: ++ parport_write_control(pport, value); ++ break; ++ case LIRC_LP_STATUS: ++ printk(KERN_INFO "%s: attempt to write to status register\n", ++ LIRC_DRIVER_NAME); ++ break; ++ } ++} ++ ++static unsigned int lirc_get_timer(void) ++{ ++ return in(LIRC_PORT_TIMER) & LIRC_PORT_TIMER_BIT; ++} ++ ++static unsigned int lirc_get_signal(void) ++{ ++ return in(LIRC_PORT_SIGNAL) & LIRC_PORT_SIGNAL_BIT; ++} ++ ++static void lirc_on(void) ++{ ++ out(LIRC_PORT_DATA, tx_mask); ++} ++ ++static void lirc_off(void) ++{ ++ out(LIRC_PORT_DATA, 0); ++} ++ ++static unsigned int init_lirc_timer(void) ++{ ++ struct timeval tv, now; ++ unsigned int level, newlevel, timeelapsed, newtimer; ++ int count = 0; ++ ++ do_gettimeofday(&tv); ++ tv.tv_sec++; /* wait max. 1 sec. */ ++ level = lirc_get_timer(); ++ do { ++ newlevel = lirc_get_timer(); ++ if (level == 0 && newlevel != 0) ++ count++; ++ level = newlevel; ++ do_gettimeofday(&now); ++ } while (count < 1000 && (now.tv_sec < tv.tv_sec ++ || (now.tv_sec == tv.tv_sec ++ && now.tv_usec < tv.tv_usec))); ++ ++ timeelapsed = ((now.tv_sec + 1 - tv.tv_sec)*1000000 ++ + (now.tv_usec - tv.tv_usec)); ++ if (count >= 1000 && timeelapsed > 0) { ++ if (default_timer == 0) { ++ /* autodetect timer */ ++ newtimer = (1000000*count)/timeelapsed; ++ printk(KERN_INFO "%s: %u Hz timer detected\n", ++ LIRC_DRIVER_NAME, newtimer); ++ return newtimer; ++ } else { ++ newtimer = (1000000*count)/timeelapsed; ++ if (abs(newtimer - default_timer) > default_timer/10) { ++ /* bad timer */ ++ printk(KERN_NOTICE "%s: bad timer: %u Hz\n", ++ LIRC_DRIVER_NAME, newtimer); ++ printk(KERN_NOTICE "%s: using default timer: " ++ "%u Hz\n", ++ LIRC_DRIVER_NAME, default_timer); ++ return default_timer; ++ } else { ++ printk(KERN_INFO "%s: %u Hz timer detected\n", ++ LIRC_DRIVER_NAME, newtimer); ++ return newtimer; /* use detected value */ ++ } ++ } ++ } else { ++ printk(KERN_NOTICE "%s: no timer detected\n", LIRC_DRIVER_NAME); ++ return 0; ++ } ++} ++ ++static int lirc_claim(void) ++{ ++ if (parport_claim(ppdevice) != 0) { ++ printk(KERN_WARNING "%s: could not claim port\n", ++ LIRC_DRIVER_NAME); ++ printk(KERN_WARNING "%s: waiting for port becoming available" ++ "\n", LIRC_DRIVER_NAME); ++ if (parport_claim_or_block(ppdevice) < 0) { ++ printk(KERN_NOTICE "%s: could not claim port, giving" ++ " up\n", LIRC_DRIVER_NAME); ++ return 0; ++ } ++ } ++ out(LIRC_LP_CONTROL, LP_PSELECP|LP_PINITP); ++ is_claimed = 1; ++ return 1; ++} ++ ++/*** interrupt handler ***/ ++ ++static void rbuf_write(int signal) ++{ ++ unsigned int nwptr; ++ ++ nwptr = (wptr + 1) & (RBUF_SIZE - 1); ++ if (nwptr == rptr) { ++ /* no new signals will be accepted */ ++ lost_irqs++; ++ printk(KERN_NOTICE "%s: buffer overrun\n", LIRC_DRIVER_NAME); ++ return; ++ } ++ rbuf[wptr] = signal; ++ wptr = nwptr; ++} ++ ++static void irq_handler(void *blah) ++{ ++ struct timeval tv; ++ static struct timeval lasttv; ++ static int init; ++ long signal; ++ int data; ++ unsigned int level, newlevel; ++ unsigned int timeout; ++ ++ if (!module_refcount(THIS_MODULE)) ++ return; ++ ++ if (!is_claimed) ++ return; ++ ++#if 0 ++ /* disable interrupt */ ++ disable_irq(irq); ++ out(LIRC_PORT_IRQ, in(LIRC_PORT_IRQ) & (~LP_PINTEN)); ++#endif ++ if (check_pselecd && (in(1) & LP_PSELECD)) ++ return; ++ ++#ifdef LIRC_TIMER ++ if (init) { ++ do_gettimeofday(&tv); ++ ++ signal = tv.tv_sec - lasttv.tv_sec; ++ if (signal > 15) ++ /* really long time */ ++ data = PULSE_MASK; ++ else ++ data = (int) (signal*1000000 + ++ tv.tv_usec - lasttv.tv_usec + ++ LIRC_SFH506_DELAY); ++ ++ rbuf_write(data); /* space */ ++ } else { ++ if (timer == 0) { ++ /* ++ * wake up; we'll lose this signal, but it will be ++ * garbage if the device is turned on anyway ++ */ ++ timer = init_lirc_timer(); ++ /* enable_irq(irq); */ ++ return; ++ } ++ init = 1; ++ } ++ ++ timeout = timer/10; /* timeout after 1/10 sec. */ ++ signal = 1; ++ level = lirc_get_timer(); ++ do { ++ newlevel = lirc_get_timer(); ++ if (level == 0 && newlevel != 0) ++ signal++; ++ level = newlevel; ++ ++ /* giving up */ ++ if (signal > timeout ++ || (check_pselecd && (in(1) & LP_PSELECD))) { ++ signal = 0; ++ printk(KERN_NOTICE "%s: timeout\n", LIRC_DRIVER_NAME); ++ break; ++ } ++ } while (lirc_get_signal()); ++ ++ if (signal != 0) { ++ /* ajust value to usecs */ ++ unsigned long long helper; ++ ++ helper = ((unsigned long long) signal)*1000000; ++ do_div(helper, timer); ++ signal = (long) helper; ++ ++ if (signal > LIRC_SFH506_DELAY) ++ data = signal - LIRC_SFH506_DELAY; ++ else ++ data = 1; ++ rbuf_write(PULSE_BIT|data); /* pulse */ ++ } ++ do_gettimeofday(&lasttv); ++#else ++ /* add your code here */ ++#endif ++ ++ wake_up_interruptible(&lirc_wait); ++ ++ /* enable interrupt */ ++ /* ++ enable_irq(irq); ++ out(LIRC_PORT_IRQ, in(LIRC_PORT_IRQ)|LP_PINTEN); ++ */ ++} ++ ++/*** file operations ***/ ++ ++static loff_t lirc_lseek(struct file *filep, loff_t offset, int orig) ++{ ++ return -ESPIPE; ++} ++ ++static ssize_t lirc_read(struct file *filep, char *buf, size_t n, loff_t *ppos) ++{ ++ int result = 0; ++ int count = 0; ++ DECLARE_WAITQUEUE(wait, current); ++ ++ if (n % sizeof(int)) ++ return -EINVAL; ++ ++ add_wait_queue(&lirc_wait, &wait); ++ set_current_state(TASK_INTERRUPTIBLE); ++ while (count < n) { ++ if (rptr != wptr) { ++ if (copy_to_user(buf+count, (char *) &rbuf[rptr], ++ sizeof(int))) { ++ result = -EFAULT; ++ break; ++ } ++ rptr = (rptr + 1) & (RBUF_SIZE - 1); ++ count += sizeof(int); ++ } else { ++ if (filep->f_flags & O_NONBLOCK) { ++ result = -EAGAIN; ++ break; ++ } ++ if (signal_pending(current)) { ++ result = -ERESTARTSYS; ++ break; ++ } ++ schedule(); ++ set_current_state(TASK_INTERRUPTIBLE); ++ } ++ } ++ remove_wait_queue(&lirc_wait, &wait); ++ set_current_state(TASK_RUNNING); ++ return count ? count : result; ++} ++ ++static ssize_t lirc_write(struct file *filep, const char *buf, size_t n, ++ loff_t *ppos) ++{ ++ int count; ++ unsigned int i; ++ unsigned int level, newlevel; ++ unsigned long flags; ++ int counttimer; ++ ++ if (!is_claimed) ++ return -EBUSY; ++ ++ if (n % sizeof(int)) ++ return -EINVAL; ++ ++ count = n / sizeof(int); ++ ++ if (count > WBUF_SIZE || count % 2 == 0) ++ return -EINVAL; ++ ++ if (copy_from_user(wbuf, buf, n)) ++ return -EFAULT; ++ ++#ifdef LIRC_TIMER ++ if (timer == 0) { ++ /* try again if device is ready */ ++ timer = init_lirc_timer(); ++ if (timer == 0) ++ return -EIO; ++ } ++ ++ /* adjust values from usecs */ ++ for (i = 0; i < count; i++) { ++ unsigned long long helper; ++ ++ helper = ((unsigned long long) wbuf[i])*timer; ++ do_div(helper, 1000000); ++ wbuf[i] = (int) helper; ++ } ++ ++ local_irq_save(flags); ++ i = 0; ++ while (i < count) { ++ level = lirc_get_timer(); ++ counttimer = 0; ++ lirc_on(); ++ do { ++ newlevel = lirc_get_timer(); ++ if (level == 0 && newlevel != 0) ++ counttimer++; ++ level = newlevel; ++ if (check_pselecd && (in(1) & LP_PSELECD)) { ++ lirc_off(); ++ local_irq_restore(flags); ++ return -EIO; ++ } ++ } while (counttimer < wbuf[i]); ++ i++; ++ ++ lirc_off(); ++ if (i == count) ++ break; ++ counttimer = 0; ++ do { ++ newlevel = lirc_get_timer(); ++ if (level == 0 && newlevel != 0) ++ counttimer++; ++ level = newlevel; ++ if (check_pselecd && (in(1) & LP_PSELECD)) { ++ local_irq_restore(flags); ++ return -EIO; ++ } ++ } while (counttimer < wbuf[i]); ++ i++; ++ } ++ local_irq_restore(flags); ++#else ++ /* place code that handles write without external timer here */ ++#endif ++ return n; ++} ++ ++static unsigned int lirc_poll(struct file *file, poll_table *wait) ++{ ++ poll_wait(file, &lirc_wait, wait); ++ if (rptr != wptr) ++ return POLLIN | POLLRDNORM; ++ return 0; ++} ++ ++static int lirc_ioctl(struct inode *node, struct file *filep, unsigned int cmd, ++ unsigned long arg) ++{ ++ int result; ++ unsigned long features = LIRC_CAN_SET_TRANSMITTER_MASK | ++ LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2; ++ unsigned long mode; ++ unsigned int ivalue; ++ ++ switch (cmd) { ++ case LIRC_GET_FEATURES: ++ result = put_user(features, (unsigned long *) arg); ++ if (result) ++ return result; ++ break; ++ case LIRC_GET_SEND_MODE: ++ result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg); ++ if (result) ++ return result; ++ break; ++ case LIRC_GET_REC_MODE: ++ result = put_user(LIRC_MODE_MODE2, (unsigned long *) arg); ++ if (result) ++ return result; ++ break; ++ case LIRC_SET_SEND_MODE: ++ result = get_user(mode, (unsigned long *) arg); ++ if (result) ++ return result; ++ if (mode != LIRC_MODE_PULSE) ++ return -EINVAL; ++ break; ++ case LIRC_SET_REC_MODE: ++ result = get_user(mode, (unsigned long *) arg); ++ if (result) ++ return result; ++ if (mode != LIRC_MODE_MODE2) ++ return -ENOSYS; ++ break; ++ case LIRC_SET_TRANSMITTER_MASK: ++ result = get_user(ivalue, (unsigned int *) arg); ++ if (result) ++ return result; ++ if ((ivalue & LIRC_PARALLEL_TRANSMITTER_MASK) != ivalue) ++ return LIRC_PARALLEL_MAX_TRANSMITTERS; ++ tx_mask = ivalue; ++ break; ++ default: ++ return -ENOIOCTLCMD; ++ } ++ return 0; ++} ++ ++static int lirc_open(struct inode *node, struct file *filep) ++{ ++ if (module_refcount(THIS_MODULE) || !lirc_claim()) ++ return -EBUSY; ++ ++ parport_enable_irq(pport); ++ ++ /* init read ptr */ ++ rptr = 0; ++ wptr = 0; ++ lost_irqs = 0; ++ ++ is_open = 1; ++ return 0; ++} ++ ++static int lirc_close(struct inode *node, struct file *filep) ++{ ++ if (is_claimed) { ++ is_claimed = 0; ++ parport_release(ppdevice); ++ } ++ is_open = 0; ++ return 0; ++} ++ ++static struct file_operations lirc_fops = { ++ .owner = THIS_MODULE, ++ .llseek = lirc_lseek, ++ .read = lirc_read, ++ .write = lirc_write, ++ .poll = lirc_poll, ++ .ioctl = lirc_ioctl, ++ .open = lirc_open, ++ .release = lirc_close ++}; ++ ++static int set_use_inc(void *data) ++{ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++} ++ ++static struct lirc_driver driver = { ++ .name = LIRC_DRIVER_NAME, ++ .minor = -1, ++ .code_length = 1, ++ .sample_rate = 0, ++ .data = NULL, ++ .add_to_buf = NULL, ++ .set_use_inc = set_use_inc, ++ .set_use_dec = set_use_dec, ++ .fops = &lirc_fops, ++ .dev = NULL, ++ .owner = THIS_MODULE, ++}; ++ ++static int pf(void *handle); ++static void kf(void *handle); ++ ++static struct timer_list poll_timer; ++static void poll_state(unsigned long ignored); ++ ++static void poll_state(unsigned long ignored) ++{ ++ printk(KERN_NOTICE "%s: time\n", ++ LIRC_DRIVER_NAME); ++ del_timer(&poll_timer); ++ if (is_claimed) ++ return; ++ kf(NULL); ++ if (!is_claimed) { ++ printk(KERN_NOTICE "%s: could not claim port, giving up\n", ++ LIRC_DRIVER_NAME); ++ init_timer(&poll_timer); ++ poll_timer.expires = jiffies + HZ; ++ poll_timer.data = (unsigned long)current; ++ poll_timer.function = poll_state; ++ add_timer(&poll_timer); ++ } ++} ++ ++static int pf(void *handle) ++{ ++ parport_disable_irq(pport); ++ is_claimed = 0; ++ return 0; ++} ++ ++static void kf(void *handle) ++{ ++ if (!is_open) ++ return; ++ if (!lirc_claim()) ++ return; ++ parport_enable_irq(pport); ++ lirc_off(); ++ /* this is a bit annoying when you actually print...*/ ++ /* ++ printk(KERN_INFO "%s: reclaimed port\n", LIRC_DRIVER_NAME); ++ */ ++} ++ ++/*** module initialization and cleanup ***/ ++ ++static int __init lirc_parallel_init(void) ++{ ++ pport = parport_find_base(io); ++ if (pport == NULL) { ++ printk(KERN_NOTICE "%s: no port at %x found\n", ++ LIRC_DRIVER_NAME, io); ++ return -ENXIO; ++ } ++ ppdevice = parport_register_device(pport, LIRC_DRIVER_NAME, ++ pf, kf, irq_handler, 0, NULL); ++ parport_put_port(pport); ++ if (ppdevice == NULL) { ++ printk(KERN_NOTICE "%s: parport_register_device() failed\n", ++ LIRC_DRIVER_NAME); ++ return -ENXIO; ++ } ++ if (parport_claim(ppdevice) != 0) ++ goto skip_init; ++ is_claimed = 1; ++ out(LIRC_LP_CONTROL, LP_PSELECP|LP_PINITP); ++ ++#ifdef LIRC_TIMER ++ if (debug) ++ out(LIRC_PORT_DATA, tx_mask); ++ ++ timer = init_lirc_timer(); ++ ++#if 0 /* continue even if device is offline */ ++ if (timer == 0) { ++ is_claimed = 0; ++ parport_release(pport); ++ parport_unregister_device(ppdevice); ++ return -EIO; ++ } ++ ++#endif ++ if (debug) ++ out(LIRC_PORT_DATA, 0); ++#endif ++ ++ is_claimed = 0; ++ parport_release(ppdevice); ++ skip_init: ++ driver.minor = lirc_register_driver(&driver); ++ if (driver.minor < 0) { ++ printk(KERN_NOTICE "%s: register_chrdev() failed\n", ++ LIRC_DRIVER_NAME); ++ parport_unregister_device(ppdevice); ++ return -EIO; ++ } ++ printk(KERN_INFO "%s: installed using port 0x%04x irq %d\n", ++ LIRC_DRIVER_NAME, io, irq); ++ return 0; ++} ++ ++static void __exit lirc_parallel_exit(void) ++{ ++ parport_unregister_device(ppdevice); ++ lirc_unregister_driver(driver.minor); ++} ++ ++module_init(lirc_parallel_init); ++module_exit(lirc_parallel_exit); ++ ++MODULE_DESCRIPTION("Infrared receiver driver for parallel ports."); ++MODULE_AUTHOR("Christoph Bartelmus"); ++MODULE_LICENSE("GPL"); ++ ++module_param(io, int, S_IRUGO); ++MODULE_PARM_DESC(io, "I/O address base (0x3bc, 0x378 or 0x278)"); ++ ++module_param(irq, int, S_IRUGO); ++MODULE_PARM_DESC(irq, "Interrupt (7 or 5)"); ++ ++module_param(tx_mask, int, S_IRUGO); ++MODULE_PARM_DESC(tx_maxk, "Transmitter mask (default: 0x01)"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); ++ ++module_param(check_pselecd, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Check for printer (default: 0)"); +diff --git a/drivers/input/lirc/lirc_parallel.h b/drivers/input/lirc/lirc_parallel.h +new file mode 100644 +index 0000000..4bed6af +--- /dev/null ++++ b/drivers/input/lirc/lirc_parallel.h +@@ -0,0 +1,26 @@ ++/* lirc_parallel.h */ ++ ++#ifndef _LIRC_PARALLEL_H ++#define _LIRC_PARALLEL_H ++ ++#include ++ ++#define LIRC_PORT_LEN 3 ++ ++#define LIRC_LP_BASE 0 ++#define LIRC_LP_STATUS 1 ++#define LIRC_LP_CONTROL 2 ++ ++#define LIRC_PORT_DATA LIRC_LP_BASE /* base */ ++#define LIRC_PORT_TIMER LIRC_LP_STATUS /* status port */ ++#define LIRC_PORT_TIMER_BIT LP_PBUSY /* busy signal */ ++#define LIRC_PORT_SIGNAL LIRC_LP_STATUS /* status port */ ++#define LIRC_PORT_SIGNAL_BIT LP_PACK /* ack signal */ ++#define LIRC_PORT_IRQ LIRC_LP_CONTROL /* control port */ ++ ++#define LIRC_SFH506_DELAY 0 /* delay t_phl in usecs */ ++ ++#define LIRC_PARALLEL_MAX_TRANSMITTERS 8 ++#define LIRC_PARALLEL_TRANSMITTER_MASK ((1< ++ * Tim Davies ++ * ++ * This driver was derived from: ++ * Venky Raju ++ * "lirc_imon - "LIRC/VFD driver for Ahanix/Soundgraph IMON IR/VFD" ++ * Paul Miller 's 2003-2004 ++ * "lirc_atiusb - USB remote support for LIRC" ++ * Culver Consulting Services 's 2003 ++ * "Sasem OnAir VFD/IR USB driver" ++ * ++ * ++ * NOTE - The LCDproc iMon driver should work with this module. More info at ++ * http://www.frogstorm.info/sasem ++ */ ++ ++/* ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++ ++#define MOD_AUTHOR "Oliver Stabel , " \ ++ "Tim Davies " ++#define MOD_DESC "USB Driver for Sasem Remote Controller V1.1" ++#define MOD_NAME "lirc_sasem" ++#define MOD_VERSION "0.5" ++ ++#define VFD_MINOR_BASE 144 /* Same as LCD */ ++#define DEVICE_NAME "lcd%d" ++ ++#define BUF_CHUNK_SIZE 8 ++#define BUF_SIZE 128 ++ ++#define IOCTL_LCD_CONTRAST 1 ++ ++/*** P R O T O T Y P E S ***/ ++ ++/* USB Callback prototypes */ ++static int sasem_probe(struct usb_interface *interface, ++ const struct usb_device_id *id); ++static void sasem_disconnect(struct usb_interface *interface); ++static void usb_rx_callback(struct urb *urb); ++static void usb_tx_callback(struct urb *urb); ++ ++/* VFD file_operations function prototypes */ ++static int vfd_open(struct inode *inode, struct file *file); ++static int vfd_ioctl(struct inode *inode, struct file *file, ++ unsigned cmd, unsigned long arg); ++static int vfd_close(struct inode *inode, struct file *file); ++static ssize_t vfd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos); ++ ++/* LIRC driver function prototypes */ ++static int ir_open(void *data); ++static void ir_close(void *data); ++ ++/* Driver init/exit prototypes */ ++static int __init sasem_init(void); ++static void __exit sasem_exit(void); ++ ++/*** G L O B A L S ***/ ++ ++struct sasem_context { ++ ++ struct usb_device *dev; ++ int vfd_isopen; /* VFD port has been opened */ ++ unsigned int vfd_contrast; /* VFD contrast */ ++ int ir_isopen; /* IR port has been opened */ ++ int dev_present; /* USB device presence */ ++ struct mutex ctx_lock; /* to lock this object */ ++ wait_queue_head_t remove_ok; /* For unexpected USB disconnects */ ++ ++ struct lirc_driver *driver; ++ struct usb_endpoint_descriptor *rx_endpoint; ++ struct usb_endpoint_descriptor *tx_endpoint; ++ struct urb *rx_urb; ++ struct urb *tx_urb; ++ unsigned char usb_rx_buf[8]; ++ unsigned char usb_tx_buf[8]; ++ ++ struct tx_t { ++ unsigned char data_buf[32]; /* user data buffer */ ++ struct completion finished; /* wait for write to finish */ ++ atomic_t busy; /* write in progress */ ++ int status; /* status of tx completion */ ++ } tx; ++ ++ /* for dealing with repeat codes (wish there was a toggle bit!) */ ++ struct timeval presstime; ++ char lastcode[8]; ++ int codesaved; ++}; ++ ++/* VFD file operations */ ++static struct file_operations vfd_fops = { ++ .owner = THIS_MODULE, ++ .open = &vfd_open, ++ .write = &vfd_write, ++ .ioctl = &vfd_ioctl, ++ .release = &vfd_close, ++}; ++ ++/* USB Device ID for Sasem USB Control Board */ ++static struct usb_device_id sasem_usb_id_table[] = { ++ /* Sasem USB Control Board */ ++ { USB_DEVICE(0x11ba, 0x0101) }, ++ /* Terminating entry */ ++ {} ++}; ++ ++/* USB Device data */ ++static struct usb_driver sasem_driver = { ++ .name = MOD_NAME, ++ .probe = sasem_probe, ++ .disconnect = sasem_disconnect, ++ .id_table = sasem_usb_id_table, ++}; ++ ++static struct usb_class_driver sasem_class = { ++ .name = DEVICE_NAME, ++ .fops = &vfd_fops, ++ .minor_base = VFD_MINOR_BASE, ++}; ++ ++/* to prevent races between open() and disconnect() */ ++static DEFINE_MUTEX(disconnect_lock); ++ ++static int debug; ++ ++ ++/*** M O D U L E C O D E ***/ ++ ++MODULE_AUTHOR(MOD_AUTHOR); ++MODULE_DESCRIPTION(MOD_DESC); ++MODULE_LICENSE("GPL"); ++module_param(debug, int, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes (default: no)"); ++ ++static void delete_context(struct sasem_context *context) ++{ ++ usb_free_urb(context->tx_urb); /* VFD */ ++ usb_free_urb(context->rx_urb); /* IR */ ++ lirc_buffer_free(context->driver->rbuf); ++ kfree(context->driver->rbuf); ++ kfree(context->driver); ++ kfree(context); ++ ++ if (debug) ++ printk(KERN_INFO "%s: context deleted\n", __func__); ++} ++ ++static void deregister_from_lirc(struct sasem_context *context) ++{ ++ int retval; ++ int minor = context->driver->minor; ++ ++ retval = lirc_unregister_driver(minor); ++ if (retval) ++ err("%s: unable to deregister from lirc (%d)", ++ __func__, retval); ++ else ++ printk(KERN_INFO "Deregistered Sasem driver (minor:%d)\n", ++ minor); ++ ++} ++ ++/** ++ * Called when the VFD device (e.g. /dev/usb/lcd) ++ * is opened by the application. ++ */ ++static int vfd_open(struct inode *inode, struct file *file) ++{ ++ struct usb_interface *interface; ++ struct sasem_context *context = NULL; ++ int subminor; ++ int retval = 0; ++ ++ /* prevent races with disconnect */ ++ mutex_lock(&disconnect_lock); ++ ++ subminor = iminor(inode); ++ interface = usb_find_interface(&sasem_driver, subminor); ++ if (!interface) { ++ err("%s: could not find interface for minor %d", ++ __func__, subminor); ++ retval = -ENODEV; ++ goto exit; ++ } ++ context = usb_get_intfdata(interface); ++ ++ if (!context) { ++ err("%s: no context found for minor %d", ++ __func__, subminor); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (context->vfd_isopen) { ++ err("%s: VFD port is already open", __func__); ++ retval = -EBUSY; ++ } else { ++ context->vfd_isopen = 1; ++ file->private_data = context; ++ printk(KERN_INFO "VFD port opened\n"); ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ ++exit: ++ mutex_unlock(&disconnect_lock); ++ return retval; ++} ++ ++/** ++ * Called when the VFD device (e.g. /dev/usb/lcd) ++ * is closed by the application. ++ */ ++static int vfd_ioctl(struct inode *inode, struct file *file, ++ unsigned cmd, unsigned long arg) ++{ ++ struct sasem_context *context = NULL; ++ ++ context = (struct sasem_context *) file->private_data; ++ ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ switch (cmd) { ++ case IOCTL_LCD_CONTRAST: ++ if (arg > 1000) ++ arg = 1000; ++ context->vfd_contrast = (unsigned int)arg; ++ break; ++ default: ++ printk(KERN_INFO "Unknown IOCTL command\n"); ++ mutex_unlock(&context->ctx_lock); ++ return -ENOIOCTLCMD; /* not supported */ ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ return 0; ++} ++ ++/** ++ * Called when the VFD device (e.g. /dev/usb/lcd) ++ * is closed by the application. ++ */ ++static int vfd_close(struct inode *inode, struct file *file) ++{ ++ struct sasem_context *context = NULL; ++ int retval = 0; ++ ++ context = (struct sasem_context *) file->private_data; ++ ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (!context->vfd_isopen) { ++ err("%s: VFD is not open", __func__); ++ retval = -EIO; ++ } else { ++ context->vfd_isopen = 0; ++ printk(KERN_INFO "VFD port closed\n"); ++ if (!context->dev_present && !context->ir_isopen) { ++ ++ /* Device disconnected before close and IR port is ++ * not open. If IR port is open, context will be ++ * deleted by ir_close. */ ++ mutex_unlock(&context->ctx_lock); ++ delete_context(context); ++ return retval; ++ } ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ return retval; ++} ++ ++/** ++ * Sends a packet to the VFD. ++ */ ++static int send_packet(struct sasem_context *context) ++{ ++ unsigned int pipe; ++ int interval = 0; ++ int retval = 0; ++ ++ pipe = usb_sndintpipe(context->dev, ++ context->tx_endpoint->bEndpointAddress); ++ interval = context->tx_endpoint->bInterval; ++ ++ usb_fill_int_urb(context->tx_urb, context->dev, pipe, ++ context->usb_tx_buf, sizeof(context->usb_tx_buf), ++ usb_tx_callback, context, interval); ++ ++ context->tx_urb->actual_length = 0; ++ ++ init_completion(&context->tx.finished); ++ atomic_set(&(context->tx.busy), 1); ++ ++ retval = usb_submit_urb(context->tx_urb, GFP_KERNEL); ++ if (retval) { ++ atomic_set(&(context->tx.busy), 0); ++ err("%s: error submitting urb (%d)", __func__, retval); ++ } else { ++ /* Wait for transmission to complete (or abort) */ ++ mutex_unlock(&context->ctx_lock); ++ wait_for_completion(&context->tx.finished); ++ mutex_lock(&context->ctx_lock); ++ ++ retval = context->tx.status; ++ if (retval) ++ err("%s: packet tx failed (%d)", __func__, retval); ++ } ++ ++ return retval; ++} ++ ++/** ++ * Writes data to the VFD. The Sasem VFD is 2x16 characters ++ * and requires data in 9 consecutive USB interrupt packets, ++ * each packet carrying 8 bytes. ++ */ ++static ssize_t vfd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos) ++{ ++ int i; ++ int retval = 0; ++ struct sasem_context *context; ++ ++ context = (struct sasem_context *) file->private_data; ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (!context->dev_present) { ++ err("%s: no Sasem device present", __func__); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ if (n_bytes <= 0 || n_bytes > 32) { ++ err("%s: invalid payload size", __func__); ++ retval = -EINVAL; ++ goto exit; ++ } ++ ++ retval = copy_from_user(context->tx.data_buf, buf, n_bytes); ++ if (retval < 0) ++ goto exit; ++ ++ /* Pad with spaces */ ++ for (i = n_bytes; i < 32; ++i) ++ context->tx.data_buf[i] = ' '; ++ ++ /* Nine 8 byte packets to be sent */ ++ /* NOTE: "\x07\x01\0\0\0\0\0\0" or "\x0c\0\0\0\0\0\0\0" ++ * will clear the VFD */ ++ for (i = 0; i < 9; i++) { ++ switch (i) { ++ case 0: ++ memcpy(context->usb_tx_buf, "\x07\0\0\0\0\0\0\0", 8); ++ context->usb_tx_buf[1] = (context->vfd_contrast) ? ++ (0x2B - (context->vfd_contrast - 1) / 250) ++ : 0x2B; ++ break; ++ case 1: ++ memcpy(context->usb_tx_buf, "\x09\x01\0\0\0\0\0\0", 8); ++ break; ++ case 2: ++ memcpy(context->usb_tx_buf, "\x0b\x01\0\0\0\0\0\0", 8); ++ break; ++ case 3: ++ memcpy(context->usb_tx_buf, context->tx.data_buf, 8); ++ break; ++ case 4: ++ memcpy(context->usb_tx_buf, ++ context->tx.data_buf + 8, 8); ++ break; ++ case 5: ++ memcpy(context->usb_tx_buf, "\x09\x01\0\0\0\0\0\0", 8); ++ break; ++ case 6: ++ memcpy(context->usb_tx_buf, "\x0b\x02\0\0\0\0\0\0", 8); ++ break; ++ case 7: ++ memcpy(context->usb_tx_buf, ++ context->tx.data_buf + 16, 8); ++ break; ++ case 8: ++ memcpy(context->usb_tx_buf, ++ context->tx.data_buf + 24, 8); ++ break; ++ } ++ retval = send_packet(context); ++ if (retval) { ++ ++ err("%s: send packet failed for packet #%d", ++ __func__, i); ++ goto exit; ++ } ++ } ++exit: ++ ++ mutex_unlock(&context->ctx_lock); ++ ++ return (!retval) ? n_bytes : retval; ++} ++ ++/** ++ * Callback function for USB core API: transmit data ++ */ ++static void usb_tx_callback(struct urb *urb) ++{ ++ struct sasem_context *context; ++ ++ if (!urb) ++ return; ++ context = (struct sasem_context *) urb->context; ++ if (!context) ++ return; ++ ++ context->tx.status = urb->status; ++ ++ /* notify waiters that write has finished */ ++ atomic_set(&context->tx.busy, 0); ++ complete(&context->tx.finished); ++ ++ return; ++} ++ ++/** ++ * Called by lirc_dev when the application opens /dev/lirc ++ */ ++static int ir_open(void *data) ++{ ++ int retval = 0; ++ struct sasem_context *context; ++ ++ /* prevent races with disconnect */ ++ mutex_lock(&disconnect_lock); ++ ++ context = (struct sasem_context *) data; ++ ++ mutex_lock(&context->ctx_lock); ++ ++ if (context->ir_isopen) { ++ err("%s: IR port is already open", __func__); ++ retval = -EBUSY; ++ goto exit; ++ } ++ ++ usb_fill_int_urb(context->rx_urb, context->dev, ++ usb_rcvintpipe(context->dev, ++ context->rx_endpoint->bEndpointAddress), ++ context->usb_rx_buf, sizeof(context->usb_rx_buf), ++ usb_rx_callback, context, context->rx_endpoint->bInterval); ++ ++ retval = usb_submit_urb(context->rx_urb, GFP_KERNEL); ++ ++ if (retval) ++ err("%s: usb_submit_urb failed for ir_open (%d)", ++ __func__, retval); ++ else { ++ context->ir_isopen = 1; ++ printk(KERN_INFO "IR port opened\n"); ++ } ++ ++exit: ++ mutex_unlock(&context->ctx_lock); ++ ++ mutex_unlock(&disconnect_lock); ++ return 0; ++} ++ ++/** ++ * Called by lirc_dev when the application closes /dev/lirc ++ */ ++static void ir_close(void *data) ++{ ++ struct sasem_context *context; ++ ++ context = (struct sasem_context *)data; ++ if (!context) { ++ err("%s: no context for device", __func__); ++ return; ++ } ++ ++ mutex_lock(&context->ctx_lock); ++ ++ usb_kill_urb(context->rx_urb); ++ context->ir_isopen = 0; ++ printk(KERN_INFO "IR port closed\n"); ++ ++ if (!context->dev_present) { ++ ++ /* ++ * Device disconnected while IR port was ++ * still open. Driver was not deregistered ++ * at disconnect time, so do it now. ++ */ ++ deregister_from_lirc(context); ++ ++ if (!context->vfd_isopen) { ++ ++ mutex_unlock(&context->ctx_lock); ++ delete_context(context); ++ return; ++ } ++ /* If VFD port is open, context will be deleted by vfd_close */ ++ } ++ ++ mutex_unlock(&context->ctx_lock); ++ return; ++} ++ ++/** ++ * Process the incoming packet ++ */ ++static void incoming_packet(struct sasem_context *context, ++ struct urb *urb) ++{ ++ int len = urb->actual_length; ++ unsigned char *buf = urb->transfer_buffer; ++ long ms; ++ struct timeval tv; ++ ++ if (len != 8) { ++ printk(KERN_WARNING "%s: invalid incoming packet size (%d)\n", ++ __func__, len); ++ return; ++ } ++ ++#ifdef DEBUG ++ int i; ++ for (i = 0; i < 8; ++i) ++ printk(KERN_INFO "%02x ", buf[i]); ++ printk(KERN_INFO "\n"); ++#endif ++ ++ /* ++ * Lirc could deal with the repeat code, but we really need to block it ++ * if it arrives too late. Otherwise we could repeat the wrong code. ++ */ ++ ++ /* get the time since the last button press */ ++ do_gettimeofday(&tv); ++ ms = (tv.tv_sec - context->presstime.tv_sec) * 1000 + ++ (tv.tv_usec - context->presstime.tv_usec) / 1000; ++ ++ if (memcmp(buf, "\x08\0\0\0\0\0\0\0", 8) == 0) { ++ /* ++ * the repeat code is being sent, so we copy ++ * the old code to LIRC ++ */ ++ ++ /* ++ * NOTE: Only if the last code was less than 250ms ago ++ * - no one should be able to push another (undetected) button ++ * in that time and then get a false repeat of the previous ++ * press but it is long enough for a genuine repeat ++ */ ++ if ((ms < 250) && (context->codesaved != 0)) { ++ memcpy(buf, &context->lastcode, 8); ++ context->presstime.tv_sec = tv.tv_sec; ++ context->presstime.tv_usec = tv.tv_usec; ++ } ++ } else { ++ /* save the current valid code for repeats */ ++ memcpy(&context->lastcode, buf, 8); ++ /* ++ * set flag to signal a valid code was save; ++ * just for safety reasons ++ */ ++ context->codesaved = 1; ++ context->presstime.tv_sec = tv.tv_sec; ++ context->presstime.tv_usec = tv.tv_usec; ++ } ++ ++ lirc_buffer_write(context->driver->rbuf, buf); ++ wake_up(&context->driver->rbuf->wait_poll); ++} ++ ++/** ++ * Callback function for USB core API: receive data ++ */ ++static void usb_rx_callback(struct urb *urb) ++{ ++ struct sasem_context *context; ++ ++ if (!urb) ++ return; ++ context = (struct sasem_context *) urb->context; ++ if (!context) ++ return; ++ ++ switch (urb->status) { ++ ++ case -ENOENT: /* usbcore unlink successful! */ ++ return; ++ ++ case 0: ++ if (context->ir_isopen) ++ incoming_packet(context, urb); ++ break; ++ ++ default: ++ printk(KERN_WARNING "%s: status (%d): ignored", ++ __func__, urb->status); ++ break; ++ } ++ ++ usb_submit_urb(context->rx_urb, GFP_ATOMIC); ++ return; ++} ++ ++ ++ ++/** ++ * Callback function for USB core API: Probe ++ */ ++static int sasem_probe(struct usb_interface *interface, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *dev = NULL; ++ struct usb_host_interface *iface_desc = NULL; ++ struct usb_endpoint_descriptor *rx_endpoint = NULL; ++ struct usb_endpoint_descriptor *tx_endpoint = NULL; ++ struct urb *rx_urb = NULL; ++ struct urb *tx_urb = NULL; ++ struct lirc_driver *driver = NULL; ++ struct lirc_buffer *rbuf = NULL; ++ int lirc_minor = 0; ++ int num_endpoints; ++ int retval = 0; ++ int vfd_ep_found; ++ int ir_ep_found; ++ int alloc_status; ++ struct sasem_context *context = NULL; ++ int i; ++ ++ printk(KERN_INFO "%s: found Sasem device\n", __func__); ++ ++ ++ dev = usb_get_dev(interface_to_usbdev(interface)); ++ iface_desc = interface->cur_altsetting; ++ num_endpoints = iface_desc->desc.bNumEndpoints; ++ ++ /* ++ * Scan the endpoint list and set: ++ * first input endpoint = IR endpoint ++ * first output endpoint = VFD endpoint ++ */ ++ ++ ir_ep_found = 0; ++ vfd_ep_found = 0; ++ ++ for (i = 0; i < num_endpoints && !(ir_ep_found && vfd_ep_found); ++i) { ++ ++ struct usb_endpoint_descriptor *ep; ++ int ep_dir; ++ int ep_type; ++ ep = &iface_desc->endpoint [i].desc; ++ ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK; ++ ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; ++ ++ if (!ir_ep_found && ++ ep_dir == USB_DIR_IN && ++ ep_type == USB_ENDPOINT_XFER_INT) { ++ ++ rx_endpoint = ep; ++ ir_ep_found = 1; ++ if (debug) ++ printk(KERN_INFO "%s: found IR endpoint\n", ++ __func__); ++ ++ } else if (!vfd_ep_found && ++ ep_dir == USB_DIR_OUT && ++ ep_type == USB_ENDPOINT_XFER_INT) { ++ ++ tx_endpoint = ep; ++ vfd_ep_found = 1; ++ if (debug) ++ printk(KERN_INFO "%s: found VFD endpoint\n", ++ __func__); ++ } ++ } ++ ++ /* Input endpoint is mandatory */ ++ if (!ir_ep_found) { ++ ++ err("%s: no valid input (IR) endpoint found.", __func__); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ if (!vfd_ep_found) ++ printk(KERN_INFO "%s: no valid output (VFD) endpoint found.\n", ++ __func__); ++ ++ ++ /* Allocate memory */ ++ alloc_status = 0; ++ ++ context = kzalloc(sizeof(struct sasem_context), GFP_KERNEL); ++ if (!context) { ++ err("%s: kzalloc failed for context", __func__); ++ alloc_status = 1; ++ goto alloc_status_switch; ++ } ++ driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); ++ if (!driver) { ++ err("%s: kzalloc failed for lirc_driver", __func__); ++ alloc_status = 2; ++ goto alloc_status_switch; ++ } ++ rbuf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!rbuf) { ++ err("%s: kmalloc failed for lirc_buffer", __func__); ++ alloc_status = 3; ++ goto alloc_status_switch; ++ } ++ if (lirc_buffer_init(rbuf, BUF_CHUNK_SIZE, BUF_SIZE)) { ++ err("%s: lirc_buffer_init failed", __func__); ++ alloc_status = 4; ++ goto alloc_status_switch; ++ } ++ rx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!rx_urb) { ++ err("%s: usb_alloc_urb failed for IR urb", __func__); ++ alloc_status = 5; ++ goto alloc_status_switch; ++ } ++ if (vfd_ep_found) { ++ tx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!tx_urb) { ++ err("%s: usb_alloc_urb failed for VFD urb", ++ __func__); ++ alloc_status = 6; ++ goto alloc_status_switch; ++ } ++ } ++ ++ mutex_init(&context->ctx_lock); ++ ++ strcpy(driver->name, MOD_NAME); ++ driver->minor = -1; ++ driver->code_length = 64; ++ driver->sample_rate = 0; ++ driver->features = LIRC_CAN_REC_LIRCCODE; ++ driver->data = context; ++ driver->rbuf = rbuf; ++ driver->set_use_inc = ir_open; ++ driver->set_use_dec = ir_close; ++ driver->dev = &interface->dev; ++ driver->owner = THIS_MODULE; ++ ++ mutex_lock(&context->ctx_lock); ++ ++ lirc_minor = lirc_register_driver(driver); ++ if (lirc_minor < 0) { ++ err("%s: lirc_register_driver failed", __func__); ++ alloc_status = 7; ++ mutex_unlock(&context->ctx_lock); ++ } else ++ printk(KERN_INFO "%s: Registered Sasem driver (minor:%d)\n", ++ __func__, lirc_minor); ++ ++alloc_status_switch: ++ ++ switch (alloc_status) { ++ ++ case 7: ++ if (vfd_ep_found) ++ usb_free_urb(tx_urb); ++ case 6: ++ usb_free_urb(rx_urb); ++ case 5: ++ lirc_buffer_free(rbuf); ++ case 4: ++ kfree(rbuf); ++ case 3: ++ kfree(driver); ++ case 2: ++ kfree(context); ++ context = NULL; ++ case 1: ++ retval = -ENOMEM; ++ goto exit; ++ } ++ ++ /* Needed while unregistering! */ ++ driver->minor = lirc_minor; ++ ++ context->dev = dev; ++ context->dev_present = 1; ++ context->rx_endpoint = rx_endpoint; ++ context->rx_urb = rx_urb; ++ if (vfd_ep_found) { ++ context->tx_endpoint = tx_endpoint; ++ context->tx_urb = tx_urb; ++ context->vfd_contrast = 1000; /* range 0 - 1000 */ ++ } ++ context->driver = driver; ++ ++ usb_set_intfdata(interface, context); ++ ++ if (vfd_ep_found) { ++ ++ if (debug) ++ printk(KERN_INFO "Registering VFD with sysfs\n"); ++ if (usb_register_dev(interface, &sasem_class)) ++ /* Not a fatal error, so ignore */ ++ printk(KERN_INFO "%s: could not get a minor number " ++ "for VFD\n", __func__); ++ } ++ ++ printk(KERN_INFO "%s: Sasem device on usb<%d:%d> initialized\n", ++ __func__, dev->bus->busnum, dev->devnum); ++ ++ mutex_unlock(&context->ctx_lock); ++exit: ++ return retval; ++} ++ ++/** ++ * Callback function for USB core API: disonnect ++ */ ++static void sasem_disconnect(struct usb_interface *interface) ++{ ++ struct sasem_context *context; ++ ++ /* prevent races with ir_open()/vfd_open() */ ++ mutex_lock(&disconnect_lock); ++ ++ context = usb_get_intfdata(interface); ++ mutex_lock(&context->ctx_lock); ++ ++ printk(KERN_INFO "%s: Sasem device disconnected\n", __func__); ++ ++ usb_set_intfdata(interface, NULL); ++ context->dev_present = 0; ++ ++ /* Stop reception */ ++ usb_kill_urb(context->rx_urb); ++ ++ /* Abort ongoing write */ ++ if (atomic_read(&context->tx.busy)) { ++ ++ usb_kill_urb(context->tx_urb); ++ wait_for_completion(&context->tx.finished); ++ } ++ ++ /* De-register from lirc_dev if IR port is not open */ ++ if (!context->ir_isopen) ++ deregister_from_lirc(context); ++ ++ usb_deregister_dev(interface, &sasem_class); ++ ++ mutex_unlock(&context->ctx_lock); ++ ++ if (!context->ir_isopen && !context->vfd_isopen) ++ delete_context(context); ++ ++ mutex_unlock(&disconnect_lock); ++} ++ ++static int __init sasem_init(void) ++{ ++ int rc; ++ ++ printk(KERN_INFO MOD_DESC ", v" MOD_VERSION "\n"); ++ printk(KERN_INFO MOD_AUTHOR "\n"); ++ ++ rc = usb_register(&sasem_driver); ++ if (rc < 0) { ++ err("%s: usb register failed (%d)", __func__, rc); ++ return -ENODEV; ++ } ++ return 0; ++} ++ ++static void __exit sasem_exit(void) ++{ ++ usb_deregister(&sasem_driver); ++ printk(KERN_INFO "module removed. Goodbye!\n"); ++} ++ ++ ++module_init(sasem_init); ++module_exit(sasem_exit); +diff --git a/drivers/input/lirc/lirc_serial.c b/drivers/input/lirc/lirc_serial.c +new file mode 100644 +index 0000000..f4fcc37 +--- /dev/null ++++ b/drivers/input/lirc/lirc_serial.c +@@ -0,0 +1,1317 @@ ++/* ++ * lirc_serial.c ++ * ++ * lirc_serial - Device driver that records pulse- and pause-lengths ++ * (space-lengths) between DDCD event on a serial port. ++ * ++ * Copyright (C) 1996,97 Ralph Metzler ++ * Copyright (C) 1998 Trent Piepho ++ * Copyright (C) 1998 Ben Pfaff ++ * Copyright (C) 1999 Christoph Bartelmus ++ * Copyright (C) 2007 Andrei Tanas (suspend/resume support) ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++/* ++ * Steve's changes to improve transmission fidelity: ++ * - for systems with the rdtsc instruction and the clock counter, a ++ * send_pule that times the pulses directly using the counter. ++ * This means that the LIRC_SERIAL_TRANSMITTER_LATENCY fudge is ++ * not needed. Measurement shows very stable waveform, even where ++ * PCI activity slows the access to the UART, which trips up other ++ * versions. ++ * - For other system, non-integer-microsecond pulse/space lengths, ++ * done using fixed point binary. So, much more accurate carrier ++ * frequency. ++ * - fine tuned transmitter latency, taking advantage of fractional ++ * microseconds in previous change ++ * - Fixed bug in the way transmitter latency was accounted for by ++ * tuning the pulse lengths down - the send_pulse routine ignored ++ * this overhead as it timed the overall pulse length - so the ++ * pulse frequency was right but overall pulse length was too ++ * long. Fixed by accounting for latency on each pulse/space ++ * iteration. ++ * ++ * Steve Davies July 2001 ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++#include ++ ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++#include ++#endif ++/* From Intel IXP42X Developer's Manual (#252480-005): */ ++/* ftp://download.intel.com/design/network/manuals/25248005.pdf */ ++#define UART_IE_IXP42X_UUE 0x40 /* IXP42X UART Unit enable */ ++#define UART_IE_IXP42X_RTOIE 0x10 /* IXP42X Receiver Data Timeout int.enable */ ++ ++#include ++#include "lirc_dev.h" ++ ++#define LIRC_DRIVER_NAME "lirc_serial" ++ ++struct lirc_serial { ++ int signal_pin; ++ int signal_pin_change; ++ u8 on; ++ u8 off; ++ long (*send_pulse)(unsigned long length); ++ void (*send_space)(long length); ++ int features; ++ spinlock_t lock; ++}; ++ ++#define LIRC_HOMEBREW 0 ++#define LIRC_IRDEO 1 ++#define LIRC_IRDEO_REMOTE 2 ++#define LIRC_ANIMAX 3 ++#define LIRC_IGOR 4 ++#define LIRC_NSLU2 5 ++ ++/*** module parameters ***/ ++static int type; ++static int io; ++static int irq; ++static int iommap; ++static int ioshift; ++static int softcarrier = 1; ++static int share_irq; ++static int debug; ++static int sense = -1; /* -1 = auto, 0 = active high, 1 = active low */ ++static int txsense; /* 0 = active high, 1 = active low */ ++ ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \ ++ fmt, ## args); \ ++ } while (0) ++ ++/* forward declarations */ ++static long send_pulse_irdeo(unsigned long length); ++static long send_pulse_homebrew(unsigned long length); ++static void send_space_irdeo(long length); ++static void send_space_homebrew(long length); ++ ++static struct lirc_serial hardware[] = { ++ [LIRC_HOMEBREW] = { ++ .signal_pin = UART_MSR_DCD, ++ .signal_pin_change = UART_MSR_DDCD, ++ .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR), ++ .off = (UART_MCR_RTS | UART_MCR_OUT2), ++ .send_pulse = send_pulse_homebrew, ++ .send_space = send_space_homebrew, ++#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER ++ .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE | ++ LIRC_CAN_SET_SEND_CARRIER | ++ LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2) ++#else ++ .features = LIRC_CAN_REC_MODE2 ++#endif ++ }, ++ ++ [LIRC_IRDEO] = { ++ .signal_pin = UART_MSR_DSR, ++ .signal_pin_change = UART_MSR_DDSR, ++ .on = UART_MCR_OUT2, ++ .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2), ++ .send_pulse = send_pulse_irdeo, ++ .send_space = send_space_irdeo, ++ .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE | ++ LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2) ++ }, ++ ++ [LIRC_IRDEO_REMOTE] = { ++ .signal_pin = UART_MSR_DSR, ++ .signal_pin_change = UART_MSR_DDSR, ++ .on = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2), ++ .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2), ++ .send_pulse = send_pulse_irdeo, ++ .send_space = send_space_irdeo, ++ .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE | ++ LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2) ++ }, ++ ++ [LIRC_ANIMAX] = { ++ .signal_pin = UART_MSR_DCD, ++ .signal_pin_change = UART_MSR_DDCD, ++ .on = 0, ++ .off = (UART_MCR_RTS | UART_MCR_DTR | UART_MCR_OUT2), ++ .send_pulse = NULL, ++ .send_space = NULL, ++ .features = LIRC_CAN_REC_MODE2 ++ }, ++ ++ [LIRC_IGOR] = { ++ .signal_pin = UART_MSR_DSR, ++ .signal_pin_change = UART_MSR_DDSR, ++ .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR), ++ .off = (UART_MCR_RTS | UART_MCR_OUT2), ++ .send_pulse = send_pulse_homebrew, ++ .send_space = send_space_homebrew, ++#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER ++ .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE | ++ LIRC_CAN_SET_SEND_CARRIER | ++ LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2) ++#else ++ .features = LIRC_CAN_REC_MODE2 ++#endif ++ }, ++ ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++ /* ++ * Modified Linksys Network Storage Link USB 2.0 (NSLU2): ++ * We receive on CTS of the 2nd serial port (R142,LHS), we ++ * transmit with a IR diode between GPIO[1] (green status LED), ++ * and ground (Matthias Goebl ). ++ * See also http://www.nslu2-linux.org for this device ++ */ ++ [LIRC_NSLU2] = { ++ .signal_pin = UART_MSR_CTS, ++ .signal_pin_change = UART_MSR_DCTS, ++ .on = (UART_MCR_RTS | UART_MCR_OUT2 | UART_MCR_DTR), ++ .off = (UART_MCR_RTS | UART_MCR_OUT2), ++ .send_pulse = send_pulse_homebrew, ++ .send_space = send_space_homebrew, ++#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER ++ .features = (LIRC_CAN_SET_SEND_DUTY_CYCLE | ++ LIRC_CAN_SET_SEND_CARRIER | ++ LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2) ++#else ++ .features = LIRC_CAN_REC_MODE2 ++#endif ++ }, ++#endif ++ ++}; ++ ++#define RS_ISR_PASS_LIMIT 256 ++ ++/* ++ * A long pulse code from a remote might take up to 300 bytes. The ++ * daemon should read the bytes as soon as they are generated, so take ++ * the number of keys you think you can push before the daemon runs ++ * and multiply by 300. The driver will warn you if you overrun this ++ * buffer. If you have a slow computer or non-busmastering IDE disks, ++ * maybe you will need to increase this. ++ */ ++ ++/* This MUST be a power of two! It has to be larger than 1 as well. */ ++ ++#define RBUF_LEN 256 ++#define WBUF_LEN 256 ++ ++static struct timeval lasttv = {0, 0}; ++ ++static struct lirc_buffer rbuf; ++ ++static int wbuf[WBUF_LEN]; ++ ++static unsigned int freq = 38000; ++static unsigned int duty_cycle = 50; ++ ++/* Initialized in init_timing_params() */ ++static unsigned long period; ++static unsigned long pulse_width; ++static unsigned long space_width; ++ ++#if defined(__i386__) ++/* ++ * From: ++ * Linux I/O port programming mini-HOWTO ++ * Author: Riku Saikkonen ++ * v, 28 December 1997 ++ * ++ * [...] ++ * Actually, a port I/O instruction on most ports in the 0-0x3ff range ++ * takes almost exactly 1 microsecond, so if you're, for example, using ++ * the parallel port directly, just do additional inb()s from that port ++ * to delay. ++ * [...] ++ */ ++/* transmitter latency 1.5625us 0x1.90 - this figure arrived at from ++ * comment above plus trimming to match actual measured frequency. ++ * This will be sensitive to cpu speed, though hopefully most of the 1.5us ++ * is spent in the uart access. Still - for reference test machine was a ++ * 1.13GHz Athlon system - Steve ++ */ ++ ++/* ++ * changed from 400 to 450 as this works better on slower machines; ++ * faster machines will use the rdtsc code anyway ++ */ ++#define LIRC_SERIAL_TRANSMITTER_LATENCY 450 ++ ++#else ++ ++/* does anybody have information on other platforms ? */ ++/* 256 = 1<<8 */ ++#define LIRC_SERIAL_TRANSMITTER_LATENCY 256 ++ ++#endif /* __i386__ */ ++/* ++ * FIXME: should we be using hrtimers instead of this ++ * LIRC_SERIAL_TRANSMITTER_LATENCY nonsense? ++ */ ++ ++/* fetch serial input packet (1 byte) from register offset */ ++static u8 sinp(int offset) ++{ ++ if (iommap != 0) ++ /* the register is memory-mapped */ ++ offset <<= ioshift; ++ ++ return inb(io + offset); ++} ++ ++/* write serial output packet (1 byte) of value to register offset */ ++static void soutp(int offset, u8 value) ++{ ++ if (iommap != 0) ++ /* the register is memory-mapped */ ++ offset <<= ioshift; ++ ++ outb(value, io + offset); ++} ++ ++static void on(void) ++{ ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++ /* ++ * On NSLU2, we put the transmit diode between the output of the green ++ * status LED and ground ++ */ ++ if (type == LIRC_NSLU2) { ++ gpio_line_set(NSLU2_LED_GRN, IXP4XX_GPIO_LOW); ++ return; ++ } ++#endif ++ if (txsense) ++ soutp(UART_MCR, hardware[type].off); ++ else ++ soutp(UART_MCR, hardware[type].on); ++} ++ ++static void off(void) ++{ ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++ if (type == LIRC_NSLU2) { ++ gpio_line_set(NSLU2_LED_GRN, IXP4XX_GPIO_HIGH); ++ return; ++ } ++#endif ++ if (txsense) ++ soutp(UART_MCR, hardware[type].on); ++ else ++ soutp(UART_MCR, hardware[type].off); ++} ++ ++#ifndef MAX_UDELAY_MS ++#define MAX_UDELAY_US 5000 ++#else ++#define MAX_UDELAY_US (MAX_UDELAY_MS*1000) ++#endif ++ ++static void safe_udelay(unsigned long usecs) ++{ ++ while (usecs > MAX_UDELAY_US) { ++ udelay(MAX_UDELAY_US); ++ usecs -= MAX_UDELAY_US; ++ } ++ udelay(usecs); ++} ++ ++#ifdef USE_RDTSC ++/* ++ * This is an overflow/precision juggle, complicated in that we can't ++ * do long long divide in the kernel ++ */ ++ ++/* ++ * When we use the rdtsc instruction to measure clocks, we keep the ++ * pulse and space widths as clock cycles. As this is CPU speed ++ * dependent, the widths must be calculated in init_port and ioctl ++ * time ++ */ ++ ++/* So send_pulse can quickly convert microseconds to clocks */ ++static unsigned long conv_us_to_clocks; ++ ++static int init_timing_params(unsigned int new_duty_cycle, ++ unsigned int new_freq) ++{ ++ unsigned long long loops_per_sec, work; ++ ++ duty_cycle = new_duty_cycle; ++ freq = new_freq; ++ ++ loops_per_sec = current_cpu_data.loops_per_jiffy; ++ loops_per_sec *= HZ; ++ ++ /* How many clocks in a microsecond?, avoiding long long divide */ ++ work = loops_per_sec; ++ work *= 4295; /* 4295 = 2^32 / 1e6 */ ++ conv_us_to_clocks = (work >> 32); ++ ++ /* ++ * Carrier period in clocks, approach good up to 32GHz clock, ++ * gets carrier frequency within 8Hz ++ */ ++ period = loops_per_sec >> 3; ++ period /= (freq >> 3); ++ ++ /* Derive pulse and space from the period */ ++ pulse_width = period * duty_cycle / 100; ++ space_width = period - pulse_width; ++ dprintk("in init_timing_params, freq=%d, duty_cycle=%d, " ++ "clk/jiffy=%ld, pulse=%ld, space=%ld, " ++ "conv_us_to_clocks=%ld\n", ++ freq, duty_cycle, current_cpu_data.loops_per_jiffy, ++ pulse_width, space_width, conv_us_to_clocks); ++ return 0; ++} ++#else /* ! USE_RDTSC */ ++static int init_timing_params(unsigned int new_duty_cycle, ++ unsigned int new_freq) ++{ ++/* ++ * period, pulse/space width are kept with 8 binary places - ++ * IE multiplied by 256. ++ */ ++ if (256 * 1000000L / new_freq * new_duty_cycle / 100 <= ++ LIRC_SERIAL_TRANSMITTER_LATENCY) ++ return -EINVAL; ++ if (256 * 1000000L / new_freq * (100 - new_duty_cycle) / 100 <= ++ LIRC_SERIAL_TRANSMITTER_LATENCY) ++ return -EINVAL; ++ duty_cycle = new_duty_cycle; ++ freq = new_freq; ++ period = 256 * 1000000L / freq; ++ pulse_width = period * duty_cycle / 100; ++ space_width = period - pulse_width; ++ dprintk("in init_timing_params, freq=%d pulse=%ld, " ++ "space=%ld\n", freq, pulse_width, space_width); ++ return 0; ++} ++#endif /* USE_RDTSC */ ++ ++ ++/* return value: space length delta */ ++ ++static long send_pulse_irdeo(unsigned long length) ++{ ++ long rawbits, ret; ++ int i; ++ unsigned char output; ++ unsigned char chunk, shifted; ++ ++ /* how many bits have to be sent ? */ ++ rawbits = length * 1152 / 10000; ++ if (duty_cycle > 50) ++ chunk = 3; ++ else ++ chunk = 1; ++ for (i = 0, output = 0x7f; rawbits > 0; rawbits -= 3) { ++ shifted = chunk << (i * 3); ++ shifted >>= 1; ++ output &= (~shifted); ++ i++; ++ if (i == 3) { ++ soutp(UART_TX, output); ++ while (!(sinp(UART_LSR) & UART_LSR_THRE)) ++ ; ++ output = 0x7f; ++ i = 0; ++ } ++ } ++ if (i != 0) { ++ soutp(UART_TX, output); ++ while (!(sinp(UART_LSR) & UART_LSR_TEMT)) ++ ; ++ } ++ ++ if (i == 0) ++ ret = (-rawbits) * 10000 / 1152; ++ else ++ ret = (3 - i) * 3 * 10000 / 1152 + (-rawbits) * 10000 / 1152; ++ ++ return ret; ++} ++ ++#ifdef USE_RDTSC ++/* Version that uses Pentium rdtsc instruction to measure clocks */ ++ ++/* ++ * This version does sub-microsecond timing using rdtsc instruction, ++ * and does away with the fudged LIRC_SERIAL_TRANSMITTER_LATENCY ++ * Implicitly i586 architecture... - Steve ++ */ ++ ++static long send_pulse_homebrew_softcarrier(unsigned long length) ++{ ++ int flag; ++ unsigned long target, start, now; ++ ++ /* Get going quick as we can */ ++ rdtscl(start); ++ on(); ++ /* Convert length from microseconds to clocks */ ++ length *= conv_us_to_clocks; ++ /* And loop till time is up - flipping at right intervals */ ++ now = start; ++ target = pulse_width; ++ flag = 1; ++ /* ++ * FIXME: This looks like a hard busy wait, without even an occasional, ++ * polite, cpu_relax() call. There's got to be a better way? ++ * ++ * The i2c code has the result of a lot of bit-banging work, I wonder if ++ * there's something there which could be helpful here. ++ */ ++ while ((now - start) < length) { ++ /* Delay till flip time */ ++ do { ++ rdtscl(now); ++ } while ((now - start) < target); ++ ++ /* flip */ ++ if (flag) { ++ rdtscl(now); ++ off(); ++ target += space_width; ++ } else { ++ rdtscl(now); on(); ++ target += pulse_width; ++ } ++ flag = !flag; ++ } ++ rdtscl(now); ++ return ((now - start) - length) / conv_us_to_clocks; ++} ++#else /* ! USE_RDTSC */ ++/* Version using udelay() */ ++ ++/* ++ * here we use fixed point arithmetic, with 8 ++ * fractional bits. that gets us within 0.1% or so of the right average ++ * frequency, albeit with some jitter in pulse length - Steve ++ */ ++ ++/* To match 8 fractional bits used for pulse/space length */ ++ ++static long send_pulse_homebrew_softcarrier(unsigned long length) ++{ ++ int flag; ++ unsigned long actual, target, d; ++ length <<= 8; ++ ++ actual = 0; target = 0; flag = 0; ++ while (actual < length) { ++ if (flag) { ++ off(); ++ target += space_width; ++ } else { ++ on(); ++ target += pulse_width; ++ } ++ d = (target - actual - ++ LIRC_SERIAL_TRANSMITTER_LATENCY + 128) >> 8; ++ /* ++ * Note - we've checked in ioctl that the pulse/space ++ * widths are big enough so that d is > 0 ++ */ ++ udelay(d); ++ actual += (d << 8) + LIRC_SERIAL_TRANSMITTER_LATENCY; ++ flag = !flag; ++ } ++ return (actual-length) >> 8; ++} ++#endif /* USE_RDTSC */ ++ ++static long send_pulse_homebrew(unsigned long length) ++{ ++ if (length <= 0) ++ return 0; ++ ++ if (softcarrier) ++ return send_pulse_homebrew_softcarrier(length); ++ else { ++ on(); ++ safe_udelay(length); ++ return 0; ++ } ++} ++ ++static void send_space_irdeo(long length) ++{ ++ if (length <= 0) ++ return; ++ ++ safe_udelay(length); ++} ++ ++static void send_space_homebrew(long length) ++{ ++ off(); ++ if (length <= 0) ++ return; ++ safe_udelay(length); ++} ++ ++static void rbwrite(int l) ++{ ++ if (lirc_buffer_full(&rbuf)) { ++ /* no new signals will be accepted */ ++ dprintk("Buffer overrun\n"); ++ return; ++ } ++ lirc_buffer_write(&rbuf, (void *)&l); ++} ++ ++static void frbwrite(int l) ++{ ++ /* simple noise filter */ ++ static int pulse, space; ++ static unsigned int ptr; ++ ++ if (ptr > 0 && (l & PULSE_BIT)) { ++ pulse += l & PULSE_MASK; ++ if (pulse > 250) { ++ rbwrite(space); ++ rbwrite(pulse | PULSE_BIT); ++ ptr = 0; ++ pulse = 0; ++ } ++ return; ++ } ++ if (!(l & PULSE_BIT)) { ++ if (ptr == 0) { ++ if (l > 20000) { ++ space = l; ++ ptr++; ++ return; ++ } ++ } else { ++ if (l > 20000) { ++ space += pulse; ++ if (space > PULSE_MASK) ++ space = PULSE_MASK; ++ space += l; ++ if (space > PULSE_MASK) ++ space = PULSE_MASK; ++ pulse = 0; ++ return; ++ } ++ rbwrite(space); ++ rbwrite(pulse | PULSE_BIT); ++ ptr = 0; ++ pulse = 0; ++ } ++ } ++ rbwrite(l); ++} ++ ++static irqreturn_t irq_handler(int i, void *blah) ++{ ++ struct timeval tv; ++ int counter, dcd; ++ u8 status; ++ long deltv; ++ int data; ++ static int last_dcd = -1; ++ ++ if ((sinp(UART_IIR) & UART_IIR_NO_INT)) { ++ /* not our interrupt */ ++ return IRQ_NONE; ++ } ++ ++ counter = 0; ++ do { ++ counter++; ++ status = sinp(UART_MSR); ++ if (counter > RS_ISR_PASS_LIMIT) { ++ printk(KERN_WARNING LIRC_DRIVER_NAME ": AIEEEE: " ++ "We're caught!\n"); ++ break; ++ } ++ if ((status & hardware[type].signal_pin_change) ++ && sense != -1) { ++ /* get current time */ ++ do_gettimeofday(&tv); ++ ++ /* New mode, written by Trent Piepho ++ . */ ++ ++ /* ++ * The old format was not very portable. ++ * We now use an int to pass pulses ++ * and spaces to user space. ++ * ++ * If PULSE_BIT is set a pulse has been ++ * received, otherwise a space has been ++ * received. The driver needs to know if your ++ * receiver is active high or active low, or ++ * the space/pulse sense could be ++ * inverted. The bits denoted by PULSE_MASK are ++ * the length in microseconds. Lengths greater ++ * than or equal to 16 seconds are clamped to ++ * PULSE_MASK. All other bits are unused. ++ * This is a much simpler interface for user ++ * programs, as well as eliminating "out of ++ * phase" errors with space/pulse ++ * autodetection. ++ */ ++ ++ /* calc time since last interrupt in microseconds */ ++ dcd = (status & hardware[type].signal_pin) ? 1 : 0; ++ ++ if (dcd == last_dcd) { ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": ignoring spike: %d %d %lx %lx %lx %lx\n", ++ dcd, sense, ++ tv.tv_sec, lasttv.tv_sec, ++ tv.tv_usec, lasttv.tv_usec); ++ continue; ++ } ++ ++ deltv = tv.tv_sec-lasttv.tv_sec; ++ if (tv.tv_sec < lasttv.tv_sec || ++ (tv.tv_sec == lasttv.tv_sec && ++ tv.tv_usec < lasttv.tv_usec)) { ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": AIEEEE: your clock just jumped " ++ "backwards\n"); ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": %d %d %lx %lx %lx %lx\n", ++ dcd, sense, ++ tv.tv_sec, lasttv.tv_sec, ++ tv.tv_usec, lasttv.tv_usec); ++ data = PULSE_MASK; ++ } else if (deltv > 15) { ++ data = PULSE_MASK; /* really long time */ ++ if (!(dcd^sense)) { ++ /* sanity check */ ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": AIEEEE: " ++ "%d %d %lx %lx %lx %lx\n", ++ dcd, sense, ++ tv.tv_sec, lasttv.tv_sec, ++ tv.tv_usec, lasttv.tv_usec); ++ /* ++ * detecting pulse while this ++ * MUST be a space! ++ */ ++ sense = sense ? 0 : 1; ++ } ++ } else ++ data = (int) (deltv*1000000 + ++ tv.tv_usec - ++ lasttv.tv_usec); ++ frbwrite(dcd^sense ? data : (data|PULSE_BIT)); ++ lasttv = tv; ++ last_dcd = dcd; ++ wake_up_interruptible(&rbuf.wait_poll); ++ } ++ } while (!(sinp(UART_IIR) & UART_IIR_NO_INT)); /* still pending ? */ ++ return IRQ_HANDLED; ++} ++ ++ ++static int hardware_init_port(void) ++{ ++ u8 scratch, scratch2, scratch3; ++ ++ /* ++ * This is a simple port existence test, borrowed from the autoconfig ++ * function in drivers/serial/8250.c ++ */ ++ scratch = sinp(UART_IER); ++ soutp(UART_IER, 0); ++#ifdef __i386__ ++ outb(0xff, 0x080); ++#endif ++ scratch2 = sinp(UART_IER) & 0x0f; ++ soutp(UART_IER, 0x0f); ++#ifdef __i386__ ++ outb(0x00, 0x080); ++#endif ++ scratch3 = sinp(UART_IER) & 0x0f; ++ soutp(UART_IER, scratch); ++ if (scratch2 != 0 || scratch3 != 0x0f) { ++ /* we fail, there's nothing here */ ++ printk(KERN_ERR LIRC_DRIVER_NAME ": port existence test " ++ "failed, cannot continue\n"); ++ return -EINVAL; ++ } ++ ++ ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ /* First of all, disable all interrupts */ ++ soutp(UART_IER, sinp(UART_IER) & ++ (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI))); ++ ++ /* Clear registers. */ ++ sinp(UART_LSR); ++ sinp(UART_RX); ++ sinp(UART_IIR); ++ sinp(UART_MSR); ++ ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++ if (type == LIRC_NSLU2) { ++ /* Setup NSLU2 UART */ ++ ++ /* Enable UART */ ++ soutp(UART_IER, sinp(UART_IER) | UART_IE_IXP42X_UUE); ++ /* Disable Receiver data Time out interrupt */ ++ soutp(UART_IER, sinp(UART_IER) & ~UART_IE_IXP42X_RTOIE); ++ /* set out2 = interrupt unmask; off() doesn't set MCR ++ on NSLU2 */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2); ++ } ++#endif ++ ++ /* Set line for power source */ ++ off(); ++ ++ /* Clear registers again to be sure. */ ++ sinp(UART_LSR); ++ sinp(UART_RX); ++ sinp(UART_IIR); ++ sinp(UART_MSR); ++ ++ switch (type) { ++ case LIRC_IRDEO: ++ case LIRC_IRDEO_REMOTE: ++ /* setup port to 7N1 @ 115200 Baud */ ++ /* 7N1+start = 9 bits at 115200 ~ 3 bits at 38kHz */ ++ ++ /* Set DLAB 1. */ ++ soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB); ++ /* Set divisor to 1 => 115200 Baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 1); ++ /* Set DLAB 0 + 7N1 */ ++ soutp(UART_LCR, UART_LCR_WLEN7); ++ /* THR interrupt already disabled at this point */ ++ break; ++ default: ++ break; ++ } ++ ++ return 0; ++} ++ ++static int init_port(void) ++{ ++ int i, nlow, nhigh; ++ ++ /* Reserve io region. */ ++ /* ++ * Future MMAP-Developers: Attention! ++ * For memory mapped I/O you *might* need to use ioremap() first, ++ * for the NSLU2 it's done in boot code. ++ */ ++ if (((iommap != 0) ++ && (request_mem_region(iommap, 8 << ioshift, ++ LIRC_DRIVER_NAME) == NULL)) ++ || ((iommap == 0) ++ && (request_region(io, 8, LIRC_DRIVER_NAME) == NULL))) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": port %04x already in use\n", io); ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": use 'setserial /dev/ttySX uart none'\n"); ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": or compile the serial port driver as module and\n"); ++ printk(KERN_WARNING LIRC_DRIVER_NAME ++ ": make sure this module is loaded first\n"); ++ return -EBUSY; ++ } ++ ++ if (hardware_init_port() < 0) ++ return -EINVAL; ++ ++ /* Initialize pulse/space widths */ ++ init_timing_params(duty_cycle, freq); ++ ++ /* If pin is high, then this must be an active low receiver. */ ++ if (sense == -1) { ++ /* wait 1/2 sec for the power supply */ ++ msleep(500); ++ ++ /* ++ * probe 9 times every 0.04s, collect "votes" for ++ * active high/low ++ */ ++ nlow = 0; ++ nhigh = 0; ++ for (i = 0; i < 9; i++) { ++ if (sinp(UART_MSR) & hardware[type].signal_pin) ++ nlow++; ++ else ++ nhigh++; ++ msleep(40); ++ } ++ sense = (nlow >= nhigh ? 1 : 0); ++ printk(KERN_INFO LIRC_DRIVER_NAME ": auto-detected active " ++ "%s receiver\n", sense ? "low" : "high"); ++ } else ++ printk(KERN_INFO LIRC_DRIVER_NAME ": Manually using active " ++ "%s receiver\n", sense ? "low" : "high"); ++ ++ return 0; ++} ++ ++static int set_use_inc(void *data) ++{ ++ int result; ++ unsigned long flags; ++ ++ /* initialize timestamp */ ++ do_gettimeofday(&lasttv); ++ ++ result = request_irq(irq, irq_handler, ++ IRQF_DISABLED | (share_irq ? IRQF_SHARED : 0), ++ LIRC_DRIVER_NAME, (void *)&hardware); ++ ++ switch (result) { ++ case -EBUSY: ++ printk(KERN_ERR LIRC_DRIVER_NAME ": IRQ %d busy\n", irq); ++ return -EBUSY; ++ case -EINVAL: ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": Bad irq number or handler\n"); ++ return -EINVAL; ++ default: ++ dprintk("Interrupt %d, port %04x obtained\n", irq, io); ++ break; ++ }; ++ ++ spin_lock_irqsave(&hardware[type].lock, flags); ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI); ++ ++ spin_unlock_irqrestore(&hardware[type].lock, flags); ++ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ unsigned long flags; ++ ++ spin_lock_irqsave(&hardware[type].lock, flags); ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ /* First of all, disable all interrupts */ ++ soutp(UART_IER, sinp(UART_IER) & ++ (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI))); ++ spin_unlock_irqrestore(&hardware[type].lock, flags); ++ ++ free_irq(irq, (void *)&hardware); ++ ++ dprintk("freed IRQ %d\n", irq); ++} ++ ++static ssize_t lirc_write(struct file *file, const char *buf, ++ size_t n, loff_t *ppos) ++{ ++ int i, count; ++ unsigned long flags; ++ long delta = 0; ++ ++ if (!(hardware[type].features&LIRC_CAN_SEND_PULSE)) ++ return -EBADF; ++ ++ if (n % sizeof(int)) ++ return -EINVAL; ++ count = n / sizeof(int); ++ if (count > WBUF_LEN || count % 2 == 0) ++ return -EINVAL; ++ if (copy_from_user(wbuf, buf, n)) ++ return -EFAULT; ++ spin_lock_irqsave(&hardware[type].lock, flags); ++ if (type == LIRC_IRDEO) { ++ /* DTR, RTS down */ ++ on(); ++ } ++ for (i = 0; i < count; i++) { ++ if (i%2) ++ hardware[type].send_space(wbuf[i]-delta); ++ else ++ delta = hardware[type].send_pulse(wbuf[i]); ++ } ++ off(); ++ spin_unlock_irqrestore(&hardware[type].lock, flags); ++ return n; ++} ++ ++static int lirc_ioctl(struct inode *node, struct file *filep, unsigned int cmd, ++ unsigned long arg) ++{ ++ int result; ++ unsigned long value; ++ unsigned int ivalue; ++ ++ switch (cmd) { ++ case LIRC_GET_SEND_MODE: ++ if (!(hardware[type].features&LIRC_CAN_SEND_MASK)) ++ return -ENOIOCTLCMD; ++ ++ result = put_user(LIRC_SEND2MODE ++ (hardware[type].features&LIRC_CAN_SEND_MASK), ++ (unsigned long *) arg); ++ if (result) ++ return result; ++ break; ++ ++ case LIRC_SET_SEND_MODE: ++ if (!(hardware[type].features&LIRC_CAN_SEND_MASK)) ++ return -ENOIOCTLCMD; ++ ++ result = get_user(value, (unsigned long *) arg); ++ if (result) ++ return result; ++ /* only LIRC_MODE_PULSE supported */ ++ if (value != LIRC_MODE_PULSE) ++ return -ENOSYS; ++ break; ++ ++ case LIRC_GET_LENGTH: ++ return -ENOSYS; ++ break; ++ ++ case LIRC_SET_SEND_DUTY_CYCLE: ++ dprintk("SET_SEND_DUTY_CYCLE\n"); ++ if (!(hardware[type].features&LIRC_CAN_SET_SEND_DUTY_CYCLE)) ++ return -ENOIOCTLCMD; ++ ++ result = get_user(ivalue, (unsigned int *) arg); ++ if (result) ++ return result; ++ if (ivalue <= 0 || ivalue > 100) ++ return -EINVAL; ++ return init_timing_params(ivalue, freq); ++ break; ++ ++ case LIRC_SET_SEND_CARRIER: ++ dprintk("SET_SEND_CARRIER\n"); ++ if (!(hardware[type].features&LIRC_CAN_SET_SEND_CARRIER)) ++ return -ENOIOCTLCMD; ++ ++ result = get_user(ivalue, (unsigned int *) arg); ++ if (result) ++ return result; ++ if (ivalue > 500000 || ivalue < 20000) ++ return -EINVAL; ++ return init_timing_params(duty_cycle, ivalue); ++ break; ++ ++ default: ++ return lirc_dev_fop_ioctl(node, filep, cmd, arg); ++ } ++ return 0; ++} ++ ++static struct file_operations lirc_fops = { ++ .owner = THIS_MODULE, ++ .write = lirc_write, ++ .ioctl = lirc_ioctl, ++ .read = lirc_dev_fop_read, ++ .poll = lirc_dev_fop_poll, ++ .open = lirc_dev_fop_open, ++ .release = lirc_dev_fop_close, ++}; ++ ++static struct lirc_driver driver = { ++ .name = LIRC_DRIVER_NAME, ++ .minor = -1, ++ .code_length = 1, ++ .sample_rate = 0, ++ .data = NULL, ++ .add_to_buf = NULL, ++ .rbuf = &rbuf, ++ .set_use_inc = set_use_inc, ++ .set_use_dec = set_use_dec, ++ .fops = &lirc_fops, ++ .dev = NULL, ++ .owner = THIS_MODULE, ++}; ++ ++static struct platform_device *lirc_serial_dev; ++ ++static int __devinit lirc_serial_probe(struct platform_device *dev) ++{ ++ return 0; ++} ++ ++static int __devexit lirc_serial_remove(struct platform_device *dev) ++{ ++ return 0; ++} ++ ++static int lirc_serial_suspend(struct platform_device *dev, ++ pm_message_t state) ++{ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ /* Disable all interrupts */ ++ soutp(UART_IER, sinp(UART_IER) & ++ (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI))); ++ ++ /* Clear registers. */ ++ sinp(UART_LSR); ++ sinp(UART_RX); ++ sinp(UART_IIR); ++ sinp(UART_MSR); ++ ++ return 0; ++} ++ ++/* twisty maze... need a forward-declaration here... */ ++static void lirc_serial_exit(void); ++ ++static int lirc_serial_resume(struct platform_device *dev) ++{ ++ unsigned long flags; ++ ++ if (hardware_init_port() < 0) { ++ lirc_serial_exit(); ++ return -EINVAL; ++ } ++ ++ spin_lock_irqsave(&hardware[type].lock, flags); ++ /* Enable Interrupt */ ++ do_gettimeofday(&lasttv); ++ soutp(UART_IER, sinp(UART_IER)|UART_IER_MSI); ++ off(); ++ ++ lirc_buffer_clear(&rbuf); ++ ++ spin_unlock_irqrestore(&hardware[type].lock, flags); ++ ++ return 0; ++} ++ ++static struct platform_driver lirc_serial_driver = { ++ .probe = lirc_serial_probe, ++ .remove = __devexit_p(lirc_serial_remove), ++ .suspend = lirc_serial_suspend, ++ .resume = lirc_serial_resume, ++ .driver = { ++ .name = "lirc_serial", ++ .owner = THIS_MODULE, ++ }, ++}; ++ ++static int __init lirc_serial_init(void) ++{ ++ int result; ++ ++ /* Init read buffer. */ ++ result = lirc_buffer_init(&rbuf, sizeof(int), RBUF_LEN); ++ if (result < 0) ++ return -ENOMEM; ++ ++ result = platform_driver_register(&lirc_serial_driver); ++ if (result) { ++ printk("lirc register returned %d\n", result); ++ goto exit_buffer_free; ++ } ++ ++ lirc_serial_dev = platform_device_alloc("lirc_serial", 0); ++ if (!lirc_serial_dev) { ++ result = -ENOMEM; ++ goto exit_driver_unregister; ++ } ++ ++ result = platform_device_add(lirc_serial_dev); ++ if (result) ++ goto exit_device_put; ++ ++ return 0; ++ ++exit_device_put: ++ platform_device_put(lirc_serial_dev); ++exit_driver_unregister: ++ platform_driver_unregister(&lirc_serial_driver); ++exit_buffer_free: ++ lirc_buffer_free(&rbuf); ++ return result; ++} ++ ++static void lirc_serial_exit(void) ++{ ++ platform_device_unregister(lirc_serial_dev); ++ platform_driver_unregister(&lirc_serial_driver); ++ lirc_buffer_free(&rbuf); ++} ++ ++static int __init lirc_serial_init_module(void) ++{ ++ int result; ++ ++ result = lirc_serial_init(); ++ if (result) ++ return result; ++ ++ switch (type) { ++ case LIRC_HOMEBREW: ++ case LIRC_IRDEO: ++ case LIRC_IRDEO_REMOTE: ++ case LIRC_ANIMAX: ++ case LIRC_IGOR: ++ /* if nothing specified, use ttyS0/com1 and irq 4 */ ++ io = io ? io : 0x3f8; ++ irq = irq ? irq : 4; ++ break; ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++ case LIRC_NSLU2: ++ io = io ? io : IRQ_IXP4XX_UART2; ++ irq = irq ? irq : (IXP4XX_UART2_BASE_VIRT + REG_OFFSET); ++ iommap = iommap ? iommap : IXP4XX_UART2_BASE_PHYS; ++ ioshift = ioshift ? ioshift : 2; ++ break; ++#endif ++ default: ++ result = -EINVAL; ++ goto exit_serial_exit; ++ } ++ if (!softcarrier) { ++ switch (type) { ++ case LIRC_HOMEBREW: ++ case LIRC_IGOR: ++#ifdef CONFIG_LIRC_SERIAL_NSLU2 ++ case LIRC_NSLU2: ++#endif ++ hardware[type].features &= ++ ~(LIRC_CAN_SET_SEND_DUTY_CYCLE| ++ LIRC_CAN_SET_SEND_CARRIER); ++ break; ++ } ++ } ++ ++ result = init_port(); ++ if (result < 0) ++ goto exit_serial_exit; ++ driver.features = hardware[type].features; ++ driver.dev = &lirc_serial_dev->dev; ++ driver.minor = lirc_register_driver(&driver); ++ if (driver.minor < 0) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": register_chrdev failed!\n"); ++ result = -EIO; ++ goto exit_release; ++ } ++ return 0; ++exit_release: ++ release_region(io, 8); ++exit_serial_exit: ++ lirc_serial_exit(); ++ return result; ++} ++ ++static void __exit lirc_serial_exit_module(void) ++{ ++ lirc_serial_exit(); ++ if (iommap != 0) ++ release_mem_region(iommap, 8 << ioshift); ++ else ++ release_region(io, 8); ++ lirc_unregister_driver(driver.minor); ++ dprintk("cleaned up module\n"); ++} ++ ++ ++module_init(lirc_serial_init_module); ++module_exit(lirc_serial_exit_module); ++ ++MODULE_DESCRIPTION("Infra-red receiver driver for serial ports."); ++MODULE_AUTHOR("Ralph Metzler, Trent Piepho, Ben Pfaff, " ++ "Christoph Bartelmus, Andrei Tanas"); ++MODULE_LICENSE("GPL"); ++ ++module_param(type, int, S_IRUGO); ++MODULE_PARM_DESC(type, "Hardware type (0 = home-brew, 1 = IRdeo," ++ " 2 = IRdeo Remote, 3 = AnimaX, 4 = IgorPlug," ++ " 5 = NSLU2 RX:CTS2/TX:GreenLED)"); ++ ++module_param(io, int, S_IRUGO); ++MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)"); ++ ++/* some architectures (e.g. intel xscale) have memory mapped registers */ ++module_param(iommap, bool, S_IRUGO); ++MODULE_PARM_DESC(iommap, "physical base for memory mapped I/O" ++ " (0 = no memory mapped io)"); ++ ++/* ++ * some architectures (e.g. intel xscale) align the 8bit serial registers ++ * on 32bit word boundaries. ++ * See linux-kernel/serial/8250.c serial_in()/out() ++ */ ++module_param(ioshift, int, S_IRUGO); ++MODULE_PARM_DESC(ioshift, "shift I/O register offset (0 = no shift)"); ++ ++module_param(irq, int, S_IRUGO); ++MODULE_PARM_DESC(irq, "Interrupt (4 or 3)"); ++ ++module_param(share_irq, bool, S_IRUGO); ++MODULE_PARM_DESC(share_irq, "Share interrupts (0 = off, 1 = on)"); ++ ++module_param(sense, bool, S_IRUGO); ++MODULE_PARM_DESC(sense, "Override autodetection of IR receiver circuit" ++ " (0 = active high, 1 = active low )"); ++ ++#ifdef CONFIG_LIRC_SERIAL_TRANSMITTER ++module_param(txsense, bool, S_IRUGO); ++MODULE_PARM_DESC(txsense, "Sense of transmitter circuit" ++ " (0 = active high, 1 = active low )"); ++#endif ++ ++module_param(softcarrier, bool, S_IRUGO); ++MODULE_PARM_DESC(softcarrier, "Software carrier (0 = off, 1 = on, default on)"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); +diff --git a/drivers/input/lirc/lirc_sir.c b/drivers/input/lirc/lirc_sir.c +new file mode 100644 +index 0000000..4a471d6 +--- /dev/null ++++ b/drivers/input/lirc/lirc_sir.c +@@ -0,0 +1,1283 @@ ++/* ++ * LIRC SIR driver, (C) 2000 Milan Pikula ++ * ++ * lirc_sir - Device driver for use with SIR (serial infra red) ++ * mode of IrDA on many notebooks. ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ * ++ * 2000/09/16 Frank Przybylski : ++ * added timeout and relaxed pulse detection, removed gap bug ++ * ++ * 2000/12/15 Christoph Bartelmus : ++ * added support for Tekram Irmate 210 (sending does not work yet, ++ * kind of disappointing that nobody was able to implement that ++ * before), ++ * major clean-up ++ * ++ * 2001/02/27 Christoph Bartelmus : ++ * added support for StrongARM SA1100 embedded microprocessor ++ * parts cut'n'pasted from sa1100_ir.c (C) 2000 Russell King ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#ifdef LIRC_ON_SA1100 ++#include ++#ifdef CONFIG_SA1100_COLLIE ++#include ++#include ++#endif ++#endif ++ ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++/* SECTION: Definitions */ ++ ++/*** Tekram dongle ***/ ++#ifdef LIRC_SIR_TEKRAM ++/* stolen from kernel source */ ++/* definitions for Tekram dongle */ ++#define TEKRAM_115200 0x00 ++#define TEKRAM_57600 0x01 ++#define TEKRAM_38400 0x02 ++#define TEKRAM_19200 0x03 ++#define TEKRAM_9600 0x04 ++#define TEKRAM_2400 0x08 ++ ++#define TEKRAM_PW 0x10 /* Pulse select bit */ ++ ++/* 10bit * 1s/115200bit in milliseconds = 87ms*/ ++#define TIME_CONST (10000000ul/115200ul) ++ ++#endif ++ ++#ifdef LIRC_SIR_ACTISYS_ACT200L ++static void init_act200(void); ++#elif defined(LIRC_SIR_ACTISYS_ACT220L) ++static void init_act220(void); ++#endif ++ ++/*** SA1100 ***/ ++#ifdef LIRC_ON_SA1100 ++struct sa1100_ser2_registers { ++ /* HSSP control register */ ++ unsigned char hscr0; ++ /* UART registers */ ++ unsigned char utcr0; ++ unsigned char utcr1; ++ unsigned char utcr2; ++ unsigned char utcr3; ++ unsigned char utcr4; ++ unsigned char utdr; ++ unsigned char utsr0; ++ unsigned char utsr1; ++} sr; ++ ++static int irq = IRQ_Ser2ICP; ++ ++#define LIRC_ON_SA1100_TRANSMITTER_LATENCY 0 ++ ++/* pulse/space ratio of 50/50 */ ++static unsigned long pulse_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY); ++/* 1000000/freq-pulse_width */ ++static unsigned long space_width = (13-LIRC_ON_SA1100_TRANSMITTER_LATENCY); ++static unsigned int freq = 38000; /* modulation frequency */ ++static unsigned int duty_cycle = 50; /* duty cycle of 50% */ ++ ++#endif ++ ++#define RBUF_LEN 1024 ++#define WBUF_LEN 1024 ++ ++#define LIRC_DRIVER_NAME "lirc_sir" ++ ++#define PULSE '[' ++ ++#ifndef LIRC_SIR_TEKRAM ++/* 9bit * 1s/115200bit in milli seconds = 78.125ms*/ ++#define TIME_CONST (9000000ul/115200ul) ++#endif ++ ++ ++/* timeout for sequences in jiffies (=5/100s), must be longer than TIME_CONST */ ++#define SIR_TIMEOUT (HZ*5/100) ++ ++#ifndef LIRC_ON_SA1100 ++#ifndef LIRC_IRQ ++#define LIRC_IRQ 4 ++#endif ++#ifndef LIRC_PORT ++/* for external dongles, default to com1 */ ++#if defined(LIRC_SIR_ACTISYS_ACT200L) || \ ++ defined(LIRC_SIR_ACTISYS_ACT220L) || \ ++ defined(LIRC_SIR_TEKRAM) ++#define LIRC_PORT 0x3f8 ++#else ++/* onboard sir ports are typically com3 */ ++#define LIRC_PORT 0x3e8 ++#endif ++#endif ++ ++static int io = LIRC_PORT; ++static int irq = LIRC_IRQ; ++static int threshold = 3; ++#endif ++ ++static DEFINE_SPINLOCK(timer_lock); ++static struct timer_list timerlist; ++/* time of last signal change detected */ ++static struct timeval last_tv = {0, 0}; ++/* time of last UART data ready interrupt */ ++static struct timeval last_intr_tv = {0, 0}; ++static int last_value; ++ ++static DECLARE_WAIT_QUEUE_HEAD(lirc_read_queue); ++ ++static DEFINE_SPINLOCK(hardware_lock); ++ ++static int rx_buf[RBUF_LEN]; ++static unsigned int rx_tail, rx_head; ++static int tx_buf[WBUF_LEN]; ++ ++static int debug; ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG LIRC_DRIVER_NAME ": " \ ++ fmt, ## args); \ ++ } while (0) ++ ++/* SECTION: Prototypes */ ++ ++/* Communication with user-space */ ++static unsigned int lirc_poll(struct file *file, poll_table *wait); ++static ssize_t lirc_read(struct file *file, char *buf, size_t count, ++ loff_t *ppos); ++static ssize_t lirc_write(struct file *file, const char *buf, size_t n, ++ loff_t *pos); ++static int lirc_ioctl(struct inode *node, struct file *filep, unsigned int cmd, ++ unsigned long arg); ++static void add_read_queue(int flag, unsigned long val); ++static int init_chrdev(void); ++static void drop_chrdev(void); ++/* Hardware */ ++static irqreturn_t sir_interrupt(int irq, void *dev_id); ++static void send_space(unsigned long len); ++static void send_pulse(unsigned long len); ++static int init_hardware(void); ++static void drop_hardware(void); ++/* Initialisation */ ++static int init_port(void); ++static void drop_port(void); ++ ++#ifdef LIRC_ON_SA1100 ++static void on(void) ++{ ++ PPSR |= PPC_TXD2; ++} ++ ++static void off(void) ++{ ++ PPSR &= ~PPC_TXD2; ++} ++#else ++static inline unsigned int sinp(int offset) ++{ ++ return inb(io + offset); ++} ++ ++static inline void soutp(int offset, int value) ++{ ++ outb(value, io + offset); ++} ++#endif ++ ++#ifndef MAX_UDELAY_MS ++#define MAX_UDELAY_US 5000 ++#else ++#define MAX_UDELAY_US (MAX_UDELAY_MS*1000) ++#endif ++ ++static void safe_udelay(unsigned long usecs) ++{ ++ while (usecs > MAX_UDELAY_US) { ++ udelay(MAX_UDELAY_US); ++ usecs -= MAX_UDELAY_US; ++ } ++ udelay(usecs); ++} ++ ++/* SECTION: Communication with user-space */ ++ ++static unsigned int lirc_poll(struct file *file, poll_table *wait) ++{ ++ poll_wait(file, &lirc_read_queue, wait); ++ if (rx_head != rx_tail) ++ return POLLIN | POLLRDNORM; ++ return 0; ++} ++ ++static ssize_t lirc_read(struct file *file, char *buf, size_t count, ++ loff_t *ppos) ++{ ++ int n = 0; ++ int retval = 0; ++ DECLARE_WAITQUEUE(wait, current); ++ ++ if (count % sizeof(int)) ++ return -EINVAL; ++ ++ add_wait_queue(&lirc_read_queue, &wait); ++ set_current_state(TASK_INTERRUPTIBLE); ++ while (n < count) { ++ if (rx_head != rx_tail) { ++ if (copy_to_user((void *) buf + n, ++ (void *) (rx_buf + rx_head), ++ sizeof(int))) { ++ retval = -EFAULT; ++ break; ++ } ++ rx_head = (rx_head + 1) & (RBUF_LEN - 1); ++ n += sizeof(int); ++ } else { ++ if (file->f_flags & O_NONBLOCK) { ++ retval = -EAGAIN; ++ break; ++ } ++ if (signal_pending(current)) { ++ retval = -ERESTARTSYS; ++ break; ++ } ++ schedule(); ++ set_current_state(TASK_INTERRUPTIBLE); ++ } ++ } ++ remove_wait_queue(&lirc_read_queue, &wait); ++ set_current_state(TASK_RUNNING); ++ return n ? n : retval; ++} ++static ssize_t lirc_write(struct file *file, const char *buf, size_t n, ++ loff_t *pos) ++{ ++ unsigned long flags; ++ int i; ++ ++ if (n % sizeof(int) || (n / sizeof(int)) > WBUF_LEN) ++ return -EINVAL; ++ if (copy_from_user(tx_buf, buf, n)) ++ return -EFAULT; ++ i = 0; ++ n /= sizeof(int); ++#ifdef LIRC_ON_SA1100 ++ /* disable receiver */ ++ Ser2UTCR3 = 0; ++#endif ++ local_irq_save(flags); ++ while (1) { ++ if (i >= n) ++ break; ++ if (tx_buf[i]) ++ send_pulse(tx_buf[i]); ++ i++; ++ if (i >= n) ++ break; ++ if (tx_buf[i]) ++ send_space(tx_buf[i]); ++ i++; ++ } ++ local_irq_restore(flags); ++#ifdef LIRC_ON_SA1100 ++ off(); ++ udelay(1000); /* wait 1ms for IR diode to recover */ ++ Ser2UTCR3 = 0; ++ /* clear status register to prevent unwanted interrupts */ ++ Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB); ++ /* enable receiver */ ++ Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE; ++#endif ++ return n; ++} ++ ++static int lirc_ioctl(struct inode *node, struct file *filep, unsigned int cmd, ++ unsigned long arg) ++{ ++ int retval = 0; ++ unsigned long value = 0; ++#ifdef LIRC_ON_SA1100 ++ unsigned int ivalue; ++ ++ if (cmd == LIRC_GET_FEATURES) ++ value = LIRC_CAN_SEND_PULSE | ++ LIRC_CAN_SET_SEND_DUTY_CYCLE | ++ LIRC_CAN_SET_SEND_CARRIER | ++ LIRC_CAN_REC_MODE2; ++ else if (cmd == LIRC_GET_SEND_MODE) ++ value = LIRC_MODE_PULSE; ++ else if (cmd == LIRC_GET_REC_MODE) ++ value = LIRC_MODE_MODE2; ++#else ++ if (cmd == LIRC_GET_FEATURES) ++ value = LIRC_CAN_SEND_PULSE | LIRC_CAN_REC_MODE2; ++ else if (cmd == LIRC_GET_SEND_MODE) ++ value = LIRC_MODE_PULSE; ++ else if (cmd == LIRC_GET_REC_MODE) ++ value = LIRC_MODE_MODE2; ++#endif ++ ++ switch (cmd) { ++ case LIRC_GET_FEATURES: ++ case LIRC_GET_SEND_MODE: ++ case LIRC_GET_REC_MODE: ++ retval = put_user(value, (unsigned long *) arg); ++ break; ++ ++ case LIRC_SET_SEND_MODE: ++ case LIRC_SET_REC_MODE: ++ retval = get_user(value, (unsigned long *) arg); ++ break; ++#ifdef LIRC_ON_SA1100 ++ case LIRC_SET_SEND_DUTY_CYCLE: ++ retval = get_user(ivalue, (unsigned int *) arg); ++ if (retval) ++ return retval; ++ if (ivalue <= 0 || ivalue > 100) ++ return -EINVAL; ++ /* (ivalue/100)*(1000000/freq) */ ++ duty_cycle = ivalue; ++ pulse_width = (unsigned long) duty_cycle*10000/freq; ++ space_width = (unsigned long) 1000000L/freq-pulse_width; ++ if (pulse_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY) ++ pulse_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY; ++ if (space_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY) ++ space_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY; ++ break; ++ case LIRC_SET_SEND_CARRIER: ++ retval = get_user(ivalue, (unsigned int *) arg); ++ if (retval) ++ return retval; ++ if (ivalue > 500000 || ivalue < 20000) ++ return -EINVAL; ++ freq = ivalue; ++ pulse_width = (unsigned long) duty_cycle*10000/freq; ++ space_width = (unsigned long) 1000000L/freq-pulse_width; ++ if (pulse_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY) ++ pulse_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY; ++ if (space_width >= LIRC_ON_SA1100_TRANSMITTER_LATENCY) ++ space_width -= LIRC_ON_SA1100_TRANSMITTER_LATENCY; ++ break; ++#endif ++ default: ++ retval = -ENOIOCTLCMD; ++ ++ } ++ ++ if (retval) ++ return retval; ++ if (cmd == LIRC_SET_REC_MODE) { ++ if (value != LIRC_MODE_MODE2) ++ retval = -ENOSYS; ++ } else if (cmd == LIRC_SET_SEND_MODE) { ++ if (value != LIRC_MODE_PULSE) ++ retval = -ENOSYS; ++ } ++ ++ return retval; ++} ++ ++static void add_read_queue(int flag, unsigned long val) ++{ ++ unsigned int new_rx_tail; ++ int newval; ++ ++ dprintk("add flag %d with val %lu\n", flag, val); ++ ++ newval = val & PULSE_MASK; ++ ++ /* ++ * statistically, pulses are ~TIME_CONST/2 too long. we could ++ * maybe make this more exact, but this is good enough ++ */ ++ if (flag) { ++ /* pulse */ ++ if (newval > TIME_CONST/2) ++ newval -= TIME_CONST/2; ++ else /* should not ever happen */ ++ newval = 1; ++ newval |= PULSE_BIT; ++ } else { ++ newval += TIME_CONST/2; ++ } ++ new_rx_tail = (rx_tail + 1) & (RBUF_LEN - 1); ++ if (new_rx_tail == rx_head) { ++ dprintk("Buffer overrun.\n"); ++ return; ++ } ++ rx_buf[rx_tail] = newval; ++ rx_tail = new_rx_tail; ++ wake_up_interruptible(&lirc_read_queue); ++} ++ ++static struct file_operations lirc_fops = { ++ .owner = THIS_MODULE, ++ .read = lirc_read, ++ .write = lirc_write, ++ .poll = lirc_poll, ++ .ioctl = lirc_ioctl, ++ .open = lirc_dev_fop_open, ++ .release = lirc_dev_fop_close, ++}; ++ ++static int set_use_inc(void *data) ++{ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++} ++ ++static struct lirc_driver driver = { ++ .name = LIRC_DRIVER_NAME, ++ .minor = -1, ++ .code_length = 1, ++ .sample_rate = 0, ++ .data = NULL, ++ .add_to_buf = NULL, ++ .set_use_inc = set_use_inc, ++ .set_use_dec = set_use_dec, ++ .fops = &lirc_fops, ++ .dev = NULL, ++ .owner = THIS_MODULE, ++}; ++ ++ ++static int init_chrdev(void) ++{ ++ driver.minor = lirc_register_driver(&driver); ++ if (driver.minor < 0) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ": init_chrdev() failed.\n"); ++ return -EIO; ++ } ++ return 0; ++} ++ ++static void drop_chrdev(void) ++{ ++ lirc_unregister_driver(driver.minor); ++} ++ ++/* SECTION: Hardware */ ++static long delta(struct timeval *tv1, struct timeval *tv2) ++{ ++ unsigned long deltv; ++ ++ deltv = tv2->tv_sec - tv1->tv_sec; ++ if (deltv > 15) ++ deltv = 0xFFFFFF; ++ else ++ deltv = deltv*1000000 + ++ tv2->tv_usec - ++ tv1->tv_usec; ++ return deltv; ++} ++ ++static void sir_timeout(unsigned long data) ++{ ++ /* ++ * if last received signal was a pulse, but receiving stopped ++ * within the 9 bit frame, we need to finish this pulse and ++ * simulate a signal change to from pulse to space. Otherwise ++ * upper layers will receive two sequences next time. ++ */ ++ ++ unsigned long flags; ++ unsigned long pulse_end; ++ ++ /* avoid interference with interrupt */ ++ spin_lock_irqsave(&timer_lock, flags); ++ if (last_value) { ++#ifndef LIRC_ON_SA1100 ++ /* clear unread bits in UART and restart */ ++ outb(UART_FCR_CLEAR_RCVR, io + UART_FCR); ++#endif ++ /* determine 'virtual' pulse end: */ ++ pulse_end = delta(&last_tv, &last_intr_tv); ++ dprintk("timeout add %d for %lu usec\n", last_value, pulse_end); ++ add_read_queue(last_value, pulse_end); ++ last_value = 0; ++ last_tv = last_intr_tv; ++ } ++ spin_unlock_irqrestore(&timer_lock, flags); ++} ++ ++static irqreturn_t sir_interrupt(int irq, void *dev_id) ++{ ++ unsigned char data; ++ struct timeval curr_tv; ++ static unsigned long deltv; ++#ifdef LIRC_ON_SA1100 ++ int status; ++ static int n; ++ ++ status = Ser2UTSR0; ++ /* ++ * Deal with any receive errors first. The bytes in error may be ++ * the only bytes in the receive FIFO, so we do this first. ++ */ ++ while (status & UTSR0_EIF) { ++ int bstat; ++ ++ if (debug) { ++ dprintk("EIF\n"); ++ bstat = Ser2UTSR1; ++ ++ if (bstat & UTSR1_FRE) ++ dprintk("frame error\n"); ++ if (bstat & UTSR1_ROR) ++ dprintk("receive fifo overrun\n"); ++ if (bstat & UTSR1_PRE) ++ dprintk("parity error\n"); ++ } ++ ++ bstat = Ser2UTDR; ++ n++; ++ status = Ser2UTSR0; ++ } ++ ++ if (status & (UTSR0_RFS | UTSR0_RID)) { ++ do_gettimeofday(&curr_tv); ++ deltv = delta(&last_tv, &curr_tv); ++ do { ++ data = Ser2UTDR; ++ dprintk("%d data: %u\n", n, (unsigned int) data); ++ n++; ++ } while (status & UTSR0_RID && /* do not empty fifo in order to ++ * get UTSR0_RID in any case */ ++ Ser2UTSR1 & UTSR1_RNE); /* data ready */ ++ ++ if (status&UTSR0_RID) { ++ add_read_queue(0 , deltv - n * TIME_CONST); /*space*/ ++ add_read_queue(1, n * TIME_CONST); /*pulse*/ ++ n = 0; ++ last_tv = curr_tv; ++ } ++ } ++ ++ if (status & UTSR0_TFS) ++ printk(KERN_ERR "transmit fifo not full, shouldn't happen\n"); ++ ++ /* We must clear certain bits. */ ++ status &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB); ++ if (status) ++ Ser2UTSR0 = status; ++#else ++ unsigned long deltintrtv; ++ unsigned long flags; ++ int iir, lsr; ++ ++ while ((iir = inb(io + UART_IIR) & UART_IIR_ID)) { ++ switch (iir&UART_IIR_ID) { /* FIXME toto treba preriedit */ ++ case UART_IIR_MSI: ++ (void) inb(io + UART_MSR); ++ break; ++ case UART_IIR_RLSI: ++ (void) inb(io + UART_LSR); ++ break; ++ case UART_IIR_THRI: ++#if 0 ++ if (lsr & UART_LSR_THRE) /* FIFO is empty */ ++ outb(data, io + UART_TX) ++#endif ++ break; ++ case UART_IIR_RDI: ++ /* avoid interference with timer */ ++ spin_lock_irqsave(&timer_lock, flags); ++ do { ++ del_timer(&timerlist); ++ data = inb(io + UART_RX); ++ do_gettimeofday(&curr_tv); ++ deltv = delta(&last_tv, &curr_tv); ++ deltintrtv = delta(&last_intr_tv, &curr_tv); ++ dprintk("t %lu, d %d\n", deltintrtv, (int)data); ++ /* ++ * if nothing came in last X cycles, ++ * it was gap ++ */ ++ if (deltintrtv > TIME_CONST * threshold) { ++ if (last_value) { ++ dprintk("GAP\n"); ++ /* simulate signal change */ ++ add_read_queue(last_value, ++ deltv - ++ deltintrtv); ++ last_value = 0; ++ last_tv.tv_sec = ++ last_intr_tv.tv_sec; ++ last_tv.tv_usec = ++ last_intr_tv.tv_usec; ++ deltv = deltintrtv; ++ } ++ } ++ data = 1; ++ if (data ^ last_value) { ++ /* ++ * deltintrtv > 2*TIME_CONST, remember? ++ * the other case is timeout ++ */ ++ add_read_queue(last_value, ++ deltv-TIME_CONST); ++ last_value = data; ++ last_tv = curr_tv; ++ if (last_tv.tv_usec >= TIME_CONST) { ++ last_tv.tv_usec -= TIME_CONST; ++ } else { ++ last_tv.tv_sec--; ++ last_tv.tv_usec += 1000000 - ++ TIME_CONST; ++ } ++ } ++ last_intr_tv = curr_tv; ++ if (data) { ++ /* ++ * start timer for end of ++ * sequence detection ++ */ ++ timerlist.expires = jiffies + ++ SIR_TIMEOUT; ++ add_timer(&timerlist); ++ } ++ ++ lsr = inb(io + UART_LSR); ++ } while (lsr & UART_LSR_DR); /* data ready */ ++ spin_unlock_irqrestore(&timer_lock, flags); ++ break; ++ default: ++ break; ++ } ++ } ++#endif ++ return IRQ_RETVAL(IRQ_HANDLED); ++} ++ ++#ifdef LIRC_ON_SA1100 ++static void send_pulse(unsigned long length) ++{ ++ unsigned long k, delay; ++ int flag; ++ ++ if (length == 0) ++ return; ++ /* ++ * this won't give us the carrier frequency we really want ++ * due to integer arithmetic, but we can accept this inaccuracy ++ */ ++ ++ for (k = flag = 0; k < length; k += delay, flag = !flag) { ++ if (flag) { ++ off(); ++ delay = space_width; ++ } else { ++ on(); ++ delay = pulse_width; ++ } ++ safe_udelay(delay); ++ } ++ off(); ++} ++ ++static void send_space(unsigned long length) ++{ ++ if (length == 0) ++ return; ++ off(); ++ safe_udelay(length); ++} ++#else ++static void send_space(unsigned long len) ++{ ++ safe_udelay(len); ++} ++ ++static void send_pulse(unsigned long len) ++{ ++ long bytes_out = len / TIME_CONST; ++ long time_left; ++ ++ time_left = (long)len - (long)bytes_out * (long)TIME_CONST; ++ if (bytes_out == 0) { ++ bytes_out++; ++ time_left = 0; ++ } ++ while (bytes_out--) { ++ outb(PULSE, io + UART_TX); ++ /* FIXME treba seriozne cakanie z char/serial.c */ ++ while (!(inb(io + UART_LSR) & UART_LSR_THRE)) ++ ; ++ } ++#if 0 ++ if (time_left > 0) ++ safe_udelay(time_left); ++#endif ++} ++#endif ++ ++#ifdef CONFIG_SA1100_COLLIE ++static int sa1100_irda_set_power_collie(int state) ++{ ++ if (state) { ++ /* ++ * 0 - off ++ * 1 - short range, lowest power ++ * 2 - medium range, medium power ++ * 3 - maximum range, high power ++ */ ++ ucb1200_set_io_direction(TC35143_GPIO_IR_ON, ++ TC35143_IODIR_OUTPUT); ++ ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_LOW); ++ udelay(100); ++ } else { ++ /* OFF */ ++ ucb1200_set_io_direction(TC35143_GPIO_IR_ON, ++ TC35143_IODIR_OUTPUT); ++ ucb1200_set_io(TC35143_GPIO_IR_ON, TC35143_IODAT_HIGH); ++ } ++ return 0; ++} ++#endif ++ ++static int init_hardware(void) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&hardware_lock, flags); ++ /* reset UART */ ++#ifdef LIRC_ON_SA1100 ++#ifdef CONFIG_SA1100_BITSY ++ if (machine_is_bitsy()) { ++ printk(KERN_INFO "Power on IR module\n"); ++ set_bitsy_egpio(EGPIO_BITSY_IR_ON); ++ } ++#endif ++#ifdef CONFIG_SA1100_COLLIE ++ sa1100_irda_set_power_collie(3); /* power on */ ++#endif ++ sr.hscr0 = Ser2HSCR0; ++ ++ sr.utcr0 = Ser2UTCR0; ++ sr.utcr1 = Ser2UTCR1; ++ sr.utcr2 = Ser2UTCR2; ++ sr.utcr3 = Ser2UTCR3; ++ sr.utcr4 = Ser2UTCR4; ++ ++ sr.utdr = Ser2UTDR; ++ sr.utsr0 = Ser2UTSR0; ++ sr.utsr1 = Ser2UTSR1; ++ ++ /* configure GPIO */ ++ /* output */ ++ PPDR |= PPC_TXD2; ++ PSDR |= PPC_TXD2; ++ /* set output to 0 */ ++ off(); ++ ++ /* Enable HP-SIR modulation, and ensure that the port is disabled. */ ++ Ser2UTCR3 = 0; ++ Ser2HSCR0 = sr.hscr0 & (~HSCR0_HSSP); ++ ++ /* clear status register to prevent unwanted interrupts */ ++ Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB); ++ ++ /* 7N1 */ ++ Ser2UTCR0 = UTCR0_1StpBit|UTCR0_7BitData; ++ /* 115200 */ ++ Ser2UTCR1 = 0; ++ Ser2UTCR2 = 1; ++ /* use HPSIR, 1.6 usec pulses */ ++ Ser2UTCR4 = UTCR4_HPSIR|UTCR4_Z1_6us; ++ ++ /* enable receiver, receive fifo interrupt */ ++ Ser2UTCR3 = UTCR3_RXE|UTCR3_RIE; ++ ++ /* clear status register to prevent unwanted interrupts */ ++ Ser2UTSR0 &= (UTSR0_RID | UTSR0_RBB | UTSR0_REB); ++ ++#elif defined(LIRC_SIR_TEKRAM) ++ /* disable FIFO */ ++ soutp(UART_FCR, ++ UART_FCR_CLEAR_RCVR| ++ UART_FCR_CLEAR_XMIT| ++ UART_FCR_TRIGGER_1); ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ /* First of all, disable all interrupts */ ++ soutp(UART_IER, sinp(UART_IER) & ++ (~(UART_IER_MSI|UART_IER_RLSI|UART_IER_THRI|UART_IER_RDI))); ++ ++ /* Set DLAB 1. */ ++ soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB); ++ ++ /* Set divisor to 12 => 9600 Baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 12); ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ /* power supply */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ safe_udelay(50*1000); ++ ++ /* -DTR low -> reset PIC */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2); ++ udelay(1*1000); ++ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ udelay(100); ++ ++ ++ /* -RTS low -> send control byte */ ++ soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2); ++ udelay(7); ++ soutp(UART_TX, TEKRAM_115200|TEKRAM_PW); ++ ++ /* one byte takes ~1042 usec to transmit at 9600,8N1 */ ++ udelay(1500); ++ ++ /* back to normal operation */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ udelay(50); ++ ++ udelay(1500); ++ ++ /* read previous control byte */ ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": 0x%02x\n", sinp(UART_RX)); ++ ++ /* Set DLAB 1. */ ++ soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB); ++ ++ /* Set divisor to 1 => 115200 Baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 1); ++ ++ /* Set DLAB 0, 8 Bit */ ++ soutp(UART_LCR, UART_LCR_WLEN8); ++ /* enable interrupts */ ++ soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI); ++#else ++ outb(0, io + UART_MCR); ++ outb(0, io + UART_IER); ++ /* init UART */ ++ /* set DLAB, speed = 115200 */ ++ outb(UART_LCR_DLAB | UART_LCR_WLEN7, io + UART_LCR); ++ outb(1, io + UART_DLL); outb(0, io + UART_DLM); ++ /* 7N1+start = 9 bits at 115200 ~ 3 bits at 44000 */ ++ outb(UART_LCR_WLEN7, io + UART_LCR); ++ /* FIFO operation */ ++ outb(UART_FCR_ENABLE_FIFO, io + UART_FCR); ++ /* interrupts */ ++ /* outb(UART_IER_RLSI|UART_IER_RDI|UART_IER_THRI, io + UART_IER); */ ++ outb(UART_IER_RDI, io + UART_IER); ++ /* turn on UART */ ++ outb(UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2, io + UART_MCR); ++#ifdef LIRC_SIR_ACTISYS_ACT200L ++ init_act200(); ++#elif defined(LIRC_SIR_ACTISYS_ACT220L) ++ init_act220(); ++#endif ++#endif ++ spin_unlock_irqrestore(&hardware_lock, flags); ++ return 0; ++} ++ ++static void drop_hardware(void) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&hardware_lock, flags); ++ ++#ifdef LIRC_ON_SA1100 ++ Ser2UTCR3 = 0; ++ ++ Ser2UTCR0 = sr.utcr0; ++ Ser2UTCR1 = sr.utcr1; ++ Ser2UTCR2 = sr.utcr2; ++ Ser2UTCR4 = sr.utcr4; ++ Ser2UTCR3 = sr.utcr3; ++ ++ Ser2HSCR0 = sr.hscr0; ++#ifdef CONFIG_SA1100_BITSY ++ if (machine_is_bitsy()) ++ clr_bitsy_egpio(EGPIO_BITSY_IR_ON); ++#endif ++#ifdef CONFIG_SA1100_COLLIE ++ sa1100_irda_set_power_collie(0); /* power off */ ++#endif ++#else ++ /* turn off interrupts */ ++ outb(0, io + UART_IER); ++#endif ++ spin_unlock_irqrestore(&hardware_lock, flags); ++} ++ ++/* SECTION: Initialisation */ ++ ++static int init_port(void) ++{ ++ int retval; ++ ++ /* get I/O port access and IRQ line */ ++#ifndef LIRC_ON_SA1100 ++ if (request_region(io, 8, LIRC_DRIVER_NAME) == NULL) { ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": i/o port 0x%.4x already in use.\n", io); ++ return -EBUSY; ++ } ++#endif ++ retval = request_irq(irq, sir_interrupt, IRQF_DISABLED, ++ LIRC_DRIVER_NAME, NULL); ++ if (retval < 0) { ++# ifndef LIRC_ON_SA1100 ++ release_region(io, 8); ++# endif ++ printk(KERN_ERR LIRC_DRIVER_NAME ++ ": IRQ %d already in use.\n", ++ irq); ++ return retval; ++ } ++#ifndef LIRC_ON_SA1100 ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": I/O port 0x%.4x, IRQ %d.\n", ++ io, irq); ++#endif ++ ++ init_timer(&timerlist); ++ timerlist.function = sir_timeout; ++ timerlist.data = 0xabadcafe; ++ ++ return 0; ++} ++ ++static void drop_port(void) ++{ ++ free_irq(irq, NULL); ++ del_timer_sync(&timerlist); ++#ifndef LIRC_ON_SA1100 ++ release_region(io, 8); ++#endif ++} ++ ++#ifdef LIRC_SIR_ACTISYS_ACT200L ++/* Crystal/Cirrus CS8130 IR transceiver, used in Actisys Act200L dongle */ ++/* some code borrowed from Linux IRDA driver */ ++ ++/* Register 0: Control register #1 */ ++#define ACT200L_REG0 0x00 ++#define ACT200L_TXEN 0x01 /* Enable transmitter */ ++#define ACT200L_RXEN 0x02 /* Enable receiver */ ++#define ACT200L_ECHO 0x08 /* Echo control chars */ ++ ++/* Register 1: Control register #2 */ ++#define ACT200L_REG1 0x10 ++#define ACT200L_LODB 0x01 /* Load new baud rate count value */ ++#define ACT200L_WIDE 0x04 /* Expand the maximum allowable pulse */ ++ ++/* Register 3: Transmit mode register #2 */ ++#define ACT200L_REG3 0x30 ++#define ACT200L_B0 0x01 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */ ++#define ACT200L_B1 0x02 /* DataBits, 0=6, 1=7, 2=8, 3=9(8P) */ ++#define ACT200L_CHSY 0x04 /* StartBit Synced 0=bittime, 1=startbit */ ++ ++/* Register 4: Output Power register */ ++#define ACT200L_REG4 0x40 ++#define ACT200L_OP0 0x01 /* Enable LED1C output */ ++#define ACT200L_OP1 0x02 /* Enable LED2C output */ ++#define ACT200L_BLKR 0x04 ++ ++/* Register 5: Receive Mode register */ ++#define ACT200L_REG5 0x50 ++#define ACT200L_RWIDL 0x01 /* fixed 1.6us pulse mode */ ++ /*.. other various IRDA bit modes, and TV remote modes..*/ ++ ++/* Register 6: Receive Sensitivity register #1 */ ++#define ACT200L_REG6 0x60 ++#define ACT200L_RS0 0x01 /* receive threshold bit 0 */ ++#define ACT200L_RS1 0x02 /* receive threshold bit 1 */ ++ ++/* Register 7: Receive Sensitivity register #2 */ ++#define ACT200L_REG7 0x70 ++#define ACT200L_ENPOS 0x04 /* Ignore the falling edge */ ++ ++/* Register 8,9: Baud Rate Divider register #1,#2 */ ++#define ACT200L_REG8 0x80 ++#define ACT200L_REG9 0x90 ++ ++#define ACT200L_2400 0x5f ++#define ACT200L_9600 0x17 ++#define ACT200L_19200 0x0b ++#define ACT200L_38400 0x05 ++#define ACT200L_57600 0x03 ++#define ACT200L_115200 0x01 ++ ++/* Register 13: Control register #3 */ ++#define ACT200L_REG13 0xd0 ++#define ACT200L_SHDW 0x01 /* Enable access to shadow registers */ ++ ++/* Register 15: Status register */ ++#define ACT200L_REG15 0xf0 ++ ++/* Register 21: Control register #4 */ ++#define ACT200L_REG21 0x50 ++#define ACT200L_EXCK 0x02 /* Disable clock output driver */ ++#define ACT200L_OSCL 0x04 /* oscillator in low power, medium accuracy mode */ ++ ++static void init_act200(void) ++{ ++ int i; ++ __u8 control[] = { ++ ACT200L_REG15, ++ ACT200L_REG13 | ACT200L_SHDW, ++ ACT200L_REG21 | ACT200L_EXCK | ACT200L_OSCL, ++ ACT200L_REG13, ++ ACT200L_REG7 | ACT200L_ENPOS, ++ ACT200L_REG6 | ACT200L_RS0 | ACT200L_RS1, ++ ACT200L_REG5 | ACT200L_RWIDL, ++ ACT200L_REG4 | ACT200L_OP0 | ACT200L_OP1 | ACT200L_BLKR, ++ ACT200L_REG3 | ACT200L_B0, ++ ACT200L_REG0 | ACT200L_TXEN | ACT200L_RXEN, ++ ACT200L_REG8 | (ACT200L_115200 & 0x0f), ++ ACT200L_REG9 | ((ACT200L_115200 >> 4) & 0x0f), ++ ACT200L_REG1 | ACT200L_LODB | ACT200L_WIDE ++ }; ++ ++ /* Set DLAB 1. */ ++ soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN8); ++ ++ /* Set divisor to 12 => 9600 Baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 12); ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, UART_LCR_WLEN8); ++ /* Set divisor to 12 => 9600 Baud */ ++ ++ /* power supply */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ for (i = 0; i < 50; i++) ++ safe_udelay(1000); ++ ++ /* Reset the dongle : set RTS low for 25 ms */ ++ soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2); ++ for (i = 0; i < 25; i++) ++ udelay(1000); ++ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ udelay(100); ++ ++ /* Clear DTR and set RTS to enter command mode */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2); ++ udelay(7); ++ ++ /* send out the control register settings for 115K 7N1 SIR operation */ ++ for (i = 0; i < sizeof(control); i++) { ++ soutp(UART_TX, control[i]); ++ /* one byte takes ~1042 usec to transmit at 9600,8N1 */ ++ udelay(1500); ++ } ++ ++ /* back to normal operation */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ udelay(50); ++ ++ udelay(1500); ++ soutp(UART_LCR, sinp(UART_LCR) | UART_LCR_DLAB); ++ ++ /* Set DLAB 1. */ ++ soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7); ++ ++ /* Set divisor to 1 => 115200 Baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 1); ++ ++ /* Set DLAB 0. */ ++ soutp(UART_LCR, sinp(UART_LCR) & (~UART_LCR_DLAB)); ++ ++ /* Set DLAB 0, 7 Bit */ ++ soutp(UART_LCR, UART_LCR_WLEN7); ++ ++ /* enable interrupts */ ++ soutp(UART_IER, sinp(UART_IER)|UART_IER_RDI); ++} ++#endif ++ ++#ifdef LIRC_SIR_ACTISYS_ACT220L ++/* ++ * Derived from linux IrDA driver (net/irda/actisys.c) ++ * Drop me a mail for any kind of comment: maxx@spaceboyz.net ++ */ ++ ++void init_act220(void) ++{ ++ int i; ++ ++ /* DLAB 1 */ ++ soutp(UART_LCR, UART_LCR_DLAB|UART_LCR_WLEN7); ++ ++ /* 9600 baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 12); ++ ++ /* DLAB 0 */ ++ soutp(UART_LCR, UART_LCR_WLEN7); ++ ++ /* reset the dongle, set DTR low for 10us */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_OUT2); ++ udelay(10); ++ ++ /* back to normal (still 9600) */ ++ soutp(UART_MCR, UART_MCR_DTR|UART_MCR_RTS|UART_MCR_OUT2); ++ ++ /* ++ * send RTS pulses until we reach 115200 ++ * i hope this is really the same for act220l/act220l+ ++ */ ++ for (i = 0; i < 3; i++) { ++ udelay(10); ++ /* set RTS low for 10 us */ ++ soutp(UART_MCR, UART_MCR_DTR|UART_MCR_OUT2); ++ udelay(10); ++ /* set RTS high for 10 us */ ++ soutp(UART_MCR, UART_MCR_RTS|UART_MCR_DTR|UART_MCR_OUT2); ++ } ++ ++ /* back to normal operation */ ++ udelay(1500); /* better safe than sorry ;) */ ++ ++ /* Set DLAB 1. */ ++ soutp(UART_LCR, UART_LCR_DLAB | UART_LCR_WLEN7); ++ ++ /* Set divisor to 1 => 115200 Baud */ ++ soutp(UART_DLM, 0); ++ soutp(UART_DLL, 1); ++ ++ /* Set DLAB 0, 7 Bit */ ++ /* The dongle doesn't seem to have any problems with operation at 7N1 */ ++ soutp(UART_LCR, UART_LCR_WLEN7); ++ ++ /* enable interrupts */ ++ soutp(UART_IER, UART_IER_RDI); ++} ++#endif ++ ++static int init_lirc_sir(void) ++{ ++ int retval; ++ ++ init_waitqueue_head(&lirc_read_queue); ++ retval = init_port(); ++ if (retval < 0) ++ return retval; ++ init_hardware(); ++ printk(KERN_INFO LIRC_DRIVER_NAME ++ ": Installed.\n"); ++ return 0; ++} ++ ++ ++static int __init lirc_sir_init(void) ++{ ++ int retval; ++ ++ retval = init_chrdev(); ++ if (retval < 0) ++ return retval; ++ retval = init_lirc_sir(); ++ if (retval) { ++ drop_chrdev(); ++ return retval; ++ } ++ return 0; ++} ++ ++static void __exit lirc_sir_exit(void) ++{ ++ drop_hardware(); ++ drop_chrdev(); ++ drop_port(); ++ printk(KERN_INFO LIRC_DRIVER_NAME ": Uninstalled.\n"); ++} ++ ++module_init(lirc_sir_init); ++module_exit(lirc_sir_exit); ++ ++#ifdef LIRC_SIR_TEKRAM ++MODULE_DESCRIPTION("Infrared receiver driver for Tekram Irmate 210"); ++MODULE_AUTHOR("Christoph Bartelmus"); ++#elif defined(LIRC_ON_SA1100) ++MODULE_DESCRIPTION("LIRC driver for StrongARM SA1100 embedded microprocessor"); ++MODULE_AUTHOR("Christoph Bartelmus"); ++#elif defined(LIRC_SIR_ACTISYS_ACT200L) ++MODULE_DESCRIPTION("LIRC driver for Actisys Act200L"); ++MODULE_AUTHOR("Karl Bongers"); ++#elif defined(LIRC_SIR_ACTISYS_ACT220L) ++MODULE_DESCRIPTION("LIRC driver for Actisys Act220L(+)"); ++MODULE_AUTHOR("Jan Roemisch"); ++#else ++MODULE_DESCRIPTION("Infrared receiver driver for SIR type serial ports"); ++MODULE_AUTHOR("Milan Pikula"); ++#endif ++MODULE_LICENSE("GPL"); ++ ++#ifdef LIRC_ON_SA1100 ++module_param(irq, int, S_IRUGO); ++MODULE_PARM_DESC(irq, "Interrupt (16)"); ++#else ++module_param(io, int, S_IRUGO); ++MODULE_PARM_DESC(io, "I/O address base (0x3f8 or 0x2f8)"); ++ ++module_param(irq, int, S_IRUGO); ++MODULE_PARM_DESC(irq, "Interrupt (4 or 3)"); ++ ++module_param(threshold, int, S_IRUGO); ++MODULE_PARM_DESC(threshold, "space detection threshold (3)"); ++#endif ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); +diff --git a/drivers/input/lirc/lirc_streamzap.c b/drivers/input/lirc/lirc_streamzap.c +new file mode 100644 +index 0000000..87db864 +--- /dev/null ++++ b/drivers/input/lirc/lirc_streamzap.c +@@ -0,0 +1,821 @@ ++/* ++ * Streamzap Remote Control driver ++ * ++ * Copyright (c) 2005 Christoph Bartelmus ++ * ++ * This driver was based on the work of Greg Wickham and Adrian ++ * Dewhurst. It was substantially rewritten to support correct signal ++ * gaps and now maintains a delay buffer, which is used to present ++ * consistent timing behaviour to user space applications. Without the ++ * delay buffer an ugly hack would be required in lircd, which can ++ * cause sluggish signal decoding in certain situations. ++ * ++ * This driver is based on the USB skeleton driver packaged with the ++ * kernel; copyright (C) 2001-2003 Greg Kroah-Hartman (greg@kroah.com) ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++#define DRIVER_VERSION "1.28" ++#define DRIVER_NAME "lirc_streamzap" ++#define DRIVER_DESC "Streamzap Remote Control driver" ++ ++static int debug; ++ ++#define USB_STREAMZAP_VENDOR_ID 0x0e9c ++#define USB_STREAMZAP_PRODUCT_ID 0x0000 ++ ++/* Use our own dbg macro */ ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG DRIVER_NAME "[%d]: " \ ++ fmt "\n", ## args); \ ++ } while (0) ++ ++/* table of devices that work with this driver */ ++static struct usb_device_id streamzap_table[] = { ++ /* Streamzap Remote Control */ ++ { USB_DEVICE(USB_STREAMZAP_VENDOR_ID, USB_STREAMZAP_PRODUCT_ID) }, ++ /* Terminating entry */ ++ { } ++}; ++ ++MODULE_DEVICE_TABLE(usb, streamzap_table); ++ ++#define STREAMZAP_PULSE_MASK 0xf0 ++#define STREAMZAP_SPACE_MASK 0x0f ++#define STREAMZAP_TIMEOUT 0xff ++#define STREAMZAP_RESOLUTION 256 ++ ++/* number of samples buffered */ ++#define STREAMZAP_BUF_LEN 128 ++ ++enum StreamzapDecoderState { ++ PulseSpace, ++ FullPulse, ++ FullSpace, ++ IgnorePulse ++}; ++ ++/* Structure to hold all of our device specific stuff ++ * ++ * some remarks regarding locking: ++ * theoretically this struct can be accessed from three threads: ++ * ++ * - from lirc_dev through set_use_inc/set_use_dec ++ * ++ * - from the USB layer throuh probe/disconnect/irq ++ * ++ * Careful placement of lirc_register_driver/lirc_unregister_driver ++ * calls will prevent conflicts. lirc_dev makes sure that ++ * set_use_inc/set_use_dec are not being executed and will not be ++ * called after lirc_unregister_driver returns. ++ * ++ * - by the timer callback ++ * ++ * The timer is only running when the device is connected and the ++ * LIRC device is open. Making sure the timer is deleted by ++ * set_use_dec will make conflicts impossible. ++ */ ++struct usb_streamzap { ++ ++ /* usb */ ++ /* save off the usb device pointer */ ++ struct usb_device *udev; ++ /* the interface for this device */ ++ struct usb_interface *interface; ++ ++ /* buffer & dma */ ++ unsigned char *buf_in; ++ dma_addr_t dma_in; ++ unsigned int buf_in_len; ++ ++ struct usb_endpoint_descriptor *endpoint; ++ ++ /* IRQ */ ++ struct urb *urb_in; ++ ++ /* lirc */ ++ struct lirc_driver *driver; ++ struct lirc_buffer *delay_buf; ++ ++ /* timer used to support delay buffering */ ++ struct timer_list delay_timer; ++ int timer_running; ++ spinlock_t timer_lock; ++ ++ /* tracks whether we are currently receiving some signal */ ++ int idle; ++ /* sum of signal lengths received since signal start */ ++ unsigned long sum; ++ /* start time of signal; necessary for gap tracking */ ++ struct timeval signal_last; ++ struct timeval signal_start; ++ enum StreamzapDecoderState decoder_state; ++ struct timer_list flush_timer; ++ int flush; ++ int in_use; ++ int timeout_enabled; ++}; ++ ++ ++/* local function prototypes */ ++static int streamzap_probe(struct usb_interface *interface, ++ const struct usb_device_id *id); ++static void streamzap_disconnect(struct usb_interface *interface); ++static void usb_streamzap_irq(struct urb *urb); ++static int streamzap_use_inc(void *data); ++static void streamzap_use_dec(void *data); ++static int streamzap_ioctl(struct inode *node, struct file *filep, ++ unsigned int cmd, unsigned long arg); ++static int streamzap_suspend(struct usb_interface *intf, pm_message_t message); ++static int streamzap_resume(struct usb_interface *intf); ++ ++/* usb specific object needed to register this driver with the usb subsystem */ ++ ++static struct usb_driver streamzap_driver = { ++ .name = DRIVER_NAME, ++ .probe = streamzap_probe, ++ .disconnect = streamzap_disconnect, ++ .suspend = streamzap_suspend, ++ .resume = streamzap_resume, ++ .id_table = streamzap_table, ++}; ++ ++static void stop_timer(struct usb_streamzap *sz) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&sz->timer_lock, flags); ++ if (sz->timer_running) { ++ sz->timer_running = 0; ++ spin_unlock_irqrestore(&sz->timer_lock, flags); ++ del_timer_sync(&sz->delay_timer); ++ } else { ++ spin_unlock_irqrestore(&sz->timer_lock, flags); ++ } ++} ++ ++static void flush_timeout(unsigned long arg) ++{ ++ struct usb_streamzap *sz = (struct usb_streamzap *) arg; ++ ++ /* finally start accepting data */ ++ sz->flush = 0; ++} ++static void delay_timeout(unsigned long arg) ++{ ++ unsigned long flags; ++ /* deliver data every 10 ms */ ++ static unsigned long timer_inc = ++ (10000/(1000000/HZ)) == 0 ? 1 : (10000/(1000000/HZ)); ++ struct usb_streamzap *sz = (struct usb_streamzap *) arg; ++ int data; ++ ++ spin_lock_irqsave(&sz->timer_lock, flags); ++ ++ if (!lirc_buffer_empty(sz->delay_buf) && ++ !lirc_buffer_full(sz->driver->rbuf)) { ++ lirc_buffer_read(sz->delay_buf, (unsigned char *) &data); ++ lirc_buffer_write(sz->driver->rbuf, (unsigned char *) &data); ++ } ++ if (!lirc_buffer_empty(sz->delay_buf)) { ++ while (lirc_buffer_available(sz->delay_buf) < ++ STREAMZAP_BUF_LEN / 2 && ++ !lirc_buffer_full(sz->driver->rbuf)) { ++ lirc_buffer_read(sz->delay_buf, ++ (unsigned char *) &data); ++ lirc_buffer_write(sz->driver->rbuf, ++ (unsigned char *) &data); ++ } ++ if (sz->timer_running) { ++ sz->delay_timer.expires = jiffies + timer_inc; ++ add_timer(&sz->delay_timer); ++ } ++ } else { ++ sz->timer_running = 0; ++ } ++ ++ if (!lirc_buffer_empty(sz->driver->rbuf)) ++ wake_up(&sz->driver->rbuf->wait_poll); ++ ++ spin_unlock_irqrestore(&sz->timer_lock, flags); ++} ++ ++static void flush_delay_buffer(struct usb_streamzap *sz) ++{ ++ int data; ++ int empty = 1; ++ ++ while (!lirc_buffer_empty(sz->delay_buf)) { ++ empty = 0; ++ lirc_buffer_read(sz->delay_buf, (unsigned char *) &data); ++ if (!lirc_buffer_full(sz->driver->rbuf)) { ++ lirc_buffer_write(sz->driver->rbuf, ++ (unsigned char *) &data); ++ } else { ++ dprintk("buffer overflow", sz->driver->minor); ++ } ++ } ++ if (!empty) ++ wake_up(&sz->driver->rbuf->wait_poll); ++} ++ ++static void push(struct usb_streamzap *sz, unsigned char *data) ++{ ++ unsigned long flags; ++ ++ spin_lock_irqsave(&sz->timer_lock, flags); ++ if (lirc_buffer_full(sz->delay_buf)) { ++ int read_data; ++ ++ lirc_buffer_read(sz->delay_buf, ++ (unsigned char *) &read_data); ++ if (!lirc_buffer_full(sz->driver->rbuf)) { ++ lirc_buffer_write(sz->driver->rbuf, ++ (unsigned char *) &read_data); ++ } else { ++ dprintk("buffer overflow", sz->driver->minor); ++ } ++ } ++ ++ lirc_buffer_write(sz->delay_buf, data); ++ ++ if (!sz->timer_running) { ++ sz->delay_timer.expires = jiffies + HZ/10; ++ add_timer(&sz->delay_timer); ++ sz->timer_running = 1; ++ } ++ ++ spin_unlock_irqrestore(&sz->timer_lock, flags); ++} ++ ++static void push_full_pulse(struct usb_streamzap *sz, ++ unsigned char value) ++{ ++ int pulse; ++ ++ if (sz->idle) { ++ long deltv; ++ int tmp; ++ ++ sz->signal_last = sz->signal_start; ++ do_gettimeofday(&sz->signal_start); ++ ++ deltv = sz->signal_start.tv_sec-sz->signal_last.tv_sec; ++ if (deltv > 15) { ++ /* really long time */ ++ tmp = LIRC_SPACE(LIRC_VALUE_MASK); ++ } else { ++ tmp = (int) (deltv*1000000+ ++ sz->signal_start.tv_usec - ++ sz->signal_last.tv_usec); ++ tmp -= sz->sum; ++ tmp = LIRC_SPACE(tmp); ++ } ++ dprintk("ls %u", sz->driver->minor, tmp); ++ push(sz, (char *)&tmp); ++ ++ sz->idle = 0; ++ sz->sum = 0; ++ } ++ ++ pulse = ((int) value) * STREAMZAP_RESOLUTION; ++ pulse += STREAMZAP_RESOLUTION / 2; ++ sz->sum += pulse; ++ pulse = LIRC_PULSE(pulse); ++ ++ dprintk("p %u", sz->driver->minor, pulse & PULSE_MASK); ++ push(sz, (char *)&pulse); ++} ++ ++static void push_half_pulse(struct usb_streamzap *sz, ++ unsigned char value) ++{ ++ push_full_pulse(sz, (value & STREAMZAP_PULSE_MASK)>>4); ++} ++ ++static void push_full_space(struct usb_streamzap *sz, ++ unsigned char value) ++{ ++ int space; ++ ++ space = ((int) value)*STREAMZAP_RESOLUTION; ++ space += STREAMZAP_RESOLUTION/2; ++ sz->sum += space; ++ space = LIRC_SPACE(space); ++ dprintk("s %u", sz->driver->minor, space); ++ push(sz, (char *)&space); ++} ++ ++static void push_half_space(struct usb_streamzap *sz, ++ unsigned char value) ++{ ++ push_full_space(sz, value & STREAMZAP_SPACE_MASK); ++} ++ ++/** ++ * usb_streamzap_irq - IRQ handler ++ * ++ * This procedure is invoked on reception of data from ++ * the usb remote. ++ */ ++static void usb_streamzap_irq(struct urb *urb) ++{ ++ struct usb_streamzap *sz; ++ int len; ++ unsigned int i = 0; ++ ++ if (!urb) ++ return; ++ ++ sz = urb->context; ++ len = urb->actual_length; ++ ++ switch (urb->status) { ++ case -ECONNRESET: ++ case -ENOENT: ++ case -ESHUTDOWN: ++ /* ++ * this urb is terminated, clean up. ++ * sz might already be invalid at this point ++ */ ++ dprintk("urb status: %d", -1, urb->status); ++ return; ++ default: ++ break; ++ } ++ ++ dprintk("received %d", sz->driver->minor, urb->actual_length); ++ if (!sz->flush) { ++ for (i = 0; i < urb->actual_length; i++) { ++ dprintk("%d: %x", sz->driver->minor, ++ i, (unsigned char) sz->buf_in[i]); ++ switch (sz->decoder_state) { ++ case PulseSpace: ++ if ((sz->buf_in[i]&STREAMZAP_PULSE_MASK) == ++ STREAMZAP_PULSE_MASK) { ++ sz->decoder_state = FullPulse; ++ continue; ++ } else if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK) ++ == STREAMZAP_SPACE_MASK) { ++ push_half_pulse(sz, sz->buf_in[i]); ++ sz->decoder_state = FullSpace; ++ continue; ++ } else { ++ push_half_pulse(sz, sz->buf_in[i]); ++ push_half_space(sz, sz->buf_in[i]); ++ } ++ break; ++ case FullPulse: ++ push_full_pulse(sz, sz->buf_in[i]); ++ sz->decoder_state = IgnorePulse; ++ break; ++ case FullSpace: ++ if (sz->buf_in[i] == STREAMZAP_TIMEOUT) { ++ sz->idle = 1; ++ stop_timer(sz); ++ if (sz->timeout_enabled) { ++ int timeout = ++ LIRC_TIMEOUT ++ (STREAMZAP_TIMEOUT * ++ STREAMZAP_RESOLUTION); ++ push(sz, (char *)&timeout); ++ } ++ flush_delay_buffer(sz); ++ } else ++ push_full_space(sz, sz->buf_in[i]); ++ sz->decoder_state = PulseSpace; ++ break; ++ case IgnorePulse: ++ if ((sz->buf_in[i]&STREAMZAP_SPACE_MASK) == ++ STREAMZAP_SPACE_MASK) { ++ sz->decoder_state = FullSpace; ++ continue; ++ } ++ push_half_space(sz, sz->buf_in[i]); ++ sz->decoder_state = PulseSpace; ++ break; ++ } ++ } ++ } ++ ++ usb_submit_urb(urb, GFP_ATOMIC); ++ ++ return; ++} ++ ++static struct file_operations streamzap_fops = { ++ .owner = THIS_MODULE, ++ .ioctl = streamzap_ioctl, ++ .read = lirc_dev_fop_read, ++ .write = lirc_dev_fop_write, ++ .poll = lirc_dev_fop_poll, ++ .open = lirc_dev_fop_open, ++ .release = lirc_dev_fop_close, ++}; ++ ++ ++/** ++ * streamzap_probe ++ * ++ * Called by usb-core to associated with a candidate device ++ * On any failure the return value is the ERROR ++ * On success return 0 ++ */ ++static int streamzap_probe(struct usb_interface *interface, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *udev = interface_to_usbdev(interface); ++ struct usb_host_interface *iface_host; ++ struct usb_streamzap *sz; ++ struct lirc_driver *driver; ++ struct lirc_buffer *lirc_buf; ++ struct lirc_buffer *delay_buf; ++ char buf[63], name[128] = ""; ++ int retval = -ENOMEM; ++ int minor = 0; ++ ++ /* Allocate space for device driver specific data */ ++ sz = kzalloc(sizeof(struct usb_streamzap), GFP_KERNEL); ++ if (sz == NULL) ++ return -ENOMEM; ++ ++ sz->udev = udev; ++ sz->interface = interface; ++ ++ /* Check to ensure endpoint information matches requirements */ ++ iface_host = interface->cur_altsetting; ++ ++ if (iface_host->desc.bNumEndpoints != 1) { ++ err("%s: Unexpected desc.bNumEndpoints (%d)", __func__, ++ iface_host->desc.bNumEndpoints); ++ retval = -ENODEV; ++ goto free_sz; ++ } ++ ++ sz->endpoint = &(iface_host->endpoint[0].desc); ++ if ((sz->endpoint->bEndpointAddress & USB_ENDPOINT_DIR_MASK) ++ != USB_DIR_IN) { ++ err("%s: endpoint doesn't match input device 02%02x", ++ __func__, sz->endpoint->bEndpointAddress); ++ retval = -ENODEV; ++ goto free_sz; ++ } ++ ++ if ((sz->endpoint->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK) ++ != USB_ENDPOINT_XFER_INT) { ++ err("%s: endpoint attributes don't match xfer 02%02x", ++ __func__, sz->endpoint->bmAttributes); ++ retval = -ENODEV; ++ goto free_sz; ++ } ++ ++ if (sz->endpoint->wMaxPacketSize == 0) { ++ err("%s: endpoint message size==0? ", __func__); ++ retval = -ENODEV; ++ goto free_sz; ++ } ++ ++ /* Allocate the USB buffer and IRQ URB */ ++ ++ sz->buf_in_len = sz->endpoint->wMaxPacketSize; ++ sz->buf_in = usb_buffer_alloc(sz->udev, sz->buf_in_len, ++ GFP_ATOMIC, &sz->dma_in); ++ if (sz->buf_in == NULL) ++ goto free_sz; ++ ++ sz->urb_in = usb_alloc_urb(0, GFP_KERNEL); ++ if (sz->urb_in == NULL) ++ goto free_sz; ++ ++ /* Connect this device to the LIRC sub-system */ ++ driver = kzalloc(sizeof(struct lirc_driver), GFP_KERNEL); ++ if (!driver) ++ goto free_sz; ++ ++ lirc_buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!lirc_buf) ++ goto free_driver; ++ if (lirc_buffer_init(lirc_buf, sizeof(int), STREAMZAP_BUF_LEN)) ++ goto kfree_lirc_buf; ++ ++ delay_buf = kmalloc(sizeof(struct lirc_buffer), GFP_KERNEL); ++ if (!delay_buf) ++ goto free_lirc_buf; ++ if (lirc_buffer_init(delay_buf, sizeof(int), STREAMZAP_BUF_LEN)) ++ goto kfree_delay_buf; ++ ++ sz->driver = driver; ++ strcpy(sz->driver->name, DRIVER_NAME); ++ sz->driver->minor = -1; ++ sz->driver->sample_rate = 0; ++ sz->driver->code_length = sizeof(int) * 8; ++ sz->driver->features = LIRC_CAN_REC_MODE2 | ++ LIRC_CAN_GET_REC_RESOLUTION | ++ LIRC_CAN_SET_REC_TIMEOUT; ++ sz->driver->data = sz; ++ sz->driver->min_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION; ++ sz->driver->max_timeout = STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION; ++ sz->driver->rbuf = lirc_buf; ++ sz->delay_buf = delay_buf; ++ sz->driver->set_use_inc = &streamzap_use_inc; ++ sz->driver->set_use_dec = &streamzap_use_dec; ++ sz->driver->fops = &streamzap_fops; ++ sz->driver->dev = &interface->dev; ++ sz->driver->owner = THIS_MODULE; ++ ++ sz->idle = 1; ++ sz->decoder_state = PulseSpace; ++ init_timer(&sz->delay_timer); ++ sz->delay_timer.function = delay_timeout; ++ sz->delay_timer.data = (unsigned long) sz; ++ sz->timer_running = 0; ++ spin_lock_init(&sz->timer_lock); ++ ++ init_timer(&sz->flush_timer); ++ sz->flush_timer.function = flush_timeout; ++ sz->flush_timer.data = (unsigned long) sz; ++ /* Complete final initialisations */ ++ ++ usb_fill_int_urb(sz->urb_in, udev, ++ usb_rcvintpipe(udev, sz->endpoint->bEndpointAddress), ++ sz->buf_in, sz->buf_in_len, usb_streamzap_irq, sz, ++ sz->endpoint->bInterval); ++ sz->urb_in->transfer_dma = sz->dma_in; ++ sz->urb_in->transfer_flags |= URB_NO_TRANSFER_DMA_MAP; ++ ++ if (udev->descriptor.iManufacturer ++ && usb_string(udev, udev->descriptor.iManufacturer, ++ buf, sizeof(buf)) > 0) ++ strlcpy(name, buf, sizeof(name)); ++ ++ if (udev->descriptor.iProduct ++ && usb_string(udev, udev->descriptor.iProduct, ++ buf, sizeof(buf)) > 0) ++ snprintf(name + strlen(name), sizeof(name) - strlen(name), ++ " %s", buf); ++ ++ minor = lirc_register_driver(driver); ++ ++ if (minor < 0) ++ goto free_delay_buf; ++ ++ sz->driver->minor = minor; ++ ++ usb_set_intfdata(interface, sz); ++ ++ printk(KERN_INFO DRIVER_NAME "[%d]: %s on usb%d:%d attached\n", ++ sz->driver->minor, name, ++ udev->bus->busnum, sz->udev->devnum); ++ ++ return 0; ++ ++free_delay_buf: ++ lirc_buffer_free(sz->delay_buf); ++kfree_delay_buf: ++ kfree(delay_buf); ++free_lirc_buf: ++ lirc_buffer_free(sz->driver->rbuf); ++kfree_lirc_buf: ++ kfree(lirc_buf); ++free_driver: ++ kfree(driver); ++free_sz: ++ if (retval == -ENOMEM) ++ err("Out of memory"); ++ ++ if (sz) { ++ usb_free_urb(sz->urb_in); ++ usb_buffer_free(udev, sz->buf_in_len, sz->buf_in, sz->dma_in); ++ kfree(sz); ++ } ++ ++ return retval; ++} ++ ++static int streamzap_use_inc(void *data) ++{ ++ struct usb_streamzap *sz = data; ++ ++ if (!sz) { ++ dprintk("%s called with no context", -1, __func__); ++ return -EINVAL; ++ } ++ dprintk("set use inc", sz->driver->minor); ++ ++ lirc_buffer_clear(sz->driver->rbuf); ++ lirc_buffer_clear(sz->delay_buf); ++ ++ sz->flush_timer.expires = jiffies + HZ; ++ sz->flush = 1; ++ add_timer(&sz->flush_timer); ++ ++ sz->urb_in->dev = sz->udev; ++ if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) { ++ dprintk("open result = -EIO error submitting urb", ++ sz->driver->minor); ++ return -EIO; ++ } ++ sz->in_use++; ++ ++ return 0; ++} ++ ++static void streamzap_use_dec(void *data) ++{ ++ struct usb_streamzap *sz = data; ++ ++ if (!sz) { ++ dprintk("%s called with no context", -1, __func__); ++ return; ++ } ++ dprintk("set use dec", sz->driver->minor); ++ ++ if (sz->flush) { ++ sz->flush = 0; ++ del_timer_sync(&sz->flush_timer); ++ } ++ ++ usb_kill_urb(sz->urb_in); ++ ++ stop_timer(sz); ++ ++ sz->in_use--; ++} ++ ++static int streamzap_ioctl(struct inode *node, struct file *filep, ++ unsigned int cmd, unsigned long arg) ++{ ++ int result = 0; ++ int val; ++ struct usb_streamzap *sz = lirc_get_pdata(filep); ++ ++ switch (cmd) { ++ case LIRC_GET_REC_RESOLUTION: ++ result = put_user(STREAMZAP_RESOLUTION, (unsigned int *) arg); ++ break; ++ case LIRC_SET_REC_TIMEOUT: ++ result = get_user(val, (int *)arg); ++ if (result == 0) { ++ if (val == STREAMZAP_TIMEOUT * STREAMZAP_RESOLUTION) ++ sz->timeout_enabled = 1; ++ else if (val == 0) ++ sz->timeout_enabled = 0; ++ else ++ result = -EINVAL; ++ } ++ break; ++ default: ++ return lirc_dev_fop_ioctl(node, filep, cmd, arg); ++ } ++ return result; ++} ++ ++/** ++ * streamzap_disconnect ++ * ++ * Called by the usb core when the device is removed from the system. ++ * ++ * This routine guarantees that the driver will not submit any more urbs ++ * by clearing dev->udev. It is also supposed to terminate any currently ++ * active urbs. Unfortunately, usb_bulk_msg(), used in streamzap_read(), ++ * does not provide any way to do this. ++ */ ++static void streamzap_disconnect(struct usb_interface *interface) ++{ ++ struct usb_streamzap *sz; ++ int errnum; ++ int minor; ++ ++ sz = usb_get_intfdata(interface); ++ ++ /* unregister from the LIRC sub-system */ ++ ++ errnum = lirc_unregister_driver(sz->driver->minor); ++ if (errnum != 0) ++ dprintk("error in lirc_unregister: (returned %d)", ++ sz->driver->minor, errnum); ++ ++ lirc_buffer_free(sz->delay_buf); ++ lirc_buffer_free(sz->driver->rbuf); ++ ++ /* unregister from the USB sub-system */ ++ ++ usb_free_urb(sz->urb_in); ++ ++ usb_buffer_free(sz->udev, sz->buf_in_len, sz->buf_in, sz->dma_in); ++ ++ minor = sz->driver->minor; ++ kfree(sz->driver->rbuf); ++ kfree(sz->driver); ++ kfree(sz->delay_buf); ++ kfree(sz); ++ ++ printk(KERN_INFO DRIVER_NAME "[%d]: disconnected\n", minor); ++} ++ ++static int streamzap_suspend(struct usb_interface *intf, pm_message_t message) ++{ ++ struct usb_streamzap *sz = usb_get_intfdata(intf); ++ ++ printk(KERN_INFO DRIVER_NAME "[%d]: suspend\n", sz->driver->minor); ++ if (sz->in_use) { ++ if (sz->flush) { ++ sz->flush = 0; ++ del_timer_sync(&sz->flush_timer); ++ } ++ ++ stop_timer(sz); ++ ++ usb_kill_urb(sz->urb_in); ++ } ++ return 0; ++} ++ ++static int streamzap_resume(struct usb_interface *intf) ++{ ++ struct usb_streamzap *sz = usb_get_intfdata(intf); ++ ++ lirc_buffer_clear(sz->driver->rbuf); ++ lirc_buffer_clear(sz->delay_buf); ++ ++ if (sz->in_use) { ++ sz->flush_timer.expires = jiffies + HZ; ++ sz->flush = 1; ++ add_timer(&sz->flush_timer); ++ ++ sz->urb_in->dev = sz->udev; ++ if (usb_submit_urb(sz->urb_in, GFP_ATOMIC)) { ++ dprintk("open result = -EIO error submitting urb", ++ sz->driver->minor); ++ return -EIO; ++ } ++ } ++ return 0; ++} ++ ++/** ++ * usb_streamzap_init ++ */ ++static int __init usb_streamzap_init(void) ++{ ++ int result; ++ ++ /* register this driver with the USB subsystem */ ++ result = usb_register(&streamzap_driver); ++ ++ if (result) { ++ err("usb_register failed. Error number %d", ++ result); ++ return result; ++ } ++ ++ printk(KERN_INFO DRIVER_NAME " " DRIVER_VERSION " registered\n"); ++ return 0; ++} ++ ++/** ++ * usb_streamzap_exit ++ */ ++static void __exit usb_streamzap_exit(void) ++{ ++ usb_deregister(&streamzap_driver); ++} ++ ++ ++module_init(usb_streamzap_init); ++module_exit(usb_streamzap_exit); ++ ++MODULE_AUTHOR("Christoph Bartelmus, Greg Wickham, Adrian Dewhurst"); ++MODULE_DESCRIPTION(DRIVER_DESC); ++MODULE_LICENSE("GPL"); ++ ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); +diff --git a/drivers/input/lirc/lirc_ttusbir.c b/drivers/input/lirc/lirc_ttusbir.c +new file mode 100644 +index 0000000..b0a4e8b +--- /dev/null ++++ b/drivers/input/lirc/lirc_ttusbir.c +@@ -0,0 +1,397 @@ ++/* ++ * lirc_ttusbir.c ++ * ++ * lirc_ttusbir - LIRC device driver for the TechnoTrend USB IR Receiver ++ * ++ * Copyright (C) 2007 Stefan Macher ++ * ++ * This LIRC driver provides access to the TechnoTrend USB IR Receiver. ++ * The receiver delivers the IR signal as raw sampled true/false data in ++ * isochronous USB packets each of size 128 byte. ++ * Currently the driver reduces the sampling rate by factor of 8 as this ++ * is still more than enough to decode RC-5 - others should be analyzed. ++ * But the driver does not rely on RC-5 it should be able to decode every ++ * IR signal that is not too fast. ++ */ ++ ++/* ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include "lirc_dev.h" ++ ++MODULE_DESCRIPTION("TechnoTrend USB IR device driver for LIRC"); ++MODULE_AUTHOR("Stefan Macher (st_maker-lirc@yahoo.de)"); ++MODULE_LICENSE("GPL"); ++ ++/* #define DEBUG */ ++#ifdef DEBUG ++#define DPRINTK printk ++#else ++#define DPRINTK(_x_, a...) ++#endif ++ ++/* function declarations */ ++static int probe(struct usb_interface *intf, const struct usb_device_id *id); ++static void disconnect(struct usb_interface *intf); ++static void urb_complete(struct urb *urb); ++static int set_use_inc(void *data); ++static void set_use_dec(void *data); ++ ++static int num_urbs = 2; ++module_param(num_urbs, int, S_IRUGO); ++MODULE_PARM_DESC(num_urbs, ++ "Number of URBs in queue. Try to increase to 4 in case " ++ "of problems (default: 2; minimum: 2)"); ++ ++/* table of devices that work with this driver */ ++static struct usb_device_id device_id_table[] = { ++ /* TechnoTrend USB IR Receiver */ ++ { USB_DEVICE(0x0B48, 0x2003) }, ++ /* Terminating entry */ ++ { } ++}; ++MODULE_DEVICE_TABLE(usb, device_id_table); ++ ++/* USB driver definition */ ++static struct usb_driver usb_driver = { ++ .name = "TTUSBIR", ++ .id_table = &(device_id_table[0]), ++ .probe = probe, ++ .disconnect = disconnect, ++}; ++ ++/* USB device definition */ ++struct ttusbir_device { ++ struct usb_driver *usb_driver; ++ struct usb_device *udev; ++ struct usb_interface *interf; ++ struct usb_class_driver class_driver; ++ unsigned int ifnum; /* Interface number to use */ ++ unsigned int alt_setting; /* alternate setting to use */ ++ unsigned int endpoint; /* Endpoint to use */ ++ struct urb **urb; /* num_urb URB pointers*/ ++ char **buffer; /* 128 byte buffer for each URB */ ++ struct lirc_buffer rbuf; /* Buffer towards LIRC */ ++ struct lirc_driver driver; ++ int minor; ++ int last_pulse; /* remembers if last received byte was pulse or space */ ++ int last_num; /* remembers how many last bytes appeared */ ++ int opened; ++}; ++ ++/*** LIRC specific functions ***/ ++static int set_use_inc(void *data) ++{ ++ int i, retval; ++ struct ttusbir_device *ttusbir = data; ++ ++ DPRINTK("Sending first URBs\n"); ++ /* @TODO Do I need to check if I am already opened */ ++ ttusbir->opened = 1; ++ ++ for (i = 0; i < num_urbs; i++) { ++ retval = usb_submit_urb(ttusbir->urb[i], GFP_KERNEL); ++ if (retval) { ++ err("%s: usb_submit_urb failed on urb %d", ++ __func__, i); ++ return retval; ++ } ++ } ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++ struct ttusbir_device *ttusbir = data; ++ ++ DPRINTK("Device closed\n"); ++ ++ ttusbir->opened = 0; ++} ++ ++/*** USB specific functions ***/ ++ ++/* ++ * This mapping table is used to do a very simple filtering of the ++ * input signal. ++ * For a value with at least 4 bits set it returns 0xFF otherwise ++ * 0x00. For faster IR signals this can not be used. But for RC-5 we ++ * still have about 14 samples per pulse/space, i.e. we sample with 14 ++ * times higher frequency than the signal frequency ++ */ ++const unsigned char map_table[] = ++{ ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x00, 0x00, 0x00, 0xFF, 0x00, 0xFF, 0xFF, 0xFF, ++ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0x00, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, ++ 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF ++}; ++ ++static void urb_complete(struct urb *urb) ++{ ++ struct ttusbir_device *ttusbir; ++ unsigned char *buf; ++ int i; ++ int l; ++ ++ ttusbir = urb->context; ++ ++ if (!ttusbir->opened) ++ return; ++ ++ buf = (unsigned char *)urb->transfer_buffer; ++ ++ for (i = 0; i < 128; i++) { ++ /* Here we do the filtering and some kind of down sampling */ ++ buf[i] = ~map_table[buf[i]]; ++ if (ttusbir->last_pulse == buf[i]) { ++ if (ttusbir->last_num < PULSE_MASK/63) ++ ttusbir->last_num++; ++ /* ++ * else we are in a idle period and do not need to ++ * increment any longer ++ */ ++ } else { ++ l = ttusbir->last_num * 62; /* about 62 = us/byte */ ++ if (ttusbir->last_pulse) /* pulse or space? */ ++ l |= PULSE_BIT; ++ if (!lirc_buffer_full(&ttusbir->rbuf)) { ++ lirc_buffer_write(&ttusbir->rbuf, (void *)&l); ++ wake_up_interruptible(&ttusbir->rbuf.wait_poll); ++ } ++ ttusbir->last_num = 0; ++ ttusbir->last_pulse = buf[i]; ++ } ++ } ++ usb_submit_urb(urb, GFP_ATOMIC); /* keep data rolling :-) */ ++} ++ ++/* ++ * Called whenever the USB subsystem thinks we could be the right driver ++ * to handle this device ++ */ ++static int probe(struct usb_interface *intf, const struct usb_device_id *id) ++{ ++ int alt_set, endp; ++ int found = 0; ++ int i, j; ++ int struct_size; ++ struct usb_host_interface *host_interf; ++ struct usb_interface_descriptor *interf_desc; ++ struct usb_host_endpoint *host_endpoint; ++ struct ttusbir_device *ttusbir; ++ ++ DPRINTK("Module ttusbir probe\n"); ++ ++ /* To reduce memory fragmentation we use only one allocation */ ++ struct_size = sizeof(struct ttusbir_device) + ++ (sizeof(struct urb *) * num_urbs) + ++ (sizeof(char *) * num_urbs) + ++ (num_urbs * 128); ++ ttusbir = kzalloc(struct_size, GFP_KERNEL); ++ if (!ttusbir) ++ return -ENOMEM; ++ ++ ttusbir->urb = (struct urb **)((char *)ttusbir + ++ sizeof(struct ttusbir_device)); ++ ttusbir->buffer = (char **)((char *)ttusbir->urb + ++ (sizeof(struct urb *) * num_urbs)); ++ for (i = 0; i < num_urbs; i++) ++ ttusbir->buffer[i] = (char *)ttusbir->buffer + ++ (sizeof(char *)*num_urbs) + (i * 128); ++ ++ ttusbir->usb_driver = &usb_driver; ++ ttusbir->alt_setting = -1; ++ /* @TODO check if error can be returned */ ++ ttusbir->udev = usb_get_dev(interface_to_usbdev(intf)); ++ ttusbir->interf = intf; ++ ttusbir->last_pulse = 0x00; ++ ttusbir->last_num = 0; ++ ++ /* ++ * Now look for interface setting we can handle ++ * We are searching for the alt setting where end point ++ * 0x82 has max packet size 16 ++ */ ++ for (alt_set = 0; alt_set < intf->num_altsetting && !found; alt_set++) { ++ host_interf = &intf->altsetting[alt_set]; ++ interf_desc = &host_interf->desc; ++ for (endp = 0; endp < interf_desc->bNumEndpoints; endp++) { ++ host_endpoint = &host_interf->endpoint[endp]; ++ if ((host_endpoint->desc.bEndpointAddress == 0x82) && ++ (host_endpoint->desc.wMaxPacketSize == 0x10)) { ++ ttusbir->alt_setting = alt_set; ++ ttusbir->endpoint = endp; ++ found = 1; ++ break; ++ } ++ } ++ } ++ if (ttusbir->alt_setting != -1) ++ DPRINTK("alt setting: %d\n", ttusbir->alt_setting); ++ else { ++ err("Could not find alternate setting\n"); ++ kfree(ttusbir); ++ return -EINVAL; ++ } ++ ++ /* OK lets setup this interface setting */ ++ usb_set_interface(ttusbir->udev, 0, ttusbir->alt_setting); ++ ++ /* Store device info in interface structure */ ++ usb_set_intfdata(intf, ttusbir); ++ ++ /* Register as a LIRC driver */ ++ if (lirc_buffer_init(&ttusbir->rbuf, sizeof(int), 256) < 0) { ++ err("Could not get memory for LIRC data buffer\n"); ++ usb_set_intfdata(intf, NULL); ++ kfree(ttusbir); ++ return -ENOMEM; ++ } ++ strcpy(ttusbir->driver.name, "TTUSBIR"); ++ ttusbir->driver.minor = -1; ++ ttusbir->driver.code_length = 1; ++ ttusbir->driver.sample_rate = 0; ++ ttusbir->driver.data = ttusbir; ++ ttusbir->driver.add_to_buf = NULL; ++ ttusbir->driver.rbuf = &ttusbir->rbuf; ++ ttusbir->driver.set_use_inc = set_use_inc; ++ ttusbir->driver.set_use_dec = set_use_dec; ++ ttusbir->driver.dev = &intf->dev; ++ ttusbir->driver.owner = THIS_MODULE; ++ ttusbir->driver.features = LIRC_CAN_REC_MODE2; ++ ttusbir->minor = lirc_register_driver(&ttusbir->driver); ++ if (ttusbir->minor < 0) { ++ err("Error registering as LIRC driver\n"); ++ usb_set_intfdata(intf, NULL); ++ lirc_buffer_free(&ttusbir->rbuf); ++ kfree(ttusbir); ++ return -EIO; ++ } ++ ++ /* Allocate and setup the URB that we will use to talk to the device */ ++ for (i = 0; i < num_urbs; i++) { ++ ttusbir->urb[i] = usb_alloc_urb(8, GFP_KERNEL); ++ if (!ttusbir->urb[i]) { ++ err("Could not allocate memory for the URB\n"); ++ for (j = i - 1; j >= 0; j--) ++ kfree(ttusbir->urb[j]); ++ lirc_buffer_free(&ttusbir->rbuf); ++ lirc_unregister_driver(ttusbir->minor); ++ kfree(ttusbir); ++ usb_set_intfdata(intf, NULL); ++ return -ENOMEM; ++ } ++ ttusbir->urb[i]->dev = ttusbir->udev; ++ ttusbir->urb[i]->context = ttusbir; ++ ttusbir->urb[i]->pipe = usb_rcvisocpipe(ttusbir->udev, ++ ttusbir->endpoint); ++ ttusbir->urb[i]->interval = 1; ++ ttusbir->urb[i]->transfer_flags = URB_ISO_ASAP; ++ ttusbir->urb[i]->transfer_buffer = &ttusbir->buffer[i][0]; ++ ttusbir->urb[i]->complete = urb_complete; ++ ttusbir->urb[i]->number_of_packets = 8; ++ ttusbir->urb[i]->transfer_buffer_length = 128; ++ for (j = 0; j < 8; j++) { ++ ttusbir->urb[i]->iso_frame_desc[j].offset = j*16; ++ ttusbir->urb[i]->iso_frame_desc[j].length = 16; ++ } ++ } ++ return 0; ++} ++ ++/** ++ * Called when the driver is unloaded or the device is unplugged ++ */ ++static void disconnect(struct usb_interface *intf) ++{ ++ int i; ++ struct ttusbir_device *ttusbir; ++ ++ DPRINTK("Module ttusbir disconnect\n"); ++ ++ ttusbir = (struct ttusbir_device *) usb_get_intfdata(intf); ++ usb_set_intfdata(intf, NULL); ++ lirc_unregister_driver(ttusbir->minor); ++ DPRINTK("unregistered\n"); ++ ++ for (i = 0; i < num_urbs; i++) { ++ usb_kill_urb(ttusbir->urb[i]); ++ usb_free_urb(ttusbir->urb[i]); ++ } ++ DPRINTK("URBs killed\n"); ++ lirc_buffer_free(&ttusbir->rbuf); ++ kfree(ttusbir); ++} ++ ++static int ttusbir_init_module(void) ++{ ++ int result; ++ ++ DPRINTK(KERN_DEBUG "Module ttusbir init\n"); ++ ++ /* register this driver with the USB subsystem */ ++ result = usb_register(&usb_driver); ++ if (result) ++ err("usb_register failed. Error number %d", result); ++ return result; ++} ++ ++static void ttusbir_exit_module(void) ++{ ++ printk(KERN_DEBUG "Module ttusbir exit\n"); ++ usb_deregister(&usb_driver); ++} ++ ++module_init(ttusbir_init_module); ++module_exit(ttusbir_exit_module); +diff --git a/drivers/input/lirc/lirc_zilog.c b/drivers/input/lirc/lirc_zilog.c +new file mode 100644 +index 0000000..9f73430 +--- /dev/null ++++ b/drivers/input/lirc/lirc_zilog.c +@@ -0,0 +1,1388 @@ ++/* ++ * i2c IR lirc driver for devices with zilog IR processors ++ * ++ * Copyright (c) 2000 Gerd Knorr ++ * modified for PixelView (BT878P+W/FM) by ++ * Michal Kochanowicz ++ * Christoph Bartelmus ++ * modified for KNC ONE TV Station/Anubis Typhoon TView Tuner by ++ * Ulrich Mueller ++ * modified for Asus TV-Box and Creative/VisionTek BreakOut-Box by ++ * Stefan Jahn ++ * modified for inclusion into kernel sources by ++ * Jerome Brock ++ * modified for Leadtek Winfast PVR2000 by ++ * Thomas Reitmayr (treitmayr@yahoo.com) ++ * modified for Hauppauge PVR-150 IR TX device by ++ * Mark Weaver ++ * changed name from lirc_pvr150 to lirc_zilog, works on more than pvr-150 ++ * Jarod Wilson ++ * ++ * parts are cut&pasted from the lirc_i2c.c driver ++ * ++ * This program is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ++ * ++ */ ++ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++ ++#include "lirc_dev.h" ++#include ++ ++struct IR { ++ struct lirc_driver l; ++ ++ /* Device info */ ++ struct mutex ir_lock; ++ int open; ++ ++ /* RX device */ ++ struct i2c_client c_rx; ++ int have_rx; ++ ++ /* RX device buffer & lock */ ++ struct lirc_buffer buf; ++ struct mutex buf_lock; ++ ++ /* RX polling thread data */ ++ struct completion *t_notify; ++ struct completion *t_notify2; ++ int shutdown; ++ struct task_struct *task; ++ ++ /* RX read data */ ++ unsigned char b[3]; ++ ++ /* TX device */ ++ struct i2c_client c_tx; ++ int need_boot; ++ int have_tx; ++}; ++ ++/* Minor -> data mapping */ ++static struct IR *ir_devices[MAX_IRCTL_DEVICES]; ++ ++/* Block size for IR transmitter */ ++#define TX_BLOCK_SIZE 99 ++ ++/* Hauppauge IR transmitter data */ ++struct tx_data_struct { ++ /* Boot block */ ++ unsigned char *boot_data; ++ ++ /* Start of binary data block */ ++ unsigned char *datap; ++ ++ /* End of binary data block */ ++ unsigned char *endp; ++ ++ /* Number of installed codesets */ ++ unsigned int num_code_sets; ++ ++ /* Pointers to codesets */ ++ unsigned char **code_sets; ++ ++ /* Global fixed data template */ ++ int fixed[TX_BLOCK_SIZE]; ++}; ++ ++static struct tx_data_struct *tx_data; ++static struct mutex tx_data_lock; ++ ++#define zilog_notify(s, args...) printk(KERN_NOTICE KBUILD_MODNAME ": " s, \ ++ ## args) ++#define zilog_error(s, args...) printk(KERN_ERR KBUILD_MODNAME ": " s, ## args) ++ ++#define ZILOG_HAUPPAUGE_IR_RX_NAME "Zilog/Hauppauge IR RX" ++#define ZILOG_HAUPPAUGE_IR_TX_NAME "Zilog/Hauppauge IR TX" ++ ++/* module parameters */ ++static int debug; /* debug output */ ++static int disable_rx; /* disable RX device */ ++static int disable_tx; /* disable TX device */ ++static int minor = -1; /* minor number */ ++ ++#define dprintk(fmt, args...) \ ++ do { \ ++ if (debug) \ ++ printk(KERN_DEBUG KBUILD_MODNAME ": " fmt, \ ++ ## args); \ ++ } while (0) ++ ++static int add_to_buf(struct IR *ir) ++{ ++ __u16 code; ++ unsigned char codes[2]; ++ unsigned char keybuf[6]; ++ int got_data = 0; ++ int ret; ++ int failures = 0; ++ unsigned char sendbuf[1] = { 0 }; ++ ++ if (lirc_buffer_full(&ir->buf)) { ++ dprintk("buffer overflow\n"); ++ return -EOVERFLOW; ++ } ++ ++ /* ++ * service the device as long as it is returning ++ * data and we have space ++ */ ++ do { ++ /* ++ * Lock i2c bus for the duration. RX/TX chips interfere so ++ * this is worth it ++ */ ++ mutex_lock(&ir->ir_lock); ++ ++ /* ++ * Send random "poll command" (?) Windows driver does this ++ * and it is a good point to detect chip failure. ++ */ ++ ret = i2c_master_send(&ir->c_rx, sendbuf, 1); ++ if (ret != 1) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ if (failures >= 3) { ++ mutex_unlock(&ir->ir_lock); ++ zilog_error("unable to read from the IR chip " ++ "after 3 resets, giving up\n"); ++ return ret; ++ } ++ ++ /* Looks like the chip crashed, reset it */ ++ zilog_error("polling the IR receiver chip failed, " ++ "trying reset\n"); ++ ++ set_current_state(TASK_UNINTERRUPTIBLE); ++ schedule_timeout((100 * HZ + 999) / 1000); ++ ir->need_boot = 1; ++ ++ ++failures; ++ mutex_unlock(&ir->ir_lock); ++ continue; ++ } ++ ++ ret = i2c_master_recv(&ir->c_rx, keybuf, sizeof(keybuf)); ++ mutex_unlock(&ir->ir_lock); ++ if (ret != sizeof(keybuf)) { ++ zilog_error("i2c_master_recv failed with %d -- " ++ "keeping last read buffer\n", ret); ++ } else { ++ ir->b[0] = keybuf[3]; ++ ir->b[1] = keybuf[4]; ++ ir->b[2] = keybuf[5]; ++ dprintk("key (0x%02x/0x%02x)\n", ir->b[0], ir->b[1]); ++ } ++ ++ /* key pressed ? */ ++#ifdef I2C_HW_B_HDPVR ++ if (ir->c_rx.adapter->id == I2C_HW_B_HDPVR) { ++ if (got_data && (keybuf[0] == 0x80)) ++ return 0; ++ else if (got_data && (keybuf[0] == 0x00)) ++ return -ENODATA; ++ } else if ((ir->b[0] & 0x80) == 0) ++#else ++ if ((ir->b[0] & 0x80) == 0) ++#endif ++ return got_data ? 0 : -ENODATA; ++ ++ /* look what we have */ ++ code = (((__u16)ir->b[0] & 0x7f) << 6) | (ir->b[1] >> 2); ++ ++ codes[0] = (code >> 8) & 0xff; ++ codes[1] = code & 0xff; ++ ++ /* return it */ ++ lirc_buffer_write(&ir->buf, codes); ++ ++got_data; ++ } while (!lirc_buffer_full(&ir->buf)); ++ ++ return 0; ++} ++ ++/* ++ * Main function of the polling thread -- from lirc_dev. ++ * We don't fit the LIRC model at all anymore. This is horrible, but ++ * basically we have a single RX/TX device with a nasty failure mode ++ * that needs to be accounted for across the pair. lirc lets us provide ++ * fops, but prevents us from using the internal polling, etc. if we do ++ * so. Hence the replication. Might be neater to extend the LIRC model ++ * to account for this but I'd think it's a very special case of seriously ++ * messed up hardware. ++ */ ++static int lirc_thread(void *arg) ++{ ++ struct IR *ir = arg; ++ ++ if (ir->t_notify != NULL) ++ complete(ir->t_notify); ++ ++ dprintk("poll thread started\n"); ++ ++ do { ++ if (ir->open) { ++ set_current_state(TASK_INTERRUPTIBLE); ++ ++ /* ++ * This is ~113*2 + 24 + jitter (2*repeat gap + ++ * code length). We use this interval as the chip ++ * resets every time you poll it (bad!). This is ++ * therefore just sufficient to catch all of the ++ * button presses. It makes the remote much more ++ * responsive. You can see the difference by ++ * running irw and holding down a button. With ++ * 100ms, the old polling interval, you'll notice ++ * breaks in the repeat sequence corresponding to ++ * lost keypresses. ++ */ ++ schedule_timeout((260 * HZ) / 1000); ++ if (ir->shutdown) ++ break; ++ if (!add_to_buf(ir)) ++ wake_up_interruptible(&ir->buf.wait_poll); ++ } else { ++ /* if device not opened so we can sleep half a second */ ++ set_current_state(TASK_INTERRUPTIBLE); ++ schedule_timeout(HZ/2); ++ } ++ } while (!ir->shutdown); ++ ++ if (ir->t_notify2 != NULL) ++ wait_for_completion(ir->t_notify2); ++ ++ ir->task = NULL; ++ if (ir->t_notify != NULL) ++ complete(ir->t_notify); ++ ++ dprintk("poll thread ended\n"); ++ return 0; ++} ++ ++static int set_use_inc(void *data) ++{ ++ struct IR *ir = data; ++ ++ if (ir->l.owner == NULL || try_module_get(ir->l.owner) == 0) ++ return -ENODEV; ++ ++ /* lock bttv in memory while /dev/lirc is in use */ ++ /* ++ * this is completely broken code. lirc_unregister_driver() ++ * must be possible even when the device is open ++ */ ++ if (ir->c_rx.addr) ++ i2c_use_client(&ir->c_rx); ++ if (ir->c_tx.addr) ++ i2c_use_client(&ir->c_tx); ++ ++ return 0; ++} ++ ++static void set_use_dec(void *data) ++{ ++ struct IR *ir = data; ++ ++ if (ir->c_rx.addr) ++ i2c_release_client(&ir->c_rx); ++ if (ir->c_tx.addr) ++ i2c_release_client(&ir->c_tx); ++ if (ir->l.owner != NULL) ++ module_put(ir->l.owner); ++} ++ ++/* safe read of a uint32 (always network byte order) */ ++static int read_uint32(unsigned char **data, ++ unsigned char *endp, unsigned int *val) ++{ ++ if (*data + 4 > endp) ++ return 0; ++ *val = ((*data)[0] << 24) | ((*data)[1] << 16) | ++ ((*data)[2] << 8) | (*data)[3]; ++ *data += 4; ++ return 1; ++} ++ ++/* safe read of a uint8 */ ++static int read_uint8(unsigned char **data, ++ unsigned char *endp, unsigned char *val) ++{ ++ if (*data + 1 > endp) ++ return 0; ++ *val = *((*data)++); ++ return 1; ++} ++ ++/* safe skipping of N bytes */ ++static int skip(unsigned char **data, ++ unsigned char *endp, unsigned int distance) ++{ ++ if (*data + distance > endp) ++ return 0; ++ *data += distance; ++ return 1; ++} ++ ++/* decompress key data into the given buffer */ ++static int get_key_data(unsigned char *buf, ++ unsigned int codeset, unsigned int key) ++{ ++ unsigned char *data, *endp, *diffs, *key_block; ++ unsigned char keys, ndiffs, id; ++ unsigned int base, lim, pos, i; ++ ++ /* Binary search for the codeset */ ++ for (base = 0, lim = tx_data->num_code_sets; lim; lim >>= 1) { ++ pos = base + (lim >> 1); ++ data = tx_data->code_sets[pos]; ++ ++ if (!read_uint32(&data, tx_data->endp, &i)) ++ goto corrupt; ++ ++ if (i == codeset) ++ break; ++ else if (codeset > i) { ++ base = pos + 1; ++ --lim; ++ } ++ } ++ /* Not found? */ ++ if (!lim) ++ return -EPROTO; ++ ++ /* Set end of data block */ ++ endp = pos < tx_data->num_code_sets - 1 ? ++ tx_data->code_sets[pos + 1] : tx_data->endp; ++ ++ /* Read the block header */ ++ if (!read_uint8(&data, endp, &keys) || ++ !read_uint8(&data, endp, &ndiffs) || ++ ndiffs > TX_BLOCK_SIZE || keys == 0) ++ goto corrupt; ++ ++ /* Save diffs & skip */ ++ diffs = data; ++ if (!skip(&data, endp, ndiffs)) ++ goto corrupt; ++ ++ /* Read the id of the first key */ ++ if (!read_uint8(&data, endp, &id)) ++ goto corrupt; ++ ++ /* Unpack the first key's data */ ++ for (i = 0; i < TX_BLOCK_SIZE; ++i) { ++ if (tx_data->fixed[i] == -1) { ++ if (!read_uint8(&data, endp, &buf[i])) ++ goto corrupt; ++ } else { ++ buf[i] = (unsigned char)tx_data->fixed[i]; ++ } ++ } ++ ++ /* Early out key found/not found */ ++ if (key == id) ++ return 0; ++ if (keys == 1) ++ return -EPROTO; ++ ++ /* Sanity check */ ++ key_block = data; ++ if (!skip(&data, endp, (keys - 1) * (ndiffs + 1))) ++ goto corrupt; ++ ++ /* Binary search for the key */ ++ for (base = 0, lim = keys - 1; lim; lim >>= 1) { ++ /* Seek to block */ ++ unsigned char *key_data; ++ pos = base + (lim >> 1); ++ key_data = key_block + (ndiffs + 1) * pos; ++ ++ if (*key_data == key) { ++ /* skip key id */ ++ ++key_data; ++ ++ /* found, so unpack the diffs */ ++ for (i = 0; i < ndiffs; ++i) { ++ unsigned char val; ++ if (!read_uint8(&key_data, endp, &val) || ++ diffs[i] >= TX_BLOCK_SIZE) ++ goto corrupt; ++ buf[diffs[i]] = val; ++ } ++ ++ return 0; ++ } else if (key > *key_data) { ++ base = pos + 1; ++ --lim; ++ } ++ } ++ /* Key not found */ ++ return -EPROTO; ++ ++corrupt: ++ zilog_error("firmware is corrupt\n"); ++ return -EFAULT; ++} ++ ++/* send a block of data to the IR TX device */ ++static int send_data_block(struct IR *ir, unsigned char *data_block) ++{ ++ int i, j, ret; ++ unsigned char buf[5]; ++ ++ for (i = 0; i < TX_BLOCK_SIZE;) { ++ int tosend = TX_BLOCK_SIZE - i; ++ if (tosend > 4) ++ tosend = 4; ++ buf[0] = (unsigned char)(i + 1); ++ for (j = 0; j < tosend; ++j) ++ buf[1 + j] = data_block[i + j]; ++ dprintk("%02x %02x %02x %02x %02x", ++ buf[0], buf[1], buf[2], buf[3], buf[4]); ++ ret = i2c_master_send(&ir->c_tx, buf, tosend + 1); ++ if (ret != tosend + 1) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ i += tosend; ++ } ++ return 0; ++} ++ ++/* send boot data to the IR TX device */ ++static int send_boot_data(struct IR *ir) ++{ ++ int ret; ++ unsigned char buf[4]; ++ ++ /* send the boot block */ ++ ret = send_data_block(ir, tx_data->boot_data); ++ if (ret != 0) ++ return ret; ++ ++ /* kick it off? */ ++ buf[0] = 0x00; ++ buf[1] = 0x20; ++ ret = i2c_master_send(&ir->c_tx, buf, 2); ++ if (ret != 2) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ ret = i2c_master_send(&ir->c_tx, buf, 1); ++ if (ret != 1) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ ++ /* Here comes the firmware version... (hopefully) */ ++ ret = i2c_master_recv(&ir->c_tx, buf, 4); ++ if (ret != 4) { ++ zilog_error("i2c_master_recv failed with %d\n", ret); ++ return 0; ++ } ++ if (buf[0] != 0x80) { ++ zilog_error("unexpected IR TX response: %02x\n", buf[0]); ++ return 0; ++ } ++ zilog_notify("Zilog/Hauppauge IR blaster firmware version " ++ "%d.%d.%d loaded\n", buf[1], buf[2], buf[3]); ++ ++ return 0; ++} ++ ++/* unload "firmware", lock held */ ++static void fw_unload_locked(void) ++{ ++ if (tx_data) { ++ if (tx_data->code_sets) ++ vfree(tx_data->code_sets); ++ ++ if (tx_data->datap) ++ vfree(tx_data->datap); ++ ++ vfree(tx_data); ++ tx_data = NULL; ++ dprintk("successfully unloaded IR blaster firmware\n"); ++ } ++} ++ ++/* unload "firmware" for the IR TX device */ ++static void fw_unload(void) ++{ ++ mutex_lock(&tx_data_lock); ++ fw_unload_locked(); ++ mutex_unlock(&tx_data_lock); ++} ++ ++/* load "firmware" for the IR TX device */ ++static int fw_load(struct IR *ir) ++{ ++ int ret; ++ unsigned int i; ++ unsigned char *data, version, num_global_fixed; ++ const struct firmware *fw_entry; ++ ++ /* Already loaded? */ ++ mutex_lock(&tx_data_lock); ++ if (tx_data) { ++ ret = 0; ++ goto out; ++ } ++ ++ /* Request codeset data file */ ++ ret = request_firmware(&fw_entry, "haup-ir-blaster.bin", &ir->c_tx.dev); ++ if (ret != 0) { ++ zilog_error("firmware haup-ir-blaster.bin not available " ++ "(%d)\n", ret); ++ ret = ret < 0 ? ret : -EFAULT; ++ goto out; ++ } ++ dprintk("firmware of size %zu loaded\n", fw_entry->size); ++ ++ /* Parse the file */ ++ tx_data = vmalloc(sizeof(*tx_data)); ++ if (tx_data == NULL) { ++ zilog_error("out of memory\n"); ++ release_firmware(fw_entry); ++ ret = -ENOMEM; ++ goto out; ++ } ++ tx_data->code_sets = NULL; ++ ++ /* Copy the data so hotplug doesn't get confused and timeout */ ++ tx_data->datap = vmalloc(fw_entry->size); ++ if (tx_data->datap == NULL) { ++ zilog_error("out of memory\n"); ++ release_firmware(fw_entry); ++ vfree(tx_data); ++ ret = -ENOMEM; ++ goto out; ++ } ++ memcpy(tx_data->datap, fw_entry->data, fw_entry->size); ++ tx_data->endp = tx_data->datap + fw_entry->size; ++ release_firmware(fw_entry); fw_entry = NULL; ++ ++ /* Check version */ ++ data = tx_data->datap; ++ if (!read_uint8(&data, tx_data->endp, &version)) ++ goto corrupt; ++ if (version != 1) { ++ zilog_error("unsupported code set file version (%u, expected" ++ "1) -- please upgrade to a newer driver", ++ version); ++ fw_unload_locked(); ++ ret = -EFAULT; ++ goto out; ++ } ++ ++ /* Save boot block for later */ ++ tx_data->boot_data = data; ++ if (!skip(&data, tx_data->endp, TX_BLOCK_SIZE)) ++ goto corrupt; ++ ++ if (!read_uint32(&data, tx_data->endp, ++ &tx_data->num_code_sets)) ++ goto corrupt; ++ ++ dprintk("%u IR blaster codesets loaded\n", tx_data->num_code_sets); ++ ++ tx_data->code_sets = vmalloc( ++ tx_data->num_code_sets * sizeof(char *)); ++ if (tx_data->code_sets == NULL) { ++ fw_unload_locked(); ++ ret = -ENOMEM; ++ goto out; ++ } ++ ++ for (i = 0; i < TX_BLOCK_SIZE; ++i) ++ tx_data->fixed[i] = -1; ++ ++ /* Read global fixed data template */ ++ if (!read_uint8(&data, tx_data->endp, &num_global_fixed) || ++ num_global_fixed > TX_BLOCK_SIZE) ++ goto corrupt; ++ for (i = 0; i < num_global_fixed; ++i) { ++ unsigned char pos, val; ++ if (!read_uint8(&data, tx_data->endp, &pos) || ++ !read_uint8(&data, tx_data->endp, &val) || ++ pos >= TX_BLOCK_SIZE) ++ goto corrupt; ++ tx_data->fixed[pos] = (int)val; ++ } ++ ++ /* Filch out the position of each code set */ ++ for (i = 0; i < tx_data->num_code_sets; ++i) { ++ unsigned int id; ++ unsigned char keys; ++ unsigned char ndiffs; ++ ++ /* Save the codeset position */ ++ tx_data->code_sets[i] = data; ++ ++ /* Read header */ ++ if (!read_uint32(&data, tx_data->endp, &id) || ++ !read_uint8(&data, tx_data->endp, &keys) || ++ !read_uint8(&data, tx_data->endp, &ndiffs) || ++ ndiffs > TX_BLOCK_SIZE || keys == 0) ++ goto corrupt; ++ ++ /* skip diff positions */ ++ if (!skip(&data, tx_data->endp, ndiffs)) ++ goto corrupt; ++ ++ /* ++ * After the diffs we have the first key id + data - ++ * global fixed ++ */ ++ if (!skip(&data, tx_data->endp, ++ 1 + TX_BLOCK_SIZE - num_global_fixed)) ++ goto corrupt; ++ ++ /* Then we have keys-1 blocks of key id+diffs */ ++ if (!skip(&data, tx_data->endp, ++ (ndiffs + 1) * (keys - 1))) ++ goto corrupt; ++ } ++ ret = 0; ++ goto out; ++ ++corrupt: ++ zilog_error("firmware is corrupt\n"); ++ fw_unload_locked(); ++ ret = -EFAULT; ++ ++out: ++ mutex_unlock(&tx_data_lock); ++ return ret; ++} ++ ++/* initialise the IR TX device */ ++static int tx_init(struct IR *ir) ++{ ++ int ret; ++ ++ /* Load 'firmware' */ ++ ret = fw_load(ir); ++ if (ret != 0) ++ return ret; ++ ++ /* Send boot block */ ++ ret = send_boot_data(ir); ++ if (ret != 0) ++ return ret; ++ ir->need_boot = 0; ++ ++ /* Looks good */ ++ return 0; ++} ++ ++/* do nothing stub to make LIRC happy */ ++static loff_t lseek(struct file *filep, loff_t offset, int orig) ++{ ++ return -ESPIPE; ++} ++ ++/* copied from lirc_dev */ ++static ssize_t read(struct file *filep, char *outbuf, size_t n, loff_t *ppos) ++{ ++ struct IR *ir = (struct IR *)filep->private_data; ++ unsigned char buf[ir->buf.chunk_size]; ++ int ret = 0, written = 0; ++ DECLARE_WAITQUEUE(wait, current); ++ ++ dprintk("read called\n"); ++ if (ir->c_rx.addr == 0) ++ return -ENODEV; ++ ++ if (mutex_lock_interruptible(&ir->buf_lock)) ++ return -ERESTARTSYS; ++ ++ if (n % ir->buf.chunk_size) { ++ dprintk("read result = -EINVAL\n"); ++ mutex_unlock(&ir->buf_lock); ++ return -EINVAL; ++ } ++ ++ /* ++ * we add ourselves to the task queue before buffer check ++ * to avoid losing scan code (in case when queue is awaken somewhere ++ * between while condition checking and scheduling) ++ */ ++ add_wait_queue(&ir->buf.wait_poll, &wait); ++ set_current_state(TASK_INTERRUPTIBLE); ++ ++ /* ++ * while we didn't provide 'length' bytes, device is opened in blocking ++ * mode and 'copy_to_user' is happy, wait for data. ++ */ ++ while (written < n && ret == 0) { ++ if (lirc_buffer_empty(&ir->buf)) { ++ /* ++ * According to the read(2) man page, 'written' can be ++ * returned as less than 'n', instead of blocking ++ * again, returning -EWOULDBLOCK, or returning ++ * -ERESTARTSYS ++ */ ++ if (written) ++ break; ++ if (filep->f_flags & O_NONBLOCK) { ++ ret = -EWOULDBLOCK; ++ break; ++ } ++ if (signal_pending(current)) { ++ ret = -ERESTARTSYS; ++ break; ++ } ++ schedule(); ++ set_current_state(TASK_INTERRUPTIBLE); ++ } else { ++ lirc_buffer_read(&ir->buf, buf); ++ ret = copy_to_user((void *)outbuf+written, buf, ++ ir->buf.chunk_size); ++ written += ir->buf.chunk_size; ++ } ++ } ++ ++ remove_wait_queue(&ir->buf.wait_poll, &wait); ++ set_current_state(TASK_RUNNING); ++ mutex_unlock(&ir->buf_lock); ++ ++ dprintk("read result = %s (%d)\n", ++ ret ? "-EFAULT" : "OK", ret); ++ ++ return ret ? ret : written; ++} ++ ++/* send a keypress to the IR TX device */ ++static int send_code(struct IR *ir, unsigned int code, unsigned int key) ++{ ++ unsigned char data_block[TX_BLOCK_SIZE]; ++ unsigned char buf[2]; ++ int i, ret; ++ ++ /* Get data for the codeset/key */ ++ ret = get_key_data(data_block, code, key); ++ ++ if (ret == -EPROTO) { ++ zilog_error("failed to get data for code %u, key %u -- check " ++ "lircd.conf entries\n", code, key); ++ return ret; ++ } else if (ret != 0) ++ return ret; ++ ++ /* Send the data block */ ++ ret = send_data_block(ir, data_block); ++ if (ret != 0) ++ return ret; ++ ++ /* Send data block length? */ ++ buf[0] = 0x00; ++ buf[1] = 0x40; ++ ret = i2c_master_send(&ir->c_tx, buf, 2); ++ if (ret != 2) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ ret = i2c_master_send(&ir->c_tx, buf, 1); ++ if (ret != 1) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ ++ /* Send finished download? */ ++ ret = i2c_master_recv(&ir->c_tx, buf, 1); ++ if (ret != 1) { ++ zilog_error("i2c_master_recv failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ if (buf[0] != 0xA0) { ++ zilog_error("unexpected IR TX response #1: %02x\n", ++ buf[0]); ++ return -EFAULT; ++ } ++ ++ /* Send prepare command? */ ++ buf[0] = 0x00; ++ buf[1] = 0x80; ++ ret = i2c_master_send(&ir->c_tx, buf, 2); ++ if (ret != 2) { ++ zilog_error("i2c_master_send failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ ++#ifdef I2C_HW_B_HDPVR ++ /* ++ * The sleep bits aren't necessary on the HD PVR, and in fact, the ++ * last i2c_master_recv always fails with a -5, so for now, we're ++ * going to skip this whole mess and say we're done on the HD PVR ++ */ ++ if (ir->c_rx.adapter->id == I2C_HW_B_HDPVR) ++ goto done; ++#endif ++ ++ /* ++ * This bit NAKs until the device is ready, so we retry it ++ * sleeping a bit each time. This seems to be what the windows ++ * driver does, approximately. ++ * Try for up to 1s. ++ */ ++ for (i = 0; i < 20; ++i) { ++ set_current_state(TASK_UNINTERRUPTIBLE); ++ schedule_timeout((50 * HZ + 999) / 1000); ++ ret = i2c_master_send(&ir->c_tx, buf, 1); ++ if (ret == 1) ++ break; ++ dprintk("NAK expected: i2c_master_send " ++ "failed with %d (try %d)\n", ret, i+1); ++ } ++ if (ret != 1) { ++ zilog_error("IR TX chip never got ready: last i2c_master_send " ++ "failed with %d\n", ret); ++ return ret < 0 ? ret : -EFAULT; ++ } ++ ++ /* Seems to be an 'ok' response */ ++ i = i2c_master_recv(&ir->c_tx, buf, 1); ++ if (i != 1) { ++ zilog_error("i2c_master_recv failed with %d\n", ret); ++ return -EFAULT; ++ } ++ if (buf[0] != 0x80) { ++ zilog_error("unexpected IR TX response #2: %02x\n", buf[0]); ++ return -EFAULT; ++ } ++ ++done: ++ /* Oh good, it worked */ ++ dprintk("sent code %u, key %u\n", code, key); ++ return 0; ++} ++ ++/* ++ * Write a code to the device. We take in a 32-bit number (an int) and then ++ * decode this to a codeset/key index. The key data is then decompressed and ++ * sent to the device. We have a spin lock as per i2c documentation to prevent ++ * multiple concurrent sends which would probably cause the device to explode. ++ */ ++static ssize_t write(struct file *filep, const char *buf, size_t n, ++ loff_t *ppos) ++{ ++ struct IR *ir = (struct IR *)filep->private_data; ++ size_t i; ++ int failures = 0; ++ ++ if (ir->c_tx.addr == 0) ++ return -ENODEV; ++ ++ /* Validate user parameters */ ++ if (n % sizeof(int)) ++ return -EINVAL; ++ ++ /* Lock i2c bus for the duration */ ++ mutex_lock(&ir->ir_lock); ++ ++ /* Send each keypress */ ++ for (i = 0; i < n;) { ++ int ret = 0; ++ int command; ++ ++ if (copy_from_user(&command, buf + i, sizeof(command))) { ++ mutex_unlock(&ir->ir_lock); ++ return -EFAULT; ++ } ++ ++ /* Send boot data first if required */ ++ if (ir->need_boot == 1) { ++ ret = send_boot_data(ir); ++ if (ret == 0) ++ ir->need_boot = 0; ++ } ++ ++ /* Send the code */ ++ if (ret == 0) { ++ ret = send_code(ir, (unsigned)command >> 16, ++ (unsigned)command & 0xFFFF); ++ if (ret == -EPROTO) { ++ mutex_unlock(&ir->ir_lock); ++ return ret; ++ } ++ } ++ ++ /* ++ * Hmm, a failure. If we've had a few then give up, otherwise ++ * try a reset ++ */ ++ if (ret != 0) { ++ /* Looks like the chip crashed, reset it */ ++ zilog_error("sending to the IR transmitter chip " ++ "failed, trying reset\n"); ++ ++ if (failures >= 3) { ++ zilog_error("unable to send to the IR chip " ++ "after 3 resets, giving up\n"); ++ mutex_unlock(&ir->ir_lock); ++ return ret; ++ } ++ set_current_state(TASK_UNINTERRUPTIBLE); ++ schedule_timeout((100 * HZ + 999) / 1000); ++ ir->need_boot = 1; ++ ++failures; ++ } else ++ i += sizeof(int); ++ } ++ ++ /* Release i2c bus */ ++ mutex_unlock(&ir->ir_lock); ++ ++ /* All looks good */ ++ return n; ++} ++ ++/* copied from lirc_dev */ ++static unsigned int poll(struct file *filep, poll_table *wait) ++{ ++ struct IR *ir = (struct IR *)filep->private_data; ++ unsigned int ret; ++ ++ dprintk("poll called\n"); ++ if (ir->c_rx.addr == 0) ++ return -ENODEV; ++ ++ mutex_lock(&ir->buf_lock); ++ ++ poll_wait(filep, &ir->buf.wait_poll, wait); ++ ++ dprintk("poll result = %s\n", ++ lirc_buffer_empty(&ir->buf) ? "0" : "POLLIN|POLLRDNORM"); ++ ++ ret = lirc_buffer_empty(&ir->buf) ? 0 : (POLLIN|POLLRDNORM); ++ ++ mutex_unlock(&ir->buf_lock); ++ return ret; ++} ++ ++static int ioctl(struct inode *node, struct file *filep, unsigned int cmd, ++ unsigned long arg) ++{ ++ struct IR *ir = (struct IR *)filep->private_data; ++ int result; ++ unsigned long mode, features = 0; ++ ++ if (ir->c_rx.addr != 0) ++ features |= LIRC_CAN_REC_LIRCCODE; ++ if (ir->c_tx.addr != 0) ++ features |= LIRC_CAN_SEND_PULSE; ++ ++ switch (cmd) { ++ case LIRC_GET_LENGTH: ++ result = put_user((unsigned long)13, ++ (unsigned long *)arg); ++ break; ++ case LIRC_GET_FEATURES: ++ result = put_user(features, (unsigned long *) arg); ++ break; ++ case LIRC_GET_REC_MODE: ++ if (!(features&LIRC_CAN_REC_MASK)) ++ return -ENOSYS; ++ ++ result = put_user(LIRC_REC2MODE ++ (features&LIRC_CAN_REC_MASK), ++ (unsigned long *)arg); ++ break; ++ case LIRC_SET_REC_MODE: ++ if (!(features&LIRC_CAN_REC_MASK)) ++ return -ENOSYS; ++ ++ result = get_user(mode, (unsigned long *)arg); ++ if (!result && !(LIRC_MODE2REC(mode) & features)) ++ result = -EINVAL; ++ break; ++ case LIRC_GET_SEND_MODE: ++ if (!(features&LIRC_CAN_SEND_MASK)) ++ return -ENOSYS; ++ ++ result = put_user(LIRC_MODE_PULSE, (unsigned long *) arg); ++ break; ++ case LIRC_SET_SEND_MODE: ++ if (!(features&LIRC_CAN_SEND_MASK)) ++ return -ENOSYS; ++ ++ result = get_user(mode, (unsigned long *) arg); ++ if (!result && mode != LIRC_MODE_PULSE) ++ return -EINVAL; ++ break; ++ default: ++ return -EINVAL; ++ } ++ return result; ++} ++ ++/* ++ * Open the IR device. Get hold of our IR structure and ++ * stash it in private_data for the file ++ */ ++static int open(struct inode *node, struct file *filep) ++{ ++ struct IR *ir; ++ int ret; ++ ++ /* find our IR struct */ ++ unsigned minor = MINOR(node->i_rdev); ++ if (minor >= MAX_IRCTL_DEVICES) { ++ dprintk("minor %d: open result = -ENODEV\n", ++ minor); ++ return -ENODEV; ++ } ++ ir = ir_devices[minor]; ++ ++ /* increment in use count */ ++ mutex_lock(&ir->ir_lock); ++ ++ir->open; ++ ret = set_use_inc(ir); ++ if (ret != 0) { ++ --ir->open; ++ mutex_unlock(&ir->ir_lock); ++ return ret; ++ } ++ mutex_unlock(&ir->ir_lock); ++ ++ /* stash our IR struct */ ++ filep->private_data = ir; ++ ++ return 0; ++} ++ ++/* Close the IR device */ ++static int close(struct inode *node, struct file *filep) ++{ ++ /* find our IR struct */ ++ struct IR *ir = (struct IR *)filep->private_data; ++ if (ir == NULL) { ++ zilog_error("close: no private_data attached to the file!\n"); ++ return -ENODEV; ++ } ++ ++ /* decrement in use count */ ++ mutex_lock(&ir->ir_lock); ++ --ir->open; ++ set_use_dec(ir); ++ mutex_unlock(&ir->ir_lock); ++ ++ return 0; ++} ++ ++static struct lirc_driver lirc_template = { ++ .name = "lirc_zilog", ++ .set_use_inc = set_use_inc, ++ .set_use_dec = set_use_dec, ++ .owner = THIS_MODULE ++}; ++ ++static int ir_remove(struct i2c_client *client); ++static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id); ++static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg); ++ ++static const struct i2c_device_id ir_transceiver_id[] = { ++ /* Generic entry for any IR transceiver */ ++ { "ir_video", 0 }, ++ /* IR device specific entries should be added here */ ++ { "ir_tx_z8f0811_haup", 0 }, ++ { "ir_rx_z8f0811_haup", 0 }, ++ { } ++}; ++ ++static struct i2c_driver driver = { ++ .driver = { ++ .owner = THIS_MODULE, ++ .name = "Zilog/Hauppauge i2c IR", ++ }, ++ .probe = ir_probe, ++ .remove = ir_remove, ++ .command = ir_command, ++ .id_table = ir_transceiver_id, ++}; ++ ++static struct file_operations lirc_fops = { ++ .owner = THIS_MODULE, ++ .llseek = lseek, ++ .read = read, ++ .write = write, ++ .poll = poll, ++ .ioctl = ioctl, ++ .open = open, ++ .release = close ++}; ++ ++static int ir_remove(struct i2c_client *client) ++{ ++ struct IR *ir = i2c_get_clientdata(client); ++ ++ mutex_lock(&ir->ir_lock); ++ ++ if (ir->have_rx || ir->have_tx) { ++ DECLARE_COMPLETION(tn); ++ DECLARE_COMPLETION(tn2); ++ ++ /* end up polling thread */ ++ if (ir->task && !IS_ERR(ir->task)) { ++ ir->t_notify = &tn; ++ ir->t_notify2 = &tn2; ++ ir->shutdown = 1; ++ wake_up_process(ir->task); ++ complete(&tn2); ++ wait_for_completion(&tn); ++ ir->t_notify = NULL; ++ ir->t_notify2 = NULL; ++ } ++ ++ } else { ++ mutex_unlock(&ir->ir_lock); ++ zilog_error("%s: detached from something we didn't " ++ "attach to\n", __func__); ++ return -ENODEV; ++ } ++ ++ /* unregister lirc driver */ ++ if (ir->l.minor >= 0 && ir->l.minor < MAX_IRCTL_DEVICES) { ++ lirc_unregister_driver(ir->l.minor); ++ ir_devices[ir->l.minor] = NULL; ++ } ++ ++ /* free memory */ ++ lirc_buffer_free(&ir->buf); ++ mutex_unlock(&ir->ir_lock); ++ kfree(ir); ++ ++ return 0; ++} ++ ++static int ir_probe(struct i2c_client *client, const struct i2c_device_id *id) ++{ ++ struct IR *ir = NULL; ++ struct i2c_adapter *adap = client->adapter; ++ char buf; ++ int ret; ++ int have_rx = 0, have_tx = 0; ++ ++ dprintk("%s: adapter id=0x%x, client addr=0x%02x\n", ++ __func__, adap->id, client->addr); ++ ++ /* ++ * The external IR receiver is at i2c address 0x71. ++ * The IR transmitter is at 0x70. ++ */ ++ client->addr = 0x70; ++ ++ if (!disable_tx) { ++ if (i2c_master_recv(client, &buf, 1) == 1) ++ have_tx = 1; ++ dprintk("probe 0x70 @ %s: %s\n", ++ adap->name, have_tx ? "success" : "failed"); ++ } ++ ++ if (!disable_rx) { ++ client->addr = 0x71; ++ if (i2c_master_recv(client, &buf, 1) == 1) ++ have_rx = 1; ++ dprintk("probe 0x71 @ %s: %s\n", ++ adap->name, have_rx ? "success" : "failed"); ++ } ++ ++ if (!(have_rx || have_tx)) { ++ zilog_error("%s: no devices found\n", adap->name); ++ goto out_nodev; ++ } ++ ++ printk(KERN_INFO "lirc_zilog: chip found with %s\n", ++ have_rx && have_tx ? "RX and TX" : ++ have_rx ? "RX only" : "TX only"); ++ ++ ir = kzalloc(sizeof(struct IR), GFP_KERNEL); ++ ++ if (!ir) ++ goto out_nomem; ++ ++ ret = lirc_buffer_init(&ir->buf, 2, BUFLEN / 2); ++ if (ret) ++ goto out_nomem; ++ ++ mutex_init(&ir->ir_lock); ++ mutex_init(&ir->buf_lock); ++ ir->need_boot = 1; ++ ++ memcpy(&ir->l, &lirc_template, sizeof(struct lirc_driver)); ++ ir->l.minor = -1; ++ ++ /* I2C attach to device */ ++ i2c_set_clientdata(client, ir); ++ ++ /* initialise RX device */ ++ if (have_rx) { ++ DECLARE_COMPLETION(tn); ++ memcpy(&ir->c_rx, client, sizeof(struct i2c_client)); ++ ++ ir->c_rx.addr = 0x71; ++ strlcpy(ir->c_rx.name, ZILOG_HAUPPAUGE_IR_RX_NAME, ++ I2C_NAME_SIZE); ++ ++ /* try to fire up polling thread */ ++ ir->t_notify = &tn; ++ ir->task = kthread_run(lirc_thread, ir, "lirc_zilog"); ++ if (IS_ERR(ir->task)) { ++ ret = PTR_ERR(ir->task); ++ zilog_error("lirc_register_driver: cannot run " ++ "poll thread %d\n", ret); ++ goto err; ++ } ++ wait_for_completion(&tn); ++ ir->t_notify = NULL; ++ ir->have_rx = 1; ++ } ++ ++ /* initialise TX device */ ++ if (have_tx) { ++ memcpy(&ir->c_tx, client, sizeof(struct i2c_client)); ++ ir->c_tx.addr = 0x70; ++ strlcpy(ir->c_tx.name, ZILOG_HAUPPAUGE_IR_TX_NAME, ++ I2C_NAME_SIZE); ++ ir->have_tx = 1; ++ } ++ ++ /* set lirc_dev stuff */ ++ ir->l.code_length = 13; ++ ir->l.rbuf = &ir->buf; ++ ir->l.fops = &lirc_fops; ++ ir->l.data = ir; ++ ir->l.minor = minor; ++ ir->l.dev = &adap->dev; ++ ir->l.sample_rate = 0; ++ ++ /* register with lirc */ ++ ir->l.minor = lirc_register_driver(&ir->l); ++ if (ir->l.minor < 0 || ir->l.minor >= MAX_IRCTL_DEVICES) { ++ zilog_error("ir_attach: \"minor\" must be between 0 and %d " ++ "(%d)!\n", MAX_IRCTL_DEVICES-1, ir->l.minor); ++ ret = -EBADRQC; ++ goto err; ++ } ++ ++ /* store this for getting back in open() later on */ ++ ir_devices[ir->l.minor] = ir; ++ ++ /* ++ * if we have the tx device, load the 'firmware'. We do this ++ * after registering with lirc as otherwise hotplug seems to take ++ * 10s to create the lirc device. ++ */ ++ if (have_tx) { ++ /* Special TX init */ ++ ret = tx_init(ir); ++ if (ret != 0) ++ goto err; ++ } ++ ++ return 0; ++ ++err: ++ /* undo everything, hopefully... */ ++ if (ir->c_rx.addr) ++ ir_remove(&ir->c_rx); ++ if (ir->c_tx.addr) ++ ir_remove(&ir->c_tx); ++ return ret; ++ ++out_nodev: ++ zilog_error("no device found\n"); ++ return -ENODEV; ++ ++out_nomem: ++ zilog_error("memory allocation failure\n"); ++ kfree(ir); ++ return -ENOMEM; ++} ++ ++static int ir_command(struct i2c_client *client, unsigned int cmd, void *arg) ++{ ++ /* nothing */ ++ return 0; ++} ++ ++static int __init zilog_init(void) ++{ ++ int ret; ++ ++ zilog_notify("Zilog/Hauppauge IR driver initializing\n"); ++ ++ mutex_init(&tx_data_lock); ++ ++ request_module("firmware_class"); ++ ++ ret = i2c_add_driver(&driver); ++ if (ret) ++ zilog_error("initialization failed\n"); ++ else ++ zilog_notify("initialization complete\n"); ++ ++ return ret; ++} ++ ++static void __exit zilog_exit(void) ++{ ++ i2c_del_driver(&driver); ++ /* if loaded */ ++ fw_unload(); ++ zilog_notify("Zilog/Hauppauge IR driver unloaded\n"); ++} ++ ++module_init(zilog_init); ++module_exit(zilog_exit); ++ ++MODULE_DESCRIPTION("Zilog/Hauppauge infrared transmitter driver (i2c stack)"); ++MODULE_AUTHOR("Gerd Knorr, Michal Kochanowicz, Christoph Bartelmus, " ++ "Ulrich Mueller, Stefan Jahn, Jerome Brock, Mark Weaver"); ++MODULE_LICENSE("GPL"); ++/* for compat with old name, which isn't all that accurate anymore */ ++MODULE_ALIAS("lirc_pvr150"); ++ ++module_param(minor, int, 0444); ++MODULE_PARM_DESC(minor, "Preferred minor device number"); ++ ++module_param(debug, bool, 0644); ++MODULE_PARM_DESC(debug, "Enable debugging messages"); ++ ++module_param(disable_rx, bool, 0644); ++MODULE_PARM_DESC(disable_rx, "Disable the IR receiver device"); ++ ++module_param(disable_tx, bool, 0644); ++MODULE_PARM_DESC(disable_tx, "Disable the IR transmitter device"); +diff --git a/drivers/input/misc/Kconfig b/drivers/input/misc/Kconfig +index 23140a3..7085225 100644 +--- a/drivers/input/misc/Kconfig ++++ b/drivers/input/misc/Kconfig +@@ -340,4 +340,16 @@ config INPUT_PCAP + To compile this driver as a module, choose M here: the + module will be called pcap_keys. + ++config INPUT_IMON ++ tristate "SoundGraph iMON Receiver and Display" ++ depends on USB_ARCH_HAS_HCD ++ select USB ++ select INPUT_SPARSEKMAP ++ help ++ Say Y here if you want to use a SoundGraph iMON (aka Antec Veris) ++ IR Receiver and/or LCD/VFD/VGA display. ++ ++ To compile this driver as a module, choose M here: the ++ module will be called imon. ++ + endif +diff --git a/drivers/input/misc/Makefile b/drivers/input/misc/Makefile +index 7e95a5d..8918ce7 100644 +--- a/drivers/input/misc/Makefile ++++ b/drivers/input/misc/Makefile +@@ -14,6 +14,7 @@ obj-$(CONFIG_INPUT_CM109) += cm109.o + obj-$(CONFIG_INPUT_COBALT_BTNS) += cobalt_btns.o + obj-$(CONFIG_INPUT_DM355EVM) += dm355evm_keys.o + obj-$(CONFIG_HP_SDC_RTC) += hp_sdc_rtc.o ++obj-$(CONFIG_INPUT_IMON) += imon.o + obj-$(CONFIG_INPUT_IXP4XX_BEEPER) += ixp4xx-beeper.o + obj-$(CONFIG_INPUT_KEYSPAN_REMOTE) += keyspan_remote.o + obj-$(CONFIG_INPUT_M68K_BEEP) += m68kspkr.o +diff --git a/drivers/input/misc/imon.c b/drivers/input/misc/imon.c +new file mode 100644 +index 0000000..58a2130 +--- /dev/null ++++ b/drivers/input/misc/imon.c +@@ -0,0 +1,2523 @@ ++/* ++ * imon.c: input and display driver for SoundGraph iMON IR/VFD/LCD ++ * ++ * Copyright(C) 2009 Jarod Wilson ++ * Portions based on the original lirc_imon driver, ++ * Copyright(C) 2004 Venky Raju(dev@venky.ws) ++ * ++ * imon is free software; you can redistribute it and/or modify ++ * it under the terms of the GNU General Public License as published by ++ * the Free Software Foundation; either version 2 of the License, or ++ * (at your option) any later version. ++ * ++ * This program is distributed in the hope that it will be useful, ++ * but WITHOUT ANY WARRANTY; without even the implied warranty of ++ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the ++ * GNU General Public License for more details. ++ * ++ * You should have received a copy of the GNU General Public License ++ * along with this program; if not, write to the Free Software ++ * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#define MOD_AUTHOR "Jarod Wilson " ++#define MOD_DESC "Driver for SoundGraph iMON MultiMedia IR/Display" ++#define MOD_NAME "imon" ++#define MOD_VERSION "0.8" ++ ++#define DISPLAY_MINOR_BASE 144 ++#define DEVICE_NAME "lcd%d" ++ ++#define BUF_CHUNK_SIZE 8 ++#define BUF_SIZE 128 ++ ++#define BIT_DURATION 250 /* each bit received is 250us */ ++ ++#define IMON_CLOCK_ENABLE_PACKETS 2 ++#define IMON_KEY_RELEASE_OFFSET 1000 ++ ++/*** P R O T O T Y P E S ***/ ++ ++/* USB Callback prototypes */ ++static int imon_probe(struct usb_interface *interface, ++ const struct usb_device_id *id); ++static void imon_disconnect(struct usb_interface *interface); ++static void usb_rx_callback_intf0(struct urb *urb); ++static void usb_rx_callback_intf1(struct urb *urb); ++static void usb_tx_callback(struct urb *urb); ++ ++/* suspend/resume support */ ++static int imon_resume(struct usb_interface *intf); ++static int imon_suspend(struct usb_interface *intf, pm_message_t message); ++ ++/* Display file_operations function prototypes */ ++static int display_open(struct inode *inode, struct file *file); ++static int display_close(struct inode *inode, struct file *file); ++ ++/* VFD write operation */ ++static ssize_t vfd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos); ++ ++/* LCD file_operations override function prototypes */ ++static ssize_t lcd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos); ++ ++/*** G L O B A L S ***/ ++ ++struct imon_context { ++ struct device *dev; ++ struct usb_device *usbdev_intf0; ++ /* Newer devices have two interfaces */ ++ struct usb_device *usbdev_intf1; ++ bool display_supported; /* not all controllers do */ ++ bool display_isopen; /* display port has been opened */ ++ bool ir_isassociating; /* IR port open for association */ ++ bool dev_present_intf0; /* USB device presence, interface 0 */ ++ bool dev_present_intf1; /* USB device presence, interface 1 */ ++ struct mutex lock; /* to lock this object */ ++ wait_queue_head_t remove_ok; /* For unexpected USB disconnects */ ++ ++ struct usb_endpoint_descriptor *rx_endpoint_intf0; ++ struct usb_endpoint_descriptor *rx_endpoint_intf1; ++ struct usb_endpoint_descriptor *tx_endpoint; ++ struct urb *rx_urb_intf0; ++ struct urb *rx_urb_intf1; ++ struct urb *tx_urb; ++ bool tx_control; ++ unsigned char usb_rx_buf[8]; ++ unsigned char usb_tx_buf[8]; ++ ++ struct tx_t { ++ unsigned char data_buf[35]; /* user data buffer */ ++ struct completion finished; /* wait for write to finish */ ++ bool busy; /* write in progress */ ++ int status; /* status of tx completion */ ++ } tx; ++ ++ u16 vendor; /* usb vendor ID */ ++ u16 product; /* usb product ID */ ++ int ir_protocol; /* iMON or MCE (RC6) IR protocol? */ ++ struct input_dev *idev; /* input device for remote */ ++ struct input_dev *touch; /* input device for touchscreen */ ++ int ki; /* current input keycode key index */ ++ u16 kc; /* current input keycode */ ++ u16 last_keycode; /* last reported input keycode */ ++ u8 mce_toggle_bit; /* last mce toggle bit */ ++ int display_type; /* store the display type */ ++ bool pad_mouse; /* toggle kbd(0)/mouse(1) mode */ ++ int touch_x; /* x coordinate on touchscreen */ ++ int touch_y; /* y coordinate on touchscreen */ ++ char name_idev[128]; /* input device name */ ++ char phys_idev[64]; /* input device phys path */ ++ struct timer_list itimer; /* input device timer, need for rc6 */ ++ char name_touch[128]; /* touch screen name */ ++ char phys_touch[64]; /* touch screen phys path */ ++ struct timer_list ttimer; /* touch screen timer */ ++}; ++ ++#define TOUCH_TIMEOUT (HZ/30) ++#define MCE_TIMEOUT_MS 200 ++ ++/* vfd character device file operations */ ++static const struct file_operations vfd_fops = { ++ .owner = THIS_MODULE, ++ .open = &display_open, ++ .write = &vfd_write, ++ .release = &display_close ++}; ++ ++/* lcd character device file operations */ ++static const struct file_operations lcd_fops = { ++ .owner = THIS_MODULE, ++ .open = &display_open, ++ .write = &lcd_write, ++ .release = &display_close ++}; ++ ++enum { ++ IMON_DISPLAY_TYPE_AUTO = 0, ++ IMON_DISPLAY_TYPE_VFD = 1, ++ IMON_DISPLAY_TYPE_LCD = 2, ++ IMON_DISPLAY_TYPE_VGA = 3, ++ IMON_DISPLAY_TYPE_NONE = 4, ++}; ++ ++enum { ++ IMON_IR_PROTOCOL_IMON = 0, ++ IMON_IR_PROTOCOL_MCE = 1, ++ IMON_IR_PROTOCOL_IMON_NOPAD = 2, ++}; ++ ++enum { ++ IMON_BUTTON_IMON = 0, ++ IMON_BUTTON_MCE = 1, ++ IMON_BUTTON_PANEL = 2, ++}; ++ ++/* ++ * USB Device ID for iMON USB Control Boards ++ * ++ * The Windows drivers contain 6 different inf files, more or less one for ++ * each new device until the 0x0034-0x0046 devices, which all use the same ++ * driver. Some of the devices in the 34-46 range haven't been definitively ++ * identified yet. Early devices have either a TriGem Computer, Inc. or a ++ * Samsung vendor ID (0x0aa8 and 0x04e8 respectively), while all later ++ * devices use the SoundGraph vendor ID (0x15c2). This driver only supports ++ * the ffdc and later devices, which do onboard decoding. ++ */ ++static struct usb_device_id imon_usb_id_table[] = { ++ /* ++ * Several devices with this same device ID, all use iMON_PAD.inf ++ * SoundGraph iMON PAD (IR & VFD) ++ * SoundGraph iMON PAD (IR & LCD) ++ * SoundGraph iMON Knob (IR only) ++ */ ++ { USB_DEVICE(0x15c2, 0xffdc) }, ++ ++ /* ++ * Newer devices, all driven by the latest iMON Windows driver, full ++ * list of device IDs extracted via 'strings Setup/data1.hdr |grep 15c2' ++ * Need user input to fill in details on unknown devices. ++ */ ++ /* SoundGraph iMON OEM Touch LCD (IR & 7" VGA LCD) */ ++ { USB_DEVICE(0x15c2, 0x0034) }, ++ /* SoundGraph iMON OEM Touch LCD (IR & 4.3" VGA LCD) */ ++ { USB_DEVICE(0x15c2, 0x0035) }, ++ /* SoundGraph iMON OEM VFD (IR & VFD) */ ++ { USB_DEVICE(0x15c2, 0x0036) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x0037) }, ++ /* SoundGraph iMON OEM LCD (IR & LCD) */ ++ { USB_DEVICE(0x15c2, 0x0038) }, ++ /* SoundGraph iMON UltraBay (IR & LCD) */ ++ { USB_DEVICE(0x15c2, 0x0039) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x003a) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x003b) }, ++ /* SoundGraph iMON OEM Inside (IR only) */ ++ { USB_DEVICE(0x15c2, 0x003c) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x003d) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x003e) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x003f) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x0040) }, ++ /* SoundGraph iMON MINI (IR only) */ ++ { USB_DEVICE(0x15c2, 0x0041) }, ++ /* Antec Veris Multimedia Station EZ External (IR only) */ ++ { USB_DEVICE(0x15c2, 0x0042) }, ++ /* Antec Veris Multimedia Station Basic Internal (IR only) */ ++ { USB_DEVICE(0x15c2, 0x0043) }, ++ /* Antec Veris Multimedia Station Elite (IR & VFD) */ ++ { USB_DEVICE(0x15c2, 0x0044) }, ++ /* Antec Veris Multimedia Station Premiere (IR & LCD) */ ++ { USB_DEVICE(0x15c2, 0x0045) }, ++ /* device specifics unknown */ ++ { USB_DEVICE(0x15c2, 0x0046) }, ++ {} ++}; ++ ++/* iMON LCD models use a different write op */ ++static struct usb_device_id lcd_device_list[] = { ++ { USB_DEVICE(0x15c2, 0xffdc) }, ++ { USB_DEVICE(0x15c2, 0x0038) }, ++ { USB_DEVICE(0x15c2, 0x0039) }, ++ { USB_DEVICE(0x15c2, 0x0045) }, ++ {} ++}; ++ ++/* Some iMON devices have no lcd/vfd, don't set one up */ ++static struct usb_device_id ir_only_list[] = { ++ /* the first imon lcd and the knob share this device id. :\ */ ++ /*{ USB_DEVICE(0x15c2, 0xffdc) },*/ ++ { USB_DEVICE(0x15c2, 0x003c) }, ++ { USB_DEVICE(0x15c2, 0x0041) }, ++ { USB_DEVICE(0x15c2, 0x0042) }, ++ { USB_DEVICE(0x15c2, 0x0043) }, ++ {} ++}; ++ ++/* iMON devices with VGA touchscreens */ ++static struct usb_device_id imon_touchscreen_list[] = { ++ { USB_DEVICE(0x15c2, 0x0034) }, ++ { USB_DEVICE(0x15c2, 0x0035) }, ++ {} ++}; ++ ++/* USB Device data */ ++static struct usb_driver imon_driver = { ++ .name = MOD_NAME, ++ .probe = imon_probe, ++ .disconnect = imon_disconnect, ++ .suspend = imon_suspend, ++ .resume = imon_resume, ++ .id_table = imon_usb_id_table, ++}; ++ ++static struct usb_class_driver imon_vfd_class = { ++ .name = DEVICE_NAME, ++ .fops = &vfd_fops, ++ .minor_base = DISPLAY_MINOR_BASE, ++}; ++ ++static struct usb_class_driver imon_lcd_class = { ++ .name = DEVICE_NAME, ++ .fops = &lcd_fops, ++ .minor_base = DISPLAY_MINOR_BASE, ++}; ++ ++/* ++ * standard imon remote key table, which isn't really entirely ++ * "standard", as different receivers decode the same key on the ++ * same remote to different hex codes... ugh. ++ */ ++static const struct key_entry imon_remote_key_table[] = { ++ /* keys sorted mostly by frequency of use to optimize lookups */ ++ { KE_KEY, 0x2a8195b7, { KEY_REWIND } }, ++ { KE_KEY, 0x298315b7, { KEY_REWIND } }, ++ { KE_KEY, 0x2b8115b7, { KEY_FASTFORWARD } }, ++ { KE_KEY, 0x2b8315b7, { KEY_FASTFORWARD } }, ++ { KE_KEY, 0x2b9115b7, { KEY_PREVIOUS } }, ++ { KE_KEY, 0x298195b7, { KEY_NEXT } }, ++ ++ { KE_KEY, 0x2a8115b7, { KEY_PLAY } }, ++ { KE_KEY, 0x2a8315b7, { KEY_PLAY } }, ++ { KE_KEY, 0x2a9115b7, { KEY_PAUSE } }, ++ { KE_KEY, 0x2b9715b7, { KEY_STOP } }, ++ { KE_KEY, 0x298115b7, { KEY_RECORD } }, ++ ++ { KE_KEY, 0x01008000, { KEY_UP } }, ++ { KE_KEY, 0x01007f00, { KEY_DOWN } }, ++ { KE_KEY, 0x01000080, { KEY_LEFT } }, ++ { KE_KEY, 0x0100007f, { KEY_RIGHT } }, ++ ++ { KE_KEY, 0x2aa515b7, { KEY_UP } }, ++ { KE_KEY, 0x289515b7, { KEY_DOWN } }, ++ { KE_KEY, 0x29a515b7, { KEY_LEFT } }, ++ { KE_KEY, 0x2ba515b7, { KEY_RIGHT } }, ++ ++ { KE_KEY, 0x0200002c, { KEY_SPACE } }, /* Select/Space */ ++ { KE_KEY, 0x2a9315b7, { KEY_SPACE } }, /* Select/Space */ ++ { KE_KEY, 0x02000028, { KEY_ENTER } }, ++ { KE_KEY, 0x28a195b7, { KEY_ENTER } }, ++ { KE_KEY, 0x288195b7, { KEY_EXIT } }, ++ { KE_KEY, 0x02000029, { KEY_ESC } }, ++ { KE_KEY, 0x2bb715b7, { KEY_ESC } }, ++ { KE_KEY, 0x0200002a, { KEY_BACKSPACE } }, ++ { KE_KEY, 0x28a115b7, { KEY_BACKSPACE } }, ++ ++ { KE_KEY, 0x2b9595b7, { KEY_MUTE } }, ++ { KE_KEY, 0x28a395b7, { KEY_VOLUMEUP } }, ++ { KE_KEY, 0x28a595b7, { KEY_VOLUMEDOWN } }, ++ { KE_KEY, 0x289395b7, { KEY_CHANNELUP } }, ++ { KE_KEY, 0x288795b7, { KEY_CHANNELDOWN } }, ++ ++ { KE_KEY, 0x0200001e, { KEY_NUMERIC_1 } }, ++ { KE_KEY, 0x0200001f, { KEY_NUMERIC_2 } }, ++ { KE_KEY, 0x02000020, { KEY_NUMERIC_3 } }, ++ { KE_KEY, 0x02000021, { KEY_NUMERIC_4 } }, ++ { KE_KEY, 0x02000022, { KEY_NUMERIC_5 } }, ++ { KE_KEY, 0x02000023, { KEY_NUMERIC_6 } }, ++ { KE_KEY, 0x02000024, { KEY_NUMERIC_7 } }, ++ { KE_KEY, 0x02000025, { KEY_NUMERIC_8 } }, ++ { KE_KEY, 0x02000026, { KEY_NUMERIC_9 } }, ++ { KE_KEY, 0x02000027, { KEY_NUMERIC_0 } }, ++ ++ { KE_KEY, 0x28b595b7, { KEY_NUMERIC_1 } }, ++ { KE_KEY, 0x2bb195b7, { KEY_NUMERIC_2 } }, ++ { KE_KEY, 0x28b195b7, { KEY_NUMERIC_3 } }, ++ { KE_KEY, 0x2a8595b7, { KEY_NUMERIC_4 } }, ++ { KE_KEY, 0x299595b7, { KEY_NUMERIC_5 } }, ++ { KE_KEY, 0x2aa595b7, { KEY_NUMERIC_6 } }, ++ { KE_KEY, 0x2b9395b7, { KEY_NUMERIC_7 } }, ++ { KE_KEY, 0x2a8515b7, { KEY_NUMERIC_8 } }, ++ { KE_KEY, 0x2aa115b7, { KEY_NUMERIC_9 } }, ++ { KE_KEY, 0x2ba595b7, { KEY_NUMERIC_0 } }, ++ ++ { KE_KEY, 0x02200025, { KEY_NUMERIC_STAR } }, ++ { KE_KEY, 0x28b515b7, { KEY_NUMERIC_STAR } }, ++ { KE_KEY, 0x02200020, { KEY_NUMERIC_POUND } }, ++ { KE_KEY, 0x29a115b7, { KEY_NUMERIC_POUND } }, ++ ++ { KE_KEY, 0x2b8515b7, { KEY_VIDEO } }, ++ { KE_KEY, 0x299195b7, { KEY_AUDIO } }, ++ { KE_KEY, 0x2ba115b7, { KEY_CAMERA } }, ++ { KE_KEY, 0x28a515b7, { KEY_TV } }, ++ { KE_KEY, 0x29a395b7, { KEY_DVD } }, ++ { KE_KEY, 0x29a295b7, { KEY_DVD } }, ++ ++ /* the Menu key between DVD and Subtitle on the RM-200... */ ++ { KE_KEY, 0x2ba385b7, { KEY_MENU } }, ++ { KE_KEY, 0x2ba395b7, { KEY_MENU } }, ++ ++ { KE_KEY, 0x288515b7, { KEY_BOOKMARKS } }, ++ { KE_KEY, 0x2ab715b7, { KEY_MEDIA } }, /* Thumbnail */ ++ { KE_KEY, 0x298595b7, { KEY_SUBTITLE } }, ++ { KE_KEY, 0x2b8595b7, { KEY_LANGUAGE } }, ++ ++ { KE_KEY, 0x29a595b7, { KEY_ZOOM } }, ++ { KE_KEY, 0x2aa395b7, { KEY_SCREEN } }, /* FullScreen */ ++ ++ { KE_KEY, 0x299115b7, { KEY_KEYBOARD } }, ++ { KE_KEY, 0x299135b7, { KEY_KEYBOARD } }, ++ ++ { KE_KEY, 0x01010000, { BTN_LEFT } }, ++ { KE_KEY, 0x01020000, { BTN_RIGHT } }, ++ { KE_KEY, 0x01010080, { BTN_LEFT } }, ++ { KE_KEY, 0x01020080, { BTN_RIGHT } }, ++ { KE_KEY, 0x688301b7, { BTN_LEFT } }, ++ { KE_KEY, 0x688481b7, { BTN_RIGHT } }, ++ ++ { KE_KEY, 0x2a9395b7, { KEY_CYCLEWINDOWS } }, /* TaskSwitcher */ ++ { KE_KEY, 0x2b8395b7, { KEY_TIME } }, /* Timer */ ++ ++ { KE_KEY, 0x289115b7, { KEY_POWER } }, ++ { KE_KEY, 0x29b195b7, { KEY_EJECTCD } }, /* the one next to play */ ++ { KE_KEY, 0x299395b7, { KEY_EJECTCLOSECD } }, /* eject (by TaskSw) */ ++ ++ { KE_KEY, 0x02800000, { KEY_CONTEXT_MENU } }, /* Left Menu */ ++ { KE_KEY, 0x2b8195b7, { KEY_CONTEXT_MENU } }, /* Left Menu*/ ++ { KE_KEY, 0x02000065, { KEY_COMPOSE } }, /* RightMenu */ ++ { KE_KEY, 0x28b715b7, { KEY_COMPOSE } }, /* RightMenu */ ++ { KE_KEY, 0x2ab195b7, { KEY_PROG1 } }, /* Go or MultiMon */ ++ { KE_KEY, 0x29b715b7, { KEY_DASHBOARD } }, /* AppLauncher */ ++ { KE_END, 0 } ++}; ++ ++/* mce-mode imon mce remote key table */ ++static const struct key_entry imon_mce_key_table[] = { ++ /* keys sorted mostly by frequency of use to optimize lookups */ ++ { KE_KEY, 0x800ff415, { KEY_REWIND } }, ++ { KE_KEY, 0x800ff414, { KEY_FASTFORWARD } }, ++ { KE_KEY, 0x800ff41b, { KEY_PREVIOUS } }, ++ { KE_KEY, 0x800ff41a, { KEY_NEXT } }, ++ ++ { KE_KEY, 0x800ff416, { KEY_PLAY } }, ++ { KE_KEY, 0x800ff418, { KEY_PAUSE } }, ++ { KE_KEY, 0x800ff419, { KEY_STOP } }, ++ { KE_KEY, 0x800ff417, { KEY_RECORD } }, ++ ++ { KE_KEY, 0x02000052, { KEY_UP } }, ++ { KE_KEY, 0x02000051, { KEY_DOWN } }, ++ { KE_KEY, 0x02000050, { KEY_LEFT } }, ++ { KE_KEY, 0x0200004f, { KEY_RIGHT } }, ++ ++ { KE_KEY, 0x800ff41e, { KEY_UP } }, ++ { KE_KEY, 0x800ff41f, { KEY_DOWN } }, ++ { KE_KEY, 0x800ff420, { KEY_LEFT } }, ++ { KE_KEY, 0x800ff421, { KEY_RIGHT } }, ++ ++ /* 0x800ff40b also KEY_NUMERIC_POUND on some receivers */ ++ { KE_KEY, 0x800ff40b, { KEY_ENTER } }, ++ { KE_KEY, 0x02000028, { KEY_ENTER } }, ++/* the OK and Enter buttons decode to the same value on some remotes ++ { KE_KEY, 0x02000028, { KEY_OK } }, */ ++ { KE_KEY, 0x800ff422, { KEY_OK } }, ++ { KE_KEY, 0x0200002a, { KEY_EXIT } }, ++ { KE_KEY, 0x800ff423, { KEY_EXIT } }, ++ { KE_KEY, 0x02000029, { KEY_DELETE } }, ++ /* 0x800ff40a also KEY_NUMERIC_STAR on some receivers */ ++ { KE_KEY, 0x800ff40a, { KEY_DELETE } }, ++ ++ { KE_KEY, 0x800ff40e, { KEY_MUTE } }, ++ { KE_KEY, 0x800ff410, { KEY_VOLUMEUP } }, ++ { KE_KEY, 0x800ff411, { KEY_VOLUMEDOWN } }, ++ { KE_KEY, 0x800ff412, { KEY_CHANNELUP } }, ++ { KE_KEY, 0x800ff413, { KEY_CHANNELDOWN } }, ++ ++ { KE_KEY, 0x0200001e, { KEY_NUMERIC_1 } }, ++ { KE_KEY, 0x0200001f, { KEY_NUMERIC_2 } }, ++ { KE_KEY, 0x02000020, { KEY_NUMERIC_3 } }, ++ { KE_KEY, 0x02000021, { KEY_NUMERIC_4 } }, ++ { KE_KEY, 0x02000022, { KEY_NUMERIC_5 } }, ++ { KE_KEY, 0x02000023, { KEY_NUMERIC_6 } }, ++ { KE_KEY, 0x02000024, { KEY_NUMERIC_7 } }, ++ { KE_KEY, 0x02000025, { KEY_NUMERIC_8 } }, ++ { KE_KEY, 0x02000026, { KEY_NUMERIC_9 } }, ++ { KE_KEY, 0x02000027, { KEY_NUMERIC_0 } }, ++ ++ { KE_KEY, 0x800ff401, { KEY_NUMERIC_1 } }, ++ { KE_KEY, 0x800ff402, { KEY_NUMERIC_2 } }, ++ { KE_KEY, 0x800ff403, { KEY_NUMERIC_3 } }, ++ { KE_KEY, 0x800ff404, { KEY_NUMERIC_4 } }, ++ { KE_KEY, 0x800ff405, { KEY_NUMERIC_5 } }, ++ { KE_KEY, 0x800ff406, { KEY_NUMERIC_6 } }, ++ { KE_KEY, 0x800ff407, { KEY_NUMERIC_7 } }, ++ { KE_KEY, 0x800ff408, { KEY_NUMERIC_8 } }, ++ { KE_KEY, 0x800ff409, { KEY_NUMERIC_9 } }, ++ { KE_KEY, 0x800ff400, { KEY_NUMERIC_0 } }, ++ ++ { KE_KEY, 0x02200025, { KEY_NUMERIC_STAR } }, ++ { KE_KEY, 0x02200020, { KEY_NUMERIC_POUND } }, ++ /* 0x800ff41d also KEY_BLUE on some receivers */ ++ { KE_KEY, 0x800ff41d, { KEY_NUMERIC_STAR } }, ++ /* 0x800ff41c also KEY_PREVIOUS on some receivers */ ++ { KE_KEY, 0x800ff41c, { KEY_NUMERIC_POUND } }, ++ ++ { KE_KEY, 0x800ff446, { KEY_TV } }, ++ { KE_KEY, 0x800ff447, { KEY_AUDIO } }, /* My Music */ ++ { KE_KEY, 0x800ff448, { KEY_PVR } }, /* RecordedTV */ ++ { KE_KEY, 0x800ff449, { KEY_CAMERA } }, ++ { KE_KEY, 0x800ff44a, { KEY_VIDEO } }, ++ /* 0x800ff424 also KEY_MENU on some receivers */ ++ { KE_KEY, 0x800ff424, { KEY_DVD } }, ++ /* 0x800ff425 also KEY_GREEN on some receivers */ ++ { KE_KEY, 0x800ff425, { KEY_TUNER } }, /* LiveTV */ ++ { KE_KEY, 0x800ff450, { KEY_RADIO } }, ++ ++ { KE_KEY, 0x800ff44c, { KEY_LANGUAGE } }, ++ { KE_KEY, 0x800ff427, { KEY_ZOOM } }, /* Aspect */ ++ ++ { KE_KEY, 0x800ff45b, { KEY_RED } }, ++ { KE_KEY, 0x800ff45c, { KEY_GREEN } }, ++ { KE_KEY, 0x800ff45d, { KEY_YELLOW } }, ++ { KE_KEY, 0x800ff45e, { KEY_BLUE } }, ++ ++ { KE_KEY, 0x800ff466, { KEY_RED } }, ++ /* { KE_KEY, 0x800ff425, { KEY_GREEN } }, */ ++ { KE_KEY, 0x800ff468, { KEY_YELLOW } }, ++ /* { KE_KEY, 0x800ff41d, { KEY_BLUE } }, */ ++ ++ { KE_KEY, 0x800ff40f, { KEY_INFO } }, ++ { KE_KEY, 0x800ff426, { KEY_EPG } }, /* Guide */ ++ { KE_KEY, 0x800ff45a, { KEY_SUBTITLE } }, /* Caption/Teletext */ ++ { KE_KEY, 0x800ff44d, { KEY_TITLE } }, ++ ++ { KE_KEY, 0x800ff40c, { KEY_POWER } }, ++ { KE_KEY, 0x800ff40d, { KEY_PROG1 } }, /* Windows MCE button */ ++ { KE_END, 0 } ++ ++}; ++ ++/* imon receiver front panel/knob key table */ ++static const struct { ++ u64 hw_code; ++ u16 keycode; ++} imon_panel_key_table[] = { ++ { 0x000000000f00ffee, KEY_PROG1 }, /* Go */ ++ { 0x000000001f00ffee, KEY_AUDIO }, ++ { 0x000000002000ffee, KEY_VIDEO }, ++ { 0x000000002100ffee, KEY_CAMERA }, ++ { 0x000000002700ffee, KEY_DVD }, ++ { 0x000000002300ffee, KEY_TV }, ++ { 0x000000000500ffee, KEY_PREVIOUS }, ++ { 0x000000000700ffee, KEY_REWIND }, ++ { 0x000000000400ffee, KEY_STOP }, ++ { 0x000000003c00ffee, KEY_PLAYPAUSE }, ++ { 0x000000000800ffee, KEY_FASTFORWARD }, ++ { 0x000000000600ffee, KEY_NEXT }, ++ { 0x000000010000ffee, KEY_RIGHT }, ++ { 0x000001000000ffee, KEY_LEFT }, ++ { 0x000000003d00ffee, KEY_SELECT }, ++ { 0x000100000000ffee, KEY_VOLUMEUP }, ++ { 0x010000000000ffee, KEY_VOLUMEDOWN }, ++ { 0x000000000100ffee, KEY_MUTE }, ++ /* iMON Knob values */ ++ { 0x000100ffffffffee, KEY_VOLUMEUP }, ++ { 0x010000ffffffffee, KEY_VOLUMEDOWN }, ++ { 0x000008ffffffffee, KEY_MUTE }, ++}; ++ ++/* to prevent races between open() and disconnect(), probing, etc */ ++static DEFINE_MUTEX(driver_lock); ++ ++/* Module bookkeeping bits */ ++MODULE_AUTHOR(MOD_AUTHOR); ++MODULE_DESCRIPTION(MOD_DESC); ++MODULE_VERSION(MOD_VERSION); ++MODULE_LICENSE("GPL"); ++MODULE_DEVICE_TABLE(usb, imon_usb_id_table); ++ ++static bool debug; ++module_param(debug, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(debug, "Debug messages: 0=no, 1=yes(default: no)"); ++ ++/* lcd, vfd, vga or none? should be auto-detected, but can be overridden... */ ++static int display_type; ++module_param(display_type, int, S_IRUGO); ++MODULE_PARM_DESC(display_type, "Type of attached display. 0=autodetect, " ++ "1=vfd, 2=lcd, 3=vga, 4=none (default: autodetect)"); ++ ++/* IR protocol: native iMON, Windows MCE (RC-6), or iMON w/o PAD stabilize */ ++static int ir_protocol; ++module_param(ir_protocol, int, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(ir_protocol, "Which IR protocol to use. 0=native iMON, " ++ "1=Windows Media Center Ed. (RC-6), 2=iMON w/o PAD stabilize " ++ "(default: native iMON)"); ++ ++/* ++ * In certain use cases, mouse mode isn't really helpful, and could actually ++ * cause confusion, so allow disabling it when the IR device is open. ++ */ ++static bool nomouse; ++module_param(nomouse, bool, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(nomouse, "Disable mouse input device mode when IR device is " ++ "open. 0=don't disable, 1=disable. (default: don't disable)"); ++ ++/* threshold at which a pad push registers as an arrow key in kbd mode */ ++static int pad_thresh; ++module_param(pad_thresh, int, S_IRUGO | S_IWUSR); ++MODULE_PARM_DESC(pad_thresh, "Threshold at which a pad push registers as an " ++ "arrow key in kbd mode (default: 28)"); ++ ++ ++static void free_imon_context(struct imon_context *ictx) ++{ ++ struct device *dev = ictx->dev; ++ ++ usb_free_urb(ictx->tx_urb); ++ usb_free_urb(ictx->rx_urb_intf0); ++ usb_free_urb(ictx->rx_urb_intf1); ++ kfree(ictx); ++ ++ dev_dbg(dev, "%s: iMON context freed\n", __func__); ++} ++ ++/** ++ * Called when the Display device (e.g. /dev/lcd0) ++ * is opened by the application. ++ */ ++static int display_open(struct inode *inode, struct file *file) ++{ ++ struct usb_interface *interface; ++ struct imon_context *ictx = NULL; ++ int subminor; ++ int retval = 0; ++ ++ /* prevent races with disconnect */ ++ mutex_lock(&driver_lock); ++ ++ subminor = iminor(inode); ++ interface = usb_find_interface(&imon_driver, subminor); ++ if (!interface) { ++ err("%s: could not find interface for minor %d", ++ __func__, subminor); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ictx = usb_get_intfdata(interface); ++ ++ if (!ictx) { ++ err("%s: no context found for minor %d", __func__, subminor); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ mutex_lock(&ictx->lock); ++ ++ if (!ictx->display_supported) { ++ err("%s: display not supported by device", __func__); ++ retval = -ENODEV; ++ } else if (ictx->display_isopen) { ++ err("%s: display port is already open", __func__); ++ retval = -EBUSY; ++ } else { ++ ictx->display_isopen = 1; ++ file->private_data = ictx; ++ dev_dbg(ictx->dev, "display port opened\n"); ++ } ++ ++ mutex_unlock(&ictx->lock); ++ ++exit: ++ mutex_unlock(&driver_lock); ++ return retval; ++} ++ ++/** ++ * Called when the display device (e.g. /dev/lcd0) ++ * is closed by the application. ++ */ ++static int display_close(struct inode *inode, struct file *file) ++{ ++ struct imon_context *ictx = NULL; ++ int retval = 0; ++ ++ ictx = (struct imon_context *)file->private_data; ++ ++ if (!ictx) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&ictx->lock); ++ ++ if (!ictx->display_supported) { ++ err("%s: display not supported by device", __func__); ++ retval = -ENODEV; ++ } else if (!ictx->display_isopen) { ++ err("%s: display is not open", __func__); ++ retval = -EIO; ++ } else { ++ ictx->display_isopen = 0; ++ dev_dbg(ictx->dev, "display port closed\n"); ++ if (!ictx->dev_present_intf0) { ++ /* ++ * Device disconnected before close and IR port is not ++ * open. If IR port is open, context will be deleted by ++ * ir_close. ++ */ ++ mutex_unlock(&ictx->lock); ++ free_imon_context(ictx); ++ return retval; ++ } ++ } ++ ++ mutex_unlock(&ictx->lock); ++ return retval; ++} ++ ++/** ++ * Sends a packet to the device -- this function must be called ++ * with ictx->lock held. ++ */ ++static int send_packet(struct imon_context *ictx) ++{ ++ unsigned int pipe; ++ int interval = 0; ++ int retval = 0; ++ struct usb_ctrlrequest *control_req = NULL; ++ ++ /* Check if we need to use control or interrupt urb */ ++ if (!ictx->tx_control) { ++ pipe = usb_sndintpipe(ictx->usbdev_intf0, ++ ictx->tx_endpoint->bEndpointAddress); ++ interval = ictx->tx_endpoint->bInterval; ++ ++ usb_fill_int_urb(ictx->tx_urb, ictx->usbdev_intf0, pipe, ++ ictx->usb_tx_buf, ++ sizeof(ictx->usb_tx_buf), ++ usb_tx_callback, ictx, interval); ++ ++ ictx->tx_urb->actual_length = 0; ++ } else { ++ /* fill request into kmalloc'ed space: */ ++ control_req = kmalloc(sizeof(struct usb_ctrlrequest), ++ GFP_KERNEL); ++ if (control_req == NULL) ++ return -ENOMEM; ++ ++ /* setup packet is '21 09 0200 0001 0008' */ ++ control_req->bRequestType = 0x21; ++ control_req->bRequest = 0x09; ++ control_req->wValue = cpu_to_le16(0x0200); ++ control_req->wIndex = cpu_to_le16(0x0001); ++ control_req->wLength = cpu_to_le16(0x0008); ++ ++ /* control pipe is endpoint 0x00 */ ++ pipe = usb_sndctrlpipe(ictx->usbdev_intf0, 0); ++ ++ /* build the control urb */ ++ usb_fill_control_urb(ictx->tx_urb, ictx->usbdev_intf0, ++ pipe, (unsigned char *)control_req, ++ ictx->usb_tx_buf, ++ sizeof(ictx->usb_tx_buf), ++ usb_tx_callback, ictx); ++ ictx->tx_urb->actual_length = 0; ++ } ++ ++ init_completion(&ictx->tx.finished); ++ ictx->tx.busy = 1; ++ smp_rmb(); /* ensure later readers know we're busy */ ++ ++ retval = usb_submit_urb(ictx->tx_urb, GFP_KERNEL); ++ if (retval) { ++ ictx->tx.busy = 0; ++ smp_rmb(); /* ensure later readers know we're not busy */ ++ err("%s: error submitting urb(%d)", __func__, retval); ++ } else { ++ /* Wait for transmission to complete (or abort) */ ++ mutex_unlock(&ictx->lock); ++ retval = wait_for_completion_interruptible( ++ &ictx->tx.finished); ++ if (retval) ++ err("%s: task interrupted", __func__); ++ mutex_lock(&ictx->lock); ++ ++ retval = ictx->tx.status; ++ if (retval) ++ err("%s: packet tx failed (%d)", __func__, retval); ++ } ++ ++ kfree(control_req); ++ ++ return retval; ++} ++ ++/** ++ * Sends an associate packet to the iMON 2.4G. ++ * ++ * This might not be such a good idea, since it has an id collision with ++ * some versions of the "IR & VFD" combo. The only way to determine if it ++ * is an RF version is to look at the product description string. (Which ++ * we currently do not fetch). ++ */ ++static int send_associate_24g(struct imon_context *ictx) ++{ ++ int retval; ++ const unsigned char packet[8] = { 0x01, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x20 }; ++ ++ if (!ictx) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ if (!ictx->dev_present_intf0) { ++ err("%s: no iMON device present", __func__); ++ return -ENODEV; ++ } ++ ++ memcpy(ictx->usb_tx_buf, packet, sizeof(packet)); ++ retval = send_packet(ictx); ++ ++ return retval; ++} ++ ++/** ++ * Sends packets to setup and show clock on iMON display ++ * ++ * Arguments: year - last 2 digits of year, month - 1..12, ++ * day - 1..31, dow - day of the week (0-Sun...6-Sat), ++ * hour - 0..23, minute - 0..59, second - 0..59 ++ */ ++static int send_set_imon_clock(struct imon_context *ictx, ++ unsigned int year, unsigned int month, ++ unsigned int day, unsigned int dow, ++ unsigned int hour, unsigned int minute, ++ unsigned int second) ++{ ++ unsigned char clock_enable_pkt[IMON_CLOCK_ENABLE_PACKETS][8]; ++ int retval = 0; ++ int i; ++ ++ if (!ictx) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ switch (ictx->display_type) { ++ case IMON_DISPLAY_TYPE_LCD: ++ clock_enable_pkt[0][0] = 0x80; ++ clock_enable_pkt[0][1] = year; ++ clock_enable_pkt[0][2] = month-1; ++ clock_enable_pkt[0][3] = day; ++ clock_enable_pkt[0][4] = hour; ++ clock_enable_pkt[0][5] = minute; ++ clock_enable_pkt[0][6] = second; ++ ++ clock_enable_pkt[1][0] = 0x80; ++ clock_enable_pkt[1][1] = 0; ++ clock_enable_pkt[1][2] = 0; ++ clock_enable_pkt[1][3] = 0; ++ clock_enable_pkt[1][4] = 0; ++ clock_enable_pkt[1][5] = 0; ++ clock_enable_pkt[1][6] = 0; ++ ++ if (ictx->product == 0xffdc) { ++ clock_enable_pkt[0][7] = 0x50; ++ clock_enable_pkt[1][7] = 0x51; ++ } else { ++ clock_enable_pkt[0][7] = 0x88; ++ clock_enable_pkt[1][7] = 0x8a; ++ } ++ ++ break; ++ ++ case IMON_DISPLAY_TYPE_VFD: ++ clock_enable_pkt[0][0] = year; ++ clock_enable_pkt[0][1] = month-1; ++ clock_enable_pkt[0][2] = day; ++ clock_enable_pkt[0][3] = dow; ++ clock_enable_pkt[0][4] = hour; ++ clock_enable_pkt[0][5] = minute; ++ clock_enable_pkt[0][6] = second; ++ clock_enable_pkt[0][7] = 0x40; ++ ++ clock_enable_pkt[1][0] = 0; ++ clock_enable_pkt[1][1] = 0; ++ clock_enable_pkt[1][2] = 1; ++ clock_enable_pkt[1][3] = 0; ++ clock_enable_pkt[1][4] = 0; ++ clock_enable_pkt[1][5] = 0; ++ clock_enable_pkt[1][6] = 0; ++ clock_enable_pkt[1][7] = 0x42; ++ ++ break; ++ ++ default: ++ return -ENODEV; ++ } ++ ++ for (i = 0; i < IMON_CLOCK_ENABLE_PACKETS; i++) { ++ memcpy(ictx->usb_tx_buf, clock_enable_pkt[i], 8); ++ retval = send_packet(ictx); ++ if (retval) { ++ err("%s: send_packet failed for packet %d", ++ __func__, i); ++ break; ++ } ++ } ++ ++ return retval; ++} ++ ++/** ++ * These are the sysfs functions to handle the association on the iMON 2.4G LT. ++ */ ++static ssize_t show_associate_remote(struct device *d, ++ struct device_attribute *attr, ++ char *buf) ++{ ++ struct imon_context *ictx = dev_get_drvdata(d); ++ ++ if (!ictx) ++ return -ENODEV; ++ ++ mutex_lock(&ictx->lock); ++ if (ictx->ir_isassociating) ++ strcpy(buf, "associating\n"); ++ else ++ strcpy(buf, "closed\n"); ++ ++ dev_info(d, "Visit http://www.lirc.org/html/imon-24g.html for " ++ "instructions on how to associate your iMON 2.4G DT/LT " ++ "remote\n"); ++ mutex_unlock(&ictx->lock); ++ return strlen(buf); ++} ++ ++static ssize_t store_associate_remote(struct device *d, ++ struct device_attribute *attr, ++ const char *buf, size_t count) ++{ ++ struct imon_context *ictx; ++ ++ ictx = dev_get_drvdata(d); ++ ++ if (!ictx) ++ return -ENODEV; ++ ++ mutex_lock(&ictx->lock); ++ ictx->ir_isassociating = 1; ++ send_associate_24g(ictx); ++ mutex_unlock(&ictx->lock); ++ ++ return count; ++} ++ ++/** ++ * sysfs functions to control internal imon clock ++ */ ++static ssize_t show_imon_clock(struct device *d, ++ struct device_attribute *attr, char *buf) ++{ ++ struct imon_context *ictx = dev_get_drvdata(d); ++ size_t len; ++ ++ if (!ictx) ++ return -ENODEV; ++ ++ mutex_lock(&ictx->lock); ++ ++ if (!ictx->display_supported) { ++ len = snprintf(buf, PAGE_SIZE, "Not supported."); ++ } else { ++ len = snprintf(buf, PAGE_SIZE, ++ "To set the clock on your iMON display:\n" ++ "# date \"+%%y %%m %%d %%w %%H %%M %%S\" > imon_clock\n" ++ "%s", ictx->display_isopen ? ++ "\nNOTE: imon device must be closed\n" : ""); ++ } ++ ++ mutex_unlock(&ictx->lock); ++ ++ return len; ++} ++ ++static ssize_t store_imon_clock(struct device *d, ++ struct device_attribute *attr, ++ const char *buf, size_t count) ++{ ++ struct imon_context *ictx = dev_get_drvdata(d); ++ ssize_t retval; ++ unsigned int year, month, day, dow, hour, minute, second; ++ ++ if (!ictx) ++ return -ENODEV; ++ ++ mutex_lock(&ictx->lock); ++ ++ if (!ictx->display_supported) { ++ retval = -ENODEV; ++ goto exit; ++ } else if (ictx->display_isopen) { ++ retval = -EBUSY; ++ goto exit; ++ } ++ ++ if (sscanf(buf, "%u %u %u %u %u %u %u", &year, &month, &day, &dow, ++ &hour, &minute, &second) != 7) { ++ retval = -EINVAL; ++ goto exit; ++ } ++ ++ if ((month < 1 || month > 12) || ++ (day < 1 || day > 31) || (dow > 6) || ++ (hour > 23) || (minute > 59) || (second > 59)) { ++ retval = -EINVAL; ++ goto exit; ++ } ++ ++ retval = send_set_imon_clock(ictx, year, month, day, dow, ++ hour, minute, second); ++ if (retval) ++ goto exit; ++ ++ retval = count; ++exit: ++ mutex_unlock(&ictx->lock); ++ ++ return retval; ++} ++ ++ ++static DEVICE_ATTR(imon_clock, S_IWUSR | S_IRUGO, show_imon_clock, ++ store_imon_clock); ++ ++static DEVICE_ATTR(associate_remote, S_IWUSR | S_IRUGO, show_associate_remote, ++ store_associate_remote); ++ ++static struct attribute *imon_display_sysfs_entries[] = { ++ &dev_attr_imon_clock.attr, ++ NULL ++}; ++ ++static struct attribute_group imon_display_attribute_group = { ++ .attrs = imon_display_sysfs_entries ++}; ++ ++static struct attribute *imon_rf_sysfs_entries[] = { ++ &dev_attr_associate_remote.attr, ++ NULL ++}; ++ ++static struct attribute_group imon_rf_attribute_group = { ++ .attrs = imon_rf_sysfs_entries ++}; ++ ++/** ++ * Writes data to the VFD. The iMON VFD is 2x16 characters ++ * and requires data in 5 consecutive USB interrupt packets, ++ * each packet but the last carrying 7 bytes. ++ * ++ * I don't know if the VFD board supports features such as ++ * scrolling, clearing rows, blanking, etc. so at ++ * the caller must provide a full screen of data. If fewer ++ * than 32 bytes are provided spaces will be appended to ++ * generate a full screen. ++ */ ++static ssize_t vfd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos) ++{ ++ int i; ++ int offset; ++ int seq; ++ int retval = 0; ++ struct imon_context *ictx; ++ const unsigned char vfd_packet6[] = { ++ 0x01, 0x00, 0x00, 0x00, 0x00, 0xFF, 0xFF }; ++ ++ ictx = (struct imon_context *)file->private_data; ++ if (!ictx) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&ictx->lock); ++ ++ if (!ictx->dev_present_intf0) { ++ err("%s: no iMON device present", __func__); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ if (n_bytes <= 0 || n_bytes > 32) { ++ err("%s: invalid payload size", __func__); ++ retval = -EINVAL; ++ goto exit; ++ } ++ ++ if (copy_from_user(ictx->tx.data_buf, buf, n_bytes)) { ++ retval = -EFAULT; ++ goto exit; ++ } ++ ++ /* Pad with spaces */ ++ for (i = n_bytes; i < 32; ++i) ++ ictx->tx.data_buf[i] = ' '; ++ ++ for (i = 32; i < 35; ++i) ++ ictx->tx.data_buf[i] = 0xFF; ++ ++ offset = 0; ++ seq = 0; ++ ++ do { ++ memcpy(ictx->usb_tx_buf, ictx->tx.data_buf + offset, 7); ++ ictx->usb_tx_buf[7] = (unsigned char) seq; ++ ++ retval = send_packet(ictx); ++ if (retval) { ++ err("%s: send packet failed for packet #%d", ++ __func__, seq/2); ++ goto exit; ++ } else { ++ seq += 2; ++ offset += 7; ++ } ++ ++ } while (offset < 35); ++ ++ /* Send packet #6 */ ++ memcpy(ictx->usb_tx_buf, &vfd_packet6, sizeof(vfd_packet6)); ++ ictx->usb_tx_buf[7] = (unsigned char) seq; ++ retval = send_packet(ictx); ++ if (retval) ++ err("%s: send packet failed for packet #%d", ++ __func__, seq / 2); ++ ++exit: ++ mutex_unlock(&ictx->lock); ++ ++ return (!retval) ? n_bytes : retval; ++} ++ ++/** ++ * Writes data to the LCD. The iMON OEM LCD screen expects 8-byte ++ * packets. We accept data as 16 hexadecimal digits, followed by a ++ * newline (to make it easy to drive the device from a command-line ++ * -- even though the actual binary data is a bit complicated). ++ * ++ * The device itself is not a "traditional" text-mode display. It's ++ * actually a 16x96 pixel bitmap display. That means if you want to ++ * display text, you've got to have your own "font" and translate the ++ * text into bitmaps for display. This is really flexible (you can ++ * display whatever diacritics you need, and so on), but it's also ++ * a lot more complicated than most LCDs... ++ */ ++static ssize_t lcd_write(struct file *file, const char *buf, ++ size_t n_bytes, loff_t *pos) ++{ ++ int retval = 0; ++ struct imon_context *ictx; ++ ++ ictx = (struct imon_context *)file->private_data; ++ if (!ictx) { ++ err("%s: no context for device", __func__); ++ return -ENODEV; ++ } ++ ++ mutex_lock(&ictx->lock); ++ ++ if (!ictx->display_supported) { ++ err("%s: no iMON display present", __func__); ++ retval = -ENODEV; ++ goto exit; ++ } ++ ++ if (n_bytes != 8) { ++ err("%s: invalid payload size: %d (expecting 8)", ++ __func__, (int) n_bytes); ++ retval = -EINVAL; ++ goto exit; ++ } ++ ++ if (copy_from_user(ictx->usb_tx_buf, buf, 8)) { ++ retval = -EFAULT; ++ goto exit; ++ } ++ ++ retval = send_packet(ictx); ++ if (retval) { ++ err("%s: send packet failed!", __func__); ++ goto exit; ++ } else { ++ dev_dbg(ictx->dev, "%s: write %d bytes to LCD\n", ++ __func__, (int) n_bytes); ++ } ++exit: ++ mutex_unlock(&ictx->lock); ++ return (!retval) ? n_bytes : retval; ++} ++ ++/** ++ * Callback function for USB core API: transmit data ++ */ ++static void usb_tx_callback(struct urb *urb) ++{ ++ struct imon_context *ictx; ++ ++ if (!urb) ++ return; ++ ictx = (struct imon_context *)urb->context; ++ if (!ictx) ++ return; ++ ++ ictx->tx.status = urb->status; ++ ++ /* notify waiters that write has finished */ ++ ictx->tx.busy = 0; ++ smp_rmb(); /* ensure later readers know we're not busy */ ++ complete(&ictx->tx.finished); ++} ++ ++/** ++ * mce/rc6 keypresses have no distinct release code, use timer ++ */ ++static void imon_mce_timeout(unsigned long data) ++{ ++ struct imon_context *ictx = (struct imon_context *)data; ++ ++ input_report_key(ictx->idev, ictx->last_keycode, 0); ++ input_sync(ictx->idev); ++} ++ ++/** ++ * report touchscreen input ++ */ ++static void imon_touch_display_timeout(unsigned long data) ++{ ++ struct imon_context *ictx = (struct imon_context *)data; ++ ++ if (!ictx->display_type == IMON_DISPLAY_TYPE_VGA) ++ return; ++ ++ input_report_abs(ictx->touch, ABS_X, ictx->touch_x); ++ input_report_abs(ictx->touch, ABS_Y, ictx->touch_y); ++ input_report_key(ictx->touch, BTN_TOUCH, 0x00); ++ input_sync(ictx->touch); ++} ++ ++/** ++ * iMON IR receivers support two different signal sets -- those used by ++ * the iMON remotes, and those used by the Windows MCE remotes (which is ++ * really just RC-6), but only one or the other at a time, as the signals ++ * are decoded onboard the receiver. ++ */ ++static void imon_set_ir_protocol(struct imon_context *ictx) ++{ ++ int retval; ++ struct device *dev = ictx->dev; ++ unsigned char ir_proto_packet[] = { ++ 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x86 }; ++ ++ switch (ir_protocol) { ++ case IMON_IR_PROTOCOL_MCE: ++ dev_dbg(dev, "Configuring IR receiver for MCE protocol\n"); ++ ir_proto_packet[0] = 0x01; ++ ictx->ir_protocol = IMON_IR_PROTOCOL_MCE; ++ ictx->pad_mouse = 0; ++ init_timer(&ictx->itimer); ++ ictx->itimer.data = (unsigned long)ictx; ++ ictx->itimer.function = imon_mce_timeout; ++ break; ++ case IMON_IR_PROTOCOL_IMON: ++ dev_dbg(dev, "Configuring IR receiver for iMON protocol\n"); ++ /* ir_proto_packet[0] = 0x00; // already the default */ ++ ictx->ir_protocol = IMON_IR_PROTOCOL_IMON; ++ ictx->pad_mouse = 1; ++ break; ++ case IMON_IR_PROTOCOL_IMON_NOPAD: ++ dev_dbg(dev, "Configuring IR receiver for iMON protocol " ++ "without PAD stabilize function enabled\n"); ++ /* ir_proto_packet[0] = 0x00; // already the default */ ++ ictx->ir_protocol = IMON_IR_PROTOCOL_IMON_NOPAD; ++ ictx->pad_mouse = 0; ++ break; ++ default: ++ dev_info(dev, "%s: unknown IR protocol specified, will " ++ "just default to iMON protocol\n", __func__); ++ ictx->ir_protocol = IMON_IR_PROTOCOL_IMON; ++ ictx->pad_mouse = 1; ++ break; ++ } ++ ++ memcpy(ictx->usb_tx_buf, &ir_proto_packet, sizeof(ir_proto_packet)); ++ ++ retval = send_packet(ictx); ++ if (retval) { ++ dev_info(dev, "%s: failed to set IR protocol, falling back " ++ "to standard iMON protocol mode\n", __func__); ++ ir_protocol = IMON_IR_PROTOCOL_IMON; ++ ictx->ir_protocol = IMON_IR_PROTOCOL_IMON; ++ } ++} ++ ++static inline int tv2int(const struct timeval *a, const struct timeval *b) ++{ ++ int usecs = 0; ++ int sec = 0; ++ ++ if (b->tv_usec > a->tv_usec) { ++ usecs = 1000000; ++ sec--; ++ } ++ ++ usecs += a->tv_usec - b->tv_usec; ++ ++ sec += a->tv_sec - b->tv_sec; ++ sec *= 1000; ++ usecs /= 1000; ++ sec += usecs; ++ ++ if (sec < 0) ++ sec = 1000; ++ ++ return sec; ++} ++ ++/** ++ * The directional pad behaves a bit differently, depending on whether this is ++ * one of the older ffdc devices or a newer device. Newer devices appear to ++ * have a higher resolution matrix for more precise mouse movement, but it ++ * makes things overly sensitive in keyboard mode, so we do some interesting ++ * contortions to make it less touchy. Older devices run through the same ++ * routine with shorter timeout and a smaller threshold. ++ */ ++static int stabilize(int a, int b, u16 timeout, u16 threshold) ++{ ++ struct timeval ct; ++ static struct timeval prev_time = {0, 0}; ++ static struct timeval hit_time = {0, 0}; ++ static int x, y, prev_result, hits; ++ int result = 0; ++ int msec, msec_hit; ++ ++ do_gettimeofday(&ct); ++ msec = tv2int(&ct, &prev_time); ++ msec_hit = tv2int(&ct, &hit_time); ++ ++ if (msec > 100) { ++ x = 0; ++ y = 0; ++ hits = 0; ++ } ++ ++ x += a; ++ y += b; ++ ++ prev_time = ct; ++ ++ if (abs(x) > threshold || abs(y) > threshold) { ++ if (abs(y) > abs(x)) ++ result = (y > 0) ? 0x7F : 0x80; ++ else ++ result = (x > 0) ? 0x7F00 : 0x8000; ++ ++ x = 0; ++ y = 0; ++ ++ if (result == prev_result) { ++ hits++; ++ ++ if (hits > 3) { ++ switch (result) { ++ case 0x7F: ++ y = 17 * threshold / 30; ++ break; ++ case 0x80: ++ y -= 17 * threshold / 30; ++ break; ++ case 0x7F00: ++ x = 17 * threshold / 30; ++ break; ++ case 0x8000: ++ x -= 17 * threshold / 30; ++ break; ++ } ++ } ++ ++ if (hits == 2 && msec_hit < timeout) { ++ result = 0; ++ hits = 1; ++ } ++ } else { ++ prev_result = result; ++ hits = 1; ++ hit_time = ct; ++ } ++ } ++ ++ return result; ++} ++ ++static int imon_remote_key_lookup(u32 hw_code) ++{ ++ int i; ++ u32 code = be32_to_cpu(hw_code); ++ ++ /* Look for the initial press of a button */ ++ for (i = 0; i < ARRAY_SIZE(imon_remote_key_table); i++) ++ if (imon_remote_key_table[i].code == code) ++ return i; ++ ++ /* Look for the release of a button, return index + offset */ ++ for (i = 0; i < ARRAY_SIZE(imon_remote_key_table); i++) ++ if ((imon_remote_key_table[i].code | 0x4000) == code) ++ return i + IMON_KEY_RELEASE_OFFSET; ++ ++ return -1; ++} ++ ++static int imon_mce_key_lookup(u32 hw_code) ++{ ++ int i; ++ u32 code = be32_to_cpu(hw_code); ++ ++#define MCE_KEY_MASK 0x7000 ++#define MCE_TOGGLE_BIT 0x8000 ++ ++ /* ++ * On some receivers, mce keys decode to 0x8000f04xx and 0x8000f84xx ++ * (the toggle bit flipping between alternating key presses), while ++ * on other receivers, we see 0x8000f74xx and 0x8000ff4xx. To keep ++ * the table trim, we always or in the bits to look up 0x8000ff4xx, ++ * but we can't or them into all codes, as some keys are decoded in ++ * a different way w/o the same use of the toggle bit... ++ */ ++ if ((code >> 24) & 0x80) ++ code = code | MCE_KEY_MASK | MCE_TOGGLE_BIT; ++ ++ for (i = 0; i < ARRAY_SIZE(imon_mce_key_table); i++) ++ if (imon_mce_key_table[i].code == code) ++ return i; ++ ++ return -1; ++} ++ ++static int imon_panel_key_lookup(u64 hw_code) ++{ ++ int i; ++ u64 code = be64_to_cpu(hw_code); ++ ++ for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) ++ if (imon_panel_key_table[i].hw_code == (code | 0xffee)) ++ return i; ++ ++ return -1; ++} ++ ++static bool imon_mouse_event(struct imon_context *ictx, ++ unsigned char *buf, int len) ++{ ++ char rel_x = 0x00, rel_y = 0x00; ++ u8 right_shift = 1; ++ bool mouse_input = 1; ++ int dir = 0; ++ ++ /* newer iMON device PAD or mouse button */ ++ if (ictx->product != 0xffdc && (buf[0] & 0x01) && len == 5) { ++ rel_x = buf[2]; ++ rel_y = buf[3]; ++ right_shift = 1; ++ /* 0xffdc iMON PAD or mouse button input */ ++ } else if (ictx->product == 0xffdc && (buf[0] & 0x40) && ++ !((buf[1] & 0x01) || ((buf[1] >> 2) & 0x01))) { ++ rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | ++ (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6; ++ if (buf[0] & 0x02) ++ rel_x |= ~0x0f; ++ rel_x = rel_x + rel_x / 2; ++ rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | ++ (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6; ++ if (buf[0] & 0x01) ++ rel_y |= ~0x0f; ++ rel_y = rel_y + rel_y / 2; ++ right_shift = 2; ++ /* some ffdc devices decode mouse buttons differently... */ ++ } else if (ictx->product == 0xffdc && (buf[0] == 0x68)) { ++ right_shift = 2; ++ /* ch+/- buttons, which we use for an emulated scroll wheel */ ++ } else if (ictx->kc == KEY_CHANNELUP && (buf[2] & 0x40) != 0x40) { ++ dir = 1; ++ } else if (ictx->kc == KEY_CHANNELDOWN && (buf[2] & 0x40) != 0x40) { ++ dir = -1; ++ } else ++ mouse_input = 0; ++ ++ if (mouse_input) { ++ dev_dbg(ictx->dev, "sending mouse data via input subsystem\n"); ++ ++ if (dir) { ++ input_report_rel(ictx->idev, REL_WHEEL, dir); ++ } else if (rel_x || rel_y) { ++ input_report_rel(ictx->idev, REL_X, rel_x); ++ input_report_rel(ictx->idev, REL_Y, rel_y); ++ } else { ++ input_report_key(ictx->idev, BTN_LEFT, buf[1] & 0x1); ++ input_report_key(ictx->idev, BTN_RIGHT, ++ buf[1] >> right_shift & 0x1); ++ } ++ input_sync(ictx->idev); ++ ictx->last_keycode = ictx->kc; ++ } ++ ++ return mouse_input; ++} ++ ++static void imon_touch_event(struct imon_context *ictx, unsigned char *buf) ++{ ++ mod_timer(&ictx->ttimer, jiffies + TOUCH_TIMEOUT); ++ ictx->touch_x = (buf[0] << 4) | (buf[1] >> 4); ++ ictx->touch_y = 0xfff - ((buf[2] << 4) | (buf[1] & 0xf)); ++ input_report_abs(ictx->touch, ABS_X, ictx->touch_x); ++ input_report_abs(ictx->touch, ABS_Y, ictx->touch_y); ++ input_report_key(ictx->touch, BTN_TOUCH, 0x01); ++ input_sync(ictx->touch); ++} ++ ++static void imon_pad_to_keys(struct imon_context *ictx, unsigned char *buf) ++{ ++ int ki = 1; ++ int dir = 0; ++ int offset = IMON_KEY_RELEASE_OFFSET; ++ char rel_x = 0x00, rel_y = 0x00; ++ u16 timeout, threshold; ++ u64 temp_key; ++ u32 remote_key; ++ ++ /* ++ * The imon directional pad functions more like a touchpad. Bytes 3 & 4 ++ * contain a position coordinate (x,y), with each component ranging ++ * from -14 to 14. We want to down-sample this to only 4 discrete values ++ * for up/down/left/right arrow keys. Also, when you get too close to ++ * diagonals, it has a tendancy to jump back and forth, so lets try to ++ * ignore when they get too close. ++ */ ++ if (ictx->product != 0xffdc) { ++ /* first, pad to 8 bytes so it conforms with everything else */ ++ buf[5] = buf[6] = buf[7] = 0; ++ timeout = 500; /* in msecs */ ++ /* (2*threshold) x (2*threshold) square */ ++ threshold = pad_thresh ? pad_thresh : 28; ++ rel_x = buf[2]; ++ rel_y = buf[3]; ++ ++ if (ictx->ir_protocol == IMON_IR_PROTOCOL_IMON) { ++ if ((buf[1] == 0) && ((rel_x != 0) || (rel_y != 0))) { ++ dir = stabilize((int)rel_x, (int)rel_y, ++ timeout, threshold); ++ if (!dir) { ++ ictx->kc = KEY_UNKNOWN; ++ return; ++ } ++ buf[2] = dir & 0xFF; ++ buf[3] = (dir >> 8) & 0xFF; ++ memcpy(&temp_key, buf, sizeof(temp_key)); ++ remote_key = (u32) (le64_to_cpu(temp_key) ++ & 0xffffffff); ++ ki = imon_remote_key_lookup(remote_key); ++ ictx->kc = ++ imon_remote_key_table[ki % offset].keycode; ++ } ++ } else { ++ if (abs(rel_y) > abs(rel_x)) { ++ buf[2] = (rel_y > 0) ? 0x7F : 0x80; ++ buf[3] = 0; ++ ictx->kc = (rel_y > 0) ? KEY_DOWN : KEY_UP; ++ } else { ++ buf[2] = 0; ++ buf[3] = (rel_x > 0) ? 0x7F : 0x80; ++ ictx->kc = (rel_x > 0) ? KEY_RIGHT : KEY_LEFT; ++ } ++ } ++ ++ /* ++ * Handle on-board decoded pad events for e.g. older VFD/iMON-Pad ++ * device (15c2:ffdc). The remote generates various codes from ++ * 0x68nnnnB7 to 0x6AnnnnB7, the left mouse button generates ++ * 0x688301b7 and the right one 0x688481b7. All other keys generate ++ * 0x2nnnnnnn. Position coordinate is encoded in buf[1] and buf[2] with ++ * reversed endianess. Extract direction from buffer, rotate endianess, ++ * adjust sign and feed the values into stabilize(). The resulting codes ++ * will be 0x01008000, 0x01007F00, which match the newer devices. ++ */ ++ } else { ++ timeout = 10; /* in msecs */ ++ /* (2*threshold) x (2*threshold) square */ ++ threshold = pad_thresh ? pad_thresh : 15; ++ ++ /* buf[1] is x */ ++ rel_x = (buf[1] & 0x08) | (buf[1] & 0x10) >> 2 | ++ (buf[1] & 0x20) >> 4 | (buf[1] & 0x40) >> 6; ++ if (buf[0] & 0x02) ++ rel_x |= ~0x10+1; ++ /* buf[2] is y */ ++ rel_y = (buf[2] & 0x08) | (buf[2] & 0x10) >> 2 | ++ (buf[2] & 0x20) >> 4 | (buf[2] & 0x40) >> 6; ++ if (buf[0] & 0x01) ++ rel_y |= ~0x10+1; ++ ++ buf[0] = 0x01; ++ buf[1] = buf[4] = buf[5] = buf[6] = buf[7] = 0; ++ ++ if (ictx->ir_protocol == IMON_IR_PROTOCOL_IMON) { ++ dir = stabilize((int)rel_x, (int)rel_y, ++ timeout, threshold); ++ if (!dir) { ++ ictx->kc = KEY_UNKNOWN; ++ return; ++ } ++ buf[2] = dir & 0xFF; ++ buf[3] = (dir >> 8) & 0xFF; ++ memcpy(&temp_key, buf, sizeof(temp_key)); ++ remote_key = (u32) (le64_to_cpu(temp_key) & 0xffffffff); ++ ki = imon_remote_key_lookup(remote_key); ++ ictx->kc = imon_remote_key_table[ki % offset].keycode; ++ } else { ++ if (abs(rel_y) > abs(rel_x)) { ++ buf[2] = (rel_y > 0) ? 0x7F : 0x80; ++ buf[3] = 0; ++ ictx->kc = (rel_y > 0) ? KEY_DOWN : KEY_UP; ++ } else { ++ buf[2] = 0; ++ buf[3] = (rel_x > 0) ? 0x7F : 0x80; ++ ictx->kc = (rel_x > 0) ? KEY_RIGHT : KEY_LEFT; ++ } ++ } ++ } ++ ++ ictx->ki = ki; ++} ++ ++static int imon_parse_press_type(struct imon_context *ictx, ++ unsigned char *buf, u8 ksrc) ++{ ++ int press_type = 0; ++ ++ /* key release of 0x02XXXXXX key */ ++ if (ictx->ki == -1 && buf[0] == 0x02 && buf[3] == 0x00) ++ ictx->kc = ictx->last_keycode; ++ ++ /* mouse button release on (some) 0xffdc devices */ ++ else if (ictx->ki == -1 && buf[0] == 0x68 && buf[1] == 0x82 && ++ buf[2] == 0x81 && buf[3] == 0xb7) ++ ictx->kc = ictx->last_keycode; ++ ++ /* mouse button release on (some other) 0xffdc devices */ ++ else if (ictx->ki == -1 && buf[0] == 0x01 && buf[1] == 0x00 && ++ buf[2] == 0x81 && buf[3] == 0xb7) ++ ictx->kc = ictx->last_keycode; ++ ++ /* mce-specific button handling */ ++ else if (ksrc == IMON_BUTTON_MCE) { ++ /* initial press */ ++ if (ictx->kc != ictx->last_keycode ++ || buf[2] != ictx->mce_toggle_bit) { ++ ictx->last_keycode = ictx->kc; ++ ictx->mce_toggle_bit = buf[2]; ++ press_type = 1; ++ mod_timer(&ictx->itimer, ++ jiffies + msecs_to_jiffies(MCE_TIMEOUT_MS)); ++ /* repeat */ ++ } else { ++ press_type = 2; ++ mod_timer(&ictx->itimer, ++ jiffies + msecs_to_jiffies(MCE_TIMEOUT_MS)); ++ } ++ ++ /* incoherent or irrelevant data */ ++ } else if (ictx->ki == -1) ++ press_type = -EINVAL; ++ ++ /* key release of 0xXXXXXXb7 key */ ++ else if (ictx->ki >= IMON_KEY_RELEASE_OFFSET) ++ press_type = 0; ++ ++ /* this is a button press */ ++ else ++ press_type = 1; ++ ++ return press_type; ++} ++ ++/** ++ * Process the incoming packet ++ */ ++static void imon_incoming_packet(struct imon_context *ictx, ++ struct urb *urb, int intf) ++{ ++ int len = urb->actual_length; ++ unsigned char *buf = urb->transfer_buffer; ++ struct device *dev = ictx->dev; ++ u16 kc; ++ bool norelease = 0; ++ int i, ki; ++ int offset = IMON_KEY_RELEASE_OFFSET; ++ u64 temp_key; ++ u64 panel_key = 0; ++ u32 remote_key = 0; ++ struct input_dev *idev = NULL; ++ int press_type = 0; ++ int msec; ++ struct timeval t; ++ static struct timeval prev_time = { 0, 0 }; ++ u8 ksrc = IMON_BUTTON_IMON; ++ ++ idev = ictx->idev; ++ ++ /* filter out junk data on the older 0xffdc imon devices */ ++ if ((buf[0] == 0xff) && (buf[7] == 0xff)) ++ return; ++ ++ /* Figure out what key was pressed */ ++ memcpy(&temp_key, buf, sizeof(temp_key)); ++ if (len == 8 && buf[7] == 0xee) { ++ ksrc = IMON_BUTTON_PANEL; ++ panel_key = le64_to_cpu(temp_key); ++ ki = imon_panel_key_lookup(panel_key); ++ if (ki < 0) ++ kc = KEY_UNKNOWN; ++ else ++ kc = imon_panel_key_table[ki].keycode; ++ } else { ++ remote_key = (u32) (le64_to_cpu(temp_key) & 0xffffffff); ++ if (ictx->ir_protocol == IMON_IR_PROTOCOL_MCE) { ++ if (buf[0] == 0x80) ++ ksrc = IMON_BUTTON_MCE; ++ ki = imon_mce_key_lookup(remote_key); ++ if (ki < 0) ++ kc = KEY_UNKNOWN; ++ else ++ kc = imon_mce_key_table[ki].keycode; ++ } else { ++ ki = imon_remote_key_lookup(remote_key); ++ if (ki < 0) ++ kc = KEY_UNKNOWN; ++ else ++ kc = imon_remote_key_table[ki % offset].keycode; ++ } ++ } ++ ++ /* keyboard/mouse mode toggle button */ ++ if (kc == KEY_KEYBOARD && ki < offset) { ++ ictx->last_keycode = kc; ++ if (!nomouse) { ++ ictx->pad_mouse = ~(ictx->pad_mouse) & 0x1; ++ dev_dbg(dev, "toggling to %s mode\n", ++ ictx->pad_mouse ? "mouse" : "keyboard"); ++ return; ++ } else { ++ ictx->pad_mouse = 0; ++ dev_dbg(dev, "mouse mode disabled, passing key value\n"); ++ } ++ } ++ ++ ictx->ki = ki; ++ ictx->kc = kc; ++ ++ /* send touchscreen events through input subsystem if touchpad data */ ++ if (ictx->display_type == IMON_DISPLAY_TYPE_VGA && len == 8 && ++ buf[7] == 0x86) { ++ imon_touch_event(ictx, buf); ++ ++ /* look for mouse events with pad in mouse mode */ ++ } else if (ictx->pad_mouse) { ++ if (imon_mouse_event(ictx, buf, len)) ++ return; ++ } ++ ++ /* Now for some special handling to convert pad input to arrow keys */ ++ if (((len == 5) && (buf[0] == 0x01) && (buf[4] == 0x00)) || ++ ((len == 8) && (buf[0] & 0x40) && ++ !(buf[1] & 0x1 || buf[1] >> 2 & 0x1))) { ++ len = 8; ++ imon_pad_to_keys(ictx, buf); ++ norelease = 1; ++ } ++ ++ if (debug) { ++ printk(KERN_INFO "intf%d decoded packet: ", intf); ++ for (i = 0; i < len; ++i) ++ printk("%02x ", buf[i]); ++ printk("\n"); ++ } ++ ++ press_type = imon_parse_press_type(ictx, buf, ksrc); ++ if (press_type < 0) ++ goto not_input_data; ++ ++ if (ictx->kc == KEY_UNKNOWN) ++ goto unknown_key; ++ ++ /* KEY_MUTE repeats from MCE and knob need to be suppressed */ ++ if ((ictx->kc == KEY_MUTE && ictx->kc == ictx->last_keycode) ++ && (buf[7] == 0xee || ksrc == IMON_BUTTON_MCE)) { ++ do_gettimeofday(&t); ++ msec = tv2int(&t, &prev_time); ++ prev_time = t; ++ if (msec < 200) ++ return; ++ } ++ ++ input_report_key(idev, ictx->kc, press_type); ++ input_sync(idev); ++ ++ /* panel keys and some remote keys don't generate a release */ ++ if (panel_key || norelease) { ++ input_report_key(idev, ictx->kc, 0); ++ input_sync(idev); ++ } ++ ++ ictx->last_keycode = ictx->kc; ++ ++ return; ++ ++unknown_key: ++ dev_info(dev, "%s: unknown keypress, code 0x%llx\n", __func__, ++ (panel_key ? be64_to_cpu(panel_key) : ++ be32_to_cpu(remote_key))); ++ return; ++ ++not_input_data: ++ if (len != 8) { ++ dev_warn(dev, "imon %s: invalid incoming packet " ++ "size (len = %d, intf%d)\n", __func__, len, intf); ++ return; ++ } ++ ++ /* iMON 2.4G associate frame */ ++ if (buf[0] == 0x00 && ++ buf[2] == 0xFF && /* REFID */ ++ buf[3] == 0xFF && ++ buf[4] == 0xFF && ++ buf[5] == 0xFF && /* iMON 2.4G */ ++ ((buf[6] == 0x4E && buf[7] == 0xDF) || /* LT */ ++ (buf[6] == 0x5E && buf[7] == 0xDF))) { /* DT */ ++ dev_warn(dev, "%s: remote associated refid=%02X\n", ++ __func__, buf[1]); ++ ictx->ir_isassociating = 0; ++ } ++} ++ ++/** ++ * Callback function for USB core API: receive data ++ */ ++static void usb_rx_callback_intf0(struct urb *urb) ++{ ++ struct imon_context *ictx; ++ int intfnum = 0; ++ ++ if (!urb) ++ return; ++ ++ ictx = (struct imon_context *)urb->context; ++ if (!ictx) ++ return; ++ ++ switch (urb->status) { ++ case -ENOENT: /* usbcore unlink successful! */ ++ return; ++ ++ case -ESHUTDOWN: /* transport endpoint was shut down */ ++ break; ++ ++ case 0: ++ imon_incoming_packet(ictx, urb, intfnum); ++ break; ++ ++ default: ++ dev_warn(ictx->dev, "imon %s: status(%d): ignored\n", ++ __func__, urb->status); ++ break; ++ } ++ ++ usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC); ++} ++ ++static void usb_rx_callback_intf1(struct urb *urb) ++{ ++ struct imon_context *ictx; ++ int intfnum = 1; ++ ++ if (!urb) ++ return; ++ ++ ictx = (struct imon_context *)urb->context; ++ if (!ictx) ++ return; ++ ++ switch (urb->status) { ++ case -ENOENT: /* usbcore unlink successful! */ ++ return; ++ ++ case -ESHUTDOWN: /* transport endpoint was shut down */ ++ break; ++ ++ case 0: ++ imon_incoming_packet(ictx, urb, intfnum); ++ break; ++ ++ default: ++ dev_warn(ictx->dev, "imon %s: status(%d): ignored\n", ++ __func__, urb->status); ++ break; ++ } ++ ++ usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC); ++} ++ ++static struct input_dev *imon_init_idev(struct imon_context *ictx) ++{ ++ struct input_dev *idev; ++ int ret, i; ++ ++ idev = input_allocate_device(); ++ if (!idev) { ++ dev_err(ictx->dev, "remote input dev allocation failed\n"); ++ goto idev_alloc_failed; ++ } ++ ++ snprintf(ictx->name_idev, sizeof(ictx->name_idev), ++ "iMON Remote (%04x:%04x)", ictx->vendor, ictx->product); ++ idev->name = ictx->name_idev; ++ ++ usb_make_path(ictx->usbdev_intf0, ictx->phys_idev, ++ sizeof(ictx->phys_idev)); ++ strlcat(ictx->phys_idev, "/input0", sizeof(ictx->phys_idev)); ++ idev->phys = ictx->phys_idev; ++ ++ idev->evbit[0] = BIT_MASK(EV_KEY) | BIT_MASK(EV_REL); ++ ++ idev->keybit[BIT_WORD(BTN_MOUSE)] = ++ BIT_MASK(BTN_LEFT) | BIT_MASK(BTN_RIGHT); ++ idev->relbit[0] = BIT_MASK(REL_X) | BIT_MASK(REL_Y) | ++ BIT_MASK(REL_WHEEL); ++ ++ input_set_drvdata(idev, ictx); ++ ++ if (ir_protocol == IMON_IR_PROTOCOL_MCE) ++ ret = sparse_keymap_setup(idev, imon_mce_key_table, NULL); ++ else ++ ret = sparse_keymap_setup(idev, imon_remote_key_table, NULL); ++ if (ret) ++ goto keymap_failed; ++ ++ /* can't use sparse keymap atm, 64-bit keycodes */ ++ for (i = 0; i < ARRAY_SIZE(imon_panel_key_table); i++) { ++ u16 kc = imon_panel_key_table[i].keycode; ++ __set_bit(kc, idev->keybit); ++ } ++ ++ usb_to_input_id(ictx->usbdev_intf0, &idev->id); ++ idev->dev.parent = ictx->dev; ++ ret = input_register_device(idev); ++ if (ret < 0) { ++ dev_err(ictx->dev, "remote input dev register failed\n"); ++ goto idev_register_failed; ++ } ++ ++ return idev; ++ ++idev_register_failed: ++ sparse_keymap_free(idev); ++keymap_failed: ++ input_free_device(idev); ++idev_alloc_failed: ++ ++ return NULL; ++} ++ ++static struct input_dev *imon_init_touch(struct imon_context *ictx) ++{ ++ struct input_dev *touch; ++ int ret; ++ ++ touch = input_allocate_device(); ++ if (!touch) { ++ dev_err(ictx->dev, "touchscreen input dev allocation failed\n"); ++ goto touch_alloc_failed; ++ } ++ ++ snprintf(ictx->name_touch, sizeof(ictx->name_touch), ++ "iMON USB Touchscreen (%04x:%04x)", ++ ictx->vendor, ictx->product); ++ touch->name = ictx->name_touch; ++ ++ usb_make_path(ictx->usbdev_intf1, ictx->phys_touch, ++ sizeof(ictx->phys_touch)); ++ strlcat(ictx->phys_touch, "/input1", sizeof(ictx->phys_touch)); ++ touch->phys = ictx->phys_touch; ++ ++ touch->evbit[0] = ++ BIT_MASK(EV_KEY) | BIT_MASK(EV_ABS); ++ touch->keybit[BIT_WORD(BTN_TOUCH)] = ++ BIT_MASK(BTN_TOUCH); ++ input_set_abs_params(touch, ABS_X, ++ 0x00, 0xfff, 0, 0); ++ input_set_abs_params(touch, ABS_Y, ++ 0x00, 0xfff, 0, 0); ++ ++ input_set_drvdata(touch, ictx); ++ ++ usb_to_input_id(ictx->usbdev_intf1, &touch->id); ++ touch->dev.parent = ictx->dev; ++ ret = input_register_device(touch); ++ if (ret < 0) { ++ dev_info(ictx->dev, "touchscreen input dev register failed\n"); ++ goto touch_register_failed; ++ } ++ ++ return touch; ++ ++touch_register_failed: ++ input_free_device(ictx->touch); ++ mutex_unlock(&ictx->lock); ++ ++touch_alloc_failed: ++ return NULL; ++} ++ ++static bool imon_find_endpoints(struct imon_context *ictx, ++ struct usb_host_interface *iface_desc) ++{ ++ struct usb_endpoint_descriptor *ep; ++ struct usb_endpoint_descriptor *rx_endpoint = NULL; ++ struct usb_endpoint_descriptor *tx_endpoint = NULL; ++ int ifnum = iface_desc->desc.bInterfaceNumber; ++ int num_endpts = iface_desc->desc.bNumEndpoints; ++ int i, ep_dir, ep_type; ++ bool ir_ep_found = 0; ++ bool display_ep_found = 0; ++ bool tx_control = 0; ++ ++ /* ++ * Scan the endpoint list and set: ++ * first input endpoint = IR endpoint ++ * first output endpoint = display endpoint ++ */ ++ for (i = 0; i < num_endpts && !(ir_ep_found && display_ep_found); ++i) { ++ ep = &iface_desc->endpoint[i].desc; ++ ep_dir = ep->bEndpointAddress & USB_ENDPOINT_DIR_MASK; ++ ep_type = ep->bmAttributes & USB_ENDPOINT_XFERTYPE_MASK; ++ ++ if (!ir_ep_found && ep_dir == USB_DIR_IN && ++ ep_type == USB_ENDPOINT_XFER_INT) { ++ ++ rx_endpoint = ep; ++ ir_ep_found = 1; ++ dev_dbg(ictx->dev, "%s: found IR endpoint\n", __func__); ++ ++ } else if (!display_ep_found && ep_dir == USB_DIR_OUT && ++ ep_type == USB_ENDPOINT_XFER_INT) { ++ tx_endpoint = ep; ++ display_ep_found = 1; ++ dev_dbg(ictx->dev, "%s: found display endpoint\n", __func__); ++ } ++ } ++ ++ if (ifnum == 0) { ++ ictx->rx_endpoint_intf0 = rx_endpoint; ++ /* ++ * tx is used to send characters to lcd/vfd, associate RF ++ * remotes, set IR protocol, and maybe more... ++ */ ++ ictx->tx_endpoint = tx_endpoint; ++ } else { ++ ictx->rx_endpoint_intf1 = rx_endpoint; ++ } ++ ++ /* ++ * If we didn't find a display endpoint, this is probably one of the ++ * newer iMON devices that use control urb instead of interrupt ++ */ ++ if (!display_ep_found) { ++ tx_control = 1; ++ display_ep_found = 1; ++ dev_dbg(ictx->dev, "%s: device uses control endpoint, not " ++ "interface OUT endpoint\n", __func__); ++ } ++ ++ /* ++ * Some iMON receivers have no display. Unfortunately, it seems ++ * that SoundGraph recycles device IDs between devices both with ++ * and without... :\ ++ */ ++ if (ictx->display_type == IMON_DISPLAY_TYPE_NONE) { ++ display_ep_found = 0; ++ dev_dbg(ictx->dev, "%s: device has no display\n", __func__); ++ } ++ ++ /* ++ * iMON Touch devices have a VGA touchscreen, but no "display", as ++ * that refers to e.g. /dev/lcd0 (a character device LCD or VFD). ++ */ ++ if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { ++ display_ep_found = 0; ++ dev_dbg(ictx->dev, "%s: iMON Touch device found\n", __func__); ++ } ++ ++ /* Input endpoint is mandatory */ ++ if (!ir_ep_found) ++ err("%s: no valid input (IR) endpoint found.", __func__); ++ ++ ictx->tx_control = tx_control; ++ ++ if (display_ep_found) ++ ictx->display_supported = 1; ++ ++ return ir_ep_found; ++ ++} ++ ++static struct imon_context *imon_init_intf0(struct usb_interface *intf) ++{ ++ struct imon_context *ictx; ++ struct urb *rx_urb; ++ struct urb *tx_urb; ++ struct device *dev = &intf->dev; ++ struct usb_host_interface *iface_desc; ++ int ret; ++ ++ ictx = kzalloc(sizeof(struct imon_context), GFP_KERNEL); ++ if (!ictx) { ++ dev_err(dev, "%s: kzalloc failed for context", __func__); ++ goto exit; ++ } ++ rx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!rx_urb) { ++ dev_err(dev, "%s: usb_alloc_urb failed for IR urb", __func__); ++ goto rx_urb_alloc_failed; ++ } ++ tx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!tx_urb) { ++ dev_err(dev, "%s: usb_alloc_urb failed for display urb", ++ __func__); ++ goto tx_urb_alloc_failed; ++ } ++ ++ mutex_init(&ictx->lock); ++ ++ mutex_lock(&ictx->lock); ++ ++ ictx->dev = dev; ++ ictx->usbdev_intf0 = usb_get_dev(interface_to_usbdev(intf)); ++ ictx->dev_present_intf0 = 1; ++ ictx->rx_urb_intf0 = rx_urb; ++ ictx->tx_urb = tx_urb; ++ ++ ictx->vendor = le16_to_cpu(ictx->usbdev_intf0->descriptor.idVendor); ++ ictx->product = le16_to_cpu(ictx->usbdev_intf0->descriptor.idProduct); ++ ++ iface_desc = intf->cur_altsetting; ++ if (!imon_find_endpoints(ictx, iface_desc)) ++ goto find_endpoint_failed; ++ ++ ictx->idev = imon_init_idev(ictx); ++ if (!ictx->idev) { ++ dev_err(dev, "%s: input device setup failed\n", __func__); ++ goto idev_setup_failed; ++ } ++ ++ usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0, ++ usb_rcvintpipe(ictx->usbdev_intf0, ++ ictx->rx_endpoint_intf0->bEndpointAddress), ++ ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), ++ usb_rx_callback_intf0, ictx, ++ ictx->rx_endpoint_intf0->bInterval); ++ ++ ret = usb_submit_urb(ictx->rx_urb_intf0, GFP_KERNEL); ++ if (ret) { ++ err("%s: usb_submit_urb failed for intf0 (%d)", ++ __func__, ret); ++ goto urb_submit_failed; ++ } ++ ++ return ictx; ++ ++urb_submit_failed: ++ sparse_keymap_free(ictx->idev); ++ input_unregister_device(ictx->idev); ++ input_free_device(ictx->idev); ++idev_setup_failed: ++find_endpoint_failed: ++ mutex_unlock(&ictx->lock); ++ usb_free_urb(tx_urb); ++tx_urb_alloc_failed: ++ usb_free_urb(rx_urb); ++rx_urb_alloc_failed: ++ kfree(ictx); ++exit: ++ dev_err(dev, "unable to initialize intf0, err %d\n", ret); ++ ++ return NULL; ++} ++ ++static struct imon_context *imon_init_intf1(struct usb_interface *intf, ++ struct imon_context *ictx) ++{ ++ struct urb *rx_urb; ++ struct usb_host_interface *iface_desc; ++ int ret; ++ ++ rx_urb = usb_alloc_urb(0, GFP_KERNEL); ++ if (!rx_urb) { ++ err("%s: usb_alloc_urb failed for IR urb", __func__); ++ ret = -ENOMEM; ++ goto rx_urb_alloc_failed; ++ } ++ ++ mutex_lock(&ictx->lock); ++ ++ if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { ++ init_timer(&ictx->ttimer); ++ ictx->ttimer.data = (unsigned long)ictx; ++ ictx->ttimer.function = imon_touch_display_timeout; ++ } ++ ++ ictx->usbdev_intf1 = usb_get_dev(interface_to_usbdev(intf)); ++ ictx->dev_present_intf1 = 1; ++ ictx->rx_urb_intf1 = rx_urb; ++ ++ iface_desc = intf->cur_altsetting; ++ if (!imon_find_endpoints(ictx, iface_desc)) ++ goto find_endpoint_failed; ++ ++ if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) { ++ ictx->touch = imon_init_touch(ictx); ++ if (!ictx->touch) ++ goto touch_setup_failed; ++ } else ++ ictx->touch = NULL; ++ ++ usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1, ++ usb_rcvintpipe(ictx->usbdev_intf1, ++ ictx->rx_endpoint_intf1->bEndpointAddress), ++ ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), ++ usb_rx_callback_intf1, ictx, ++ ictx->rx_endpoint_intf1->bInterval); ++ ++ ret = usb_submit_urb(ictx->rx_urb_intf1, GFP_KERNEL); ++ ++ if (ret) { ++ err("%s: usb_submit_urb failed for intf1 (%d)", ++ __func__, ret); ++ goto urb_submit_failed; ++ } ++ ++ return ictx; ++ ++urb_submit_failed: ++ if (ictx->touch) { ++ input_unregister_device(ictx->touch); ++ input_free_device(ictx->touch); ++ } ++touch_setup_failed: ++find_endpoint_failed: ++ mutex_unlock(&ictx->lock); ++ usb_free_urb(rx_urb); ++rx_urb_alloc_failed: ++ dev_err(ictx->dev, "unable to initialize intf0, err %d\n", ret); ++ ++ return NULL; ++} ++ ++static void imon_set_display_type(struct imon_context *ictx, ++ struct usb_interface *intf) ++{ ++ int configured_display_type = IMON_DISPLAY_TYPE_VFD; ++ ++ /* ++ * Try to auto-detect the type of display if the user hasn't set ++ * it by hand via the display_type modparam. Default is VFD. ++ */ ++ if (display_type == IMON_DISPLAY_TYPE_AUTO) { ++ if (usb_match_id(intf, lcd_device_list)) ++ configured_display_type = IMON_DISPLAY_TYPE_LCD; ++ else if (usb_match_id(intf, imon_touchscreen_list)) ++ configured_display_type = IMON_DISPLAY_TYPE_VGA; ++ else if (usb_match_id(intf, ir_only_list)) ++ configured_display_type = IMON_DISPLAY_TYPE_NONE; ++ else ++ configured_display_type = IMON_DISPLAY_TYPE_VFD; ++ } else { ++ configured_display_type = display_type; ++ dev_dbg(ictx->dev, "%s: overriding display type to %d via " ++ "modparam\n", __func__, display_type); ++ } ++ ++ ictx->display_type = configured_display_type; ++} ++ ++static void imon_init_display(struct imon_context *ictx, ++ struct usb_interface *intf) ++{ ++ int ret; ++ const unsigned char fp_packet[] = { 0x40, 0x00, 0x00, 0x00, ++ 0x00, 0x00, 0x00, 0x88 }; ++ ++ dev_dbg(ictx->dev, "Registering iMON display with sysfs\n"); ++ ++ /* set up sysfs entry for built-in clock */ ++ ret = sysfs_create_group(&intf->dev.kobj, ++ &imon_display_attribute_group); ++ if (ret) ++ dev_err(ictx->dev, "Could not create display sysfs " ++ "entries(%d)", ret); ++ ++ if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) ++ ret = usb_register_dev(intf, &imon_lcd_class); ++ else ++ ret = usb_register_dev(intf, &imon_vfd_class); ++ if (ret) ++ /* Not a fatal error, so ignore */ ++ dev_info(ictx->dev, "could not get a minor number for " ++ "display\n"); ++ ++ /* Enable front-panel buttons and/or knobs */ ++ memcpy(ictx->usb_tx_buf, &fp_packet, sizeof(fp_packet)); ++ ret = send_packet(ictx); ++ /* Not fatal, but warn about it */ ++ if (ret) ++ dev_info(ictx->dev, "failed to enable front-panel " ++ "buttons and/or knobs\n"); ++} ++ ++/** ++ * Callback function for USB core API: Probe ++ */ ++static int __devinit imon_probe(struct usb_interface *interface, ++ const struct usb_device_id *id) ++{ ++ struct usb_device *usbdev = NULL; ++ struct usb_host_interface *iface_desc = NULL; ++ struct usb_interface *first_if; ++ struct device *dev = &interface->dev; ++ int ifnum, code_length, sysfs_err; ++ int ret = 0; ++ struct imon_context *ictx = NULL; ++ struct imon_context *first_if_ctx = NULL; ++ u16 vendor, product; ++ ++ code_length = BUF_CHUNK_SIZE * 8; ++ ++ usbdev = usb_get_dev(interface_to_usbdev(interface)); ++ iface_desc = interface->cur_altsetting; ++ ifnum = iface_desc->desc.bInterfaceNumber; ++ vendor = le16_to_cpu(usbdev->descriptor.idVendor); ++ product = le16_to_cpu(usbdev->descriptor.idProduct); ++ ++ dev_dbg(dev, "%s: found iMON device (%04x:%04x, intf%d)\n", ++ __func__, vendor, product, ifnum); ++ ++ /* prevent races probing devices w/multiple interfaces */ ++ mutex_lock(&driver_lock); ++ ++ first_if = usb_ifnum_to_if(usbdev, 0); ++ first_if_ctx = (struct imon_context *)usb_get_intfdata(first_if); ++ ++ if (ifnum == 0) { ++ ictx = imon_init_intf0(interface); ++ if (!ictx) { ++ err("%s: failed to initialize context!\n", __func__); ++ ret = -ENODEV; ++ goto fail; ++ } ++ ++ imon_set_display_type(ictx, interface); ++ ++ if (ictx->display_supported) ++ imon_init_display(ictx, interface); ++ ++ if (product == 0xffdc) { ++ /* RF products *also* use 0xffdc... sigh... */ ++ sysfs_err = sysfs_create_group(&interface->dev.kobj, ++ &imon_rf_attribute_group); ++ if (sysfs_err) ++ err("%s: Could not create RF sysfs entries(%d)", ++ __func__, sysfs_err); ++ } ++ ++ } else { ++ /* this is the secondary interface on the device */ ++ ictx = imon_init_intf1(interface, first_if_ctx); ++ if (!ictx) { ++ err("%s: failed to attach to context!\n", __func__); ++ ret = -ENODEV; ++ goto fail; ++ } ++ ++ } ++ ++ usb_set_intfdata(interface, ictx); ++ ++ /* set IR protocol/remote type */ ++ imon_set_ir_protocol(ictx); ++ ++ dev_info(dev, "iMON device (%04x:%04x, intf%d) on " ++ "usb<%d:%d> initialized\n", vendor, product, ifnum, ++ usbdev->bus->busnum, usbdev->devnum); ++ ++ mutex_unlock(&ictx->lock); ++ mutex_unlock(&driver_lock); ++ ++ return 0; ++ ++fail: ++ mutex_unlock(&driver_lock); ++ dev_err(dev, "unable to register, err %d\n", ret); ++ ++ return ret; ++} ++ ++/** ++ * Callback function for USB core API: disconnect ++ */ ++static void __devexit imon_disconnect(struct usb_interface *interface) ++{ ++ struct imon_context *ictx; ++ struct device *dev; ++ int ifnum; ++ ++ /* prevent races with multi-interface device probing and display_open */ ++ mutex_lock(&driver_lock); ++ ++ ictx = usb_get_intfdata(interface); ++ dev = ictx->dev; ++ ifnum = interface->cur_altsetting->desc.bInterfaceNumber; ++ ++ mutex_lock(&ictx->lock); ++ ++ /* ++ * sysfs_remove_group is safe to call even if sysfs_create_group ++ * hasn't been called ++ */ ++ sysfs_remove_group(&interface->dev.kobj, ++ &imon_display_attribute_group); ++ sysfs_remove_group(&interface->dev.kobj, ++ &imon_rf_attribute_group); ++ ++ usb_set_intfdata(interface, NULL); ++ ++ /* Abort ongoing write */ ++ if (ictx->tx.busy) { ++ usb_kill_urb(ictx->tx_urb); ++ complete_all(&ictx->tx.finished); ++ } ++ ++ if (ifnum == 0) { ++ ictx->dev_present_intf0 = 0; ++ usb_kill_urb(ictx->rx_urb_intf0); ++ sparse_keymap_free(ictx->idev); ++ input_unregister_device(ictx->idev); ++ if (ictx->display_supported) { ++ if (ictx->display_type == IMON_DISPLAY_TYPE_LCD) ++ usb_deregister_dev(interface, &imon_lcd_class); ++ else ++ usb_deregister_dev(interface, &imon_vfd_class); ++ } ++ } else { ++ ictx->dev_present_intf1 = 0; ++ usb_kill_urb(ictx->rx_urb_intf1); ++ if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) ++ input_unregister_device(ictx->touch); ++ } ++ ++ if (!ictx->dev_present_intf0 && !ictx->dev_present_intf1) { ++ if (ictx->display_type == IMON_DISPLAY_TYPE_VGA) ++ del_timer_sync(&ictx->ttimer); ++ mutex_unlock(&ictx->lock); ++ if (!ictx->display_isopen) ++ free_imon_context(ictx); ++ } else { ++ if (ictx->ir_protocol == IMON_IR_PROTOCOL_MCE) ++ del_timer_sync(&ictx->itimer); ++ mutex_unlock(&ictx->lock); ++ } ++ ++ mutex_unlock(&driver_lock); ++ ++ dev_dbg(dev, "%s: iMON device (intf%d) disconnected\n", ++ __func__, ifnum); ++} ++ ++static int imon_suspend(struct usb_interface *intf, pm_message_t message) ++{ ++ struct imon_context *ictx = usb_get_intfdata(intf); ++ int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; ++ ++ if (ifnum == 0) ++ usb_kill_urb(ictx->rx_urb_intf0); ++ else ++ usb_kill_urb(ictx->rx_urb_intf1); ++ ++ return 0; ++} ++ ++static int imon_resume(struct usb_interface *intf) ++{ ++ int rc = 0; ++ struct imon_context *ictx = usb_get_intfdata(intf); ++ int ifnum = intf->cur_altsetting->desc.bInterfaceNumber; ++ ++ if (ifnum == 0) { ++ usb_fill_int_urb(ictx->rx_urb_intf0, ictx->usbdev_intf0, ++ usb_rcvintpipe(ictx->usbdev_intf0, ++ ictx->rx_endpoint_intf0->bEndpointAddress), ++ ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), ++ usb_rx_callback_intf0, ictx, ++ ictx->rx_endpoint_intf0->bInterval); ++ ++ rc = usb_submit_urb(ictx->rx_urb_intf0, GFP_ATOMIC); ++ ++ } else { ++ usb_fill_int_urb(ictx->rx_urb_intf1, ictx->usbdev_intf1, ++ usb_rcvintpipe(ictx->usbdev_intf1, ++ ictx->rx_endpoint_intf1->bEndpointAddress), ++ ictx->usb_rx_buf, sizeof(ictx->usb_rx_buf), ++ usb_rx_callback_intf1, ictx, ++ ictx->rx_endpoint_intf1->bInterval); ++ ++ rc = usb_submit_urb(ictx->rx_urb_intf1, GFP_ATOMIC); ++ } ++ ++ return rc; ++} ++ ++static int __init imon_init(void) ++{ ++ int rc; ++ ++ rc = usb_register(&imon_driver); ++ if (rc) { ++ err("%s: usb register failed(%d)", __func__, rc); ++ rc = -ENODEV; ++ } ++ ++ return rc; ++} ++ ++static void __exit imon_exit(void) ++{ ++ usb_deregister(&imon_driver); ++} ++ ++module_init(imon_init); ++module_exit(imon_exit); +diff --git a/include/linux/lirc.h b/include/linux/lirc.h +new file mode 100644 +index 0000000..9ca6876 +--- /dev/null ++++ b/include/linux/lirc.h +@@ -0,0 +1,159 @@ ++/* ++ * lirc.h - linux infrared remote control header file ++ * last modified 2007/09/27 ++ */ ++ ++#ifndef _LINUX_LIRC_H ++#define _LINUX_LIRC_H ++ ++#include ++#include ++ ++/* */ ++#define PULSE_BIT 0x01000000 ++#define PULSE_MASK 0x00FFFFFF ++/* */ ++ ++#define LIRC_MODE2_SPACE 0x00000000 ++#define LIRC_MODE2_PULSE 0x01000000 ++#define LIRC_MODE2_FREQUENCY 0x02000000 ++#define LIRC_MODE2_TIMEOUT 0x03000000 ++ ++#define LIRC_VALUE_MASK 0x00FFFFFF ++#define LIRC_MODE2_MASK 0xFF000000 ++ ++#define LIRC_SPACE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_SPACE) ++#define LIRC_PULSE(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_PULSE) ++#define LIRC_FREQUENCY(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_FREQUENCY) ++#define LIRC_TIMEOUT(val) (((val)&LIRC_VALUE_MASK) | LIRC_MODE2_TIMEOUT) ++ ++#define LIRC_VALUE(val) ((val)&LIRC_VALUE_MASK) ++#define LIRC_MODE2(val) ((val)&LIRC_MODE2_MASK) ++ ++#define LIRC_IS_SPACE(val) (LIRC_MODE2(val) == LIRC_MODE2_SPACE) ++#define LIRC_IS_PULSE(val) (LIRC_MODE2(val) == LIRC_MODE2_PULSE) ++#define LIRC_IS_FREQUENCY(val) (LIRC_MODE2(val) == LIRC_MODE2_FREQUENCY) ++#define LIRC_IS_TIMEOUT(val) (LIRC_MODE2(val) == LIRC_MODE2_TIMEOUT) ++ ++/*** lirc compatible hardware features ***/ ++ ++#define LIRC_MODE2SEND(x) (x) ++#define LIRC_SEND2MODE(x) (x) ++#define LIRC_MODE2REC(x) ((x) << 16) ++#define LIRC_REC2MODE(x) ((x) >> 16) ++ ++#define LIRC_MODE_RAW 0x00000001 ++#define LIRC_MODE_PULSE 0x00000002 ++#define LIRC_MODE_MODE2 0x00000004 ++#define LIRC_MODE_LIRCCODE 0x00000010 ++ ++ ++#define LIRC_CAN_SEND_RAW LIRC_MODE2SEND(LIRC_MODE_RAW) ++#define LIRC_CAN_SEND_PULSE LIRC_MODE2SEND(LIRC_MODE_PULSE) ++#define LIRC_CAN_SEND_MODE2 LIRC_MODE2SEND(LIRC_MODE_MODE2) ++#define LIRC_CAN_SEND_LIRCCODE LIRC_MODE2SEND(LIRC_MODE_LIRCCODE) ++ ++#define LIRC_CAN_SEND_MASK 0x0000003f ++ ++#define LIRC_CAN_SET_SEND_CARRIER 0x00000100 ++#define LIRC_CAN_SET_SEND_DUTY_CYCLE 0x00000200 ++#define LIRC_CAN_SET_TRANSMITTER_MASK 0x00000400 ++ ++#define LIRC_CAN_REC_RAW LIRC_MODE2REC(LIRC_MODE_RAW) ++#define LIRC_CAN_REC_PULSE LIRC_MODE2REC(LIRC_MODE_PULSE) ++#define LIRC_CAN_REC_MODE2 LIRC_MODE2REC(LIRC_MODE_MODE2) ++#define LIRC_CAN_REC_LIRCCODE LIRC_MODE2REC(LIRC_MODE_LIRCCODE) ++ ++#define LIRC_CAN_REC_MASK LIRC_MODE2REC(LIRC_CAN_SEND_MASK) ++ ++#define LIRC_CAN_SET_REC_CARRIER (LIRC_CAN_SET_SEND_CARRIER << 16) ++#define LIRC_CAN_SET_REC_DUTY_CYCLE (LIRC_CAN_SET_SEND_DUTY_CYCLE << 16) ++ ++#define LIRC_CAN_SET_REC_DUTY_CYCLE_RANGE 0x40000000 ++#define LIRC_CAN_SET_REC_CARRIER_RANGE 0x80000000 ++#define LIRC_CAN_GET_REC_RESOLUTION 0x20000000 ++#define LIRC_CAN_SET_REC_TIMEOUT 0x10000000 ++#define LIRC_CAN_SET_REC_FILTER 0x08000000 ++ ++#define LIRC_CAN_MEASURE_CARRIER 0x02000000 ++ ++#define LIRC_CAN_SEND(x) ((x)&LIRC_CAN_SEND_MASK) ++#define LIRC_CAN_REC(x) ((x)&LIRC_CAN_REC_MASK) ++ ++#define LIRC_CAN_NOTIFY_DECODE 0x01000000 ++ ++/*** IOCTL commands for lirc driver ***/ ++ ++#define LIRC_GET_FEATURES _IOR('i', 0x00000000, unsigned long) ++ ++#define LIRC_GET_SEND_MODE _IOR('i', 0x00000001, unsigned long) ++#define LIRC_GET_REC_MODE _IOR('i', 0x00000002, unsigned long) ++#define LIRC_GET_SEND_CARRIER _IOR('i', 0x00000003, unsigned int) ++#define LIRC_GET_REC_CARRIER _IOR('i', 0x00000004, unsigned int) ++#define LIRC_GET_SEND_DUTY_CYCLE _IOR('i', 0x00000005, unsigned int) ++#define LIRC_GET_REC_DUTY_CYCLE _IOR('i', 0x00000006, unsigned int) ++#define LIRC_GET_REC_RESOLUTION _IOR('i', 0x00000007, unsigned int) ++ ++#define LIRC_GET_MIN_TIMEOUT _IOR('i', 0x00000008, uint32_t) ++#define LIRC_GET_MAX_TIMEOUT _IOR('i', 0x00000009, uint32_t) ++ ++#define LIRC_GET_MIN_FILTER_PULSE _IOR('i', 0x0000000a, uint32_t) ++#define LIRC_GET_MAX_FILTER_PULSE _IOR('i', 0x0000000b, uint32_t) ++#define LIRC_GET_MIN_FILTER_SPACE _IOR('i', 0x0000000c, uint32_t) ++#define LIRC_GET_MAX_FILTER_SPACE _IOR('i', 0x0000000d, uint32_t) ++ ++/* code length in bits, currently only for LIRC_MODE_LIRCCODE */ ++#define LIRC_GET_LENGTH _IOR('i', 0x0000000f, unsigned long) ++ ++#define LIRC_SET_SEND_MODE _IOW('i', 0x00000011, unsigned long) ++#define LIRC_SET_REC_MODE _IOW('i', 0x00000012, unsigned long) ++/* Note: these can reset the according pulse_width */ ++#define LIRC_SET_SEND_CARRIER _IOW('i', 0x00000013, unsigned int) ++#define LIRC_SET_REC_CARRIER _IOW('i', 0x00000014, unsigned int) ++#define LIRC_SET_SEND_DUTY_CYCLE _IOW('i', 0x00000015, unsigned int) ++#define LIRC_SET_REC_DUTY_CYCLE _IOW('i', 0x00000016, unsigned int) ++#define LIRC_SET_TRANSMITTER_MASK _IOW('i', 0x00000017, unsigned int) ++ ++/* ++ * when a timeout != 0 is set the driver will send a ++ * LIRC_MODE2_TIMEOUT data packet, otherwise LIRC_MODE2_TIMEOUT is ++ * never sent, timeout is disabled by default ++ */ ++#define LIRC_SET_REC_TIMEOUT _IOW('i', 0x00000018, uint32_t) ++ ++/* ++ * pulses shorter than this are filtered out by hardware (software ++ * emulation in lirc_dev?) ++ */ ++#define LIRC_SET_REC_FILTER_PULSE _IOW('i', 0x00000019, uint32_t) ++/* ++ * spaces shorter than this are filtered out by hardware (software ++ * emulation in lirc_dev?) ++ */ ++#define LIRC_SET_REC_FILTER_SPACE _IOW('i', 0x0000001a, uint32_t) ++/* ++ * if filter cannot be set independantly for pulse/space, this should ++ * be used ++ */ ++#define LIRC_SET_REC_FILTER _IOW('i', 0x0000001b, uint32_t) ++ ++/* ++ * to set a range use ++ * LIRC_SET_REC_DUTY_CYCLE_RANGE/LIRC_SET_REC_CARRIER_RANGE with the ++ * lower bound first and later ++ * LIRC_SET_REC_DUTY_CYCLE/LIRC_SET_REC_CARRIER with the upper bound ++ */ ++ ++#define LIRC_SET_REC_DUTY_CYCLE_RANGE _IOW('i', 0x0000001e, unsigned int) ++#define LIRC_SET_REC_CARRIER_RANGE _IOW('i', 0x0000001f, unsigned int) ++ ++#define LIRC_NOTIFY_DECODE _IO('i', 0x00000020) ++ ++/* ++ * from the next key press on the driver will send ++ * LIRC_MODE2_FREQUENCY packets ++ */ ++#define LIRC_MEASURE_CARRIER_ENABLE _IO('i', 0x00000021) ++#define LIRC_MEASURE_CARRIER_DISABLE _IO('i', 0x00000022) ++ ++#endif diff --git a/mac80211-explicitly-disable-enable-QoS.patch b/mac80211-explicitly-disable-enable-QoS.patch new file mode 100644 index 000000000..6bd4fcda8 --- /dev/null +++ b/mac80211-explicitly-disable-enable-QoS.patch @@ -0,0 +1,102 @@ +From: Stanislaw Gruszka +To: kernel@lists.fedoraproject.org, "John W. Linville" +Subject: [PATCH 1/4 2.6.33.y] mac80211: explicitly disable/enable QoS +Date: Fri, 11 Jun 2010 17:04:17 +0200 + +commit e1b3ec1a2a336c328c336cfa5485a5f0484cc90d upstream. + +Add interface to disable/enable QoS (aka WMM or WME). Currently drivers +enable it explicitly when ->conf_tx method is called, and newer disable. +Disabling is needed for some APs, which do not support QoS, such +we should send QoS frames to them. + +Signed-off-by: Stanislaw Gruszka +--- + include/net/mac80211.h | 5 +++++ + net/mac80211/mlme.c | 9 ++++++++- + net/mac80211/util.c | 5 +++++ + 3 files changed, 18 insertions(+), 1 deletions(-) + +diff --git a/include/net/mac80211.h b/include/net/mac80211.h +index f39b303..8c1f0ee 100644 +--- a/include/net/mac80211.h ++++ b/include/net/mac80211.h +@@ -577,11 +577,15 @@ struct ieee80211_rx_status { + * may turn the device off as much as possible. Typically, this flag will + * be set when an interface is set UP but not associated or scanning, but + * it can also be unset in that case when monitor interfaces are active. ++ * @IEEE80211_CONF_QOS: Enable 802.11e QoS also know as WMM (Wireless ++ * Multimedia). On some drivers (iwlwifi is one of know) we have ++ * to enable/disable QoS explicitly. + */ + enum ieee80211_conf_flags { + IEEE80211_CONF_MONITOR = (1<<0), + IEEE80211_CONF_PS = (1<<1), + IEEE80211_CONF_IDLE = (1<<2), ++ IEEE80211_CONF_QOS = (1<<3), + }; + + +@@ -604,6 +608,7 @@ enum ieee80211_conf_changed { + IEEE80211_CONF_CHANGE_CHANNEL = BIT(6), + IEEE80211_CONF_CHANGE_RETRY_LIMITS = BIT(7), + IEEE80211_CONF_CHANGE_IDLE = BIT(8), ++ IEEE80211_CONF_CHANGE_QOS = BIT(9), + }; + + /** +diff --git a/net/mac80211/mlme.c b/net/mac80211/mlme.c +index 1a209ac..950088d 100644 +--- a/net/mac80211/mlme.c ++++ b/net/mac80211/mlme.c +@@ -798,6 +798,9 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local, + int count; + u8 *pos; + ++ if (!local->ops->conf_tx) ++ return; ++ + if (!(ifmgd->flags & IEEE80211_STA_WMM_ENABLED)) + return; + +@@ -856,11 +859,15 @@ static void ieee80211_sta_wmm_params(struct ieee80211_local *local, + wiphy_name(local->hw.wiphy), queue, aci, acm, + params.aifs, params.cw_min, params.cw_max, params.txop); + #endif +- if (drv_conf_tx(local, queue, ¶ms) && local->ops->conf_tx) ++ if (drv_conf_tx(local, queue, ¶ms)) + printk(KERN_DEBUG "%s: failed to set TX queue " + "parameters for queue %d\n", + wiphy_name(local->hw.wiphy), queue); + } ++ ++ /* enable WMM or activate new settings */ ++ local->hw.conf.flags |= IEEE80211_CONF_QOS; ++ drv_config(local, IEEE80211_CONF_CHANGE_QOS); + } + + static u32 ieee80211_handle_bss_capability(struct ieee80211_sub_if_data *sdata, +diff --git a/net/mac80211/util.c b/net/mac80211/util.c +index 27212e8..9e35dcb 100644 +--- a/net/mac80211/util.c ++++ b/net/mac80211/util.c +@@ -795,6 +795,11 @@ void ieee80211_set_wmm_default(struct ieee80211_sub_if_data *sdata) + + drv_conf_tx(local, queue, &qparam); + } ++ ++ /* after reinitialize QoS TX queues setting to default, ++ * disable QoS at all */ ++ local->hw.conf.flags &= ~IEEE80211_CONF_QOS; ++ drv_config(local, IEEE80211_CONF_CHANGE_QOS); + } + + void ieee80211_sta_def_wmm_params(struct ieee80211_sub_if_data *sdata, +-- +1.6.2.5 + +_______________________________________________ +kernel mailing list +kernel@lists.fedoraproject.org +https://admin.fedoraproject.org/mailman/listinfo/kernel + diff --git a/merge.pl b/merge.pl new file mode 100755 index 000000000..8c318156a --- /dev/null +++ b/merge.pl @@ -0,0 +1,66 @@ +#! /usr/bin/perl + +my @args=@ARGV; +my %configvalues; +my @configoptions; +my $configcounter = 0; + +# optionally print out the architecture as the first line of our output +my $arch = $args[2]; +if (defined $arch) { + print "# $arch\n"; +} + +# first, read the override file + +open (FILE,"$args[0]") || die "Could not open $args[0]"; +while () { + my $str = $_; + my $configname; + + if (/\# ([\w]+) is not set/) { + $configname = $1; + } elsif (/([\w]+)=/) { + $configname = $1; + } + + if (defined($configname) && !exists($configvalues{$configname})) { + $configvalues{$configname} = $str; + $configoptions[$configcounter] = $configname; + $configcounter ++; + } +}; + +# now, read and output the entire configfile, except for the overridden +# parts... for those the new value is printed. + +open (FILE2,"$args[1]") || die "Could not open $args[1]"; +while () { + my $configname; + + if (/\# ([\w]+) is not set/) { + $configname = $1; + } elsif (/([\w]+)=/) { + $configname = $1; + } + + if (defined($configname) && exists($configvalues{$configname})) { + print "$configvalues{$configname}"; + delete($configvalues{$configname}); + } else { + print "$_"; + } +} + +# now print the new values from the overridden configfile +my $counter = 0; + +while ($counter < $configcounter) { + my $configname = $configoptions[$counter]; + if (exists($configvalues{$configname})) { + print "$configvalues{$configname}"; + } + $counter++; +} + +1; diff --git a/mm-fix-page-table-unmap-for-stack-guard-page-properly.patch b/mm-fix-page-table-unmap-for-stack-guard-page-properly.patch new file mode 100644 index 000000000..0989fe3b7 --- /dev/null +++ b/mm-fix-page-table-unmap-for-stack-guard-page-properly.patch @@ -0,0 +1,71 @@ +From: Linus Torvalds +Date: Sat, 14 Aug 2010 18:44:56 +0000 (-0700) +Subject: mm: fix page table unmap for stack guard page properly +X-Git-Tag: v2.6.36-rc1~20 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=11ac552477e32835cb6970bf0a70c210807f5673 + +mm: fix page table unmap for stack guard page properly + +We do in fact need to unmap the page table _before_ doing the whole +stack guard page logic, because if it is needed (mainly 32-bit x86 with +PAE and CONFIG_HIGHPTE, but other architectures may use it too) then it +will do a kmap_atomic/kunmap_atomic. + +And those kmaps will create an atomic region that we cannot do +allocations in. However, the whole stack expand code will need to do +anon_vma_prepare() and vma_lock_anon_vma() and they cannot do that in an +atomic region. + +Now, a better model might actually be to do the anon_vma_prepare() when +_creating_ a VM_GROWSDOWN segment, and not have to worry about any of +this at page fault time. But in the meantime, this is the +straightforward fix for the issue. + +See https://bugzilla.kernel.org/show_bug.cgi?id=16588 for details. + +Reported-by: Wylda +Reported-by: Sedat Dilek +Reported-by: Mike Pagano +Reported-by: François Valenduc +Tested-by: Ed Tomlinson +Cc: Pekka Enberg +Cc: Greg KH +Cc: stable@kernel.org +Signed-off-by: Linus Torvalds +--- + +diff --git a/mm/memory.c b/mm/memory.c +index 9b3b73f..b6e5fd2 100644 +--- a/mm/memory.c ++++ b/mm/memory.c +@@ -2792,24 +2792,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma, + spinlock_t *ptl; + pte_t entry; + +- if (check_stack_guard_page(vma, address) < 0) { +- pte_unmap(page_table); ++ pte_unmap(page_table); ++ ++ /* Check if we need to add a guard page to the stack */ ++ if (check_stack_guard_page(vma, address) < 0) + return VM_FAULT_SIGBUS; +- } + ++ /* Use the zero-page for reads */ + if (!(flags & FAULT_FLAG_WRITE)) { + entry = pte_mkspecial(pfn_pte(my_zero_pfn(address), + vma->vm_page_prot)); +- ptl = pte_lockptr(mm, pmd); +- spin_lock(ptl); ++ page_table = pte_offset_map_lock(mm, pmd, address, &ptl); + if (!pte_none(*page_table)) + goto unlock; + goto setpte; + } + + /* Allocate our own private page. */ +- pte_unmap(page_table); +- + if (unlikely(anon_vma_prepare(vma))) + goto oom; + page = alloc_zeroed_user_highpage_movable(vma, address); diff --git a/mm-fix-up-some-user-visible-effects-of-the-stack-guard-page.patch b/mm-fix-up-some-user-visible-effects-of-the-stack-guard-page.patch new file mode 100644 index 000000000..095a9336d --- /dev/null +++ b/mm-fix-up-some-user-visible-effects-of-the-stack-guard-page.patch @@ -0,0 +1,85 @@ +From: Linus Torvalds +Date: Sun, 15 Aug 2010 18:35:52 +0000 (-0700) +Subject: mm: fix up some user-visible effects of the stack guard page +X-Git-Tag: v2.6.36-rc1~5 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=d7824370e26325c881b665350ce64fb0a4fde24a + +mm: fix up some user-visible effects of the stack guard page + +This commit makes the stack guard page somewhat less visible to user +space. It does this by: + + - not showing the guard page in /proc//maps + + It looks like lvm-tools will actually read /proc/self/maps to figure + out where all its mappings are, and effectively do a specialized + "mlockall()" in user space. By not showing the guard page as part of + the mapping (by just adding PAGE_SIZE to the start for grows-up + pages), lvm-tools ends up not being aware of it. + + - by also teaching the _real_ mlock() functionality not to try to lock + the guard page. + + That would just expand the mapping down to create a new guard page, + so there really is no point in trying to lock it in place. + +It would perhaps be nice to show the guard page specially in +/proc//maps (or at least mark grow-down segments some way), but +let's not open ourselves up to more breakage by user space from programs +that depends on the exact deails of the 'maps' file. + +Special thanks to Henrique de Moraes Holschuh for diving into lvm-tools +source code to see what was going on with the whole new warning. + +Reported-and-tested-by: François Valenduc +Cc: stable@kernel.org +Signed-off-by: Linus Torvalds +--- + +diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c +index aea1d3f..439fc1f 100644 +--- a/fs/proc/task_mmu.c ++++ b/fs/proc/task_mmu.c +@@ -210,6 +210,7 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma) + int flags = vma->vm_flags; + unsigned long ino = 0; + unsigned long long pgoff = 0; ++ unsigned long start; + dev_t dev = 0; + int len; + +@@ -220,8 +221,13 @@ static void show_map_vma(struct seq_file *m, struct vm_area_struct *vma) + pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT; + } + ++ /* We don't show the stack guard page in /proc/maps */ ++ start = vma->vm_start; ++ if (vma->vm_flags & VM_GROWSDOWN) ++ start += PAGE_SIZE; ++ + seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu %n", +- vma->vm_start, ++ start, + vma->vm_end, + flags & VM_READ ? 'r' : '-', + flags & VM_WRITE ? 'w' : '-', +diff --git a/mm/mlock.c b/mm/mlock.c +index 3f82720..49e5e4c 100644 +--- a/mm/mlock.c ++++ b/mm/mlock.c +@@ -167,6 +167,14 @@ static long __mlock_vma_pages_range(struct vm_area_struct *vma, + if (vma->vm_flags & VM_WRITE) + gup_flags |= FOLL_WRITE; + ++ /* We don't try to access the guard page of a stack vma */ ++ if (vma->vm_flags & VM_GROWSDOWN) { ++ if (start == vma->vm_start) { ++ start += PAGE_SIZE; ++ nr_pages--; ++ } ++ } ++ + while (nr_pages > 0) { + int i; + diff --git a/neuter_intel_microcode_load.patch b/neuter_intel_microcode_load.patch new file mode 100644 index 000000000..2766e439d --- /dev/null +++ b/neuter_intel_microcode_load.patch @@ -0,0 +1,24 @@ +diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c +index ebd193e..c57024a 100644 +--- a/arch/x86/kernel/microcode_intel.c ++++ b/arch/x86/kernel/microcode_intel.c +@@ -453,9 +453,18 @@ static void microcode_fini_cpu(int cpu) + uci->mc = NULL; + } + ++/* we don't ship the broken out files... ++ * instead, we'll just fail here, and load it with microcode_ctl ++ */ ++static enum ucode_state noop_request_microcode_fw(int cpu, ++ struct device *device) ++{ ++ return UCODE_NFOUND; ++} ++ + static struct microcode_ops microcode_intel_ops = { + .request_microcode_user = request_microcode_user, +- .request_microcode_fw = request_microcode_fw, ++ .request_microcode_fw = noop_request_microcode_fw, + .collect_cpu_info = collect_cpu_info, + .apply_microcode = apply_microcode, + .microcode_fini_cpu = microcode_fini_cpu, diff --git a/ntrig-backport.patch b/ntrig-backport.patch new file mode 100644 index 000000000..69ffd775f --- /dev/null +++ b/ntrig-backport.patch @@ -0,0 +1,512 @@ +commit 094693bee2b1fd8628846040f4a07cc4725b6011 +Author: Rafi Rubin +Date: Mon May 3 05:08:30 2010 -0400 + + HID: ntrig: Remove unused macro, TripleTap and QuadTap + + Removing the higher number taps. Their usage was incorrect + and even if correct they should not be used for a touch screen. + _MT_ events should be used to communicate multiple fingers. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit e4ca1ed6c39920c6be60e26c8b1c61b82792906b +Author: Rafi Rubin +Date: Mon May 3 05:08:29 2010 -0400 + + HID: ntrig: TipSwitch for single touch mode touch. + + Include TipSwitch in the touch detection decision for some single touch + firmwares. Confidence and InRange are high for all finger events + including those used to indicate the finger is no longer in contact with + the sensor. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 2a85cd7c45cf219fe27e5f8c031f954fdec637fd +Author: Rafi Rubin +Date: Fri Apr 9 17:58:25 2010 -0400 + + HID: ntrig: Emit TOUCH with DOUBLETAP for single touch + + I squelched TipSwitch in a recent patch which resulted in the loss + of Touch events for single touch firmwares. This patch just puts Touch back + in for single touch, and bundles it with DoubleTap (like the multitouch code). + The two events are used to convey the same message to different drivers. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 811b16c09476e2a72736dd55f3fe62549c4d722c +Author: Jiri Kosina +Date: Wed Apr 7 12:10:29 2010 +0200 + + HID: ntrig: explain firmware quirk + + Commit 6549981bc54777c ("HID: fix N-trig touch panel with recent firmware") + adds a quirk that is needed for devices with more recent firmware so that + they become operational. + + As it's not directly obvious from the code why is it needed, a comment + is worthwile. + + Signed-off-by: Jiri Kosina + +commit aa604050185ad5b17e8bf838d73d76382ee3e3e5 +Author: Stephane Chatty +Date: Tue Apr 6 22:22:58 2010 +0200 + + HID: fix N-trig touch panel with recent firmware + + Added an init message that avoids device freeze with recent firmware. + + Signed-off-by: Stephane Chatty + Tested-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 26196d5d0f6884f632e978103f435e2ba001a7ce +Author: Rafi Rubin +Date: Wed Mar 10 16:10:28 2010 +0100 + + HID: ntrig: fix touch events + + This reinstates the lost unpressing of BTN_TOUCH. To prevent undesireably + touch toggles this also deals with tip switch events. + + Added a trap to prevent going out of bounds for hidinputs with empty reports. + + Clear bits of unused buttons which result in misidentification. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 04b1217771e454eea260d5cf8e66fa75cd7863bf +Author: Rafi Rubin +Date: Tue Feb 16 10:22:11 2010 -0500 + + HID: hid-ntrig: Single touch mode tap + + Add DOUBLETAP to events emitted when in single touch only mode. + + Users with a single touch firmware report not seeing the DOUBLETAP events; this + is a side effect of dropping old mapping for confidence. The confidence mapping + may be fine for singletouch mode but causes problems in multitouch mode. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 52bd98e1c2e3b0587f8c45c15f3ff8af69353044 +Author: Rafi Rubin +Date: Fri Feb 12 21:13:05 2010 -0500 + + HID: hid-ntrig: multitouch cleanup and fix + + This cleans up the identification of multitouch groups and enables + the end of group sync. + + Taps are now explicitly handled to adjust for the changes in the + event stream in multitouch mode. Added triple and quad tap for the + benefit of tools that recognize different tap types but do not have + full multi touch support. + + This cleans up the behavior particularly for the latest firmware, which + didn't work particularly well with the older version of the driver. + + In this form, when multitouch is active, both mt and st events will come out of + the "N-Trig MultiTouch" device. And when its not st events will come out of + "N-Trig Touchscreen". + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 9ff5ed6b935929019c459e4d853c3afe52a4d8f2 +Author: Rafi Rubin +Date: Thu Feb 11 22:14:06 2010 -0500 + + HID: n-trig: remove unnecessary tool switching + + With the pen and touch split apart, we no longer need to inject + additional tool switching events. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + +commit 0336d54acf59a4ccd97fc9d983518c6d60639f5b +Author: Rafi Rubin +Date: Thu Feb 11 22:14:05 2010 -0500 + + HID: hid-ntrig add multi input quirk and clean up + + Added a quirk to enable distinct input devices. The digitizer utilizes + three inputs to represent pen, multitouch and a normal touch screen. + + With the Pen partitioned, it behaves well and does not need special + handling. + + Also, I set names to the input devices to clarify the functions of the + various inputs. + + Signed-off-by: Rafi Rubin + Signed-off-by: Jiri Kosina + + drivers/hid/hid-ntrig.c | 229 ++++++++++++++++++++++++++++++++-------------- + 1 files changed, 159 insertions(+), 70 deletions(-) + +diff --git a/drivers/hid/hid-ntrig.c b/drivers/hid/hid-ntrig.c +index 49ce69d..836a4ba 100644 +--- a/drivers/hid/hid-ntrig.c ++++ b/drivers/hid/hid-ntrig.c +@@ -1,8 +1,8 @@ + /* + * HID driver for N-Trig touchscreens + * +- * Copyright (c) 2008 Rafi Rubin +- * Copyright (c) 2009 Stephane Chatty ++ * Copyright (c) 2008-2010 Rafi Rubin ++ * Copyright (c) 2009-2010 Stephane Chatty + * + */ + +@@ -15,21 +15,27 @@ + + #include + #include ++#include ++#include "usbhid/usbhid.h" + #include + + #include "hid-ids.h" + + #define NTRIG_DUPLICATE_USAGES 0x001 + +-#define nt_map_key_clear(c) hid_map_usage_clear(hi, usage, bit, max, \ +- EV_KEY, (c)) +- + struct ntrig_data { +- __s32 x, y, id, w, h; +- char reading_a_point, found_contact_id; +- char pen_active; +- char finger_active; +- char inverted; ++ /* Incoming raw values for a single contact */ ++ __u16 x, y, w, h; ++ __u16 id; ++ ++ bool tipswitch; ++ bool confidence; ++ bool first_contact_touch; ++ ++ bool reading_mt; ++ ++ __u8 mt_footer[4]; ++ __u8 mt_foot_count; + }; + + /* +@@ -42,8 +48,11 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) + { +- switch (usage->hid & HID_USAGE_PAGE) { ++ /* No special mappings needed for the pen and single touch */ ++ if (field->physical) ++ return 0; + ++ switch (usage->hid & HID_USAGE_PAGE) { + case HID_UP_GENDESK: + switch (usage->hid) { + case HID_GD_X: +@@ -66,18 +75,12 @@ static int ntrig_input_mapping(struct hid_device *hdev, struct hid_input *hi, + case HID_UP_DIGITIZER: + switch (usage->hid) { + /* we do not want to map these for now */ +- case HID_DG_CONTACTID: /* value is useless */ ++ case HID_DG_CONTACTID: /* Not trustworthy, squelch for now */ + case HID_DG_INPUTMODE: + case HID_DG_DEVICEINDEX: +- case HID_DG_CONTACTCOUNT: + case HID_DG_CONTACTMAX: + return -1; + +- /* original mapping by Rafi Rubin */ +- case HID_DG_CONFIDENCE: +- nt_map_key_clear(BTN_TOOL_DOUBLETAP); +- return 1; +- + /* width/height mapped on TouchMajor/TouchMinor/Orientation */ + case HID_DG_WIDTH: + hid_map_usage(hi, usage, bit, max, +@@ -104,6 +107,10 @@ static int ntrig_input_mapped(struct hid_device *hdev, struct hid_input *hi, + struct hid_field *field, struct hid_usage *usage, + unsigned long **bit, int *max) + { ++ /* No special mappings needed for the pen and single touch */ ++ if (field->physical) ++ return 0; ++ + if (usage->type == EV_KEY || usage->type == EV_REL + || usage->type == EV_ABS) + clear_bit(usage->code, *bit); +@@ -123,31 +130,34 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, + struct input_dev *input = field->hidinput->input; + struct ntrig_data *nd = hid_get_drvdata(hid); + ++ /* No special handling needed for the pen */ ++ if (field->application == HID_DG_PEN) ++ return 0; ++ + if (hid->claimed & HID_CLAIMED_INPUT) { + switch (usage->hid) { +- +- case HID_DG_INRANGE: +- if (field->application & 0x3) +- nd->pen_active = (value != 0); +- else +- nd->finger_active = (value != 0); +- return 0; +- +- case HID_DG_INVERT: +- nd->inverted = value; +- return 0; +- ++ case 0xff000001: ++ /* Tag indicating the start of a multitouch group */ ++ nd->reading_mt = 1; ++ nd->first_contact_touch = 0; ++ break; ++ case HID_DG_TIPSWITCH: ++ nd->tipswitch = value; ++ /* Prevent emission of touch until validated */ ++ return 1; ++ case HID_DG_CONFIDENCE: ++ nd->confidence = value; ++ break; + case HID_GD_X: + nd->x = value; +- nd->reading_a_point = 1; ++ /* Clear the contact footer */ ++ nd->mt_foot_count = 0; + break; + case HID_GD_Y: + nd->y = value; + break; + case HID_DG_CONTACTID: + nd->id = value; +- /* we receive this only when in multitouch mode */ +- nd->found_contact_id = 1; + break; + case HID_DG_WIDTH: + nd->w = value; +@@ -159,33 +169,17 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, + * report received in a finger event. We want + * to emit a normal (X, Y) position + */ +- if (!nd->found_contact_id) { +- if (nd->pen_active && nd->finger_active) { +- input_report_key(input, BTN_TOOL_DOUBLETAP, 0); +- input_report_key(input, BTN_TOOL_DOUBLETAP, 1); +- } +- input_event(input, EV_ABS, ABS_X, nd->x); +- input_event(input, EV_ABS, ABS_Y, nd->y); +- } +- break; +- case HID_DG_TIPPRESSURE: +- /* +- * when in single touch mode, this is the last +- * report received in a pen event. We want +- * to emit a normal (X, Y) position +- */ +- if (! nd->found_contact_id) { +- if (nd->pen_active && nd->finger_active) { +- input_report_key(input, +- nd->inverted ? BTN_TOOL_RUBBER : BTN_TOOL_PEN +- , 0); +- input_report_key(input, +- nd->inverted ? BTN_TOOL_RUBBER : BTN_TOOL_PEN +- , 1); +- } ++ if (!nd->reading_mt) { ++ /* ++ * TipSwitch indicates the presence of a ++ * finger in single touch mode. ++ */ ++ input_report_key(input, BTN_TOUCH, ++ nd->tipswitch); ++ input_report_key(input, BTN_TOOL_DOUBLETAP, ++ nd->tipswitch); + input_event(input, EV_ABS, ABS_X, nd->x); + input_event(input, EV_ABS, ABS_Y, nd->y); +- input_event(input, EV_ABS, ABS_PRESSURE, value); + } + break; + case 0xff000002: +@@ -195,10 +189,40 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, + * this usage tells if the contact point is real + * or a placeholder + */ +- if (!nd->reading_a_point || value != 1) ++ ++ /* Shouldn't get more than 4 footer packets, so skip */ ++ if (nd->mt_foot_count >= 4) + break; ++ ++ nd->mt_footer[nd->mt_foot_count++] = value; ++ ++ /* if the footer isn't complete break */ ++ if (nd->mt_foot_count != 4) ++ break; ++ ++ /* Pen activity signal, trigger end of touch. */ ++ if (nd->mt_footer[2]) { ++ nd->confidence = 0; ++ break; ++ } ++ ++ /* If the contact was invalid */ ++ if (!(nd->confidence && nd->mt_footer[0]) ++ || nd->w <= 250 ++ || nd->h <= 190) { ++ nd->confidence = 0; ++ break; ++ } ++ + /* emit a normal (X, Y) for the first point only */ + if (nd->id == 0) { ++ /* ++ * TipSwitch is superfluous in multitouch ++ * mode. The footer events tell us ++ * if there is a finger on the screen or ++ * not. ++ */ ++ nd->first_contact_touch = nd->confidence; + input_event(input, EV_ABS, ABS_X, nd->x); + input_event(input, EV_ABS, ABS_Y, nd->y); + } +@@ -220,8 +244,21 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, + ABS_MT_TOUCH_MINOR, nd->w); + } + input_mt_sync(field->hidinput->input); +- nd->reading_a_point = 0; +- nd->found_contact_id = 0; ++ break; ++ ++ case HID_DG_CONTACTCOUNT: /* End of a multitouch group */ ++ if (!nd->reading_mt) ++ break; ++ ++ nd->reading_mt = 0; ++ ++ if (nd->first_contact_touch) { ++ input_report_key(input, BTN_TOOL_DOUBLETAP, 1); ++ input_report_key(input, BTN_TOUCH, 1); ++ } else { ++ input_report_key(input, BTN_TOOL_DOUBLETAP, 0); ++ input_report_key(input, BTN_TOUCH, 0); ++ } + break; + + default: +@@ -231,8 +268,8 @@ static int ntrig_event (struct hid_device *hid, struct hid_field *field, + } + + /* we have handled the hidinput part, now remains hiddev */ +- if (hid->claimed & HID_CLAIMED_HIDDEV && hid->hiddev_hid_event) +- hid->hiddev_hid_event(hid, field, usage, value); ++ if ((hid->claimed & HID_CLAIMED_HIDDEV) && hid->hiddev_hid_event) ++ hid->hiddev_hid_event(hid, field, usage, value); + + return 1; + } +@@ -241,23 +278,75 @@ static int ntrig_probe(struct hid_device *hdev, const struct hid_device_id *id) + { + int ret; + struct ntrig_data *nd; ++ struct hid_input *hidinput; ++ struct input_dev *input; ++ struct hid_report *report; ++ ++ if (id->driver_data) ++ hdev->quirks |= HID_QUIRK_MULTI_INPUT; + + nd = kmalloc(sizeof(struct ntrig_data), GFP_KERNEL); + if (!nd) { + dev_err(&hdev->dev, "cannot allocate N-Trig data\n"); + return -ENOMEM; + } +- nd->reading_a_point = 0; +- nd->found_contact_id = 0; ++ ++ nd->reading_mt = 0; + hid_set_drvdata(hdev, nd); + + ret = hid_parse(hdev); +- if (!ret) +- ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT); ++ if (ret) { ++ dev_err(&hdev->dev, "parse failed\n"); ++ goto err_free; ++ } ++ ++ ret = hid_hw_start(hdev, HID_CONNECT_DEFAULT & ~HID_CONNECT_FF); ++ if (ret) { ++ dev_err(&hdev->dev, "hw start failed\n"); ++ goto err_free; ++ } ++ ++ ++ list_for_each_entry(hidinput, &hdev->inputs, list) { ++ if (hidinput->report->maxfield < 1) ++ continue; ++ ++ input = hidinput->input; ++ switch (hidinput->report->field[0]->application) { ++ case HID_DG_PEN: ++ input->name = "N-Trig Pen"; ++ break; ++ case HID_DG_TOUCHSCREEN: ++ /* These keys are redundant for fingers, clear them ++ * to prevent incorrect identification */ ++ __clear_bit(BTN_TOOL_PEN, input->keybit); ++ __clear_bit(BTN_TOOL_FINGER, input->keybit); ++ __clear_bit(BTN_0, input->keybit); ++ __set_bit(BTN_TOOL_DOUBLETAP, input->keybit); ++ /* ++ * The physical touchscreen (single touch) ++ * input has a value for physical, whereas ++ * the multitouch only has logical input ++ * fields. ++ */ ++ input->name = ++ (hidinput->report->field[0] ++ ->physical) ? ++ "N-Trig Touchscreen" : ++ "N-Trig MultiTouch"; ++ break; ++ } ++ } + +- if (ret) +- kfree (nd); ++ /* This is needed for devices with more recent firmware versions */ ++ report = hdev->report_enum[HID_FEATURE_REPORT].report_id_hash[0x0a]; ++ if (report) ++ usbhid_submit_report(hdev, report, USB_DIR_OUT); + ++ ++ return 0; ++err_free: ++ kfree(nd); + return ret; + } + +@@ -276,7 +365,7 @@ MODULE_DEVICE_TABLE(hid, ntrig_devices); + + static const struct hid_usage_id ntrig_grabbed_usages[] = { + { HID_ANY_ID, HID_ANY_ID, HID_ANY_ID }, +- { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1} ++ { HID_ANY_ID - 1, HID_ANY_ID - 1, HID_ANY_ID - 1 } + }; + + static struct hid_driver ntrig_driver = { diff --git a/perf b/perf new file mode 100644 index 000000000..ea8980694 --- /dev/null +++ b/perf @@ -0,0 +1,12 @@ +#!/bin/sh + +# In pathological situations, this will print some error about uname. +kverrel="`uname -r`" || exit + +exec "/usr/libexec/perf.$kverrel" ${1+"$@"} +rc=$? + +# We're still here, so the exec failed. +echo >&2 "Sorry, your kernel ($kverrel) doesn't support perf." + +exit $rc diff --git a/perf-mount-debugfs-automatically.patch b/perf-mount-debugfs-automatically.patch new file mode 100644 index 000000000..caf6a2599 --- /dev/null +++ b/perf-mount-debugfs-automatically.patch @@ -0,0 +1,93 @@ +From 29c52aa2300173dd45df04dae1f5acc81a2c93b1 Mon Sep 17 00:00:00 2001 +From: Xiao Guangrong +Date: Mon, 28 Dec 2009 16:47:12 +0800 +Subject: [PATCH] perf tools: Mount debugfs automatically + +Mount debugfs filesystem under '/sys/kernel/debug', if it's not +mounted. + +Signed-off-by: Xiao Guangrong +Cc: Peter Zijlstra +Cc: Paul Mackerras +Cc: Frederic Weisbecker +Cc: Clark Williams +Cc: John Kacur +LKML-Reference: <4B387090.7080407@cn.fujitsu.com> +Signed-off-by: Ingo Molnar +--- + tools/perf/perf.c | 2 +- + tools/perf/util/debugfs.c | 16 +++++++--------- + tools/perf/util/debugfs.h | 2 +- + 3 files changed, 9 insertions(+), 11 deletions(-) + +diff --git a/tools/perf/perf.c b/tools/perf/perf.c +index 873e55f..fc89005 100644 +--- a/tools/perf/perf.c ++++ b/tools/perf/perf.c +@@ -388,7 +388,7 @@ static int run_argv(int *argcp, const char ***argv) + /* mini /proc/mounts parser: searching for "^blah /mount/point debugfs" */ + static void get_debugfs_mntpt(void) + { +- const char *path = debugfs_find_mountpoint(); ++ const char *path = debugfs_mount(NULL); + + if (path) + strncpy(debugfs_mntpt, path, sizeof(debugfs_mntpt)); +diff --git a/tools/perf/util/debugfs.c b/tools/perf/util/debugfs.c +index 06b73ee..1f805fd 100644 +--- a/tools/perf/util/debugfs.c ++++ b/tools/perf/util/debugfs.c +@@ -106,16 +106,14 @@ int debugfs_valid_entry(const char *path) + return 0; + } + +-/* mount the debugfs somewhere */ ++/* mount the debugfs somewhere if it's not mounted */ + +-int debugfs_mount(const char *mountpoint) ++char *debugfs_mount(const char *mountpoint) + { +- char mountcmd[128]; +- + /* see if it's already mounted */ + if (debugfs_find_mountpoint()) { + debugfs_premounted = 1; +- return 0; ++ return debugfs_mountpoint; + } + + /* if not mounted and no argument */ +@@ -127,13 +125,13 @@ int debugfs_mount(const char *mountpoint) + mountpoint = "/sys/kernel/debug"; + } + ++ if (mount(NULL, mountpoint, "debugfs", 0, NULL) < 0) ++ return NULL; ++ + /* save the mountpoint */ + strncpy(debugfs_mountpoint, mountpoint, sizeof(debugfs_mountpoint)); + +- /* mount it */ +- snprintf(mountcmd, sizeof(mountcmd), +- "/bin/mount -t debugfs debugfs %s", mountpoint); +- return system(mountcmd); ++ return debugfs_mountpoint; + } + + /* umount the debugfs */ +diff --git a/tools/perf/util/debugfs.h b/tools/perf/util/debugfs.h +index 3cd14f9..83a0287 100644 +--- a/tools/perf/util/debugfs.h ++++ b/tools/perf/util/debugfs.h +@@ -15,7 +15,7 @@ + extern const char *debugfs_find_mountpoint(void); + extern int debugfs_valid_mountpoint(const char *debugfs); + extern int debugfs_valid_entry(const char *path); +-extern int debugfs_mount(const char *mountpoint); ++extern char *debugfs_mount(const char *mountpoint); + extern int debugfs_umount(void); + extern int debugfs_write(const char *entry, const char *value); + extern int debugfs_read(const char *entry, char *buffer, size_t size); +-- +1.7.1 + diff --git a/prevent-runtime-conntrack-changes.patch b/prevent-runtime-conntrack-changes.patch new file mode 100644 index 000000000..59d62f3de --- /dev/null +++ b/prevent-runtime-conntrack-changes.patch @@ -0,0 +1,74 @@ +Jon Masters correctly points out that conntrack hash sizes +(nf_conntrack_htable_size) are global (not per-netns) and +modifiable at runtime via /sys/module/nf_conntrack/hashsize . + +Steps to reproduce: + clone(CLONE_NEWNET) + [grow /sys/module/nf_conntrack/hashsize] + exit() + +At netns exit we are going to scan random memory for conntracks to be killed. + +Apparently there is a code which deals with hashtable resize for +init_net (and it was there befode netns conntrack code), so prohibit +hashsize modification if there is more than one netns exists. + +To change hashtable sizes, you need to reload module. + +Expectation hashtable size was simply glued to a variable with no code +to rehash expectations, so it was a bug to allow writing to it. +Make "expect_hashsize" readonly. + +This is temporarily until we figure out what to do. + +Signed-off-by: Alexey Dobriyan +Cc: stable@kernel.org +--- + + net/netfilter/nf_conntrack_core.c | 15 +++++++++++++++ + net/netfilter/nf_conntrack_expect.c | 2 +- + 2 files changed, 16 insertions(+), 1 deletion(-) + +--- a/net/netfilter/nf_conntrack_core.c ++++ b/net/netfilter/nf_conntrack_core.c +@@ -21,6 +21,7 @@ + #include + #include + #include ++#include + #include + #include + #include +@@ -1198,6 +1199,20 @@ int nf_conntrack_set_hashsize(const char *val, struct kernel_param *kp) + if (!nf_conntrack_htable_size) + return param_set_uint(val, kp); + ++ { ++ struct net *net; ++ unsigned int nr; ++ ++ nr = 0; ++ rtnl_lock(); ++ for_each_net(net) ++ nr++; ++ rtnl_unlock(); ++ /* init_net always exists */ ++ if (nr != 1) ++ return -EINVAL; ++ } ++ + hashsize = simple_strtoul(val, NULL, 0); + if (!hashsize) + return -EINVAL; +--- a/net/netfilter/nf_conntrack_expect.c ++++ b/net/netfilter/nf_conntrack_expect.c +@@ -569,7 +569,7 @@ static void exp_proc_remove(struct net *net) + #endif /* CONFIG_PROC_FS */ + } + +-module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0600); ++module_param_named(expect_hashsize, nf_ct_expect_hsize, uint, 0400); + + int nf_conntrack_expect_init(struct net *net) + { + diff --git a/rt2x00-rt2800-Make-rt30xx-and-rt35xx-chipsets-configurable.patch b/rt2x00-rt2800-Make-rt30xx-and-rt35xx-chipsets-configurable.patch new file mode 100644 index 000000000..39db1691a --- /dev/null +++ b/rt2x00-rt2800-Make-rt30xx-and-rt35xx-chipsets-configurable.patch @@ -0,0 +1,559 @@ +commit de1ebdceb6a4fe1b7073b81d273285b7c8bed312 +Author: Gertjan van Wingerde +Date: Sun Feb 14 12:52:05 2010 +0100 + + rt2x00: rt2800 - Make rt30xx and rt35xx chipsets configurable. + + Support for rt30xx- and rt35xx-based devices is currently not functional + in rt2800pci and rt2800usb. + In order to not confuse users we shouldn't claim the PCI and USB device + ID's for these devices. However, to allow for testing it is good to still + have them available, although disabled by default. + Make support for these device configuration options that default to off. + + For rt2800usb a 3rd class of devices is added, which are the unknown + devices. For these devices it is known that they are either based on + rt28xx, rt30xx or rt35xx, but it is not known on what chipset exactly. + These devices are disabled by default as well, until it can be established + on what chipset exactly they are based. + + Signed-off-by: Gertjan van Wingerde + Signed-off-by: John W. Linville + +diff --git a/drivers/net/wireless/rt2x00/Kconfig b/drivers/net/wireless/rt2x00/Kconfig +index 3ca824a..5239e08 100644 +--- a/drivers/net/wireless/rt2x00/Kconfig ++++ b/drivers/net/wireless/rt2x00/Kconfig +@@ -64,7 +64,7 @@ config RT2800PCI_SOC + default y + + config RT2800PCI +- tristate "Ralink rt2800 (PCI/PCMCIA) support (VERY EXPERIMENTAL)" ++ tristate "Ralink rt28xx/rt30xx/rt35xx (PCI/PCIe/PCMCIA) support (EXPERIMENTAL)" + depends on (RT2800PCI_PCI || RT2800PCI_SOC) && EXPERIMENTAL + select RT2800_LIB + select RT2X00_LIB_PCI if RT2800PCI_PCI +@@ -75,7 +75,7 @@ config RT2800PCI + select CRC_CCITT + select EEPROM_93CX6 + ---help--- +- This adds support for rt2800 wireless chipset family. ++ This adds support for rt2800/rt3000/rt3500 wireless chipset family. + Supported chips: RT2760, RT2790, RT2860, RT2880, RT2890 & RT3052 + + This driver is non-functional at the moment and is intended for +@@ -83,6 +83,32 @@ config RT2800PCI + + When compiled as a module, this driver will be called "rt2800pci.ko". + ++if RT2800PCI ++ ++config RT2800PCI_RT30XX ++ bool "rt2800pci - Include support for rt30xx (PCI/PCIe/PCMCIA) devices" ++ default n ++ ---help--- ++ This adds support for rt30xx wireless chipset family to the ++ rt2800pci driver. ++ Supported chips: RT3090, RT3091 & RT3092 ++ ++ Support for these devices is non-functional at the moment and is ++ intended for testers and developers. ++ ++config RT2800PCI_RT35XX ++ bool "rt2800pci - Include support for rt35xx (PCI/PCIe/PCMCIA) devices" ++ default n ++ ---help--- ++ This adds support for rt35xx wireless chipset family to the ++ rt2800pci driver. ++ Supported chips: RT3060, RT3062, RT3562, RT3592 ++ ++ Support for these devices is non-functional at the moment and is ++ intended for testers and developers. ++ ++endif ++ + config RT2500USB + tristate "Ralink rt2500 (USB) support" + depends on USB +@@ -126,6 +152,43 @@ config RT2800USB + + When compiled as a module, this driver will be called "rt2800usb.ko". + ++if RT2800USB ++ ++config RT2800USB_RT30XX ++ bool "rt2800usb - Include support for rt30xx (USB) devices" ++ default n ++ ---help--- ++ This adds support for rt30xx wireless chipset family to the ++ rt2800usb driver. ++ Supported chips: RT3070, RT3071 & RT3072 ++ ++ Support for these devices is non-functional at the moment and is ++ intended for testers and developers. ++ ++config RT2800USB_RT35XX ++ bool "rt2800usb - Include support for rt35xx (USB) devices" ++ default n ++ ---help--- ++ This adds support for rt35xx wireless chipset family to the ++ rt2800usb driver. ++ Supported chips: RT3572 ++ ++ Support for these devices is non-functional at the moment and is ++ intended for testers and developers. ++ ++config RT2800USB_UNKNOWN ++ bool "rt2800usb - Include support for unknown (USB) devices" ++ default n ++ ---help--- ++ This adds support for rt2800 family devices that are known to ++ have a rt2800 family chipset, but for which the exact chipset ++ is unknown. ++ ++ Support status for these devices is unknown, and enabling these ++ devices may or may not work. ++ ++endif ++ + config RT2800_LIB + tristate + +diff --git a/drivers/net/wireless/rt2x00/rt2800pci.c b/drivers/net/wireless/rt2x00/rt2800pci.c +index fc35105..0e4c417 100644 +--- a/drivers/net/wireless/rt2x00/rt2800pci.c ++++ b/drivers/net/wireless/rt2x00/rt2800pci.c +@@ -1185,7 +1185,10 @@ static const struct rt2x00_ops rt2800pci_ops = { + * RT2800pci module information. + */ + static struct pci_device_id rt2800pci_device_table[] = { +- { PCI_DEVICE(0x1462, 0x891a), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1814, 0x0601), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1814, 0x0681), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1814, 0x0701), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1814, 0x0781), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1432, 0x7708), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1432, 0x7727), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1432, 0x7728), PCI_DEVICE_DATA(&rt2800pci_ops) }, +@@ -1193,18 +1196,19 @@ static struct pci_device_id rt2800pci_device_table[] = { + { PCI_DEVICE(0x1432, 0x7748), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1432, 0x7758), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1432, 0x7768), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1814, 0x0601), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1814, 0x0681), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1814, 0x0701), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1814, 0x0781), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1814, 0x3060), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1814, 0x3062), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1a3b, 0x1059), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++#ifdef CONFIG_RT2800PCI_RT30XX + { PCI_DEVICE(0x1814, 0x3090), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1814, 0x3091), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1814, 0x3092), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1462, 0x891a), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++#endif ++#ifdef CONFIG_RT2800PCI_RT35XX ++ { PCI_DEVICE(0x1814, 0x3060), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++ { PCI_DEVICE(0x1814, 0x3062), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1814, 0x3562), PCI_DEVICE_DATA(&rt2800pci_ops) }, + { PCI_DEVICE(0x1814, 0x3592), PCI_DEVICE_DATA(&rt2800pci_ops) }, +- { PCI_DEVICE(0x1a3b, 0x1059), PCI_DEVICE_DATA(&rt2800pci_ops) }, ++#endif + { 0, } + }; + +diff --git a/drivers/net/wireless/rt2x00/rt2800usb.c b/drivers/net/wireless/rt2x00/rt2800usb.c +index 79ea379..5e4ee20 100644 +--- a/drivers/net/wireless/rt2x00/rt2800usb.c ++++ b/drivers/net/wireless/rt2x00/rt2800usb.c +@@ -805,51 +805,27 @@ static struct usb_device_id rt2800usb_device_table[] = { + /* Abocom */ + { USB_DEVICE(0x07b8, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x07b8, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1482, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* AirTies */ +- { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Amigo */ +- { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Amit */ + { USB_DEVICE(0x15c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Askey */ + { USB_DEVICE(0x1690, 0x0740), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1690, 0x0744), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0930, 0x0a07), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* ASUS */ + { USB_DEVICE(0x0b05, 0x1731), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0b05, 0x1732), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0b05, 0x1742), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0b05, 0x1784), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* AzureWave */ + { USB_DEVICE(0x13d3, 0x3247), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x13d3, 0x3305), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Belkin */ + { USB_DEVICE(0x050d, 0x8053), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x050d, 0x805c), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x050d, 0x815c), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Buffalo */ + { USB_DEVICE(0x0411, 0x00e8), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Cisco */ +- { USB_DEVICE(0x167b, 0x4001), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Conceptronic */ + { USB_DEVICE(0x14b2, 0x3c06), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x14b2, 0x3c07), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x14b2, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x14b2, 0x3c23), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x14b2, 0x3c25), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x14b2, 0x3c27), USB_DEVICE_DATA(&rt2800usb_ops) }, +@@ -858,157 +834,257 @@ static struct usb_device_id rt2800usb_device_table[] = { + { USB_DEVICE(0x07aa, 0x002f), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x07aa, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x07aa, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07aa, 0x0041), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07aa, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* D-Link */ + { USB_DEVICE(0x07d1, 0x3c09), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Edimax */ ++ { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* EnGenius */ ++ { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Gigabyte */ ++ { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Hawking */ ++ { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Linksys */ ++ { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Logitec */ ++ { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Motorola */ ++ { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* MSI */ ++ { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Philips */ ++ { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Planex */ ++ { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Ralink */ ++ { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Samsung */ ++ { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Siemens */ ++ { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Sitecom */ ++ { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* SMC */ ++ { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Sparklan */ ++ { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Sweex */ ++ { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* U-Media*/ ++ { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* ZCOM */ ++ { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Zinwell */ ++ { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Zyxel */ ++ { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) }, ++#ifdef CONFIG_RT2800USB_RT30XX ++ /* Abocom */ ++ { USB_DEVICE(0x07b8, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07b8, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07b8, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* AirTies */ ++ { USB_DEVICE(0x1eda, 0x2310), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* AzureWave */ ++ { USB_DEVICE(0x13d3, 0x3273), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Conceptronic */ ++ { USB_DEVICE(0x14b2, 0x3c12), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Corega */ ++ { USB_DEVICE(0x18c5, 0x0012), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* D-Link */ + { USB_DEVICE(0x07d1, 0x3c0a), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x07d1, 0x3c0d), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x07d1, 0x3c0e), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x07d1, 0x3c0f), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07d1, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x07d1, 0x3c15), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Edimax */ + { USB_DEVICE(0x7392, 0x7711), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x7392, 0x7717), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x7392, 0x7718), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Encore */ + { USB_DEVICE(0x203d, 0x1480), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x203d, 0x14a1), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x203d, 0x14a9), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* EnGenius */ +- { USB_DEVICE(0X1740, 0x9701), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1740, 0x9702), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1740, 0x9703), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1740, 0x9705), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1740, 0x9706), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Gigabyte */ ++ { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* I-O DATA */ ++ { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* MSI */ ++ { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Pegatron */ ++ { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Planex */ ++ { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Quanta */ ++ { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Ralink */ ++ { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Sitecom */ ++ { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* SMC */ ++ { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Zinwell */ ++ { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) }, ++#endif ++#ifdef CONFIG_RT2800USB_RT35XX ++ /* Askey */ ++ { USB_DEVICE(0x1690, 0x0744), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Cisco */ ++ { USB_DEVICE(0x167b, 0x4001), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* EnGenius */ ++ { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* I-O DATA */ ++ { USB_DEVICE(0x04bb, 0x0944), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Ralink */ ++ { USB_DEVICE(0x148f, 0x3370), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x148f, 0x8070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Sitecom */ ++ { USB_DEVICE(0x0df6, 0x0041), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Zinwell */ ++ { USB_DEVICE(0x5a57, 0x0284), USB_DEVICE_DATA(&rt2800usb_ops) }, ++#endif ++#ifdef CONFIG_RT2800USB_UNKNOWN ++ /* ++ * Unclear what kind of devices these are (they aren't supported by the ++ * vendor driver). ++ */ ++ /* Allwin */ ++ { USB_DEVICE(0x8516, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x8516, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x8516, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x8516, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x8516, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x8516, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x8516, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Amigo */ ++ { USB_DEVICE(0x0e0b, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0e0b, 0x9041), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Askey */ ++ { USB_DEVICE(0x0930, 0x0a07), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* ASUS */ ++ { USB_DEVICE(0x0b05, 0x1760), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0b05, 0x1761), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0b05, 0x1784), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0b05, 0x1790), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x1761, 0x0b05), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* AzureWave */ ++ { USB_DEVICE(0x13d3, 0x3262), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x13d3, 0x3284), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x13d3, 0x3305), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Belkin */ ++ { USB_DEVICE(0x050d, 0x825a), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Buffalo */ ++ { USB_DEVICE(0x0411, 0x012e), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0411, 0x0148), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0411, 0x0150), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0411, 0x015d), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Conceptronic */ ++ { USB_DEVICE(0x14b2, 0x3c08), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x14b2, 0x3c11), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Corega */ ++ { USB_DEVICE(0x07aa, 0x0041), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07aa, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x18c5, 0x0008), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* D-Link */ ++ { USB_DEVICE(0x07d1, 0x3c0b), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07d1, 0x3c13), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07d1, 0x3c15), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x07d1, 0x3c16), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* Encore */ ++ { USB_DEVICE(0x203d, 0x14a1), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x203d, 0x14a9), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ /* EnGenius */ + { USB_DEVICE(0x1740, 0x9707), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1740, 0x9708), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1740, 0x9709), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1740, 0x9801), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Gemtek */ + { USB_DEVICE(0x15a9, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Gigabyte */ +- { USB_DEVICE(0x1044, 0x800b), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1044, 0x800c), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1044, 0x800d), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Hawking */ +- { USB_DEVICE(0x0e66, 0x0001), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0e66, 0x0003), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0e66, 0x0009), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0e66, 0x000b), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* I-O DATA */ +- { USB_DEVICE(0x04bb, 0x0944), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x04bb, 0x0945), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x04bb, 0x0947), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x04bb, 0x0948), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* LevelOne */ + { USB_DEVICE(0x1740, 0x0605), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1740, 0x0615), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Linksys */ +- { USB_DEVICE(0x1737, 0x0070), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1737, 0x0071), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1737, 0x0077), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x1737, 0x0078), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1737, 0x0079), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Logitec */ +- { USB_DEVICE(0x0789, 0x0162), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0789, 0x0163), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0789, 0x0164), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Motorola */ +- { USB_DEVICE(0x100d, 0x9031), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x100d, 0x9032), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* MSI */ +- { USB_DEVICE(0x0db0, 0x3820), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0db0, 0x3821), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0db0, 0x3822), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0db0, 0x3870), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0db0, 0x6899), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0db0, 0x3871), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0db0, 0x821a), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0db0, 0x822a), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0db0, 0x870a), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x0db0, 0x871a), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0db0, 0x899a), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Ovislink */ + { USB_DEVICE(0x1b75, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Para */ + { USB_DEVICE(0x20b8, 0x8888), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Pegatron */ ++ { USB_DEVICE(0x05a6, 0x0101), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x1d4d, 0x0002), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1d4d, 0x000c), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x1d4d, 0x000e), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Philips */ +- { USB_DEVICE(0x0471, 0x200f), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x1d4d, 0x0010), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Planex */ +- { USB_DEVICE(0x2019, 0xed06), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x2019, 0xab24), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x2019, 0xab25), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Qcom */ + { USB_DEVICE(0x18e8, 0x6259), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Quanta */ +- { USB_DEVICE(0x1a32, 0x0304), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Ralink */ +- { USB_DEVICE(0x148f, 0x2070), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x148f, 0x2770), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x148f, 0x2870), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x148f, 0x3070), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x148f, 0x3071), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x148f, 0x3072), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x148f, 0x3572), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Samsung */ +- { USB_DEVICE(0x04e8, 0x2018), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Siemens */ +- { USB_DEVICE(0x129b, 0x1828), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Sitecom */ +- { USB_DEVICE(0x0df6, 0x0017), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x002b), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x002c), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x002d), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x0039), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x003b), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x003c), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x003d), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x003e), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x003f), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x0040), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x0041), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0df6, 0x0042), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x0047), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x0048), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x004a), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0df6, 0x004d), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* SMC */ +- { USB_DEVICE(0x083a, 0x6618), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x083a, 0x7511), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x083a, 0x7512), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x083a, 0x7522), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x083a, 0x8522), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x083a, 0xa512), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x083a, 0xa618), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x083a, 0xa701), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x083a, 0xa702), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x083a, 0xb522), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x083a, 0xc522), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Sparklan */ +- { USB_DEVICE(0x15a9, 0x0006), USB_DEVICE_DATA(&rt2800usb_ops) }, ++ { USB_DEVICE(0x083a, 0xd522), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Sweex */ + { USB_DEVICE(0x177f, 0x0153), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x177f, 0x0302), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x177f, 0x0313), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* U-Media*/ +- { USB_DEVICE(0x157e, 0x300e), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* ZCOM */ +- { USB_DEVICE(0x0cde, 0x0022), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x0cde, 0x0025), USB_DEVICE_DATA(&rt2800usb_ops) }, +- /* Zinwell */ +- { USB_DEVICE(0x5a57, 0x0280), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x5a57, 0x0282), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x5a57, 0x0283), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x5a57, 0x0284), USB_DEVICE_DATA(&rt2800usb_ops) }, +- { USB_DEVICE(0x5a57, 0x5257), USB_DEVICE_DATA(&rt2800usb_ops) }, + /* Zyxel */ +- { USB_DEVICE(0x0586, 0x3416), USB_DEVICE_DATA(&rt2800usb_ops) }, + { USB_DEVICE(0x0586, 0x341a), USB_DEVICE_DATA(&rt2800usb_ops) }, ++#endif + { 0, } + }; + diff --git a/scripts/bumpspecfile.py b/scripts/bumpspecfile.py new file mode 100755 index 000000000..478e82871 --- /dev/null +++ b/scripts/bumpspecfile.py @@ -0,0 +1,71 @@ +#!/usr/bin/python +# +# Needs $GIT_COMMITTER_NAME and $GIT_COMMITTER_EMAIL set. +# +import re +import sys +import time +import os +import string + +class Specfile: + def __init__(self,filename): + file=open(filename,"r") + self.lines=file.readlines() + self.vr="" + + def getNextVR(self,aspec): + # Get VR for changelog entry. + (ver,rel) = os.popen("LC_ALL=C rpm --specfile -q --qf '%%{version} %%{release}\n' --define 'dist %%{nil}' %s | head -1" % aspec).read().strip().split(' ') + pos = 0 + # general released kernel case, bump 1st field + fedora_build = rel.split('.')[pos] + if fedora_build == "0": + # this is a devel kernel, bump 2nd field + pos = 1 + elif rel.split('.')[-1] != fedora_build: + # this is a branch, must bump 3rd field + pos = 2 + fedora_build = rel.split('.')[pos] + if pos == 1 and len(rel.split('.')) > 4: + # uh... what? devel kernel in a branch? private build? just do no VR in clog... + print "Warning: not adding any VR to changelog, couldn't tell for sure which field to bump" + pos = -1 + next_fedora_build = int(fedora_build) + 1 + if pos == 0: + nextrel = str(next_fedora_build) + elif pos == 1: + nextrel = "0." + str(next_fedora_build) + elif pos == 2: + nextrel = rel.split('.')[0] + "." + rel.split('.')[1] + "." + str(next_fedora_build) + if pos >= 0: + for s in rel.split('.')[pos + 1:]: + nextrel = nextrel + "." + s + self.vr = " "+ver+'-'+nextrel + + def addChangelogEntry(self,entry): + user = os.environ.get("GIT_COMMITTER_NAME","unknown") + email = os.environ.get("GIT_COMMITTER_EMAIL","unknown") + if (email == "unknown"): + email = os.environ.get("USER","unknown")+"@fedoraproject.org" + changematch=re.compile(r"^%changelog") + date=time.strftime("%a %b %d %Y", time.localtime(time.time())) + newchangelogentry="%changelog\n* "+date+" "+user+" <"+email+">"+self.vr+"\n"+entry+"\n\n" + for i in range(len(self.lines)): + if(changematch.match(self.lines[i])): + self.lines[i]=newchangelogentry + break + + def writeFile(self,filename): + file=open(filename,"w") + file.writelines(self.lines) + file.close() + +if __name__=="__main__": + aspec=(sys.argv[1]) + s=Specfile(aspec) + entry=(sys.argv[2]) + s.getNextVR(aspec) + s.addChangelogEntry(entry) + s.writeFile(aspec) + diff --git a/scripts/check-TODO.sh b/scripts/check-TODO.sh new file mode 100755 index 000000000..7067f0b44 --- /dev/null +++ b/scripts/check-TODO.sh @@ -0,0 +1,27 @@ +#!/bin/sh + +for i in `grep ^* TODO | awk '{ print $2 }'` +do + if [ ! -f $i ]; then + echo "$i referenced in the TODO, but isn't in CVS!" + fi; +done + +# sometimes dead stuff lingers in cvs, even though it's not in the specfile. +for i in *.patch +do + for j in $(grep $i kernel.spec | grep Apply.*Patch | awk '{ print $2 }' | wc -l) + do + if [ "$j" = "0" ]; then + echo $i is in CVS, but not applied in spec file. + grep $i TODO | awk '{ print $2 " is also still in the TODO" }' + fi + done +done + +#for i in `grep ApplyPatch kernel.spec | awk '{ print $2 }'` +#do +# R=$(grep $i TODO) +# echo "$i is in CVS, but not mentioned in the TODO!" +#done + diff --git a/scripts/combine.sh b/scripts/combine.sh new file mode 100755 index 000000000..86a68d302 --- /dev/null +++ b/scripts/combine.sh @@ -0,0 +1,34 @@ +#! /bin/sh + +# combine a set of quilt patches + +# $1 : base dir (source tree) +# $2 : quilt dir (patches to apply) +# $3 : pre-patch to apply first (optional) + +# e.g.: +# combine.sh /home/user/fedora/trunk/kernel/F-11/kernel-2.6.30/vanilla-2.6.30 \ +# /home/user/git/stable-queue/queue-2.6.30 \ +# /home/user/fedora/trunk/kernel/F-11/patch-2.6.30.5.bz2 + +if [ $# -lt 2 ] ; then + exit 1 +fi + +TD="combine_temp.d" + +cd $1 || exit 1 +cd .. +[ -d $TD ] && rm -Rf $TD +mkdir $TD || exit 1 +cd $TD + +cp -al ../$(basename $1) work.d +cd work.d +[ "$3" ] && bzcat $3 | patch -p1 -s +ln -s $2 patches +[ -h patches ] || exit 1 +quilt snapshot +quilt upgrade +quilt push -a -q +quilt diff --snapshot >../combined.patch diff --git a/scripts/configcommon.pl b/scripts/configcommon.pl new file mode 100644 index 000000000..38bbe80dc --- /dev/null +++ b/scripts/configcommon.pl @@ -0,0 +1,82 @@ +#! /usr/bin/perl + +my @args=@ARGV; +my @configoptions; +my @configvalues; +my @common; +my $configcounter = 0; + +# first, read the 1st file + +open (FILE,"$args[0]") || die "Could not open $args[0]"; +while () { + my $str = $_; + if (/\# ([\w]+) is not set/) { + $configoptions[$configcounter] = $1; + $configvalues[$configcounter] = $str; + $common[$configcounter] = 1; + $configcounter ++; + } else { + if (/([\w]+)=/) { + $configoptions[$configcounter] = $1; + $configvalues[$configcounter] = $str; + $common[$configcounter] = 1; + $configcounter ++; + } else { + $configoptions[$configcounter] = "foobarbar"; + $configvalues[$configcounter] = $str; + $common[$configcounter] = 1; + $configcounter ++; + } + } +}; + +# now, read all configfiles and see of the options match the initial one. +# if not, mark it not common +my $cntr=1; + + +while ($cntr < @ARGV) { + open (FILE,$args[$cntr]) || die "Could not open $args[$cntr]"; + while () { + my $nooutput; + my $counter; + my $configname; + + if (/\# ([\w]+) is not set/) { + $configname = $1; + } else { + if (/([\w]+)=/) { + $configname = $1; + } + } + + $counter = 0; + $nooutput = 0; + while ($counter < $configcounter) { + if ("$configname" eq "$configoptions[$counter]") { + if ("$_" eq "$configvalues[$counter]") { + 1; + } else { + $common[$counter] = 0; + } + } + $counter++; + } + } + + $cntr++; +} + +# now print the common values +my $counter = 0; + +while ($counter < $configcounter) { + if ($common[$counter]!=0) { + print "$configvalues[$counter]"; + } + $counter++; +} + +1; + diff --git a/scripts/configdiff.pl b/scripts/configdiff.pl new file mode 100644 index 000000000..848d8df0f --- /dev/null +++ b/scripts/configdiff.pl @@ -0,0 +1,76 @@ +#! /usr/bin/perl + +my @args=@ARGV; +my @configoptions; +my @configvalues; +my @alreadyprinted; +my $configcounter = 0; + +# first, read the override file + +open (FILE,"$args[0]") || die "Could not open $args[0]"; +while () { + my $str = $_; + if (/\# ([\w]+) is not set/) { + $configoptions[$configcounter] = $1; + $configvalues[$configcounter] = $str; + $alreadprinted[$configcounter] = 0; + $configcounter ++; + } else { + if (/([\w]+)=/) { + $configoptions[$configcounter] = $1; + $configvalues[$configcounter] = $str; + $alreadprinted[$configcounter] = 0; + $configcounter ++; + } else { + $configoptions[$configcounter] = "$_"; + $configvalues[$configcounter] = $str; + $alreadprinted[$configcounter] = 0; + $configcounter ++; + } + } +}; + +# now, read and output the entire configfile, except for the overridden +# parts... for those the new value is printed. +# O(N^2) algorithm so if this is slow I need to look at it later + +open (FILE2,"$args[1]") || die "Could not open $args[1]"; +while () { + my $nooutput; + my $counter; + my $configname="$_"; + my $match; + + if (/\# ([\w]+) is not set/) { + $configname = $1; + } else { + if (/([\w]+)=/) { + $configname = $1; + } + } + + $counter = 0; + $nooutput = 0; + $match = 0; +# print "C : $configname"; + while ($counter < $configcounter) { + if ("$configname" eq "$configoptions[$counter]") { + if ( ("$_" eq "$configvalues[$counter]") || ("$configname" eq "") ) { + $match = 1; + } else { + $alreadyprinted[$configcounter] = 1; + print "$_"; + $match = 1; + } + } + $counter++; + } + if ($match == 0) { + print "$_"; + } + +} + + +1; diff --git a/scripts/cross-amd64.sh b/scripts/cross-amd64.sh new file mode 100644 index 000000000..b3119d8fc --- /dev/null +++ b/scripts/cross-amd64.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=x86_64-linux- ARCH=x86_64 hammer + diff --git a/scripts/cross-i586.sh b/scripts/cross-i586.sh new file mode 100644 index 000000000..000f4ae7e --- /dev/null +++ b/scripts/cross-i586.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make ARCH=i386 i586 + diff --git a/scripts/cross-i686.sh b/scripts/cross-i686.sh new file mode 100644 index 000000000..5c0cfe137 --- /dev/null +++ b/scripts/cross-i686.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make ARCH=i386 i686 + diff --git a/scripts/cross-ia64.sh b/scripts/cross-ia64.sh new file mode 100644 index 000000000..5699a57c1 --- /dev/null +++ b/scripts/cross-ia64.sh @@ -0,0 +1,2 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ia64-linux- ARCH=ia64 ia64 diff --git a/scripts/cross-iseries.sh b/scripts/cross-iseries.sh new file mode 100644 index 000000000..71bfd9156 --- /dev/null +++ b/scripts/cross-iseries.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ppc64-linux- ARCH=ppc64 ppc64iseries + diff --git a/scripts/cross-ppc.sh b/scripts/cross-ppc.sh new file mode 100644 index 000000000..c49b740f3 --- /dev/null +++ b/scripts/cross-ppc.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ppc-linux- ARCH=ppc ppc + diff --git a/scripts/cross-ppc64.sh b/scripts/cross-ppc64.sh new file mode 100644 index 000000000..fb29d4481 --- /dev/null +++ b/scripts/cross-ppc64.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ppc64-linux- ARCH=ppc64 ppc64 + diff --git a/scripts/cross-ppc8260.sh b/scripts/cross-ppc8260.sh new file mode 100644 index 000000000..10fbc3292 --- /dev/null +++ b/scripts/cross-ppc8260.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ppc-linux- ARCH=ppc ppc8260 + diff --git a/scripts/cross-ppc8560.sh b/scripts/cross-ppc8560.sh new file mode 100644 index 000000000..405f98a9c --- /dev/null +++ b/scripts/cross-ppc8560.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ppc-linux- ARCH=ppc ppc8560 + diff --git a/scripts/cross-pseries.sh b/scripts/cross-pseries.sh new file mode 100644 index 000000000..724a8e582 --- /dev/null +++ b/scripts/cross-pseries.sh @@ -0,0 +1,3 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=ppc64-linux- ARCH=ppc64 pseries64 + diff --git a/scripts/cross-s390.sh b/scripts/cross-s390.sh new file mode 100644 index 000000000..4a274397c --- /dev/null +++ b/scripts/cross-s390.sh @@ -0,0 +1,2 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=s390-linux- ARCH=s390 s390 diff --git a/scripts/cross-s390x.sh b/scripts/cross-s390x.sh new file mode 100644 index 000000000..1cdc98a73 --- /dev/null +++ b/scripts/cross-s390x.sh @@ -0,0 +1,2 @@ +export PATH=$PATH:/opt/cross/bin +make CROSS_COMPILE=s390x-linux- ARCH=s390 s390x diff --git a/scripts/get-snapshot.sh b/scripts/get-snapshot.sh new file mode 100755 index 000000000..79d2b095e --- /dev/null +++ b/scripts/get-snapshot.sh @@ -0,0 +1,35 @@ +#!/bin/bash + +VER=$(tail -n1 upstream | sed s/bz2/id/) +rm -f $VER +wget -c http://www.kernel.org/pub/linux/kernel/v2.6/snapshots/$VER +SHA1=$(cat $VER) +rm -f patch-2.6.*-git*.id + +cd ~/src/git-trees/kernel/linux-2.6 +git pull + +DIF=$(git diff $SHA1.. | wc -l) +if [ "$DIF" = "0" ]; then + echo Nothing changed. + exit +fi +TOT=$(git log | head -n1) + +git diff $SHA1.. > ~/src/fedora/kernel/devel/git-linus-new.diff +cd ~/src/fedora/kernel/devel/ +DIF=$(cmp git-linus.diff git-linus-new.diff) +if [ "$?" = "0" ]; then + echo Nothing new in git + rm -f git-linus-new.diff + exit +fi +mv git-linus-new.diff git-linus.diff + +perl -p -i -e 's|^#ApplyPatch\ git-linus.diff|ApplyPatch\ git-linus.diff|' kernel.spec + +echo "- Merge Linux-2.6 up to" $TOT > ~/src/fedora/kernel/devel/clog.tmp +cd ~/src/fedora/kernel/devel/ +bumpspecfile.py kernel.spec "$(cat clog.tmp)" +rm -f clog.tmp +make clog diff --git a/scripts/grab-logs.sh b/scripts/grab-logs.sh new file mode 100755 index 000000000..8a445ec99 --- /dev/null +++ b/scripts/grab-logs.sh @@ -0,0 +1,16 @@ +#!/bin/sh + +VER=$(make verrel) +ver=$(echo $VER | sed -e 's/-/ /g' | awk '{print $2}') +rev=$(echo $VER | sed -e 's/-/ /g' | awk '{print $3}') + +if [ -d logs ]; then + DIR=logs/ +else + DIR=./ +fi + +wget -O $DIR/build-$VER-i686.log http://kojipkgs.fedoraproject.org/packages/kernel/$ver/$rev/data/logs/i686/build.log +wget -O $DIR/build-$VER-x86-64.log http://kojipkgs.fedoraproject.org/packages/kernel/$ver/$rev/data/logs/x86_64/build.log +wget -O $DIR/build-$VER-noarch.log http://kojipkgs.fedoraproject.org/packages/kernel/$ver/$rev/data/logs/noarch/build.log + diff --git a/scripts/newpatch.sh b/scripts/newpatch.sh new file mode 100755 index 000000000..0dc2e837c --- /dev/null +++ b/scripts/newpatch.sh @@ -0,0 +1,21 @@ +#!/bin/sh +# Easy application of new patches. +# Always adds to the very end. (Bumps last patch nr by 100) +# Parameters: +# $1 - patch filename +# $2 - description + +OLD=$(grep ^Patch kernel.spec | tail -n1 | awk '{ print $1 }' | sed s/Patch// | sed s/://) +NEW=$(($OLD/100*100+100)) + +sed -i "/^Patch$OLD:\ /a#\ $2\nPatch$NEW:\ $1" kernel.spec + +LAST=$(grep ^ApplyPatch kernel.spec | tail -n1 | awk '{ print $2 }') + +sed -i "/^ApplyPatch $LAST/aApplyPatch $1" kernel.spec + +cvs add $1 + +scripts/bumpspecfile.py kernel.spec "- $2" +make clog + diff --git a/scripts/pull-upstreams.sh b/scripts/pull-upstreams.sh new file mode 100755 index 000000000..e94fcfd48 --- /dev/null +++ b/scripts/pull-upstreams.sh @@ -0,0 +1,13 @@ +#!/bin/bash + +utrace_base=2.6-current +utrace_base=2.6.34 + +url=http://people.redhat.com/roland/utrace/${1:-$utrace_base} + +wget -q -O /dev/stdout $url/series | grep 'patch$' | +while read i +do + rm -f linux-2.6-$i + wget -nv -O linux-2.6-$i $url/$i +done diff --git a/scripts/rebase.sh b/scripts/rebase.sh new file mode 100755 index 000000000..fc3157b24 --- /dev/null +++ b/scripts/rebase.sh @@ -0,0 +1,199 @@ +#!/bin/bash + +if [ ! -f /usr/bin/curl ]; then + echo yum install curl + exit 0 +fi + +# Current kernel bits +if [ `grep -c ^patch upstream` -ge 1 ]; then + export OLD=`grep ^patch upstream | tail -n1 | sed s/patch-// | sed s/\.bz2//` +else + export OLD=`grep linux-2.6 upstream | tail -n1 | sed s/linux-// | sed s/\.tar\.bz2//` +fi +export OLDBASE=`echo $OLD | sed s/-/\ /g | sed s/2\.6\.// | awk '{ print $1 }'` +if [ `echo $OLD | grep -c rc` -ge 1 ]; then + export OLDRC=`echo $OLD | sed s/-/\ /g | sed s/rc// | awk '{ print $2 }'` + if [ `echo $OLD | grep -c git` -ge 1 ]; then + export OLDGIT=`echo $OLD | sed s/-/\ /g | sed s/git// | awk '{ print $3 }'` + else + export OLDGIT=0 + fi +else + export OLDRC=0 + if [ `echo $OLD | grep -c git` -ge 1 ]; then + export OLDGIT=`echo $OLD | sed s/-/\ /g | sed s/git// | awk '{ print $2 }'` + else + export OLDGIT=0 + fi +fi + +# Is there a new snapshot or prepatch ? +NEW=`curl -s http://www.kernel.org/kdist/finger_banner | grep "latest snapshot 2.6 version"` +if [ -z "$NEW" ] ; then + NEW=`curl -s http://www.kernel.org/kdist/finger_banner | grep "latest mainline 2.6 version"` + if [ -z "$NEW" ] ; then + if [ "$OLDRC" -ne 0 ] ; then + NEW=`curl -s http://www.kernel.org/kdist/finger_banner | grep "latest stable 2.6." | head -n1` + else + echo "No new rc or git snapshot of stable branch". + exit 0 + fi + fi +fi +export N=`echo $NEW | awk '{ print $11 }'` +if [ -z "$N" ]; then + # "Stable version" + export NEW=`echo $NEW | awk '{ print $10 }'` +else + export NEW=`echo $NEW | awk '{ print $11 }'` +fi + +export NEWBASE=`echo $NEW | sed s/-/\ /g | sed s/2\.6\.// | awk '{ print $1 }'` +if [ `echo $NEW | grep -c rc` -ge 1 ]; then + export NEWRC=`echo $NEW | sed s/-/\ /g | sed s/rc// | awk '{ print $2 }'` + if [ `echo $NEW | grep -c git` -ge 1 ]; then + export NEWGIT=`echo $NEW | sed s/-/\ /g | sed s/git// | awk '{ print $3 }'` + else + export NEWGIT=0 + fi +else + export NEWRC=0 + if [ `echo $NEW | grep -c git` -ge 1 ]; then + export NEWGIT=`echo $NEW | sed s/-/\ /g | sed s/git// | awk '{ print $2 }'` + else + export NEWGIT=0 + fi +fi + +echo "OLD kernel was $OLD BASE=$OLDBASE RC=$OLDRC GIT=$OLDGIT" +echo "NEW kernel is $NEW BASE=$NEWBASE RC=$NEWRC GIT=$NEWGIT" + +if [ "$OLDRC" -eq 0 -a "$OLDGIT" -eq 0 -a "$OLDGIT" -ne "$NEWGIT" ]; then + echo "Rebasing from a stable release to a new git snapshot" + perl -p -i -e 's/^%define\ released_kernel\ 1/\%define\ released_kernel\ 0/' kernel.spec + perl -p -i -e 's/^%define\ rawhide_skip_docs\ 1/\%define\ rawhide_skip_docs\ 0/' kernel.spec + # force these to zero in this case, they may not have been when we rebased to stable + perl -p -i -e 's/^%define\ rcrev.*/\%define\ rcrev\ 0/' kernel.spec + perl -p -i -e 's/^%define\ gitrev.*/\%define\ gitrev\ 0/' kernel.spec +fi + +# make sure we build docs at least once per -rc kernel, shut it off otherwise +if [ "$OLDRC" -ne 0 -a "$NEWRC" -gt "$OLDRC" ]; then + perl -p -i -e 's/^%define\ rawhide_skip_docs\ 1/\%define\ rawhide_skip_docs\ 0/' kernel.spec +else + if [ "$NEWRC" -eq "$OLDRC" -a "$NEWGIT" -gt "$OLDGIT" ]; then + # common case, same -rc, new -git, make sure docs are off. + perl -p -i -e 's/^%define\ rawhide_skip_docs\ 0/\%define\ rawhide_skip_docs\ 1/' kernel.spec + fi +fi + +if [ "$NEWRC" -eq 0 -a "$NEWGIT" -eq 0 ]; then + echo "Rebasing from -rc to final release." + perl -p -i -e 's/^%define\ released_kernel\ 0/\%define\ released_kernel\ 1/' kernel.spec + perl -p -i -e 's/^%define\ rawhide_skip_docs\ 1/\%define\ rawhide_skip_docs\ 0/' kernel.spec + export OLD_TARBALL_BASE=$(($OLDBASE-1)) + perl -p -i -e 's/^%define\ base_sublevel\ $ENV{OLD_TARBALL_BASE}/%define\ base_sublevel\ $ENV{NEWBASE}/' kernel.spec + perl -p -i -e 's/^%define\ rcrev.*/\%define\ rcrev\ 0/' kernel.spec + perl -p -i -e 's/^%define\ gitrev.*/\%define\ gitrev\ 0/' kernel.spec + + grep -v kernel-2.6.$OLD_TARBALL_BASE .cvsignore >.cvsignore.tmp ; mv .cvsignore.tmp .cvsignore + echo kernel-2.6.$NEWBASE >> .cvsignore + + for i in upstream sources .cvsignore + do + grep -v linux-2.6.$OLD_TARBALL_BASE.tar.bz2 $i > .$i.tmp; mv .$i.tmp $i + grep -v patch-2.6.$OLDBASE-rc$OLDRC.bz2 $i > .$i.tmp; mv .$i.tmp $i + grep -v patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2 $i > .$i.tmp; mv .$i.tmp $i + done + + echo linux-2.6.$NEWBASE.tar.bz2 >> upstream + + rm -f linux-2.6.$OLD_TARBALL_BASE.tar.bz2 + rm -f linux-2.6.$OLD_TARBALL_BASE.tar.bz2.sign + rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2 + rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign + rm -f patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2 + rm -f patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2.sign + + cvs remove linux-2.6.$OLD_TARBALL_BASE.tar.bz2.sign + cvs remove patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign + cvs remove patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2.sign + + make download + make upload FILES=linux-$NEW.tar.bz2 + + cvs add linux-$NEW.tar.bz2.sign + + bumpspecfile.py kernel.spec "- $NEW" + make clog + echo FIXME! Fix up fedora_cvs_origin + make verrel + exit 1 +fi + +if [ "$OLDRC" != "$NEWRC" ]; then + echo "Different rc. Rebasing from $OLDRC to $NEWRC" + perl -p -i -e 's/^%define\ rcrev.*/\%define\ rcrev\ $ENV{"NEWRC"}/' kernel.spec + perl -p -i -e 's/$ENV{OLDBASE}-rc$ENV{OLDRC}.bz2/$ENV{NEWBASE}-rc$ENV{NEWRC}.bz2/' .cvsignore + perl -p -i -e 's/$ENV{OLDBASE}-rc$ENV{OLDRC}.bz2/$ENV{NEWBASE}-rc$ENV{NEWRC}.bz2/' upstream + grep -v patch-2.6.$OLDBASE-rc$OLDRC.bz2 sources > .sources.tmp; mv .sources.tmp sources + grep -v patch-2.6.$OLDBASE-rc$OLDRC-git$OLDGIT.bz2 .cvsignore >.cvsignore.tmp ; mv .cvsignore.tmp .cvsignore + if [ `grep -c patch-2.6.$NEWBASE-rc$NEWRC.bz2 upstream` -eq 0 ]; then + echo patch-2.6.$NEWBASE-rc$NEWRC.bz2 >> .cvsignore + echo patch-2.6.$NEWBASE-rc$NEWRC.bz2 >> upstream + fi + rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2 + rm -f patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign + cvs remove patch-2.6.$OLDBASE-rc$OLDRC.bz2.sign + make download + make upload FILES=patch-2.6.$NEWBASE-rc$NEWRC.bz2 + cvs add patch-2.6.$NEWBASE-rc$NEWRC.bz2.sign + + # Another awkward (albeit unlikely) corner case. + # Moving from say 26-rc3-git1 to 26-rc4-git1 + # The above will grab the new -rc, but the below will + # think that the -git hasn't changed. + # Fudge around this, by pretending the old git was something crazy. + OLDGIT=99 +fi + +if [ "$OLDGIT" != "$NEWGIT" ]; then + if [ "$OLDRC" -eq 0 -a "$OLDGIT" -eq 0 ]; then + echo "Rebasing to pre-rc git$NEWGIT" + else + echo "Different git. Rebasing from git$OLDGIT to git$NEWGIT" + fi + perl -p -i -e 's/^%define\ gitrev.*/\%define\ gitrev\ $ENV{"NEWGIT"}/' kernel.spec + if [ "$OLDGIT" -ne 0 ]; then + if [ "$NEWGIT" -ne 0 ]; then + perl -p -i -e 's/$ENV{OLD}/$ENV{NEW}/' .cvsignore + perl -p -i -e 's/$ENV{OLD}/$ENV{NEW}/' upstream + fi + grep -v patch-$OLD.bz2 sources > .sources.tmp; mv .sources.tmp sources + grep -v patch-$OLD.bz2 upstream > .upstream.tmp; mv .upstream.tmp upstream + else + echo patch-$NEW.bz2 >> .cvsignore + echo patch-$NEW.bz2 >> upstream + fi + + make download + make upload FILES=patch-$NEW.bz2 + + cvs add patch-$NEW.bz2.sign + if [ "$OLDGIT" -ne 0 ]; then + rm -f patch-$OLD.bz2 + rm -f patch-$OLD.bz2.sign + cvs remove patch-$OLD.bz2.sign + fi +fi + +if [ "$OLDRC" != "$NEWRC" -o "$OLDGIT" != "$NEWGIT" ]; then + perl -p -i -e 's|^ApplyPatch\ git-linus.diff|#ApplyPatch\ git-linus.diff|' kernel.spec + > git-linus.diff + bumpspecfile.py kernel.spec "- $NEW" + make clog + exit 1 +else + exit 0 +fi diff --git a/scripts/reconfig.sh b/scripts/reconfig.sh new file mode 100755 index 000000000..d9e8fa7c3 --- /dev/null +++ b/scripts/reconfig.sh @@ -0,0 +1,26 @@ +#!/bin/bash + +base_sublevel=$(grep "^%define base_sublevel" kernel.spec | head -n1 | awk '{ print $3 }') + +#if [ `grep -c "^%define released_kernel 1" kernel.spec` -ge 1 ]; then + V=$base_sublevel +#else +# let V=$base_sublevel+1 +#fi + +cd kernel-2.6.$base_sublevel/linux-2.6.$base_sublevel.noarch/ +rm -f kernel-*.config +cp ../../kernel-2.6.$V-*.config . + +for i in kernel-*.config +do + echo $i + rm -f .config + cp $i .config + Arch=`head -1 .config | cut -b 3-` + make ARCH=$Arch nonint_oldconfig > /dev/null || exit 1 + echo "# $Arch" > configs/$i + cat .config >> configs/$i + echo +done + diff --git a/scripts/rediffall.pl b/scripts/rediffall.pl new file mode 100644 index 000000000..29f12beb9 --- /dev/null +++ b/scripts/rediffall.pl @@ -0,0 +1,64 @@ +#!/usr/bin/perl -w +# +# Script to rediff all patches in the spec +# Usage: perl -w rediffall.pl < kernel-2.4.spec +# +# $workdir is where the new rediff'ed patches are created +# $origdir is where the original patches and tarball are located +# +# Note that both $workdir and $origdir must be absolute path names. +# Suggestion: create a /kernel symbolic link to the top of your CVS tree. + +my $workdir = "/dev/shm/redifftree"; +my $origdir = "/home/davej/devel"; +my $kernver = "linux-2.6.17"; +my $datestrip = "s/^\\(\\(+++\\|---\\) [^[:blank:]]\\+\\)[[:blank:]].*/\\1/"; +my $patchindex = 0; +my @patchlist; + +# phase 1: create a tree +print "Extracting pristine source..\n"; +system("mkdir -p $workdir"); +system("rm -rf $workdir/*"); +chdir("$workdir"); +system("tar -jxvf $origdir/$kernver.tar.bz2 > /dev/null"); +system("cp -al $kernver linux-$patchindex"); + +# phase 2: read the spec from stdin and store all patches +print "Reading specfile..\n"; + +while (<>) { + my $line = $_; + if ($line =~ /^Patch([0-9]+)\: ([a-zA-Z0-9\-\_\.\+]+\.patch)/) { + $patchlist[$1] = $2; + } else { + if ($line =~ /^Patch([0-9]+)\: ([a-zA-Z0-9\-\_\.]+\.bz2)/) { + $patchlist[$1] = $2; + } + } + + if ($line =~ /^%patch([0-9]+) -p1/) { + # copy the tree, apply the patch, diff and remove the old tree + my $oldindex = $patchindex; + $patchindex = $1; + + print "rediffing patch number $patchindex: $patchlist[$patchindex]\n"; + + system("cp -al linux-$oldindex linux-$patchindex"); + chdir("linux-$patchindex"); + if ($patchlist[$patchindex] =~ /bz2/) { + system("bzcat $origdir/$patchlist[$patchindex] | patch -p1 &>/dev/null"); + } else { + system("cat $origdir/$patchlist[$patchindex] | patch -p1 &>/dev/null"); + } + chdir("$workdir"); + system("rm -f `find -name \"*orig\"`"); + if ($patchlist[$patchindex] =~ /bz2/) { + } else { + system("diff -urNp --exclude-from=/home/davej/.exclude linux-$oldindex linux-$patchindex | sed '$datestrip' > $patchlist[$patchindex]"); + } + system("rm -rf linux-$oldindex"); + } +}; + +1; diff --git a/scripts/sort-config b/scripts/sort-config new file mode 100755 index 000000000..bc497ea0b --- /dev/null +++ b/scripts/sort-config @@ -0,0 +1,222 @@ +#!/bin/bash + +SRC=($(ls config-* 2>/dev/null)) +TGT=($(ls kernel-*/linux-*.noarch/configs/kernel-2.6.*-*.config \ + kernel-*/linux-*.noarch/configs/kernel-2.6.*-*-debug.config 2>/dev/null)) +TGT1=(${TGT[*]#kernel-*/linux-*.noarch/configs/kernel-2.6.*-}) + +ALL_OPTS="cdfimn" +if [ $# -lt 2 ] ; then + echo -e "Usage:\n $(basename $0) [-$ALL_OPTS] input target\n" + echo -e " Sort input config file into the same order as the target\n" + echo -e " -c: insert comments about non-matching/impossible items" + echo -e " -d: show raw unsorted output with extra debug text" + echo -e " -f: force output to match what is in the target config," + echo -e " and/or remove impossible config items" + echo -e " -i: find impossible config items" + echo -e " -m: find changed config items" + echo -e " -n: do not sort output\n" + echo -e " input: source config file" ' [' "${SRC[*]#config-}" ']\n' + echo -e " target: output arch name" ' [' "${TGT1[*]%.config}" ']\n' + exit 1 +fi + +while getopts "$ALL_OPTS" OPTION ; do +case $OPTION in +c) + ADDCOMMENT=1 ;; +d) + DEBUG=1 ;; +f) + FORCE=1 ;; +i) + FIND_IMPOSS=1 ;; +m) + FIND_CHANGED=1 ;; +n) + NOSORT=1 ;; +\?) + exit 2 ;; +esac +done + +if [ "$FORCE" -a "$ADDCOMMENT" ] ; then + echo "-f and -c options cannot be used together" + exit 2 +fi + +shift $((OPTIND-1)) + +TEMPFILES="xx00 xx01 xx98 xx99" +TEMPLEFT= +for FILE in $TEMPFILES ; do + [ -f "$FILE" ] && TEMPLEFT="Y" +done +if [ "$TEMPLEFT" ] ; then + echo "WARNING! Output files named xx?? already exist." >&2 + read -p "Press to erase files, or Ctrl-C to exit..." + echo >&2 +fi +rm -f $TEMPFILES + +SRCFILE=config-$1 +[ ! -f $SRCFILE ] && echo "Input file" $SRCFILE "missing" && exit 2 + +TGTFILE=kernel-*/linux-*.noarch/configs/kernel-2.6.*-$2.config +[ ! -f $TGTFILE ] && echo "No target file matching" $TGTFILE "exists" && exit 2 + +[ "$FIND_IMPOSS" ] && \ + find kernel-*/*.noarch -name Kconfig\* -type f \ + | xargs egrep -s -h '^[[:space:]]*(menu)?config[[:space:]]+' \ + | sed -r 's/^[[:space:]]*(menu)?config[[:space:]]+/CONFIG_/' \ + | sort | uniq >xx98 + +extract_optname() { + # extract the option name from $TEXT, setting $OPTNAME + OPTNAME= + if [ "${TEXT:0:7}" = "CONFIG_" ] ; then + OPTNAME=${TEXT%%=*} + elif [ "${TEXT:0:9}" = "# CONFIG_" ] ; then + OPTNAME=${TEXT%" is not set"} + OPTNAME=${OPTNAME#\# } + fi +} + +print_saved_comments() { + if [ $IX -gt 0 ] ; then + [ "$DEBUG" ] && echo " ->" $IX "comments were saved" + (( IX-- )) + for IX in $(seq 0 $IX) ; do + echo "$LINE":"${SAVECOMMENT[$IX]}" + done + unset SAVECOMMENT + IX=0 + fi +} + +assign_line_number() { + # use input line numbers if not sorting + [ "$NOSORT" ] && LINE=$IN + # make sure it has a line number + [ -z "$LINE" ] && LINE=999999 +} + +IX=0 +IN=0 +declare -a SAVECOMMENT + +cat ${SRCFILE} | { +while read TEXT ; do + + LINE= + COMMENT= + + # replace empty lines + [ -z "$TEXT" ] && TEXT='//' + + if [ "${TEXT:0:7}" = "CONFIG_" -o "${TEXT:0:9}" = "# CONFIG_" ] ; then + + LINE=$(grep -n "^$TEXT" $TGTFILE | head -1 | cut -f 1 -d ':') + if [ -z "$LINE" ] ; then + [ "$DEBUG" ] && echo "nofind ->" "$TEXT" + + extract_optname + if [ "$OPTNAME" ] ; then + + if [ "$FIND_CHANGED" ] ; then + for FINDTEXT in "^${OPTNAME}=" "^# ${OPTNAME} is not set" ; do + if [ -z "$LINE" ] ; then + [ "$DEBUG" ] && echo "looking for ->" "$FINDTEXT" + LINE=$(grep -n "$FINDTEXT" $TGTFILE | head -1 | cut -f 1 -d ':') + if [ "$LINE" ] ; then + CHANGED=$(grep "$FINDTEXT" $TGTFILE | head -1) + if [ "$FORCE" ] ; then + TEXT=$CHANGED + [ "$DEBUG" ] && echo 'forced ->' "$TEXT" + else + if [ "$ADDCOMMENT" ] ; then + if [ ${CHANGED:0:1} = '#' ] ; then + NEWOPT="not set" + else + NEWOPT=${CHANGED#$OPTNAME} + fi + COMMENT="# -- Next option changed to \"${NEWOPT}\" at target line $LINE --" + fi + fi + fi + fi + done + fi + + if [ "$FIND_IMPOSS" -a -z "$LINE" -a -z "$COMMENT" ] ; then + POSSIBLE=$(grep -n "^$OPTNAME" xx98) + if [ -z "$POSSIBLE" ] ; then + if [ "$ADDCOMMENT" ] ; then + COMMENT="# -- Next option is impossible --" + elif [ "$FORCE" ] ; then + [ "$DEBUG" ] && echo 'impossible ->' "$TEXT" + TEXT="" + fi + fi + fi + + fi + + fi + + else + # not a config variable + COMMENT="$TEXT" + TEXT= + fi + + [ "$DEBUG" -a "$COMMENT" ] && echo "comment ->" "$LINE" "$COMMENT" + [ "$DEBUG" -a "$TEXT" ] && echo "text ->" "$LINE" "$TEXT" + + if [ "$TEXT" ] ; then + + assign_line_number + + # print the saved comments first + print_saved_comments + # now print the latest comment and text + [ "$COMMENT" ] && echo "$LINE":"$COMMENT" + echo "$LINE":"$TEXT" + + elif [ "$COMMENT" ] ; then + + # no output yet, save the comment + SAVECOMMENT[$IX]="$COMMENT" + let IX++ + [ "$DEBUG" ] && echo 'savecomment (#'${IX}')' + + fi + + let IN++ + +done +# flush the buffers +assign_line_number +print_saved_comments +[ "$DEBUG" ] && echo "$IN lines read from input" +} >xx99 + +if [ "$DEBUG" ] ; then + # just show the raw output with debug info, then exit + cat xx99 +else + + # split output into two files, for matched and unmatched items + cat xx99 | sort -s -t ":" -k 1g | csplit -k -s - /^999999/ 2>/dev/null + + cat xx00 | cut -f 2- -d ':' | sed 's/^\/\/$//' + if [ -s xx01 ] ; then + echo + echo '# ------------ UNMATCHED OPTIONS ------------' + echo + cat xx01 | cut -f 2- -d ':' | sed 's/^\/\/$//' + fi + +fi + +rm -f $TEMPFILES diff --git a/sources b/sources index e69de29bb..734a069ad 100644 --- a/sources +++ b/sources @@ -0,0 +1,3 @@ +c3883760b18d50e8d78819c54d579b00 linux-2.6.33.tar.bz2 +04b3affb4f7fb3035303a32bd6080baf patch-2.6.33.7.bz2 +422e1fc4ee7dde101435f0d8555b51a3 patch-2.6.33.7-8.bz2 diff --git a/thinkpad-acpi-add-x100e.patch b/thinkpad-acpi-add-x100e.patch new file mode 100644 index 000000000..9609ec4a6 --- /dev/null +++ b/thinkpad-acpi-add-x100e.patch @@ -0,0 +1,10 @@ +diff -up linux-2.6.33.noarch/drivers/platform/x86/thinkpad_acpi.c.mjg linux-2.6.33.noarch/drivers/platform/x86/thinkpad_acpi.c +--- linux-2.6.33.noarch/drivers/platform/x86/thinkpad_acpi.c.mjg 2010-04-21 10:05:14.125030722 -0400 ++++ linux-2.6.33.noarch/drivers/platform/x86/thinkpad_acpi.c 2010-04-21 10:05:17.732030163 -0400 +@@ -506,6 +506,7 @@ TPACPI_HANDLE(ec, root, "\\_SB.PCI0.ISA. + "\\_SB.PCI0.ISA.EC", /* A21e, A2xm/p, T20-22, X20-21 */ + "\\_SB.PCI0.AD4S.EC0", /* i1400, R30 */ + "\\_SB.PCI0.ICH3.EC0", /* R31 */ ++ "\\_SB.PCI0.LPC0.EC", /* X100e */ + "\\_SB.PCI0.LPC.EC", /* all others */ + ); diff --git a/thinkpad-acpi-fix-backlight.patch b/thinkpad-acpi-fix-backlight.patch new file mode 100644 index 000000000..3b38dc514 --- /dev/null +++ b/thinkpad-acpi-fix-backlight.patch @@ -0,0 +1,56 @@ +diff -ur linux-2.6.33.noarch.bak/drivers/platform/x86/thinkpad_acpi.c linux-2.6.33.noarch/drivers/platform/x86/thinkpad_acpi.c +--- linux-2.6.33.noarch.bak/drivers/platform/x86/thinkpad_acpi.c 2010-05-17 15:56:10.864200185 -0400 ++++ linux-2.6.33.noarch/drivers/platform/x86/thinkpad_acpi.c 2010-05-17 16:12:20.232074844 -0400 +@@ -3396,7 +3396,7 @@ + /* update bright_acpimode... */ + tpacpi_check_std_acpi_brightness_support(); + +- if (tp_features.bright_acpimode && acpi_video_backlight_support()) { ++ if (acpi_video_backlight_support()) { + printk(TPACPI_INFO + "This ThinkPad has standard ACPI backlight " + "brightness control, supported by the ACPI " +@@ -6187,26 +6187,24 @@ + * going to publish a backlight interface + */ + b = tpacpi_check_std_acpi_brightness_support(); +- if (b > 0) { + +- if (acpi_video_backlight_support()) { +- if (brightness_enable > 1) { +- printk(TPACPI_NOTICE +- "Standard ACPI backlight interface " +- "available, not loading native one.\n"); +- return 1; +- } else if (brightness_enable == 1) { +- printk(TPACPI_NOTICE +- "Backlight control force enabled, even if standard " +- "ACPI backlight interface is available\n"); +- } +- } else { +- if (brightness_enable > 1) { +- printk(TPACPI_NOTICE +- "Standard ACPI backlight interface not " +- "available, thinkpad_acpi native " +- "brightness control enabled\n"); +- } ++ if (acpi_video_backlight_support()) { ++ if (brightness_enable > 1) { ++ printk(TPACPI_NOTICE ++ "Standard ACPI backlight interface " ++ "available, not loading native one.\n"); ++ return 1; ++ } else if (brightness_enable == 1) { ++ printk(TPACPI_NOTICE ++ "Backlight control force enabled, even if standard " ++ "ACPI backlight interface is available\n"); ++ } ++ } else { ++ if (brightness_enable > 1) { ++ printk(TPACPI_NOTICE ++ "Standard ACPI backlight interface not " ++ "available, thinkpad_acpi native " ++ "brightness control enabled\n"); + } + } + diff --git a/vhost_net-rollup.patch b/vhost_net-rollup.patch new file mode 100644 index 000000000..816d6d606 --- /dev/null +++ b/vhost_net-rollup.patch @@ -0,0 +1,2542 @@ +commit fe512819010f71694384621b34ec32f8be678bbb +Author: Michael S. Tsirkin +Date: Thu Jan 14 06:17:27 2010 +0000 + + vhost_net: a kernel-level virtio server + + What it is: vhost net is a character device that can be used to reduce + the number of system calls involved in virtio networking. + Existing virtio net code is used in the guest without modification. + + There's similarity with vringfd, with some differences and reduced scope + - uses eventfd for signalling + - structures can be moved around in memory at any time (good for + migration, bug work-arounds in userspace) + - write logging is supported (good for migration) + - support memory table and not just an offset (needed for kvm) + + common virtio related code has been put in a separate file vhost.c and + can be made into a separate module if/when more backends appear. I used + Rusty's lguest.c as the source for developing this part : this supplied + me with witty comments I wouldn't be able to write myself. + + What it is not: vhost net is not a bus, and not a generic new system + call. No assumptions are made on how guest performs hypercalls. + Userspace hypervisors are supported as well as kvm. + + How it works: Basically, we connect virtio frontend (configured by + userspace) to a backend. The backend could be a network device, or a tap + device. Backend is also configured by userspace, including vlan/mac + etc. + + Status: This works for me, and I haven't see any crashes. + Compared to userspace, people reported improved latency (as I save up to + 4 system calls per packet), as well as better bandwidth and CPU + utilization. + + Features that I plan to look at in the future: + - mergeable buffers + - zero copy + - scalability tuning: figure out the best threading model to use + + Note on RCU usage (this is also documented in vhost.h, near + private_pointer which is the value protected by this variant of RCU): + what is happening is that the rcu_dereference() is being used in a + workqueue item. The role of rcu_read_lock() is taken on by the start of + execution of the workqueue item, of rcu_read_unlock() by the end of + execution of the workqueue item, and of synchronize_rcu() by + flush_workqueue()/flush_work(). In the future we might need to apply + some gcc attribute or sparse annotation to the function passed to + INIT_WORK(). Paul's ack below is for this RCU usage. + + (Includes fixes by Alan Cox , + David L Stevens , + Chris Wright ) + + Acked-by: Rusty Russell + Acked-by: Arnd Bergmann + Acked-by: "Paul E. McKenney" + Signed-off-by: Michael S. Tsirkin + Signed-off-by: David S. Miller + (cherry picked from commit 3a4d5c94e959359ece6d6b55045c3f046677f55c) + +commit 7b6a72cf7f96d5c75ce91e826372c6d488ac1e18 +Author: Michael S. Tsirkin +Date: Thu Jan 14 06:17:18 2010 +0000 + + mm: export use_mm/unuse_mm to modules + + vhost net module wants to do copy to/from user from a kernel thread, + which needs use_mm. Export it to modules. + + Acked-by: Andrea Arcangeli + Acked-by: Andrew Morton + Signed-off-by: Michael S. Tsirkin + Signed-off-by: David S. Miller + (cherry picked from commit 5da779c34ccff5e1e617892b6c8bd8260fb1f04c) + +commit 24f4237bf319b27e7c28544425e2cd52abe9332c +Author: Michael S. Tsirkin +Date: Thu Jan 14 06:17:09 2010 +0000 + + tun: export underlying socket + + Tun device looks similar to a packet socket + in that both pass complete frames from/to userspace. + + This patch fills in enough fields in the socket underlying tun driver + to support sendmsg/recvmsg operations, and message flags + MSG_TRUNC and MSG_DONTWAIT, and exports access to this socket + to modules. Regular read/write behaviour is unchanged. + + This way, code using raw sockets to inject packets + into a physical device, can support injecting + packets into host network stack almost without modification. + + First user of this interface will be vhost virtualization + accelerator. + + Signed-off-by: Michael S. Tsirkin + Acked-by: Herbert Xu + Acked-by: David S. Miller + Signed-off-by: David S. Miller + (cherry picked from commit 05c2828c72c4eabf62376adfe27bd24797621f62) + +diff --git a/MAINTAINERS b/MAINTAINERS +index 3f59162..0b4c8be 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -5795,6 +5795,15 @@ S: Maintained + F: Documentation/filesystems/vfat.txt + F: fs/fat/ + ++VIRTIO HOST (VHOST) ++M: "Michael S. Tsirkin" ++L: kvm@vger.kernel.org ++L: virtualization@lists.osdl.org ++L: netdev@vger.kernel.org ++S: Maintained ++F: drivers/vhost/ ++F: include/linux/vhost.h ++ + VIA RHINE NETWORK DRIVER + M: Roger Luethi + S: Maintained +diff --git a/arch/ia64/kvm/Kconfig b/arch/ia64/kvm/Kconfig +index ef3e7be..01c7579 100644 +--- a/arch/ia64/kvm/Kconfig ++++ b/arch/ia64/kvm/Kconfig +@@ -47,6 +47,7 @@ config KVM_INTEL + Provides support for KVM on Itanium 2 processors equipped with the VT + extensions. + ++source drivers/vhost/Kconfig + source drivers/virtio/Kconfig + + endif # VIRTUALIZATION +diff --git a/arch/powerpc/kvm/Kconfig b/arch/powerpc/kvm/Kconfig +index 07703f7..e28841f 100644 +--- a/arch/powerpc/kvm/Kconfig ++++ b/arch/powerpc/kvm/Kconfig +@@ -75,6 +75,7 @@ config KVM_E500 + + If unsure, say N. + ++source drivers/vhost/Kconfig + source drivers/virtio/Kconfig + + endif # VIRTUALIZATION +diff --git a/arch/s390/kvm/Kconfig b/arch/s390/kvm/Kconfig +index 6ee55ae..a725158 100644 +--- a/arch/s390/kvm/Kconfig ++++ b/arch/s390/kvm/Kconfig +@@ -35,6 +35,7 @@ config KVM + + # OK, it's a little counter-intuitive to do this, but it puts it neatly under + # the virtualization menu. ++source drivers/vhost/Kconfig + source drivers/virtio/Kconfig + + endif # VIRTUALIZATION +diff --git a/arch/x86/kvm/Kconfig b/arch/x86/kvm/Kconfig +index 4cd4983..3c4d010 100644 +--- a/arch/x86/kvm/Kconfig ++++ b/arch/x86/kvm/Kconfig +@@ -65,6 +65,7 @@ config KVM_AMD + + # OK, it's a little counter-intuitive to do this, but it puts it neatly under + # the virtualization menu. ++source drivers/vhost/Kconfig + source drivers/lguest/Kconfig + source drivers/virtio/Kconfig + +diff --git a/drivers/Makefile b/drivers/Makefile +index 6ee53c7..81e3659 100644 +--- a/drivers/Makefile ++++ b/drivers/Makefile +@@ -106,6 +106,7 @@ obj-$(CONFIG_HID) += hid/ + obj-$(CONFIG_PPC_PS3) += ps3/ + obj-$(CONFIG_OF) += of/ + obj-$(CONFIG_SSB) += ssb/ ++obj-$(CONFIG_VHOST_NET) += vhost/ + obj-$(CONFIG_VLYNQ) += vlynq/ + obj-$(CONFIG_STAGING) += staging/ + obj-y += platform/ +diff --git a/drivers/net/tun.c b/drivers/net/tun.c +index 2834a01..5adb3d1 100644 +--- a/drivers/net/tun.c ++++ b/drivers/net/tun.c +@@ -144,6 +144,7 @@ static int tun_attach(struct tun_struct *tun, struct file *file) + err = 0; + tfile->tun = tun; + tun->tfile = tfile; ++ tun->socket.file = file; + dev_hold(tun->dev); + sock_hold(tun->socket.sk); + atomic_inc(&tfile->count); +@@ -158,6 +159,7 @@ static void __tun_detach(struct tun_struct *tun) + /* Detach from net device */ + netif_tx_lock_bh(tun->dev); + tun->tfile = NULL; ++ tun->socket.file = NULL; + netif_tx_unlock_bh(tun->dev); + + /* Drop read queue */ +@@ -387,7 +389,8 @@ static netdev_tx_t tun_net_xmit(struct sk_buff *skb, struct net_device *dev) + /* Notify and wake up reader process */ + if (tun->flags & TUN_FASYNC) + kill_fasync(&tun->fasync, SIGIO, POLL_IN); +- wake_up_interruptible(&tun->socket.wait); ++ wake_up_interruptible_poll(&tun->socket.wait, POLLIN | ++ POLLRDNORM | POLLRDBAND); + return NETDEV_TX_OK; + + drop: +@@ -743,7 +746,7 @@ static __inline__ ssize_t tun_put_user(struct tun_struct *tun, + len = min_t(int, skb->len, len); + + skb_copy_datagram_const_iovec(skb, 0, iv, total, len); +- total += len; ++ total += skb->len; + + tun->dev->stats.tx_packets++; + tun->dev->stats.tx_bytes += len; +@@ -751,34 +754,23 @@ static __inline__ ssize_t tun_put_user(struct tun_struct *tun, + return total; + } + +-static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv, +- unsigned long count, loff_t pos) ++static ssize_t tun_do_read(struct tun_struct *tun, ++ struct kiocb *iocb, const struct iovec *iv, ++ ssize_t len, int noblock) + { +- struct file *file = iocb->ki_filp; +- struct tun_file *tfile = file->private_data; +- struct tun_struct *tun = __tun_get(tfile); + DECLARE_WAITQUEUE(wait, current); + struct sk_buff *skb; +- ssize_t len, ret = 0; +- +- if (!tun) +- return -EBADFD; ++ ssize_t ret = 0; + + DBG(KERN_INFO "%s: tun_chr_read\n", tun->dev->name); + +- len = iov_length(iv, count); +- if (len < 0) { +- ret = -EINVAL; +- goto out; +- } +- + add_wait_queue(&tun->socket.wait, &wait); + while (len) { + current->state = TASK_INTERRUPTIBLE; + + /* Read frames from the queue */ + if (!(skb=skb_dequeue(&tun->socket.sk->sk_receive_queue))) { +- if (file->f_flags & O_NONBLOCK) { ++ if (noblock) { + ret = -EAGAIN; + break; + } +@@ -805,6 +797,27 @@ static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv, + current->state = TASK_RUNNING; + remove_wait_queue(&tun->socket.wait, &wait); + ++ return ret; ++} ++ ++static ssize_t tun_chr_aio_read(struct kiocb *iocb, const struct iovec *iv, ++ unsigned long count, loff_t pos) ++{ ++ struct file *file = iocb->ki_filp; ++ struct tun_file *tfile = file->private_data; ++ struct tun_struct *tun = __tun_get(tfile); ++ ssize_t len, ret; ++ ++ if (!tun) ++ return -EBADFD; ++ len = iov_length(iv, count); ++ if (len < 0) { ++ ret = -EINVAL; ++ goto out; ++ } ++ ++ ret = tun_do_read(tun, iocb, iv, len, file->f_flags & O_NONBLOCK); ++ ret = min_t(ssize_t, ret, len); + out: + tun_put(tun); + return ret; +@@ -847,7 +860,8 @@ static void tun_sock_write_space(struct sock *sk) + return; + + if (sk->sk_sleep && waitqueue_active(sk->sk_sleep)) +- wake_up_interruptible_sync(sk->sk_sleep); ++ wake_up_interruptible_sync_poll(sk->sk_sleep, POLLOUT | ++ POLLWRNORM | POLLWRBAND); + + tun = tun_sk(sk)->tun; + kill_fasync(&tun->fasync, SIGIO, POLL_OUT); +@@ -858,6 +872,37 @@ static void tun_sock_destruct(struct sock *sk) + free_netdev(tun_sk(sk)->tun->dev); + } + ++static int tun_sendmsg(struct kiocb *iocb, struct socket *sock, ++ struct msghdr *m, size_t total_len) ++{ ++ struct tun_struct *tun = container_of(sock, struct tun_struct, socket); ++ return tun_get_user(tun, m->msg_iov, total_len, ++ m->msg_flags & MSG_DONTWAIT); ++} ++ ++static int tun_recvmsg(struct kiocb *iocb, struct socket *sock, ++ struct msghdr *m, size_t total_len, ++ int flags) ++{ ++ struct tun_struct *tun = container_of(sock, struct tun_struct, socket); ++ int ret; ++ if (flags & ~(MSG_DONTWAIT|MSG_TRUNC)) ++ return -EINVAL; ++ ret = tun_do_read(tun, iocb, m->msg_iov, total_len, ++ flags & MSG_DONTWAIT); ++ if (ret > total_len) { ++ m->msg_flags |= MSG_TRUNC; ++ ret = flags & MSG_TRUNC ? ret : total_len; ++ } ++ return ret; ++} ++ ++/* Ops structure to mimic raw sockets with tun */ ++static const struct proto_ops tun_socket_ops = { ++ .sendmsg = tun_sendmsg, ++ .recvmsg = tun_recvmsg, ++}; ++ + static struct proto tun_proto = { + .name = "tun", + .owner = THIS_MODULE, +@@ -986,6 +1031,7 @@ static int tun_set_iff(struct net *net, struct file *file, struct ifreq *ifr) + goto err_free_dev; + + init_waitqueue_head(&tun->socket.wait); ++ tun->socket.ops = &tun_socket_ops; + sock_init_data(&tun->socket, sk); + sk->sk_write_space = tun_sock_write_space; + sk->sk_sndbuf = INT_MAX; +@@ -1525,6 +1571,23 @@ static void tun_cleanup(void) + rtnl_link_unregister(&tun_link_ops); + } + ++/* Get an underlying socket object from tun file. Returns error unless file is ++ * attached to a device. The returned object works like a packet socket, it ++ * can be used for sock_sendmsg/sock_recvmsg. The caller is responsible for ++ * holding a reference to the file for as long as the socket is in use. */ ++struct socket *tun_get_socket(struct file *file) ++{ ++ struct tun_struct *tun; ++ if (file->f_op != &tun_fops) ++ return ERR_PTR(-EINVAL); ++ tun = tun_get(file); ++ if (!tun) ++ return ERR_PTR(-EBADFD); ++ tun_put(tun); ++ return &tun->socket; ++} ++EXPORT_SYMBOL_GPL(tun_get_socket); ++ + module_init(tun_init); + module_exit(tun_cleanup); + MODULE_DESCRIPTION(DRV_DESCRIPTION); +diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig +new file mode 100644 +index 0000000..9f409f4 +--- /dev/null ++++ b/drivers/vhost/Kconfig +@@ -0,0 +1,11 @@ ++config VHOST_NET ++ tristate "Host kernel accelerator for virtio net (EXPERIMENTAL)" ++ depends on NET && EVENTFD && EXPERIMENTAL ++ ---help--- ++ This kernel module can be loaded in host kernel to accelerate ++ guest networking with virtio_net. Not to be confused with virtio_net ++ module itself which needs to be loaded in guest kernel. ++ ++ To compile this driver as a module, choose M here: the module will ++ be called vhost_net. ++ +diff --git a/drivers/vhost/Makefile b/drivers/vhost/Makefile +new file mode 100644 +index 0000000..72dd020 +--- /dev/null ++++ b/drivers/vhost/Makefile +@@ -0,0 +1,2 @@ ++obj-$(CONFIG_VHOST_NET) += vhost_net.o ++vhost_net-y := vhost.o net.o +diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c +new file mode 100644 +index 0000000..4c89283 +--- /dev/null ++++ b/drivers/vhost/net.c +@@ -0,0 +1,661 @@ ++/* Copyright (C) 2009 Red Hat, Inc. ++ * Author: Michael S. Tsirkin ++ * ++ * This work is licensed under the terms of the GNU GPL, version 2. ++ * ++ * virtio-net server in host kernel. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++#include ++ ++#include ++ ++#include "vhost.h" ++ ++/* Max number of bytes transferred before requeueing the job. ++ * Using this limit prevents one virtqueue from starving others. */ ++#define VHOST_NET_WEIGHT 0x80000 ++ ++enum { ++ VHOST_NET_VQ_RX = 0, ++ VHOST_NET_VQ_TX = 1, ++ VHOST_NET_VQ_MAX = 2, ++}; ++ ++enum vhost_net_poll_state { ++ VHOST_NET_POLL_DISABLED = 0, ++ VHOST_NET_POLL_STARTED = 1, ++ VHOST_NET_POLL_STOPPED = 2, ++}; ++ ++struct vhost_net { ++ struct vhost_dev dev; ++ struct vhost_virtqueue vqs[VHOST_NET_VQ_MAX]; ++ struct vhost_poll poll[VHOST_NET_VQ_MAX]; ++ /* Tells us whether we are polling a socket for TX. ++ * We only do this when socket buffer fills up. ++ * Protected by tx vq lock. */ ++ enum vhost_net_poll_state tx_poll_state; ++}; ++ ++/* Pop first len bytes from iovec. Return number of segments used. */ ++static int move_iovec_hdr(struct iovec *from, struct iovec *to, ++ size_t len, int iov_count) ++{ ++ int seg = 0; ++ size_t size; ++ while (len && seg < iov_count) { ++ size = min(from->iov_len, len); ++ to->iov_base = from->iov_base; ++ to->iov_len = size; ++ from->iov_len -= size; ++ from->iov_base += size; ++ len -= size; ++ ++from; ++ ++to; ++ ++seg; ++ } ++ return seg; ++} ++ ++/* Caller must have TX VQ lock */ ++static void tx_poll_stop(struct vhost_net *net) ++{ ++ if (likely(net->tx_poll_state != VHOST_NET_POLL_STARTED)) ++ return; ++ vhost_poll_stop(net->poll + VHOST_NET_VQ_TX); ++ net->tx_poll_state = VHOST_NET_POLL_STOPPED; ++} ++ ++/* Caller must have TX VQ lock */ ++static void tx_poll_start(struct vhost_net *net, struct socket *sock) ++{ ++ if (unlikely(net->tx_poll_state != VHOST_NET_POLL_STOPPED)) ++ return; ++ vhost_poll_start(net->poll + VHOST_NET_VQ_TX, sock->file); ++ net->tx_poll_state = VHOST_NET_POLL_STARTED; ++} ++ ++/* Expects to be always run from workqueue - which acts as ++ * read-size critical section for our kind of RCU. */ ++static void handle_tx(struct vhost_net *net) ++{ ++ struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_TX]; ++ unsigned head, out, in, s; ++ struct msghdr msg = { ++ .msg_name = NULL, ++ .msg_namelen = 0, ++ .msg_control = NULL, ++ .msg_controllen = 0, ++ .msg_iov = vq->iov, ++ .msg_flags = MSG_DONTWAIT, ++ }; ++ size_t len, total_len = 0; ++ int err, wmem; ++ size_t hdr_size; ++ struct socket *sock = rcu_dereference(vq->private_data); ++ if (!sock) ++ return; ++ ++ wmem = atomic_read(&sock->sk->sk_wmem_alloc); ++ if (wmem >= sock->sk->sk_sndbuf) ++ return; ++ ++ use_mm(net->dev.mm); ++ mutex_lock(&vq->mutex); ++ vhost_disable_notify(vq); ++ ++ if (wmem < sock->sk->sk_sndbuf * 2) ++ tx_poll_stop(net); ++ hdr_size = vq->hdr_size; ++ ++ for (;;) { ++ head = vhost_get_vq_desc(&net->dev, vq, vq->iov, ++ ARRAY_SIZE(vq->iov), ++ &out, &in, ++ NULL, NULL); ++ /* Nothing new? Wait for eventfd to tell us they refilled. */ ++ if (head == vq->num) { ++ wmem = atomic_read(&sock->sk->sk_wmem_alloc); ++ if (wmem >= sock->sk->sk_sndbuf * 3 / 4) { ++ tx_poll_start(net, sock); ++ set_bit(SOCK_ASYNC_NOSPACE, &sock->flags); ++ break; ++ } ++ if (unlikely(vhost_enable_notify(vq))) { ++ vhost_disable_notify(vq); ++ continue; ++ } ++ break; ++ } ++ if (in) { ++ vq_err(vq, "Unexpected descriptor format for TX: " ++ "out %d, int %d\n", out, in); ++ break; ++ } ++ /* Skip header. TODO: support TSO. */ ++ s = move_iovec_hdr(vq->iov, vq->hdr, hdr_size, out); ++ msg.msg_iovlen = out; ++ len = iov_length(vq->iov, out); ++ /* Sanity check */ ++ if (!len) { ++ vq_err(vq, "Unexpected header len for TX: " ++ "%zd expected %zd\n", ++ iov_length(vq->hdr, s), hdr_size); ++ break; ++ } ++ /* TODO: Check specific error and bomb out unless ENOBUFS? */ ++ err = sock->ops->sendmsg(NULL, sock, &msg, len); ++ if (unlikely(err < 0)) { ++ vhost_discard_vq_desc(vq); ++ tx_poll_start(net, sock); ++ break; ++ } ++ if (err != len) ++ pr_err("Truncated TX packet: " ++ " len %d != %zd\n", err, len); ++ vhost_add_used_and_signal(&net->dev, vq, head, 0); ++ total_len += len; ++ if (unlikely(total_len >= VHOST_NET_WEIGHT)) { ++ vhost_poll_queue(&vq->poll); ++ break; ++ } ++ } ++ ++ mutex_unlock(&vq->mutex); ++ unuse_mm(net->dev.mm); ++} ++ ++/* Expects to be always run from workqueue - which acts as ++ * read-size critical section for our kind of RCU. */ ++static void handle_rx(struct vhost_net *net) ++{ ++ struct vhost_virtqueue *vq = &net->dev.vqs[VHOST_NET_VQ_RX]; ++ unsigned head, out, in, log, s; ++ struct vhost_log *vq_log; ++ struct msghdr msg = { ++ .msg_name = NULL, ++ .msg_namelen = 0, ++ .msg_control = NULL, /* FIXME: get and handle RX aux data. */ ++ .msg_controllen = 0, ++ .msg_iov = vq->iov, ++ .msg_flags = MSG_DONTWAIT, ++ }; ++ ++ struct virtio_net_hdr hdr = { ++ .flags = 0, ++ .gso_type = VIRTIO_NET_HDR_GSO_NONE ++ }; ++ ++ size_t len, total_len = 0; ++ int err; ++ size_t hdr_size; ++ struct socket *sock = rcu_dereference(vq->private_data); ++ if (!sock || skb_queue_empty(&sock->sk->sk_receive_queue)) ++ return; ++ ++ use_mm(net->dev.mm); ++ mutex_lock(&vq->mutex); ++ vhost_disable_notify(vq); ++ hdr_size = vq->hdr_size; ++ ++ vq_log = unlikely(vhost_has_feature(&net->dev, VHOST_F_LOG_ALL)) ? ++ vq->log : NULL; ++ ++ for (;;) { ++ head = vhost_get_vq_desc(&net->dev, vq, vq->iov, ++ ARRAY_SIZE(vq->iov), ++ &out, &in, ++ vq_log, &log); ++ /* OK, now we need to know about added descriptors. */ ++ if (head == vq->num) { ++ if (unlikely(vhost_enable_notify(vq))) { ++ /* They have slipped one in as we were ++ * doing that: check again. */ ++ vhost_disable_notify(vq); ++ continue; ++ } ++ /* Nothing new? Wait for eventfd to tell us ++ * they refilled. */ ++ break; ++ } ++ /* We don't need to be notified again. */ ++ if (out) { ++ vq_err(vq, "Unexpected descriptor format for RX: " ++ "out %d, int %d\n", ++ out, in); ++ break; ++ } ++ /* Skip header. TODO: support TSO/mergeable rx buffers. */ ++ s = move_iovec_hdr(vq->iov, vq->hdr, hdr_size, in); ++ msg.msg_iovlen = in; ++ len = iov_length(vq->iov, in); ++ /* Sanity check */ ++ if (!len) { ++ vq_err(vq, "Unexpected header len for RX: " ++ "%zd expected %zd\n", ++ iov_length(vq->hdr, s), hdr_size); ++ break; ++ } ++ err = sock->ops->recvmsg(NULL, sock, &msg, ++ len, MSG_DONTWAIT | MSG_TRUNC); ++ /* TODO: Check specific error and bomb out unless EAGAIN? */ ++ if (err < 0) { ++ vhost_discard_vq_desc(vq); ++ break; ++ } ++ /* TODO: Should check and handle checksum. */ ++ if (err > len) { ++ pr_err("Discarded truncated rx packet: " ++ " len %d > %zd\n", err, len); ++ vhost_discard_vq_desc(vq); ++ continue; ++ } ++ len = err; ++ err = memcpy_toiovec(vq->hdr, (unsigned char *)&hdr, hdr_size); ++ if (err) { ++ vq_err(vq, "Unable to write vnet_hdr at addr %p: %d\n", ++ vq->iov->iov_base, err); ++ break; ++ } ++ len += hdr_size; ++ vhost_add_used_and_signal(&net->dev, vq, head, len); ++ if (unlikely(vq_log)) ++ vhost_log_write(vq, vq_log, log, len); ++ total_len += len; ++ if (unlikely(total_len >= VHOST_NET_WEIGHT)) { ++ vhost_poll_queue(&vq->poll); ++ break; ++ } ++ } ++ ++ mutex_unlock(&vq->mutex); ++ unuse_mm(net->dev.mm); ++} ++ ++static void handle_tx_kick(struct work_struct *work) ++{ ++ struct vhost_virtqueue *vq; ++ struct vhost_net *net; ++ vq = container_of(work, struct vhost_virtqueue, poll.work); ++ net = container_of(vq->dev, struct vhost_net, dev); ++ handle_tx(net); ++} ++ ++static void handle_rx_kick(struct work_struct *work) ++{ ++ struct vhost_virtqueue *vq; ++ struct vhost_net *net; ++ vq = container_of(work, struct vhost_virtqueue, poll.work); ++ net = container_of(vq->dev, struct vhost_net, dev); ++ handle_rx(net); ++} ++ ++static void handle_tx_net(struct work_struct *work) ++{ ++ struct vhost_net *net; ++ net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_TX].work); ++ handle_tx(net); ++} ++ ++static void handle_rx_net(struct work_struct *work) ++{ ++ struct vhost_net *net; ++ net = container_of(work, struct vhost_net, poll[VHOST_NET_VQ_RX].work); ++ handle_rx(net); ++} ++ ++static int vhost_net_open(struct inode *inode, struct file *f) ++{ ++ struct vhost_net *n = kmalloc(sizeof *n, GFP_KERNEL); ++ int r; ++ if (!n) ++ return -ENOMEM; ++ n->vqs[VHOST_NET_VQ_TX].handle_kick = handle_tx_kick; ++ n->vqs[VHOST_NET_VQ_RX].handle_kick = handle_rx_kick; ++ r = vhost_dev_init(&n->dev, n->vqs, VHOST_NET_VQ_MAX); ++ if (r < 0) { ++ kfree(n); ++ return r; ++ } ++ ++ vhost_poll_init(n->poll + VHOST_NET_VQ_TX, handle_tx_net, POLLOUT); ++ vhost_poll_init(n->poll + VHOST_NET_VQ_RX, handle_rx_net, POLLIN); ++ n->tx_poll_state = VHOST_NET_POLL_DISABLED; ++ ++ f->private_data = n; ++ ++ return 0; ++} ++ ++static void vhost_net_disable_vq(struct vhost_net *n, ++ struct vhost_virtqueue *vq) ++{ ++ if (!vq->private_data) ++ return; ++ if (vq == n->vqs + VHOST_NET_VQ_TX) { ++ tx_poll_stop(n); ++ n->tx_poll_state = VHOST_NET_POLL_DISABLED; ++ } else ++ vhost_poll_stop(n->poll + VHOST_NET_VQ_RX); ++} ++ ++static void vhost_net_enable_vq(struct vhost_net *n, ++ struct vhost_virtqueue *vq) ++{ ++ struct socket *sock = vq->private_data; ++ if (!sock) ++ return; ++ if (vq == n->vqs + VHOST_NET_VQ_TX) { ++ n->tx_poll_state = VHOST_NET_POLL_STOPPED; ++ tx_poll_start(n, sock); ++ } else ++ vhost_poll_start(n->poll + VHOST_NET_VQ_RX, sock->file); ++} ++ ++static struct socket *vhost_net_stop_vq(struct vhost_net *n, ++ struct vhost_virtqueue *vq) ++{ ++ struct socket *sock; ++ ++ mutex_lock(&vq->mutex); ++ sock = vq->private_data; ++ vhost_net_disable_vq(n, vq); ++ rcu_assign_pointer(vq->private_data, NULL); ++ mutex_unlock(&vq->mutex); ++ return sock; ++} ++ ++static void vhost_net_stop(struct vhost_net *n, struct socket **tx_sock, ++ struct socket **rx_sock) ++{ ++ *tx_sock = vhost_net_stop_vq(n, n->vqs + VHOST_NET_VQ_TX); ++ *rx_sock = vhost_net_stop_vq(n, n->vqs + VHOST_NET_VQ_RX); ++} ++ ++static void vhost_net_flush_vq(struct vhost_net *n, int index) ++{ ++ vhost_poll_flush(n->poll + index); ++ vhost_poll_flush(&n->dev.vqs[index].poll); ++} ++ ++static void vhost_net_flush(struct vhost_net *n) ++{ ++ vhost_net_flush_vq(n, VHOST_NET_VQ_TX); ++ vhost_net_flush_vq(n, VHOST_NET_VQ_RX); ++} ++ ++static int vhost_net_release(struct inode *inode, struct file *f) ++{ ++ struct vhost_net *n = f->private_data; ++ struct socket *tx_sock; ++ struct socket *rx_sock; ++ ++ vhost_net_stop(n, &tx_sock, &rx_sock); ++ vhost_net_flush(n); ++ vhost_dev_cleanup(&n->dev); ++ if (tx_sock) ++ fput(tx_sock->file); ++ if (rx_sock) ++ fput(rx_sock->file); ++ /* We do an extra flush before freeing memory, ++ * since jobs can re-queue themselves. */ ++ vhost_net_flush(n); ++ kfree(n); ++ return 0; ++} ++ ++static struct socket *get_raw_socket(int fd) ++{ ++ struct { ++ struct sockaddr_ll sa; ++ char buf[MAX_ADDR_LEN]; ++ } uaddr; ++ int uaddr_len = sizeof uaddr, r; ++ struct socket *sock = sockfd_lookup(fd, &r); ++ if (!sock) ++ return ERR_PTR(-ENOTSOCK); ++ ++ /* Parameter checking */ ++ if (sock->sk->sk_type != SOCK_RAW) { ++ r = -ESOCKTNOSUPPORT; ++ goto err; ++ } ++ ++ r = sock->ops->getname(sock, (struct sockaddr *)&uaddr.sa, ++ &uaddr_len, 0); ++ if (r) ++ goto err; ++ ++ if (uaddr.sa.sll_family != AF_PACKET) { ++ r = -EPFNOSUPPORT; ++ goto err; ++ } ++ return sock; ++err: ++ fput(sock->file); ++ return ERR_PTR(r); ++} ++ ++static struct socket *get_tun_socket(int fd) ++{ ++ struct file *file = fget(fd); ++ struct socket *sock; ++ if (!file) ++ return ERR_PTR(-EBADF); ++ sock = tun_get_socket(file); ++ if (IS_ERR(sock)) ++ fput(file); ++ return sock; ++} ++ ++static struct socket *get_socket(int fd) ++{ ++ struct socket *sock; ++ /* special case to disable backend */ ++ if (fd == -1) ++ return NULL; ++ sock = get_raw_socket(fd); ++ if (!IS_ERR(sock)) ++ return sock; ++ sock = get_tun_socket(fd); ++ if (!IS_ERR(sock)) ++ return sock; ++ return ERR_PTR(-ENOTSOCK); ++} ++ ++static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd) ++{ ++ struct socket *sock, *oldsock; ++ struct vhost_virtqueue *vq; ++ int r; ++ ++ mutex_lock(&n->dev.mutex); ++ r = vhost_dev_check_owner(&n->dev); ++ if (r) ++ goto err; ++ ++ if (index >= VHOST_NET_VQ_MAX) { ++ r = -ENOBUFS; ++ goto err; ++ } ++ vq = n->vqs + index; ++ mutex_lock(&vq->mutex); ++ ++ /* Verify that ring has been setup correctly. */ ++ if (!vhost_vq_access_ok(vq)) { ++ r = -EFAULT; ++ goto err; ++ } ++ sock = get_socket(fd); ++ if (IS_ERR(sock)) { ++ r = PTR_ERR(sock); ++ goto err; ++ } ++ ++ /* start polling new socket */ ++ oldsock = vq->private_data; ++ if (sock == oldsock) ++ goto done; ++ ++ vhost_net_disable_vq(n, vq); ++ rcu_assign_pointer(vq->private_data, sock); ++ vhost_net_enable_vq(n, vq); ++ mutex_unlock(&vq->mutex); ++done: ++ if (oldsock) { ++ vhost_net_flush_vq(n, index); ++ fput(oldsock->file); ++ } ++err: ++ mutex_unlock(&n->dev.mutex); ++ return r; ++} ++ ++static long vhost_net_reset_owner(struct vhost_net *n) ++{ ++ struct socket *tx_sock = NULL; ++ struct socket *rx_sock = NULL; ++ long err; ++ mutex_lock(&n->dev.mutex); ++ err = vhost_dev_check_owner(&n->dev); ++ if (err) ++ goto done; ++ vhost_net_stop(n, &tx_sock, &rx_sock); ++ vhost_net_flush(n); ++ err = vhost_dev_reset_owner(&n->dev); ++done: ++ mutex_unlock(&n->dev.mutex); ++ if (tx_sock) ++ fput(tx_sock->file); ++ if (rx_sock) ++ fput(rx_sock->file); ++ return err; ++} ++ ++static int vhost_net_set_features(struct vhost_net *n, u64 features) ++{ ++ size_t hdr_size = features & (1 << VHOST_NET_F_VIRTIO_NET_HDR) ? ++ sizeof(struct virtio_net_hdr) : 0; ++ int i; ++ mutex_lock(&n->dev.mutex); ++ if ((features & (1 << VHOST_F_LOG_ALL)) && ++ !vhost_log_access_ok(&n->dev)) { ++ mutex_unlock(&n->dev.mutex); ++ return -EFAULT; ++ } ++ n->dev.acked_features = features; ++ smp_wmb(); ++ for (i = 0; i < VHOST_NET_VQ_MAX; ++i) { ++ mutex_lock(&n->vqs[i].mutex); ++ n->vqs[i].hdr_size = hdr_size; ++ mutex_unlock(&n->vqs[i].mutex); ++ } ++ vhost_net_flush(n); ++ mutex_unlock(&n->dev.mutex); ++ return 0; ++} ++ ++static long vhost_net_ioctl(struct file *f, unsigned int ioctl, ++ unsigned long arg) ++{ ++ struct vhost_net *n = f->private_data; ++ void __user *argp = (void __user *)arg; ++ u64 __user *featurep = argp; ++ struct vhost_vring_file backend; ++ u64 features; ++ int r; ++ switch (ioctl) { ++ case VHOST_NET_SET_BACKEND: ++ r = copy_from_user(&backend, argp, sizeof backend); ++ if (r < 0) ++ return r; ++ return vhost_net_set_backend(n, backend.index, backend.fd); ++ case VHOST_GET_FEATURES: ++ features = VHOST_FEATURES; ++ return copy_to_user(featurep, &features, sizeof features); ++ case VHOST_SET_FEATURES: ++ r = copy_from_user(&features, featurep, sizeof features); ++ if (r < 0) ++ return r; ++ if (features & ~VHOST_FEATURES) ++ return -EOPNOTSUPP; ++ return vhost_net_set_features(n, features); ++ case VHOST_RESET_OWNER: ++ return vhost_net_reset_owner(n); ++ default: ++ mutex_lock(&n->dev.mutex); ++ r = vhost_dev_ioctl(&n->dev, ioctl, arg); ++ vhost_net_flush(n); ++ mutex_unlock(&n->dev.mutex); ++ return r; ++ } ++} ++ ++#ifdef CONFIG_COMPAT ++static long vhost_net_compat_ioctl(struct file *f, unsigned int ioctl, ++ unsigned long arg) ++{ ++ return vhost_net_ioctl(f, ioctl, (unsigned long)compat_ptr(arg)); ++} ++#endif ++ ++const static struct file_operations vhost_net_fops = { ++ .owner = THIS_MODULE, ++ .release = vhost_net_release, ++ .unlocked_ioctl = vhost_net_ioctl, ++#ifdef CONFIG_COMPAT ++ .compat_ioctl = vhost_net_compat_ioctl, ++#endif ++ .open = vhost_net_open, ++}; ++ ++static struct miscdevice vhost_net_misc = { ++ VHOST_NET_MINOR, ++ "vhost-net", ++ &vhost_net_fops, ++}; ++ ++int vhost_net_init(void) ++{ ++ int r = vhost_init(); ++ if (r) ++ goto err_init; ++ r = misc_register(&vhost_net_misc); ++ if (r) ++ goto err_reg; ++ return 0; ++err_reg: ++ vhost_cleanup(); ++err_init: ++ return r; ++ ++} ++module_init(vhost_net_init); ++ ++void vhost_net_exit(void) ++{ ++ misc_deregister(&vhost_net_misc); ++ vhost_cleanup(); ++} ++module_exit(vhost_net_exit); ++ ++MODULE_VERSION("0.0.1"); ++MODULE_LICENSE("GPL v2"); ++MODULE_AUTHOR("Michael S. Tsirkin"); ++MODULE_DESCRIPTION("Host kernel accelerator for virtio net"); +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +new file mode 100644 +index 0000000..c8c25db +--- /dev/null ++++ b/drivers/vhost/vhost.c +@@ -0,0 +1,1098 @@ ++/* Copyright (C) 2009 Red Hat, Inc. ++ * Copyright (C) 2006 Rusty Russell IBM Corporation ++ * ++ * Author: Michael S. Tsirkin ++ * ++ * Inspiration, some code, and most witty comments come from ++ * Documentation/lguest/lguest.c, by Rusty Russell ++ * ++ * This work is licensed under the terms of the GNU GPL, version 2. ++ * ++ * Generic code for virtio server in host kernel. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++#include ++#include ++#include ++ ++#include ++ ++#include "vhost.h" ++ ++enum { ++ VHOST_MEMORY_MAX_NREGIONS = 64, ++ VHOST_MEMORY_F_LOG = 0x1, ++}; ++ ++static struct workqueue_struct *vhost_workqueue; ++ ++static void vhost_poll_func(struct file *file, wait_queue_head_t *wqh, ++ poll_table *pt) ++{ ++ struct vhost_poll *poll; ++ poll = container_of(pt, struct vhost_poll, table); ++ ++ poll->wqh = wqh; ++ add_wait_queue(wqh, &poll->wait); ++} ++ ++static int vhost_poll_wakeup(wait_queue_t *wait, unsigned mode, int sync, ++ void *key) ++{ ++ struct vhost_poll *poll; ++ poll = container_of(wait, struct vhost_poll, wait); ++ if (!((unsigned long)key & poll->mask)) ++ return 0; ++ ++ queue_work(vhost_workqueue, &poll->work); ++ return 0; ++} ++ ++/* Init poll structure */ ++void vhost_poll_init(struct vhost_poll *poll, work_func_t func, ++ unsigned long mask) ++{ ++ INIT_WORK(&poll->work, func); ++ init_waitqueue_func_entry(&poll->wait, vhost_poll_wakeup); ++ init_poll_funcptr(&poll->table, vhost_poll_func); ++ poll->mask = mask; ++} ++ ++/* Start polling a file. We add ourselves to file's wait queue. The caller must ++ * keep a reference to a file until after vhost_poll_stop is called. */ ++void vhost_poll_start(struct vhost_poll *poll, struct file *file) ++{ ++ unsigned long mask; ++ mask = file->f_op->poll(file, &poll->table); ++ if (mask) ++ vhost_poll_wakeup(&poll->wait, 0, 0, (void *)mask); ++} ++ ++/* Stop polling a file. After this function returns, it becomes safe to drop the ++ * file reference. You must also flush afterwards. */ ++void vhost_poll_stop(struct vhost_poll *poll) ++{ ++ remove_wait_queue(poll->wqh, &poll->wait); ++} ++ ++/* Flush any work that has been scheduled. When calling this, don't hold any ++ * locks that are also used by the callback. */ ++void vhost_poll_flush(struct vhost_poll *poll) ++{ ++ flush_work(&poll->work); ++} ++ ++void vhost_poll_queue(struct vhost_poll *poll) ++{ ++ queue_work(vhost_workqueue, &poll->work); ++} ++ ++static void vhost_vq_reset(struct vhost_dev *dev, ++ struct vhost_virtqueue *vq) ++{ ++ vq->num = 1; ++ vq->desc = NULL; ++ vq->avail = NULL; ++ vq->used = NULL; ++ vq->last_avail_idx = 0; ++ vq->avail_idx = 0; ++ vq->last_used_idx = 0; ++ vq->used_flags = 0; ++ vq->used_flags = 0; ++ vq->log_used = false; ++ vq->log_addr = -1ull; ++ vq->hdr_size = 0; ++ vq->private_data = NULL; ++ vq->log_base = NULL; ++ vq->error_ctx = NULL; ++ vq->error = NULL; ++ vq->kick = NULL; ++ vq->call_ctx = NULL; ++ vq->call = NULL; ++} ++ ++long vhost_dev_init(struct vhost_dev *dev, ++ struct vhost_virtqueue *vqs, int nvqs) ++{ ++ int i; ++ dev->vqs = vqs; ++ dev->nvqs = nvqs; ++ mutex_init(&dev->mutex); ++ dev->log_ctx = NULL; ++ dev->log_file = NULL; ++ dev->memory = NULL; ++ dev->mm = NULL; ++ ++ for (i = 0; i < dev->nvqs; ++i) { ++ dev->vqs[i].dev = dev; ++ mutex_init(&dev->vqs[i].mutex); ++ vhost_vq_reset(dev, dev->vqs + i); ++ if (dev->vqs[i].handle_kick) ++ vhost_poll_init(&dev->vqs[i].poll, ++ dev->vqs[i].handle_kick, ++ POLLIN); ++ } ++ return 0; ++} ++ ++/* Caller should have device mutex */ ++long vhost_dev_check_owner(struct vhost_dev *dev) ++{ ++ /* Are you the owner? If not, I don't think you mean to do that */ ++ return dev->mm == current->mm ? 0 : -EPERM; ++} ++ ++/* Caller should have device mutex */ ++static long vhost_dev_set_owner(struct vhost_dev *dev) ++{ ++ /* Is there an owner already? */ ++ if (dev->mm) ++ return -EBUSY; ++ /* No owner, become one */ ++ dev->mm = get_task_mm(current); ++ return 0; ++} ++ ++/* Caller should have device mutex */ ++long vhost_dev_reset_owner(struct vhost_dev *dev) ++{ ++ struct vhost_memory *memory; ++ ++ /* Restore memory to default empty mapping. */ ++ memory = kmalloc(offsetof(struct vhost_memory, regions), GFP_KERNEL); ++ if (!memory) ++ return -ENOMEM; ++ ++ vhost_dev_cleanup(dev); ++ ++ memory->nregions = 0; ++ dev->memory = memory; ++ return 0; ++} ++ ++/* Caller should have device mutex */ ++void vhost_dev_cleanup(struct vhost_dev *dev) ++{ ++ int i; ++ for (i = 0; i < dev->nvqs; ++i) { ++ if (dev->vqs[i].kick && dev->vqs[i].handle_kick) { ++ vhost_poll_stop(&dev->vqs[i].poll); ++ vhost_poll_flush(&dev->vqs[i].poll); ++ } ++ if (dev->vqs[i].error_ctx) ++ eventfd_ctx_put(dev->vqs[i].error_ctx); ++ if (dev->vqs[i].error) ++ fput(dev->vqs[i].error); ++ if (dev->vqs[i].kick) ++ fput(dev->vqs[i].kick); ++ if (dev->vqs[i].call_ctx) ++ eventfd_ctx_put(dev->vqs[i].call_ctx); ++ if (dev->vqs[i].call) ++ fput(dev->vqs[i].call); ++ vhost_vq_reset(dev, dev->vqs + i); ++ } ++ if (dev->log_ctx) ++ eventfd_ctx_put(dev->log_ctx); ++ dev->log_ctx = NULL; ++ if (dev->log_file) ++ fput(dev->log_file); ++ dev->log_file = NULL; ++ /* No one will access memory at this point */ ++ kfree(dev->memory); ++ dev->memory = NULL; ++ if (dev->mm) ++ mmput(dev->mm); ++ dev->mm = NULL; ++} ++ ++static int log_access_ok(void __user *log_base, u64 addr, unsigned long sz) ++{ ++ u64 a = addr / VHOST_PAGE_SIZE / 8; ++ /* Make sure 64 bit math will not overflow. */ ++ if (a > ULONG_MAX - (unsigned long)log_base || ++ a + (unsigned long)log_base > ULONG_MAX) ++ return -EFAULT; ++ ++ return access_ok(VERIFY_WRITE, log_base + a, ++ (sz + VHOST_PAGE_SIZE * 8 - 1) / VHOST_PAGE_SIZE / 8); ++} ++ ++/* Caller should have vq mutex and device mutex. */ ++static int vq_memory_access_ok(void __user *log_base, struct vhost_memory *mem, ++ int log_all) ++{ ++ int i; ++ for (i = 0; i < mem->nregions; ++i) { ++ struct vhost_memory_region *m = mem->regions + i; ++ unsigned long a = m->userspace_addr; ++ if (m->memory_size > ULONG_MAX) ++ return 0; ++ else if (!access_ok(VERIFY_WRITE, (void __user *)a, ++ m->memory_size)) ++ return 0; ++ else if (log_all && !log_access_ok(log_base, ++ m->guest_phys_addr, ++ m->memory_size)) ++ return 0; ++ } ++ return 1; ++} ++ ++/* Can we switch to this memory table? */ ++/* Caller should have device mutex but not vq mutex */ ++static int memory_access_ok(struct vhost_dev *d, struct vhost_memory *mem, ++ int log_all) ++{ ++ int i; ++ for (i = 0; i < d->nvqs; ++i) { ++ int ok; ++ mutex_lock(&d->vqs[i].mutex); ++ /* If ring is inactive, will check when it's enabled. */ ++ if (d->vqs[i].private_data) ++ ok = vq_memory_access_ok(d->vqs[i].log_base, mem, ++ log_all); ++ else ++ ok = 1; ++ mutex_unlock(&d->vqs[i].mutex); ++ if (!ok) ++ return 0; ++ } ++ return 1; ++} ++ ++static int vq_access_ok(unsigned int num, ++ struct vring_desc __user *desc, ++ struct vring_avail __user *avail, ++ struct vring_used __user *used) ++{ ++ return access_ok(VERIFY_READ, desc, num * sizeof *desc) && ++ access_ok(VERIFY_READ, avail, ++ sizeof *avail + num * sizeof *avail->ring) && ++ access_ok(VERIFY_WRITE, used, ++ sizeof *used + num * sizeof *used->ring); ++} ++ ++/* Can we log writes? */ ++/* Caller should have device mutex but not vq mutex */ ++int vhost_log_access_ok(struct vhost_dev *dev) ++{ ++ return memory_access_ok(dev, dev->memory, 1); ++} ++ ++/* Verify access for write logging. */ ++/* Caller should have vq mutex and device mutex */ ++static int vq_log_access_ok(struct vhost_virtqueue *vq, void __user *log_base) ++{ ++ return vq_memory_access_ok(log_base, vq->dev->memory, ++ vhost_has_feature(vq->dev, VHOST_F_LOG_ALL)) && ++ (!vq->log_used || log_access_ok(log_base, vq->log_addr, ++ sizeof *vq->used + ++ vq->num * sizeof *vq->used->ring)); ++} ++ ++/* Can we start vq? */ ++/* Caller should have vq mutex and device mutex */ ++int vhost_vq_access_ok(struct vhost_virtqueue *vq) ++{ ++ return vq_access_ok(vq->num, vq->desc, vq->avail, vq->used) && ++ vq_log_access_ok(vq, vq->log_base); ++} ++ ++static long vhost_set_memory(struct vhost_dev *d, struct vhost_memory __user *m) ++{ ++ struct vhost_memory mem, *newmem, *oldmem; ++ unsigned long size = offsetof(struct vhost_memory, regions); ++ long r; ++ r = copy_from_user(&mem, m, size); ++ if (r) ++ return r; ++ if (mem.padding) ++ return -EOPNOTSUPP; ++ if (mem.nregions > VHOST_MEMORY_MAX_NREGIONS) ++ return -E2BIG; ++ newmem = kmalloc(size + mem.nregions * sizeof *m->regions, GFP_KERNEL); ++ if (!newmem) ++ return -ENOMEM; ++ ++ memcpy(newmem, &mem, size); ++ r = copy_from_user(newmem->regions, m->regions, ++ mem.nregions * sizeof *m->regions); ++ if (r) { ++ kfree(newmem); ++ return r; ++ } ++ ++ if (!memory_access_ok(d, newmem, vhost_has_feature(d, VHOST_F_LOG_ALL))) ++ return -EFAULT; ++ oldmem = d->memory; ++ rcu_assign_pointer(d->memory, newmem); ++ synchronize_rcu(); ++ kfree(oldmem); ++ return 0; ++} ++ ++static int init_used(struct vhost_virtqueue *vq, ++ struct vring_used __user *used) ++{ ++ int r = put_user(vq->used_flags, &used->flags); ++ if (r) ++ return r; ++ return get_user(vq->last_used_idx, &used->idx); ++} ++ ++static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) ++{ ++ struct file *eventfp, *filep = NULL, ++ *pollstart = NULL, *pollstop = NULL; ++ struct eventfd_ctx *ctx = NULL; ++ u32 __user *idxp = argp; ++ struct vhost_virtqueue *vq; ++ struct vhost_vring_state s; ++ struct vhost_vring_file f; ++ struct vhost_vring_addr a; ++ u32 idx; ++ long r; ++ ++ r = get_user(idx, idxp); ++ if (r < 0) ++ return r; ++ if (idx > d->nvqs) ++ return -ENOBUFS; ++ ++ vq = d->vqs + idx; ++ ++ mutex_lock(&vq->mutex); ++ ++ switch (ioctl) { ++ case VHOST_SET_VRING_NUM: ++ /* Resizing ring with an active backend? ++ * You don't want to do that. */ ++ if (vq->private_data) { ++ r = -EBUSY; ++ break; ++ } ++ r = copy_from_user(&s, argp, sizeof s); ++ if (r < 0) ++ break; ++ if (!s.num || s.num > 0xffff || (s.num & (s.num - 1))) { ++ r = -EINVAL; ++ break; ++ } ++ vq->num = s.num; ++ break; ++ case VHOST_SET_VRING_BASE: ++ /* Moving base with an active backend? ++ * You don't want to do that. */ ++ if (vq->private_data) { ++ r = -EBUSY; ++ break; ++ } ++ r = copy_from_user(&s, argp, sizeof s); ++ if (r < 0) ++ break; ++ if (s.num > 0xffff) { ++ r = -EINVAL; ++ break; ++ } ++ vq->last_avail_idx = s.num; ++ /* Forget the cached index value. */ ++ vq->avail_idx = vq->last_avail_idx; ++ break; ++ case VHOST_GET_VRING_BASE: ++ s.index = idx; ++ s.num = vq->last_avail_idx; ++ r = copy_to_user(argp, &s, sizeof s); ++ break; ++ case VHOST_SET_VRING_ADDR: ++ r = copy_from_user(&a, argp, sizeof a); ++ if (r < 0) ++ break; ++ if (a.flags & ~(0x1 << VHOST_VRING_F_LOG)) { ++ r = -EOPNOTSUPP; ++ break; ++ } ++ /* For 32bit, verify that the top 32bits of the user ++ data are set to zero. */ ++ if ((u64)(unsigned long)a.desc_user_addr != a.desc_user_addr || ++ (u64)(unsigned long)a.used_user_addr != a.used_user_addr || ++ (u64)(unsigned long)a.avail_user_addr != a.avail_user_addr) { ++ r = -EFAULT; ++ break; ++ } ++ if ((a.avail_user_addr & (sizeof *vq->avail->ring - 1)) || ++ (a.used_user_addr & (sizeof *vq->used->ring - 1)) || ++ (a.log_guest_addr & (sizeof *vq->used->ring - 1))) { ++ r = -EINVAL; ++ break; ++ } ++ ++ /* We only verify access here if backend is configured. ++ * If it is not, we don't as size might not have been setup. ++ * We will verify when backend is configured. */ ++ if (vq->private_data) { ++ if (!vq_access_ok(vq->num, ++ (void __user *)(unsigned long)a.desc_user_addr, ++ (void __user *)(unsigned long)a.avail_user_addr, ++ (void __user *)(unsigned long)a.used_user_addr)) { ++ r = -EINVAL; ++ break; ++ } ++ ++ /* Also validate log access for used ring if enabled. */ ++ if ((a.flags & (0x1 << VHOST_VRING_F_LOG)) && ++ !log_access_ok(vq->log_base, a.log_guest_addr, ++ sizeof *vq->used + ++ vq->num * sizeof *vq->used->ring)) { ++ r = -EINVAL; ++ break; ++ } ++ } ++ ++ r = init_used(vq, (struct vring_used __user *)(unsigned long) ++ a.used_user_addr); ++ if (r) ++ break; ++ vq->log_used = !!(a.flags & (0x1 << VHOST_VRING_F_LOG)); ++ vq->desc = (void __user *)(unsigned long)a.desc_user_addr; ++ vq->avail = (void __user *)(unsigned long)a.avail_user_addr; ++ vq->log_addr = a.log_guest_addr; ++ vq->used = (void __user *)(unsigned long)a.used_user_addr; ++ break; ++ case VHOST_SET_VRING_KICK: ++ r = copy_from_user(&f, argp, sizeof f); ++ if (r < 0) ++ break; ++ eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); ++ if (IS_ERR(eventfp)) ++ return PTR_ERR(eventfp); ++ if (eventfp != vq->kick) { ++ pollstop = filep = vq->kick; ++ pollstart = vq->kick = eventfp; ++ } else ++ filep = eventfp; ++ break; ++ case VHOST_SET_VRING_CALL: ++ r = copy_from_user(&f, argp, sizeof f); ++ if (r < 0) ++ break; ++ eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); ++ if (IS_ERR(eventfp)) ++ return PTR_ERR(eventfp); ++ if (eventfp != vq->call) { ++ filep = vq->call; ++ ctx = vq->call_ctx; ++ vq->call = eventfp; ++ vq->call_ctx = eventfp ? ++ eventfd_ctx_fileget(eventfp) : NULL; ++ } else ++ filep = eventfp; ++ break; ++ case VHOST_SET_VRING_ERR: ++ r = copy_from_user(&f, argp, sizeof f); ++ if (r < 0) ++ break; ++ eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); ++ if (IS_ERR(eventfp)) ++ return PTR_ERR(eventfp); ++ if (eventfp != vq->error) { ++ filep = vq->error; ++ vq->error = eventfp; ++ ctx = vq->error_ctx; ++ vq->error_ctx = eventfp ? ++ eventfd_ctx_fileget(eventfp) : NULL; ++ } else ++ filep = eventfp; ++ break; ++ default: ++ r = -ENOIOCTLCMD; ++ } ++ ++ if (pollstop && vq->handle_kick) ++ vhost_poll_stop(&vq->poll); ++ ++ if (ctx) ++ eventfd_ctx_put(ctx); ++ if (filep) ++ fput(filep); ++ ++ if (pollstart && vq->handle_kick) ++ vhost_poll_start(&vq->poll, vq->kick); ++ ++ mutex_unlock(&vq->mutex); ++ ++ if (pollstop && vq->handle_kick) ++ vhost_poll_flush(&vq->poll); ++ return r; ++} ++ ++/* Caller must have device mutex */ ++long vhost_dev_ioctl(struct vhost_dev *d, unsigned int ioctl, unsigned long arg) ++{ ++ void __user *argp = (void __user *)arg; ++ struct file *eventfp, *filep = NULL; ++ struct eventfd_ctx *ctx = NULL; ++ u64 p; ++ long r; ++ int i, fd; ++ ++ /* If you are not the owner, you can become one */ ++ if (ioctl == VHOST_SET_OWNER) { ++ r = vhost_dev_set_owner(d); ++ goto done; ++ } ++ ++ /* You must be the owner to do anything else */ ++ r = vhost_dev_check_owner(d); ++ if (r) ++ goto done; ++ ++ switch (ioctl) { ++ case VHOST_SET_MEM_TABLE: ++ r = vhost_set_memory(d, argp); ++ break; ++ case VHOST_SET_LOG_BASE: ++ r = copy_from_user(&p, argp, sizeof p); ++ if (r < 0) ++ break; ++ if ((u64)(unsigned long)p != p) { ++ r = -EFAULT; ++ break; ++ } ++ for (i = 0; i < d->nvqs; ++i) { ++ struct vhost_virtqueue *vq; ++ void __user *base = (void __user *)(unsigned long)p; ++ vq = d->vqs + i; ++ mutex_lock(&vq->mutex); ++ /* If ring is inactive, will check when it's enabled. */ ++ if (vq->private_data && !vq_log_access_ok(vq, base)) ++ r = -EFAULT; ++ else ++ vq->log_base = base; ++ mutex_unlock(&vq->mutex); ++ } ++ break; ++ case VHOST_SET_LOG_FD: ++ r = get_user(fd, (int __user *)argp); ++ if (r < 0) ++ break; ++ eventfp = fd == -1 ? NULL : eventfd_fget(fd); ++ if (IS_ERR(eventfp)) { ++ r = PTR_ERR(eventfp); ++ break; ++ } ++ if (eventfp != d->log_file) { ++ filep = d->log_file; ++ ctx = d->log_ctx; ++ d->log_ctx = eventfp ? ++ eventfd_ctx_fileget(eventfp) : NULL; ++ } else ++ filep = eventfp; ++ for (i = 0; i < d->nvqs; ++i) { ++ mutex_lock(&d->vqs[i].mutex); ++ d->vqs[i].log_ctx = d->log_ctx; ++ mutex_unlock(&d->vqs[i].mutex); ++ } ++ if (ctx) ++ eventfd_ctx_put(ctx); ++ if (filep) ++ fput(filep); ++ break; ++ default: ++ r = vhost_set_vring(d, ioctl, argp); ++ break; ++ } ++done: ++ return r; ++} ++ ++static const struct vhost_memory_region *find_region(struct vhost_memory *mem, ++ __u64 addr, __u32 len) ++{ ++ struct vhost_memory_region *reg; ++ int i; ++ /* linear search is not brilliant, but we really have on the order of 6 ++ * regions in practice */ ++ for (i = 0; i < mem->nregions; ++i) { ++ reg = mem->regions + i; ++ if (reg->guest_phys_addr <= addr && ++ reg->guest_phys_addr + reg->memory_size - 1 >= addr) ++ return reg; ++ } ++ return NULL; ++} ++ ++/* TODO: This is really inefficient. We need something like get_user() ++ * (instruction directly accesses the data, with an exception table entry ++ * returning -EFAULT). See Documentation/x86/exception-tables.txt. ++ */ ++static int set_bit_to_user(int nr, void __user *addr) ++{ ++ unsigned long log = (unsigned long)addr; ++ struct page *page; ++ void *base; ++ int bit = nr + (log % PAGE_SIZE) * 8; ++ int r; ++ r = get_user_pages_fast(log, 1, 1, &page); ++ if (r) ++ return r; ++ base = kmap_atomic(page, KM_USER0); ++ set_bit(bit, base); ++ kunmap_atomic(base, KM_USER0); ++ set_page_dirty_lock(page); ++ put_page(page); ++ return 0; ++} ++ ++static int log_write(void __user *log_base, ++ u64 write_address, u64 write_length) ++{ ++ int r; ++ if (!write_length) ++ return 0; ++ write_address /= VHOST_PAGE_SIZE; ++ for (;;) { ++ u64 base = (u64)(unsigned long)log_base; ++ u64 log = base + write_address / 8; ++ int bit = write_address % 8; ++ if ((u64)(unsigned long)log != log) ++ return -EFAULT; ++ r = set_bit_to_user(bit, (void __user *)(unsigned long)log); ++ if (r < 0) ++ return r; ++ if (write_length <= VHOST_PAGE_SIZE) ++ break; ++ write_length -= VHOST_PAGE_SIZE; ++ write_address += VHOST_PAGE_SIZE; ++ } ++ return r; ++} ++ ++int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, ++ unsigned int log_num, u64 len) ++{ ++ int i, r; ++ ++ /* Make sure data written is seen before log. */ ++ wmb(); ++ for (i = 0; i < log_num; ++i) { ++ u64 l = min(log[i].len, len); ++ r = log_write(vq->log_base, log[i].addr, l); ++ if (r < 0) ++ return r; ++ len -= l; ++ if (!len) ++ return 0; ++ } ++ if (vq->log_ctx) ++ eventfd_signal(vq->log_ctx, 1); ++ /* Length written exceeds what we have stored. This is a bug. */ ++ BUG(); ++ return 0; ++} ++ ++int translate_desc(struct vhost_dev *dev, u64 addr, u32 len, ++ struct iovec iov[], int iov_size) ++{ ++ const struct vhost_memory_region *reg; ++ struct vhost_memory *mem; ++ struct iovec *_iov; ++ u64 s = 0; ++ int ret = 0; ++ ++ rcu_read_lock(); ++ ++ mem = rcu_dereference(dev->memory); ++ while ((u64)len > s) { ++ u64 size; ++ if (ret >= iov_size) { ++ ret = -ENOBUFS; ++ break; ++ } ++ reg = find_region(mem, addr, len); ++ if (!reg) { ++ ret = -EFAULT; ++ break; ++ } ++ _iov = iov + ret; ++ size = reg->memory_size - addr + reg->guest_phys_addr; ++ _iov->iov_len = min((u64)len, size); ++ _iov->iov_base = (void *)(unsigned long) ++ (reg->userspace_addr + addr - reg->guest_phys_addr); ++ s += size; ++ addr += size; ++ ++ret; ++ } ++ ++ rcu_read_unlock(); ++ return ret; ++} ++ ++/* Each buffer in the virtqueues is actually a chain of descriptors. This ++ * function returns the next descriptor in the chain, ++ * or -1U if we're at the end. */ ++static unsigned next_desc(struct vring_desc *desc) ++{ ++ unsigned int next; ++ ++ /* If this descriptor says it doesn't chain, we're done. */ ++ if (!(desc->flags & VRING_DESC_F_NEXT)) ++ return -1U; ++ ++ /* Check they're not leading us off end of descriptors. */ ++ next = desc->next; ++ /* Make sure compiler knows to grab that: we don't want it changing! */ ++ /* We will use the result as an index in an array, so most ++ * architectures only need a compiler barrier here. */ ++ read_barrier_depends(); ++ ++ return next; ++} ++ ++static unsigned get_indirect(struct vhost_dev *dev, struct vhost_virtqueue *vq, ++ struct iovec iov[], unsigned int iov_size, ++ unsigned int *out_num, unsigned int *in_num, ++ struct vhost_log *log, unsigned int *log_num, ++ struct vring_desc *indirect) ++{ ++ struct vring_desc desc; ++ unsigned int i = 0, count, found = 0; ++ int ret; ++ ++ /* Sanity check */ ++ if (indirect->len % sizeof desc) { ++ vq_err(vq, "Invalid length in indirect descriptor: " ++ "len 0x%llx not multiple of 0x%zx\n", ++ (unsigned long long)indirect->len, ++ sizeof desc); ++ return -EINVAL; ++ } ++ ++ ret = translate_desc(dev, indirect->addr, indirect->len, vq->indirect, ++ ARRAY_SIZE(vq->indirect)); ++ if (ret < 0) { ++ vq_err(vq, "Translation failure %d in indirect.\n", ret); ++ return ret; ++ } ++ ++ /* We will use the result as an address to read from, so most ++ * architectures only need a compiler barrier here. */ ++ read_barrier_depends(); ++ ++ count = indirect->len / sizeof desc; ++ /* Buffers are chained via a 16 bit next field, so ++ * we can have at most 2^16 of these. */ ++ if (count > USHORT_MAX + 1) { ++ vq_err(vq, "Indirect buffer length too big: %d\n", ++ indirect->len); ++ return -E2BIG; ++ } ++ ++ do { ++ unsigned iov_count = *in_num + *out_num; ++ if (++found > count) { ++ vq_err(vq, "Loop detected: last one at %u " ++ "indirect size %u\n", ++ i, count); ++ return -EINVAL; ++ } ++ if (memcpy_fromiovec((unsigned char *)&desc, vq->indirect, ++ sizeof desc)) { ++ vq_err(vq, "Failed indirect descriptor: idx %d, %zx\n", ++ i, (size_t)indirect->addr + i * sizeof desc); ++ return -EINVAL; ++ } ++ if (desc.flags & VRING_DESC_F_INDIRECT) { ++ vq_err(vq, "Nested indirect descriptor: idx %d, %zx\n", ++ i, (size_t)indirect->addr + i * sizeof desc); ++ return -EINVAL; ++ } ++ ++ ret = translate_desc(dev, desc.addr, desc.len, iov + iov_count, ++ iov_size - iov_count); ++ if (ret < 0) { ++ vq_err(vq, "Translation failure %d indirect idx %d\n", ++ ret, i); ++ return ret; ++ } ++ /* If this is an input descriptor, increment that count. */ ++ if (desc.flags & VRING_DESC_F_WRITE) { ++ *in_num += ret; ++ if (unlikely(log)) { ++ log[*log_num].addr = desc.addr; ++ log[*log_num].len = desc.len; ++ ++*log_num; ++ } ++ } else { ++ /* If it's an output descriptor, they're all supposed ++ * to come before any input descriptors. */ ++ if (*in_num) { ++ vq_err(vq, "Indirect descriptor " ++ "has out after in: idx %d\n", i); ++ return -EINVAL; ++ } ++ *out_num += ret; ++ } ++ } while ((i = next_desc(&desc)) != -1); ++ return 0; ++} ++ ++/* This looks in the virtqueue and for the first available buffer, and converts ++ * it to an iovec for convenient access. Since descriptors consist of some ++ * number of output then some number of input descriptors, it's actually two ++ * iovecs, but we pack them into one and note how many of each there were. ++ * ++ * This function returns the descriptor number found, or vq->num (which ++ * is never a valid descriptor number) if none was found. */ ++unsigned vhost_get_vq_desc(struct vhost_dev *dev, struct vhost_virtqueue *vq, ++ struct iovec iov[], unsigned int iov_size, ++ unsigned int *out_num, unsigned int *in_num, ++ struct vhost_log *log, unsigned int *log_num) ++{ ++ struct vring_desc desc; ++ unsigned int i, head, found = 0; ++ u16 last_avail_idx; ++ int ret; ++ ++ /* Check it isn't doing very strange things with descriptor numbers. */ ++ last_avail_idx = vq->last_avail_idx; ++ if (get_user(vq->avail_idx, &vq->avail->idx)) { ++ vq_err(vq, "Failed to access avail idx at %p\n", ++ &vq->avail->idx); ++ return vq->num; ++ } ++ ++ if ((u16)(vq->avail_idx - last_avail_idx) > vq->num) { ++ vq_err(vq, "Guest moved used index from %u to %u", ++ last_avail_idx, vq->avail_idx); ++ return vq->num; ++ } ++ ++ /* If there's nothing new since last we looked, return invalid. */ ++ if (vq->avail_idx == last_avail_idx) ++ return vq->num; ++ ++ /* Only get avail ring entries after they have been exposed by guest. */ ++ rmb(); ++ ++ /* Grab the next descriptor number they're advertising, and increment ++ * the index we've seen. */ ++ if (get_user(head, &vq->avail->ring[last_avail_idx % vq->num])) { ++ vq_err(vq, "Failed to read head: idx %d address %p\n", ++ last_avail_idx, ++ &vq->avail->ring[last_avail_idx % vq->num]); ++ return vq->num; ++ } ++ ++ /* If their number is silly, that's an error. */ ++ if (head >= vq->num) { ++ vq_err(vq, "Guest says index %u > %u is available", ++ head, vq->num); ++ return vq->num; ++ } ++ ++ /* When we start there are none of either input nor output. */ ++ *out_num = *in_num = 0; ++ if (unlikely(log)) ++ *log_num = 0; ++ ++ i = head; ++ do { ++ unsigned iov_count = *in_num + *out_num; ++ if (i >= vq->num) { ++ vq_err(vq, "Desc index is %u > %u, head = %u", ++ i, vq->num, head); ++ return vq->num; ++ } ++ if (++found > vq->num) { ++ vq_err(vq, "Loop detected: last one at %u " ++ "vq size %u head %u\n", ++ i, vq->num, head); ++ return vq->num; ++ } ++ ret = copy_from_user(&desc, vq->desc + i, sizeof desc); ++ if (ret) { ++ vq_err(vq, "Failed to get descriptor: idx %d addr %p\n", ++ i, vq->desc + i); ++ return vq->num; ++ } ++ if (desc.flags & VRING_DESC_F_INDIRECT) { ++ ret = get_indirect(dev, vq, iov, iov_size, ++ out_num, in_num, ++ log, log_num, &desc); ++ if (ret < 0) { ++ vq_err(vq, "Failure detected " ++ "in indirect descriptor at idx %d\n", i); ++ return vq->num; ++ } ++ continue; ++ } ++ ++ ret = translate_desc(dev, desc.addr, desc.len, iov + iov_count, ++ iov_size - iov_count); ++ if (ret < 0) { ++ vq_err(vq, "Translation failure %d descriptor idx %d\n", ++ ret, i); ++ return vq->num; ++ } ++ if (desc.flags & VRING_DESC_F_WRITE) { ++ /* If this is an input descriptor, ++ * increment that count. */ ++ *in_num += ret; ++ if (unlikely(log)) { ++ log[*log_num].addr = desc.addr; ++ log[*log_num].len = desc.len; ++ ++*log_num; ++ } ++ } else { ++ /* If it's an output descriptor, they're all supposed ++ * to come before any input descriptors. */ ++ if (*in_num) { ++ vq_err(vq, "Descriptor has out after in: " ++ "idx %d\n", i); ++ return vq->num; ++ } ++ *out_num += ret; ++ } ++ } while ((i = next_desc(&desc)) != -1); ++ ++ /* On success, increment avail index. */ ++ vq->last_avail_idx++; ++ return head; ++} ++ ++/* Reverse the effect of vhost_get_vq_desc. Useful for error handling. */ ++void vhost_discard_vq_desc(struct vhost_virtqueue *vq) ++{ ++ vq->last_avail_idx--; ++} ++ ++/* After we've used one of their buffers, we tell them about it. We'll then ++ * want to notify the guest, using eventfd. */ ++int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len) ++{ ++ struct vring_used_elem *used; ++ ++ /* The virtqueue contains a ring of used buffers. Get a pointer to the ++ * next entry in that used ring. */ ++ used = &vq->used->ring[vq->last_used_idx % vq->num]; ++ if (put_user(head, &used->id)) { ++ vq_err(vq, "Failed to write used id"); ++ return -EFAULT; ++ } ++ if (put_user(len, &used->len)) { ++ vq_err(vq, "Failed to write used len"); ++ return -EFAULT; ++ } ++ /* Make sure buffer is written before we update index. */ ++ wmb(); ++ if (put_user(vq->last_used_idx + 1, &vq->used->idx)) { ++ vq_err(vq, "Failed to increment used idx"); ++ return -EFAULT; ++ } ++ if (unlikely(vq->log_used)) { ++ /* Make sure data is seen before log. */ ++ wmb(); ++ log_write(vq->log_base, vq->log_addr + sizeof *vq->used->ring * ++ (vq->last_used_idx % vq->num), ++ sizeof *vq->used->ring); ++ log_write(vq->log_base, vq->log_addr, sizeof *vq->used->ring); ++ if (vq->log_ctx) ++ eventfd_signal(vq->log_ctx, 1); ++ } ++ vq->last_used_idx++; ++ return 0; ++} ++ ++/* This actually signals the guest, using eventfd. */ ++void vhost_signal(struct vhost_dev *dev, struct vhost_virtqueue *vq) ++{ ++ __u16 flags = 0; ++ if (get_user(flags, &vq->avail->flags)) { ++ vq_err(vq, "Failed to get flags"); ++ return; ++ } ++ ++ /* If they don't want an interrupt, don't signal, unless empty. */ ++ if ((flags & VRING_AVAIL_F_NO_INTERRUPT) && ++ (vq->avail_idx != vq->last_avail_idx || ++ !vhost_has_feature(dev, VIRTIO_F_NOTIFY_ON_EMPTY))) ++ return; ++ ++ /* Signal the Guest tell them we used something up. */ ++ if (vq->call_ctx) ++ eventfd_signal(vq->call_ctx, 1); ++} ++ ++/* And here's the combo meal deal. Supersize me! */ ++void vhost_add_used_and_signal(struct vhost_dev *dev, ++ struct vhost_virtqueue *vq, ++ unsigned int head, int len) ++{ ++ vhost_add_used(vq, head, len); ++ vhost_signal(dev, vq); ++} ++ ++/* OK, now we need to know about added descriptors. */ ++bool vhost_enable_notify(struct vhost_virtqueue *vq) ++{ ++ u16 avail_idx; ++ int r; ++ if (!(vq->used_flags & VRING_USED_F_NO_NOTIFY)) ++ return false; ++ vq->used_flags &= ~VRING_USED_F_NO_NOTIFY; ++ r = put_user(vq->used_flags, &vq->used->flags); ++ if (r) { ++ vq_err(vq, "Failed to enable notification at %p: %d\n", ++ &vq->used->flags, r); ++ return false; ++ } ++ /* They could have slipped one in as we were doing that: make ++ * sure it's written, then check again. */ ++ mb(); ++ r = get_user(avail_idx, &vq->avail->idx); ++ if (r) { ++ vq_err(vq, "Failed to check avail idx at %p: %d\n", ++ &vq->avail->idx, r); ++ return false; ++ } ++ ++ return avail_idx != vq->last_avail_idx; ++} ++ ++/* We don't need to be notified again. */ ++void vhost_disable_notify(struct vhost_virtqueue *vq) ++{ ++ int r; ++ if (vq->used_flags & VRING_USED_F_NO_NOTIFY) ++ return; ++ vq->used_flags |= VRING_USED_F_NO_NOTIFY; ++ r = put_user(vq->used_flags, &vq->used->flags); ++ if (r) ++ vq_err(vq, "Failed to enable notification at %p: %d\n", ++ &vq->used->flags, r); ++} ++ ++int vhost_init(void) ++{ ++ vhost_workqueue = create_singlethread_workqueue("vhost"); ++ if (!vhost_workqueue) ++ return -ENOMEM; ++ return 0; ++} ++ ++void vhost_cleanup(void) ++{ ++ destroy_workqueue(vhost_workqueue); ++} +diff --git a/drivers/vhost/vhost.h b/drivers/vhost/vhost.h +new file mode 100644 +index 0000000..44591ba +--- /dev/null ++++ b/drivers/vhost/vhost.h +@@ -0,0 +1,161 @@ ++#ifndef _VHOST_H ++#define _VHOST_H ++ ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++#include ++ ++struct vhost_device; ++ ++enum { ++ /* Enough place for all fragments, head, and virtio net header. */ ++ VHOST_NET_MAX_SG = MAX_SKB_FRAGS + 2, ++}; ++ ++/* Poll a file (eventfd or socket) */ ++/* Note: there's nothing vhost specific about this structure. */ ++struct vhost_poll { ++ poll_table table; ++ wait_queue_head_t *wqh; ++ wait_queue_t wait; ++ /* struct which will handle all actual work. */ ++ struct work_struct work; ++ unsigned long mask; ++}; ++ ++void vhost_poll_init(struct vhost_poll *poll, work_func_t func, ++ unsigned long mask); ++void vhost_poll_start(struct vhost_poll *poll, struct file *file); ++void vhost_poll_stop(struct vhost_poll *poll); ++void vhost_poll_flush(struct vhost_poll *poll); ++void vhost_poll_queue(struct vhost_poll *poll); ++ ++struct vhost_log { ++ u64 addr; ++ u64 len; ++}; ++ ++/* The virtqueue structure describes a queue attached to a device. */ ++struct vhost_virtqueue { ++ struct vhost_dev *dev; ++ ++ /* The actual ring of buffers. */ ++ struct mutex mutex; ++ unsigned int num; ++ struct vring_desc __user *desc; ++ struct vring_avail __user *avail; ++ struct vring_used __user *used; ++ struct file *kick; ++ struct file *call; ++ struct file *error; ++ struct eventfd_ctx *call_ctx; ++ struct eventfd_ctx *error_ctx; ++ struct eventfd_ctx *log_ctx; ++ ++ struct vhost_poll poll; ++ ++ /* The routine to call when the Guest pings us, or timeout. */ ++ work_func_t handle_kick; ++ ++ /* Last available index we saw. */ ++ u16 last_avail_idx; ++ ++ /* Caches available index value from user. */ ++ u16 avail_idx; ++ ++ /* Last index we used. */ ++ u16 last_used_idx; ++ ++ /* Used flags */ ++ u16 used_flags; ++ ++ /* Log writes to used structure. */ ++ bool log_used; ++ u64 log_addr; ++ ++ struct iovec indirect[VHOST_NET_MAX_SG]; ++ struct iovec iov[VHOST_NET_MAX_SG]; ++ struct iovec hdr[VHOST_NET_MAX_SG]; ++ size_t hdr_size; ++ /* We use a kind of RCU to access private pointer. ++ * All readers access it from workqueue, which makes it possible to ++ * flush the workqueue instead of synchronize_rcu. Therefore readers do ++ * not need to call rcu_read_lock/rcu_read_unlock: the beginning of ++ * work item execution acts instead of rcu_read_lock() and the end of ++ * work item execution acts instead of rcu_read_lock(). ++ * Writers use virtqueue mutex. */ ++ void *private_data; ++ /* Log write descriptors */ ++ void __user *log_base; ++ struct vhost_log log[VHOST_NET_MAX_SG]; ++}; ++ ++struct vhost_dev { ++ /* Readers use RCU to access memory table pointer ++ * log base pointer and features. ++ * Writers use mutex below.*/ ++ struct vhost_memory *memory; ++ struct mm_struct *mm; ++ struct mutex mutex; ++ unsigned acked_features; ++ struct vhost_virtqueue *vqs; ++ int nvqs; ++ struct file *log_file; ++ struct eventfd_ctx *log_ctx; ++}; ++ ++long vhost_dev_init(struct vhost_dev *, struct vhost_virtqueue *vqs, int nvqs); ++long vhost_dev_check_owner(struct vhost_dev *); ++long vhost_dev_reset_owner(struct vhost_dev *); ++void vhost_dev_cleanup(struct vhost_dev *); ++long vhost_dev_ioctl(struct vhost_dev *, unsigned int ioctl, unsigned long arg); ++int vhost_vq_access_ok(struct vhost_virtqueue *vq); ++int vhost_log_access_ok(struct vhost_dev *); ++ ++unsigned vhost_get_vq_desc(struct vhost_dev *, struct vhost_virtqueue *, ++ struct iovec iov[], unsigned int iov_count, ++ unsigned int *out_num, unsigned int *in_num, ++ struct vhost_log *log, unsigned int *log_num); ++void vhost_discard_vq_desc(struct vhost_virtqueue *); ++ ++int vhost_add_used(struct vhost_virtqueue *, unsigned int head, int len); ++void vhost_signal(struct vhost_dev *, struct vhost_virtqueue *); ++void vhost_add_used_and_signal(struct vhost_dev *, struct vhost_virtqueue *, ++ unsigned int head, int len); ++void vhost_disable_notify(struct vhost_virtqueue *); ++bool vhost_enable_notify(struct vhost_virtqueue *); ++ ++int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, ++ unsigned int log_num, u64 len); ++ ++int vhost_init(void); ++void vhost_cleanup(void); ++ ++#define vq_err(vq, fmt, ...) do { \ ++ pr_debug(pr_fmt(fmt), ##__VA_ARGS__); \ ++ if ((vq)->error_ctx) \ ++ eventfd_signal((vq)->error_ctx, 1);\ ++ } while (0) ++ ++enum { ++ VHOST_FEATURES = (1 << VIRTIO_F_NOTIFY_ON_EMPTY) | ++ (1 << VIRTIO_RING_F_INDIRECT_DESC) | ++ (1 << VHOST_F_LOG_ALL) | ++ (1 << VHOST_NET_F_VIRTIO_NET_HDR), ++}; ++ ++static inline int vhost_has_feature(struct vhost_dev *dev, int bit) ++{ ++ unsigned acked_features = rcu_dereference(dev->acked_features); ++ return acked_features & (1 << bit); ++} ++ ++#endif +diff --git a/include/linux/Kbuild b/include/linux/Kbuild +index 756f831..d930807 100644 +--- a/include/linux/Kbuild ++++ b/include/linux/Kbuild +@@ -362,6 +362,7 @@ unifdef-y += uio.h + unifdef-y += unistd.h + unifdef-y += usbdevice_fs.h + unifdef-y += utsname.h ++unifdef-y += vhost.h + unifdef-y += videodev2.h + unifdef-y += videodev.h + unifdef-y += virtio_config.h +diff --git a/include/linux/if_tun.h b/include/linux/if_tun.h +index 3f5fd52..404abe0 100644 +--- a/include/linux/if_tun.h ++++ b/include/linux/if_tun.h +@@ -86,4 +86,18 @@ struct tun_filter { + __u8 addr[0][ETH_ALEN]; + }; + ++#ifdef __KERNEL__ ++#if defined(CONFIG_TUN) || defined(CONFIG_TUN_MODULE) ++struct socket *tun_get_socket(struct file *); ++#else ++#include ++#include ++struct file; ++struct socket; ++static inline struct socket *tun_get_socket(struct file *f) ++{ ++ return ERR_PTR(-EINVAL); ++} ++#endif /* CONFIG_TUN */ ++#endif /* __KERNEL__ */ + #endif /* __IF_TUN_H */ +diff --git a/include/linux/miscdevice.h b/include/linux/miscdevice.h +index adaf3c1..8b5f7cc 100644 +--- a/include/linux/miscdevice.h ++++ b/include/linux/miscdevice.h +@@ -30,6 +30,7 @@ + #define HPET_MINOR 228 + #define FUSE_MINOR 229 + #define KVM_MINOR 232 ++#define VHOST_NET_MINOR 233 + #define MISC_DYNAMIC_MINOR 255 + + struct device; +diff --git a/include/linux/vhost.h b/include/linux/vhost.h +new file mode 100644 +index 0000000..e847f1e +--- /dev/null ++++ b/include/linux/vhost.h +@@ -0,0 +1,130 @@ ++#ifndef _LINUX_VHOST_H ++#define _LINUX_VHOST_H ++/* Userspace interface for in-kernel virtio accelerators. */ ++ ++/* vhost is used to reduce the number of system calls involved in virtio. ++ * ++ * Existing virtio net code is used in the guest without modification. ++ * ++ * This header includes interface used by userspace hypervisor for ++ * device configuration. ++ */ ++ ++#include ++#include ++#include ++#include ++#include ++ ++struct vhost_vring_state { ++ unsigned int index; ++ unsigned int num; ++}; ++ ++struct vhost_vring_file { ++ unsigned int index; ++ int fd; /* Pass -1 to unbind from file. */ ++ ++}; ++ ++struct vhost_vring_addr { ++ unsigned int index; ++ /* Option flags. */ ++ unsigned int flags; ++ /* Flag values: */ ++ /* Whether log address is valid. If set enables logging. */ ++#define VHOST_VRING_F_LOG 0 ++ ++ /* Start of array of descriptors (virtually contiguous) */ ++ __u64 desc_user_addr; ++ /* Used structure address. Must be 32 bit aligned */ ++ __u64 used_user_addr; ++ /* Available structure address. Must be 16 bit aligned */ ++ __u64 avail_user_addr; ++ /* Logging support. */ ++ /* Log writes to used structure, at offset calculated from specified ++ * address. Address must be 32 bit aligned. */ ++ __u64 log_guest_addr; ++}; ++ ++struct vhost_memory_region { ++ __u64 guest_phys_addr; ++ __u64 memory_size; /* bytes */ ++ __u64 userspace_addr; ++ __u64 flags_padding; /* No flags are currently specified. */ ++}; ++ ++/* All region addresses and sizes must be 4K aligned. */ ++#define VHOST_PAGE_SIZE 0x1000 ++ ++struct vhost_memory { ++ __u32 nregions; ++ __u32 padding; ++ struct vhost_memory_region regions[0]; ++}; ++ ++/* ioctls */ ++ ++#define VHOST_VIRTIO 0xAF ++ ++/* Features bitmask for forward compatibility. Transport bits are used for ++ * vhost specific features. */ ++#define VHOST_GET_FEATURES _IOR(VHOST_VIRTIO, 0x00, __u64) ++#define VHOST_SET_FEATURES _IOW(VHOST_VIRTIO, 0x00, __u64) ++ ++/* Set current process as the (exclusive) owner of this file descriptor. This ++ * must be called before any other vhost command. Further calls to ++ * VHOST_OWNER_SET fail until VHOST_OWNER_RESET is called. */ ++#define VHOST_SET_OWNER _IO(VHOST_VIRTIO, 0x01) ++/* Give up ownership, and reset the device to default values. ++ * Allows subsequent call to VHOST_OWNER_SET to succeed. */ ++#define VHOST_RESET_OWNER _IO(VHOST_VIRTIO, 0x02) ++ ++/* Set up/modify memory layout */ ++#define VHOST_SET_MEM_TABLE _IOW(VHOST_VIRTIO, 0x03, struct vhost_memory) ++ ++/* Write logging setup. */ ++/* Memory writes can optionally be logged by setting bit at an offset ++ * (calculated from the physical address) from specified log base. ++ * The bit is set using an atomic 32 bit operation. */ ++/* Set base address for logging. */ ++#define VHOST_SET_LOG_BASE _IOW(VHOST_VIRTIO, 0x04, __u64) ++/* Specify an eventfd file descriptor to signal on log write. */ ++#define VHOST_SET_LOG_FD _IOW(VHOST_VIRTIO, 0x07, int) ++ ++/* Ring setup. */ ++/* Set number of descriptors in ring. This parameter can not ++ * be modified while ring is running (bound to a device). */ ++#define VHOST_SET_VRING_NUM _IOW(VHOST_VIRTIO, 0x10, struct vhost_vring_state) ++/* Set addresses for the ring. */ ++#define VHOST_SET_VRING_ADDR _IOW(VHOST_VIRTIO, 0x11, struct vhost_vring_addr) ++/* Base value where queue looks for available descriptors */ ++#define VHOST_SET_VRING_BASE _IOW(VHOST_VIRTIO, 0x12, struct vhost_vring_state) ++/* Get accessor: reads index, writes value in num */ ++#define VHOST_GET_VRING_BASE _IOWR(VHOST_VIRTIO, 0x12, struct vhost_vring_state) ++ ++/* The following ioctls use eventfd file descriptors to signal and poll ++ * for events. */ ++ ++/* Set eventfd to poll for added buffers */ ++#define VHOST_SET_VRING_KICK _IOW(VHOST_VIRTIO, 0x20, struct vhost_vring_file) ++/* Set eventfd to signal when buffers have beed used */ ++#define VHOST_SET_VRING_CALL _IOW(VHOST_VIRTIO, 0x21, struct vhost_vring_file) ++/* Set eventfd to signal an error */ ++#define VHOST_SET_VRING_ERR _IOW(VHOST_VIRTIO, 0x22, struct vhost_vring_file) ++ ++/* VHOST_NET specific defines */ ++ ++/* Attach virtio net ring to a raw socket, or tap device. ++ * The socket must be already bound to an ethernet device, this device will be ++ * used for transmit. Pass fd -1 to unbind from the socket and the transmit ++ * device. This can be used to stop the ring (e.g. for migration). */ ++#define VHOST_NET_SET_BACKEND _IOW(VHOST_VIRTIO, 0x30, struct vhost_vring_file) ++ ++/* Feature bits */ ++/* Log all write descriptors. Can be changed while device is active. */ ++#define VHOST_F_LOG_ALL 26 ++/* vhost-net should add virtio_net_hdr for RX, and strip for TX packets. */ ++#define VHOST_NET_F_VIRTIO_NET_HDR 27 ++ ++#endif +diff --git a/mm/mmu_context.c b/mm/mmu_context.c +index ded9081..0777654 100644 +--- a/mm/mmu_context.c ++++ b/mm/mmu_context.c +@@ -5,6 +5,7 @@ + + #include + #include ++#include + #include + + #include +@@ -37,6 +38,7 @@ void use_mm(struct mm_struct *mm) + if (active_mm != mm) + mmdrop(active_mm); + } ++EXPORT_SYMBOL_GPL(use_mm); + + /* + * unuse_mm +@@ -56,3 +58,4 @@ void unuse_mm(struct mm_struct *mm) + enter_lazy_tlb(mm, tsk); + task_unlock(tsk); + } ++EXPORT_SYMBOL_GPL(unuse_mm); diff --git a/vhost_net-rollup2.patch b/vhost_net-rollup2.patch new file mode 100644 index 000000000..a05272a48 --- /dev/null +++ b/vhost_net-rollup2.patch @@ -0,0 +1,377 @@ +commit 17660f81243e998f36257881ac3ae61685bf91c1 +Author: Michael S. Tsirkin +Date: Thu Jan 21 01:28:45 2010 -0800 + + vhost: fix TUN=m VHOST_NET=y + + drivers/built-in.o: In function `get_tun_socket': + net.c:(.text+0x15436e): undefined reference to `tun_get_socket' + + If tun is a module, vhost must be a module, too. + If tun is built-in or disabled, vhost can be built-in. + + Note: TUN || !TUN might look a bit strange until you realize + that boolean logic rules do not apply for tristate variables. + + Reported-by: Randy Dunlap + Signed-off-by: Michael S. Tsirkin + Acked-by: Randy Dunlap + Signed-off-by: David S. Miller + +diff --git a/drivers/vhost/Kconfig b/drivers/vhost/Kconfig +index 9f409f4..9e93553 100644 +--- a/drivers/vhost/Kconfig ++++ b/drivers/vhost/Kconfig +@@ -1,6 +1,6 @@ + config VHOST_NET + tristate "Host kernel accelerator for virtio net (EXPERIMENTAL)" +- depends on NET && EVENTFD && EXPERIMENTAL ++ depends on NET && EVENTFD && (TUN || !TUN) && EXPERIMENTAL + ---help--- + This kernel module can be loaded in host kernel to accelerate + guest networking with virtio_net. Not to be confused with virtio_net +commit 5659338c88963ea791118e5e11e314b24f90c3eb +Author: Michael S. Tsirkin +Date: Mon Feb 1 07:21:02 2010 +0000 + + vhost-net: switch to smp barriers + + vhost-net only uses memory barriers to control SMP effects + (communication with userspace potentially running on a different CPU), + so it should use SMP barriers and not mandatory barriers for memory + access ordering, as suggested by Documentation/memory-barriers.txt + + Signed-off-by: Michael S. Tsirkin + Acked-by: Rusty Russell + Signed-off-by: David S. Miller + +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +index c8c25db..6eb1525 100644 +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -685,7 +685,7 @@ int vhost_log_write(struct vhost_virtqueue *vq, struct vhost_log *log, + int i, r; + + /* Make sure data written is seen before log. */ +- wmb(); ++ smp_wmb(); + for (i = 0; i < log_num; ++i) { + u64 l = min(log[i].len, len); + r = log_write(vq->log_base, log[i].addr, l); +@@ -884,7 +884,7 @@ unsigned vhost_get_vq_desc(struct vhost_dev *dev, struct vhost_virtqueue *vq, + return vq->num; + + /* Only get avail ring entries after they have been exposed by guest. */ +- rmb(); ++ smp_rmb(); + + /* Grab the next descriptor number they're advertising, and increment + * the index we've seen. */ +@@ -996,14 +996,14 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len) + return -EFAULT; + } + /* Make sure buffer is written before we update index. */ +- wmb(); ++ smp_wmb(); + if (put_user(vq->last_used_idx + 1, &vq->used->idx)) { + vq_err(vq, "Failed to increment used idx"); + return -EFAULT; + } + if (unlikely(vq->log_used)) { + /* Make sure data is seen before log. */ +- wmb(); ++ smp_wmb(); + log_write(vq->log_base, vq->log_addr + sizeof *vq->used->ring * + (vq->last_used_idx % vq->num), + sizeof *vq->used->ring); +@@ -1060,7 +1060,7 @@ bool vhost_enable_notify(struct vhost_virtqueue *vq) + } + /* They could have slipped one in as we were doing that: make + * sure it's written, then check again. */ +- mb(); ++ smp_mb(); + r = get_user(avail_idx, &vq->avail->idx); + if (r) { + vq_err(vq, "Failed to check avail idx at %p: %d\n", +commit 86e9424d7252bae5ad1c17b4b8088193e6b27cbe +Author: Michael S. Tsirkin +Date: Wed Feb 17 19:11:33 2010 +0200 + + vhost: logging thinko fix + + vhost was dong some complex math to get + offset to log at, and got it wrong by a couple of bytes, + while in fact it's simple: get address where we write, + subtract start of buffer, add log base. + + Do it this way. + + Reviewed-by: Juan Quintela + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +index 6eb1525..db21518 100644 +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -1004,10 +1004,14 @@ int vhost_add_used(struct vhost_virtqueue *vq, unsigned int head, int len) + if (unlikely(vq->log_used)) { + /* Make sure data is seen before log. */ + smp_wmb(); +- log_write(vq->log_base, vq->log_addr + sizeof *vq->used->ring * +- (vq->last_used_idx % vq->num), +- sizeof *vq->used->ring); +- log_write(vq->log_base, vq->log_addr, sizeof *vq->used->ring); ++ /* Log used ring entry write. */ ++ log_write(vq->log_base, ++ vq->log_addr + ((void *)used - (void *)vq->used), ++ sizeof *used); ++ /* Log used index update. */ ++ log_write(vq->log_base, ++ vq->log_addr + offsetof(struct vring_used, idx), ++ sizeof vq->used->idx); + if (vq->log_ctx) + eventfd_signal(vq->log_ctx, 1); + } +commit 73a99f083009d67d8e12603420e008d5c21b0b7d +Author: Michael S. Tsirkin +Date: Tue Feb 23 11:23:45 2010 +0200 + + vhost: initialize log eventfd context pointer + + vq log eventfd context pointer needs to be initialized, otherwise + operation may fail or oops if log is enabled but log eventfd not set by + userspace. When log_ctx for device is created, it is copied to the vq. + This reset was missing. + + Reviewed-by: Juan Quintela + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +index db21518..6c31c0c 100644 +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -121,6 +121,7 @@ static void vhost_vq_reset(struct vhost_dev *dev, + vq->kick = NULL; + vq->call_ctx = NULL; + vq->call = NULL; ++ vq->log_ctx = NULL; + } + + long vhost_dev_init(struct vhost_dev *dev, +commit d6db3f5c11dc7ed5712d5d5682aa34025ee5248e +Author: Michael S. Tsirkin +Date: Tue Feb 23 11:25:23 2010 +0200 + + vhost: fix get_user_pages_fast error handling + + get_user_pages_fast returns number of pages on success, negative value + on failure, but never 0. Fix vhost code to match this logic. + + Reviewed-by: Juan Quintela + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +index 6c31c0c..7cd55e0 100644 +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -646,8 +646,9 @@ static int set_bit_to_user(int nr, void __user *addr) + int bit = nr + (log % PAGE_SIZE) * 8; + int r; + r = get_user_pages_fast(log, 1, 1, &page); +- if (r) ++ if (r < 0) + return r; ++ BUG_ON(r != 1); + base = kmap_atomic(page, KM_USER0); + set_bit(bit, base); + kunmap_atomic(base, KM_USER0); +commit 39286fa41a8b2c6a9c1f656a7b3c3efca95bc1b9 +Author: Sridhar Samudrala +Date: Sun Feb 28 19:39:16 2010 +0200 + + vhost-net: restart tx poll on sk_sndbuf full + + guest to remote communication with vhost net sometimes stops until + guest driver is restarted. This happens when we get guest kick precisely + when the backend send queue is full, as a result handle_tx() returns without + polling backend. This patch fixes this by restarting tx poll on this condition. + + Signed-off-by: Sridhar Samudrala + Signed-off-by: Michael S. Tsirkin + Tested-by: Tom Lendacky + +diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c +index 91a324c..ad37da2 100644 +--- a/drivers/vhost/net.c ++++ b/drivers/vhost/net.c +@@ -114,8 +114,12 @@ static void handle_tx(struct vhost_net *net) + return; + + wmem = atomic_read(&sock->sk->sk_wmem_alloc); +- if (wmem >= sock->sk->sk_sndbuf) ++ if (wmem >= sock->sk->sk_sndbuf) { ++ mutex_lock(&vq->mutex); ++ tx_poll_start(net, sock); ++ mutex_unlock(&vq->mutex); + return; ++ } + + use_mm(net->dev.mm); + mutex_lock(&vq->mutex); +commit 1dace8c801ac531022bd31a7316a6b4351837617 +Author: Jeff Dike +Date: Thu Mar 4 16:10:14 2010 -0500 + + vhost: fix error path in vhost_net_set_backend + + An error could cause vhost_net_set_backend to exit without unlocking + vq->mutex. Fix this. + + Signed-off-by: Jeff Dike + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c +index ad37da2..fcafb6b 100644 +--- a/drivers/vhost/net.c ++++ b/drivers/vhost/net.c +@@ -508,12 +508,12 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd) + /* Verify that ring has been setup correctly. */ + if (!vhost_vq_access_ok(vq)) { + r = -EFAULT; +- goto err; ++ goto err_vq; + } + sock = get_socket(fd); + if (IS_ERR(sock)) { + r = PTR_ERR(sock); +- goto err; ++ goto err_vq; + } + + /* start polling new socket */ +@@ -524,12 +524,14 @@ static long vhost_net_set_backend(struct vhost_net *n, unsigned index, int fd) + vhost_net_disable_vq(n, vq); + rcu_assign_pointer(vq->private_data, sock); + vhost_net_enable_vq(n, vq); +- mutex_unlock(&vq->mutex); + done: + if (oldsock) { + vhost_net_flush_vq(n, index); + fput(oldsock->file); + } ++ ++err_vq: ++ mutex_unlock(&vq->mutex); + err: + mutex_unlock(&n->dev.mutex); + return r; +commit 0e255572121180c900e24e33b87047abd8153cce +Author: Michael S. Tsirkin +Date: Mon Mar 8 23:24:22 2010 +0200 + + vhost: fix interrupt mitigation with raw sockets + + A thinko in code means we never trigger interrupt + mitigation. Fix this. + + Reported-by: Juan Quintela + Reported-by: Unai Uribarri + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/net.c b/drivers/vhost/net.c +index fcafb6b..a6a88df 100644 +--- a/drivers/vhost/net.c ++++ b/drivers/vhost/net.c +@@ -125,7 +125,7 @@ static void handle_tx(struct vhost_net *net) + mutex_lock(&vq->mutex); + vhost_disable_notify(vq); + +- if (wmem < sock->sk->sk_sndbuf * 2) ++ if (wmem < sock->sk->sk_sndbuf / 2) + tx_poll_stop(net); + hdr_size = vq->hdr_size; + +commit 535297a6ae4c3b7a0562e71fac15c213eeec68e7 +Author: Michael S. Tsirkin +Date: Wed Mar 17 16:06:11 2010 +0200 + + vhost: fix error handling in vring ioctls + + Stanse found a locking problem in vhost_set_vring: + several returns from VHOST_SET_VRING_KICK, VHOST_SET_VRING_CALL, + VHOST_SET_VRING_ERR with the vq->mutex held. + Fix these up. + + Reported-by: Jiri Slaby + Acked-by: Laurent Chavey + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +index 7cd55e0..7bd7a1e 100644 +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -476,8 +476,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) + if (r < 0) + break; + eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); +- if (IS_ERR(eventfp)) +- return PTR_ERR(eventfp); ++ if (IS_ERR(eventfp)) { ++ r = PTR_ERR(eventfp); ++ break; ++ } + if (eventfp != vq->kick) { + pollstop = filep = vq->kick; + pollstart = vq->kick = eventfp; +@@ -489,8 +491,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) + if (r < 0) + break; + eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); +- if (IS_ERR(eventfp)) +- return PTR_ERR(eventfp); ++ if (IS_ERR(eventfp)) { ++ r = PTR_ERR(eventfp); ++ break; ++ } + if (eventfp != vq->call) { + filep = vq->call; + ctx = vq->call_ctx; +@@ -505,8 +509,10 @@ static long vhost_set_vring(struct vhost_dev *d, int ioctl, void __user *argp) + if (r < 0) + break; + eventfp = f.fd == -1 ? NULL : eventfd_fget(f.fd); +- if (IS_ERR(eventfp)) +- return PTR_ERR(eventfp); ++ if (IS_ERR(eventfp)) { ++ r = PTR_ERR(eventfp); ++ break; ++ } + if (eventfp != vq->error) { + filep = vq->error; + vq->error = eventfp; +commit 179b284e2fc0c638035843968f7d7ab8ab701525 +Author: Jeff Dike +Date: Wed Apr 7 09:59:10 2010 -0400 + + vhost-net: fix vq_memory_access_ok error checking + + vq_memory_access_ok needs to check whether mem == NULL + + Signed-off-by: Jeff Dike + Signed-off-by: Michael S. Tsirkin + +diff --git a/drivers/vhost/vhost.c b/drivers/vhost/vhost.c +index 7bd7a1e..b8e1127 100644 +--- a/drivers/vhost/vhost.c ++++ b/drivers/vhost/vhost.c +@@ -235,6 +235,10 @@ static int vq_memory_access_ok(void __user *log_base, struct vhost_memory *mem, + int log_all) + { + int i; ++ ++ if (!mem) ++ return 0; ++ + for (i = 0; i < mem->nregions; ++i) { + struct vhost_memory_region *m = mem->regions + i; + unsigned long a = m->userspace_addr; diff --git a/virt_console-fix-fix-race.patch b/virt_console-fix-fix-race.patch new file mode 100644 index 000000000..816022caa --- /dev/null +++ b/virt_console-fix-fix-race.patch @@ -0,0 +1,68 @@ +From: Anton Blanchard +Date: Tue, 6 Apr 2010 11:42:38 +0000 (+1000) +Subject: hvc_console: Fix race between hvc_close and hvc_remove +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=320718ee074acce5ffced6506cb51af1388942aa + +hvc_console: Fix race between hvc_close and hvc_remove + +I don't claim to understand the tty layer, but it seems like hvc_open and +hvc_close should be balanced in their kref reference counting. + +Right now we get a kref every call to hvc_open: + + if (hp->count++ > 0) { + tty_kref_get(tty); <----- here + spin_unlock_irqrestore(&hp->lock, flags); + hvc_kick(); + return 0; + } /* else count == 0 */ + + tty->driver_data = hp; + + hp->tty = tty_kref_get(tty); <------ or here if hp->count was 0 + +But hvc_close has: + + tty_kref_get(tty); + + if (--hp->count == 0) { +... + /* Put the ref obtained in hvc_open() */ + tty_kref_put(tty); +... + } + + tty_kref_put(tty); + +Since the outside kref get/put balance we only do a single kref_put when +count reaches 0. + +The patch below changes things to call tty_kref_put once for every +hvc_close call, and with that my machine boots fine. + +Signed-off-by: Anton Blanchard +Acked-by: Amit Shah +Signed-off-by: Rusty Russell +--- + +diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c +index d3890e8..35cca4c 100644 +--- a/drivers/char/hvc_console.c ++++ b/drivers/char/hvc_console.c +@@ -368,16 +368,12 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) + hp = tty->driver_data; + + spin_lock_irqsave(&hp->lock, flags); +- tty_kref_get(tty); + + if (--hp->count == 0) { + /* We are done with the tty pointer now. */ + hp->tty = NULL; + spin_unlock_irqrestore(&hp->lock, flags); + +- /* Put the ref obtained in hvc_open() */ +- tty_kref_put(tty); +- + if (hp->ops->notifier_del) + hp->ops->notifier_del(hp, hp->data); + diff --git a/virt_console-fix-race.patch b/virt_console-fix-race.patch new file mode 100644 index 000000000..344430cb0 --- /dev/null +++ b/virt_console-fix-race.patch @@ -0,0 +1,168 @@ +From: Amit Shah +Date: Fri, 12 Mar 2010 06:23:15 +0000 (+0530) +Subject: hvc_console: Fix race between hvc_close and hvc_remove +X-Git-Tag: v2.6.34-rc2~6^2~3 +X-Git-Url: http://git.kernel.org/?p=linux%2Fkernel%2Fgit%2Ftorvalds%2Flinux-2.6.git;a=commitdiff_plain;h=e74d098c66543d0731de62eb747ccd5b636a6f4c + +hvc_console: Fix race between hvc_close and hvc_remove + +Alan pointed out a race in the code where hvc_remove is invoked. The +recent virtio_console work is the first user of hvc_remove(). + +Alan describes it thus: + +The hvc_console assumes that a close and remove call can't occur at the +same time. + +In addition tty_hangup(tty) is problematic as tty_hangup is asynchronous +itself.... + +So this can happen + + hvc_close hvc_remove + hung up ? - no + lock + tty = hp->tty + unlock + lock + hp->tty = NULL + unlock + notify del + kref_put the hvc struct + close completes + tty is destroyed + tty_hangup dead tty + tty->ops will be NULL + NULL->... + +This patch adds some tty krefs and also converts to using tty_vhangup(). + +Reported-by: Alan Cox +Signed-off-by: Amit Shah +CC: Alan Cox +CC: linuxppc-dev@ozlabs.org +CC: Rusty Russell +Signed-off-by: Greg Kroah-Hartman +--- + +diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c +index 465185f..ba55bba 100644 +--- a/drivers/char/hvc_console.c ++++ b/drivers/char/hvc_console.c +@@ -312,6 +312,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp) + spin_lock_irqsave(&hp->lock, flags); + /* Check and then increment for fast path open. */ + if (hp->count++ > 0) { ++ tty_kref_get(tty); + spin_unlock_irqrestore(&hp->lock, flags); + hvc_kick(); + return 0; +@@ -319,7 +320,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp) + + tty->driver_data = hp; + +- hp->tty = tty; ++ hp->tty = tty_kref_get(tty); + + spin_unlock_irqrestore(&hp->lock, flags); + +@@ -336,6 +337,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp) + spin_lock_irqsave(&hp->lock, flags); + hp->tty = NULL; + spin_unlock_irqrestore(&hp->lock, flags); ++ tty_kref_put(tty); + tty->driver_data = NULL; + kref_put(&hp->kref, destroy_hvc_struct); + printk(KERN_ERR "hvc_open: request_irq failed with rc %d.\n", rc); +@@ -363,13 +365,18 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) + return; + + hp = tty->driver_data; ++ + spin_lock_irqsave(&hp->lock, flags); ++ tty_kref_get(tty); + + if (--hp->count == 0) { + /* We are done with the tty pointer now. */ + hp->tty = NULL; + spin_unlock_irqrestore(&hp->lock, flags); + ++ /* Put the ref obtained in hvc_open() */ ++ tty_kref_put(tty); ++ + if (hp->ops->notifier_del) + hp->ops->notifier_del(hp, hp->data); + +@@ -389,6 +396,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp) + spin_unlock_irqrestore(&hp->lock, flags); + } + ++ tty_kref_put(tty); + kref_put(&hp->kref, destroy_hvc_struct); + } + +@@ -424,10 +432,11 @@ static void hvc_hangup(struct tty_struct *tty) + spin_unlock_irqrestore(&hp->lock, flags); + + if (hp->ops->notifier_hangup) +- hp->ops->notifier_hangup(hp, hp->data); ++ hp->ops->notifier_hangup(hp, hp->data); + + while(temp_open_count) { + --temp_open_count; ++ tty_kref_put(tty); + kref_put(&hp->kref, destroy_hvc_struct); + } + } +@@ -592,7 +601,7 @@ int hvc_poll(struct hvc_struct *hp) + } + + /* No tty attached, just skip */ +- tty = hp->tty; ++ tty = tty_kref_get(hp->tty); + if (tty == NULL) + goto bail; + +@@ -672,6 +681,8 @@ int hvc_poll(struct hvc_struct *hp) + + tty_flip_buffer_push(tty); + } ++ if (tty) ++ tty_kref_put(tty); + + return poll_mask; + } +@@ -807,7 +818,7 @@ int hvc_remove(struct hvc_struct *hp) + struct tty_struct *tty; + + spin_lock_irqsave(&hp->lock, flags); +- tty = hp->tty; ++ tty = tty_kref_get(hp->tty); + + if (hp->index < MAX_NR_HVC_CONSOLES) + vtermnos[hp->index] = -1; +@@ -819,18 +830,18 @@ int hvc_remove(struct hvc_struct *hp) + /* + * We 'put' the instance that was grabbed when the kref instance + * was initialized using kref_init(). Let the last holder of this +- * kref cause it to be removed, which will probably be the tty_hangup ++ * kref cause it to be removed, which will probably be the tty_vhangup + * below. + */ + kref_put(&hp->kref, destroy_hvc_struct); + + /* +- * This function call will auto chain call hvc_hangup. The tty should +- * always be valid at this time unless a simultaneous tty close already +- * cleaned up the hvc_struct. ++ * This function call will auto chain call hvc_hangup. + */ +- if (tty) +- tty_hangup(tty); ++ if (tty) { ++ tty_vhangup(tty); ++ tty_kref_put(tty); ++ } + return 0; + } + EXPORT_SYMBOL_GPL(hvc_remove); diff --git a/virt_console-rollup.patch b/virt_console-rollup.patch new file mode 100644 index 000000000..20b475d04 --- /dev/null +++ b/virt_console-rollup.patch @@ -0,0 +1,2020 @@ +diff --git a/MAINTAINERS b/MAINTAINERS +index 03f38c1..3118dfa 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -2394,6 +2394,12 @@ L: linuxppc-dev@ozlabs.org + S: Odd Fixes + F: drivers/char/hvc_* + ++VIRTIO CONSOLE DRIVER ++M: Amit Shah ++L: virtualization@lists.linux-foundation.org ++S: Maintained ++F: drivers/char/virtio_console.c ++ + GSPCA FINEPIX SUBDRIVER + M: Frank Zago + L: linux-media@vger.kernel.org +diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig +index e023682..3141dd3 100644 +--- a/drivers/char/Kconfig ++++ b/drivers/char/Kconfig +@@ -666,6 +666,14 @@ config VIRTIO_CONSOLE + help + Virtio console for use with lguest and other hypervisors. + ++ Also serves as a general-purpose serial device for data ++ transfer between the guest and host. Character devices at ++ /dev/vportNpn will be created when corresponding ports are ++ found, where N is the device number and n is the port number ++ within that device. If specified by the host, a sysfs ++ attribute called 'name' will be populated with a name for ++ the port which can be used by udev scripts to create a ++ symlink to the device. + + config HVCS + tristate "IBM Hypervisor Virtual Console Server support" +diff --git a/drivers/char/hvc_beat.c b/drivers/char/hvc_beat.c +index 0afc8b8..6913fc3 100644 +--- a/drivers/char/hvc_beat.c ++++ b/drivers/char/hvc_beat.c +@@ -84,7 +84,7 @@ static int hvc_beat_put_chars(uint32_t vtermno, const char *buf, int cnt) + return cnt; + } + +-static struct hv_ops hvc_beat_get_put_ops = { ++static const struct hv_ops hvc_beat_get_put_ops = { + .get_chars = hvc_beat_get_chars, + .put_chars = hvc_beat_put_chars, + }; +diff --git a/drivers/char/hvc_console.c b/drivers/char/hvc_console.c +index 416d342..4c3b59b 100644 +--- a/drivers/char/hvc_console.c ++++ b/drivers/char/hvc_console.c +@@ -125,7 +125,7 @@ static struct hvc_struct *hvc_get_by_index(int index) + * console interfaces but can still be used as a tty device. This has to be + * static because kmalloc will not work during early console init. + */ +-static struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES]; ++static const struct hv_ops *cons_ops[MAX_NR_HVC_CONSOLES]; + static uint32_t vtermnos[MAX_NR_HVC_CONSOLES] = + {[0 ... MAX_NR_HVC_CONSOLES - 1] = -1}; + +@@ -247,7 +247,7 @@ static void destroy_hvc_struct(struct kref *kref) + * vty adapters do NOT get an hvc_instantiate() callback since they + * appear after early console init. + */ +-int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops) ++int hvc_instantiate(uint32_t vtermno, int index, const struct hv_ops *ops) + { + struct hvc_struct *hp; + +@@ -748,8 +748,9 @@ static const struct tty_operations hvc_ops = { + .chars_in_buffer = hvc_chars_in_buffer, + }; + +-struct hvc_struct __devinit *hvc_alloc(uint32_t vtermno, int data, +- struct hv_ops *ops, int outbuf_size) ++struct hvc_struct *hvc_alloc(uint32_t vtermno, int data, ++ const struct hv_ops *ops, ++ int outbuf_size) + { + struct hvc_struct *hp; + int i; +diff --git a/drivers/char/hvc_console.h b/drivers/char/hvc_console.h +index 10950ca..54381eb 100644 +--- a/drivers/char/hvc_console.h ++++ b/drivers/char/hvc_console.h +@@ -55,7 +55,7 @@ struct hvc_struct { + int outbuf_size; + int n_outbuf; + uint32_t vtermno; +- struct hv_ops *ops; ++ const struct hv_ops *ops; + int irq_requested; + int data; + struct winsize ws; +@@ -76,11 +76,12 @@ struct hv_ops { + }; + + /* Register a vterm and a slot index for use as a console (console_init) */ +-extern int hvc_instantiate(uint32_t vtermno, int index, struct hv_ops *ops); ++extern int hvc_instantiate(uint32_t vtermno, int index, ++ const struct hv_ops *ops); + + /* register a vterm for hvc tty operation (module_init or hotplug add) */ +-extern struct hvc_struct * __devinit hvc_alloc(uint32_t vtermno, int data, +- struct hv_ops *ops, int outbuf_size); ++extern struct hvc_struct * hvc_alloc(uint32_t vtermno, int data, ++ const struct hv_ops *ops, int outbuf_size); + /* remove a vterm from hvc tty operation (module_exit or hotplug remove) */ + extern int hvc_remove(struct hvc_struct *hp); + +diff --git a/drivers/char/hvc_iseries.c b/drivers/char/hvc_iseries.c +index 936d05b..fd02426 100644 +--- a/drivers/char/hvc_iseries.c ++++ b/drivers/char/hvc_iseries.c +@@ -197,7 +197,7 @@ done: + return sent; + } + +-static struct hv_ops hvc_get_put_ops = { ++static const struct hv_ops hvc_get_put_ops = { + .get_chars = get_chars, + .put_chars = put_chars, + .notifier_add = notifier_add_irq, +diff --git a/drivers/char/hvc_iucv.c b/drivers/char/hvc_iucv.c +index fe62bd0..21681a8 100644 +--- a/drivers/char/hvc_iucv.c ++++ b/drivers/char/hvc_iucv.c +@@ -922,7 +922,7 @@ static int hvc_iucv_pm_restore_thaw(struct device *dev) + + + /* HVC operations */ +-static struct hv_ops hvc_iucv_ops = { ++static const struct hv_ops hvc_iucv_ops = { + .get_chars = hvc_iucv_get_chars, + .put_chars = hvc_iucv_put_chars, + .notifier_add = hvc_iucv_notifier_add, +diff --git a/drivers/char/hvc_rtas.c b/drivers/char/hvc_rtas.c +index 88590d0..61c4a61 100644 +--- a/drivers/char/hvc_rtas.c ++++ b/drivers/char/hvc_rtas.c +@@ -71,7 +71,7 @@ static int hvc_rtas_read_console(uint32_t vtermno, char *buf, int count) + return i; + } + +-static struct hv_ops hvc_rtas_get_put_ops = { ++static const struct hv_ops hvc_rtas_get_put_ops = { + .get_chars = hvc_rtas_read_console, + .put_chars = hvc_rtas_write_console, + }; +diff --git a/drivers/char/hvc_udbg.c b/drivers/char/hvc_udbg.c +index bd63ba8..b0957e6 100644 +--- a/drivers/char/hvc_udbg.c ++++ b/drivers/char/hvc_udbg.c +@@ -58,7 +58,7 @@ static int hvc_udbg_get(uint32_t vtermno, char *buf, int count) + return i; + } + +-static struct hv_ops hvc_udbg_ops = { ++static const struct hv_ops hvc_udbg_ops = { + .get_chars = hvc_udbg_get, + .put_chars = hvc_udbg_put, + }; +diff --git a/drivers/char/hvc_vio.c b/drivers/char/hvc_vio.c +index 10be343..27370e9 100644 +--- a/drivers/char/hvc_vio.c ++++ b/drivers/char/hvc_vio.c +@@ -77,7 +77,7 @@ static int filtered_get_chars(uint32_t vtermno, char *buf, int count) + return got; + } + +-static struct hv_ops hvc_get_put_ops = { ++static const struct hv_ops hvc_get_put_ops = { + .get_chars = filtered_get_chars, + .put_chars = hvc_put_chars, + .notifier_add = notifier_add_irq, +diff --git a/drivers/char/hvc_xen.c b/drivers/char/hvc_xen.c +index b1a7163..60446f8 100644 +--- a/drivers/char/hvc_xen.c ++++ b/drivers/char/hvc_xen.c +@@ -122,7 +122,7 @@ static int read_console(uint32_t vtermno, char *buf, int len) + return recv; + } + +-static struct hv_ops hvc_ops = { ++static const struct hv_ops hvc_ops = { + .get_chars = read_console, + .put_chars = write_console, + .notifier_add = notifier_add_irq, +diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c +index a035ae3..213373b 100644 +--- a/drivers/char/virtio_console.c ++++ b/drivers/char/virtio_console.c +@@ -1,18 +1,6 @@ +-/*D:300 +- * The Guest console driver +- * +- * Writing console drivers is one of the few remaining Dark Arts in Linux. +- * Fortunately for us, the path of virtual consoles has been well-trodden by +- * the PowerPC folks, who wrote "hvc_console.c" to generically support any +- * virtual console. We use that infrastructure which only requires us to write +- * the basic put_chars and get_chars functions and call the right register +- * functions. +- :*/ +- +-/*M:002 The console can be flooded: while the Guest is processing input the +- * Host can send more. Buffering in the Host could alleviate this, but it is a +- * difficult problem in general. :*/ +-/* Copyright (C) 2006, 2007 Rusty Russell, IBM Corporation ++/* ++ * Copyright (C) 2006, 2007, 2009 Rusty Russell, IBM Corporation ++ * Copyright (C) 2009, 2010 Red Hat, Inc. + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by +@@ -28,142 +16,694 @@ + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ ++#include ++#include ++#include + #include ++#include + #include ++#include ++#include ++#include ++#include + #include + #include ++#include ++#include + #include "hvc_console.h" + +-/*D:340 These represent our input and output console queues, and the virtio +- * operations for them. */ +-static struct virtqueue *in_vq, *out_vq; +-static struct virtio_device *vdev; ++/* ++ * This is a global struct for storing common data for all the devices ++ * this driver handles. ++ * ++ * Mainly, it has a linked list for all the consoles in one place so ++ * that callbacks from hvc for get_chars(), put_chars() work properly ++ * across multiple devices and multiple ports per device. ++ */ ++struct ports_driver_data { ++ /* Used for registering chardevs */ ++ struct class *class; ++ ++ /* Used for exporting per-port information to debugfs */ ++ struct dentry *debugfs_dir; ++ ++ /* Number of devices this driver is handling */ ++ unsigned int index; ++ ++ /* ++ * This is used to keep track of the number of hvc consoles ++ * spawned by this driver. This number is given as the first ++ * argument to hvc_alloc(). To correctly map an initial ++ * console spawned via hvc_instantiate to the console being ++ * hooked up via hvc_alloc, we need to pass the same vtermno. ++ * ++ * We also just assume the first console being initialised was ++ * the first one that got used as the initial console. ++ */ ++ unsigned int next_vtermno; ++ ++ /* All the console devices handled by this driver */ ++ struct list_head consoles; ++}; ++static struct ports_driver_data pdrvdata; ++ ++DEFINE_SPINLOCK(pdrvdata_lock); ++ ++/* This struct holds information that's relevant only for console ports */ ++struct console { ++ /* We'll place all consoles in a list in the pdrvdata struct */ ++ struct list_head list; ++ ++ /* The hvc device associated with this console port */ ++ struct hvc_struct *hvc; ++ ++ /* ++ * This number identifies the number that we used to register ++ * with hvc in hvc_instantiate() and hvc_alloc(); this is the ++ * number passed on by the hvc callbacks to us to ++ * differentiate between the other console ports handled by ++ * this driver ++ */ ++ u32 vtermno; ++}; ++ ++struct port_buffer { ++ char *buf; ++ ++ /* size of the buffer in *buf above */ ++ size_t size; ++ ++ /* used length of the buffer */ ++ size_t len; ++ /* offset in the buf from which to consume data */ ++ size_t offset; ++}; ++ ++/* ++ * This is a per-device struct that stores data common to all the ++ * ports for that device (vdev->priv). ++ */ ++struct ports_device { ++ /* ++ * Workqueue handlers where we process deferred work after ++ * notification ++ */ ++ struct work_struct control_work; ++ struct work_struct config_work; ++ ++ struct list_head ports; ++ ++ /* To protect the list of ports */ ++ spinlock_t ports_lock; ++ ++ /* To protect the vq operations for the control channel */ ++ spinlock_t cvq_lock; ++ ++ /* The current config space is stored here */ ++ struct virtio_console_config config; ++ ++ /* The virtio device we're associated with */ ++ struct virtio_device *vdev; ++ ++ /* ++ * A couple of virtqueues for the control channel: one for ++ * guest->host transfers, one for host->guest transfers ++ */ ++ struct virtqueue *c_ivq, *c_ovq; ++ ++ /* Array of per-port IO virtqueues */ ++ struct virtqueue **in_vqs, **out_vqs; ++ ++ /* Used for numbering devices for sysfs and debugfs */ ++ unsigned int drv_index; ++ ++ /* Major number for this device. Ports will be created as minors. */ ++ int chr_major; ++}; ++ ++/* This struct holds the per-port data */ ++struct port { ++ /* Next port in the list, head is in the ports_device */ ++ struct list_head list; ++ ++ /* Pointer to the parent virtio_console device */ ++ struct ports_device *portdev; ++ ++ /* The current buffer from which data has to be fed to readers */ ++ struct port_buffer *inbuf; ++ ++ /* ++ * To protect the operations on the in_vq associated with this ++ * port. Has to be a spinlock because it can be called from ++ * interrupt context (get_char()). ++ */ ++ spinlock_t inbuf_lock; ++ ++ /* The IO vqs for this port */ ++ struct virtqueue *in_vq, *out_vq; ++ ++ /* File in the debugfs directory that exposes this port's information */ ++ struct dentry *debugfs_file; ++ ++ /* ++ * The entries in this struct will be valid if this port is ++ * hooked up to an hvc console ++ */ ++ struct console cons; ++ ++ /* Each port associates with a separate char device */ ++ struct cdev cdev; ++ struct device *dev; ++ ++ /* A waitqueue for poll() or blocking read operations */ ++ wait_queue_head_t waitqueue; ++ ++ /* The 'name' of the port that we expose via sysfs properties */ ++ char *name; ++ ++ /* The 'id' to identify the port with the Host */ ++ u32 id; ++ ++ /* Is the host device open */ ++ bool host_connected; ++ ++ /* We should allow only one process to open a port */ ++ bool guest_connected; ++}; ++ ++/* This is the very early arch-specified put chars function. */ ++static int (*early_put_chars)(u32, const char *, int); ++ ++static struct port *find_port_by_vtermno(u32 vtermno) ++{ ++ struct port *port; ++ struct console *cons; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&pdrvdata_lock, flags); ++ list_for_each_entry(cons, &pdrvdata.consoles, list) { ++ if (cons->vtermno == vtermno) { ++ port = container_of(cons, struct port, cons); ++ goto out; ++ } ++ } ++ port = NULL; ++out: ++ spin_unlock_irqrestore(&pdrvdata_lock, flags); ++ return port; ++} ++ ++static struct port *find_port_by_id(struct ports_device *portdev, u32 id) ++{ ++ struct port *port; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&portdev->ports_lock, flags); ++ list_for_each_entry(port, &portdev->ports, list) ++ if (port->id == id) ++ goto out; ++ port = NULL; ++out: ++ spin_unlock_irqrestore(&portdev->ports_lock, flags); ++ ++ return port; ++} ++ ++static struct port *find_port_by_vq(struct ports_device *portdev, ++ struct virtqueue *vq) ++{ ++ struct port *port; ++ unsigned long flags; ++ ++ spin_lock_irqsave(&portdev->ports_lock, flags); ++ list_for_each_entry(port, &portdev->ports, list) ++ if (port->in_vq == vq || port->out_vq == vq) ++ goto out; ++ port = NULL; ++out: ++ spin_unlock_irqrestore(&portdev->ports_lock, flags); ++ return port; ++} ++ ++static bool is_console_port(struct port *port) ++{ ++ if (port->cons.hvc) ++ return true; ++ return false; ++} ++ ++static inline bool use_multiport(struct ports_device *portdev) ++{ ++ /* ++ * This condition can be true when put_chars is called from ++ * early_init ++ */ ++ if (!portdev->vdev) ++ return 0; ++ return portdev->vdev->features[0] & (1 << VIRTIO_CONSOLE_F_MULTIPORT); ++} + +-/* This is our input buffer, and how much data is left in it. */ +-static unsigned int in_len; +-static char *in, *inbuf; ++static void free_buf(struct port_buffer *buf) ++{ ++ kfree(buf->buf); ++ kfree(buf); ++} ++ ++static struct port_buffer *alloc_buf(size_t buf_size) ++{ ++ struct port_buffer *buf; + +-/* The operations for our console. */ +-static struct hv_ops virtio_cons; ++ buf = kmalloc(sizeof(*buf), GFP_KERNEL); ++ if (!buf) ++ goto fail; ++ buf->buf = kzalloc(buf_size, GFP_KERNEL); ++ if (!buf->buf) ++ goto free_buf; ++ buf->len = 0; ++ buf->offset = 0; ++ buf->size = buf_size; ++ return buf; ++ ++free_buf: ++ kfree(buf); ++fail: ++ return NULL; ++} ++ ++/* Callers should take appropriate locks */ ++static void *get_inbuf(struct port *port) ++{ ++ struct port_buffer *buf; ++ struct virtqueue *vq; ++ unsigned int len; + +-/* The hvc device */ +-static struct hvc_struct *hvc; ++ vq = port->in_vq; ++ buf = vq->vq_ops->get_buf(vq, &len); ++ if (buf) { ++ buf->len = len; ++ buf->offset = 0; ++ } ++ return buf; ++} + +-/*D:310 The put_chars() callback is pretty straightforward. ++/* ++ * Create a scatter-gather list representing our input buffer and put ++ * it in the queue. + * +- * We turn the characters into a scatter-gather list, add it to the output +- * queue and then kick the Host. Then we sit here waiting for it to finish: +- * inefficient in theory, but in practice implementations will do it +- * immediately (lguest's Launcher does). */ +-static int put_chars(u32 vtermno, const char *buf, int count) ++ * Callers should take appropriate locks. ++ */ ++static int add_inbuf(struct virtqueue *vq, struct port_buffer *buf) + { + struct scatterlist sg[1]; ++ int ret; ++ ++ sg_init_one(sg, buf->buf, buf->size); ++ ++ ret = vq->vq_ops->add_buf(vq, sg, 0, 1, buf); ++ vq->vq_ops->kick(vq); ++ return ret; ++} ++ ++/* Discard any unread data this port has. Callers lockers. */ ++static void discard_port_data(struct port *port) ++{ ++ struct port_buffer *buf; ++ struct virtqueue *vq; + unsigned int len; ++ int ret; + +- /* This is a convenient routine to initialize a single-elem sg list */ +- sg_init_one(sg, buf, count); ++ vq = port->in_vq; ++ if (port->inbuf) ++ buf = port->inbuf; ++ else ++ buf = vq->vq_ops->get_buf(vq, &len); + +- /* add_buf wants a token to identify this buffer: we hand it any +- * non-NULL pointer, since there's only ever one buffer. */ +- if (out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, (void *)1) >= 0) { +- /* Tell Host to go! */ +- out_vq->vq_ops->kick(out_vq); +- /* Chill out until it's done with the buffer. */ +- while (!out_vq->vq_ops->get_buf(out_vq, &len)) +- cpu_relax(); ++ ret = 0; ++ while (buf) { ++ if (add_inbuf(vq, buf) < 0) { ++ ret++; ++ free_buf(buf); ++ } ++ buf = vq->vq_ops->get_buf(vq, &len); + } ++ port->inbuf = NULL; ++ if (ret) ++ dev_warn(port->dev, "Errors adding %d buffers back to vq\n", ++ ret); ++} + +- /* We're expected to return the amount of data we wrote: all of it. */ +- return count; ++static bool port_has_data(struct port *port) ++{ ++ unsigned long flags; ++ bool ret; ++ ++ spin_lock_irqsave(&port->inbuf_lock, flags); ++ if (port->inbuf) { ++ ret = true; ++ goto out; ++ } ++ port->inbuf = get_inbuf(port); ++ if (port->inbuf) { ++ ret = true; ++ goto out; ++ } ++ ret = false; ++out: ++ spin_unlock_irqrestore(&port->inbuf_lock, flags); ++ return ret; + } + +-/* Create a scatter-gather list representing our input buffer and put it in the +- * queue. */ +-static void add_inbuf(void) ++static ssize_t send_control_msg(struct port *port, unsigned int event, ++ unsigned int value) + { + struct scatterlist sg[1]; +- sg_init_one(sg, inbuf, PAGE_SIZE); ++ struct virtio_console_control cpkt; ++ struct virtqueue *vq; ++ int len; ++ ++ if (!use_multiport(port->portdev)) ++ return 0; ++ ++ cpkt.id = port->id; ++ cpkt.event = event; ++ cpkt.value = value; ++ ++ vq = port->portdev->c_ovq; + +- /* We should always be able to add one buffer to an empty queue. */ +- if (in_vq->vq_ops->add_buf(in_vq, sg, 0, 1, inbuf) < 0) +- BUG(); +- in_vq->vq_ops->kick(in_vq); ++ sg_init_one(sg, &cpkt, sizeof(cpkt)); ++ if (vq->vq_ops->add_buf(vq, sg, 1, 0, &cpkt) >= 0) { ++ vq->vq_ops->kick(vq); ++ while (!vq->vq_ops->get_buf(vq, &len)) ++ cpu_relax(); ++ } ++ return 0; + } + +-/*D:350 get_chars() is the callback from the hvc_console infrastructure when +- * an interrupt is received. +- * +- * Most of the code deals with the fact that the hvc_console() infrastructure +- * only asks us for 16 bytes at a time. We keep in_offset and in_used fields +- * for partially-filled buffers. */ +-static int get_chars(u32 vtermno, char *buf, int count) ++static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count) + { +- /* If we don't have an input queue yet, we can't get input. */ +- BUG_ON(!in_vq); ++ struct scatterlist sg[1]; ++ struct virtqueue *out_vq; ++ ssize_t ret; ++ unsigned int len; ++ ++ out_vq = port->out_vq; ++ ++ sg_init_one(sg, in_buf, in_count); ++ ret = out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, in_buf); ++ ++ /* Tell Host to go! */ ++ out_vq->vq_ops->kick(out_vq); ++ ++ if (ret < 0) { ++ len = 0; ++ goto fail; ++ } ++ ++ /* ++ * Wait till the host acknowledges it pushed out the data we ++ * sent. Also ensure we return to userspace the number of ++ * bytes that were successfully consumed by the host. ++ */ ++ while (!out_vq->vq_ops->get_buf(out_vq, &len)) ++ cpu_relax(); ++fail: ++ /* We're expected to return the amount of data we wrote */ ++ return len; ++} ++ ++/* ++ * Give out the data that's requested from the buffer that we have ++ * queued up. ++ */ ++static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count, ++ bool to_user) ++{ ++ struct port_buffer *buf; ++ unsigned long flags; ++ ++ if (!out_count || !port_has_data(port)) ++ return 0; ++ ++ buf = port->inbuf; ++ out_count = min(out_count, buf->len - buf->offset); ++ ++ if (to_user) { ++ ssize_t ret; ++ ++ ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count); ++ if (ret) ++ return -EFAULT; ++ } else { ++ memcpy(out_buf, buf->buf + buf->offset, out_count); ++ } ++ ++ buf->offset += out_count; ++ ++ if (buf->offset == buf->len) { ++ /* ++ * We're done using all the data in this buffer. ++ * Re-queue so that the Host can send us more data. ++ */ ++ spin_lock_irqsave(&port->inbuf_lock, flags); ++ port->inbuf = NULL; ++ ++ if (add_inbuf(port->in_vq, buf) < 0) ++ dev_warn(port->dev, "failed add_buf\n"); ++ ++ spin_unlock_irqrestore(&port->inbuf_lock, flags); ++ } ++ /* Return the number of bytes actually copied */ ++ return out_count; ++} + +- /* No buffer? Try to get one. */ +- if (!in_len) { +- in = in_vq->vq_ops->get_buf(in_vq, &in_len); +- if (!in) ++/* The condition that must be true for polling to end */ ++static bool wait_is_over(struct port *port) ++{ ++ return port_has_data(port) || !port->host_connected; ++} ++ ++static ssize_t port_fops_read(struct file *filp, char __user *ubuf, ++ size_t count, loff_t *offp) ++{ ++ struct port *port; ++ ssize_t ret; ++ ++ port = filp->private_data; ++ ++ if (!port_has_data(port)) { ++ /* ++ * If nothing's connected on the host just return 0 in ++ * case of list_empty; this tells the userspace app ++ * that there's no connection ++ */ ++ if (!port->host_connected) + return 0; ++ if (filp->f_flags & O_NONBLOCK) ++ return -EAGAIN; ++ ++ ret = wait_event_interruptible(port->waitqueue, ++ wait_is_over(port)); ++ if (ret < 0) ++ return ret; ++ } ++ /* ++ * We could've received a disconnection message while we were ++ * waiting for more data. ++ * ++ * This check is not clubbed in the if() statement above as we ++ * might receive some data as well as the host could get ++ * disconnected after we got woken up from our wait. So we ++ * really want to give off whatever data we have and only then ++ * check for host_connected. ++ */ ++ if (!port_has_data(port) && !port->host_connected) ++ return 0; ++ ++ return fill_readbuf(port, ubuf, count, true); ++} ++ ++static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, ++ size_t count, loff_t *offp) ++{ ++ struct port *port; ++ char *buf; ++ ssize_t ret; ++ ++ port = filp->private_data; ++ ++ count = min((size_t)(32 * 1024), count); ++ ++ buf = kmalloc(count, GFP_KERNEL); ++ if (!buf) ++ return -ENOMEM; ++ ++ ret = copy_from_user(buf, ubuf, count); ++ if (ret) { ++ ret = -EFAULT; ++ goto free_buf; + } + +- /* You want more than we have to give? Well, try wanting less! */ +- if (in_len < count) +- count = in_len; ++ ret = send_buf(port, buf, count); ++free_buf: ++ kfree(buf); ++ return ret; ++} ++ ++static unsigned int port_fops_poll(struct file *filp, poll_table *wait) ++{ ++ struct port *port; ++ unsigned int ret; ++ ++ port = filp->private_data; ++ poll_wait(filp, &port->waitqueue, wait); ++ ++ ret = 0; ++ if (port->inbuf) ++ ret |= POLLIN | POLLRDNORM; ++ if (port->host_connected) ++ ret |= POLLOUT; ++ if (!port->host_connected) ++ ret |= POLLHUP; ++ ++ return ret; ++} ++ ++static int port_fops_release(struct inode *inode, struct file *filp) ++{ ++ struct port *port; ++ ++ port = filp->private_data; ++ ++ /* Notify host of port being closed */ ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); ++ ++ spin_lock_irq(&port->inbuf_lock); ++ port->guest_connected = false; ++ ++ discard_port_data(port); ++ ++ spin_unlock_irq(&port->inbuf_lock); ++ ++ return 0; ++} ++ ++static int port_fops_open(struct inode *inode, struct file *filp) ++{ ++ struct cdev *cdev = inode->i_cdev; ++ struct port *port; ++ ++ port = container_of(cdev, struct port, cdev); ++ filp->private_data = port; ++ ++ /* ++ * Don't allow opening of console port devices -- that's done ++ * via /dev/hvc ++ */ ++ if (is_console_port(port)) ++ return -ENXIO; ++ ++ /* Allow only one process to open a particular port at a time */ ++ spin_lock_irq(&port->inbuf_lock); ++ if (port->guest_connected) { ++ spin_unlock_irq(&port->inbuf_lock); ++ return -EMFILE; ++ } + +- /* Copy across to their buffer and increment offset. */ +- memcpy(buf, in, count); +- in += count; +- in_len -= count; ++ port->guest_connected = true; ++ spin_unlock_irq(&port->inbuf_lock); + +- /* Finished? Re-register buffer so Host will use it again. */ +- if (in_len == 0) +- add_inbuf(); ++ /* Notify host of port being opened */ ++ send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1); + +- return count; ++ return 0; + } +-/*:*/ + +-/*D:320 Console drivers are initialized very early so boot messages can go out, +- * so we do things slightly differently from the generic virtio initialization +- * of the net and block drivers. ++/* ++ * The file operations that we support: programs in the guest can open ++ * a console device, read from it, write to it, poll for data and ++ * close it. The devices are at ++ * /dev/vportp ++ */ ++static const struct file_operations port_fops = { ++ .owner = THIS_MODULE, ++ .open = port_fops_open, ++ .read = port_fops_read, ++ .write = port_fops_write, ++ .poll = port_fops_poll, ++ .release = port_fops_release, ++}; ++ ++/* ++ * The put_chars() callback is pretty straightforward. + * +- * At this stage, the console is output-only. It's too early to set up a +- * virtqueue, so we let the drivers do some boutique early-output thing. */ +-int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) ++ * We turn the characters into a scatter-gather list, add it to the ++ * output queue and then kick the Host. Then we sit here waiting for ++ * it to finish: inefficient in theory, but in practice ++ * implementations will do it immediately (lguest's Launcher does). ++ */ ++static int put_chars(u32 vtermno, const char *buf, int count) + { +- virtio_cons.put_chars = put_chars; +- return hvc_instantiate(0, 0, &virtio_cons); ++ struct port *port; ++ ++ port = find_port_by_vtermno(vtermno); ++ if (!port) ++ return 0; ++ ++ if (unlikely(early_put_chars)) ++ return early_put_chars(vtermno, buf, count); ++ ++ return send_buf(port, (void *)buf, count); + } + + /* +- * virtio console configuration. This supports: +- * - console resize ++ * get_chars() is the callback from the hvc_console infrastructure ++ * when an interrupt is received. ++ * ++ * We call out to fill_readbuf that gets us the required data from the ++ * buffers that are queued up. + */ +-static void virtcons_apply_config(struct virtio_device *dev) ++static int get_chars(u32 vtermno, char *buf, int count) + { ++ struct port *port; ++ ++ port = find_port_by_vtermno(vtermno); ++ if (!port) ++ return 0; ++ ++ /* If we don't have an input queue yet, we can't get input. */ ++ BUG_ON(!port->in_vq); ++ ++ return fill_readbuf(port, buf, count, false); ++} ++ ++static void resize_console(struct port *port) ++{ ++ struct virtio_device *vdev; + struct winsize ws; + +- if (virtio_has_feature(dev, VIRTIO_CONSOLE_F_SIZE)) { +- dev->config->get(dev, +- offsetof(struct virtio_console_config, cols), +- &ws.ws_col, sizeof(u16)); +- dev->config->get(dev, +- offsetof(struct virtio_console_config, rows), +- &ws.ws_row, sizeof(u16)); +- hvc_resize(hvc, ws); ++ vdev = port->portdev->vdev; ++ if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) { ++ vdev->config->get(vdev, ++ offsetof(struct virtio_console_config, cols), ++ &ws.ws_col, sizeof(u16)); ++ vdev->config->get(vdev, ++ offsetof(struct virtio_console_config, rows), ++ &ws.ws_row, sizeof(u16)); ++ hvc_resize(port->cons.hvc, ws); + } + } + +-/* +- * we support only one console, the hvc struct is a global var +- * We set the configuration at this point, since we now have a tty +- */ ++/* We set the configuration at this point, since we now have a tty */ + static int notifier_add_vio(struct hvc_struct *hp, int data) + { ++ struct port *port; ++ ++ port = find_port_by_vtermno(hp->vtermno); ++ if (!port) ++ return -EINVAL; ++ + hp->irq_requested = 1; +- virtcons_apply_config(vdev); ++ resize_console(port); + + return 0; + } +@@ -173,79 +713,797 @@ static void notifier_del_vio(struct hvc_struct *hp, int data) + hp->irq_requested = 0; + } + +-static void hvc_handle_input(struct virtqueue *vq) ++/* The operations for console ports. */ ++static const struct hv_ops hv_ops = { ++ .get_chars = get_chars, ++ .put_chars = put_chars, ++ .notifier_add = notifier_add_vio, ++ .notifier_del = notifier_del_vio, ++ .notifier_hangup = notifier_del_vio, ++}; ++ ++/* ++ * Console drivers are initialized very early so boot messages can go ++ * out, so we do things slightly differently from the generic virtio ++ * initialization of the net and block drivers. ++ * ++ * At this stage, the console is output-only. It's too early to set ++ * up a virtqueue, so we let the drivers do some boutique early-output ++ * thing. ++ */ ++int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)) + { +- if (hvc_poll(hvc)) ++ early_put_chars = put_chars; ++ return hvc_instantiate(0, 0, &hv_ops); ++} ++ ++int init_port_console(struct port *port) ++{ ++ int ret; ++ ++ /* ++ * The Host's telling us this port is a console port. Hook it ++ * up with an hvc console. ++ * ++ * To set up and manage our virtual console, we call ++ * hvc_alloc(). ++ * ++ * The first argument of hvc_alloc() is the virtual console ++ * number. The second argument is the parameter for the ++ * notification mechanism (like irq number). We currently ++ * leave this as zero, virtqueues have implicit notifications. ++ * ++ * The third argument is a "struct hv_ops" containing the ++ * put_chars() get_chars(), notifier_add() and notifier_del() ++ * pointers. The final argument is the output buffer size: we ++ * can do any size, so we put PAGE_SIZE here. ++ */ ++ port->cons.vtermno = pdrvdata.next_vtermno; ++ ++ port->cons.hvc = hvc_alloc(port->cons.vtermno, 0, &hv_ops, PAGE_SIZE); ++ if (IS_ERR(port->cons.hvc)) { ++ ret = PTR_ERR(port->cons.hvc); ++ dev_err(port->dev, ++ "error %d allocating hvc for port\n", ret); ++ port->cons.hvc = NULL; ++ return ret; ++ } ++ spin_lock_irq(&pdrvdata_lock); ++ pdrvdata.next_vtermno++; ++ list_add_tail(&port->cons.list, &pdrvdata.consoles); ++ spin_unlock_irq(&pdrvdata_lock); ++ port->guest_connected = true; ++ ++ /* Notify host of port being opened */ ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); ++ ++ return 0; ++} ++ ++static ssize_t show_port_name(struct device *dev, ++ struct device_attribute *attr, char *buffer) ++{ ++ struct port *port; ++ ++ port = dev_get_drvdata(dev); ++ ++ return sprintf(buffer, "%s\n", port->name); ++} ++ ++static DEVICE_ATTR(name, S_IRUGO, show_port_name, NULL); ++ ++static struct attribute *port_sysfs_entries[] = { ++ &dev_attr_name.attr, ++ NULL ++}; ++ ++static struct attribute_group port_attribute_group = { ++ .name = NULL, /* put in device directory */ ++ .attrs = port_sysfs_entries, ++}; ++ ++static int debugfs_open(struct inode *inode, struct file *filp) ++{ ++ filp->private_data = inode->i_private; ++ return 0; ++} ++ ++static ssize_t debugfs_read(struct file *filp, char __user *ubuf, ++ size_t count, loff_t *offp) ++{ ++ struct port *port; ++ char *buf; ++ ssize_t ret, out_offset, out_count; ++ ++ out_count = 1024; ++ buf = kmalloc(out_count, GFP_KERNEL); ++ if (!buf) ++ return -ENOMEM; ++ ++ port = filp->private_data; ++ out_offset = 0; ++ out_offset += snprintf(buf + out_offset, out_count, ++ "name: %s\n", port->name ? port->name : ""); ++ out_offset += snprintf(buf + out_offset, out_count - out_offset, ++ "guest_connected: %d\n", port->guest_connected); ++ out_offset += snprintf(buf + out_offset, out_count - out_offset, ++ "host_connected: %d\n", port->host_connected); ++ out_offset += snprintf(buf + out_offset, out_count - out_offset, ++ "is_console: %s\n", ++ is_console_port(port) ? "yes" : "no"); ++ out_offset += snprintf(buf + out_offset, out_count - out_offset, ++ "console_vtermno: %u\n", port->cons.vtermno); ++ ++ ret = simple_read_from_buffer(ubuf, count, offp, buf, out_offset); ++ kfree(buf); ++ return ret; ++} ++ ++static const struct file_operations port_debugfs_ops = { ++ .owner = THIS_MODULE, ++ .open = debugfs_open, ++ .read = debugfs_read, ++}; ++ ++/* Remove all port-specific data. */ ++static int remove_port(struct port *port) ++{ ++ struct port_buffer *buf; ++ ++ spin_lock_irq(&port->portdev->ports_lock); ++ list_del(&port->list); ++ spin_unlock_irq(&port->portdev->ports_lock); ++ ++ if (is_console_port(port)) { ++ spin_lock_irq(&pdrvdata_lock); ++ list_del(&port->cons.list); ++ spin_unlock_irq(&pdrvdata_lock); ++ hvc_remove(port->cons.hvc); ++ } ++ if (port->guest_connected) ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); ++ ++ sysfs_remove_group(&port->dev->kobj, &port_attribute_group); ++ device_destroy(pdrvdata.class, port->dev->devt); ++ cdev_del(&port->cdev); ++ ++ /* Remove unused data this port might have received. */ ++ discard_port_data(port); ++ ++ /* Remove buffers we queued up for the Host to send us data in. */ ++ while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) ++ free_buf(buf); ++ ++ kfree(port->name); ++ ++ debugfs_remove(port->debugfs_file); ++ ++ kfree(port); ++ return 0; ++} ++ ++/* Any private messages that the Host and Guest want to share */ ++static void handle_control_message(struct ports_device *portdev, ++ struct port_buffer *buf) ++{ ++ struct virtio_console_control *cpkt; ++ struct port *port; ++ size_t name_size; ++ int err; ++ ++ cpkt = (struct virtio_console_control *)(buf->buf + buf->offset); ++ ++ port = find_port_by_id(portdev, cpkt->id); ++ if (!port) { ++ /* No valid header at start of buffer. Drop it. */ ++ dev_dbg(&portdev->vdev->dev, ++ "Invalid index %u in control packet\n", cpkt->id); ++ return; ++ } ++ ++ switch (cpkt->event) { ++ case VIRTIO_CONSOLE_CONSOLE_PORT: ++ if (!cpkt->value) ++ break; ++ if (is_console_port(port)) ++ break; ++ ++ init_port_console(port); ++ /* ++ * Could remove the port here in case init fails - but ++ * have to notify the host first. ++ */ ++ break; ++ case VIRTIO_CONSOLE_RESIZE: ++ if (!is_console_port(port)) ++ break; ++ port->cons.hvc->irq_requested = 1; ++ resize_console(port); ++ break; ++ case VIRTIO_CONSOLE_PORT_OPEN: ++ port->host_connected = cpkt->value; ++ wake_up_interruptible(&port->waitqueue); ++ break; ++ case VIRTIO_CONSOLE_PORT_NAME: ++ /* ++ * Skip the size of the header and the cpkt to get the size ++ * of the name that was sent ++ */ ++ name_size = buf->len - buf->offset - sizeof(*cpkt) + 1; ++ ++ port->name = kmalloc(name_size, GFP_KERNEL); ++ if (!port->name) { ++ dev_err(port->dev, ++ "Not enough space to store port name\n"); ++ break; ++ } ++ strncpy(port->name, buf->buf + buf->offset + sizeof(*cpkt), ++ name_size - 1); ++ port->name[name_size - 1] = 0; ++ ++ /* ++ * Since we only have one sysfs attribute, 'name', ++ * create it only if we have a name for the port. ++ */ ++ err = sysfs_create_group(&port->dev->kobj, ++ &port_attribute_group); ++ if (err) ++ dev_err(port->dev, ++ "Error %d creating sysfs device attributes\n", ++ err); ++ ++ break; ++ case VIRTIO_CONSOLE_PORT_REMOVE: ++ /* ++ * Hot unplug the port. We don't decrement nr_ports ++ * since we don't want to deal with extra complexities ++ * of using the lowest-available port id: We can just ++ * pick up the nr_ports number as the id and not have ++ * userspace send it to us. This helps us in two ++ * ways: ++ * ++ * - We don't need to have a 'port_id' field in the ++ * config space when a port is hot-added. This is a ++ * good thing as we might queue up multiple hotplug ++ * requests issued in our workqueue. ++ * ++ * - Another way to deal with this would have been to ++ * use a bitmap of the active ports and select the ++ * lowest non-active port from that map. That ++ * bloats the already tight config space and we ++ * would end up artificially limiting the ++ * max. number of ports to sizeof(bitmap). Right ++ * now we can support 2^32 ports (as the port id is ++ * stored in a u32 type). ++ * ++ */ ++ remove_port(port); ++ break; ++ } ++} ++ ++static void control_work_handler(struct work_struct *work) ++{ ++ struct ports_device *portdev; ++ struct virtqueue *vq; ++ struct port_buffer *buf; ++ unsigned int len; ++ ++ portdev = container_of(work, struct ports_device, control_work); ++ vq = portdev->c_ivq; ++ ++ spin_lock(&portdev->cvq_lock); ++ while ((buf = vq->vq_ops->get_buf(vq, &len))) { ++ spin_unlock(&portdev->cvq_lock); ++ ++ buf->len = len; ++ buf->offset = 0; ++ ++ handle_control_message(portdev, buf); ++ ++ spin_lock(&portdev->cvq_lock); ++ if (add_inbuf(portdev->c_ivq, buf) < 0) { ++ dev_warn(&portdev->vdev->dev, ++ "Error adding buffer to queue\n"); ++ free_buf(buf); ++ } ++ } ++ spin_unlock(&portdev->cvq_lock); ++} ++ ++static void in_intr(struct virtqueue *vq) ++{ ++ struct port *port; ++ unsigned long flags; ++ ++ port = find_port_by_vq(vq->vdev->priv, vq); ++ if (!port) ++ return; ++ ++ spin_lock_irqsave(&port->inbuf_lock, flags); ++ if (!port->inbuf) ++ port->inbuf = get_inbuf(port); ++ ++ /* ++ * Don't queue up data when port is closed. This condition ++ * can be reached when a console port is not yet connected (no ++ * tty is spawned) and the host sends out data to console ++ * ports. For generic serial ports, the host won't ++ * (shouldn't) send data till the guest is connected. ++ */ ++ if (!port->guest_connected) ++ discard_port_data(port); ++ ++ spin_unlock_irqrestore(&port->inbuf_lock, flags); ++ ++ wake_up_interruptible(&port->waitqueue); ++ ++ if (is_console_port(port) && hvc_poll(port->cons.hvc)) + hvc_kick(); + } + +-/*D:370 Once we're further in boot, we get probed like any other virtio device. +- * At this stage we set up the output virtqueue. +- * +- * To set up and manage our virtual console, we call hvc_alloc(). Since we +- * never remove the console device we never need this pointer again. ++static void control_intr(struct virtqueue *vq) ++{ ++ struct ports_device *portdev; ++ ++ portdev = vq->vdev->priv; ++ schedule_work(&portdev->control_work); ++} ++ ++static void config_intr(struct virtio_device *vdev) ++{ ++ struct ports_device *portdev; ++ ++ portdev = vdev->priv; ++ if (use_multiport(portdev)) { ++ /* Handle port hot-add */ ++ schedule_work(&portdev->config_work); ++ } ++ /* ++ * We'll use this way of resizing only for legacy support. ++ * For newer userspace (VIRTIO_CONSOLE_F_MULTPORT+), use ++ * control messages to indicate console size changes so that ++ * it can be done per-port ++ */ ++ resize_console(find_port_by_id(portdev, 0)); ++} ++ ++static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock) ++{ ++ struct port_buffer *buf; ++ unsigned int ret; ++ int err; ++ ++ ret = 0; ++ do { ++ buf = alloc_buf(PAGE_SIZE); ++ if (!buf) ++ break; ++ ++ spin_lock_irq(lock); ++ err = add_inbuf(vq, buf); ++ if (err < 0) { ++ spin_unlock_irq(lock); ++ free_buf(buf); ++ break; ++ } ++ ret++; ++ spin_unlock_irq(lock); ++ } while (err > 0); ++ ++ return ret; ++} ++ ++static int add_port(struct ports_device *portdev, u32 id) ++{ ++ char debugfs_name[16]; ++ struct port *port; ++ struct port_buffer *buf; ++ dev_t devt; ++ int err; ++ ++ port = kmalloc(sizeof(*port), GFP_KERNEL); ++ if (!port) { ++ err = -ENOMEM; ++ goto fail; ++ } ++ ++ port->portdev = portdev; ++ port->id = id; ++ ++ port->name = NULL; ++ port->inbuf = NULL; ++ port->cons.hvc = NULL; ++ ++ port->host_connected = port->guest_connected = false; ++ ++ port->in_vq = portdev->in_vqs[port->id]; ++ port->out_vq = portdev->out_vqs[port->id]; ++ ++ cdev_init(&port->cdev, &port_fops); ++ ++ devt = MKDEV(portdev->chr_major, id); ++ err = cdev_add(&port->cdev, devt, 1); ++ if (err < 0) { ++ dev_err(&port->portdev->vdev->dev, ++ "Error %d adding cdev for port %u\n", err, id); ++ goto free_port; ++ } ++ port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, ++ devt, port, "vport%up%u", ++ port->portdev->drv_index, id); ++ if (IS_ERR(port->dev)) { ++ err = PTR_ERR(port->dev); ++ dev_err(&port->portdev->vdev->dev, ++ "Error %d creating device for port %u\n", ++ err, id); ++ goto free_cdev; ++ } ++ ++ spin_lock_init(&port->inbuf_lock); ++ init_waitqueue_head(&port->waitqueue); ++ ++ /* Fill the in_vq with buffers so the host can send us data. */ ++ err = fill_queue(port->in_vq, &port->inbuf_lock); ++ if (!err) { ++ dev_err(port->dev, "Error allocating inbufs\n"); ++ err = -ENOMEM; ++ goto free_device; ++ } ++ ++ /* ++ * If we're not using multiport support, this has to be a console port ++ */ ++ if (!use_multiport(port->portdev)) { ++ err = init_port_console(port); ++ if (err) ++ goto free_inbufs; ++ } ++ ++ spin_lock_irq(&portdev->ports_lock); ++ list_add_tail(&port->list, &port->portdev->ports); ++ spin_unlock_irq(&portdev->ports_lock); ++ ++ /* ++ * Tell the Host we're set so that it can send us various ++ * configuration parameters for this port (eg, port name, ++ * caching, whether this is a console port, etc.) ++ */ ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); ++ ++ if (pdrvdata.debugfs_dir) { ++ /* ++ * Finally, create the debugfs file that we can use to ++ * inspect a port's state at any time ++ */ ++ sprintf(debugfs_name, "vport%up%u", ++ port->portdev->drv_index, id); ++ port->debugfs_file = debugfs_create_file(debugfs_name, 0444, ++ pdrvdata.debugfs_dir, ++ port, ++ &port_debugfs_ops); ++ } ++ return 0; ++ ++free_inbufs: ++ while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) ++ free_buf(buf); ++free_device: ++ device_destroy(pdrvdata.class, port->dev->devt); ++free_cdev: ++ cdev_del(&port->cdev); ++free_port: ++ kfree(port); ++fail: ++ return err; ++} ++ ++/* ++ * The workhandler for config-space updates. + * +- * Finally we put our input buffer in the input queue, ready to receive. */ +-static int __devinit virtcons_probe(struct virtio_device *dev) ++ * This is called when ports are hot-added. ++ */ ++static void config_work_handler(struct work_struct *work) ++{ ++ struct virtio_console_config virtconconf; ++ struct ports_device *portdev; ++ struct virtio_device *vdev; ++ int err; ++ ++ portdev = container_of(work, struct ports_device, config_work); ++ ++ vdev = portdev->vdev; ++ vdev->config->get(vdev, ++ offsetof(struct virtio_console_config, nr_ports), ++ &virtconconf.nr_ports, ++ sizeof(virtconconf.nr_ports)); ++ ++ if (portdev->config.nr_ports == virtconconf.nr_ports) { ++ /* ++ * Port 0 got hot-added. Since we already did all the ++ * other initialisation for it, just tell the Host ++ * that the port is ready if we find the port. In ++ * case the port was hot-removed earlier, we call ++ * add_port to add the port. ++ */ ++ struct port *port; ++ ++ port = find_port_by_id(portdev, 0); ++ if (!port) ++ add_port(portdev, 0); ++ else ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); ++ return; ++ } ++ if (virtconconf.nr_ports > portdev->config.max_nr_ports) { ++ dev_warn(&vdev->dev, ++ "More ports specified (%u) than allowed (%u)", ++ portdev->config.nr_ports + 1, ++ portdev->config.max_nr_ports); ++ return; ++ } ++ if (virtconconf.nr_ports < portdev->config.nr_ports) ++ return; ++ ++ /* Hot-add ports */ ++ while (virtconconf.nr_ports - portdev->config.nr_ports) { ++ err = add_port(portdev, portdev->config.nr_ports); ++ if (err) ++ break; ++ portdev->config.nr_ports++; ++ } ++} ++ ++static int init_vqs(struct ports_device *portdev) + { +- vq_callback_t *callbacks[] = { hvc_handle_input, NULL}; +- const char *names[] = { "input", "output" }; +- struct virtqueue *vqs[2]; ++ vq_callback_t **io_callbacks; ++ char **io_names; ++ struct virtqueue **vqs; ++ u32 i, j, nr_ports, nr_queues; + int err; + +- vdev = dev; ++ nr_ports = portdev->config.max_nr_ports; ++ nr_queues = use_multiport(portdev) ? (nr_ports + 1) * 2 : 2; + +- /* This is the scratch page we use to receive console input */ +- inbuf = kmalloc(PAGE_SIZE, GFP_KERNEL); +- if (!inbuf) { ++ vqs = kmalloc(nr_queues * sizeof(struct virtqueue *), GFP_KERNEL); ++ if (!vqs) { + err = -ENOMEM; + goto fail; + } ++ io_callbacks = kmalloc(nr_queues * sizeof(vq_callback_t *), GFP_KERNEL); ++ if (!io_callbacks) { ++ err = -ENOMEM; ++ goto free_vqs; ++ } ++ io_names = kmalloc(nr_queues * sizeof(char *), GFP_KERNEL); ++ if (!io_names) { ++ err = -ENOMEM; ++ goto free_callbacks; ++ } ++ portdev->in_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), ++ GFP_KERNEL); ++ if (!portdev->in_vqs) { ++ err = -ENOMEM; ++ goto free_names; ++ } ++ portdev->out_vqs = kmalloc(nr_ports * sizeof(struct virtqueue *), ++ GFP_KERNEL); ++ if (!portdev->out_vqs) { ++ err = -ENOMEM; ++ goto free_invqs; ++ } ++ ++ /* ++ * For backward compat (newer host but older guest), the host ++ * spawns a console port first and also inits the vqs for port ++ * 0 before others. ++ */ ++ j = 0; ++ io_callbacks[j] = in_intr; ++ io_callbacks[j + 1] = NULL; ++ io_names[j] = "input"; ++ io_names[j + 1] = "output"; ++ j += 2; + ++ if (use_multiport(portdev)) { ++ io_callbacks[j] = control_intr; ++ io_callbacks[j + 1] = NULL; ++ io_names[j] = "control-i"; ++ io_names[j + 1] = "control-o"; ++ ++ for (i = 1; i < nr_ports; i++) { ++ j += 2; ++ io_callbacks[j] = in_intr; ++ io_callbacks[j + 1] = NULL; ++ io_names[j] = "input"; ++ io_names[j + 1] = "output"; ++ } ++ } + /* Find the queues. */ +- /* FIXME: This is why we want to wean off hvc: we do nothing +- * when input comes in. */ +- err = vdev->config->find_vqs(vdev, 2, vqs, callbacks, names); ++ err = portdev->vdev->config->find_vqs(portdev->vdev, nr_queues, vqs, ++ io_callbacks, ++ (const char **)io_names); + if (err) ++ goto free_outvqs; ++ ++ j = 0; ++ portdev->in_vqs[0] = vqs[0]; ++ portdev->out_vqs[0] = vqs[1]; ++ j += 2; ++ if (use_multiport(portdev)) { ++ portdev->c_ivq = vqs[j]; ++ portdev->c_ovq = vqs[j + 1]; ++ ++ for (i = 1; i < nr_ports; i++) { ++ j += 2; ++ portdev->in_vqs[i] = vqs[j]; ++ portdev->out_vqs[i] = vqs[j + 1]; ++ } ++ } ++ kfree(io_callbacks); ++ kfree(io_names); ++ kfree(vqs); ++ ++ return 0; ++ ++free_names: ++ kfree(io_names); ++free_callbacks: ++ kfree(io_callbacks); ++free_outvqs: ++ kfree(portdev->out_vqs); ++free_invqs: ++ kfree(portdev->in_vqs); ++free_vqs: ++ kfree(vqs); ++fail: ++ return err; ++} ++ ++static const struct file_operations portdev_fops = { ++ .owner = THIS_MODULE, ++}; ++ ++/* ++ * Once we're further in boot, we get probed like any other virtio ++ * device. ++ * ++ * If the host also supports multiple console ports, we check the ++ * config space to see how many ports the host has spawned. We ++ * initialize each port found. ++ */ ++static int __devinit virtcons_probe(struct virtio_device *vdev) ++{ ++ struct ports_device *portdev; ++ u32 i; ++ int err; ++ bool multiport; ++ ++ portdev = kmalloc(sizeof(*portdev), GFP_KERNEL); ++ if (!portdev) { ++ err = -ENOMEM; ++ goto fail; ++ } ++ ++ /* Attach this portdev to this virtio_device, and vice-versa. */ ++ portdev->vdev = vdev; ++ vdev->priv = portdev; ++ ++ spin_lock_irq(&pdrvdata_lock); ++ portdev->drv_index = pdrvdata.index++; ++ spin_unlock_irq(&pdrvdata_lock); ++ ++ portdev->chr_major = register_chrdev(0, "virtio-portsdev", ++ &portdev_fops); ++ if (portdev->chr_major < 0) { ++ dev_err(&vdev->dev, ++ "Error %d registering chrdev for device %u\n", ++ portdev->chr_major, portdev->drv_index); ++ err = portdev->chr_major; + goto free; ++ } + +- in_vq = vqs[0]; +- out_vq = vqs[1]; ++ multiport = false; ++ portdev->config.nr_ports = 1; ++ portdev->config.max_nr_ports = 1; ++ if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) { ++ multiport = true; ++ vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT; + +- /* Start using the new console output. */ +- virtio_cons.get_chars = get_chars; +- virtio_cons.put_chars = put_chars; +- virtio_cons.notifier_add = notifier_add_vio; +- virtio_cons.notifier_del = notifier_del_vio; +- virtio_cons.notifier_hangup = notifier_del_vio; +- +- /* The first argument of hvc_alloc() is the virtual console number, so +- * we use zero. The second argument is the parameter for the +- * notification mechanism (like irq number). We currently leave this +- * as zero, virtqueues have implicit notifications. +- * +- * The third argument is a "struct hv_ops" containing the put_chars() +- * get_chars(), notifier_add() and notifier_del() pointers. +- * The final argument is the output buffer size: we can do any size, +- * so we put PAGE_SIZE here. */ +- hvc = hvc_alloc(0, 0, &virtio_cons, PAGE_SIZE); +- if (IS_ERR(hvc)) { +- err = PTR_ERR(hvc); +- goto free_vqs; ++ vdev->config->get(vdev, offsetof(struct virtio_console_config, ++ nr_ports), ++ &portdev->config.nr_ports, ++ sizeof(portdev->config.nr_ports)); ++ vdev->config->get(vdev, offsetof(struct virtio_console_config, ++ max_nr_ports), ++ &portdev->config.max_nr_ports, ++ sizeof(portdev->config.max_nr_ports)); ++ if (portdev->config.nr_ports > portdev->config.max_nr_ports) { ++ dev_warn(&vdev->dev, ++ "More ports (%u) specified than allowed (%u). Will init %u ports.", ++ portdev->config.nr_ports, ++ portdev->config.max_nr_ports, ++ portdev->config.max_nr_ports); ++ ++ portdev->config.nr_ports = portdev->config.max_nr_ports; ++ } ++ } ++ ++ /* Let the Host know we support multiple ports.*/ ++ vdev->config->finalize_features(vdev); ++ ++ err = init_vqs(portdev); ++ if (err < 0) { ++ dev_err(&vdev->dev, "Error %d initializing vqs\n", err); ++ goto free_chrdev; ++ } ++ ++ spin_lock_init(&portdev->ports_lock); ++ INIT_LIST_HEAD(&portdev->ports); ++ ++ if (multiport) { ++ spin_lock_init(&portdev->cvq_lock); ++ INIT_WORK(&portdev->control_work, &control_work_handler); ++ INIT_WORK(&portdev->config_work, &config_work_handler); ++ ++ err = fill_queue(portdev->c_ivq, &portdev->cvq_lock); ++ if (!err) { ++ dev_err(&vdev->dev, ++ "Error allocating buffers for control queue\n"); ++ err = -ENOMEM; ++ goto free_vqs; ++ } + } + +- /* Register the input buffer the first time. */ +- add_inbuf(); ++ for (i = 0; i < portdev->config.nr_ports; i++) ++ add_port(portdev, i); ++ ++ /* Start using the new console output. */ ++ early_put_chars = NULL; + return 0; + + free_vqs: + vdev->config->del_vqs(vdev); ++ kfree(portdev->in_vqs); ++ kfree(portdev->out_vqs); ++free_chrdev: ++ unregister_chrdev(portdev->chr_major, "virtio-portsdev"); + free: +- kfree(inbuf); ++ kfree(portdev); + fail: + return err; + } + ++static void virtcons_remove(struct virtio_device *vdev) ++{ ++ struct ports_device *portdev; ++ struct port *port, *port2; ++ struct port_buffer *buf; ++ unsigned int len; ++ ++ portdev = vdev->priv; ++ ++ cancel_work_sync(&portdev->control_work); ++ cancel_work_sync(&portdev->config_work); ++ ++ list_for_each_entry_safe(port, port2, &portdev->ports, list) ++ remove_port(port); ++ ++ unregister_chrdev(portdev->chr_major, "virtio-portsdev"); ++ ++ while ((buf = portdev->c_ivq->vq_ops->get_buf(portdev->c_ivq, &len))) ++ free_buf(buf); ++ ++ while ((buf = portdev->c_ivq->vq_ops->detach_unused_buf(portdev->c_ivq))) ++ free_buf(buf); ++ ++ vdev->config->del_vqs(vdev); ++ kfree(portdev->in_vqs); ++ kfree(portdev->out_vqs); ++ ++ kfree(portdev); ++} ++ + static struct virtio_device_id id_table[] = { + { VIRTIO_ID_CONSOLE, VIRTIO_DEV_ANY_ID }, + { 0 }, +@@ -253,6 +1511,7 @@ static struct virtio_device_id id_table[] = { + + static unsigned int features[] = { + VIRTIO_CONSOLE_F_SIZE, ++ VIRTIO_CONSOLE_F_MULTIPORT, + }; + + static struct virtio_driver virtio_console = { +@@ -262,14 +1521,41 @@ static struct virtio_driver virtio_console = { + .driver.owner = THIS_MODULE, + .id_table = id_table, + .probe = virtcons_probe, +- .config_changed = virtcons_apply_config, ++ .remove = virtcons_remove, ++ .config_changed = config_intr, + }; + + static int __init init(void) + { ++ int err; ++ ++ pdrvdata.class = class_create(THIS_MODULE, "virtio-ports"); ++ if (IS_ERR(pdrvdata.class)) { ++ err = PTR_ERR(pdrvdata.class); ++ pr_err("Error %d creating virtio-ports class\n", err); ++ return err; ++ } ++ ++ pdrvdata.debugfs_dir = debugfs_create_dir("virtio-ports", NULL); ++ if (!pdrvdata.debugfs_dir) { ++ pr_warning("Error %ld creating debugfs dir for virtio-ports\n", ++ PTR_ERR(pdrvdata.debugfs_dir)); ++ } ++ INIT_LIST_HEAD(&pdrvdata.consoles); ++ + return register_virtio_driver(&virtio_console); + } ++ ++static void __exit fini(void) ++{ ++ unregister_virtio_driver(&virtio_console); ++ ++ class_destroy(pdrvdata.class); ++ if (pdrvdata.debugfs_dir) ++ debugfs_remove_recursive(pdrvdata.debugfs_dir); ++} + module_init(init); ++module_exit(fini); + + MODULE_DEVICE_TABLE(virtio, id_table); + MODULE_DESCRIPTION("Virtio console driver"); +diff --git a/drivers/virtio/virtio_ring.c b/drivers/virtio/virtio_ring.c +index fbd2ecd..9bcfe95 100644 +--- a/drivers/virtio/virtio_ring.c ++++ b/drivers/virtio/virtio_ring.c +@@ -334,6 +334,30 @@ static bool vring_enable_cb(struct virtqueue *_vq) + return true; + } + ++static void *vring_detach_unused_buf(struct virtqueue *_vq) ++{ ++ struct vring_virtqueue *vq = to_vvq(_vq); ++ unsigned int i; ++ void *buf; ++ ++ START_USE(vq); ++ ++ for (i = 0; i < vq->vring.num; i++) { ++ if (!vq->data[i]) ++ continue; ++ /* detach_buf clears data, so grab it now. */ ++ buf = vq->data[i]; ++ detach_buf(vq, i); ++ END_USE(vq); ++ return buf; ++ } ++ /* That should have freed everything. */ ++ BUG_ON(vq->num_free != vq->vring.num); ++ ++ END_USE(vq); ++ return NULL; ++} ++ + irqreturn_t vring_interrupt(int irq, void *_vq) + { + struct vring_virtqueue *vq = to_vvq(_vq); +@@ -360,6 +384,7 @@ static struct virtqueue_ops vring_vq_ops = { + .kick = vring_kick, + .disable_cb = vring_disable_cb, + .enable_cb = vring_enable_cb, ++ .detach_unused_buf = vring_detach_unused_buf, + }; + + struct virtqueue *vring_new_virtqueue(unsigned int num, +@@ -406,8 +431,11 @@ struct virtqueue *vring_new_virtqueue(unsigned int num, + /* Put everything in free lists. */ + vq->num_free = num; + vq->free_head = 0; +- for (i = 0; i < num-1; i++) ++ for (i = 0; i < num-1; i++) { + vq->vring.desc[i].next = i+1; ++ vq->data[i] = NULL; ++ } ++ vq->data[i] = NULL; + + return &vq->vq; + } +diff --git a/include/linux/virtio.h b/include/linux/virtio.h +index 057a2e0..f508c65 100644 +--- a/include/linux/virtio.h ++++ b/include/linux/virtio.h +@@ -51,6 +51,9 @@ struct virtqueue { + * This re-enables callbacks; it returns "false" if there are pending + * buffers in the queue, to detect a possible race between the driver + * checking for more work, and enabling callbacks. ++ * @detach_unused_buf: detach first unused buffer ++ * vq: the struct virtqueue we're talking about. ++ * Returns NULL or the "data" token handed to add_buf + * + * Locking rules are straightforward: the driver is responsible for + * locking. No two operations may be invoked simultaneously, with the exception +@@ -71,6 +74,7 @@ struct virtqueue_ops { + + void (*disable_cb)(struct virtqueue *vq); + bool (*enable_cb)(struct virtqueue *vq); ++ void *(*detach_unused_buf)(struct virtqueue *vq); + }; + + /** +diff --git a/include/linux/virtio_console.h b/include/linux/virtio_console.h +index fe88517..ae4f039 100644 +--- a/include/linux/virtio_console.h ++++ b/include/linux/virtio_console.h +@@ -3,19 +3,45 @@ + #include + #include + #include +-/* This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so +- * anyone can use the definitions to implement compatible drivers/servers. */ ++/* ++ * This header, excluding the #ifdef __KERNEL__ part, is BSD licensed so ++ * anyone can use the definitions to implement compatible drivers/servers. ++ * ++ * Copyright (C) Red Hat, Inc., 2009, 2010 ++ */ + + /* Feature bits */ + #define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */ ++#define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */ + + struct virtio_console_config { + /* colums of the screens */ + __u16 cols; + /* rows of the screens */ + __u16 rows; ++ /* max. number of ports this device can hold */ ++ __u32 max_nr_ports; ++ /* number of ports added so far */ ++ __u32 nr_ports; + } __attribute__((packed)); + ++/* ++ * A message that's passed between the Host and the Guest for a ++ * particular port. ++ */ ++struct virtio_console_control { ++ __u32 id; /* Port number */ ++ __u16 event; /* The kind of control event (see below) */ ++ __u16 value; /* Extra information for the key */ ++}; ++ ++/* Some events for control messages */ ++#define VIRTIO_CONSOLE_PORT_READY 0 ++#define VIRTIO_CONSOLE_CONSOLE_PORT 1 ++#define VIRTIO_CONSOLE_RESIZE 2 ++#define VIRTIO_CONSOLE_PORT_OPEN 3 ++#define VIRTIO_CONSOLE_PORT_NAME 4 ++#define VIRTIO_CONSOLE_PORT_REMOVE 5 + + #ifdef __KERNEL__ + int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int)); diff --git a/virt_console-rollup2.patch b/virt_console-rollup2.patch new file mode 100644 index 000000000..3b1358f8b --- /dev/null +++ b/virt_console-rollup2.patch @@ -0,0 +1,961 @@ +diff --git a/MAINTAINERS b/MAINTAINERS +index d371022..63c3620 100644 +--- a/MAINTAINERS ++++ b/MAINTAINERS +@@ -2336,12 +2336,6 @@ L: linuxppc-dev@ozlabs.org + S: Odd Fixes + F: drivers/char/hvc_* + +-VIRTIO CONSOLE DRIVER +-M: Amit Shah +-L: virtualization@lists.linux-foundation.org +-S: Maintained +-F: drivers/char/virtio_console.c +- + GSPCA FINEPIX SUBDRIVER + M: Frank Zago + L: linux-media@vger.kernel.org +@@ -5682,6 +5676,13 @@ S: Maintained + F: Documentation/filesystems/vfat.txt + F: fs/fat/ + ++VIRTIO CONSOLE DRIVER ++M: Amit Shah ++L: virtualization@lists.linux-foundation.org ++S: Maintained ++F: drivers/char/virtio_console.c ++F: include/linux/virtio_console.h ++ + VIRTIO HOST (VHOST) + M: "Michael S. Tsirkin" + L: kvm@vger.kernel.org +diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c +index 213373b..ab29b98 100644 +--- a/drivers/char/virtio_console.c ++++ b/drivers/char/virtio_console.c +@@ -109,7 +109,6 @@ struct ports_device { + * notification + */ + struct work_struct control_work; +- struct work_struct config_work; + + struct list_head ports; + +@@ -159,6 +158,9 @@ struct port { + */ + spinlock_t inbuf_lock; + ++ /* Protect the operations on the out_vq. */ ++ spinlock_t outvq_lock; ++ + /* The IO vqs for this port */ + struct virtqueue *in_vq, *out_vq; + +@@ -184,6 +186,8 @@ struct port { + /* The 'id' to identify the port with the Host */ + u32 id; + ++ bool outvq_full; ++ + /* Is the host device open */ + bool host_connected; + +@@ -373,22 +377,22 @@ out: + return ret; + } + +-static ssize_t send_control_msg(struct port *port, unsigned int event, +- unsigned int value) ++static ssize_t __send_control_msg(struct ports_device *portdev, u32 port_id, ++ unsigned int event, unsigned int value) + { + struct scatterlist sg[1]; + struct virtio_console_control cpkt; + struct virtqueue *vq; +- int len; ++ unsigned int len; + +- if (!use_multiport(port->portdev)) ++ if (!use_multiport(portdev)) + return 0; + +- cpkt.id = port->id; ++ cpkt.id = port_id; + cpkt.event = event; + cpkt.value = value; + +- vq = port->portdev->c_ovq; ++ vq = portdev->c_ovq; + + sg_init_one(sg, &cpkt, sizeof(cpkt)); + if (vq->vq_ops->add_buf(vq, sg, 1, 0, &cpkt) >= 0) { +@@ -399,15 +403,39 @@ static ssize_t send_control_msg(struct port *port, unsigned int event, + return 0; + } + +-static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count) ++static ssize_t send_control_msg(struct port *port, unsigned int event, ++ unsigned int value) ++{ ++ return __send_control_msg(port->portdev, port->id, event, value); ++} ++ ++/* Callers must take the port->outvq_lock */ ++static void reclaim_consumed_buffers(struct port *port) ++{ ++ void *buf; ++ unsigned int len; ++ ++ while ((buf = port->out_vq->vq_ops->get_buf(port->out_vq, &len))) { ++ kfree(buf); ++ port->outvq_full = false; ++ } ++} ++ ++static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count, ++ bool nonblock) + { + struct scatterlist sg[1]; + struct virtqueue *out_vq; + ssize_t ret; ++ unsigned long flags; + unsigned int len; + + out_vq = port->out_vq; + ++ spin_lock_irqsave(&port->outvq_lock, flags); ++ ++ reclaim_consumed_buffers(port); ++ + sg_init_one(sg, in_buf, in_count); + ret = out_vq->vq_ops->add_buf(out_vq, sg, 1, 0, in_buf); + +@@ -415,20 +443,31 @@ static ssize_t send_buf(struct port *port, void *in_buf, size_t in_count) + out_vq->vq_ops->kick(out_vq); + + if (ret < 0) { +- len = 0; +- goto fail; ++ in_count = 0; ++ goto done; + } + ++ if (ret == 0) ++ port->outvq_full = true; ++ ++ if (nonblock) ++ goto done; ++ + /* + * Wait till the host acknowledges it pushed out the data we +- * sent. Also ensure we return to userspace the number of +- * bytes that were successfully consumed by the host. ++ * sent. This is done for ports in blocking mode or for data ++ * from the hvc_console; the tty operations are performed with ++ * spinlocks held so we can't sleep here. + */ + while (!out_vq->vq_ops->get_buf(out_vq, &len)) + cpu_relax(); +-fail: +- /* We're expected to return the amount of data we wrote */ +- return len; ++done: ++ spin_unlock_irqrestore(&port->outvq_lock, flags); ++ /* ++ * We're expected to return the amount of data we wrote -- all ++ * of it ++ */ ++ return in_count; + } + + /* +@@ -477,9 +516,28 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count, + } + + /* The condition that must be true for polling to end */ +-static bool wait_is_over(struct port *port) ++static bool will_read_block(struct port *port) ++{ ++ return !port_has_data(port) && port->host_connected; ++} ++ ++static bool will_write_block(struct port *port) + { +- return port_has_data(port) || !port->host_connected; ++ bool ret; ++ ++ if (!port->host_connected) ++ return true; ++ ++ spin_lock_irq(&port->outvq_lock); ++ /* ++ * Check if the Host has consumed any buffers since we last ++ * sent data (this is only applicable for nonblocking ports). ++ */ ++ reclaim_consumed_buffers(port); ++ ret = port->outvq_full; ++ spin_unlock_irq(&port->outvq_lock); ++ ++ return ret; + } + + static ssize_t port_fops_read(struct file *filp, char __user *ubuf, +@@ -502,7 +560,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf, + return -EAGAIN; + + ret = wait_event_interruptible(port->waitqueue, +- wait_is_over(port)); ++ !will_read_block(port)); + if (ret < 0) + return ret; + } +@@ -528,9 +586,22 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, + struct port *port; + char *buf; + ssize_t ret; ++ bool nonblock; + + port = filp->private_data; + ++ nonblock = filp->f_flags & O_NONBLOCK; ++ ++ if (will_write_block(port)) { ++ if (nonblock) ++ return -EAGAIN; ++ ++ ret = wait_event_interruptible(port->waitqueue, ++ !will_write_block(port)); ++ if (ret < 0) ++ return ret; ++ } ++ + count = min((size_t)(32 * 1024), count); + + buf = kmalloc(count, GFP_KERNEL); +@@ -543,9 +614,14 @@ static ssize_t port_fops_write(struct file *filp, const char __user *ubuf, + goto free_buf; + } + +- ret = send_buf(port, buf, count); ++ ret = send_buf(port, buf, count, nonblock); ++ ++ if (nonblock && ret > 0) ++ goto out; ++ + free_buf: + kfree(buf); ++out: + return ret; + } + +@@ -560,7 +636,7 @@ static unsigned int port_fops_poll(struct file *filp, poll_table *wait) + ret = 0; + if (port->inbuf) + ret |= POLLIN | POLLRDNORM; +- if (port->host_connected) ++ if (!will_write_block(port)) + ret |= POLLOUT; + if (!port->host_connected) + ret |= POLLHUP; +@@ -584,6 +660,10 @@ static int port_fops_release(struct inode *inode, struct file *filp) + + spin_unlock_irq(&port->inbuf_lock); + ++ spin_lock_irq(&port->outvq_lock); ++ reclaim_consumed_buffers(port); ++ spin_unlock_irq(&port->outvq_lock); ++ + return 0; + } + +@@ -612,6 +692,15 @@ static int port_fops_open(struct inode *inode, struct file *filp) + port->guest_connected = true; + spin_unlock_irq(&port->inbuf_lock); + ++ spin_lock_irq(&port->outvq_lock); ++ /* ++ * There might be a chance that we missed reclaiming a few ++ * buffers in the window of the port getting previously closed ++ * and opening now. ++ */ ++ reclaim_consumed_buffers(port); ++ spin_unlock_irq(&port->outvq_lock); ++ + /* Notify host of port being opened */ + send_control_msg(filp->private_data, VIRTIO_CONSOLE_PORT_OPEN, 1); + +@@ -645,14 +734,14 @@ static int put_chars(u32 vtermno, const char *buf, int count) + { + struct port *port; + +- port = find_port_by_vtermno(vtermno); +- if (!port) +- return 0; +- + if (unlikely(early_put_chars)) + return early_put_chars(vtermno, buf, count); + +- return send_buf(port, (void *)buf, count); ++ port = find_port_by_vtermno(vtermno); ++ if (!port) ++ return -EPIPE; ++ ++ return send_buf(port, (void *)buf, count, false); + } + + /* +@@ -666,9 +755,13 @@ static int get_chars(u32 vtermno, char *buf, int count) + { + struct port *port; + ++ /* If we've not set up the port yet, we have no input to give. */ ++ if (unlikely(early_put_chars)) ++ return 0; ++ + port = find_port_by_vtermno(vtermno); + if (!port) +- return 0; ++ return -EPIPE; + + /* If we don't have an input queue yet, we can't get input. */ + BUG_ON(!port->in_vq); +@@ -681,6 +774,10 @@ static void resize_console(struct port *port) + struct virtio_device *vdev; + struct winsize ws; + ++ /* The port could have been hot-unplugged */ ++ if (!port) ++ return; ++ + vdev = port->portdev->vdev; + if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_SIZE)) { + vdev->config->get(vdev, +@@ -774,6 +871,13 @@ int init_port_console(struct port *port) + spin_unlock_irq(&pdrvdata_lock); + port->guest_connected = true; + ++ /* ++ * Start using the new console output if this is the first ++ * console to come up. ++ */ ++ if (early_put_chars) ++ early_put_chars = NULL; ++ + /* Notify host of port being opened */ + send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 1); + +@@ -829,6 +933,8 @@ static ssize_t debugfs_read(struct file *filp, char __user *ubuf, + out_offset += snprintf(buf + out_offset, out_count - out_offset, + "host_connected: %d\n", port->host_connected); + out_offset += snprintf(buf + out_offset, out_count - out_offset, ++ "outvq_full: %d\n", port->outvq_full); ++ out_offset += snprintf(buf + out_offset, out_count - out_offset, + "is_console: %s\n", + is_console_port(port) ? "yes" : "no"); + out_offset += snprintf(buf + out_offset, out_count - out_offset, +@@ -845,6 +951,140 @@ static const struct file_operations port_debugfs_ops = { + .read = debugfs_read, + }; + ++static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock) ++{ ++ struct port_buffer *buf; ++ unsigned int nr_added_bufs; ++ int ret; ++ ++ nr_added_bufs = 0; ++ do { ++ buf = alloc_buf(PAGE_SIZE); ++ if (!buf) ++ break; ++ ++ spin_lock_irq(lock); ++ ret = add_inbuf(vq, buf); ++ if (ret < 0) { ++ spin_unlock_irq(lock); ++ free_buf(buf); ++ break; ++ } ++ nr_added_bufs++; ++ spin_unlock_irq(lock); ++ } while (ret > 0); ++ ++ return nr_added_bufs; ++} ++ ++static int add_port(struct ports_device *portdev, u32 id) ++{ ++ char debugfs_name[16]; ++ struct port *port; ++ struct port_buffer *buf; ++ dev_t devt; ++ unsigned int nr_added_bufs; ++ int err; ++ ++ port = kmalloc(sizeof(*port), GFP_KERNEL); ++ if (!port) { ++ err = -ENOMEM; ++ goto fail; ++ } ++ ++ port->portdev = portdev; ++ port->id = id; ++ ++ port->name = NULL; ++ port->inbuf = NULL; ++ port->cons.hvc = NULL; ++ ++ port->host_connected = port->guest_connected = false; ++ ++ port->outvq_full = false; ++ ++ port->in_vq = portdev->in_vqs[port->id]; ++ port->out_vq = portdev->out_vqs[port->id]; ++ ++ cdev_init(&port->cdev, &port_fops); ++ ++ devt = MKDEV(portdev->chr_major, id); ++ err = cdev_add(&port->cdev, devt, 1); ++ if (err < 0) { ++ dev_err(&port->portdev->vdev->dev, ++ "Error %d adding cdev for port %u\n", err, id); ++ goto free_port; ++ } ++ port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, ++ devt, port, "vport%up%u", ++ port->portdev->drv_index, id); ++ if (IS_ERR(port->dev)) { ++ err = PTR_ERR(port->dev); ++ dev_err(&port->portdev->vdev->dev, ++ "Error %d creating device for port %u\n", ++ err, id); ++ goto free_cdev; ++ } ++ ++ spin_lock_init(&port->inbuf_lock); ++ spin_lock_init(&port->outvq_lock); ++ init_waitqueue_head(&port->waitqueue); ++ ++ /* Fill the in_vq with buffers so the host can send us data. */ ++ nr_added_bufs = fill_queue(port->in_vq, &port->inbuf_lock); ++ if (!nr_added_bufs) { ++ dev_err(port->dev, "Error allocating inbufs\n"); ++ err = -ENOMEM; ++ goto free_device; ++ } ++ ++ /* ++ * If we're not using multiport support, this has to be a console port ++ */ ++ if (!use_multiport(port->portdev)) { ++ err = init_port_console(port); ++ if (err) ++ goto free_inbufs; ++ } ++ ++ spin_lock_irq(&portdev->ports_lock); ++ list_add_tail(&port->list, &port->portdev->ports); ++ spin_unlock_irq(&portdev->ports_lock); ++ ++ /* ++ * Tell the Host we're set so that it can send us various ++ * configuration parameters for this port (eg, port name, ++ * caching, whether this is a console port, etc.) ++ */ ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); ++ ++ if (pdrvdata.debugfs_dir) { ++ /* ++ * Finally, create the debugfs file that we can use to ++ * inspect a port's state at any time ++ */ ++ sprintf(debugfs_name, "vport%up%u", ++ port->portdev->drv_index, id); ++ port->debugfs_file = debugfs_create_file(debugfs_name, 0444, ++ pdrvdata.debugfs_dir, ++ port, ++ &port_debugfs_ops); ++ } ++ return 0; ++ ++free_inbufs: ++ while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) ++ free_buf(buf); ++free_device: ++ device_destroy(pdrvdata.class, port->dev->devt); ++free_cdev: ++ cdev_del(&port->cdev); ++free_port: ++ kfree(port); ++fail: ++ return err; ++} ++ + /* Remove all port-specific data. */ + static int remove_port(struct port *port) + { +@@ -858,7 +1098,18 @@ static int remove_port(struct port *port) + spin_lock_irq(&pdrvdata_lock); + list_del(&port->cons.list); + spin_unlock_irq(&pdrvdata_lock); ++#if 0 ++ /* ++ * hvc_remove() not called as removing one hvc port ++ * results in other hvc ports getting frozen. ++ * ++ * Once this is resolved in hvc, this functionality ++ * will be enabled. Till that is done, the -EPIPE ++ * return from get_chars() above will help ++ * hvc_console.c to clean up on ports we remove here. ++ */ + hvc_remove(port->cons.hvc); ++#endif + } + if (port->guest_connected) + send_control_msg(port, VIRTIO_CONSOLE_PORT_OPEN, 0); +@@ -870,6 +1121,8 @@ static int remove_port(struct port *port) + /* Remove unused data this port might have received. */ + discard_port_data(port); + ++ reclaim_consumed_buffers(port); ++ + /* Remove buffers we queued up for the Host to send us data in. */ + while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) + free_buf(buf); +@@ -894,7 +1147,7 @@ static void handle_control_message(struct ports_device *portdev, + cpkt = (struct virtio_console_control *)(buf->buf + buf->offset); + + port = find_port_by_id(portdev, cpkt->id); +- if (!port) { ++ if (!port && cpkt->event != VIRTIO_CONSOLE_PORT_ADD) { + /* No valid header at start of buffer. Drop it. */ + dev_dbg(&portdev->vdev->dev, + "Invalid index %u in control packet\n", cpkt->id); +@@ -902,6 +1155,24 @@ static void handle_control_message(struct ports_device *portdev, + } + + switch (cpkt->event) { ++ case VIRTIO_CONSOLE_PORT_ADD: ++ if (port) { ++ dev_dbg(&portdev->vdev->dev, ++ "Port %u already added\n", port->id); ++ send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); ++ break; ++ } ++ if (cpkt->id >= portdev->config.max_nr_ports) { ++ dev_warn(&portdev->vdev->dev, ++ "Request for adding port with out-of-bound id %u, max. supported id: %u\n", ++ cpkt->id, portdev->config.max_nr_ports - 1); ++ break; ++ } ++ add_port(portdev, cpkt->id); ++ break; ++ case VIRTIO_CONSOLE_PORT_REMOVE: ++ remove_port(port); ++ break; + case VIRTIO_CONSOLE_CONSOLE_PORT: + if (!cpkt->value) + break; +@@ -923,6 +1194,14 @@ static void handle_control_message(struct ports_device *portdev, + case VIRTIO_CONSOLE_PORT_OPEN: + port->host_connected = cpkt->value; + wake_up_interruptible(&port->waitqueue); ++ /* ++ * If the host port got closed and the host had any ++ * unconsumed buffers, we'll be able to reclaim them ++ * now. ++ */ ++ spin_lock_irq(&port->outvq_lock); ++ reclaim_consumed_buffers(port); ++ spin_unlock_irq(&port->outvq_lock); + break; + case VIRTIO_CONSOLE_PORT_NAME: + /* +@@ -947,37 +1226,18 @@ static void handle_control_message(struct ports_device *portdev, + */ + err = sysfs_create_group(&port->dev->kobj, + &port_attribute_group); +- if (err) ++ if (err) { + dev_err(port->dev, + "Error %d creating sysfs device attributes\n", + err); +- +- break; +- case VIRTIO_CONSOLE_PORT_REMOVE: +- /* +- * Hot unplug the port. We don't decrement nr_ports +- * since we don't want to deal with extra complexities +- * of using the lowest-available port id: We can just +- * pick up the nr_ports number as the id and not have +- * userspace send it to us. This helps us in two +- * ways: +- * +- * - We don't need to have a 'port_id' field in the +- * config space when a port is hot-added. This is a +- * good thing as we might queue up multiple hotplug +- * requests issued in our workqueue. +- * +- * - Another way to deal with this would have been to +- * use a bitmap of the active ports and select the +- * lowest non-active port from that map. That +- * bloats the already tight config space and we +- * would end up artificially limiting the +- * max. number of ports to sizeof(bitmap). Right +- * now we can support 2^32 ports (as the port id is +- * stored in a u32 type). +- * +- */ +- remove_port(port); ++ } else { ++ /* ++ * Generate a udev event so that appropriate ++ * symlinks can be created based on udev ++ * rules. ++ */ ++ kobject_uevent(&port->dev->kobj, KOBJ_CHANGE); ++ } + break; + } + } +@@ -1055,10 +1315,7 @@ static void config_intr(struct virtio_device *vdev) + struct ports_device *portdev; + + portdev = vdev->priv; +- if (use_multiport(portdev)) { +- /* Handle port hot-add */ +- schedule_work(&portdev->config_work); +- } ++ + /* + * We'll use this way of resizing only for legacy support. + * For newer userspace (VIRTIO_CONSOLE_F_MULTPORT+), use +@@ -1068,192 +1325,6 @@ static void config_intr(struct virtio_device *vdev) + resize_console(find_port_by_id(portdev, 0)); + } + +-static unsigned int fill_queue(struct virtqueue *vq, spinlock_t *lock) +-{ +- struct port_buffer *buf; +- unsigned int ret; +- int err; +- +- ret = 0; +- do { +- buf = alloc_buf(PAGE_SIZE); +- if (!buf) +- break; +- +- spin_lock_irq(lock); +- err = add_inbuf(vq, buf); +- if (err < 0) { +- spin_unlock_irq(lock); +- free_buf(buf); +- break; +- } +- ret++; +- spin_unlock_irq(lock); +- } while (err > 0); +- +- return ret; +-} +- +-static int add_port(struct ports_device *portdev, u32 id) +-{ +- char debugfs_name[16]; +- struct port *port; +- struct port_buffer *buf; +- dev_t devt; +- int err; +- +- port = kmalloc(sizeof(*port), GFP_KERNEL); +- if (!port) { +- err = -ENOMEM; +- goto fail; +- } +- +- port->portdev = portdev; +- port->id = id; +- +- port->name = NULL; +- port->inbuf = NULL; +- port->cons.hvc = NULL; +- +- port->host_connected = port->guest_connected = false; +- +- port->in_vq = portdev->in_vqs[port->id]; +- port->out_vq = portdev->out_vqs[port->id]; +- +- cdev_init(&port->cdev, &port_fops); +- +- devt = MKDEV(portdev->chr_major, id); +- err = cdev_add(&port->cdev, devt, 1); +- if (err < 0) { +- dev_err(&port->portdev->vdev->dev, +- "Error %d adding cdev for port %u\n", err, id); +- goto free_port; +- } +- port->dev = device_create(pdrvdata.class, &port->portdev->vdev->dev, +- devt, port, "vport%up%u", +- port->portdev->drv_index, id); +- if (IS_ERR(port->dev)) { +- err = PTR_ERR(port->dev); +- dev_err(&port->portdev->vdev->dev, +- "Error %d creating device for port %u\n", +- err, id); +- goto free_cdev; +- } +- +- spin_lock_init(&port->inbuf_lock); +- init_waitqueue_head(&port->waitqueue); +- +- /* Fill the in_vq with buffers so the host can send us data. */ +- err = fill_queue(port->in_vq, &port->inbuf_lock); +- if (!err) { +- dev_err(port->dev, "Error allocating inbufs\n"); +- err = -ENOMEM; +- goto free_device; +- } +- +- /* +- * If we're not using multiport support, this has to be a console port +- */ +- if (!use_multiport(port->portdev)) { +- err = init_port_console(port); +- if (err) +- goto free_inbufs; +- } +- +- spin_lock_irq(&portdev->ports_lock); +- list_add_tail(&port->list, &port->portdev->ports); +- spin_unlock_irq(&portdev->ports_lock); +- +- /* +- * Tell the Host we're set so that it can send us various +- * configuration parameters for this port (eg, port name, +- * caching, whether this is a console port, etc.) +- */ +- send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); +- +- if (pdrvdata.debugfs_dir) { +- /* +- * Finally, create the debugfs file that we can use to +- * inspect a port's state at any time +- */ +- sprintf(debugfs_name, "vport%up%u", +- port->portdev->drv_index, id); +- port->debugfs_file = debugfs_create_file(debugfs_name, 0444, +- pdrvdata.debugfs_dir, +- port, +- &port_debugfs_ops); +- } +- return 0; +- +-free_inbufs: +- while ((buf = port->in_vq->vq_ops->detach_unused_buf(port->in_vq))) +- free_buf(buf); +-free_device: +- device_destroy(pdrvdata.class, port->dev->devt); +-free_cdev: +- cdev_del(&port->cdev); +-free_port: +- kfree(port); +-fail: +- return err; +-} +- +-/* +- * The workhandler for config-space updates. +- * +- * This is called when ports are hot-added. +- */ +-static void config_work_handler(struct work_struct *work) +-{ +- struct virtio_console_config virtconconf; +- struct ports_device *portdev; +- struct virtio_device *vdev; +- int err; +- +- portdev = container_of(work, struct ports_device, config_work); +- +- vdev = portdev->vdev; +- vdev->config->get(vdev, +- offsetof(struct virtio_console_config, nr_ports), +- &virtconconf.nr_ports, +- sizeof(virtconconf.nr_ports)); +- +- if (portdev->config.nr_ports == virtconconf.nr_ports) { +- /* +- * Port 0 got hot-added. Since we already did all the +- * other initialisation for it, just tell the Host +- * that the port is ready if we find the port. In +- * case the port was hot-removed earlier, we call +- * add_port to add the port. +- */ +- struct port *port; +- +- port = find_port_by_id(portdev, 0); +- if (!port) +- add_port(portdev, 0); +- else +- send_control_msg(port, VIRTIO_CONSOLE_PORT_READY, 1); +- return; +- } +- if (virtconconf.nr_ports > portdev->config.max_nr_ports) { +- dev_warn(&vdev->dev, +- "More ports specified (%u) than allowed (%u)", +- portdev->config.nr_ports + 1, +- portdev->config.max_nr_ports); +- return; +- } +- if (virtconconf.nr_ports < portdev->config.nr_ports) +- return; +- +- /* Hot-add ports */ +- while (virtconconf.nr_ports - portdev->config.nr_ports) { +- err = add_port(portdev, portdev->config.nr_ports); +- if (err) +- break; +- portdev->config.nr_ports++; +- } +-} +- + static int init_vqs(struct ports_device *portdev) + { + vq_callback_t **io_callbacks; +@@ -1375,7 +1446,6 @@ static const struct file_operations portdev_fops = { + static int __devinit virtcons_probe(struct virtio_device *vdev) + { + struct ports_device *portdev; +- u32 i; + int err; + bool multiport; + +@@ -1404,29 +1474,15 @@ static int __devinit virtcons_probe(struct virtio_device *vdev) + } + + multiport = false; +- portdev->config.nr_ports = 1; + portdev->config.max_nr_ports = 1; + if (virtio_has_feature(vdev, VIRTIO_CONSOLE_F_MULTIPORT)) { + multiport = true; + vdev->features[0] |= 1 << VIRTIO_CONSOLE_F_MULTIPORT; + + vdev->config->get(vdev, offsetof(struct virtio_console_config, +- nr_ports), +- &portdev->config.nr_ports, +- sizeof(portdev->config.nr_ports)); +- vdev->config->get(vdev, offsetof(struct virtio_console_config, + max_nr_ports), + &portdev->config.max_nr_ports, + sizeof(portdev->config.max_nr_ports)); +- if (portdev->config.nr_ports > portdev->config.max_nr_ports) { +- dev_warn(&vdev->dev, +- "More ports (%u) specified than allowed (%u). Will init %u ports.", +- portdev->config.nr_ports, +- portdev->config.max_nr_ports, +- portdev->config.max_nr_ports); +- +- portdev->config.nr_ports = portdev->config.max_nr_ports; +- } + } + + /* Let the Host know we support multiple ports.*/ +@@ -1442,24 +1498,28 @@ static int __devinit virtcons_probe(struct virtio_device *vdev) + INIT_LIST_HEAD(&portdev->ports); + + if (multiport) { ++ unsigned int nr_added_bufs; ++ + spin_lock_init(&portdev->cvq_lock); + INIT_WORK(&portdev->control_work, &control_work_handler); +- INIT_WORK(&portdev->config_work, &config_work_handler); + +- err = fill_queue(portdev->c_ivq, &portdev->cvq_lock); +- if (!err) { ++ nr_added_bufs = fill_queue(portdev->c_ivq, &portdev->cvq_lock); ++ if (!nr_added_bufs) { + dev_err(&vdev->dev, + "Error allocating buffers for control queue\n"); + err = -ENOMEM; + goto free_vqs; + } ++ } else { ++ /* ++ * For backward compatibility: Create a console port ++ * if we're running on older host. ++ */ ++ add_port(portdev, 0); + } + +- for (i = 0; i < portdev->config.nr_ports; i++) +- add_port(portdev, i); +- +- /* Start using the new console output. */ +- early_put_chars = NULL; ++ __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, ++ VIRTIO_CONSOLE_DEVICE_READY, 1); + return 0; + + free_vqs: +@@ -1471,6 +1531,9 @@ free_chrdev: + free: + kfree(portdev); + fail: ++ /* The host might want to notify mgmt sw about device add failure */ ++ __send_control_msg(portdev, VIRTIO_CONSOLE_BAD_ID, ++ VIRTIO_CONSOLE_DEVICE_READY, 0); + return err; + } + +@@ -1484,7 +1547,6 @@ static void virtcons_remove(struct virtio_device *vdev) + portdev = vdev->priv; + + cancel_work_sync(&portdev->control_work); +- cancel_work_sync(&portdev->config_work); + + list_for_each_entry_safe(port, port2, &portdev->ports, list) + remove_port(port); +diff --git a/include/linux/virtio_console.h b/include/linux/virtio_console.h +index ae4f039..a85064d 100644 +--- a/include/linux/virtio_console.h ++++ b/include/linux/virtio_console.h +@@ -14,6 +14,8 @@ + #define VIRTIO_CONSOLE_F_SIZE 0 /* Does host provide console size? */ + #define VIRTIO_CONSOLE_F_MULTIPORT 1 /* Does host provide multiple ports? */ + ++#define VIRTIO_CONSOLE_BAD_ID (~(u32)0) ++ + struct virtio_console_config { + /* colums of the screens */ + __u16 cols; +@@ -21,8 +23,6 @@ struct virtio_console_config { + __u16 rows; + /* max. number of ports this device can hold */ + __u32 max_nr_ports; +- /* number of ports added so far */ +- __u32 nr_ports; + } __attribute__((packed)); + + /* +@@ -36,12 +36,14 @@ struct virtio_console_control { + }; + + /* Some events for control messages */ +-#define VIRTIO_CONSOLE_PORT_READY 0 +-#define VIRTIO_CONSOLE_CONSOLE_PORT 1 +-#define VIRTIO_CONSOLE_RESIZE 2 +-#define VIRTIO_CONSOLE_PORT_OPEN 3 +-#define VIRTIO_CONSOLE_PORT_NAME 4 +-#define VIRTIO_CONSOLE_PORT_REMOVE 5 ++#define VIRTIO_CONSOLE_DEVICE_READY 0 ++#define VIRTIO_CONSOLE_PORT_ADD 1 ++#define VIRTIO_CONSOLE_PORT_REMOVE 2 ++#define VIRTIO_CONSOLE_PORT_READY 3 ++#define VIRTIO_CONSOLE_CONSOLE_PORT 4 ++#define VIRTIO_CONSOLE_RESIZE 5 ++#define VIRTIO_CONSOLE_PORT_OPEN 6 ++#define VIRTIO_CONSOLE_PORT_NAME 7 + + #ifdef __KERNEL__ + int __init virtio_cons_early_init(int (*put_chars)(u32, const char *, int));